Skip to content

Commit

Permalink
blockchaintest: Simplify genesis handling
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chfast committed Jul 23, 2024
1 parent ff3559a commit d0e72ed
Showing 1 changed file with 13 additions and 32 deletions.
45 changes: 13 additions & 32 deletions test/blockchaintest/blockchaintest_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,40 +125,21 @@ void run_blockchain_tests(std::span<const BlockchainTest> 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<int64_t, hash256> known_block_hashes;
known_block_hashes[c.genesis_block_header.block_number] = c.genesis_block_header.hash;
std::unordered_map<int64_t, hash256> known_block_hashes{
{c.genesis_block_header.block_number, c.genesis_block_header.hash}};

for (const auto& test_block : c.test_blocks)
{
Expand Down

0 comments on commit d0e72ed

Please sign in to comment.