-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Add verification to Sign
, SignCompact
and SignSchnorr
#22934
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
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
Concept ACK |
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.
Concept ACK, two small comments.
Any reason not to do the same for ECDSA?
SignSchnorr
Sign
, SignCompact
and SignSchnorr
As per @sipa's suggestion, I added verification step to ECDSA signing functions too. |
Please squash your commits https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#squashing-commits |
67e3138
to
454be06
Compare
Does this ever come up in practice? I mean, yes, the secp256k1 library is used on some very low-end hardware. However Bitcoin Core's minimum specifications are a lot higher. The amount of signatures generated is also fairly low, compared to the number of verifications done, so it's important that verification is fast. Does it add that much overhead? But maybe I'm missing something. |
@amadeuszpawlik Do you have any measurements suggesting that |
454be06
to
9ed9ef2
Compare
@laanwj @practicalswift I got this idea from the original issue: #22435, but I agree with you both and have thus dropped the "disable option". |
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.
Concept ACK
Left a code-review comment below. As an additional improvement, I'd suggest to add a comment like "// Additional verification step to prevent using a potentially corrupted signature
" in each function before your introduced code to increase readability.
To fix the failed CI run on windows, rebasing on master should help (to include #23089).
96ec9d8
to
c9a920e
Compare
@theStack I don't think #23089 is it |
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.
Light code-review ACK c9a920e
(LGTM, though I don't have strong experience with correct secp256k1 usage, hence only "light")
@amadeuszpawlik: Weird that it still fails on the Windows CI. I think it's unlikely that it's connected to this PR; if your introduced code failed in the course of a wallet send RPC, an assertion would be thrown (crashing bitcoind) and the "generate" RPC call above the line where the test assertion fails would not have succeeded.
@theStack Agree, I reran the Win64 build and it went through just fine 👍 |
c9a920e
to
ed16d80
Compare
As defined in BIP340, a verification step should be executed after `secp256k1_schnorrsig_sign` to ensure that a potentially corrupted signature isn't used; using corrupted signatures could reveal information about the private key used. This applies to ECSDA as well. Additionally clears schnorr signature if signing failed.
ed16d80
to
79fd28c
Compare
utACK 79fd28c |
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.
re-ACK 79fd28c
Checked that compared to my last ACK, the verificiation verification step in CKey::SignCompact
is now done via ECDSA public key recovery (secp256k1 function secp256k1_ecdsa_recover
), which according to the interface documentation "guarantees a correct signature" if successful,
bitcoin/src/secp256k1/include/secp256k1_recovery.h
Lines 90 to 93 in 24abd83
/** Recover an ECDSA public key from a signature. | |
* | |
* Returns: 1: public key successfully recovered (which guarantees a correct signature). | |
* 0: otherwise. |
plus a comparison (
secp256k1_ec_pubkey_cmp
) between the recovered and the created public key (secp256k1_ec_pubkey_create
). Also ran unit tests locally.
Code review ACK 79fd28c |
…ignSchnorr` 79fd28c Adds verification step to Schnorr and ECDSA signing (amadeuszpawlik) Pull request description: As detailed in bitcoin#22435, BIP340 defines that during Schnorr signing a verification should be done. This is so that potentially corrupt signage does not leak information about private keys used during the process. This is not followed today as no such verification step is being done. The same is valid for ECDSA signing functions `Sign` and `SignCompact`. This PR adds this missing verification step to `SignSchnorr`, `Sign` and `SignCompact`. ACKs for top commit: sipa: utACK 79fd28c laanwj: Code review ACK 79fd28c theStack: re-ACK 79fd28c Tree-SHA512: 8fefa26caea577ae8631cc16c4e2f4cc6cfa1c7cf51d45a4a34165636ee290950617a17a19b4237c6f7a841db0e40fd5c36ad12ef43da82507c0e9fb9375ab82
As detailed in #22435, BIP340 defines that during Schnorr signing a verification should be done. This is so that potentially corrupt signage does not leak information about private keys used during the process. This is not followed today as no such verification step is being done. The same is valid for ECDSA signing functions
Sign
andSignCompact
.This PR adds this missing verification step to
SignSchnorr
,Sign
andSignCompact
.