Skip to content

Commit

Permalink
Merge pull request #627 from ethereum/rev_merge
Browse files Browse the repository at this point in the history
Add Merge revision
  • Loading branch information
chfast authored Feb 12, 2022
2 parents a79dced + 3123de8 commit 9766b77
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning].

### Added

- The [Merge](https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/merge.md)
EVM revision.
[#627](https://github.com/ethereum/evmc/pull/627)
- The error code `EVMC_LOADER_UNSPECIFIED_ERROR` has been defined to provide
a convenient way of initializing `evmc_loader_error_code` objects.
[#617](https://github.com/ethereum/evmc/pull/617)
Expand Down
15 changes: 11 additions & 4 deletions include/evmc/evmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -868,23 +868,30 @@ enum evmc_revision
/**
* The Berlin revision.
*
* https://github.com/ethereum/eth1.0-specs/blob/master/network-upgrades/mainnet-upgrades/berlin.md
* https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/berlin.md
*/
EVMC_BERLIN = 8,

/**
* The London revision.
*
* https://github.com/ethereum/eth1.0-specs/blob/master/network-upgrades/mainnet-upgrades/london.md
* 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/eth1.0-specs/blob/master/network-upgrades/mainnet-upgrades/shanghai.md
* 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 9766b77

Please sign in to comment.