Skip to content

Commit

Permalink
eth/gasprice: add query limit for FeeHistory to defend DDOS attack (e…
Browse files Browse the repository at this point in the history
…thereum#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
2 people authored and jorgemmsilva committed Jun 17, 2024
1 parent 5934c0b commit 573c19b
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 573c19b

Please sign in to comment.