From e3c7369413c3cde5c703b33a837ba6cd52fd301f Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Fri, 16 Sep 2022 12:57:29 +0200 Subject: [PATCH] EVMHost: Simplify some code and dcoument functions --- test/EVMHost.cpp | 7 +++++-- test/EVMHost.h | 16 +++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/test/EVMHost.cpp b/test/EVMHost.cpp index 118a517fb..dd487b67b 100644 --- a/test/EVMHost.cpp +++ b/test/EVMHost.cpp @@ -37,8 +37,6 @@ using namespace solidity::util; using namespace solidity::test; using namespace evmc::literals; -using StorageMap = std::map; - evmc::VM& EVMHost::getVM(string const& _path) { static evmc::VM NullVM{nullptr}; @@ -205,6 +203,8 @@ void EVMHost::recordCalls(evmc_message const& _message) noexcept recorded_calls.emplace_back(_message); } +// NOTE: this is used for both internal and external calls. +// External calls are triggered from ExecutionFramework and contain only EVMC_CREATE or EVMC_CALL. evmc::result EVMHost::call(evmc_message const& _message) noexcept { recordCalls(_message); @@ -408,6 +408,7 @@ evmc::result EVMHost::precompileSha256(evmc_message const& _message) noexcept )); evmc::result result({}); + result.status_code = EVMC_SUCCESS; result.gas_left = _message.gas; result.output_data = hash.data(); result.output_size = hash.size(); @@ -485,7 +486,9 @@ evmc::result EVMHost::precompileIdentity(evmc_message const& _message) noexcept // static data so that we do not need a release routine... bytes static data; data = bytes(_message.input_data, _message.input_data + _message.input_size); + evmc::result result({}); + result.status_code = EVMC_SUCCESS; result.gas_left = _message.gas; result.output_data = data.data(); result.output_size = data.size(); diff --git a/test/EVMHost.h b/test/EVMHost.h index bd085b7c5..e91f252ab 100644 --- a/test/EVMHost.h +++ b/test/EVMHost.h @@ -35,6 +35,7 @@ namespace solidity::test { using Address = util::h160; +using StorageMap = std::map; class EVMHost: public evmc::MockedHost { @@ -55,9 +56,10 @@ public: explicit EVMHost(langutil::EVMVersion _evmVersion, evmc::VM& _vm); + /// Reset entire state (including accounts). void reset(); - /// Clears EIP-2929 account and storage access indicator - void resetWarmAccess(); + + /// Start new block. void newBlock() { tx_context.block_number++; @@ -67,7 +69,7 @@ public: } /// @returns contents of storage at @param _addr. - std::map const& get_address_storage(evmc::address const& _addr); + StorageMap const& get_address_storage(evmc::address const& _addr); bool account_exists(evmc::address const& _addr) const noexcept final { @@ -94,8 +96,12 @@ public: private: evmc::address m_currentAddress = {}; + /// Transfer value between accounts. Checks for sufficient balance. void transfer(evmc::MockedAccount& _sender, evmc::MockedAccount& _recipient, u256 const& _value) noexcept; + /// Clears EIP-2929 account and storage access indicator + void resetWarmAccess(); + /// Records calls made via @param _message. void recordCalls(evmc_message const& _message) noexcept; @@ -113,9 +119,9 @@ private: static evmc::result resultWithGas(evmc_message const& _message, bytes const& _data) noexcept; evmc::VM& m_vm; - // EVM version requested by the testing tool + /// EVM version requested by the testing tool langutil::EVMVersion m_evmVersion; - // EVM version requested from EVMC (matches the above) + /// EVM version requested from EVMC (matches the above) evmc_revision m_evmRevision; };