From 5ba077a3847cd4077bd309c57d25bc909d624897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 20 Sep 2019 11:29:46 +0200 Subject: [PATCH] Rename evmc_context to evmc_host_context --- bindings/go/evmc/evmc.go | 2 +- bindings/go/evmc/host.c | 2 +- bindings/go/evmc/host.go | 2 +- bindings/rust/evmc-declare/src/lib.rs | 2 +- bindings/rust/evmc-vm/src/container.rs | 4 +- bindings/rust/evmc-vm/src/lib.rs | 43 ++++----- docs/Host_Guide.md | 4 +- examples/example.c | 2 +- examples/example_host.cpp | 4 +- examples/example_host.h | 4 +- .../example_precompiles_vm.cpp | 2 +- examples/example_vm/example_vm.c | 2 +- include/evmc/evmc.h | 92 +++++++++---------- include/evmc/evmc.hpp | 40 ++++---- include/evmc/helpers.h | 2 +- test/unittests/test_cpp.cpp | 2 +- test/vmtester/tests.cpp | 4 +- 17 files changed, 106 insertions(+), 107 deletions(-) diff --git a/bindings/go/evmc/evmc.go b/bindings/go/evmc/evmc.go index 318f36d..6fa0727 100644 --- a/bindings/go/evmc/evmc.go +++ b/bindings/go/evmc/evmc.go @@ -25,7 +25,7 @@ static inline enum evmc_set_option_result set_option(struct evmc_instance* insta struct extended_context { - struct evmc_context context; + struct evmc_host_context context; int64_t index; }; diff --git a/bindings/go/evmc/host.c b/bindings/go/evmc/host.c index fdfd1a2..3d0b55a 100644 --- a/bindings/go/evmc/host.c +++ b/bindings/go/evmc/host.c @@ -32,7 +32,7 @@ const struct evmc_host_interface evmc_go_host = { #pragma GCC diagnostic error "-Wconversion" static inline void go_exported_functions_type_checks() { - struct evmc_context* context = NULL; + struct evmc_host_context* context = NULL; evmc_address* address = NULL; evmc_bytes32 bytes32; uint8_t* data = NULL; diff --git a/bindings/go/evmc/host.go b/bindings/go/evmc/host.go index a9b4696..3b1ee97 100644 --- a/bindings/go/evmc/host.go +++ b/bindings/go/evmc/host.go @@ -12,7 +12,7 @@ package evmc struct extended_context { - struct evmc_context context; + struct evmc_host_context context; int64_t index; }; diff --git a/bindings/rust/evmc-declare/src/lib.rs b/bindings/rust/evmc-declare/src/lib.rs index 7a64d2e..6a4a422 100644 --- a/bindings/rust/evmc-declare/src/lib.rs +++ b/bindings/rust/evmc-declare/src/lib.rs @@ -336,7 +336,7 @@ fn build_execute_fn(names: &VMNameSet) -> proc_macro2::TokenStream { quote! { extern "C" fn __evmc_execute( instance: *mut ::evmc_vm::ffi::evmc_instance, - context: *mut ::evmc_vm::ffi::evmc_context, + context: *mut ::evmc_vm::ffi::evmc_host_context, revision: ::evmc_vm::ffi::evmc_revision, msg: *const ::evmc_vm::ffi::evmc_message, code: *const u8, diff --git a/bindings/rust/evmc-vm/src/container.rs b/bindings/rust/evmc-vm/src/container.rs index 602f4d6..0c618f8 100644 --- a/bindings/rust/evmc-vm/src/container.rs +++ b/bindings/rust/evmc-vm/src/container.rs @@ -75,7 +75,7 @@ mod tests { } unsafe extern "C" fn get_dummy_tx_context( - _context: *mut evmc_sys::evmc_context, + _context: *mut evmc_sys::evmc_host_context, ) -> evmc_sys::evmc_tx_context { evmc_sys::evmc_tx_context { tx_gas_price: Uint256::default(), @@ -132,7 +132,7 @@ mod tests { get_block_hash: None, emit_log: None, }; - let mut backing_context = ::evmc_sys::evmc_context { host: &host }; + let mut backing_context = ::evmc_sys::evmc_host_context { host: &host }; let mut context = ExecutionContext::new(&mut backing_context); let container = EvmcContainer::::new(instance); diff --git a/bindings/rust/evmc-vm/src/lib.rs b/bindings/rust/evmc-vm/src/lib.rs index 57fbb77..a13c067 100644 --- a/bindings/rust/evmc-vm/src/lib.rs +++ b/bindings/rust/evmc-vm/src/lib.rs @@ -58,7 +58,7 @@ pub type ExecutionTxContext = ffi::evmc_tx_context; /// EVMC context structure. Exposes the EVMC host functions, message data, and transaction context /// to the executing VM. pub struct ExecutionContext<'a> { - context: &'a mut ffi::evmc_context, + context: &'a mut ffi::evmc_host_context, tx_context: ExecutionTxContext, } @@ -194,11 +194,11 @@ impl ExecutionMessage { } impl<'a> ExecutionContext<'a> { - pub fn new(_context: &'a mut ffi::evmc_context) -> Self { + pub fn new(_context: &'a mut ffi::evmc_host_context) -> Self { assert!(_context.host != std::ptr::null()); let _tx_context = unsafe { assert!((*(_context.host)).get_tx_context.is_some()); - (*(_context.host)).get_tx_context.unwrap()(_context as *mut ffi::evmc_context) + (*(_context.host)).get_tx_context.unwrap()(_context as *mut ffi::evmc_host_context) }; ExecutionContext { @@ -217,7 +217,7 @@ impl<'a> ExecutionContext<'a> { unsafe { assert!((*self.context.host).account_exists.is_some()); (*self.context.host).account_exists.unwrap()( - self.context as *mut ffi::evmc_context, + self.context as *mut ffi::evmc_host_context, address as *const Address, ) } @@ -228,7 +228,7 @@ impl<'a> ExecutionContext<'a> { unsafe { assert!((*self.context.host).get_storage.is_some()); (*self.context.host).get_storage.unwrap()( - self.context as *mut ffi::evmc_context, + self.context as *mut ffi::evmc_host_context, address as *const Address, key as *const Bytes32, ) @@ -245,7 +245,7 @@ impl<'a> ExecutionContext<'a> { unsafe { assert!((*self.context.host).set_storage.is_some()); (*self.context.host).set_storage.unwrap()( - self.context as *mut ffi::evmc_context, + self.context as *mut ffi::evmc_host_context, address as *const Address, key as *const Bytes32, value as *const Bytes32, @@ -258,7 +258,7 @@ impl<'a> ExecutionContext<'a> { unsafe { assert!((*self.context.host).get_balance.is_some()); (*self.context.host).get_balance.unwrap()( - self.context as *mut ffi::evmc_context, + self.context as *mut ffi::evmc_host_context, address as *const Address, ) } @@ -269,7 +269,7 @@ impl<'a> ExecutionContext<'a> { unsafe { assert!((*self.context.host).get_code_size.is_some()); (*self.context.host).get_code_size.unwrap()( - self.context as *mut ffi::evmc_context, + self.context as *mut ffi::evmc_host_context, address as *const Address, ) } @@ -280,7 +280,7 @@ impl<'a> ExecutionContext<'a> { unsafe { assert!((*self.context.host).get_code_size.is_some()); (*self.context.host).get_code_hash.unwrap()( - self.context as *mut ffi::evmc_context, + self.context as *mut ffi::evmc_host_context, address as *const Address, ) } @@ -291,7 +291,7 @@ impl<'a> ExecutionContext<'a> { unsafe { assert!((*self.context.host).copy_code.is_some()); (*self.context.host).copy_code.unwrap()( - self.context as *mut ffi::evmc_context, + self.context as *mut ffi::evmc_host_context, address as *const Address, code_offset, // FIXME: ensure that alignment of the array elements is OK @@ -306,7 +306,7 @@ impl<'a> ExecutionContext<'a> { unsafe { assert!((*self.context.host).selfdestruct.is_some()); (*self.context.host).selfdestruct.unwrap()( - self.context as *mut ffi::evmc_context, + self.context as *mut ffi::evmc_host_context, address as *const Address, beneficiary as *const Address, ) @@ -345,7 +345,7 @@ impl<'a> ExecutionContext<'a> { unsafe { assert!((*self.context.host).call.is_some()); (*self.context.host).call.unwrap()( - self.context as *mut ffi::evmc_context, + self.context as *mut ffi::evmc_host_context, &message as *const ffi::evmc_message, ) .into() @@ -357,7 +357,7 @@ impl<'a> ExecutionContext<'a> { unsafe { assert!((*self.context.host).get_block_hash.is_some()); (*self.context.host).get_block_hash.unwrap()( - self.context as *mut ffi::evmc_context, + self.context as *mut ffi::evmc_host_context, num, ) } @@ -368,7 +368,7 @@ impl<'a> ExecutionContext<'a> { unsafe { assert!((*self.context.host).emit_log.is_some()); (*self.context.host).emit_log.unwrap()( - self.context as *mut ffi::evmc_context, + self.context as *mut ffi::evmc_host_context, address as *const Address, // FIXME: ensure that alignment of the array elements is OK data.as_ptr(), @@ -749,7 +749,7 @@ mod tests { } unsafe extern "C" fn get_dummy_tx_context( - _context: *mut ffi::evmc_context, + _context: *mut ffi::evmc_host_context, ) -> ffi::evmc_tx_context { ffi::evmc_tx_context { tx_gas_price: Uint256 { bytes: [0u8; 32] }, @@ -764,14 +764,14 @@ mod tests { } unsafe extern "C" fn get_dummy_code_size( - _context: *mut ffi::evmc_context, + _context: *mut ffi::evmc_host_context, _addr: *const Address, ) -> usize { 105023 as usize } unsafe extern "C" fn execute_call( - _context: *mut ffi::evmc_context, + _context: *mut ffi::evmc_host_context, _msg: *const ffi::evmc_message, ) -> ffi::evmc_result { // Some dumb validation for testing. @@ -801,8 +801,8 @@ mod tests { } // Update these when needed for tests - fn get_dummy_context() -> ffi::evmc_context { - ffi::evmc_context { + fn get_dummy_context() -> ffi::evmc_host_context { + ffi::evmc_host_context { host: Box::into_raw(Box::new(ffi::evmc_host_interface { account_exists: None, get_storage: None, @@ -822,7 +822,7 @@ mod tests { // Helper to safely dispose of the dummy context, and not bring up false positives in the // sanitizers. - fn dummy_context_dispose(context: ffi::evmc_context) { + fn dummy_context_dispose(context: ffi::evmc_host_context) { unsafe { Box::from_raw(context.host as *mut ffi::evmc_host_interface); } @@ -838,7 +838,8 @@ mod tests { let exe_context = ExecutionContext::new(&mut context_raw); let a = exe_context.get_tx_context(); - let b = unsafe { get_dummy_tx_context(&mut context_raw_copy as *mut ffi::evmc_context) }; + let b = + unsafe { get_dummy_tx_context(&mut context_raw_copy as *mut ffi::evmc_host_context) }; assert_eq!(a.block_gas_limit, b.block_gas_limit); assert_eq!(a.block_timestamp, b.block_timestamp); diff --git a/docs/Host_Guide.md b/docs/Host_Guide.md index cdd0266..d669374 100644 --- a/docs/Host_Guide.md +++ b/docs/Host_Guide.md @@ -10,7 +10,7 @@ allows VMs to query and modify Ethereum state during the execution. The implementation can be done in object-oriented manner. The ::evmc_host_interface lists the methods any Host must implement. -Moreover, each of the methods has a pointer to ::evmc_context +Moreover, each of the methods has a pointer to ::evmc_host_context as a parameter. The context is owned entirely by the Host allowing a Host instance to behave as an object with data. @@ -35,7 +35,7 @@ When Host implementation is ready it's time to start using EVMC VMs. You will need: - the code to execute, - the message (::evmc_message) object that describes the execution context, - - the Host instance, passed as ::evmc_context pointer. + - the Host instance, passed as ::evmc_host_context pointer. 5. When execution finishes you will receive ::evmc_result object that describes the results of the execution. diff --git a/examples/example.c b/examples/example.c index 720751c..d71f4fe 100644 --- a/examples/example.c +++ b/examples/example.c @@ -48,7 +48,7 @@ int main(int argc, char* argv[]) tx_context.block_number = 42; tx_context.block_timestamp = 66; tx_context.block_gas_limit = gas * 2; - struct evmc_context* ctx = example_host_create_context(tx_context); + struct evmc_host_context* ctx = example_host_create_context(tx_context); struct evmc_message msg; msg.kind = EVMC_CALL; msg.sender = addr; diff --git a/examples/example_host.cpp b/examples/example_host.cpp index ec7dedd..074a328 100644 --- a/examples/example_host.cpp +++ b/examples/example_host.cpp @@ -130,12 +130,12 @@ public: extern "C" { -evmc_context* example_host_create_context(evmc_tx_context tx_context) +evmc_host_context* example_host_create_context(evmc_tx_context tx_context) { return new ExampleHost(tx_context); } -void example_host_destroy_context(evmc_context* context) +void example_host_destroy_context(evmc_host_context* context) { delete static_cast(context); } diff --git a/examples/example_host.h b/examples/example_host.h index 1a15e66..6c54920 100644 --- a/examples/example_host.h +++ b/examples/example_host.h @@ -9,9 +9,9 @@ extern "C" { #endif -struct evmc_context* example_host_create_context(struct evmc_tx_context tx_context); +struct evmc_host_context* example_host_create_context(struct evmc_tx_context tx_context); -void example_host_destroy_context(struct evmc_context* context); +void example_host_destroy_context(struct evmc_host_context* context); #if __cplusplus } diff --git a/examples/example_precompiles_vm/example_precompiles_vm.cpp b/examples/example_precompiles_vm/example_precompiles_vm.cpp index e03737c..2335e8c 100644 --- a/examples/example_precompiles_vm/example_precompiles_vm.cpp +++ b/examples/example_precompiles_vm/example_precompiles_vm.cpp @@ -49,7 +49,7 @@ static evmc_result not_implemented() } static evmc_result execute(evmc_instance*, - evmc_context*, + evmc_host_context*, enum evmc_revision rev, const evmc_message* msg, const uint8_t*, diff --git a/examples/example_vm/example_vm.c b/examples/example_vm/example_vm.c index 6e5eeaa..5bde510 100644 --- a/examples/example_vm/example_vm.c +++ b/examples/example_vm/example_vm.c @@ -75,7 +75,7 @@ static void free_result_output_data(const struct evmc_result* result) /// The example implementation of the evmc_instance::execute() method. static struct evmc_result execute(struct evmc_instance* instance, - struct evmc_context* context, + struct evmc_host_context* context, enum evmc_revision rev, const struct evmc_message* msg, const uint8_t* code, diff --git a/include/evmc/evmc.h b/include/evmc/evmc.h index e408391..4e1e0d8 100644 --- a/include/evmc/evmc.h +++ b/include/evmc/evmc.h @@ -156,7 +156,7 @@ struct evmc_tx_context evmc_uint256be chain_id; /**< The blockchain's ChainID. */ }; -struct evmc_context; +struct evmc_host_context; /** * Get transaction context callback function. @@ -167,7 +167,7 @@ struct evmc_context; * @param context The pointer to the Host execution context. * @return The transaction context. */ -typedef struct evmc_tx_context (*evmc_get_tx_context_fn)(struct evmc_context* context); +typedef struct evmc_tx_context (*evmc_get_tx_context_fn)(struct evmc_host_context* context); /** * Get block hash callback function. @@ -181,7 +181,7 @@ typedef struct evmc_tx_context (*evmc_get_tx_context_fn)(struct evmc_context* co * @return The block hash or null bytes * if the information about the block is not available. */ -typedef evmc_bytes32 (*evmc_get_block_hash_fn)(struct evmc_context* context, int64_t number); +typedef evmc_bytes32 (*evmc_get_block_hash_fn)(struct evmc_host_context* context, int64_t number); /** * The execution status code. @@ -421,7 +421,8 @@ struct evmc_result * @param address The address of the account the query is about. * @return true if exists, false otherwise. */ -typedef bool (*evmc_account_exists_fn)(struct evmc_context* context, const evmc_address* address); +typedef bool (*evmc_account_exists_fn)(struct evmc_host_context* context, + const evmc_address* address); /** * Get storage callback function. @@ -434,7 +435,7 @@ typedef bool (*evmc_account_exists_fn)(struct evmc_context* context, const evmc_ * @return The storage value at the given storage key or null bytes * if the account does not exist. */ -typedef evmc_bytes32 (*evmc_get_storage_fn)(struct evmc_context* context, +typedef evmc_bytes32 (*evmc_get_storage_fn)(struct evmc_host_context* context, const evmc_address* address, const evmc_bytes32* key); @@ -493,7 +494,7 @@ enum evmc_storage_status * @param value The value to be stored. * @return The effect on the storage item. */ -typedef enum evmc_storage_status (*evmc_set_storage_fn)(struct evmc_context* context, +typedef enum evmc_storage_status (*evmc_set_storage_fn)(struct evmc_host_context* context, const evmc_address* address, const evmc_bytes32* key, const evmc_bytes32* value); @@ -507,7 +508,7 @@ typedef enum evmc_storage_status (*evmc_set_storage_fn)(struct evmc_context* con * @param address The address of the account. * @return The balance of the given account or 0 if the account does not exist. */ -typedef evmc_uint256be (*evmc_get_balance_fn)(struct evmc_context* context, +typedef evmc_uint256be (*evmc_get_balance_fn)(struct evmc_host_context* context, const evmc_address* address); /** @@ -520,7 +521,8 @@ typedef evmc_uint256be (*evmc_get_balance_fn)(struct evmc_context* context, * @param address The address of the account. * @return The size of the code in the account or 0 if the account does not exist. */ -typedef size_t (*evmc_get_code_size_fn)(struct evmc_context* context, const evmc_address* address); +typedef size_t (*evmc_get_code_size_fn)(struct evmc_host_context* context, + const evmc_address* address); /** * Get code size callback function. @@ -533,28 +535,27 @@ typedef size_t (*evmc_get_code_size_fn)(struct evmc_context* context, const evmc * @param address The address of the account. * @return The hash of the code in the account or null bytes if the account does not exist. */ -typedef evmc_bytes32 (*evmc_get_code_hash_fn)(struct evmc_context* context, +typedef evmc_bytes32 (*evmc_get_code_hash_fn)(struct evmc_host_context* context, const evmc_address* address); /** * Copy code callback function. * - * This callback function is used by an EVM to request a copy of the code - * of the given account to the memory buffer provided by the EVM. - * The Client MUST copy the requested code, starting with the given offset, - * to the provided memory buffer up to the size of the buffer or the size of - * the code, whichever is smaller. + * This callback function is used by an EVM to request a copy of the code + * of the given account to the memory buffer provided by the EVM. + * The Client MUST copy the requested code, starting with the given offset, + * to the provided memory buffer up to the size of the buffer or the size of + * the code, whichever is smaller. * - * @param context The pointer to the Client execution context. - * @see ::evmc_context. - * @param address The address of the account. - * @param code_offset The offset of the code to copy. - * @param buffer_data The pointer to the memory buffer allocated by the EVM - * to store a copy of the requested code. - * @param buffer_size The size of the memory buffer. - * @return The number of bytes copied to the buffer by the Client. + * @param context The pointer to the Host execution context. See ::evmc_host_context. + * @param address The address of the account. + * @param code_offset The offset of the code to copy. + * @param buffer_data The pointer to the memory buffer allocated by the EVM + * to store a copy of the requested code. + * @param buffer_size The size of the memory buffer. + * @return The number of bytes copied to the buffer by the Client. */ -typedef size_t (*evmc_copy_code_fn)(struct evmc_context* context, +typedef size_t (*evmc_copy_code_fn)(struct evmc_host_context* context, const evmc_address* address, size_t code_offset, uint8_t* buffer_data, @@ -563,34 +564,31 @@ typedef size_t (*evmc_copy_code_fn)(struct evmc_context* context, /** * Selfdestruct callback function. * - * This callback function is used by an EVM to SELFDESTRUCT given contract. - * The execution of the contract will not be stopped, that is up to the EVM. + * This callback function is used by an EVM to SELFDESTRUCT given contract. + * The execution of the contract will not be stopped, that is up to the EVM. * - * @param context The pointer to the Host execution context. - * @see ::evmc_context. - * @param address The address of the contract to be selfdestructed. - * @param beneficiary The address where the remaining ETH is going to be - * transferred. + * @param context The pointer to the Host execution context. See ::evmc_host_context. + * @param address The address of the contract to be selfdestructed. + * @param beneficiary The address where the remaining ETH is going to be transferred. */ -typedef void (*evmc_selfdestruct_fn)(struct evmc_context* context, +typedef void (*evmc_selfdestruct_fn)(struct evmc_host_context* context, const evmc_address* address, const evmc_address* beneficiary); /** * Log callback function. * - * This callback function is used by an EVM to inform about a LOG that happened - * during an EVM bytecode execution. - * @param context The pointer to the Host execution context. - * @see ::evmc_context. - * @param address The address of the contract that generated the log. - * @param data The pointer to unindexed data attached to the log. - * @param data_size The length of the data. - * @param topics The pointer to the array of topics attached to the log. - * @param topics_count The number of the topics. Valid values are between - * 0 and 4 inclusively. + * This callback function is used by an EVM to inform about a LOG that happened + * during an EVM bytecode execution. + * + * @param context The pointer to the Host execution context. See ::evmc_host_context. + * @param address The address of the contract that generated the log. + * @param data The pointer to unindexed data attached to the log. + * @param data_size The length of the data. + * @param topics The pointer to the array of topics attached to the log. + * @param topics_count The number of the topics. Valid values are between 0 and 4 inclusively. */ -typedef void (*evmc_emit_log_fn)(struct evmc_context* context, +typedef void (*evmc_emit_log_fn)(struct evmc_host_context* context, const evmc_address* address, const uint8_t* data, size_t data_size, @@ -600,11 +598,11 @@ typedef void (*evmc_emit_log_fn)(struct evmc_context* context, /** * Pointer to the callback function supporting EVM calls. * - * @param context The pointer to the Host execution context. - * @param msg The call parameters. + * @param context The pointer to the Host execution context. + * @param msg The call parameters. * @return The result of the call. */ -typedef struct evmc_result (*evmc_call_fn)(struct evmc_context* context, +typedef struct evmc_result (*evmc_call_fn)(struct evmc_host_context* context, const struct evmc_message* msg); /** @@ -664,7 +662,7 @@ struct evmc_host_interface * the context callback interface. * Optionally, the Host MAY include in the context additional data. */ -struct evmc_context +struct evmc_host_context { /** The Host interface. */ const struct evmc_host_interface* host; @@ -804,7 +802,7 @@ enum evmc_revision * @return The execution result. */ typedef struct evmc_result (*evmc_execute_fn)(struct evmc_instance* instance, - struct evmc_context* context, + struct evmc_host_context* context, enum evmc_revision rev, const struct evmc_message* msg, uint8_t const* code, diff --git a/include/evmc/evmc.hpp b/include/evmc/evmc.hpp index 31e4e3c..dfa30ab 100644 --- a/include/evmc/evmc.hpp +++ b/include/evmc/evmc.hpp @@ -398,7 +398,7 @@ public: } /// @copydoc evmc_execute() - result execute(evmc_context& ctx, + result execute(evmc_host_context& ctx, evmc_revision rev, const evmc_message& msg, const uint8_t* code, @@ -475,15 +475,15 @@ public: /// Wrapper around EVMC host context / host interface. /// -/// To be used by VM implementations as better alternative to using ::evmc_context directly. +/// To be used by VM implementations as better alternative to using ::evmc_host_context directly. class HostContext : public HostInterface { - evmc_context* context = nullptr; + evmc_host_context* context = nullptr; evmc_tx_context tx_context = {}; public: - /// Implicit converting constructor from evmc_context. - HostContext(evmc_context* ctx) noexcept : context{ctx} {} // NOLINT + /// Implicit converting constructor from evmc_host_context. + HostContext(evmc_host_context* ctx) noexcept : context{ctx} {} // NOLINT bool account_exists(const address& address) noexcept final { @@ -567,8 +567,8 @@ public: /// /// When implementing EVMC Host, you can directly inherit from the evmc::Host class. /// This way your implementation will be simpler by avoiding manual handling -/// of the ::evmc_context and the ::evmc_context::host. -class Host : public HostInterface, public evmc_context +/// of the ::evmc_host_context and the ::evmc_host_context::host. +class Host : public HostInterface, public evmc_host_context { public: inline Host() noexcept; @@ -576,36 +576,36 @@ public: namespace internal { -inline bool account_exists(evmc_context* h, const evmc_address* addr) noexcept +inline bool account_exists(evmc_host_context* h, const evmc_address* addr) noexcept { return static_cast(h)->account_exists(*addr); } -inline evmc_bytes32 get_storage(evmc_context* h, +inline evmc_bytes32 get_storage(evmc_host_context* h, const evmc_address* addr, const evmc_bytes32* key) noexcept { return static_cast(h)->get_storage(*addr, *key); } -inline evmc_storage_status set_storage(evmc_context* h, +inline evmc_storage_status set_storage(evmc_host_context* h, const evmc_address* addr, const evmc_bytes32* key, const evmc_bytes32* value) noexcept { return static_cast(h)->set_storage(*addr, *key, *value); } -inline evmc_uint256be get_balance(evmc_context* h, const evmc_address* addr) noexcept +inline evmc_uint256be get_balance(evmc_host_context* h, const evmc_address* addr) noexcept { return static_cast(h)->get_balance(*addr); } -inline size_t get_code_size(evmc_context* h, const evmc_address* addr) noexcept +inline size_t get_code_size(evmc_host_context* h, const evmc_address* addr) noexcept { return static_cast(h)->get_code_size(*addr); } -inline evmc_bytes32 get_code_hash(evmc_context* h, const evmc_address* addr) noexcept +inline evmc_bytes32 get_code_hash(evmc_host_context* h, const evmc_address* addr) noexcept { return static_cast(h)->get_code_hash(*addr); } -inline size_t copy_code(evmc_context* h, +inline size_t copy_code(evmc_host_context* h, const evmc_address* addr, size_t code_offset, uint8_t* buffer_data, @@ -613,25 +613,25 @@ inline size_t copy_code(evmc_context* h, { return static_cast(h)->copy_code(*addr, code_offset, buffer_data, buffer_size); } -inline void selfdestruct(evmc_context* h, +inline void selfdestruct(evmc_host_context* h, const evmc_address* addr, const evmc_address* beneficiary) noexcept { static_cast(h)->selfdestruct(*addr, *beneficiary); } -inline evmc_result call(evmc_context* h, const evmc_message* msg) noexcept +inline evmc_result call(evmc_host_context* h, const evmc_message* msg) noexcept { return static_cast(h)->call(*msg).release_raw(); } -inline evmc_tx_context get_tx_context(evmc_context* h) noexcept +inline evmc_tx_context get_tx_context(evmc_host_context* h) noexcept { return static_cast(h)->get_tx_context(); } -inline evmc_bytes32 get_block_hash(evmc_context* h, int64_t block_number) noexcept +inline evmc_bytes32 get_block_hash(evmc_host_context* h, int64_t block_number) noexcept { return static_cast(h)->get_block_hash(block_number); } -inline void emit_log(evmc_context* h, +inline void emit_log(evmc_host_context* h, const evmc_address* addr, const uint8_t* data, size_t data_size, @@ -647,7 +647,7 @@ constexpr evmc_host_interface interface{ copy_code, selfdestruct, call, get_tx_context, get_block_hash, emit_log}; } // namespace internal -inline Host::Host() noexcept : evmc_context{&evmc::internal::interface} {} +inline Host::Host() noexcept : evmc_host_context{&evmc::internal::interface} {} } // namespace evmc diff --git a/include/evmc/helpers.h b/include/evmc/helpers.h index 2c4dbce..0cb32c2 100644 --- a/include/evmc/helpers.h +++ b/include/evmc/helpers.h @@ -100,7 +100,7 @@ static inline void evmc_set_tracer(struct evmc_instance* instance, * @see evmc_execute_fn. */ static inline struct evmc_result evmc_execute(struct evmc_instance* instance, - struct evmc_context* context, + struct evmc_host_context* context, enum evmc_revision rev, const struct evmc_message* msg, uint8_t const* code, diff --git a/test/unittests/test_cpp.cpp b/test/unittests/test_cpp.cpp index b5a19e8..1b5e2f6 100644 --- a/test/unittests/test_cpp.cpp +++ b/test/unittests/test_cpp.cpp @@ -266,7 +266,7 @@ TEST(cpp, vm) EXPECT_EQ(vm.name(), std::string{"example_vm"}); EXPECT_NE(vm.version()[0], 0); - auto ctx = evmc_context{}; + auto ctx = evmc_host_context{}; auto res = vm.execute(ctx, EVMC_MAX_REVISION, {}, nullptr, 0); EXPECT_EQ(res.status_code, EVMC_FAILURE); diff --git a/test/vmtester/tests.cpp b/test/vmtester/tests.cpp index 36bfe16..916c349 100644 --- a/test/vmtester/tests.cpp +++ b/test/vmtester/tests.cpp @@ -59,7 +59,7 @@ TEST_F(evmc_vm_test, capabilities) TEST_F(evmc_vm_test, execute_call) { - evmc_context* context = example_host_create_context(evmc_tx_context{}); + evmc_host_context* context = example_host_create_context(evmc_tx_context{}); evmc_message msg{}; std::array code = {{0xfe, 0x00}}; @@ -92,7 +92,7 @@ TEST_F(evmc_vm_test, execute_call) TEST_F(evmc_vm_test, execute_create) { - evmc_context* context = example_host_create_context(evmc_tx_context{}); + evmc_host_context* context = example_host_create_context(evmc_tx_context{}); evmc_message msg{ EVMC_CREATE, 0, 0, 65536, evmc_address{}, evmc_address{}, nullptr, 0, evmc_uint256be{}, evmc_bytes32{}};