Skip to content
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

Validate that FromBlock/ToBlock epoch is indeed a hex value #10780

Merged
merged 2 commits into from
May 9, 2023

Conversation

fridrik01
Copy link
Contributor

@fridrik01 fridrik01 commented Apr 28, 2023

Context
When calling ETH rpc method eth_getLogs and giving it a fromBlock/toBlock as epoch then return an error if its not in a hexadecimal format (instead of silently passing through and returning nothing or even worse potentially giving incorrect results)

Test plan

Verify that giving epoch ("2812200") as decimal returns a nice error:

curl -s http://localhost:1234/rpc/v1  -X POST -H "Content-Type: application/json" --data '{"method":"eth_getLogs","params":[{"fromBlock": "2812200"}],"id":1,"jsonrpc":"2.0"}'
{"jsonrpc":"2.0","id":1,"error":{"code":1,"message":"FromBlock is not a hex"}}

And that giving the same epoch in hex ("0x2AE928") works:

curl -s http://localhost:1234/rpc/v1  -X POST -H "Content-Type: application/json" --data '{"method":"eth_getLogs","params":[{"fromBlock": "0x2AE928"}],"id":1,"jsonrpc":"2.0"}'|jq|head -n 15
{
  "jsonrpc": "2.0",
  "result": [
    {
      "address": "0xa35bf7ef23b09fb099e6e75a078727dff14b7576",
      "data": "0x0000000000000000000000000000000000000000000000000429d069189e0000",
      "topics": [
        "0xe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c",
        "0x0000000000000000000000006c29c4366a2f9ac5f083ef3394d9849b02a690c0"
      ],
      "removed": false,
      "logIndex": "0x0",
      "transactionIndex": "0x3f",
      "transactionHash": "0xce8a0e185d8e64ea5a9aeae51fde7f46aaa57239d1e3ce351759ccd9fb604c69",
      "blockHash": "0x3aa8d8603c95936cc964c64951bc75af118c5f79a8e81c8130281ec62ef98130",

@fridrik01 fridrik01 marked this pull request as ready for review April 28, 2023 09:42
@fridrik01 fridrik01 requested a review from a team as a code owner April 28, 2023 09:42
Copy link
Contributor

@arajasek arajasek left a comment

Choose a reason for hiding this comment

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

LGTM, but let's add a very simple test to eth_filter_test.go for this.

@fridrik01 fridrik01 force-pushed the add-eth-getlogs-validation branch from b8e3a64 to cf17fa1 Compare May 5, 2023 09:53
@fridrik01
Copy link
Contributor Author

LGTM, but let's add a very simple test to eth_filter_test.go for this.

@arajasek I added a simple test for passing invalid from/to blocknumber

@Stebalien Stebalien merged commit ceb3f1e into master May 9, 2023
@Stebalien Stebalien deleted the add-eth-getlogs-validation branch May 9, 2023 21:17
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.

3 participants