From cf43fe0f6636379a2634cd87789df7c4be46e816 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 3 Sep 2018 16:13:18 +0200 Subject: [PATCH 1/2] Reorder evmc_message fields --- bindings/go/evmc/evmc.go | 34 ++++++++++++++++------------- include/evmc/evmc.h | 46 ++++++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/bindings/go/evmc/evmc.go b/bindings/go/evmc/evmc.go index d2411c2a6..7fa5fabe1 100644 --- a/bindings/go/evmc/evmc.go +++ b/bindings/go/evmc/evmc.go @@ -31,24 +31,26 @@ struct extended_context extern const struct evmc_host_interface evmc_go_host; -static struct evmc_result execute_wrapper(struct evmc_instance* instance, int64_t context_index, enum evmc_revision rev, - const struct evmc_address* destination, const struct evmc_address* sender, const struct evmc_uint256be* value, - const uint8_t* input_data, size_t input_size, const struct evmc_uint256be* code_hash, int64_t gas, - int32_t depth, enum evmc_call_kind kind, uint32_t flags, const uint8_t* code, size_t code_size) +static struct evmc_result execute_wrapper(struct evmc_instance* instance, + int64_t context_index, enum evmc_revision rev, + enum evmc_call_kind kind, uint32_t flags, int32_t depth, int64_t gas, + const struct evmc_address* destination, const struct evmc_address* sender, + const uint8_t* input_data, size_t input_size, const struct evmc_uint256be* value, + const uint8_t* code, size_t code_size, const struct evmc_uint256be* code_hash) { struct evmc_uint256be create2_salt = {}; struct evmc_message msg = { + kind, + flags, + depth, + gas, *destination, *sender, - *value, input_data, input_size, - *code_hash, + *value, create2_salt, - gas, - depth, - kind, - flags, + *code_hash, }; struct extended_context ctx = {{&evmc_go_host}, context_index}; @@ -195,8 +197,9 @@ func (instance *Instance) SetOption(name string, value string) (err error) { } func (instance *Instance) Execute(ctx HostContext, rev Revision, - destination common.Address, sender common.Address, value common.Hash, input []byte, codeHash common.Hash, gas int64, - depth int, kind CallKind, static bool, code []byte) (output []byte, gasLeft int64, err error) { + kind CallKind, static bool, depth int, gas int64, + destination common.Address, sender common.Address, input []byte, value common.Hash, + code []byte, codeHash common.Hash) (output []byte, gasLeft int64, err error) { flags := C.uint32_t(0) if static { @@ -209,9 +212,10 @@ func (instance *Instance) Execute(ctx HostContext, rev Revision, evmcSender := evmcAddress(sender) evmcValue := evmcUint256be(value) evmcCodeHash := evmcUint256be(codeHash) - result := C.execute_wrapper(instance.handle, C.int64_t(ctxId), uint32(rev), &evmcDestination, &evmcSender, &evmcValue, - bytesPtr(input), C.size_t(len(input)), &evmcCodeHash, C.int64_t(gas), C.int32_t(depth), C.enum_evmc_call_kind(kind), - flags, bytesPtr(code), C.size_t(len(code))) + result := C.execute_wrapper(instance.handle, C.int64_t(ctxId), uint32(rev), + C.enum_evmc_call_kind(kind), flags, C.int32_t(depth), C.int64_t(gas), + &evmcDestination, &evmcSender, bytesPtr(input), C.size_t(len(input)), &evmcValue, + bytesPtr(code), C.size_t(len(code)), &evmcCodeHash) removeHostContext(ctxId) output = C.GoBytes(unsafe.Pointer(result.output_data), C.int(result.output_size)) diff --git a/include/evmc/evmc.h b/include/evmc/evmc.h index 4d26d347f..141668b65 100644 --- a/include/evmc/evmc.h +++ b/include/evmc/evmc.h @@ -70,58 +70,58 @@ enum evmc_flags */ struct evmc_message { + /** The kind of the call. For zero-depth calls ::EVMC_CALL SHOULD be used. */ + enum evmc_call_kind kind; + + /** + * Additional flags modifying the call execution behavior. + * In the current version the only valid values are ::EVMC_STATIC or 0. + */ + uint32_t flags; + + /** The call depth. */ + int32_t depth; + + /** The amount of gas for message execution. */ + int64_t gas; + /** The destination of the message. */ struct evmc_address destination; /** The sender of the message. */ struct evmc_address sender; - /** - * The amount of Ether transferred with the message. - */ - struct evmc_uint256be value; - /** * The message input data. * - * This MAY be NULL. + * This MAY be NULL. */ const uint8_t* input_data; /** * The size of the message input data. * - * If input_data is NULL this MUST be 0. + * If input_data is NULL this MUST be 0. */ size_t input_size; /** - * The optional hash of the code of the destination account. - * The null hash MUST be used when not specified. + * The amount of Ether transferred with the message. */ - struct evmc_uint256be code_hash; + struct evmc_uint256be value; /** * The optional value used in new contract address construction. * - * Ignored unless kind is EVMC_CREATE2. + * Ignored unless kind is EVMC_CREATE2. */ struct evmc_uint256be create2_salt; - /** The amount of gas for message execution. */ - int64_t gas; - - /** The call depth. */ - int32_t depth; - - /** The kind of the call. For zero-depth calls ::EVMC_CALL SHOULD be used. */ - enum evmc_call_kind kind; - /** - * Additional flags modifying the call execution behavior. - * In the current version the only valid values are ::EVMC_STATIC or 0. + * The optional hash of the code of the destination account. + * The null hash MUST be used when not specified. */ - uint32_t flags; + struct evmc_uint256be code_hash; }; From 9a2d07e5955cfc858a68e621c12aff1cd6a7e1a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 3 Sep 2018 16:32:16 +0200 Subject: [PATCH 2/2] Remove code hash from evmc_message --- bindings/go/evmc/evmc.go | 8 +++----- examples/example.c | 2 -- include/evmc/evmc.h | 6 ------ test/vmtester/tests.cpp | 2 +- 4 files changed, 4 insertions(+), 14 deletions(-) diff --git a/bindings/go/evmc/evmc.go b/bindings/go/evmc/evmc.go index 7fa5fabe1..d5d7a2a0e 100644 --- a/bindings/go/evmc/evmc.go +++ b/bindings/go/evmc/evmc.go @@ -36,7 +36,7 @@ static struct evmc_result execute_wrapper(struct evmc_instance* instance, enum evmc_call_kind kind, uint32_t flags, int32_t depth, int64_t gas, const struct evmc_address* destination, const struct evmc_address* sender, const uint8_t* input_data, size_t input_size, const struct evmc_uint256be* value, - const uint8_t* code, size_t code_size, const struct evmc_uint256be* code_hash) + const uint8_t* code, size_t code_size) { struct evmc_uint256be create2_salt = {}; struct evmc_message msg = { @@ -50,7 +50,6 @@ static struct evmc_result execute_wrapper(struct evmc_instance* instance, input_size, *value, create2_salt, - *code_hash, }; struct extended_context ctx = {{&evmc_go_host}, context_index}; @@ -199,7 +198,7 @@ func (instance *Instance) SetOption(name string, value string) (err error) { func (instance *Instance) Execute(ctx HostContext, rev Revision, kind CallKind, static bool, depth int, gas int64, destination common.Address, sender common.Address, input []byte, value common.Hash, - code []byte, codeHash common.Hash) (output []byte, gasLeft int64, err error) { + code []byte) (output []byte, gasLeft int64, err error) { flags := C.uint32_t(0) if static { @@ -211,11 +210,10 @@ func (instance *Instance) Execute(ctx HostContext, rev Revision, evmcDestination := evmcAddress(destination) evmcSender := evmcAddress(sender) evmcValue := evmcUint256be(value) - evmcCodeHash := evmcUint256be(codeHash) result := C.execute_wrapper(instance.handle, C.int64_t(ctxId), uint32(rev), C.enum_evmc_call_kind(kind), flags, C.int32_t(depth), C.int64_t(gas), &evmcDestination, &evmcSender, bytesPtr(input), C.size_t(len(input)), &evmcValue, - bytesPtr(code), C.size_t(len(code)), &evmcCodeHash) + bytesPtr(code), C.size_t(len(code))) removeHostContext(ctxId) output = C.GoBytes(unsafe.Pointer(result.output_data), C.int(result.output_size)) diff --git a/examples/example.c b/examples/example.c index fcf47cee7..0044f77d0 100644 --- a/examples/example.c +++ b/examples/example.c @@ -19,7 +19,6 @@ int main() // EVM bytecode goes here. This is one of the examples. const uint8_t code[] = "\x30\x60\x00\x52\x59\x60\x00\xf3"; const size_t code_size = sizeof(code); - const struct evmc_uint256be code_hash = {.bytes = {1, 2, 3}}; const uint8_t input[] = "Hello World!"; const struct evmc_uint256be value = {{1, 0}}; const struct evmc_address addr = {{0, 1, 2}}; @@ -31,7 +30,6 @@ int main() msg.value = value; msg.input_data = input; msg.input_size = sizeof(input); - msg.code_hash = code_hash; msg.gas = gas; msg.depth = 0; struct evmc_result result = evmc_execute(vm, ctx, EVMC_HOMESTEAD, &msg, code, code_size); diff --git a/include/evmc/evmc.h b/include/evmc/evmc.h index 141668b65..71929ddb2 100644 --- a/include/evmc/evmc.h +++ b/include/evmc/evmc.h @@ -116,12 +116,6 @@ struct evmc_message * Ignored unless kind is EVMC_CREATE2. */ struct evmc_uint256be create2_salt; - - /** - * The optional hash of the code of the destination account. - * The null hash MUST be used when not specified. - */ - struct evmc_uint256be code_hash; }; diff --git a/test/vmtester/tests.cpp b/test/vmtester/tests.cpp index 957d382a6..5d6b7537a 100644 --- a/test/vmtester/tests.cpp +++ b/test/vmtester/tests.cpp @@ -16,7 +16,7 @@ static_assert(sizeof(evmc_uint256be) == 32, "evmc_uint256be is too big"); static_assert(sizeof(evmc_address) == 20, "evmc_address is too big"); static_assert(sizeof(evmc_result) <= 64, "evmc_result does not fit cache line"); static_assert(sizeof(evmc_instance) <= 64, "evmc_instance does not fit cache line"); -static_assert(offsetof(evmc_message, code_hash) % 8 == 0, "evmc_message.code_hash not aligned"); +static_assert(offsetof(evmc_message, value) % 8 == 0, "evmc_message.value not aligned"); // Check enums match int size. // On GCC/clang the underlying type should be unsigned int, on MSVC int