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

Deprecate and reject code/gas-observability in EOF #834

Merged
merged 2 commits into from
Mar 18, 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
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ jobs:
~/tests/EIPTests/BlockchainTests/
- download_execution_tests:
repo: ipsilon/tests
rev: eof-extcode-20240313
rev: eof-deprecate-ops-20240318
legacy: false
- run:
name: "State tests (EOF)"
Expand Down
6 changes: 6 additions & 0 deletions lib/evmone/baseline_instruction_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ constexpr auto eof_cost_tables = []() noexcept {
tables[EVMC_PRAGUE][OP_SELFDESTRUCT] = instr::undefined;
tables[EVMC_PRAGUE][OP_CREATE] = instr::undefined;
tables[EVMC_PRAGUE][OP_CREATE2] = instr::undefined;
tables[EVMC_PRAGUE][OP_CODESIZE] = instr::undefined;
tables[EVMC_PRAGUE][OP_CODECOPY] = instr::undefined;
tables[EVMC_PRAGUE][OP_EXTCODESIZE] = instr::undefined;
tables[EVMC_PRAGUE][OP_EXTCODECOPY] = instr::undefined;
tables[EVMC_PRAGUE][OP_EXTCODEHASH] = instr::undefined;
tables[EVMC_PRAGUE][OP_GAS] = instr::undefined;
return tables;
}();

Expand Down
7 changes: 5 additions & 2 deletions test/unittests/eof_validation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ TEST_F(eof_validation, EOF1_undefined_opcodes)
// These opcodes are deprecated since Prague.
// gas_cost table current implementation does not allow to undef instructions.
if (opcode == OP_JUMP || opcode == OP_JUMPI || opcode == OP_PC || opcode == OP_CALLCODE ||
opcode == OP_SELFDESTRUCT || opcode == OP_CREATE || opcode == OP_CREATE2)
opcode == OP_SELFDESTRUCT || opcode == OP_CREATE || opcode == OP_CREATE2 ||
opcode == OP_CODESIZE || opcode == OP_CODECOPY || opcode == OP_EXTCODESIZE ||
opcode == OP_EXTCODECOPY || opcode == OP_EXTCODEHASH || opcode == OP_GAS)
continue;

auto cont =
Expand Down Expand Up @@ -574,7 +576,8 @@ TEST_F(eof_validation, EOF1_section_order)

TEST_F(eof_validation, deprecated_instructions)
{
for (auto op : {OP_CALLCODE, OP_SELFDESTRUCT, OP_JUMP, OP_JUMPI, OP_PC, OP_CREATE, OP_CREATE2})
for (auto op : {OP_CALLCODE, OP_SELFDESTRUCT, OP_JUMP, OP_JUMPI, OP_PC, OP_CREATE, OP_CREATE2,
OP_CODESIZE, OP_CODECOPY, OP_EXTCODESIZE, OP_EXTCODECOPY, OP_EXTCODEHASH, OP_GAS})
add_test_case(eof_bytecode(op), EOFValidationError::undefined_instruction);
}

Expand Down
101 changes: 0 additions & 101 deletions test/unittests/evm_eof_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,107 +31,6 @@ TEST_P(evm, eof1_execution_with_data_section)
EXPECT_EQ(result.output_size, 0);
}

TEST_P(evm, eof1_codesize)
{
rev = EVMC_PRAGUE;
auto code = eof_bytecode(mstore8(0, OP_CODESIZE) + ret(0, 1), 2);

execute(code);
EXPECT_STATUS(EVMC_SUCCESS);
ASSERT_EQ(result.output_size, 1);
EXPECT_EQ(result.output_data[0], 28);

code = eof_bytecode(mstore8(0, OP_CODESIZE) + ret(0, 1), 2).data("deadbeef");

execute(code);
EXPECT_STATUS(EVMC_SUCCESS);
ASSERT_EQ(result.output_size, 1);
EXPECT_EQ(result.output_data[0], 32);
}

