Skip to content

Commit

Permalink
Add Shanghai revision
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed May 31, 2021
1 parent 17fd712 commit 924f47a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion include/evmc/evmc.h
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,15 @@ enum evmc_revision
*/
EVMC_LONDON = 9,

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

/** The maximum EVM revision supported. */
EVMC_MAX_REVISION = EVMC_LONDON
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 @@ -285,6 +285,8 @@ static inline const char* evmc_revision_to_string(enum evmc_revision rev)
return "Berlin";
case EVMC_LONDON:
return "London";
case EVMC_SHANGHAI:
return "Shanghai";
}
return "<unknown>";
}
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_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_LONDON:
return london_names;
case EVMC_BERLIN:
Expand Down
14 changes: 14 additions & 0 deletions test/unittests/instructions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,17 @@ TEST(instructions, london_hard_fork)
EXPECT_EQ(ln[OP_BASEFEE], std::string{"BASEFEE"});
EXPECT_TRUE(bn[OP_BASEFEE] == nullptr);
}

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

for (int op{OP_STOP}; op <= OP_SELFDESTRUCT; ++op)
{
EXPECT_EQ(p[op], c[op]) << op;
EXPECT_STREQ(pn[op], cn[op]) << op;
}
}

0 comments on commit 924f47a

Please sign in to comment.