From 13f209ff47f8b38720d25caa6959ea5f90bf8a67 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Mon, 15 Apr 2024 10:43:03 +0200 Subject: [PATCH 1/2] eth/filters: enforce topic-limit early on filter criterias --- eth/filters/api.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/eth/filters/api.go b/eth/filters/api.go index 59103ac03ca6..ce725ea4fc5c 100644 --- a/eth/filters/api.go +++ b/eth/filters/api.go @@ -539,6 +539,9 @@ func (args *FilterCriteria) UnmarshalJSON(data []byte) error { return errors.New("invalid addresses in query") } } + if len(raw.Topics) > maxTopics { + return errExceedMaxTopics + } // topics is an array consisting of strings and/or arrays of strings. // JSON null values are converted to common.Hash{} and ignored by the filter manager. @@ -559,6 +562,9 @@ func (args *FilterCriteria) UnmarshalJSON(data []byte) error { case []interface{}: // or case e.g. [null, "topic0", "topic1"] + if len(topic) > maxTopics { + return errExceedMaxTopics + } for _, rawTopic := range topic { if rawTopic == nil { // null component, match all From 5a91d23df703b4cc5c2a53f0550f3269db757f02 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Mon, 15 Apr 2024 14:25:08 +0200 Subject: [PATCH 2/2] eth/filters: change limit to 1K --- eth/filters/api.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/eth/filters/api.go b/eth/filters/api.go index ce725ea4fc5c..56a9de1b215f 100644 --- a/eth/filters/api.go +++ b/eth/filters/api.go @@ -43,6 +43,9 @@ var ( // The maximum number of topic criteria allowed, vm.LOG4 - vm.LOG0 const maxTopics = 4 +// The maximum number of allowed topics within a topic criteria +const maxSubTopics = 1000 + // filter is a helper struct that holds meta information over the filter type // and associated subscription in the event system. type filter struct { @@ -562,7 +565,7 @@ func (args *FilterCriteria) UnmarshalJSON(data []byte) error { case []interface{}: // or case e.g. [null, "topic0", "topic1"] - if len(topic) > maxTopics { + if len(topic) > maxSubTopics { return errExceedMaxTopics } for _, rawTopic := range topic {