@@ -42,7 +42,7 @@ TransitionResult apply_block(TestState& state, evmc::VM& vm, const state::BlockI
4242
4343 std::vector<state::Log> txs_logs;
4444 int64_t block_gas_left = block.gas_limit ;
45- int64_t blob_gas_left = 0 ;
45+ auto blob_gas_left = static_cast < int64_t >(block. blob_gas_used . value_or ( 0 )) ;
4646
4747 std::vector<RejectedTransaction> rejected_txs;
4848 std::vector<state::TransactionReceipt> receipts;
@@ -75,7 +75,7 @@ TransitionResult apply_block(TestState& state, evmc::VM& vm, const state::BlockI
7575 receipt.post_state = state::mpt_hash (block_state);
7676
7777 block_gas_left -= receipt.gas_used ;
78- blob_gas_left -= tx.blob_gas_used ();
78+ blob_gas_left -= static_cast < int64_t >( tx.blob_gas_used () );
7979 receipts.emplace_back (std::move (receipt));
8080 }
8181 }
@@ -95,10 +95,34 @@ TransitionResult apply_block(TestState& state, evmc::VM& vm, const state::BlockI
9595 bloom, blob_gas_left, std::move (block_state)};
9696}
9797
98- bool validate_block (evmc_revision, const TestBlock&, const BlockHeader&) noexcept
98+ bool validate_block (
99+ evmc_revision rev, const TestBlock& test_block, const BlockHeader& parent_header) noexcept
99100{
100101 // NOTE: includes only block validity unrelated to individual txs. See `apply_block`.
101102
103+ if (rev >= EVMC_CANCUN)
104+ {
105+ // `excess_blob_gas` and `blob_gas_used` mandatory after Cancun and invalid before.
106+ if (!test_block.block_info .excess_blob_gas .has_value () ||
107+ !test_block.block_info .blob_gas_used .has_value ())
108+ return false ;
109+
110+ // Check that the excess blob gas was updated correctly.
111+ if (*test_block.block_info .excess_blob_gas !=
112+ state::calc_excess_blob_gas (
113+ parent_header.blob_gas_used .value_or (0 ), parent_header.excess_blob_gas .value_or (0 )))
114+ return false ;
115+
116+ // Ensure the total blob gas spent is at most equal to the limit
117+ if (*test_block.block_info .blob_gas_used > state::BlockInfo::MAX_BLOB_GAS_PER_BLOCK)
118+ return false ;
119+ }
120+ else
121+ {
122+ if (test_block.block_info .excess_blob_gas .has_value () ||
123+ test_block.block_info .blob_gas_used .has_value ())
124+ return false ;
125+ }
102126 return true ;
103127}
104128
0 commit comments