Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Chain ID opcode: hardcoded at 1? #1643

Open
oberstet opened this issue Feb 24, 2020 · 2 comments
Open

Chain ID opcode: hardcoded at 1? #1643

oberstet opened this issue Feb 24, 2020 · 2 comments

Comments

@oberstet
Copy link

I am using Ganache v6.9.1 (from docker trufflesuite/ganache-cli:v6.9.1) with --networkId=5777 and want to read the chain ID from within solidity using:

uint256 _chainId;
assembly {
    _chainId := chainid()
}

source: wamp-proto/wamp-xbr#51 (comment)

The returned chain ID however is not 5777, but always 1.

Is this a know bug? Am I doing sth wrong?

I am using truffle 5.1.14 and pragma solidity ^0.5.12; in my contracts, as the CHAINID opcode was only intruduced in v0.5.12 https://solidity.readthedocs.io/en/v0.5.12/assembly.html#opcodes

@davidmurdoch
Copy link
Member

It is a bug in Ganache that is tricky to fix due to backcompat reasons. We'll be changing this behavior in the next major version of ganache-core (trufflesuite/ganache#451)

Note that chain ID !== network id (net_version). The bug is actually different than you have discovered, as the eth_chainId RPC actually returns 1337 right now, but 1 for the chainid opcode in the EVM.

@oberstet
Copy link
Author

Ah, ok, thanks for confirming!

Looking forward, as I am working on some 2-layer stuff and getting all the EIP712 bits working together (for which I need the chain ID to prevent replay attacks) is tricky .. some stuff required is still in the move/new/buggy ;)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants