@@ -42,7 +42,7 @@ TransitionResult apply_block(TestState& state, evmc::VM& vm, const state::BlockI
42
42
43
43
std::vector<state::Log> txs_logs;
44
44
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 )) ;
46
46
47
47
std::vector<RejectedTransaction> rejected_txs;
48
48
std::vector<state::TransactionReceipt> receipts;
@@ -75,7 +75,7 @@ TransitionResult apply_block(TestState& state, evmc::VM& vm, const state::BlockI
75
75
receipt.post_state = state::mpt_hash (block_state);
76
76
77
77
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 () );
79
79
receipts.emplace_back (std::move (receipt));
80
80
}
81
81
}
@@ -95,10 +95,34 @@ TransitionResult apply_block(TestState& state, evmc::VM& vm, const state::BlockI
95
95
bloom, blob_gas_left, std::move (block_state)};
96
96
}
97
97
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
99
100
{
100
101
// NOTE: includes only block validity unrelated to individual txs. See `apply_block`.
101
102
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
+ }
102
126
return true ;
103
127
}
104
128
0 commit comments