-
Notifications
You must be signed in to change notification settings - Fork 375
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
Fix bug in signature parsing for EIP712TypedData #8836
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd5485b
to
1adf012
Compare
codyborn
reviewed
Oct 28, 2021
codyborn
approved these changes
Oct 28, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very thorough per usual! 🚢
6fe45c2
to
24a8335
Compare
eefc25e
to
1cc94a2
Compare
This was referenced Apr 21, 2022
This was referenced May 26, 2022
This was referenced Aug 5, 2022
This was referenced Oct 6, 2022
This was referenced Apr 24, 2023
This was referenced Jun 23, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When parsing EIP712 signed typed data in
SignatureUtils.recoverEIP712TypedDataSigner
, we break and return a value as soon as a signature can be parsed. The issue is that 1) we do not serialize signatures consistently (examples from the monorepo:SignatureUtils.serializeSignature
serializes as VRS, butLocalSigner.signTypedData
returns an RSV-serialized sig) 2) some small percentage of signatures can be parsed as both RSV & VRS signatures, in which case the order of the parsing matters as long as we do not check against the expected signer.Given that the usage in
offchain-data-wrapper
is relatively new (and breaking changes shouldn't be too disruptive), the proposed fix splits uprecoverEIP712TypedDataSigner
into two (VRS & RSV-specific, so the caller can choose to explicitly call these if it's necessary to "guess" an address), while modifying theverify
function to be in line with how the existing message parsingverifySignature
function works -- i.e. boolean that suppresses errors but works regardless of RSV/VRS serialization.This is a breaking change in that
recoverEIP712TypedDataSigner
has been deprecated in favor of two functions.Other changes
SignatureUtils.verifyEIP712TypedDataSigner
in a try/catch to ensure that it always returns a boolean (and no longer propagates the error from the recovery step). This is in line with the other signature parsing/verification functions.recover & verify
: these are pretty dumb and based on hardcoded examples in order to not add the CK/LocalWallet dependencies to the utils package -- open to thoughts on this though, if you think it's worthwhile to randomize PKs but incorporate these dependencies)Testing
recover & verify
against a hard-coded edge case that was failingoffchain-data-wrapper
passInvalid signature
error, but now throw "Invalid code" as we want)Closes #8812
Edit: further notes for future documentation:
Notes on implementation choices in
offchain-data-wrapper
and future TODOs here:Initially @nambrot and I thought it would make sense to double down on the usage of just VRS-serialization. This PR diverges from that initial thought due to the following:
PublicSimpleAccessor.sign
we are actually using thewallet.signTypedData
method which returns an RSV-signature (we can switch this to using theCK.signTypedData
+SignatureUtils.serializeSignature
, but this increases the scope of this PR)wallet.signTypedData
andserializeSignature
(in the tests), so standardizing should take a more rigorous comb through of everything here IMO)The current implementation is slightly less efficient than before, but should not suffer from the same edge case that this PR fixes (except in the case that the
guessedSignature
must still be used, which seems unavoidable). Notes on this:verifyEIP712TypedDataSigner
) which is less efficient (on the order of a few milliseconds in total)I ultimately opted for minimizing the amount of signature standardization across the module for now and eliminating the possible edge case, and would be slightly in favor of splitting out signature standardization across the offchain-data-wrapper into a separate ticket for the future.
TODOs
offchain-data-wrapper
#8862 (assigned to Applications initially)