From 6e18588f8093d9d45b07ba60a2fc48cc06ba9043 Mon Sep 17 00:00:00 2001 From: sashabeton Date: Mon, 17 Mar 2025 20:11:22 +0100 Subject: [PATCH] internal/ethapi: add a simple DoS protection to authorizations processing in eth_createAccessList --- internal/ethapi/api.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 0a7ade5422..6b77640807 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1171,14 +1171,18 @@ func AccessList(ctx context.Context, b Backend, blockNrOrHash rpc.BlockNumberOrH addressesToExclude[addr] = struct{}{} } - for _, auth := range args.AuthorizationList { - // Duplicating stateTransition.validateAuthorization() logic - if (!auth.ChainID.IsZero() && auth.ChainID.CmpBig(b.ChainConfig().ChainID) != 0) || auth.Nonce+1 < auth.Nonce { - continue - } + // 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 { + // Duplicating stateTransition.validateAuthorization() logic + if (!auth.ChainID.IsZero() && auth.ChainID.CmpBig(b.ChainConfig().ChainID) != 0) || auth.Nonce+1 < auth.Nonce { + continue + } - if authority, err := auth.Authority(); err == nil { - addressesToExclude[authority] = struct{}{} + if authority, err := auth.Authority(); err == nil { + addressesToExclude[authority] = struct{}{} + } } }