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

opCodeFinder #1

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

Conversation

JukLee0ira
Copy link

@JukLee0ira JukLee0ira commented Aug 29, 2024

Overview

opCodeFinder.js is a Node.js script designed to search for Ethereum contract addresses that contain specific opcodes within a specified block range. The script scans the blockchain for contracts that match the criteria and outputs the resulting contract addresses to a .txt file.

Requirements

Before you can use opCodeFinder.js, ensure that you have the following environment set up:

  • Node.js: Make sure Node.js is installed on your system. You can download and install it from nodejs.org.
  • Web3.js: The script requires the web3js package to interact with the Ethereum blockchain. You can install it using npm:
    npm install web3

Usage

To run the opCodeFinder.js script, use the following command:

node src\opCodeFinder.js [START_BLOCK] [END_BLOCK] [OPCODE] [RPC_ENDPOINT]

Example

To search for contracts that include the PREVRANDAO opcode on the mainnet, execute the script in your terminal. In this example, 72290000 is a block before the PREVRANDAO opcode was introduced.

node src\opCodeFinder.js 72290000 latest PREVRANDAO https://rpc.ankr.com/xdc

Parameters

  • [START_BLOCK]: The starting block number for the search.
  • [END_BLOCK]: The ending block number or latest for the most recent block.
  • [OPCODE]: The opcode you want to search for.
  • [RPC_ENDPOINT]: The URL of the RPC endpoint.

@JukLee0ira JukLee0ira force-pushed the opCodeFinder branch 6 times, most recently from 26bcf7f to 60e0253 Compare August 31, 2024 13:37
src/opCodeFinder.js Outdated Show resolved Hide resolved
Copy link

@s1na s1na left a comment

Choose a reason for hiding this comment

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

LGTM! Please merge.

@s1na
Copy link

s1na commented Sep 30, 2024

Actually it seems to panic in some cases:

root@vmi1959243:~/Scripts/src# node opCodeFinder.js 79300000 80300000 0x44 "http://0.0.0.0:8989"
Searching for block 79302963 ,total found 2 contracts, 1 of which meet the criteriafile:///root/Scripts/src/opCodeFinder.js:87
            traceObject.result.type === "CREATE" ||
                               ^

TypeError: Cannot read properties of undefined (reading 'type')
    at findContracts (file:///root/Scripts/src/opCodeFinder.js:87:32)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async main (file:///root/Scripts/src/opCodeFinder.js:203:3)

Node.js v20.17.0

@JukLee0ira
Copy link
Author

JukLee0ira commented Oct 8, 2024

Actually it seems to panic in some cases:

root@vmi1959243:~/Scripts/src# node opCodeFinder.js 79300000 80300000 0x44 "http://0.0.0.0:8989"
Searching for block 79302963 ,total found 2 contracts, 1 of which meet the criteriafile:///root/Scripts/src/opCodeFinder.js:87
            traceObject.result.type === "CREATE" ||
                               ^

TypeError: Cannot read properties of undefined (reading 'type')
    at findContracts (file:///root/Scripts/src/opCodeFinder.js:87:32)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async main (file:///root/Scripts/src/opCodeFinder.js:203:3)

Node.js v20.17.0

I reproduced the error and got the transaction hash that caused the issue: 0x518c932989883b0bf9dabb9e904397d5f3d6561ef776ceb5dd8a1de5533212cb. I tried sending a request to the node and received the following response:
Request:

lee@linux01:~$ curl -X POST -H "Content-Type: application/json" --data '{
  "jsonrpc": "2.0",
  "method": "debug_traceTransaction",
  "params": [
    "0x518c932989883b0bf9dabb9e904397d5f3d6561ef776ceb5dd8a1de5533212cb",
    { "tracer": "callTracer" }
  ],
  "id": 1
}' https://rpc.ankr.com/xdc | jq

Response:

{
  "id": "1",
  "jsonrpc": "2.0",
  "error": {
    "code": -32053,
    "message": "API key is not allowed to access method"
  }
}

And in another RPC node:
Request:

lee@linux01:~$ curl -X POST -H "Content-Type: application/json" --data '{
  "jsonrpc": "2.0",
  "method": "debug_traceTransaction",
  "params": [
    "0x518c932989883b0bf9dabb9e904397d5f3d6561ef776ceb5dd8a1de5533212cb",
    { "tracer": "callTracer" }
  ],
  "id": 1
}' https://earpc.xinfin.network/ | jq

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32000,
    "message": "execution timeout"
  }
}

It seems to be an issue with the node.

I haven’t encountered this problem on the private network, so I’ve added code to handle this situation. The code will retry sending the request, record the failed transaction hashes, and skip querying those hashes. If you can provide more information about the node, I can work on finding a complete solution to this issue.

@JukLee0ira JukLee0ira force-pushed the opCodeFinder branch 4 times, most recently from 5c8bf24 to d988667 Compare October 28, 2024 03:41
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.

2 participants