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

Bool encoding ("0" & "false") discrepancy on TypedDataUtils.eip712Hash #303

Open
gokhanaliccii opened this issue Mar 21, 2023 · 0 comments

Comments

@gokhanaliccii
Copy link

gokhanaliccii commented Mar 21, 2023

I was testing bool property encoding using TypedDataUtils.eip712Hash but I noticed different output when I change "false" to 0.

Proof

 const hash = TypedDataUtils.eip712Hash(
    {
      types: {
        EIP712Domain: [
          {
            name: 'name',
            type: 'string',
          },
          {
            name: 'version',
            type: 'string',
          },
          {
            name: 'chainId',
            type: 'uint256',
          },
          {
            name: 'verifyingContract',
            type: 'address',
          },
        ],
        Message: [
          { name: 'data_true', type: 'bool' },
          { name: 'data_false', type: 'bool' },
        ],
      },
      primaryType: 'Message',
      domain: {
        name: 'com.test.test',
        version: '1',
        chainId: 1,
        verifyingContract: '0xc000000000000000000000000000000000000000',
      },
      message: {
        data_true: 'true',
        data_false: 0,
      },
      
    },
    SignTypedDataVersion.V4,
  ).toString('hex');

  console.log(`result bool ->  ${hash}`)

This gives "0737ed294ff3a12f840067c728e500008f23a7b79f4a62c09b5d1bbca85ddb2e"

  1. Change data_false: 0 to data_false: 'false' then the output is changed to "1a3a9fdfbecde2bb500792a5cdfc2d0deca9401edafa4186d71f5842ecf12d0b"

Seems "false" is wrongly mapped, when I give "false" and "1" it gives the same output

PS: According to Eip-712 spec bool values should be encoded same as uint256 0 or 1. I tested uint256 0 and 1 values and I confirm it gives correct output

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

No branches or pull requests

1 participant