Repository navigation
BIP-375: allow SIGHASH_DEFAULT, harden validator, regenerate vectors - #2389
Open
macgyver13 wants to merge 12 commits into
Open
macgyver13 wants to merge 12 commits into
macgyver13 wants to merge 12 commits into
Conversation
The Signer rules now allow SIGHASH_DEFAULT for a taproot input. Clarify that the sighash type means PSBT_IN_SIGHASH_TYPE or a signature's type. The validator accepts SIGHASH_DEFAULT on a taproot input. It also checks the sighash type of every signature in the PSBT signature fields, not only PSBT_IN_SIGHASH_TYPE. Add 7 invalid vectors: - non-SIGHASH_ALL signature on input with sp output and PSBT_IN_SIGHASH_TYPE omitted - non-SIGHASH_ALL signature on ineligible input with sp output - non-SIGHASH_ALL signature on ineligible input with sp output and PSBT_IN_SIGHASH_TYPE omitted - non-SIGHASH_ALL signature on taproot input with sp output - non-SIGHASH_ALL signature on taproot input with sp output and PSBT_IN_SIGHASH_TYPE omitted - SIGHASH_ALL|ANYONECANPAY sighash type on input with sp output - SIGHASH_DEFAULT sighash type on non-taproot input with sp output Add 2 valid vectors: - one P2TR input signed with SIGHASH_DEFAULT - P2WPKH input with ineligible P2SH multisig input declaring SIGHASH_ALL
… one The runner runs the checks in order on every vector and reports the first one that rejects it. It no longer reads the per-vector `checks` field. A PSBT that does not parse counts as a PSBT Structure failure. The checks now raise ValidationError and name the failing input instead of returning a result.
Check two Signer rules in Input Eligibility: - no input is signed until every sp output has PSBT_OUT_SCRIPT - the Inputs Modifiable and Outputs Modifiable flags are cleared once a PSBT_OUT_SCRIPT is set for an sp output Now a present PSBT_OUT_SCRIPT counts as set, even when empty. An omitted PSBT_GLOBAL_TX_MODIFIABLE counts as zero. Rename 1 invalid vector from psbt structure: PSBT_GLOBAL_TX_MODIFIABLE field is non-zero... to input eligibility: PSBT_GLOBAL_TX_MODIFIABLE Inputs/Outputs Modifiable flags not cleared... Add 1 invalid vector: - input signed before every sp output has PSBT_OUT_SCRIPT Add 1 valid vector: - one P2WPKH input with PSBT_GLOBAL_TX_MODIFIABLE omitted
Fix the validator so it no longer crashes when an input's scriptPubKey cannot be found. It now fails the check when an input has no witness or non-witness UTXO, or when a P2SH input has no redeem script. Add 2 invalid vectors: - input 1 with no PSBT_IN_WITNESS_UTXO or PSBT_IN_NON_WITNESS_UTXO and no ECDH share - P2SH input 1 with no PSBT_IN_REDEEM_SCRIPT and no ECDH share Based on bitcoin#2324. Co-authored-by: Ferdinando Ametrano <ferdinando@ametrano.net>
A Signer relies on the per-input DLEQ proofs before it computes the output scripts. The validator only checked them once PSBT_OUT_SCRIPT was set. An invalid proof on an in-progress PSBT passed. Every share on an eligible input now needs a proof that verifies, whether or not the script is set. Coverage of every eligible input is still only required once a script is set. Also add the matching vector for the existing global DLEQ proof check before PSBT_OUT_SCRIPT is set. Add 2 invalid vectors: - invalid proof in PSBT_IN_SP_DLEQ field when PSBT_OUT_SCRIPT not set for sp output - invalid proof in PSBT_GLOBAL_SP_DLEQ field when PSBT_OUT_SCRIPT not set for sp output Based on bitcoin#2321. Co-authored-by: gophersg <gopher@2980.com>
ECDH share and DLEQ proof keydata must be 33-byte scan keys. This is from the validator change in bitcoin#2318. Add 1 invalid vector: - incorrect byte length for PSBT_IN_SP_ECDH_SHARE scan key Co-authored-by: myetcd <mytech@139.com>
PSBT Structure rejects a scan key, ECDH share, or either PSBT_OUT_SP_V0_INFO key that is 33 bytes but not a valid point. Matching Bitcoin Core and rust-psbt deserialize behavior. Add 4 invalid vectors: - PSBT_IN_SP_ECDH_SHARE scan key is not a valid point - PSBT_IN_SP_ECDH_SHARE value is not a valid point - PSBT_OUT_SP_V0_INFO scan key is not a valid point - PSBT_OUT_SP_V0_INFO spend key is not a valid point
A global ECDH share fails when no input is eligible. Eligible input pubkeys that sum to the point at infinity fail instead of crashing. Add 3 invalid vectors: - PSBT_GLOBAL_SP_ECDH_SHARE set when the only input is ineligible (P2TR with NUMS internal key) - eligible input keys sum to the point at infinity when PSBT_GLOBAL_SP_ECDH_SHARE set and PSBT_OUT_SCRIPT not set for sp output - PSBT_OUT_SCRIPT set for sp output when the eligible input keys sum to the point at infinity
hashlib only offers RIPEMD-160 when OpenSSL provides it, and OpenSSL 3 moved it to the legacy provider. Bring in crypto/ripemd160.py from Bitcoin Core test/functional/test_framework, and compute hash160 with it as Core's messages.py does. Based on bitcoin#2317, which makes the same change. Co-authored-by: macgyver13 <4712150+macgyver13@users.noreply.github.com>
A P2SH redeem script must hash to the scriptPubKey before eligibility is read from it. An uncompressed P2PKH input is ineligible and should be skipped. Add 1 invalid vector: - P2SH-P2WPKH input 1 with a non-P2WPKH PSBT_IN_REDEEM_SCRIPT that does not hash to scriptPubKey and no ECDH share Add 1 valid vector: - two mixed input types - only eligible inputs contribute ECDH shares (uncompressed P2PKH excluded) The redeem script check follows the P2SH commitment check fametrano proposed in bitcoin#2317. Co-authored-by: Ferdinando Ametrano <ferdinando@ametrano.net>
Refresh bip375_test_vectors.json with the bip375-test-generator file (version 1.2.0). The remaining 8 key binding v1.2.0 vectors arrive in the next commit with the validator changes. Use the `task` field from each vector to determine the outcome a runner should expect: fail_deserialize, fail_sign, deserialize, sign, finalize. Every vector has new keys, prevouts, and derivations. The P2WPKH programs and signatures that bitcoin#2316 fixes are repaired. The runner now maps PSBT Structure to fail_deserialize and the other checks to fail_sign. Rename 1 vector: "segwit version greater than 1 supplied via PSBT_IN_NON_WITNESS_UTXO..." now ends with "when PSBT_OUT_SCRIPT not set for sp output"
Nothing checked that a PSBT_IN_BIP32_DERIVATION pubkey matches the prevout script it claims to spend. A valid share and DLEQ proof made with an incorrect key, intentional or accidental, do not catch it. A false NUMS PSBT_IN_TAP_INTERNAL_KEY on a key-path spendable input makes the sender leave out an input the receiver expects. Either way the receiver never finds the output. An input's pubkey must now come from the BIP32 derivation its scriptPubKey commits to. A NUMS claim counts only when PSBT_IN_TAP_MERKLE_ROOT reproduces the scriptPubKey. An eligible input with no usable pubkey now fails instead of dropping out of the global share's key sum. Add 6 invalid vectors: - PSBT_GLOBAL_SP_DLEQ proven without input 1 (also missing PSBT_IN_BIP32_DERIVATION) - P2WPKH PSBT_IN_BIP32_DERIVATION pubkey does not match scriptPubKey - P2PKH PSBT_IN_BIP32_DERIVATION pubkey does not match scriptPubKey - P2SH-P2WPKH PSBT_IN_BIP32_DERIVATION pubkey does not match scriptPubKey - global ECDH share computed from a PSBT_IN_BIP32_DERIVATION pubkey not matching scriptPubKey - P2TR input 1 with a NUMS PSBT_IN_TAP_INTERNAL_KEY that does not tweak to scriptPubKey and no ECDH share Add 2 valid vectors: - P2WPKH with decoy PSBT_IN_BIP32_DERIVATION before the matching key - P2PKH with decoy PSBT_IN_BIP32_DERIVATION before the matching key A reviewer of the caravan BIP-375 PR raised this case. Binding input keys to the scriptPubKey adapts the key commitment check fametrano proposed for the test vectors in bitcoin#2317 (signatures.py). Co-authored-by: Ferdinando Ametrano <ferdinando@ametrano.net>
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.
This PR allows
SIGHASH_DEFAULTfor taproot inputs, hardens the BIP-375 reference validator and regeneratesbip375_test_vectors.jsonfrom bip375-test-generator v1.2.0. It builds on and replaces #2316, #2317 and #2324 by @fametrano, #2318 by @myetcd and #2321 by @gophersg. The regenerated vectors derive from two BIP-39 test wallets, so their prevout scripts match the wallet keys and a real signer can reproduce the signatures. Vector file 1.2.0 has 26 valid and 51 invalid vectors (1.1.1 had 20 and 24).This is groundwork for a role-based test strategy. Replacing
checkswithtaskis the first step. Each vector now names the role step it targets (deserialize, sign or finalize) and whether that step should succeed. A follow-up PR will add workflow vectors that take a PSBT through each BIP-375 role and check every transition.Here is a categorical overview of each of the 12 commits.
Spec change
SIGHASH_DEFAULTand check signature sighash types. This is the only change to the specification, and implementors have read the spec differently. BIP-341 definesSIGHASH_DEFAULTas committing to the same transaction data asSIGHASH_ALL, and BIP-352 recommends it for taproot inputs. The validator now also checks the sighash type of each signature, so a non-SIGHASH_ALLsignature fails even whenPSBT_IN_SIGHASH_TYPEis omitted. The BIP version moves to 0.2.0.Make the validator check what a signer checks
ValidationErrorfrom the checks and report the failing one.TX_MODIFIABLEflags. No input may be signed until every SP output hasPSBT_OUT_SCRIPT, and the Inputs/Outputs Modifiable flags must be cleared once one is set. BIP-370 allows omittingPSBT_GLOBAL_TX_MODIFIABLE, and the validator no longer rejects that.Edge cases found in open PRs and review
PSBT_IN_SP_ECDH_SHAREcase in place of the unit tests in BIP375: validate scan-key keydata lengths #2318.hash160, as bip-0375: check test vector signatures in the test runner #2317 does.Regenerate the vectors
checkswithtaskand fixing the P2WPKH programs and signatures from bip-0375: fix P2WPKH scriptPubKeys and signatures in test vectors #2316.Bind input keys
@caravan/psbtBIP-375 PR found this gap and bip-0375: check test vector signatures in the test runner #2317 noted a similar one.python test_runner.py -vv (77 passed, 0 failed, 0 skipped)