From 494b69668bcf3ba995cb985d67042cba6d665e1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Thu, 9 May 2019 12:51:50 +0200 Subject: [PATCH 1/2] docs: Clarify validity of result::create_address --- include/evmc/evmc.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/evmc/evmc.h b/include/evmc/evmc.h index a324ca9..f0dcd75 100644 --- a/include/evmc/evmc.h +++ b/include/evmc/evmc.h @@ -385,10 +385,13 @@ struct evmc_result evmc_release_result_fn release; /** - * The address of the contract created by CREATE opcode. + * The address of the contract created by create instructions. * - * This field has valid value only if the result describes successful - * CREATE (evmc_result::status_code is ::EVMC_SUCCESS). + * This field has valid value only if: + * - it is a result of the Host method evmc_host_interface::call + * - and the result describes successful contract creation + * (evmc_result::status_code is ::EVMC_SUCCESS). + * In all other cases the address MUST be null bytes. */ evmc_address create_address; From 3779b533a16526b72fef6fcc41ce557471dada56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 8 May 2019 22:33:15 +0200 Subject: [PATCH 2/2] vmtester: Change tests for result::create_address --- examples/example_vm.c | 3 --- test/vmtester/tests.cpp | 13 ++++++------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/examples/example_vm.c b/examples/example_vm.c index e825c8b..91df9c9 100644 --- a/examples/example_vm.c +++ b/examples/example_vm.c @@ -112,10 +112,7 @@ static struct evmc_result execute(struct evmc_instance* instance, if (msg->kind == EVMC_CREATE) { - evmc_address create_address = { - {1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; ret.status_code = EVMC_SUCCESS; - ret.create_address = create_address; ret.gas_left = msg->gas / 10; return ret; } diff --git a/test/vmtester/tests.cpp b/test/vmtester/tests.cpp index 083a27a..44ed154 100644 --- a/test/vmtester/tests.cpp +++ b/test/vmtester/tests.cpp @@ -78,6 +78,8 @@ TEST_F(evmc_vm_test, execute_call) read_buffer(result.output_data, result.output_size); } + EXPECT_TRUE(is_zero(result.create_address)); + if (result.release) result.release(&result); @@ -88,7 +90,7 @@ TEST_F(evmc_vm_test, execute_create) { evmc_context* context = example_host_create_context(); evmc_message msg{ - EVMC_CREATE, 0, 0, 65536, evmc_address{}, evmc_address{}, NULL, 0, evmc_uint256be{}, + EVMC_CREATE, 0, 0, 65536, evmc_address{}, evmc_address{}, nullptr, 0, evmc_uint256be{}, evmc_bytes32{}}; std::array code = {{0xfe, 0x00}}; @@ -101,7 +103,7 @@ TEST_F(evmc_vm_test, execute_create) EXPECT_EQ(result.gas_left, 0); } - if (result.output_data == NULL) + if (result.output_data == nullptr) { EXPECT_EQ(result.output_size, 0); } @@ -111,11 +113,8 @@ TEST_F(evmc_vm_test, execute_create) read_buffer(result.output_data, result.output_size); } - if (result.status_code == EVMC_SUCCESS) - { - // This assumes that CREATE returns a non-zero address on success. - EXPECT_FALSE(is_zero(result.create_address)); - } + // The VM will never provide the create address. + EXPECT_TRUE(is_zero(result.create_address)); if (result.release) result.release(&result);