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

cmd/evm ignores the baseFeePerGas setting in genesis.json when executing opcode BASEFEE #30279

Closed
Alleysira opened this issue Aug 8, 2024 · 1 comment · Fixed by #30281
Closed

Comments

@Alleysira
Copy link

System information

Geth version: evm version 1.14.5-stable-0dd173a7 and evm version 1.14.8-unstable-978041fe
CL client & version: Nope
OS & Version: Ubuntu 20.04
Commit hash : Nope

Expected behaviour

Hello developers,

I'm currently testing EVM implementations and have encountered a peculiar issue. When executing the BASEFEE opcode (0x48), evm will return 0x3b9aca00(1000000000) instead of the value provided in genesis.json .

Steps to reproduce the behaviour

I used the latest version of geth image pulled from dockerhub(digest bb0eb0bd6) to reproduce this bug.

docker pull ethereum/client-go:alltools-latest
docker run ethereum/client-go:alltools-latest tail -f /dev/null
docker exec -it containerid /bin/sh

This is the genesis.json file for --prestate, which sets the baseFee to 0xffff.

{
  "config": {
    "chainId": 9599,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0,
    "berlinBlock": 0,
    "londonBlock": 0,
    "shanghaiBlock": 0,
    "shanghaiTime":0
  },
  "alloc": {
    "0x1c7cd2d37ffd63856a5bd56a9af1643f2bcf545f": {
     "balance": "0x1234"
    }
  },
  "coinbase": "0x000000000000000000000000000000000000abcd",
  "difficulty": "0x0",
  "extraData": "",
  "gasLimit": "0xffffff",
  "nonce": "0x0000000000000042",
  "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp": "0x00",
  "baseFeePerGas": "0xffff"
}

Use evm to run the bytecode 4860005260406000f3 .

evm --debug --gas 0xffffff --nomemory=false --json --code 4860005260406000f3 --prestate ./genesis.json run

The mnemonics of the bytecode are as follows.

BASEFEE
PUSH1 00
MSTORE
PUSH1 40
PUSH1 00
RETURN 

The result from evm's output, the stack output of BASEFEE is 0x3b9aca00.

{"pc":0,"op":72,"gas":"0xffffff","gasCost":"0x2","memSize":0,"stack":[],"depth":1,"refund":0,"opName":"BASEFEE"}
{"pc":1,"op":96,"gas":"0xfffffd","gasCost":"0x3","memSize":0,"stack":["0x3b9aca00"],"depth":1,"refund":0,"opName":"PUSH1"}
{"pc":3,"op":82,"gas":"0xfffffa","gasCost":"0x6","memSize":0,"stack":["0x3b9aca00","0x0"],"depth":1,"refund":0,"opName":"MSTORE"}
{"pc":4,"op":96,"gas":"0xfffff4","gasCost":"0x3","memory":"0x000000000000000000000000000000000000000000000000000000003b9aca00","memSize":32,"stack":[],"depth":1,"refund":0,"opName":"PUSH1"}
{"pc":6,"op":96,"gas":"0xfffff1","gasCost":"0x3","memory":"0x000000000000000000000000000000000000000000000000000000003b9aca00","memSize":32,"stack":["0x40"],"depth":1,"refund":0,"opName":"PUSH1"}
{"pc":8,"op":243,"gas":"0xffffee","gasCost":"0x3","memory":"0x000000000000000000000000000000000000000000000000000000003b9aca00","memSize":32,"stack":["0x40","0x0"],"depth":1,"refund":0,"opName":"RETURN"}
{"output":"000000000000000000000000000000000000000000000000000000003b9aca000000000000000000000000000000000000000000000000000000000000000000","gasUsed":"0x14"}

Backtrace

I checked in evm version 1.14.8-unstable-978041fe and evm version 1.14.5-stable-0dd173a7, the problem occured in both versions.

It seems that the baseFeePerGas in genesis.json is just ignored.

runtimeConfig := runtime.Config{
Origin: sender,
State: statedb,
GasLimit: initialGas,
GasPrice: flags.GlobalBig(ctx, PriceFlag.Name),
Value: flags.GlobalBig(ctx, ValueFlag.Name),
Difficulty: genesisConfig.Difficulty,
Time: genesisConfig.Timestamp,
Coinbase: genesisConfig.Coinbase,
BlockNumber: new(big.Int).SetUint64(genesisConfig.Number),
BlobHashes: blobHashes,
BlobBaseFee: blobBaseFee,
EVMConfig: vm.Config{
Tracer: tracer,
},

Thanks for your time!

@holiman
Copy link
Contributor

holiman commented Aug 8, 2024

Thanks for providing a detailed "how to repro"!

@holiman holiman closed this as completed in 83e70aa Aug 8, 2024
rjl493456442 pushed a commit to rjl493456442/go-ethereum that referenced this issue Aug 13, 2024
fixes ethereum#30279 -- previously we did not use the basefee from the genesis, and instead the defaults were used from `runtime.go/setDefaults`-function
leeren pushed a commit to storyprotocol/story-geth that referenced this issue Aug 16, 2024
fixes ethereum#30279 -- previously we did not use the basefee from the genesis, and instead the defaults were used from `runtime.go/setDefaults`-function
This issue was closed.
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 a pull request may close this issue.

2 participants