q9f / eth.rb

a straightforward library to build, sign, and broadcast ethereum transactions anywhere you can run ruby.
https://q9f.github.io/eth.rb
Apache License 2.0
196 stars 85 forks source link

Signature Mismatch Issue with bytes #251

Closed bolom closed 9 months ago

bolom commented 9 months ago

I am facing an issue with signing typed data in both Ruby and JavaScript. The signatures generated from the two languages do not match. Below, I have provided my Ruby and JavaScript code along with the respective signatures for your reference:

Ruby Code:

data = {
  types: {
    EIP712Domain: [
      { name: 'name', type: 'string' },
      { name: 'version', type: 'string' },
      { name: 'chainId', type: 'uint256' },
      { name: 'verifyingContract', type: 'address' },
    ],
    Data: [
       { name: 'data', type: 'bytes' },
     ],
  },
  primaryType: 'Data',
  domain: {
    name: 'Complex Data',
    version: '1',
    chainId: 421613, 
    verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
  },
  message: {
    data: "0xa2d6eae3",
  }
}
# Sign the typed data
signature = key.sign_typed_data(data)
# ...

JavaScript Code:


const domain = {
    name: 'Complex Data',
    version: '1',
    chainId: 421613,  // Make sure the chainId matches your Ethereum network
    verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'
};

const types = {
  Data: [
        { name: 'data', type: 'bytes' },
    ]
};

const value = {
  data: "0xa2d6eae3",
};

async function signTypedData() {
    const wallet = new ethers.Wallet(PRIVATE_KEY);
    const signature = await wallet.signTypedData(domain, types, value);
    console.log('Signature:', signature);
}

signTypedData();
// ...

when data is type bytes, the signature doesn't match but when its a string it's working

bolom commented 9 months ago

@q9f Could you tell me what I did wrong?

q9f commented 9 months ago

Thanks for reporting. This is a confirmed bug.

bolom commented 9 months ago

@q9f How I can help to fix the bug?

q9f commented 9 months ago

Yes, I have patched it in #252

bolom commented 9 months ago

@q9f btw I would love to be a contributor, do you have any issue with the label "good to first issue" in the pipeline?

q9f commented 9 months ago

Contributions are very welcome! I don't have any good first issues, though. I'm still looking for someone to take on #102 or #103 - these are the biggest pain points but also need some work.

bolom commented 9 months ago

between both with one is more important. I would love to try

q9f commented 9 months ago

102 is more important.

bolom commented 9 months ago

I'll give it a go and read through it. If I have any questions, I'll ask in the thread