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

Fix EIP712 chain ID handling #51

Closed
oberstet opened this issue Sep 13, 2019 · 5 comments
Closed

Fix EIP712 chain ID handling #51

oberstet opened this issue Sep 13, 2019 · 5 comments

Comments

@oberstet
Copy link
Member

EIP712 contains the chain ID in signed typed data to prohibit cross-chain replay attacks.

We should run-time read the chain ID from within Solidity in the channel contract - currently, its hard-coded:

https://github.com/crossbario/xbr-protocol/blob/bf7edc0e45b180f88b4076774ce89f08f3709a92/contracts/XBRChannel.sol#L192

@oberstet oberstet added this to the Mark-II milestone Sep 27, 2019
@oberstet
Copy link
Member Author

reading the chain ID from within a contract at run-time is not possible currently. it will be possible once this EIP is implemented https://eips.ethereum.org/EIPS/eip-1344

@oberstet
Copy link
Member Author

ok, here is an update:

  1. the new CHAINID opcode (EIP-1344) was deployed in Istanbul release
  2. Solidity 0.5.12 exposes this opcode in assembly:
        uint256 chain_id;
        assembly {
            chain_id := chainid()
        }

@oberstet
Copy link
Member Author

ganache CHAINID opcode currently is buggy: https://github.com/trufflesuite/ganache/issues/1643

@oberstet
Copy link
Member Author

so above is now fixed. chain ID is dynamically read, as well as exposed on XBRNetwork:

    /// Used for EIP712 verification: network ID of the blockchain this contract is running on.
    uint256 public verifyingChain;

    /// Used for EIP712 verification: verifying contract address.
    address public verifyingContract;

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

No branches or pull requests

1 participant