Skip to content

Commit

Permalink
Fix after rebase on master
Browse files Browse the repository at this point in the history
  • Loading branch information
rodiazet committed Feb 13, 2023
1 parent 6fefade commit 3987c3d
Show file tree
Hide file tree
Showing 14 changed files with 48 additions and 47 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Finally, the options `O=2` and `O=0` have been replaced by `advanced`. See below
- `PUSH0` instruction implementation ([EIP-3855]), enabled in [Shanghai].
[#448](https://github.com/ethereum/evmone/pull/448)
[#432](https://github.com/ethereum/evmone/pull/432)
- Experimental [EOF] validation and execution ([EIP-3540]), enabled in [Shanghai].
- Experimental [EOF] validation and execution ([EIP-3540]), enabled in [Cancun].
[#334](https://github.com/ethereum/evmone/pull/334)
[#366](https://github.com/ethereum/evmone/pull/366)
[#471](https://github.com/ethereum/evmone/pull/471)
Expand Down
2 changes: 1 addition & 1 deletion lib/evmone/baseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ evmc_result execute(const VM& vm, ExecutionState& state, const CodeAnalysis& ana
evmc_result execute(evmc_vm* c_vm, const evmc_host_interface* host, evmc_host_context* ctx,
evmc_revision rev, const evmc_message* msg, const uint8_t* code, size_t code_size) noexcept
{
if (rev >= EVMC_SHANGHAI && is_eof_code({code, code_size}))
if (rev >= EVMC_CANCUN && is_eof_code({code, code_size}))
{
// TODO(EOF): The initcode must be validated. Doing this just before execution is
// good because validation can be combined with analysis/loading. But consider also
Expand Down
14 changes: 7 additions & 7 deletions lib/evmone/baseline_instruction_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ constexpr auto common_cost_tables = []() noexcept {

constexpr auto legacy_cost_tables = []() noexcept {
auto tables = common_cost_tables;
tables[EVMC_SHANGHAI][OP_RJUMP] = instr::undefined;
tables[EVMC_SHANGHAI][OP_RJUMPI] = instr::undefined;
tables[EVMC_CANCUN][OP_RJUMP] = instr::undefined;
tables[EVMC_CANCUN][OP_RJUMPI] = instr::undefined;
return tables;
}();

constexpr auto eof_cost_tables = []() noexcept {
auto tables = common_cost_tables;
tables[EVMC_SHANGHAI][OP_JUMP] = instr::undefined;
tables[EVMC_SHANGHAI][OP_JUMPI] = instr::undefined;
tables[EVMC_SHANGHAI][OP_PC] = instr::undefined;
tables[EVMC_SHANGHAI][OP_CALLCODE] = instr::undefined;
tables[EVMC_SHANGHAI][OP_SELFDESTRUCT] = instr::undefined;
tables[EVMC_CANCUN][OP_JUMP] = instr::undefined;
tables[EVMC_CANCUN][OP_JUMPI] = instr::undefined;
tables[EVMC_CANCUN][OP_PC] = instr::undefined;
tables[EVMC_CANCUN][OP_CALLCODE] = instr::undefined;
tables[EVMC_CANCUN][OP_SELFDESTRUCT] = instr::undefined;
return tables;
}();

Expand Down
2 changes: 1 addition & 1 deletion lib/evmone/instructions_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ evmc_status_code create_impl(StackTop stack, ExecutionState& state) noexcept
msg.input_size = init_code_size;
}

if (state.rev >= EVMC_SHANGHAI &&
if (state.rev >= EVMC_CANCUN &&
(is_eof_code(state.original_code) || is_eof_code({msg.input_data, msg.input_size})))
if (validate_eof(state.rev, {msg.input_data, msg.input_size}) !=
EOFValidationError::success)
Expand Down
20 changes: 10 additions & 10 deletions lib/evmone/instructions_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ constexpr inline GasCostTable gas_costs = []() noexcept {

table[EVMC_SHANGHAI] = table[EVMC_PARIS];
table[EVMC_SHANGHAI][OP_PUSH0] = 2;
table[EVMC_SHANGHAI][OP_RJUMP] = 2;
table[EVMC_SHANGHAI][OP_RJUMPI] = 4;
table[EVMC_SHANGHAI][OP_RJUMPV] = 4;
table[EVMC_SHANGHAI][OP_CALLF] = 5;
table[EVMC_SHANGHAI][OP_RETF] = 3;

table[EVMC_CANCUN] = table[EVMC_SHANGHAI];
table[EVMC_CANCUN][OP_DUPN] = 3;
table[EVMC_CANCUN][OP_SWAPN] = 3;
table[EVMC_CANCUN][OP_RJUMP] = 2;
table[EVMC_CANCUN][OP_RJUMPI] = 4;
table[EVMC_CANCUN][OP_RJUMPV] = 4;
table[EVMC_CANCUN][OP_CALLF] = 5;
table[EVMC_CANCUN][OP_RETF] = 3;

return table;
}();
Expand Down Expand Up @@ -291,10 +291,10 @@ constexpr inline std::array<Traits, 256> traits = []() noexcept {
table[OP_MSIZE] = {"MSIZE", 0, false, 0, 1, EVMC_FRONTIER};
table[OP_GAS] = {"GAS", 0, false, 0, 1, EVMC_FRONTIER};
table[OP_JUMPDEST] = {"JUMPDEST", 0, false, 0, 0, EVMC_FRONTIER};
table[OP_RJUMP] = {"RJUMP", 2, false, 0, 0, EVMC_SHANGHAI};
table[OP_RJUMPI] = {"RJUMPI", 2, false, 1, -1, EVMC_SHANGHAI};
table[OP_RJUMP] = {"RJUMP", 2, false, 0, 0, EVMC_CANCUN};
table[OP_RJUMPI] = {"RJUMPI", 2, false, 1, -1, EVMC_CANCUN};
table[OP_RJUMPV] = {
"RJUMPV", 0 /* WARNING: immediate_size is dynamic */, false, 1, -1, EVMC_SHANGHAI};
"RJUMPV", 0 /* WARNING: immediate_size is dynamic */, false, 1, -1, EVMC_CANCUN};

table[OP_PUSH0] = {"PUSH0", 0, false, 0, 1, EVMC_SHANGHAI};

Expand Down Expand Up @@ -381,8 +381,8 @@ constexpr inline std::array<Traits, 256> traits = []() noexcept {
table[OP_DELEGATECALL] = {"DELEGATECALL", 0, false, 6, -5, EVMC_HOMESTEAD};
table[OP_CREATE2] = {"CREATE2", 0, false, 4, -3, EVMC_CONSTANTINOPLE};
table[OP_STATICCALL] = {"STATICCALL", 0, false, 6, -5, EVMC_BYZANTIUM};
table[OP_CALLF] = {"CALLF", 2, false, 0, 0, EVMC_SHANGHAI};
table[OP_RETF] = {"RETF", 0, true, 0, 0, EVMC_SHANGHAI};
table[OP_CALLF] = {"CALLF", 2, false, 0, 0, EVMC_CANCUN};
table[OP_RETF] = {"RETF", 0, true, 0, 0, EVMC_CANCUN};
table[OP_REVERT] = {"REVERT", 0, true, 2, -2, EVMC_BYZANTIUM};
table[OP_INVALID] = {"INVALID", 0, true, 0, 0, EVMC_FRONTIER};
table[OP_SELFDESTRUCT] = {"SELFDESTRUCT", 0, true, 1, -1, EVMC_FRONTIER};
Expand Down
2 changes: 1 addition & 1 deletion test/eofparse/eofparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ int main()
}

const auto eof = std::move(*o);
const auto err = evmone::validate_eof(EVMC_SHANGHAI, eof);
const auto err = evmone::validate_eof(EVMC_CANCUN, eof);
if (err != evmone::EOFValidationError::success)
{
std::cout << "err: " << evmone::get_error_message(err) << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion test/eofparsefuzz/eofparsefuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t data_size) noexcept
{
const evmone::bytes_view eof{data, data_size};
if (evmone::validate_eof(EVMC_SHANGHAI, eof) == evmone::EOFValidationError::success)
if (evmone::validate_eof(EVMC_CANCUN, eof) == evmone::EOFValidationError::success)
(void)evmone::read_valid_eof1_header(eof);
return 0;
}
2 changes: 1 addition & 1 deletion test/state/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ evmc::Result Host::create(const evmc_message& msg) noexcept
evmc::Result{EVMC_FAILURE};
}

if (m_rev >= EVMC_SHANGHAI && (is_eof_code(initcode) || is_eof_code(code)))
if (m_rev >= EVMC_CANCUN && (is_eof_code(initcode) || is_eof_code(code)))
{
if (validate_eof(m_rev, code) != EOFValidationError::success)
return evmc::Result{EVMC_CONTRACT_VALIDATION_FAILURE};
Expand Down
2 changes: 1 addition & 1 deletion test/state/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ std::variant<TransactionReceipt, std::error_code> transition(
auto is_valid_tx = true;
auto result = evmc::Result{};

if (rev >= EVMC_SHANGHAI && !tx.to.has_value() && is_eof_code(tx.data))
if (rev >= EVMC_CANCUN && !tx.to.has_value() && is_eof_code(tx.data))
is_valid_tx = (validate_eof(rev, tx.data) == evmone::EOFValidationError::success);

if (is_valid_tx)
Expand Down
3 changes: 1 addition & 2 deletions test/unittests/analysis_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ TEST(analysis, example1_eof1)
const auto code = eof1_bytecode(
push(0x2a) + push(0x1e) + OP_MSTORE8 + OP_MSIZE + push(0) + OP_SSTORE, 2, "deadbeef");
const auto header = evmone::read_valid_eof1_header(bytes_view(code));
const auto analysis =
analyze(EVMC_SHANGHAI, {&code[header.code_begin(0)], header.code_sizes[0]});
const auto analysis = analyze(EVMC_CANCUN, {&code[header.code_begin(0)], header.code_sizes[0]});

ASSERT_EQ(analysis.instrs.size(), 8);

Expand Down
4 changes: 3 additions & 1 deletion test/unittests/eof_validation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,16 @@ TEST(eof_validation, EOF1_undefined_opcodes)
""_hex;

// Skip opcodes requiring immediate arguments.
// They're all valid in Shanghai and checked in other tests below.
// They're all valid in Cancun and checked in other tests below.
if (opcode >= OP_PUSH1 && opcode <= OP_PUSH32)
continue;
if (opcode == OP_RJUMP || opcode == OP_RJUMPI || opcode == OP_RJUMPV || opcode == OP_CALLF)
continue;
if (opcode == OP_JUMP || opcode == OP_JUMPI || opcode == OP_PC || opcode == OP_CALLCODE ||
opcode == OP_SELFDESTRUCT)
continue;
if (opcode == OP_DUPN || opcode == OP_SWAPN)
continue;

if (opcode == OP_RETF)
{
Expand Down
28 changes: 14 additions & 14 deletions test/unittests/evm_eof_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ TEST_P(evm, eof2_rjump)
if (is_advanced())
return;

rev = EVMC_SHANGHAI;
rev = EVMC_CANCUN;
auto code = eof1_bytecode(rjumpi(3, 0) + rjump(1) + OP_INVALID + mstore8(0, 1) + ret(0, 1), 2);

execute(code);
Expand All @@ -252,7 +252,7 @@ TEST_P(evm, eof2_rjump_backward)
if (is_advanced())
return;

rev = EVMC_SHANGHAI;
rev = EVMC_CANCUN;
auto code = eof1_bytecode(rjump(10) + mstore8(0, 1) + ret(0, 1) + rjump(-13), 2);

execute(code);
Expand All @@ -274,7 +274,7 @@ TEST_P(evm, eof2_rjump_0_offset)
if (is_advanced())
return;

rev = EVMC_SHANGHAI;
rev = EVMC_CANCUN;
auto code = eof1_bytecode(rjump(0) + mstore8(0, 1) + ret(0, 1), 2);

execute(code);
Expand All @@ -289,7 +289,7 @@ TEST_P(evm, eof2_rjumpi)
if (is_advanced())
return;

rev = EVMC_SHANGHAI;
rev = EVMC_CANCUN;
auto code = eof1_bytecode(
rjumpi(10, calldataload(0)) + mstore8(0, 2) + ret(0, 1) + mstore8(0, 1) + ret(0, 1), 2);

Expand All @@ -312,7 +312,7 @@ TEST_P(evm, eof2_rjumpi_backwards)
if (is_advanced())
return;

rev = EVMC_SHANGHAI;
rev = EVMC_CANCUN;
auto code = eof1_bytecode(rjump(10) + mstore8(0, 1) + ret(0, 1) + rjumpi(-16, calldataload(0)) +
mstore8(0, 2) + ret(0, 1),
2);
Expand All @@ -336,7 +336,7 @@ TEST_P(evm, eof2_rjumpi_0_offset)
if (is_advanced())
return;

rev = EVMC_SHANGHAI;
rev = EVMC_CANCUN;
auto code = eof1_bytecode(rjumpi(0, calldataload(0)) + mstore8(0, 1) + ret(0, 1), 2);

// RJUMPI condition is true
Expand All @@ -358,7 +358,7 @@ TEST_P(evm, eof1_rjumpv_single_offset)
if (is_advanced())
return;

rev = EVMC_SHANGHAI;
rev = EVMC_CANCUN;
auto code = eof1_bytecode(rjumpv({3}, 0) + OP_JUMPDEST + OP_JUMPDEST + OP_STOP + 20 + 40 + 0 +
OP_CODECOPY + ret(0, 20),
3, "ef000101000402000100010300000000000000fe");
Expand All @@ -376,7 +376,7 @@ TEST_P(evm, eof1_rjumpv_multiple_offsets)
if (is_advanced())
return;

rev = EVMC_SHANGHAI;
rev = EVMC_CANCUN;
auto code = eof1_bytecode(rjump(12) + 10 + 68 + 0 + OP_CODECOPY + ret(0, 10) +
rjumpv({12, -22, 0}, 1) + 10 + 78 + 0 + OP_CODECOPY + ret(0, 10) +
20 + 68 + 0 + OP_CODECOPY + ret(0, 20),
Expand Down Expand Up @@ -415,7 +415,7 @@ TEST_P(evm, eof1_rjumpv_long_jumps)
if (is_advanced())
return;

rev = EVMC_SHANGHAI;
rev = EVMC_CANCUN;
auto code =
rjump(0x7fff - 3 - 5) + (0x7fff - 3 - 2 - 8 - 5) * bytecode{OP_JUMPDEST} + 7 + ret_top();

Expand All @@ -438,7 +438,7 @@ TEST_P(evm, eof1_rjumpv_long_jumps)

TEST_P(evm, relative_jumps_undefined_in_legacy)
{
rev = EVMC_SHANGHAI;
rev = EVMC_CANCUN;
auto code = rjump(1) + OP_INVALID + mstore8(0, 1) + ret(0, 1);

execute(code);
Expand All @@ -456,7 +456,7 @@ TEST_P(evm, eof_function_example1)
if (is_advanced())
return;

rev = EVMC_SHANGHAI;
rev = EVMC_CANCUN;
const auto code =
"EF00 01 010008 020002 000f 0002 030000 00"
"00000002 02010002"
Expand All @@ -476,7 +476,7 @@ TEST_P(evm, eof_function_example2)
if (is_advanced())
return;

rev = EVMC_SHANGHAI;
rev = EVMC_CANCUN;
const auto code =
"ef0001 01000c 020003 003b 0017 001d 030000 00 00000004 01010003 01010004"
"60043560003560e01c63c766526781145d001c63c6c2ea1781145d00065050600080fd50b00002600052602060"
Expand Down Expand Up @@ -507,7 +507,7 @@ TEST_P(evm, eof_data_only_contract)
if (is_advanced())
return;

rev = EVMC_SHANGHAI;
rev = EVMC_CANCUN;
auto code = "EF0001 010004 020001 0001 03daaa 00 00000000 FE"_hex;
const auto data_size_ptr = &code[code.find(0xda)];

Expand All @@ -526,7 +526,7 @@ TEST_P(evm, eof_data_only_contract)

TEST_P(evm, eof_creates_valid_eof_contract_only)
{
rev = EVMC_SHANGHAI;
rev = EVMC_CANCUN;
host.call_result.create_address = 0x02_address;
{
// invalid eof contract (push1 truncated)
Expand Down
10 changes: 5 additions & 5 deletions test/unittests/instructions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ TEST(instructions, compare_with_evmc_instruction_tables)
for (size_t i = 0; i < evmone_tbl.size(); ++i)
{
// TODO pending update in EVMC
if (r >= EVMC_SHANGHAI && (i == OP_RJUMP || i == OP_RJUMPI || i == OP_RJUMPV ||
i == OP_CALLF || i == OP_RETF))
if (r >= EVMC_CANCUN && (i == OP_RJUMP || i == OP_RJUMPI || i == OP_RJUMPV ||
i == OP_CALLF || i == OP_RETF))
continue;

// Skip DUPN and SWAPN for Cancun. They are not defined in evmc
Expand Down Expand Up @@ -145,13 +145,13 @@ TEST(instructions, compare_undefined_instructions)
for (size_t i = 0; i < instr_tbl.size(); ++i)
{
// TODO pending update in EVMC
if (r >= EVMC_SHANGHAI && (i == OP_RJUMP || i == OP_RJUMPI || i == OP_RJUMPV ||
i == OP_CALLF || i == OP_RETF))
if (r >= EVMC_CANCUN && (i == OP_RJUMP || i == OP_RJUMPI || i == OP_RJUMPV ||
i == OP_CALLF || i == OP_RETF))
continue;

// Skip DUPN and SWAPN. They are not defined in evmc
// TODO: Define DUPN and SWAPN in evmc
if (Opcode(i) == OP_DUPN || Opcode(i) == OP_SWAPN)
if (r >= EVMC_CANCUN && (Opcode(i) == OP_DUPN || Opcode(i) == OP_SWAPN))
continue;
EXPECT_EQ(instr_tbl[i] == instr::undefined, evmc_names_tbl[i] == nullptr) << i;
}
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/tracing_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ TEST_F(tracing, trace_eof)
vm.add_tracer(evmone::create_instruction_tracer(trace_stream));

trace_stream << '\n';
EXPECT_EQ(trace(eof1_bytecode(add(2, 3) + OP_STOP), 0, 0, EVMC_CANCUN), R"(
EXPECT_EQ(trace(eof1_bytecode(add(2, 3) + OP_STOP, 2), 0, 0, EVMC_CANCUN), R"(
{"depth":0,"rev":"Cancun","static":false}
{"pc":0,"op":96,"opName":"PUSH1","gas":1000000,"stack":[],"memorySize":0}
{"pc":2,"op":96,"opName":"PUSH1","gas":999997,"stack":["0x3"],"memorySize":0}
Expand Down

0 comments on commit 3987c3d

Please sign in to comment.