Skip to content

Estimate gas chooses wrong instruction set at genesis #29404

@lightclient

Description

@lightclient

Bug

$ geth --dev dumpgenesis > genesis.json
$ geth --dev --datadir=data init genesis.json
$ geth --dev --datadir=data console
> eth.estimateGas({from: "0xd67dC7d443C902bd6ABfBc91C9E2E6906f55Ca46", data: "0x5959f3"})
Error: invalid opcode: PUSH0
        at web3.js:6382:9(39)
        at send (web3.js:5116:62(29))
        at <eval>:1:16(7)

Culprit

We determine random value based on if difficulty is set:

go-ethereum/core/evm.go

Lines 62 to 64 in a382917

if header.Difficulty.Cmp(common.Big0) == 0 {
random = &header.MixDigest
}

But then here we use it as isMerge for creating the chain rules.

chainRules: chainConfig.Rules(blockCtx.BlockNumber, blockCtx.Random != nil, blockCtx.Time),

The chain rules then dictate the instruction set, so we choose London instructions instead of Shanghai.

Resolution

I guess the main question is should we support this behavior. Is the genesis block technically considered post-merge? A simple fix would be to change the value that goes into Rules(..) to be blockCtx.Random != nil || chainConfig.TerminalTotalDifficultyPassed. But this doesn't feel too great either.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions