Skip to content

ecrecover return the different address from signer's #1419

Answered by ricmoo
TheBestOrNothing asked this question in Q&A
Discussion options

You must be logged in to vote

Oh! As I was trying up a script to test this, I see a mistake. You are passing messageHash into verifyMessage, but verifyMessage accept the data being signed (which it then hashes itself). You are effectively hashing the data twice. You just happen to signing and verifying again the data hashed twice, but passing the data hashed once to Solidity.

If you use:

const data = "0x512345673440";
console.log(ethers.utils.verifyMessage(ethers.utils.arrayify(data), signature));
// 0xDA606925E15d926B943b0a300c229f5E27190E9a

You probably want to fix your Signing up, which then might make it all work:

// Replace this:
// const signature = await signer.signMessage(messageHashBytes);
// with:
const sign…

Replies: 8 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ricmoo
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1417 on March 31, 2021 18:37.