Skip to content

Commit 958331e

Browse files
holimanstwiname
authored andcommitted
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 b079771 commit 958331e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

eth/filters/api.go

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

47+
// The maximum number of allowed topics within a topic criteria
48+
const maxSubTopics = 1000
49+
4750
// filter is a helper struct that holds meta information over the filter type
4851
// and associated subscription in the event system.
4952
type filter struct {
@@ -620,7 +623,6 @@ func (args *TxFilterCriteria) UnmarshalJSON(data []byte) error {
620623
// data is an array consisting of strings.
621624
// JSON null values are converted to common.Hash{} and ignored by the filter manager.
622625
if len(raw.SigHashes) > 0 {
623-
624626
parsed, err := decodeSigHashes(raw.SigHashes)
625627
if err != nil {
626628
return err
@@ -694,6 +696,10 @@ func decodeTopics(input []interface{}) ([][]common.Hash, error) {
694696
return nil, nil
695697
}
696698

699+
if len(input) > maxTopics {
700+
return nil, errExceedMaxTopics
701+
}
702+
697703
result := make([][]common.Hash, len(input))
698704

699705
for i, t := range input {
@@ -711,6 +717,9 @@ func decodeTopics(input []interface{}) ([][]common.Hash, error) {
711717

712718
case []interface{}:
713719
// or case e.g. [null, "topic0", "topic1"]
720+
if len(topic) > maxSubTopics {
721+
return nil, errExceedMaxTopics
722+
}
714723
for _, rawTopic := range topic {
715724
if rawTopic == nil {
716725
// null component, match all

0 commit comments

Comments
 (0)