Skip to content

Commit 7bcb553

Browse files
committed
eth/filters: enforce topic-limit early on filter criterias (ethereum#29535)
This PR adds a limit of 1000 to the "inner" topics in a filter-criteria
1 parent e343ddf commit 7bcb553

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

eth/filters/api.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ var (
4343
// The maximum number of topic criteria allowed, vm.LOG4 - vm.LOG0
4444
const maxTopics = 4
4545

46+
// The maximum number of allowed topics within a topic criteria
47+
const maxSubTopics = 1000
48+
4649
// filter is a helper struct that holds meta information over the filter type
4750
// and associated subscription in the event system.
4851
type filter struct {
@@ -545,6 +548,9 @@ func (args *FilterCriteria) UnmarshalJSON(data []byte) error {
545548
return errors.New("invalid addresses in query")
546549
}
547550
}
551+
if len(raw.Topics) > maxTopics {
552+
return errExceedMaxTopics
553+
}
548554

549555
// topics is an array consisting of strings and/or arrays of strings.
550556
// JSON null values are converted to common.Hash{} and ignored by the filter manager.
@@ -565,6 +571,9 @@ func (args *FilterCriteria) UnmarshalJSON(data []byte) error {
565571

566572
case []interface{}:
567573
// or case e.g. [null, "topic0", "topic1"]
574+
if len(topic) > maxSubTopics {
575+
return errExceedMaxTopics
576+
}
568577
for _, rawTopic := range topic {
569578
if rawTopic == nil {
570579
// null component, match all

0 commit comments

Comments
 (0)