hyperledger / besu

An enterprise-grade Java-based, Apache 2.0 licensed Ethereum client https://wiki.hyperledger.org/display/besu
https://www.hyperledger.org/projects/besu
Apache License 2.0
1.49k stars 814 forks source link

`evmtool` Returns Long Null String in JSON `error` Field When Executing `REVERT` #7608

Open Alleysira opened 1 month ago

Alleysira commented 1 month ago

Description

Hello developers!

I'm doing fuzzing on EVM implementations, and I'm using besu/evm-tool for testing. I found a log error that when executing the opcode REVERT(0XFD), the getRevertReason() of besu/evm-tool will return a long null string in the error field of json when no revert reason is available, such as \u0000\u0000.

Steps to Reproduce

  1. I try to reproduce this on the latest develop version of besu/evm-tool(6ed1db32ae3c1b5bdc0576321fee35157feb6ae4). I build evmtool with:
    ./gradlew --parallel ethereum:evmTool:installDist 
  2. The bytecode to be executed:
    # BYTECODE
    60255ffd
    # MENMONICS
    PUSH1 25 //size
    PUSH0 //offset
    REVERT
  3. Run the besu/evm-tool with:
    ./ethereum/evmtool/build/install/evmtool/bin/evmtool --code 60255ffd --json

    Expected behavior: If no Revert reason is available, no error field is needed.

Actual behavior: evmtool will output meaningless \u0000s.

{"pc":0,"op":96,"gas":"0x2540be400","gasCost":"0x3","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"PUSH1"}
{"pc":2,"op":95,"gas":"0x2540be3fd","gasCost":"0x2","memSize":0,"stack":["0x25"],"depth":1,"refund":0,"opName":"PUSH0"}
{"pc":3,"op":253,"gas":"0x2540be3fb","gasCost":"0x6","memSize":0,"stack":["0x25","0x0"],"depth":1,"refund":0,"opName":"REVERT","error":"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"}

{"stateRoot":"0x24ac5f36f02918efac8340b49f4cb41f45ac0bedb8dcfa511b4bfac6da08299a","output":"0x00000000000000000000000000000000000000000000000000000000000000000000000000","gasUsed":"0xb","pass":true,"fork":"Cancun","timens":4076285,"time":4076}

Frequency: Always.

Logs (if a bug)

This is a reference result from geth/evm:

{"pc":0,"op":96,"gas":"0xffffff","gasCost":"0x3","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"PUSH1"}
{"pc":2,"op":95,"gas":"0xfffffc","gasCost":"0x2","memSize":0,"stack":["0x25"],"depth":1,"refund":0,"opName":"PUSH0"}
{"pc":3,"op":253,"gas":"0xfffffa","gasCost":"0x6","memSize":0,"stack":["0x25","0x0"],"depth":1,"refund":0,"opName":"REVERT"}
{"pc":3,"op":253,"gas":"0xfffffa","gasCost":"0x6","memory":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","memSize":64,"stack":[],"depth":1,"refund":0,"opName":"REVERT","error":"execution reverted"}
{"output":"00000000000000000000000000000000000000000000000000000000000000000000000000","gasUsed":"0xb","error":"execution reverted"}

Versions (Add all that apply)

Thanks for your time!

itfat commented 5 days ago

@siladu please assign this issue to me