zemse / hardhat-tracer

🕵️ allows you to see internal calls, events and storage operations in the console
MIT License
351 stars 36 forks source link

Unable to find a block containing transaction #19

Closed fulldecent closed 1 year ago

fulldecent commented 1 year ago

I am trying to use hardhat-tracer in this way:

  1. npx hardhat node --fork https://mainnet.infura.io/v3/xxxxAPIxKEYxxxxxx open in one terminal
  2. node aScript.js in another terminal with ethers.providers.JsonRpcProvider("http://127.0.0.1:8545/")
  3. npx hardhat trace --hash 0xxxxxxTXxIDxxxxxx --rpc http://127.0.0.1:8545/ in a third terminal

Hardhat is configured to fork Ethereum Mainnet.

The contract being traced is not built using Hardhat, I'm doing a reverse engineering/blackbox inspection task.


This produces an error (the third terminal) with:

ALL UnknownContractAndFunction(to=0xREDACTED, input=0xREDACTED, ret=0x)
   EVENT <UnknownContract 0xREDACTED>.UnknownEvent(0xREDACTED, [0xREDACTED, 0xREDACTED, 0xREDACTED, 0xREDACTED])
Trying with hardhat mainnet fork
Error in printDebugTraceElseLogs: InvalidInputError: Unable to find a block containing transaction 0xREDACTED
    at HardhatNode.traceTransaction (/Users/williamentriken/Developer/REDACTED/node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:1335:13)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at HardhatNetworkProvider.request (/Users/williamentriken/Developer/REDACTED/node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:118:18)
    at printDebugTrace (/Users/williamentriken/Developer/REDACTED/node_modules/hardhat-tracer/src/print/debug-trace.ts:14:17)
    at printDebugTraceOrLogs (/Users/williamentriken/Developer/REDACTED/node_modules/hardhat-tracer/src/print/index.ts:18:7)
    at SimpleTaskDefinition.action (/Users/williamentriken/Developer/REDACTED/node_modules/hardhat-tracer/src/tasks/trace.ts:82:22)
    at Environment._runTaskDefinition (/Users/williamentriken/Developer/REDACTED/node_modules/hardhat/src/internal/core/runtime-environment.ts:308:14)
    at Environment.run (/Users/williamentriken/Developer/REDACTED/node_modules/hardhat/src/internal/core/runtime-environment.ts:156:14)
    at main (/Users/williamentriken/Developer/REDACTED/node_modules/hardhat/src/internal/cli/cli.ts:272:7)
If you think the above error is a bug, please report it to https://github.com/zemse/hardhat-tracer/issues/new, meanwhile falling back to --logs:
An unexpected error occurred:

TypeError: Cannot read properties of null (reading 'to')
    at printTopLevelTx (/Users/williamentriken/Developer/REDACTED/node_modules/hardhat-tracer/src/print/top-level-tx.ts:18:8)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at printLogs (/Users/williamentriken/Developer/REDACTED/node_modules/hardhat-tracer/src/print/logs.ts:19:3)
    at printDebugTraceOrLogs (/Users/williamentriken/Developer/REDACTED/node_modules/hardhat-tracer/src/print/index.ts:34:7)
    at SimpleTaskDefinition.action (/Users/williamentriken/Developer/REDACTED/node_modules/hardhat-tracer/src/tasks/trace.ts:82:22)
    at Environment._runTaskDefinition (/Users/williamentriken/Developer/REDACTED/node_modules/hardhat/src/internal/core/runtime-environment.ts:308:14)
    at Environment.run (/Users/williamentriken/Developer/REDACTED/node_modules/hardhat/src/internal/core/runtime-environment.ts:156:14)
    at main (/Users/williamentriken/Developer/REDACTED/node_modules/hardhat/src/internal/cli/cli.ts:272:7)

I can see from terminal 2, this is how the tracer is driving Hardhat (terminal 1):

eth_getTransactionByHash
eth_blockNumber
debug_traceTransaction
eth_getTransactionByHash
eth_getCode (2)

Please advise if I am using hardhat-tracer in a supported way and how I could achieve this.

zemse commented 1 year ago

Your usage is correct. The trace for the transaction is just the first two lines, the logic doesn't stop there which is a bug.

ALL UnknownContractAndFunction(to=0xREDACTED, input=0xREDACTED, ret=0x)
   EVENT <UnknownContract 0xREDACTED>.UnknownEvent(0xREDACTED, [0xREDACTED, 0xREDACTED, 0xREDACTED, 0xREDACTED])

// You can ignore things after that. 

The fix is just released in hardhat-tracer@1.1.1. Sorry for the delay in response, if you get chance to try this out, do lmk if there are any further issues with this.

fulldecent commented 1 year ago

Perfect, thank you!

And I was able to use this (undocumented?) usage to get what I wanted:

npx hardhat trace --fulltrace --hash 0xxxxxxTXxIDxxxxxx --rpc http://127.0.0.1:8545/