Make secp256k1 sign_digest chain-agnostic, add sign_eth_digest#1048
Merged
Make secp256k1 sign_digest chain-agnostic, add sign_eth_digest#1048
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors Secp256k1 signing logic to centralize Ethereum-style recovery ID handling, introducing sign_eth_digest and an idempotent apply_ethereum_recovery_id function. Feedback suggests optimizing sign_eth_digest to avoid unnecessary allocations by pushing the recovery ID directly to the signature vector. Additionally, it is recommended to replace the assert_eq! in apply_ethereum_recovery_id with a safe length check to prevent potential panics in library usage.
23cb23b to
43c68d6
Compare
The Ethereum recovery id offset (27) was hardcoded in the shared secp256k1 sign_digest, producing invalid signatures for non-Ethereum chains (e.g. Bitcoin BIP-137 headers became 66/67 instead of 39/40). Split into chain-agnostic and Ethereum-specific signing: - sign_digest returns raw recovery id (0/1) - sign_eth_digest returns Ethereum-style v (27/28) - apply_ethereum_recovery_id for the WalletConnect path (idempotent) Add Signer::sign_eth_digest and use it in EIP-712, Tron, and message signers. Add BIP-137 header assertion to Bitcoin signer test.
43c68d6 to
d2299e2
Compare
This file contains hidden or 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
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.
The Ethereum recovery id offset (27) was hardcoded in the shared secp256k1 sign_digest, producing invalid signatures for non-Ethereum chains (e.g. Bitcoin BIP-137 headers became 66/67 instead of 39/40).
Split into chain-agnostic and Ethereum-specific signing:
Add Signer::sign_eth_digest and use it in EIP-712, Tron, and message signers. Add BIP-137 header assertion to Bitcoin signer test.