trustwallet / trust-wallet-ios

:iphone: Trust - Ethereum Wallet and Web3 DApp Browser for iOS
https://trustwallet.com
GNU General Public License v3.0
1.52k stars 718 forks source link

eth_signTypedData_v3 for uint64 is not working correctly #967

Closed leroldary closed 5 years ago

leroldary commented 5 years ago

Using EIP-712 (eth_signTypedData_v3) with uint of other size than uint256 an invalid signature is produced. Android version of Trustwallet has the same problem. Example: https://dicether.github.io/js-eth-personal-sign-examples/ ("Sign Typed Data V3")

hewigovens commented 5 years ago

hi, can you share your json playload and expected signature here?

leroldary commented 5 years ago

Hi, Payload:

  const payload = {
    types:{
      EIP712Domain:[],
      Test:[
        {name: "test", type: "uint64"}
      ],
    },
    primaryType:"Test",
    domain: {},
    message: {
      test: 1,
    },
  };

The expected hash is 0x34091011761262618af3045f97715b4a73eb6737c9396353b85b757201e3ad9f (produced with eth-sig-util)

hewigovens commented 5 years ago

it's weird, I can get exact 0x34091011761262618af3045f97715b4a73eb6737c9396353b85b757201e3ad9f here is the test code:

func testUint64() throws {
        let jsonString = """
        {
            "types": {
                "EIP712Domain": [],
                "Test": [
                    {"name": "test", "type": "uint64"}
                ],
            },
            "primaryType": "Test",
            "domain": {},
            "message": {
                "test": 1
            }
        }
        """
        let typed = try JSONDecoder().decode(EIP712TypedData.self, from: jsonString.data(using: .utf8)!)
        let signhash = typed.signHash

        XCTAssertEqual(signhash.hexString, "34091011761262618af3045f97715b4a73eb6737c9396353b85b757201e3ad9f")
    }

put it in this file: https://github.com/TrustWallet/trust-core/blob/master/Tests/Ethereum/Solidity/EIP712/EIP712TypedDataTests.swift

hewigovens commented 5 years ago

Simulator Screen Shot - iPhone Xʀ - 2019-05-22 at 10 51 56

leroldary commented 5 years ago

Seems the second example is only failing on android. Sorry for the confusion.

This is failing on android and iOS:

  const typedData = {
  types:{
    EIP712Domain:[
      {name:"name",type:"string"},
      {name:"version",type:"string"},
      {name:"chainId",type:"uint256"},
      {name:"verifyingContract",type:"address"}
    ],
    Person:[
      {name:"age",type:"uint64"},
      {name:"name",type:"string"},
      {name:"wallet",type:"address"}
    ],
    Mail:[
      {name:"from",type:"Person"},
      {name:"to",type:"Person"},
      {name:"contents",type:"string"},
      {name: "id", type: "uint256"},
    ]
  },
  primaryType:"Mail",
  domain:{name:"Ether Mail",version:"1",chainId:1,verifyingContract:"0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"},
  message:{
    from:{age: 46,name:"Cow",wallet:"0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"},
    to:{age: 445711732, name:"Bob",wallet:"0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"},
    contents:"Hello, Bob!",
    id: "18446744073709551617"}
  };

The expected hash is: 0xd7452bcc4deef52ad1a3f658f4100fa870fcb849b2f8c7738c23bd8e736e6c7b

hewigovens commented 5 years ago

Thanks, we can reproduce this bug, and it will be fixed in future releases