go-ethereum/eth/filters
Ceyhun Onur 1f4ea4d162
eth/filters: add address limit to filters (#31876)
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.

---------

Co-authored-by: zsfelfoldi <zsfelfoldi@gmail.com>
2025-07-01 08:13:19 +02:00
..
api.go eth/filters: add address limit to filters (#31876) 2025-07-01 08:13:19 +02:00
api_test.go eth/filters: add address limit to filters (#31876) 2025-07-01 08:13:19 +02:00
filter.go eth/filters: add timestamp to derived logs (#31887) 2025-06-10 11:52:02 +02:00
filter_system.go eth/filters: add address limit to filters (#31876) 2025-07-01 08:13:19 +02:00
filter_system_test.go eth/filters: add address limit to filters (#31876) 2025-07-01 08:13:19 +02:00
filter_test.go core: consolidate BlockChain constructor options (#31925) 2025-06-19 12:21:15 +02:00