mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
EVMHost: Simplify some code and dcoument functions
This commit is contained in:
parent
3ddf5db755
commit
e3c7369413
@ -37,8 +37,6 @@ using namespace solidity::util;
|
||||
using namespace solidity::test;
|
||||
using namespace evmc::literals;
|
||||
|
||||
using StorageMap = std::map<evmc::bytes32, evmc::storage_value>;
|
||||
|
||||
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();
|
||||
|
@ -35,6 +35,7 @@
|
||||
namespace solidity::test
|
||||
{
|
||||
using Address = util::h160;
|
||||
using StorageMap = std::map<evmc::bytes32, evmc::storage_value>;
|
||||
|
||||
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<evmc::bytes32, evmc::storage_value> 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;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user