Submitted by berndartmueller
The eth_getLogs ETH JSON-RPC method returns an array of all logs matching a given filter criteria, e.g., a topic list Topics and/or a list of addresses (Addresses) that restricts matches to events created by specific contracts.
While Topics is limited to maxTopics = 4, Addresses in unbounded.
minievm:jsonrpc/namespaces/eth/filters/api.go#L366
This can be exploited to DoS the RPC server and bring it to a halt by sending eth_getLogs requests with a large number of addresses in the Addresses field, which takes a considerable amount of time to process.
It should be noted that the JSON-RPC server has a default request body limit of ~10MB, which can be adjusted via the max-recv-msg-size configuration option. This at least limits the Addresses field to a certain extent. However, the below the PoC demonstrates that this is not sufficient and it is still possible to DoS the server.
The same issue, not having an upper bound on the Addresses, is also observed in:
The following estimation shows how many addresses we can fit within a ~10MB JSON-RPC request limit:
So for n addresses:
With a 10MB (10,485,760 bytes) limit:
To account for some request overhead, a more conservative estimate would be around 200,000 addresses.
The following test case demonstrates that by providing 200,000 addresses to the GetLogs function, the request takes more than 5 seconds to complete. This opens up the possibility of a DoS attack by sending a large number of addresses to the GetLogs function and repeating the request to bring the RPC to a halt.
Apply the following git diff and run the Test_GetLogs test with go test -timeout 30s -run ^Test_GetLogs$ ./jsonrpc/namespaces/eth/filters
Consider enforcing an upper limit on the number of Addresses, similar to how its done for Topics.
beer-1 (Initia) confirmed and commented:
LSDan (judge) commented:
beer-1 (Initia) commented:
Initia mitigated:
Status: Mitigation confirmed. Full details in reports from 0xAlix2, berndartmueller and Franfran.
