mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-12 11:06:40 +00:00
core: verify BAL gas limit
This commit is contained in:
parent
1ef86906fc
commit
cd945a6477
3 changed files with 32 additions and 0 deletions
|
|
@ -2418,6 +2418,11 @@ func (bc *BlockChain) ProcessBlock(ctx context.Context, parentRoot common.Hash,
|
||||||
bc.reportBadBlock(block, res, err)
|
bc.reportBadBlock(block, res, err)
|
||||||
return nil, 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 {
|
if block.AccessList() == nil {
|
||||||
// attach the computed access list to the block so it gets persisted
|
// attach the computed access list to the block so it gets persisted
|
||||||
// when the block is written to disk
|
// when the block is written to disk
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,31 @@ func (e BlockAccessList) Validate(blockTxCount int) error {
|
||||||
return nil
|
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
|
// Hash computes the keccak256 hash of the access list
|
||||||
func (e *BlockAccessList) Hash() common.Hash {
|
func (e *BlockAccessList) Hash() common.Hash {
|
||||||
var enc bytes.Buffer
|
var enc bytes.Buffer
|
||||||
|
|
|
||||||
|
|
@ -192,6 +192,8 @@ const (
|
||||||
AccountCreationSize = 112
|
AccountCreationSize = 112
|
||||||
StorageCreationSize = 32
|
StorageCreationSize = 32
|
||||||
AuthorizationCreationSize = 23
|
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
|
// Bls12381G1MultiExpDiscountTable is the gas discount table for BLS12-381 G1 multi exponentiation operation
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue