EVMC
|
Mocked EVMC Host implementation. More...
#include <mocked_host.hpp>
Classes | |
struct | log_record |
LOG record. More... | |
Public Member Functions | |
bool | account_exists (const address &addr) const noexcept override |
Returns true if an account exists (EVMC Host method). | |
bytes32 | get_storage (const address &addr, const bytes32 &key) const noexcept override |
Get the account's storage value at the given key (EVMC Host method). | |
evmc_storage_status | set_storage (const address &addr, const bytes32 &key, const bytes32 &value) noexcept override |
Set the account's storage value (EVMC Host method). | |
uint256be | get_balance (const address &addr) const noexcept override |
Get the account's balance (EVMC Host method). | |
size_t | get_code_size (const address &addr) const noexcept override |
Get the account's code size (EVMC host method). | |
bytes32 | get_code_hash (const address &addr) const noexcept override |
Get the account's code hash (EVMC host method). | |
size_t | copy_code (const address &addr, size_t code_offset, uint8_t *buffer_data, size_t buffer_size) const noexcept override |
Copy the account's code to the given buffer (EVMC host method). | |
bool | selfdestruct (const address &addr, const address &beneficiary) noexcept override |
Selfdestruct the account (EVMC host method). | |
Result | call (const evmc_message &msg) noexcept override |
Call/create other contract (EVMC host method). | |
evmc_tx_context | get_tx_context () const noexcept override |
Get transaction context (EVMC host method). | |
bytes32 | get_block_hash (int64_t block_number) const noexcept override |
Get the block header hash (EVMC host method). | |
void | emit_log (const address &addr, const uint8_t *data, size_t data_size, const bytes32 topics[], size_t topics_count) noexcept override |
Emit LOG (EVMC host method). | |
evmc_access_status | access_account (const address &addr) noexcept override |
Record an account access. | |
evmc_access_status | access_storage (const address &addr, const bytes32 &key) noexcept override |
Access the account's storage value at the given key. | |
bytes32 | get_transient_storage (const address &addr, const bytes32 &key) const noexcept override |
Get account's transient storage. | |
void | set_transient_storage (const address &addr, const bytes32 &key, const bytes32 &value) noexcept override |
Set account's transient storage. | |
Public Member Functions inherited from evmc::Host | |
evmc_host_context * | to_context () noexcept |
Converts the Host object to the opaque host context pointer. | |
virtual bool | account_exists (const address &addr) const noexcept=0 |
Check account existence callback function. | |
virtual bytes32 | get_storage (const address &addr, const bytes32 &key) const noexcept=0 |
Get storage callback function. | |
virtual evmc_storage_status | set_storage (const address &addr, const bytes32 &key, const bytes32 &value) noexcept=0 |
Set storage callback function. | |
virtual uint256be | get_balance (const address &addr) const noexcept=0 |
Get balance callback function. | |
virtual size_t | get_code_size (const address &addr) const noexcept=0 |
Get code size callback function. | |
virtual bytes32 | get_code_hash (const address &addr) const noexcept=0 |
Get code hash callback function. | |
virtual size_t | copy_code (const address &addr, size_t code_offset, uint8_t *buffer_data, size_t buffer_size) const noexcept=0 |
Copy code callback function. | |
virtual bool | selfdestruct (const address &addr, const address &beneficiary) noexcept=0 |
Selfdestruct callback function. | |
virtual Result | call (const evmc_message &msg) noexcept=0 |
Call callback function. | |
virtual evmc_tx_context | get_tx_context () const noexcept=0 |
Get transaction context callback function. | |
virtual bytes32 | get_block_hash (int64_t block_number) const noexcept=0 |
Get block hash callback function. | |
virtual void | emit_log (const address &addr, const uint8_t *data, size_t data_size, const bytes32 topics[], size_t num_topics) noexcept=0 |
Emit log callback function. | |
virtual evmc_access_status | access_account (const address &addr) noexcept=0 |
Access account callback function. | |
virtual evmc_access_status | access_storage (const address &addr, const bytes32 &key) noexcept=0 |
Access storage callback function. | |
virtual bytes32 | get_transient_storage (const address &addr, const bytes32 &key) const noexcept=0 |
Get transient storage callback function. | |
virtual void | set_transient_storage (const address &addr, const bytes32 &key, const bytes32 &value) noexcept=0 |
Set transient storage callback function. | |
Public Attributes | |
std::unordered_map< address, MockedAccount > | accounts |
The set of all accounts in the Host, organized by their addresses. | |
evmc_tx_context | tx_context = {} |
The EVMC transaction context to be returned by get_tx_context(). | |
bytes32 | block_hash = {} |
The block header hash value to be returned by get_block_hash(). | |
evmc_result | call_result = {} |
The call result to be returned by the call() method. | |
std::vector< int64_t > | recorded_blockhashes |
The record of all block numbers for which get_block_hash() was called. | |
std::vector< address > | recorded_account_accesses |
The record of all account accesses. | |
std::vector< evmc_message > | recorded_calls |
The record of all call messages requested in the call() method. | |
std::vector< log_record > | recorded_logs |
The record of all LOGs passed to the emit_log() method. | |
std::unordered_map< address, std::vector< address > > | recorded_selfdestructs |
The record of all SELFDESTRUCTs from the selfdestruct() method as a map selfdestructed_address => [beneficiary1, beneficiary2, ...]. | |
Static Public Attributes | |
static constexpr auto | max_recorded_account_accesses = 200 |
The maximum number of entries in recorded_account_accesses record. | |
static constexpr auto | max_recorded_calls = 100 |
The maximum number of entries in recorded_calls record. | |
Additional Inherited Members | |
Static Public Member Functions inherited from evmc::Host | |
static const evmc_host_interface & | get_interface () noexcept |
Provides access to the global host interface. | |
template<typename DerivedClass = Host> | |
static DerivedClass * | from_context (evmc_host_context *context) noexcept |
Converts the opaque host context pointer back to the original Host object. | |
Mocked EVMC Host implementation.
Definition at line 75 of file mocked_host.hpp.
|
inlineoverridevirtualnoexcept |
Record an account access.
This method is required by EIP-2929 introduced in EVMC_BERLIN. It will record the account access in MockedHost::recorded_account_accesses and return previous access status. This methods returns EVMC_ACCESS_WARM for known addresses of precompiles. The EIP-2929 specifies that evmc_message::sender and evmc_message::recipient are always EVMC_ACCESS_WARM. Therefore, you should init the MockedHost with:
mocked_host.access_account(msg.sender); mocked_host.access_account(msg.recipient);
The same way you can mock transaction access list (EIP-2930) for account addresses.
addr | The address of the accessed account. |
Implements evmc::HostInterface.
Definition at line 440 of file mocked_host.hpp.
|
inlineoverridevirtualnoexcept |
Access the account's storage value at the given key.
This method is required by EIP-2929 introduced in EVMC_BERLIN. In records that the given account's storage key has been access and returns the previous access status. To mock storage access list (EIP-2930), you can pre-init account's storage values with the EVMC_ACCESS_WARM flag:
mocked_host.accounts[msg.recipient].storage[key] = {value, EVMC_ACCESS_WARM};
addr | The account address. |
key | The account's storage key. |
Implements evmc::HostInterface.
Definition at line 471 of file mocked_host.hpp.
|
inlineoverridevirtualnoexcept |
Returns true if an account exists (EVMC Host method).
Implements evmc::HostInterface.
Definition at line 150 of file mocked_host.hpp.
|
inlineoverridevirtualnoexcept |
Call/create other contract (EVMC host method).
Implements evmc::HostInterface.
Definition at line 380 of file mocked_host.hpp.
|
inlineoverridevirtualnoexcept |
Copy the account's code to the given buffer (EVMC host method).
Implements evmc::HostInterface.
Definition at line 348 of file mocked_host.hpp.
|
inlineoverridevirtualnoexcept |
Emit LOG (EVMC host method).
Implements evmc::HostInterface.
Definition at line 415 of file mocked_host.hpp.
Get the account's balance (EVMC Host method).
Implements evmc::HostInterface.
Definition at line 317 of file mocked_host.hpp.
|
inlineoverridevirtualnoexcept |
Get the block header hash (EVMC host method).
Implements evmc::HostInterface.
Definition at line 408 of file mocked_host.hpp.
Get the account's code hash (EVMC host method).
Implements evmc::HostInterface.
Definition at line 338 of file mocked_host.hpp.
|
inlineoverridevirtualnoexcept |
Get the account's code size (EVMC host method).
Implements evmc::HostInterface.
Definition at line 328 of file mocked_host.hpp.
|
inlineoverridevirtualnoexcept |
Get the account's storage value at the given key (EVMC Host method).
Implements evmc::HostInterface.
Definition at line 157 of file mocked_host.hpp.
|
inlineoverridevirtualnoexcept |
Get account's transient storage.
addr | The account address. |
key | The account's transient storage key. |
Implements evmc::HostInterface.
Definition at line 484 of file mocked_host.hpp.
|
inlineoverridevirtualnoexcept |
Get transaction context (EVMC host method).
Implements evmc::HostInterface.
Definition at line 405 of file mocked_host.hpp.
|
inlineoverridevirtualnoexcept |
Selfdestruct the account (EVMC host method).
Implements evmc::HostInterface.
Definition at line 371 of file mocked_host.hpp.
|
inlineoverridevirtualnoexcept |
Set the account's storage value (EVMC Host method).
Implements evmc::HostInterface.
Definition at line 172 of file mocked_host.hpp.
|
inlineoverridevirtualnoexcept |
Set account's transient storage.
addr | The account address. |
key | The account's transient storage key. |
value | The value to be stored. |
Implements evmc::HostInterface.
Definition at line 503 of file mocked_host.hpp.
std::unordered_map<address, MockedAccount> evmc::MockedHost::accounts |
The set of all accounts in the Host, organized by their addresses.
Definition at line 98 of file mocked_host.hpp.
bytes32 evmc::MockedHost::block_hash = {} |
The block header hash value to be returned by get_block_hash().
Definition at line 104 of file mocked_host.hpp.
evmc_result evmc::MockedHost::call_result = {} |
The call result to be returned by the call() method.
Definition at line 107 of file mocked_host.hpp.
|
staticconstexpr |
The maximum number of entries in recorded_account_accesses record.
This is arbitrary value useful in fuzzing when we don't want the record to explode.
Definition at line 117 of file mocked_host.hpp.
|
staticconstexpr |
The maximum number of entries in recorded_calls record.
This is arbitrary value useful in fuzzing when we don't want the record to explode.
Definition at line 124 of file mocked_host.hpp.
|
mutable |
The record of all account accesses.
Definition at line 113 of file mocked_host.hpp.
|
mutable |
The record of all block numbers for which get_block_hash() was called.
Definition at line 110 of file mocked_host.hpp.
std::vector<evmc_message> evmc::MockedHost::recorded_calls |
The record of all call messages requested in the call() method.
Definition at line 120 of file mocked_host.hpp.
std::vector<log_record> evmc::MockedHost::recorded_logs |
The record of all LOGs passed to the emit_log() method.
Definition at line 127 of file mocked_host.hpp.
The record of all SELFDESTRUCTs from the selfdestruct() method as a map selfdestructed_address => [beneficiary1, beneficiary2, ...].
Definition at line 131 of file mocked_host.hpp.
evmc_tx_context evmc::MockedHost::tx_context = {} |
The EVMC transaction context to be returned by get_tx_context().
Definition at line 101 of file mocked_host.hpp.