@@ -11,6 +11,8 @@ import (
1111 "github.com/onflow/flow-evm-gateway/storage"
1212)
1313
14+ const LogQueryLimit = 1000
15+
1416// RangeFilter matches all the indexed logs within the range defined as
1517// start and end block height. The start must be strictly smaller or equal than end value.
1618type RangeFilter struct {
@@ -24,6 +26,10 @@ func NewRangeFilter(
2426 criteria filters.FilterCriteria ,
2527 receipts storage.ReceiptIndexer ,
2628) (* RangeFilter , error ) {
29+ if ! ValidCriteriaLimits (criteria ) {
30+ return nil , errs .ErrExceedLogQueryLimit
31+ }
32+
2733 // make sure that beginning number is not bigger than end
2834 if start > end {
2935 return nil , fmt .Errorf (
@@ -100,6 +106,10 @@ func NewIDFilter(
100106 blocks storage.BlockIndexer ,
101107 receipts storage.ReceiptIndexer ,
102108) (* IDFilter , error ) {
109+ if ! ValidCriteriaLimits (criteria ) {
110+ return nil , errs .ErrExceedLogQueryLimit
111+ }
112+
103113 if criteria .BlockHash == nil {
104114 return nil , fmt .Errorf ("filter criteria should have a non-nil block hash" )
105115 }
@@ -161,6 +171,20 @@ func ExactMatch(log *gethTypes.Log, criteria filters.FilterCriteria) bool {
161171 return slices .Contains (criteria .Addresses , log .Address )
162172}
163173
174+ func ValidCriteriaLimits (criteria filters.FilterCriteria ) bool {
175+ if len (criteria .Addresses ) > LogQueryLimit {
176+ return false
177+ }
178+
179+ for _ , topics := range criteria .Topics {
180+ if len (topics ) > LogQueryLimit {
181+ return false
182+ }
183+ }
184+
185+ return true
186+ }
187+
164188// bloomMatch takes a bloom value and tests if the addresses and topics provided pass the bloom filter.
165189// This acts as a fast probabilistic test that might produce false-positives but not false-negatives.
166190// If true is returned we should further check against the exactMatch to really make sure the log is matched.
0 commit comments