From 924f47a57092301a92c3e3c678af822a8d705403 Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Mon, 31 May 2021 15:48:05 +0200 Subject: [PATCH] Add Shanghai revision --- include/evmc/evmc.h | 9 ++++++++- include/evmc/helpers.h | 2 ++ lib/instructions/instruction_metrics.c | 1 + lib/instructions/instruction_names.c | 1 + test/unittests/instructions_test.cpp | 14 ++++++++++++++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/evmc/evmc.h b/include/evmc/evmc.h index fae53b84f..20d053194 100644 --- a/include/evmc/evmc.h +++ b/include/evmc/evmc.h @@ -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 }; diff --git a/include/evmc/helpers.h b/include/evmc/helpers.h index 5ada94a77..21f2ad011 100644 --- a/include/evmc/helpers.h +++ b/include/evmc/helpers.h @@ -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 ""; } diff --git a/lib/instructions/instruction_metrics.c b/lib/instructions/instruction_metrics.c index 0357b8b89..4325f94bd 100644 --- a/lib/instructions/instruction_metrics.c +++ b/lib/instructions/instruction_metrics.c @@ -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: diff --git a/lib/instructions/instruction_names.c b/lib/instructions/instruction_names.c index 62245f70d..6fd8294ec 100644 --- a/lib/instructions/instruction_names.c +++ b/lib/instructions/instruction_names.c @@ -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: diff --git a/test/unittests/instructions_test.cpp b/test/unittests/instructions_test.cpp index e56a5050d..60d6907e0 100644 --- a/test/unittests/instructions_test.cpp +++ b/test/unittests/instructions_test.cpp @@ -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; + } +}