TEST_P(evm, eof1_codecopy_full)
{
rev = EVMC_PRAGUE;
auto code = eof_bytecode(bytecode{31} + 0 + 0 + OP_CODECOPY + ret(0, 31), 3);

execute(code);
EXPECT_STATUS(EVMC_SUCCESS);
EXPECT_EQ(bytes_view(result.output_data, result.output_size),
"ef0001010004020001000c0400000000800003601f6000600039601f6000f3"_hex);

code = eof_bytecode(bytecode{35} + 0 + 0 + OP_CODECOPY + ret(0, 35), 3).data("deadbeef");

execute(code);
EXPECT_STATUS(EVMC_SUCCESS);
EXPECT_EQ(bytes_view(result.output_data, result.output_size),
"ef0001010004020001000c04000400008000036023600060003960236000f3deadbeef"_hex);
}

TEST_P(evm, eof1_codecopy_header)
{
rev = EVMC_PRAGUE;
auto code = eof_bytecode(bytecode{15} + 0 + 0 + OP_CODECOPY + ret(0, 15), 3);

execute(code);
EXPECT_STATUS(EVMC_SUCCESS);
EXPECT_EQ(
bytes_view(result.output_data, result.output_size), "ef0001010004020001000c04000000"_hex);

code = eof_bytecode(bytecode{15} + 0 + 0 + OP_CODECOPY + ret(0, 15), 3).data("deadbeef");

execute(code);
EXPECT_STATUS(EVMC_SUCCESS);
EXPECT_EQ(
bytes_view(result.output_data, result.output_size), "ef0001010004020001000c04000400"_hex);
}

TEST_P(evm, eof1_codecopy_code)
{
rev = EVMC_PRAGUE;
auto code = eof_bytecode(bytecode{12} + 19 + 0 + OP_CODECOPY + ret(0, 12), 3);

execute(code);
EXPECT_STATUS(EVMC_SUCCESS);
EXPECT_EQ(bytes_view(result.output_data, result.output_size), "600c6013600039600c6000f3"_hex);

code = eof_bytecode(bytecode{12} + 19 + 0 + OP_CODECOPY + ret(0, 12), 3).data("deadbeef");

execute(code);
EXPECT_STATUS(EVMC_SUCCESS);
EXPECT_EQ(bytes_view(result.output_data, result.output_size), "600c6013600039600c6000f3"_hex);
}

TEST_P(evm, eof1_codecopy_data)
{
rev = EVMC_PRAGUE;

const auto code =
eof_bytecode(bytecode{4} + 31 + 0 + OP_CODECOPY + ret(0, 4), 3).data("deadbeef");

execute(code);
EXPECT_STATUS(EVMC_SUCCESS);
EXPECT_EQ(bytes_view(result.output_data, result.output_size), "deadbeef"_hex);
}

TEST_P(evm, eof1_codecopy_out_of_bounds)
{
// 4 bytes out of container bounds - result is implicitly 0-padded
rev = EVMC_PRAGUE;
auto code = eof_bytecode(bytecode{35} + 0 + 0 + OP_CODECOPY + ret(0, 35), 3);

execute(code);
EXPECT_STATUS(EVMC_SUCCESS);
EXPECT_EQ(bytes_view(result.output_data, result.output_size),
"ef0001010004020001000c04000000008000036023600060003960236000f300000000"_hex);

code = eof_bytecode(bytecode{39} + 0 + 0 + OP_CODECOPY + ret(0, 39), 3).data("deadbeef");

execute(code);
EXPECT_STATUS(EVMC_SUCCESS);
EXPECT_EQ(bytes_view(result.output_data, result.output_size),
"ef0001010004020001000c04000400008000036027600060003960276000f3deadbeef00000000"_hex);
}

TEST_P(evm, eof_data_only_contract)
{
rev = EVMC_PRAGUE;
Expand Down