Merge pull request #9887 from ethereum/evmhost

EVMHost: keep precompile balance/settings across resets
This commit is contained in:
chriseth 2020-09-24 21:15:06 +02:00 committed by GitHub
commit 5711d664aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 11 deletions

View File

@ -123,6 +123,22 @@ EVMHost::EVMHost(langutil::EVMVersion _evmVersion, evmc::VM& _vm):
else
assertThrow(false, Exception, "Unsupported EVM version");
tx_context.block_difficulty = evmc::uint256be{200000000};
tx_context.block_gas_limit = 20000000;
tx_context.block_coinbase = 0x7878787878787878787878787878787878787878_address;
tx_context.tx_gas_price = evmc::uint256be{3000000000};
tx_context.tx_origin = 0x9292929292929292929292929292929292929292_address;
// Mainnet according to EIP-155
tx_context.chain_id = evmc::uint256be{1};
reset();
}
void EVMHost::reset()
{
accounts.clear();
m_currentAddress = {};
// Mark all precompiled contracts as existing. Existing here means to have a balance (as per EIP-161).
// NOTE: keep this in sync with `EVMHost::call` below.
//
@ -131,19 +147,13 @@ EVMHost::EVMHost(langutil::EVMVersion _evmVersion, evmc::VM& _vm):
// roughly 22 days before the update went live.
for (unsigned precompiledAddress = 1; precompiledAddress <= 8; precompiledAddress++)
{
evmc::address address{};
address.bytes[19] = precompiledAddress;
evmc::address address{precompiledAddress};
// 1wei
accounts[address].balance = evmc::uint256be{1};
// Set according to EIP-1052.
if (precompiledAddress < 5 || m_evmVersion >= langutil::EVMVersion::byzantium())
accounts[address].codehash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470_bytes32;
}
tx_context.block_difficulty = evmc::uint256be{200000000};
tx_context.block_gas_limit = 20000000;
tx_context.block_coinbase = 0x7878787878787878787878787878787878787878_address;
tx_context.tx_gas_price = evmc::uint256be{3000000000};
tx_context.tx_origin = 0x9292929292929292929292929292929292929292_address;
// Mainnet according to EIP-155
tx_context.chain_id = evmc::uint256be{1};
}
void EVMHost::selfdestruct(const evmc::address& _addr, const evmc::address& _beneficiary) noexcept

View File

@ -54,7 +54,7 @@ public:
explicit EVMHost(langutil::EVMVersion _evmVersion, evmc::VM& _vm);
void reset() { accounts.clear(); m_currentAddress = {}; }
void reset();
void newBlock()
{
tx_context.block_number++;

View File

@ -0,0 +1,28 @@
contract C {
constructor() payable {}
function f() public returns (uint256 ret) {
assembly {
ret := balance(0)
}
}
function g() public returns (uint256 ret) {
assembly {
ret := balance(1)
}
}
function h() public returns (uint256 ret) {
assembly {
ret := balance(address())
}
}
}
// ====
// EVMVersion: >=constantinople
// compileViaYul: also
// ----
// constructor(), 23 wei ->
// f() -> 0
// g() -> 1
// h() -> 23

View File

@ -0,0 +1,25 @@
contract C {
function f() public returns (bytes32 ret) {
assembly {
ret := extcodehash(0)
}
}
function g() public returns (bytes32 ret) {
assembly {
ret := extcodehash(1)
}
}
function h() public returns (bool ret) {
assembly {
ret := iszero(iszero(extcodehash(address())))
}
}
}
// ====
// EVMVersion: >=constantinople
// compileViaYul: also
// ----
// f() -> 0
// g() -> 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
// h() -> true