Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Clarify validity of result::create_address #276

Merged
merged 2 commits into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions examples/example_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 6 additions & 3 deletions include/evmc/evmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
13 changes: 6 additions & 7 deletions test/vmtester/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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<uint8_t, 2> code = {{0xfe, 0x00}};

Expand All @@ -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);
}
Expand All @@ -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);
Expand Down