core: verify BAL gas limit

This commit is contained in:
Marius van der Wijden 2026-03-10 16:21:01 +01:00
parent 1ef86906fc
commit cd945a6477
3 changed files with 32 additions and 0 deletions

View file

@ -2418,6 +2418,11 @@ func (bc *BlockChain) ProcessBlock(ctx context.Context, parentRoot common.Hash,
bc.reportBadBlock(block, res, err)
return nil, err
}
// EIP-7928: Validate BAL items do not exceed block gas limit
if err := computedAccessList.ValidateGasLimit(block.Header().GasLimit); err != nil {
bc.reportBadBlock(block, res, err)
return nil, err
}
if block.AccessList() == nil {
// attach the computed access list to the block so it gets persisted
// when the block is written to disk

View file

@ -131,6 +131,31 @@ func (e BlockAccessList) Validate(blockTxCount int) error {
return nil
}
// ValidateGasLimit checks that the total number of BAL items (addresses +
// unique storage keys) does not exceed block_gas_limit / GasBlockAccessListItem.
// See EIP-7928 validate_block_access_list_gas_limit.
func (e BlockAccessList) ValidateGasLimit(blockGasLimit uint64) error {
var balItems uint64
for _, account := range e {
// Count each address as one item
balItems++
// Count unique storage keys across both reads and writes
uniqueSlots := make(map[common.Hash]struct{})
for _, sc := range account.StorageChanges {
uniqueSlots[sc.Slot.ToHash()] = struct{}{}
}
for _, sr := range account.StorageReads {
uniqueSlots[sr.ToHash()] = struct{}{}
}
balItems += uint64(len(uniqueSlots))
}
limit := blockGasLimit / params.GasBlockAccessListItem
if balItems > limit {
return fmt.Errorf("block access list exceeds gas limit: %d items exceeds limit of %d", balItems, limit)
}
return nil
}
// Hash computes the keccak256 hash of the access list
func (e *BlockAccessList) Hash() common.Hash {
var enc bytes.Buffer

View file

@ -192,6 +192,8 @@ const (
AccountCreationSize = 112
StorageCreationSize = 32
AuthorizationCreationSize = 23
GasBlockAccessListItem = 2000 // EIP-7928: gas cost per BAL item for gas limit check
)
// Bls12381G1MultiExpDiscountTable is the gas discount table for BLS12-381 G1 multi exponentiation operation