diff --git a/test/EVMHost.cpp b/test/EVMHost.cpp index e2dd7bf17..779e9e000 100644 --- a/test/EVMHost.cpp +++ b/test/EVMHost.cpp @@ -86,6 +86,20 @@ EVMHost::EVMHost(langutil::EVMVersion _evmVersion, evmc::VM& _vm): assertThrow(false, Exception, "Berlin is not supported yet."); else //if (_evmVersion == langutil::EVMVersion::petersburg()) m_evmRevision = EVMC_PETERSBURG; + + // 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. + // + // A lot of precompile addresses had a balance before they became valid addresses for precompiles. + // For example all the precompile addresses allocated in Byzantium had a 1 wei balance sent to them + // roughly 22 days before the update went live. + for (unsigned precompiledAddress = 1; precompiledAddress <= 8; precompiledAddress++) + { + evmc::address address{}; + address.bytes[19] = precompiledAddress; + // 1wei + m_state.accounts[address].balance.bytes[31] = 1; + } } evmc_storage_status EVMHost::set_storage(const evmc::address& _addr, const evmc::bytes32& _key, const evmc::bytes32& _value) noexcept diff --git a/test/EVMHost.h b/test/EVMHost.h index edef88d01..4cbb045f0 100644 --- a/test/EVMHost.h +++ b/test/EVMHost.h @@ -70,10 +70,6 @@ public: Account* account(evmc::address const& _address) { - // Make all precompiled contracts exist. - // Be future-proof and consider everything below 1024 as precompiled contract. - if (u160(convertFromEVMC(_address)) < 1024) - m_state.accounts[_address]; auto it = m_state.accounts.find(_address); return it == m_state.accounts.end() ? nullptr : &it->second; }