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

blockchain/vm: add chainId opcode (eip1344) #952

Merged
merged 2 commits into from
May 3, 2021

Conversation

yoomee1313
Copy link
Contributor

@yoomee1313 yoomee1313 commented Apr 26, 2021

Proposed changes

  • This PR contains istanbul hardfork item. It is not activated yet since istanbulCompatible block number is set nil.
  • This PR is derived from eip1344.
  • ChainId has been supported since Solidity 8.0. If you're using solidity under 8.0, you can get the chainId by calling 0x46 opcode in assembly code.

solidity 8.0 example code

pragma solidity >=0.7.0 <0.9.0;

contract ChainIDTest {
    uint256 chainID;
    // sendTransaction
    function blockCall() public {
        chainID = block.chainid;
    }
    function getChainID() public view returns (uint256) {
        return chainID;
    }
    // call
    function blockViewCall() public view returns (uint256) {
        return block.chainid;
    }
    function assemblyViewCall() public view returns (uint256) {
        uint256 id;
        assembly {
            id := chainid()
        }
        return id;
    }
}

Types of changes

Please put an x in the boxes related to your change.

  • Bugfix
  • New feature or enhancement
  • Others

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING GUIDELINES doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes ($ make test)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Related issues

  • Please leave the issue numbers or links related to this PR here.

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

KimKyungup
KimKyungup previously approved these changes Apr 27, 2021
blockchain/vm/opcodes.go Show resolved Hide resolved
blockchain/vm/jump_table.go Outdated Show resolved Hide resolved
joowon-byun
joowon-byun previously approved these changes Apr 28, 2021
@yoomee1313 yoomee1313 dismissed stale reviews from joowon-byun and KimKyungup via 4bbb9f2 April 28, 2021 06:48
@yoomee1313 yoomee1313 merged commit f04e214 into klaytn:dev May 3, 2021
@yoomee1313 yoomee1313 deleted the chainId-opcode branch May 3, 2021 08:53
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 this pull request may close these issues.

None yet

5 participants