From 26d56091136addea1eb429eb803c8b5b4baa19c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Tue, 23 Jul 2024 16:54:50 +0200 Subject: [PATCH] blockchaintest: Simplify genesis handling (#954) Do not execute system contracts on the blockchain test genesis block. It is unspecified how they should behave and the genesis block is expected to be a static block without transactions. Instead just validate there are no transactions/receipt/withdrowals referenced by the genesis block header. --- test/blockchaintest/blockchaintest_runner.cpp | 45 ++++++------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/test/blockchaintest/blockchaintest_runner.cpp b/test/blockchaintest/blockchaintest_runner.cpp index 9c1a0ffe53..c8d37448a9 100644 --- a/test/blockchaintest/blockchaintest_runner.cpp +++ b/test/blockchaintest/blockchaintest_runner.cpp @@ -125,40 +125,21 @@ void run_blockchain_tests(std::span tests, evmc::VM& vm) SCOPED_TRACE(std::string{evmc::to_string(c.rev.get_revision(0))} + '/' + std::to_string(case_index) + '/' + c.name); - auto state = c.pre_state.to_intra_state(); + // Validate the genesis block header. + EXPECT_EQ(c.genesis_block_header.block_number, 0); + EXPECT_EQ(c.genesis_block_header.gas_used, 0); + EXPECT_EQ(c.genesis_block_header.transactions_root, state::EMPTY_MPT_HASH); + EXPECT_EQ(c.genesis_block_header.receipts_root, state::EMPTY_MPT_HASH); + EXPECT_EQ(c.genesis_block_header.withdrawal_root, + c.rev.get_revision(c.genesis_block_header.timestamp) >= EVMC_SHANGHAI ? + state::EMPTY_MPT_HASH : + bytes32{}); + EXPECT_EQ(c.genesis_block_header.logs_bloom, bytes_view{state::BloomFilter{}}); - const state::BlockInfo genesis{ - .number = c.genesis_block_header.block_number, - .timestamp = c.genesis_block_header.timestamp, - .parent_timestamp = 0, - .gas_limit = c.genesis_block_header.gas_limit, - .coinbase = c.genesis_block_header.coinbase, - .difficulty = c.genesis_block_header.difficulty, - .parent_difficulty = 0, - .parent_ommers_hash = {}, - .prev_randao = c.genesis_block_header.prev_randao, - .base_fee = c.genesis_block_header.base_fee_per_gas, - .ommers = {}, - .withdrawals = {}, - .known_block_hashes = {}, - }; - - const auto genesis_res = apply_block(state, vm, genesis, {}, c.rev.get_revision(0), {}); - - EXPECT_EQ(state::mpt_hash(TestState{state}), state::mpt_hash(c.pre_state)); - - if (c.rev.get_revision(0) >= EVMC_SHANGHAI) - { - EXPECT_EQ(state::mpt_hash(genesis.withdrawals), c.genesis_block_header.withdrawal_root); - } - - EXPECT_EQ(state::mpt_hash({}), c.genesis_block_header.transactions_root); - EXPECT_EQ(state::mpt_hash(genesis_res.receipts), c.genesis_block_header.receipts_root); - EXPECT_EQ(genesis_res.gas_used, c.genesis_block_header.gas_used); - EXPECT_EQ(bytes_view{genesis_res.bloom}, bytes_view{c.genesis_block_header.logs_bloom}); + auto state = c.pre_state.to_intra_state(); - std::unordered_map known_block_hashes; - known_block_hashes[c.genesis_block_header.block_number] = c.genesis_block_header.hash; + std::unordered_map known_block_hashes{ + {c.genesis_block_header.block_number, c.genesis_block_header.hash}}; for (const auto& test_block : c.test_blocks) {