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

Fix EOF initcode handling before EOF is enabled #893

Merged
merged 1 commit into from
May 22, 2024
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
9 changes: 6 additions & 3 deletions lib/evmone/instructions_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,12 @@ Result create_impl(StackTop stack, int64_t gas_left, ExecutionState& state) noex
msg.input_data = &state.memory[init_code_offset];
msg.input_size = init_code_size;

// EOF initcode is not allowed for legacy creation
if (is_eof_container({msg.input_data, msg.input_size}))
return {EVMC_SUCCESS, gas_left}; // "Light" failure.
if (state.rev >= EVMC_PRAGUE)
{
// EOF initcode is not allowed for legacy creation
if (is_eof_container({msg.input_data, msg.input_size}))
return {EVMC_SUCCESS, gas_left}; // "Light" failure.
}
}
msg.sender = state.msg->recipient;
msg.depth = state.msg->depth + 1;
Expand Down
49 changes: 47 additions & 2 deletions test/unittests/state_transition_eof_create_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TEST_F(state_transition, create_with_eof_initcode)
tx.gas_limit = block.gas_limit;
pre.get(tx.sender).balance = tx.gas_limit * tx.max_gas_price + tx.value + 1;

const bytecode init_container = eof_bytecode(ret(0, 1));
const bytecode init_container = eof_bytecode(OP_INVALID);
const auto factory_code =
mstore(0, push(init_container)) +
// init_container will be left-padded in memory to 32 bytes
Expand All @@ -46,14 +46,36 @@ TEST_F(state_transition, create_with_eof_initcode)
expect.post[*tx.to].storage[0x01_bytes32] = 0x01_bytes32;
}

TEST_F(state_transition, create_with_eof_initcode_cancun)
{
rev = EVMC_CANCUN;
block.gas_limit = 10'000'000;
tx.gas_limit = block.gas_limit;
pre.get(tx.sender).balance = tx.gas_limit * tx.max_gas_price + tx.value + 1;

const bytecode init_container = eof_bytecode(OP_INVALID);
const auto factory_code =
mstore(0, push(init_container)) +
// init_container will be left-padded in memory to 32 bytes
sstore(0, create().input(32 - init_container.size(), init_container.size())) + sstore(1, 1);

tx.to = To;

pre.insert(*tx.to, {.nonce = 1, .code = factory_code});

expect.post[*tx.to].nonce = pre.get(*tx.to).nonce + 1; // fails by EF execution, nonce bumped.
expect.post[*tx.to].storage[0x00_bytes32] = 0x00_bytes32;
expect.post[*tx.to].storage[0x01_bytes32] = 0x01_bytes32;
}

TEST_F(state_transition, create2_with_eof_initcode)
{
rev = EVMC_PRAGUE;
block.gas_limit = 10'000'000;
tx.gas_limit = block.gas_limit;
pre.get(tx.sender).balance = tx.gas_limit * tx.max_gas_price + tx.value + 1;

const bytecode init_container = eof_bytecode(ret(0, 1));
const bytecode init_container = eof_bytecode(OP_INVALID);
const auto factory_code =
mstore(0, push(init_container)) +
// init_container will be left-padded in memory to 32 bytes
Expand All @@ -69,6 +91,29 @@ TEST_F(state_transition, create2_with_eof_initcode)
expect.post[*tx.to].storage[0x01_bytes32] = 0x01_bytes32;
}

TEST_F(state_transition, create2_with_eof_initcode_cancun)
{
rev = EVMC_CANCUN;
block.gas_limit = 10'000'000;
tx.gas_limit = block.gas_limit;
pre.get(tx.sender).balance = tx.gas_limit * tx.max_gas_price + tx.value + 1;

const bytecode init_container = eof_bytecode(OP_INVALID);
const auto factory_code =
mstore(0, push(init_container)) +
// init_container will be left-padded in memory to 32 bytes
sstore(0, create2().input(32 - init_container.size(), init_container.size()).salt(Salt)) +
sstore(1, 1);

tx.to = To;

pre.insert(*tx.to, {.nonce = 1, .code = factory_code});

expect.post[*tx.to].nonce = pre.get(*tx.to).nonce + 1; // fails by EF execution, nonce bumped.
expect.post[*tx.to].storage[0x00_bytes32] = 0x00_bytes32;
expect.post[*tx.to].storage[0x01_bytes32] = 0x01_bytes32;
}

TEST_F(state_transition, create_tx_deploying_eof)
{
rev = EVMC_PRAGUE;
Expand Down