Skip to content

Commit

Permalink
Move EOF activation to Prague
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Aug 1, 2023
1 parent 9c9f0d4 commit 6b35712
Show file tree
Hide file tree
Showing 25 changed files with 100 additions and 99 deletions.
2 changes: 1 addition & 1 deletion lib/evmone/advanced_execution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ evmc_result execute(evmc_vm* /*unused*/, const evmc_host_interface* host, evmc_h
const bytes_view container = {code, code_size};
if (is_eof_container(container))
{
if (rev >= EVMC_CANCUN)
if (rev >= EVMC_PRAGUE)
{
const auto eof1_header = read_valid_eof1_header(container);
analysis = analyze(rev, eof1_header.get_code(container, 0));
Expand Down
2 changes: 1 addition & 1 deletion lib/evmone/baseline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ CodeAnalysis analyze_eof1(bytes_view container)

CodeAnalysis analyze(evmc_revision rev, bytes_view code)
{
if (rev < EVMC_CANCUN || !is_eof_container(code))
if (rev < EVMC_PRAGUE || !is_eof_container(code))
return analyze_legacy(code);
return analyze_eof1(code);
}
Expand Down
28 changes: 14 additions & 14 deletions lib/evmone/baseline_instruction_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@ constexpr auto common_cost_tables = []() noexcept {

constexpr auto legacy_cost_tables = []() noexcept {
auto tables = common_cost_tables;
tables[EVMC_CANCUN][OP_RJUMP] = instr::undefined;
tables[EVMC_CANCUN][OP_RJUMPI] = instr::undefined;
tables[EVMC_CANCUN][OP_RJUMPV] = instr::undefined;
tables[EVMC_CANCUN][OP_CALLF] = instr::undefined;
tables[EVMC_CANCUN][OP_RETF] = instr::undefined;
tables[EVMC_CANCUN][OP_DATALOAD] = instr::undefined;
tables[EVMC_CANCUN][OP_DATALOADN] = instr::undefined;
tables[EVMC_CANCUN][OP_DATASIZE] = instr::undefined;
tables[EVMC_CANCUN][OP_DATACOPY] = instr::undefined;
tables[EVMC_PRAGUE][OP_RJUMP] = instr::undefined;
tables[EVMC_PRAGUE][OP_RJUMPI] = instr::undefined;
tables[EVMC_PRAGUE][OP_RJUMPV] = instr::undefined;
tables[EVMC_PRAGUE][OP_CALLF] = instr::undefined;
tables[EVMC_PRAGUE][OP_RETF] = instr::undefined;
tables[EVMC_PRAGUE][OP_DATALOAD] = instr::undefined;
tables[EVMC_PRAGUE][OP_DATALOADN] = instr::undefined;
tables[EVMC_PRAGUE][OP_DATASIZE] = instr::undefined;
tables[EVMC_PRAGUE][OP_DATACOPY] = instr::undefined;
return tables;
}();

constexpr auto eof_cost_tables = []() noexcept {
auto tables = common_cost_tables;
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;
tables[EVMC_PRAGUE][OP_JUMP] = instr::undefined;
tables[EVMC_PRAGUE][OP_JUMPI] = instr::undefined;
tables[EVMC_PRAGUE][OP_PC] = instr::undefined;
tables[EVMC_PRAGUE][OP_CALLCODE] = instr::undefined;
tables[EVMC_PRAGUE][OP_SELFDESTRUCT] = instr::undefined;
return tables;
}();

Expand Down
2 changes: 1 addition & 1 deletion lib/evmone/eof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ EOFValidationError validate_eof(evmc_revision rev, bytes_view container) noexcep

if (version == 1)
{
if (rev < EVMC_CANCUN)
if (rev < EVMC_PRAGUE)
return EOFValidationError::eof_version_unknown;

const auto header_or_error = validate_eof1(rev, container);
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 @@ -98,7 +98,7 @@ Result call_impl(StackTop stack, int64_t gas_left, ExecutionState& state) noexce

if constexpr (Op == OP_DELEGATECALL)
{
if (state.rev >= EVMC_CANCUN && is_eof_container(state.original_code))
if (state.rev >= EVMC_PRAGUE && is_eof_container(state.original_code))
{
// The code targeted by DELEGATECALL must also be an EOF.
// This restriction has been added to EIP-3540 in
Expand Down
1 change: 1 addition & 0 deletions lib/evmone/instructions_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ constexpr auto storage_cost_spec = []() noexcept {
tbl[EVMC_PARIS] = tbl[EVMC_LONDON];
tbl[EVMC_SHANGHAI] = tbl[EVMC_LONDON];
tbl[EVMC_CANCUN] = tbl[EVMC_LONDON];
tbl[EVMC_PRAGUE] = tbl[EVMC_LONDON];
return tbl;
}();

Expand Down
44 changes: 22 additions & 22 deletions lib/evmone/instructions_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,19 @@ constexpr inline GasCostTable gas_costs = []() noexcept {

table[EVMC_CANCUN] = table[EVMC_SHANGHAI];
table[EVMC_CANCUN][OP_MCOPY] = 3;
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;
table[EVMC_CANCUN][OP_DATALOAD] = 3;
table[EVMC_CANCUN][OP_DATALOADN] = 2;
table[EVMC_CANCUN][OP_DATASIZE] = 2;
table[EVMC_CANCUN][OP_DATACOPY] = 3;

table[EVMC_PRAGUE] = table[EVMC_CANCUN];
table[EVMC_PRAGUE][OP_DUPN] = 3;
table[EVMC_PRAGUE][OP_SWAPN] = 3;
table[EVMC_PRAGUE][OP_RJUMP] = 2;
table[EVMC_PRAGUE][OP_RJUMPI] = 4;
table[EVMC_PRAGUE][OP_RJUMPV] = 4;
table[EVMC_PRAGUE][OP_CALLF] = 5;
table[EVMC_PRAGUE][OP_RETF] = 3;
table[EVMC_PRAGUE][OP_DATALOAD] = 3;
table[EVMC_PRAGUE][OP_DATALOADN] = 2;
table[EVMC_PRAGUE][OP_DATASIZE] = 2;
table[EVMC_PRAGUE][OP_DATACOPY] = 3;

return table;
}();
Expand Down Expand Up @@ -298,10 +298,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_CANCUN};
table[OP_RJUMPI] = {"RJUMPI", 2, false, 1, -1, EVMC_CANCUN};
table[OP_RJUMP] = {"RJUMP", 2, false, 0, 0, EVMC_PRAGUE};
table[OP_RJUMPI] = {"RJUMPI", 2, false, 1, -1, EVMC_PRAGUE};
table[OP_RJUMPV] = {
"RJUMPV", 1 /* 1 byte static immediate + dynamic immediate */, false, 1, -1, EVMC_CANCUN};
"RJUMPV", 1 /* 1 byte static immediate + dynamic immediate */, false, 1, -1, EVMC_PRAGUE};

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

Expand Down Expand Up @@ -378,13 +378,13 @@ constexpr inline std::array<Traits, 256> traits = []() noexcept {
table[OP_LOG3] = {"LOG3", 0, false, 5, -5, EVMC_FRONTIER};
table[OP_LOG4] = {"LOG4", 0, false, 6, -6, EVMC_FRONTIER};

table[OP_DUPN] = {"DUPN", 1, false, 0, 1, EVMC_CANCUN};
table[OP_SWAPN] = {"SWAPN", 1, false, 0, 0, EVMC_CANCUN};
table[OP_DUPN] = {"DUPN", 1, false, 0, 1, EVMC_PRAGUE};
table[OP_SWAPN] = {"SWAPN", 1, false, 0, 0, EVMC_PRAGUE};
table[OP_MCOPY] = {"MCOPY", 0, false, 3, -3, EVMC_CANCUN};
table[OP_DATALOAD] = {"DATALOAD", 0, false, 1, 0, EVMC_CANCUN};
table[OP_DATALOADN] = {"DATALOADN", 2, false, 0, 1, EVMC_CANCUN};
table[OP_DATASIZE] = {"DATASIZE", 0, false, 0, 1, EVMC_CANCUN};
table[OP_DATACOPY] = {"DATACOPY", 0, false, 3, -3, EVMC_CANCUN};
table[OP_DATALOAD] = {"DATALOAD", 0, false, 1, 0, EVMC_PRAGUE};
table[OP_DATALOADN] = {"DATALOADN", 2, false, 0, 1, EVMC_PRAGUE};
table[OP_DATASIZE] = {"DATASIZE", 0, false, 0, 1, EVMC_PRAGUE};
table[OP_DATACOPY] = {"DATACOPY", 0, false, 3, -3, EVMC_PRAGUE};

table[OP_CREATE] = {"CREATE", 0, false, 3, -2, EVMC_FRONTIER};
table[OP_CALL] = {"CALL", 0, false, 7, -6, EVMC_FRONTIER};
Expand All @@ -393,8 +393,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_CANCUN};
table[OP_RETF] = {"RETF", 0, true, 0, 0, EVMC_CANCUN};
table[OP_CALLF] = {"CALLF", 2, false, 0, 0, EVMC_PRAGUE};
table[OP_RETF] = {"RETF", 0, true, 0, 0, EVMC_PRAGUE};
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 @@ -52,7 +52,7 @@ int main()
}

const auto& eof = *o;
const auto err = evmone::validate_eof(EVMC_CANCUN, eof);
const auto err = evmone::validate_eof(EVMC_PRAGUE, eof);
if (err != evmone::EOFValidationError::success)
{
std::cout << "err: " << evmone::get_error_message(err) << "\n";
Expand Down
2 changes: 1 addition & 1 deletion test/eofparsefuzz/eofparsefuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,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_CANCUN, eof) == evmone::EOFValidationError::success)
if (evmone::validate_eof(EVMC_PRAGUE, eof) == evmone::EOFValidationError::success)
(void)evmone::read_valid_eof1_header(eof);
return 0;
}
2 changes: 1 addition & 1 deletion test/integration/statetest/eof/invalid_eof_in_state.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"currentTimestamp": "0x03e8"
},
"post": {
"Cancun": [
"Prague": [
{
"hash": "0xe8010ce590f401c9d61fef8ab05bea9bcec24281b795e5868809bc4e515aa530",
"indexes": {
Expand Down
4 changes: 2 additions & 2 deletions test/state/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ evmc::Result Host::create(const evmc_message& msg) noexcept
create_msg.input_data = nullptr;
create_msg.input_size = 0;

if (m_rev >= EVMC_CANCUN && (is_eof_container(initcode) || is_eof_container(sender_acc.code)))
if (m_rev >= EVMC_PRAGUE && (is_eof_container(initcode) || is_eof_container(sender_acc.code)))
{
if (validate_eof(m_rev, initcode) != EOFValidationError::success)
return evmc::Result{EVMC_CONTRACT_VALIDATION_FAILURE};
Expand Down Expand Up @@ -228,7 +228,7 @@ evmc::Result Host::create(const evmc_message& msg) noexcept
evmc::Result{EVMC_FAILURE};
}

if (m_rev >= EVMC_CANCUN && (is_eof_container(initcode) || is_eof_container(code)))
if (m_rev >= EVMC_PRAGUE && (is_eof_container(initcode) || is_eof_container(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/statetest/statetest_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ void validate_deployed_code(const state::State& state, evmc_revision rev)
{
if (is_eof_container(acc.code))
{
if (rev >= EVMC_CANCUN)
if (rev >= EVMC_PRAGUE)
{
if (const auto result = validate_eof(rev, acc.code);
result != EOFValidationError::success)
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/analysis_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,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(code);
const auto analysis = analyze(EVMC_CANCUN, header.get_code(code, 0));
const auto analysis = analyze(EVMC_PRAGUE, header.get_code(code, 0));

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

Expand Down
2 changes: 1 addition & 1 deletion test/unittests/eof_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TEST(eof, read_valid_eof1_header)
for (const auto& test_case : test_cases)
{
const auto code = from_spaced_hex(test_case.code).value();
EXPECT_EQ(validate_eof(EVMC_CANCUN, code), EOFValidationError::success) << test_case.code;
EXPECT_EQ(validate_eof(EVMC_PRAGUE, code), EOFValidationError::success) << test_case.code;

const auto header = read_valid_eof1_header(code);
EXPECT_EQ(header.code_sizes, test_case.code_sizes) << test_case.code;
Expand Down
8 changes: 4 additions & 4 deletions test/unittests/eof_validation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace
{
// Can be called as validate_eof(string_view hex, rev) or validate_eof(bytes_view cont, rev).
inline EOFValidationError validate_eof(
const bytecode& container, evmc_revision rev = EVMC_CANCUN) noexcept
const bytecode& container, evmc_revision rev = EVMC_PRAGUE) noexcept
{
return evmone::validate_eof(rev, container);
}
Expand Down Expand Up @@ -222,7 +222,7 @@ TEST(eof_validation, EOF1_code_section_offset)
{
const auto eof =
"EF0001 010008 02000200030001 040004 00 00000001 00000000 6001fe fe 0000 0000"_hex;
ASSERT_EQ(validate_eof(EVMC_CANCUN, eof), EOFValidationError::success);
ASSERT_EQ(validate_eof(EVMC_PRAGUE, eof), EOFValidationError::success);

const auto header = read_valid_eof1_header(eof);
ASSERT_EQ(header.code_sizes.size(), 2);
Expand Down Expand Up @@ -313,7 +313,7 @@ TEST(eof_validation, EOF1_too_many_code_sections)

TEST(eof_validation, EOF1_undefined_opcodes)
{
const auto& gas_table = evmone::instr::gas_costs[EVMC_CANCUN];
const auto& gas_table = evmone::instr::gas_costs[EVMC_PRAGUE];

for (uint16_t opcode = 0; opcode <= 0xff; ++opcode)
{
Expand All @@ -323,7 +323,7 @@ TEST(eof_validation, EOF1_undefined_opcodes)
opcode == OP_SWAPN || opcode == OP_RJUMP || opcode == OP_RJUMPI || opcode == OP_CALLF ||
opcode == OP_RJUMPV || opcode == OP_DATALOADN)
continue;
// These opcodes are deprecated since Cancun.
// 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)
Expand Down
12 changes: 6 additions & 6 deletions test/unittests/evm_eip663_dupn_swapn_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ TEST_P(evm, dupn)
if (evm::is_advanced())
return;

rev = EVMC_CANCUN;
rev = EVMC_PRAGUE;

auto pushes = bytecode{};
for (uint64_t i = 1; i <= 20; ++i)
Expand Down Expand Up @@ -44,7 +44,7 @@ TEST_P(evm, swapn)
if (evm::is_advanced())
return;

rev = EVMC_CANCUN;
rev = EVMC_PRAGUE;

auto pushes = bytecode{};
for (uint64_t i = 1; i <= 20; ++i)
Expand Down Expand Up @@ -84,7 +84,7 @@ TEST_P(evm, dupn_full_stack)
if (evm::is_advanced())
return;

rev = EVMC_CANCUN;
rev = EVMC_PRAGUE;
auto full_stack_code = bytecode{};
for (uint64_t i = 1023; i >= 1; --i)
full_stack_code += push(i);
Expand All @@ -111,7 +111,7 @@ TEST_P(evm, swapn_full_stack)
if (evm::is_advanced())
return;

rev = EVMC_CANCUN;
rev = EVMC_PRAGUE;
auto full_stack_code = bytecode{};
for (uint64_t i = 1024; i >= 1; --i)
full_stack_code += push(i);
Expand Down Expand Up @@ -139,7 +139,7 @@ TEST_P(evm, dupn_dup_consistency)
if (evm::is_advanced())
return;

rev = EVMC_CANCUN;
rev = EVMC_PRAGUE;
auto pushes = bytecode{};
for (uint64_t i = 32; i >= 1; --i)
pushes += push(i);
Expand Down Expand Up @@ -167,7 +167,7 @@ TEST_P(evm, swapn_swap_consistency)
if (evm::is_advanced())
return;

rev = EVMC_CANCUN;
rev = EVMC_PRAGUE;
auto pushes = bytecode{};
for (uint64_t i = 32; i >= 1; --i)
pushes += push(i);
Expand Down
4 changes: 2 additions & 2 deletions test/unittests/evm_eof_calls_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ using namespace evmc::literals;

TEST_P(evm, eof1_delegatecall_eof1)
{
rev = EVMC_CANCUN;
rev = EVMC_PRAGUE;
constexpr auto callee = 0xca11ee_address;
host.accounts[callee].code = eof1_bytecode(OP_STOP);
bytes call_output{0x01, 0x02, 0x03};
Expand All @@ -30,7 +30,7 @@ TEST_P(evm, eof1_delegatecall_eof1)

TEST_P(evm, eof1_delegatecall_legacy)
{
rev = EVMC_CANCUN;
rev = EVMC_PRAGUE;
constexpr auto callee = 0xca11ee_address;
host.access_account(callee);

Expand Down
Loading

0 comments on commit 6b35712

Please sign in to comment.