Skip to content

t8n: CHAINID opcode ignores --state.chainid (hardcoded to 1) #1486

@chfast

Description

@chfast

Summary

evmone-t8n returns CHAINID = 1 even when run with a different --state.chainid.

The same tx/env/alloc produces different post-state vs geth evm t8n when the contract executes CHAINID.

Reproducer (Cancun, chain id = 2)

alloc.json

{
  "0x095e7baea6a6c7c4c2dfeb977efac326af552d87": {
    "code": "0x4660005500",
    "nonce": "0x0",
    "balance": "0x0",
    "storage": {}
  },
  "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b": {
    "code": "0x",
    "nonce": "0x0",
    "balance": "0xde0b6b3a7640000",
    "storage": {}
  }
}

env.json

{
  "currentCoinbase": "0x8888f1f195afa192cfee860698584c030f4c9db1",
  "currentNumber": "0x01",
  "currentTimestamp": "0x54c99069",
  "currentGasLimit": "0x2fefd8",
  "currentRandom": "0x0000000000000000000000000000000000000000000000000000000000000001",
  "parentBeaconBlockRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "currentBaseFee": "0x1",
  "currentExcessBlobGas": "0x0",
  "withdrawals": []
}

txs.json

[
  {
    "chainId": "0x2",
    "gas": "0x186a0",
    "gasPrice": "0x1",
    "hash": "0x0c22569888cd0d60438efe2aa73f0432747521c0b00ae6d23438460a3472b6fd",
    "input": "0x",
    "nonce": "0x0",
    "r": "0x4b2e52f9747df7f24e93ee6f19a920dcf6bab9696cabf27c5e662f5cbf2baf4d",
    "s": "0x6d2be974c69cbcf0965c2e69bc02300702575bcd6ee3c21abe2a84aad25a4eac",
    "sender": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
    "to": "0x095e7baea6a6c7c4c2dfeb977efac326af552d87",
    "v": "0x27",
    "value": "0x0"
  }
]

Commands

# evmone
evmone-t8n \
  --state.fork Cancun --state.chainid 2 \
  --input.alloc alloc.json --input.env env.json --input.txs txs.json \
  --output.basedir out-evmone --output.result result.json --output.alloc alloc.json

# geth
evm t8n \
  --state.fork Cancun --state.chainid 2 \
  --input.alloc alloc.json --input.env env.json --input.txs txs.json \
  --output.basedir out-geth --output.result result.json --output.alloc alloc.json

Observed divergence

  • txRoot and receiptsRoot match.
  • stateRoot differs:
    • evmone: 0x37bdda8f0c6377867644e4dca47b1a57e529c3b0f16cdef6d15e6674fff411ee
    • geth: 0xa15bdc8810f73f3f6831d201a3b01a7fe3fc31f56593fb94c30bb2272a4ff1de
  • Contract storage slot 0x0 after execution:
    • evmone: ...0001
    • geth: ...0002

Control: with --state.chainid 1 and a chain-1 tx, both clients agree and store ...0001.

Suspected root cause

In evmone test host tx context:

  • test/state/host.cpp sets chain id to a hardcoded 0x01_bytes32 in get_tx_context().

So CHAINID opcode does not reflect configured chain id.

For reference, geth CHAINID uses chain configuration:

  • core/vm/eips.go: opChainID pushes evm.chainConfig.ChainID.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions