internal/ethapi: add a simple DoS protection to authorizations processing in eth_createAccessList

This commit is contained in:
sashabeton 2025-03-17 20:11:22 +01:00
parent 4bcf1449d3
commit 6e18588f80

View file

@ -1171,6 +1171,9 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
addressesToExclude[addr] = struct{}{} addressesToExclude[addr] = struct{}{}
} }
// Prevent redundant operations if args contain more authorizations than EVM may handle
maxAuthorizations := uint64(*args.Gas) / params.TxAuthTupleGas
if uint64(len(args.AuthorizationList)) <= maxAuthorizations {
for _, auth := range args.AuthorizationList { for _, auth := range args.AuthorizationList {
// Duplicating stateTransition.validateAuthorization() logic // Duplicating stateTransition.validateAuthorization() logic
if (!auth.ChainID.IsZero() && auth.ChainID.CmpBig(b.ChainConfig().ChainID) != 0) || auth.Nonce+1 < auth.Nonce { if (!auth.ChainID.IsZero() && auth.ChainID.CmpBig(b.ChainConfig().ChainID) != 0) || auth.Nonce+1 < auth.Nonce {
@ -1181,6 +1184,7 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH
addressesToExclude[authority] = struct{}{} addressesToExclude[authority] = struct{}{}
} }
} }
}
// Create an initial tracer // Create an initial tracer
prevTracer := logger.NewAccessListTracer(nil, addressesToExclude) prevTracer := logger.NewAccessListTracer(nil, addressesToExclude)