Skip to content

Commit

Permalink
eth/filters: enforce topic-limit early on filter criterias (ethereum#…
Browse files Browse the repository at this point in the history
…29535)

This PR adds a limit of 1000 to the "inner" topics in a filter-criteria
  • Loading branch information
holiman authored and stwiname committed Apr 21, 2024
1 parent b079771 commit 958331e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion eth/filters/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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 {
Expand Down Expand Up @@ -620,7 +623,6 @@ func (args *TxFilterCriteria) UnmarshalJSON(data []byte) error {
// data is an array consisting of strings.
// JSON null values are converted to common.Hash{} and ignored by the filter manager.
if len(raw.SigHashes) > 0 {

parsed, err := decodeSigHashes(raw.SigHashes)
if err != nil {
return err
Expand Down Expand Up @@ -694,6 +696,10 @@ func decodeTopics(input []interface{}) ([][]common.Hash, error) {
return nil, nil
}

if len(input) > maxTopics {
return nil, errExceedMaxTopics
}

result := make([][]common.Hash, len(input))

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

case []interface{}:
// or case e.g. [null, "topic0", "topic1"]
if len(topic) > maxSubTopics {
return nil, errExceedMaxTopics
}
for _, rawTopic := range topic {
if rawTopic == nil {
// null component, match all
Expand Down

0 comments on commit 958331e

Please sign in to comment.