christoftorres / Horus

A framework to detect attacks and trace stolen assets across Ethereum (FC 2021).
33 stars 11 forks source link

Example transaction yields no results with Reth #1

Open Otto-AA opened 4 months ago

Otto-AA commented 4 months ago

Hi, the example from the README does not yield any results to me.

I guess, the problem is that the tracer does not find all the CALLs that it should find. See the attached trace.json for what it found in my case, using the node Reth hosted on merkle.io.

To debug, it would likely be best if you can check if the expected traces look different with your provider. I've attached a script to make the RPC call with the JS tracer for simple use.

Steps I've performed:

# use --network=host to access the local proxy
docker run --network=host -it christoftorres/horus
cd horus

# merkle RPC does not accept GET apparently, so I replaced it with POST
grep -rl "'GET'" . | xargs sed -i 's/'GET'/'POST'/g'

python3 horus.py -e -tx 0x0ec3f2488a93839524add10ea229e773f6bc891b4eb4794c3337d4495263790b --host localhost --port 8080
python3 horus.py -a

This results in following outputs (note the many 0-byte files):

# ls -l results/
total 4
-rw-r--r-- 1 root root  0 Jun  7 08:54 IntegerOverflow.csv
-rw-r--r-- 1 root root  0 Jun  7 08:54 ParityWalletHack1.csv
-rw-r--r-- 1 root root  0 Jun  7 08:54 ParityWalletHack2.csv
-rw-r--r-- 1 root root  0 Jun  7 08:54 Reentrancy.csv
-rw-r--r-- 1 root root  0 Jun  7 08:54 ReentrancyToken.csv
-rw-r--r-- 1 root root  0 Jun  7 08:54 ShortAddress.csv
-rw-r--r-- 1 root root  0 Jun  7 08:54 UnhandledException.csv
-rw-r--r-- 1 root root 20 Jun  7 08:54 stats.json

# ls -l facts/
total 12
-rw-r--r-- 1 root root   0 Jun  7 08:53 arithmetic.facts
-rw-r--r-- 1 root root  36 Jun  7 08:53 block.facts
-rw-r--r-- 1 root root   0 Jun  7 08:53 call.facts
-rw-r--r-- 1 root root   0 Jun  7 08:53 condition.facts
-rw-r--r-- 1 root root   0 Jun  7 08:53 def.facts
-rw-r--r-- 1 root root   0 Jun  7 08:53 error.facts
-rw-r--r-- 1 root root   0 Jun  7 08:53 selfdestruct.facts
-rw-r--r-- 1 root root 176 Jun  7 08:53 stats.json
-rw-r--r-- 1 root root   0 Jun  7 08:53 storage.facts
-rw-r--r-- 1 root root   0 Jun  7 08:53 throw.facts
-rw-r--r-- 1 root root 509 Jun  7 08:53 transaction.facts
-rw-r--r-- 1 root root   0 Jun  7 08:53 transfer.facts
-rw-r--r-- 1 root root   0 Jun  7 08:53 use.facts

Apart from the souffle version 2.0.2 warning, it does not show any errors/warnings.

Otto-AA commented 4 months ago

I've also tested it with an Erigon node, which raised an Exception: Sadly I don't have access to a Geth instance to test it currently.

From what I know, the nodes try to achieve equal behaviour. So if this is indeed a bug caused by differences in the JS tracing, we could collect the data and open a corresponding issue. However, it would be useful to have access to the expected trace for comparison, which I can't provide myself.

@@@  @@@   @@@@@@   @@@@@@@   @@@  @@@   @@@@@@ 
@@@  @@@  @@@@@@@@  @@@@@@@@  @@@  @@@  @@@@@@@ 
@@!  @@@  @@!  @@@  @@!  @@@  @@!  @@@  !@@     
!@!  @!@  !@!  @!@  !@!  @!@  !@!  @!@  !@!     
@!@!@!@!  @!@  !@!  @!@!!@!   @!@  !@!  !!@@!!  
!!!@!!!!  !@!  !!!  !!@!@!    !@!  !!!   !!@!!! 
!!:  !!!  !!:  !!!  !!: :!!   !!:  !!!       !:!
:!:  !:!  :!:  !:!  :!:  !:!  :!:  !:!      !:! 
::   :::  ::::: ::  ::   :::  ::::: ::  :::: :: 
:   : :   : :  :    :   : :   : :  :   :: : :   

Connecting to http://localhost:8080...
Connected to erigon/2.59.3/linux-amd64/go1.21.5 (mainnet)
Blockchain is in sync.
Latest block: 20039089

An error occured in retrieving the trace: {'code': -32000, 'message': "tracer accessed out of bound stack: size 0, index 0 at step (<eval>:1:3215(796))    in server-side tracer function 'step'"}
Traceback (most recent call last):
  File "horus.py", line 172, in main
    extractor.extract_facts_from_transactions(connection, transactions, blocks, settings.FACTS_FOLDER, args.compress)
  File "/root/horus/extractor/__init__.py", line 447, in extract_facts_from_transactions
    raise e
  File "/root/horus/extractor/__init__.py", line 422, in extract_facts_from_transactions
    raise Exception("An error occured in retrieving the trace: {}".format(trace_response["error"]))
Exception: An error occured in retrieving the trace: {'code': -32000, 'message': "tracer accessed out of bound stack: size 0, index 0 at step (<eval>:1:3215(796))    in server-side tracer function 'step'"}