Skip to content

Commit

Permalink
eth/gasprice: add query limit for FeeHistory to defend DDOS attack (#…
Browse files Browse the repository at this point in the history
…29644)

* eth/gasprice: add query limit for FeeHistory to defend DDOS attack

* fix return values after cherry-pick

---------

Co-authored-by: Eric <45141191+zlacfzy@users.noreply.github.com>
  • Loading branch information
NathanBSC and zlacfzy committed May 7, 2024
1 parent 3e896c8 commit e4b8058
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions eth/gasprice/feehistory.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const (
// maxBlockFetchers is the max number of goroutines to spin up to pull blocks
// for the fee history calculation (mostly relevant for LES).
maxBlockFetchers = 4
maxQueryLimit = 100
)

// blockFees represents a single block for processing
Expand Down Expand Up @@ -240,6 +241,9 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blocks uint64, unresolvedL
if len(rewardPercentiles) != 0 {
maxFeeHistory = oracle.maxBlockHistory
}
if len(rewardPercentiles) > maxQueryLimit {
return common.Big0, nil, nil, nil, nil, nil, fmt.Errorf("%w: over the query limit %d", errInvalidPercentile, maxQueryLimit)
}
if blocks > maxFeeHistory {
log.Warn("Sanitizing fee history length", "requested", blocks, "truncated", maxFeeHistory)
blocks = maxFeeHistory
Expand Down

0 comments on commit e4b8058

Please sign in to comment.