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

Fixes a parsing issue of EIP712 chain_id (chain_id = 80001 parsed as chain_id = 0x80001) #892

Merged
merged 2 commits into from
Feb 10, 2022

Conversation

alexisrobert
Copy link
Contributor

Motivation

When using the Eip712 derive macro for a contract on the Polygon chain, chain_ids seem to be not parsed correctly.

use ethers::contract::EthAbiType;
use ethers_derive_eip712::*;
use ethers::core::types::U256;
use ethers::core::types::transaction::eip712::Eip712;

#[derive(Debug, Clone, Eip712, EthAbiType)]
#[eip712(
    name = "TestContract",
    version = "0.1",
    chain_id = 80001,
    verifying_contract = "0x0000000000000000000000000000000000000001"
)]
pub struct TestRequest {
    pub nonce: U256,
}

fn main() {
    let msg = TestRequest {
        nonce: U256::from(1_u32),
    };

    println!("{:#?}", msg.domain().unwrap());
}

This outputs the following domain, with a chain_id that seems incorrect (and not validated by the Solidity contract) :

EIP712Domain {
    name: "TestContract",
    version: "0.1",
    chain_id: 524289,
    verifying_contract: 0x0000000000000000000000000000000000000001,
    salt: None,
}

The chain_id of 524289 is equal to 0x80001 where it should normally be 80001 in decimal.

Solution

I changed the parsing of domain.chain_id to be parsed into a u64, instead of directly to the U256 type.

After being parsed to u64, I convert it to U256.

alexisrobert and others added 2 commits February 10, 2022 20:03
This fixes a bug for chain_ids that are > 10, base10_parse::<U256>() was
somehow parsing into hex.

When using the derive macro, chain_id = 10 was parsed as chain_id = 0x10 = 16,
causing an issue for some chains like Polygon.
@gakonst gakonst merged commit b07b302 into gakonst:master Feb 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants