Skip to content

Commit

Permalink
Add Merge revision
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Feb 10, 2022
1 parent 23b5eb7 commit 163f145
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
7 changes: 6 additions & 1 deletion include/evmc/evmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -875,10 +875,15 @@ enum evmc_revision
/// https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/london.md
EVMC_LONDON = 9,

/// The Merge revision.
///
/// https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/merge.md
EVMC_MERGE = 10,

/// The Shanghai revision.
///
/// https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/shanghai.md
EVMC_SHANGHAI = 10,
EVMC_SHANGHAI = 11,

/** The maximum EVM revision supported. */
EVMC_MAX_REVISION = EVMC_SHANGHAI,
Expand Down
2 changes: 2 additions & 0 deletions include/evmc/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ static inline const char* evmc_revision_to_string(enum evmc_revision rev)
return "Berlin";
case EVMC_LONDON:
return "London";
case EVMC_MERGE:
return "Merge";
case EVMC_SHANGHAI:
return "Shanghai";
}
Expand Down
1 change: 1 addition & 0 deletions lib/instructions/instruction_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -2108,6 +2108,7 @@ const struct evmc_instruction_metrics* evmc_get_instruction_metrics_table(
switch (revision)
{
case EVMC_SHANGHAI:
case EVMC_MERGE:
case EVMC_LONDON:
return london_metrics;
case EVMC_BERLIN:
Expand Down
1 change: 1 addition & 0 deletions lib/instructions/instruction_names.c
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,7 @@ const char* const* evmc_get_instruction_names_table(enum evmc_revision revision)
switch (revision)
{
case EVMC_SHANGHAI:
case EVMC_MERGE:
case EVMC_LONDON:
return london_names;
case EVMC_BERLIN:
Expand Down
1 change: 1 addition & 0 deletions test/unittests/cpp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,7 @@ TEST(cpp, revision_to_string)
TEST_CASE(EVMC_ISTANBUL),
TEST_CASE(EVMC_BERLIN),
TEST_CASE(EVMC_LONDON),
TEST_CASE(EVMC_MERGE),
TEST_CASE(EVMC_SHANGHAI),
};
#undef TEST_CASE
Expand Down
22 changes: 18 additions & 4 deletions test/unittests/instructions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,30 @@ TEST(instructions, london_hard_fork)
EXPECT_TRUE(bn[OP_BASEFEE] == nullptr);
}

TEST(instructions, merge_hard_fork)
{
const auto m = evmc_get_instruction_metrics_table(EVMC_MERGE);
const auto l = evmc_get_instruction_metrics_table(EVMC_LONDON);
const auto mn = evmc_get_instruction_names_table(EVMC_MERGE);
const auto ln = evmc_get_instruction_names_table(EVMC_LONDON);

for (int op = 0x00; op <= 0xff; ++op)
{
EXPECT_EQ(m[op], l[op]) << op;
EXPECT_STREQ(mn[op], ln[op]) << op;
}
}

TEST(instructions, shanghai_hard_fork)
{
const auto s = evmc_get_instruction_metrics_table(EVMC_SHANGHAI);
const auto l = evmc_get_instruction_metrics_table(EVMC_LONDON);
const auto m = evmc_get_instruction_metrics_table(EVMC_MERGE);
const auto sn = evmc_get_instruction_names_table(EVMC_SHANGHAI);
const auto ln = evmc_get_instruction_names_table(EVMC_LONDON);
const auto mn = evmc_get_instruction_names_table(EVMC_MERGE);

for (int op = 0x00; op <= 0xff; ++op)
{
EXPECT_EQ(s[op], l[op]) << op;
EXPECT_STREQ(sn[op], ln[op]) << op;
EXPECT_EQ(s[op], m[op]) << op;
EXPECT_STREQ(sn[op], mn[op]) << op;
}
}

0 comments on commit 163f145

Please sign in to comment.