harmony icon indicating copy to clipboard operation
harmony copied to clipboard

`block.chainid` returns unexpected id

Open alerdenisov opened this issue 2 years ago • 5 comments

Describe the bug Querying of block.chainid from smartcontract returns unexpected value

To Reproduce Steps to reproduce the behavior:

  1. Create smart contract with external view method which returns value of block.chainid
  2. Deploy to Harmony Testnet Shard 0
  3. Call with web3

Expected behavior Should returns 1666700000

Actual behavior Returns 2

Additional context Ruins EIP712 implementation from open-zeppelin contracts

alerdenisov avatar Apr 18 '22 08:04 alerdenisov

I can confirm this. I deployed this contract with remix on the testnet and get the same result.

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.7.0;

contract ChainIdViewer {
    function chainId() public pure returns (uint256){
        uint256 id;
        assembly {
            id := chainid()
        }
        return id;
    }
}

Severino avatar Apr 20 '22 06:04 Severino

Yes, the ‘block.chainid’ method called within the contract returns value of ‘2’. ChainId: 2 is currently assigned to ‘Expanse Network’.

onatheengineer avatar Apr 20 '22 10:04 onatheengineer

Also just came across this. Is this only affecting the testnet or also the mainnet?

0xD006F00D avatar Apr 22 '22 14:04 0xD006F00D

Also just came across this. Is this only affecting the testnet or also the mainnet?

I have only tried on the testnet

onatheengineer avatar Apr 22 '22 20:04 onatheengineer

Also just came across this. Is this only affecting the testnet or also the mainnet?

Reading the code I assume it behaves the same way on mainnet, but returning 1 for mainnet.

@rlan35 this seems to not be conform with eip-155 (which was rolled out on Harmony):

This would provide a way to send transactions that work on Ethereum without working on ETC or the Morden testnet. ETC is encouraged to adopt this EIP but replacing CHAIN_ID with a different value, and all future testnets, consortium chains and alt-etherea are encouraged to adopt this EIP replacing CHAIN_ID with a unique value.

https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md

I'm not so firm with the harmony repository and couldn't locate where the ID is accessed. But I assume, that the value should return the config.EthCompatibleChainID.

Severino avatar Apr 23 '22 10:04 Severino

Fixed by #4154

MaxMustermann2 avatar Nov 01 '22 10:11 MaxMustermann2

@MaxMustermann2 Why is it marked fixed, if the hard fork wasn't completed? https://github.com/harmony-one/harmony/blob/b11800fe3f813b682c22f056d5b5ed4809c0da19/internal/params/config.go#L68 block.chainid still returns 1 for Harmony Mainnet.

ChiTimesChi avatar Nov 26 '22 01:11 ChiTimesChi