From 7350b129b8d0e7397c682d89208bca439a815954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 23 Oct 2017 17:28:53 +0200 Subject: [PATCH 1/2] EVM-C: create address in evm_result --- include/evm.h | 59 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/include/evm.h b/include/evm.h index fadd1a0..c7d3be5 100644 --- a/include/evm.h +++ b/include/evm.h @@ -171,21 +171,58 @@ struct evm_result { /// function to the result itself allows EVM composition. evm_release_result_fn release; + /// The address of the contract created by CREATE opcode. + /// + /// This field has valid value only if the result describes successful + /// CREATE (evm_result::status_code is ::EVM_SUCCESS). + struct evm_address create_address; + /// Reserved data that MAY be used by a evm_result object creator. /// - /// This reserved 24 bytes extends the size of the evm_result to 64 bytes - /// (full cache line). - /// An EVM implementation MAY use this memory to keep additional data - /// when returning result from ::evm_execute_fn. - /// The host application MAY use this memory to keep additional data - /// when returning result of performed calls from ::evm_call_fn. - union - { - void* context; ///< A pointer for storing external objects. - uint8_t data[24]; ///< 24 bytes of reserved data. - } reserved; + /// This reserved 4 bytes together with 20 bytes from create_address form + /// 24 bytes of memory called "optional data" within evm_result struct + /// to be optionally used by the evm_result object creator. + /// + /// @see evm_result_optional_data, evm_get_optional_data(). + /// + /// Also extends the size of the evm_result to 64 bytes (full cache line). + uint8_t padding[4]; }; + +/// The union representing evm_result "optional data". +/// +/// The evm_result struct contains 24 bytes of optional data that can be +/// reused by the obejct creator if the object does not contain +/// evm_result::create_address. +/// +/// An EVM implementation MAY use this memory to keep additional data +/// when returning result from ::evm_execute_fn. +/// The host application MAY use this memory to keep additional data +/// when returning result of performed calls from ::evm_call_fn. +/// +/// @see evm_get_optional_data(), evm_get_const_optional_data(). +union evm_result_optional_data +{ + uint8_t bytes[24]; + void* pointer; +}; + +/// Provides read-write access to evm_result "optional data". +static inline union evm_result_optional_data* evm_get_optional_data( + struct evm_result* result) +{ + return (union evm_result_optional_data*) &result->create_address; +} + +/// Provides read-only access to evm_result "optional data". +static inline const union evm_result_optional_data* evm_get_const_optional_data( + const struct evm_result* result) +{ + return (const union evm_result_optional_data*) &result->create_address; +} + + /// Check account existence callback function /// /// This callback function is used by the EVM to check if From 2e92618966a5887df50feea4b80416581d5b545c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 24 Oct 2017 13:50:35 +0200 Subject: [PATCH 2/2] Fix example --- examples/capi.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/capi.c b/examples/capi.c index 74caf16..53b3f23 100644 --- a/examples/capi.c +++ b/examples/capi.c @@ -166,4 +166,6 @@ int main(int argc, char *argv[]) { if (result.release) result.release(&result); jit->destroy(jit); + + return 0; }