trustwallet / trust-wallet-android-source

Trust - Ethereum Wallet for Android (Inactive Repository)
https://trustwalletapp.com
GNU General Public License v3.0
389 stars 256 forks source link

eth_signTypedData_v3 produces invalid signature #45

Open leroldary opened 5 years ago

leroldary commented 5 years ago

Using EIP-712 (eth_signTypedData_v3) with the provided example data an invalid signature is produced. Ios version of trust wallet had the same problem (https://github.com/TrustWallet/trust-wallet-ios/issues/967, now fixed). Example: https://dicether.github.io/js-eth-personal-sign-examples/ ("Sign Typed Data V3")

Example Data:

  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

@leroldary The root cause is that we use float type to handle JSON number value, we will fix it in later releasees , current workaround is use uint256 type or smaller value, in this case 445711732 causes precision loose