Skip to content

eth/filters: add address limit to filters #31876

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ceyonur
Copy link
Contributor

@ceyonur ceyonur commented May 22, 2025

The address filter was never checked against a maximum limit, which can be somewhat abusive for API nodes. This PR adds a limit similar to topics

Description (AI generated)

This pull request introduces a new validation to enforce a maximum limit on the number of addresses allowed in filter criteria for Ethereum logs. It includes updates to the FilterAPI and EventSystem logic, as well as corresponding test cases to ensure the new constraint is properly enforced.

Core functionality changes:

  • Validation for maximum addresses in filter criteria:
    • Added a new constant, maxAddresses, set to 100, to define the maximum allowable addresses in a filter.
    • Introduced a new error, errExceedMaxAddresses, to handle cases where the number of addresses exceeds the limit.
    • Updated the GetLogs method in FilterAPI to validate the number of addresses against maxAddresses.
    • Modified the UnmarshalJSON method to return an error if the number of addresses in the input JSON exceeds maxAddresses.
    • Added similar validation to the SubscribeLogs method in EventSystem.

Test updates:

  • New test cases for address limit validation:
    • Added a test in TestUnmarshalJSONNewFilterArgs to verify that exceeding the maximum number of addresses triggers the errExceedMaxAddresses error.
    • Updated TestInvalidLogFilterCreation to include a test case for an invalid filter with more than maxAddresses addresses.
    • Updated TestInvalidGetLogsRequest to test for invalid log requests with excessive addresses.

These changes ensure that the system enforces a reasonable limit on the number of addresses in filter criteria, improving robustness and preventing potential performance issues.

@ceyonur ceyonur requested a review from rjl493456442 as a code owner May 22, 2025 14:22
Comment on lines 462 to 464
1: {BlockHash: &blockHash, ToBlock: big.NewInt(500)},
2: {BlockHash: &blockHash, FromBlock: big.NewInt(rpc.LatestBlockNumber.Int64())},
3: {BlockHash: &blockHash, Topics: [][]common.Hash{{}, {}, {}, {}, {}}},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

none of these cases actually working at the moment a fix is put here:
#31877

@fjl fjl changed the title filters: add address limit to filters eth/filters: add address limit to filters May 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant