From d6edf7a8b8da4db644c31b16d1430f91a26218ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 22 Jul 2024 15:28:17 +0200 Subject: [PATCH 1/2] EIP-2935: Serve historical block hashes from state --- test/state/system_contracts.cpp | 4 ++++ test/state/system_contracts.hpp | 3 +++ test/unittests/state_system_call_test.cpp | 20 ++++++++++++++++++++ test/utils/utils.cpp | 2 ++ 4 files changed, 29 insertions(+) diff --git a/test/state/system_contracts.cpp b/test/state/system_contracts.cpp index d4e1c52acd..55219db629 100644 --- a/test/state/system_contracts.cpp +++ b/test/state/system_contracts.cpp @@ -24,6 +24,10 @@ struct SystemContract constexpr std::array SYSTEM_CONTRACTS{ SystemContract{EVMC_CANCUN, BEACON_ROOTS_ADDRESS, [](const BlockInfo& block) noexcept { return bytes_view{block.parent_beacon_block_root}; }}, + SystemContract{EVMC_PRAGUE, HISTORY_STORAGE_ADDRESS, + [](const BlockInfo& block) noexcept { + return bytes_view{block.known_block_hashes.at(block.number - 1)}; + }}, }; static_assert(std::ranges::is_sorted(SYSTEM_CONTRACTS, diff --git a/test/state/system_contracts.hpp b/test/state/system_contracts.hpp index 7423661335..b3e6114add 100644 --- a/test/state/system_contracts.hpp +++ b/test/state/system_contracts.hpp @@ -15,6 +15,9 @@ constexpr auto SYSTEM_ADDRESS = 0xfffffffffffffffffffffffffffffffffffffffe_addre /// The address of the system contract storing the root hashes of beacon chain blocks (EIP-4788). constexpr auto BEACON_ROOTS_ADDRESS = 0x000F3df6D732807Ef1319fB7B8bB8522d0Beac02_address; +/// The address of the system contract storing historical block hashes (EIP-2935). +constexpr auto HISTORY_STORAGE_ADDRESS = 0x0aae40965e6800cd9b1f4b05ff21581047e3f91e_address; + struct BlockInfo; class State; diff --git a/test/unittests/state_system_call_test.cpp b/test/unittests/state_system_call_test.cpp index 85f1151280..209234a06a 100644 --- a/test/unittests/state_system_call_test.cpp +++ b/test/unittests/state_system_call_test.cpp @@ -44,3 +44,23 @@ TEST_F(state_system_call, beacon_roots) EXPECT_EQ(storage.at(0x01_bytes32).current, block.parent_beacon_block_root); EXPECT_EQ(storage.at(0x00_bytes32).current, to_bytes32(SYSTEM_ADDRESS)); } + +TEST_F(state_system_call, history_storage) +{ + static constexpr auto NUMBER = 123456789; + static constexpr auto PREV_BLOCKHASH = 0xbbbb_bytes32; + const BlockInfo block{.number = NUMBER, .known_block_hashes = {{NUMBER - 1, PREV_BLOCKHASH}}}; + state.insert(HISTORY_STORAGE_ADDRESS, + {.code = sstore(OP_NUMBER, calldataload(0)) + sstore(0, OP_CALLER)}); + + system_call(state, block, EVMC_PRAGUE, vm); + + ASSERT_EQ(state.get_accounts().size(), 1); + EXPECT_EQ(state.find(SYSTEM_ADDRESS), nullptr); + EXPECT_EQ(state.get(HISTORY_STORAGE_ADDRESS).nonce, 0); + EXPECT_EQ(state.get(HISTORY_STORAGE_ADDRESS).balance, 0); + const auto& storage = state.get(HISTORY_STORAGE_ADDRESS).storage; + ASSERT_EQ(storage.size(), 2); + EXPECT_EQ(storage.at(bytes32{NUMBER}).current, PREV_BLOCKHASH); + EXPECT_EQ(storage.at(0x00_bytes32).current, to_bytes32(SYSTEM_ADDRESS)); +} diff --git a/test/utils/utils.cpp b/test/utils/utils.cpp index a60581fe03..a3abe5b660 100644 --- a/test/utils/utils.cpp +++ b/test/utils/utils.cpp @@ -46,6 +46,8 @@ RevisionSchedule to_rev_schedule(std::string_view s) { if (s == "ShanghaiToCancunAtTime15k") return {EVMC_SHANGHAI, EVMC_CANCUN, 15'000}; + if (s == "CancunToPragueAtTime15k") + return {EVMC_CANCUN, EVMC_PRAGUE, 15'000}; const auto single_rev = to_rev(s); return {single_rev, single_rev, 0}; From 645756f18462b658e244d7eaade2789581d21439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 10 Sep 2024 14:59:17 +0200 Subject: [PATCH 2/2] ci: Enable EIP-2935 EEST tests --- circle.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 44bd6e496e..84313817a6 100644 --- a/circle.yml +++ b/circle.yml @@ -371,9 +371,16 @@ jobs: # Tests for in-development EVM revision currently passing. working_directory: ~/spec-tests/fixtures/state_tests command: > - ~/build/bin/evmone-statetest + ~/build/bin/evmone-statetest prague/eip2537_bls_12_381_precompiles/bls12_precompiles_before_fork prague/eip2537_bls_12_381_precompiles/bls12_g1add + - run: + name: "Execution spec tests (develop, blockchain_tests)" + # Tests for in-development EVM revision currently passing. + working_directory: ~/spec-tests/fixtures/blockchain_tests + command: > + ~/build/bin/evmone-blockchaintest + prague/eip2935_historical_block_hashes_from_state - collect_coverage_gcc - upload_coverage: flags: execution_spec_tests