Skip to content

Commit

Permalink
Fix support for EOF creation tx in evmc run (#713)
Browse files Browse the repository at this point in the history
This PR will be accompanied by a PR in `evmone`, fixing the handling of
top level creation msgs when validation EOF.

Here, we only replicate the behavior of creation txs for EOF - if the
code begins with EOF magic it will be interpreted as an EOF creation
transaction and the msg kind will be set appropriately, in order to be
consumed by the `vm.execute`.
  • Loading branch information
pdobacz authored Jul 26, 2024
1 parent 0a642bc commit 7c0de9d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/tooling/run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ constexpr auto create_address = 0xc9ea7ed000000000000000000000000000000001_addre
/// The gas limit for contract creation.
constexpr auto create_gas = 10'000'000;

/// MAGIC bytes denoting an EOF container.
constexpr uint8_t MAGIC[] = {0xef, 0x00};

auto bench(MockedHost& host,
evmc::VM& vm,
evmc_revision rev,
Expand Down Expand Up @@ -57,6 +60,11 @@ auto bench(MockedHost& host,
<< " (avg of " << num_iterations << " iterations)\n";
}
}

bool is_eof_container(bytes_view code)
{
return code.size() >= 2 && code[0] == MAGIC[0] && code[1] == MAGIC[1];
}
} // namespace

int run(VM& vm,
Expand All @@ -82,7 +90,7 @@ int run(VM& vm,
if (create)
{
evmc_message create_msg{};
create_msg.kind = EVMC_CREATE;
create_msg.kind = is_eof_container(code) ? EVMC_EOFCREATE : EVMC_CREATE;
create_msg.recipient = create_address;
create_msg.gas = create_gas;

Expand Down

0 comments on commit 7c0de9d

Please sign in to comment.