Skip to content

Commit 42e699e

Browse files
NathanBSCzlacfzy
authored andcommitted
eth/gasprice: add query limit for FeeHistory to defend DDOS attack (ethereum#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>
1 parent 9d58c70 commit 42e699e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

eth/gasprice/feehistory.go

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const (
4242
// maxBlockFetchers is the max number of goroutines to spin up to pull blocks
4343
// for the fee history calculation (mostly relevant for LES).
4444
maxBlockFetchers = 4
45+
maxQueryLimit = 100
4546
)
4647

4748
// blockFees represents a single block for processing
@@ -219,6 +220,9 @@ func (oracle *Oracle) FeeHistory(ctx context.Context, blocks uint64, unresolvedL
219220
if len(rewardPercentiles) != 0 {
220221
maxFeeHistory = oracle.maxBlockHistory
221222
}
223+
if len(rewardPercentiles) > maxQueryLimit {
224+
return common.Big0, nil, nil, nil, fmt.Errorf("%w: over the query limit %d", errInvalidPercentile, maxQueryLimit)
225+
}
222226
if blocks > maxFeeHistory {
223227
log.Warn("Sanitizing fee history length", "requested", blocks, "truncated", maxFeeHistory)
224228
blocks = maxFeeHistory

0 commit comments

Comments
 (0)