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

ethers.utils.splitSignature: recoveryParam doesn't match v value. #933

Closed
Amxx opened this issue Jul 7, 2020 · 4 comments
Closed

ethers.utils.splitSignature: recoveryParam doesn't match v value. #933

Amxx opened this issue Jul 7, 2020 · 4 comments
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@Amxx
Copy link

Amxx commented Jul 7, 2020

ethers.utils.splitSignature("0x84708e867ef906fc61eecacf38218a209718e9529c32b33f5d68ee4c240b76133e3aeb2bacec6ae4b3fe0f9d982b214d265abe5434175dc41fc46210ff81a0da01")

returns

{ r:
   '0x84708e867ef906fc61eecacf38218a209718e9529c32b33f5d68ee4c240b7613',
  s:
   '0x3e3aeb2bacec6ae4b3fe0f9d982b214d265abe5434175dc41fc46210ff81a0da',
  _vs:
   '0x3e3aeb2bacec6ae4b3fe0f9d982b214d265abe5434175dc41fc46210ff81a0da',
  recoveryParam: 0,
  v: 28 }

I was expecting (for the most common cases where 27 <= v <= 28) to have v = 27 + recoveryParam

@ricmoo ricmoo added investigate Under investigation and may be a bug. on-deck This Enhancement or Bug is currently being worked on. labels Jul 7, 2020
@ricmoo
Copy link
Member

ricmoo commented Jul 8, 2020

This is related to #893.

I've found the problem and am putting a fix in place.

It has to do with when a signature encodes the recoveryParam instead of a using the SIG header offset.

So, for signatures ending in 0 or 1, that is the recoveryParam and the canonical v is 27 + recoveryParam. For signatures ending with a value 27 or higher, take that as the v and compute the recoveryParam from the ((parity of v) xor 0x01). I was doing this step before normalizing the v, so the v was equal to the recoveryParam in this case.

It's harder to explain than show, once you see the code, I think the mistake will be more obvious. :)

@ricmoo ricmoo added bug Verified to be an issue. and removed investigate Under investigation and may be a bug. labels Jul 8, 2020
@ricmoo
Copy link
Member

ricmoo commented Jul 8, 2020

This should be fixed in 5.0.5.

Try it out and let me know. :)

@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels Jul 8, 2020
@ricmoo
Copy link
Member

ricmoo commented Jul 19, 2020

@Amxx Can you confirm this is still an issue? I know you continued having the problem after the fix, but just curious if it was a caching issue that has since gone away?

@ricmoo
Copy link
Member

ricmoo commented Aug 26, 2020

I think this is resolved now, so I'm going to close it. If you still have issues, please re-open.

Thanks! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

No branches or pull requests

2 participants