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

The `gasLimit` configuration in `genesis.json` is not being recognized by `evmtool` #7432

Closed Alleysira closed 1 month ago

Alleysira commented 2 months ago

Description

Hello developers!

I'm doing fuzzing on EVM implementations, and I'm usingbesu/evm-tool for testing. I found that the opcode GASLIMIT (0X45) returned hardcoded value 5000(0x1388) in:

https://github.com/hyperledger/besu/blob/a92fdbb44c4c20416643903d9fa288ffdc4929b6/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EvmToolCommand.java#L468

However, according to the docs at evm-tool and genesis, the gasLimit can be set using --prestate genesis.json or --genesis genesis.json but besu/evm-tool seems to ignore the setting, while the alloc setting works fine.

Steps to Reproduce (Bug)

  1. I try to reproduce this on the latest develop version of besu/evm-tool with docker image(digest: e79d839a699b). I also compiled the evmtool locally(commit: 7433c8c25a5c), got the same result. This the genesis.json file I provided:
{
    "config": {
      "chainId": 9599,
      "shanghaiBlock": 0
    },
    "alloc": {
      "0x1c7cd2d37ffd63856a5bd56a9af1643f2bcf545f": {
        "balance": "0xffffffffffffffffffffffffffffffffffffffff"
      }
    },
    "coinbase": "0x000000000000000000000000000000000000abcd",
    "difficulty": "1",
    "extraData": "",
    "gasLimit": "0xffffff",
    "nonce": "0x0",
    "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "timestamp": "0x00"
}
  1. The bytecode to be executed:
# BYTECODE
4560005260406000f3
# MENMONICS
GASLIMIT
PUSH1 00
MSTORE
PUSH1 40
PUSH1 00
RETURN
  1. Run the besu/evm-tool with:
docker run --rm  -i -v ${PWD}/genesis.json:/opt/data/genesis.json hyperledger/besu-evmtool:develop --code 4560005260406000f3 --json --notime --genesis /opt/data/genesis.json
  1. Results: besu/evm-tool returned 0x1388.
{"pc":0,"op":69,"gas":"0x2540be400","gasCost":"0x2","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"GASLIMIT"}
{"pc":1,"op":96,"gas":"0x2540be3fe","gasCost":"0x3","memSize":0,"stack":["0x1388"],"depth":1,"refund":0,"opName":"PUSH1"}
{"pc":3,"op":82,"gas":"0x2540be3fb","gasCost":"0x6","memSize":0,"stack":["0x1388","0x0"],"depth":1,"refund":0,"opName":"MSTORE"}
{"pc":4,"op":96,"gas":"0x2540be3f5","gasCost":"0x3","memSize":32,"stack":[],"depth":1,"refund":0,"opName":"PUSH1"}
{"pc":6,"op":96,"gas":"0x2540be3f2","gasCost":"0x3","memSize":32,"stack":["0x40"],"depth":1,"refund":0,"opName":"PUSH1"}
{"pc":8,"op":243,"gas":"0x2540be3ef","gasCost":"0x3","memSize":32,"stack":["0x40","0x0"],"depth":1,"refund":0,"opName":"RETURN"}

{"gasUser":"0x14","gasTotal":"0x14","output":"0x00000000000000000000000000000000000000000000000000000000000013880000000000000000000000000000000000000000000000000000000000000000"}

Expected behavior: besu/evmtool should return 0xffffff, which is thegasLimit set in the file genesis.json.

Actual behavior: besu/evmtool ignored the gasLimit setting in, returned 0x1388

Frequency: 100%

Logs (if a bug)

See the results.

Versions (Add all that apply)

Thanks for your time and patience!

jframe commented 1 month ago

@shemnon Any thoughts on this?