feat(finalizer)!: enforce BIP-174 sighash type and preserve unknown fields#8
Open
evanlinjin wants to merge 1 commit into
Open
feat(finalizer)!: enforce BIP-174 sighash type and preserve unknown fields#8evanlinjin wants to merge 1 commit into
evanlinjin wants to merge 1 commit into
Conversation
…ields Closes the two BIP-174 input-finalizer gaps tracked in bitcoindevkit#75. 1. Sighash type enforcement (MUST): `finalize_input` now rejects any input whose declared `PSBT_IN_SIGHASH_TYPE` disagrees with one of its signatures. ECDSA, Taproot key-path, and Taproot script-path signatures are all checked by comparing their sighash type against the declared type (uniformly via the raw `PsbtSighashType` u32, which captures the 64-byte vs 65-byte Taproot encoding). Inputs that do not declare a sighash type stay unconstrained, as the BIP only requires matching a *declared* type. 2. Unknown field preservation (SHOULD): finalization previously cleared the whole `psbt::Input` and restored only the UTXO, dropping the `unknown` and `proprietary` key-value maps. These are now preserved alongside the UTXO. `finalize_input` and `FinalizeMap` now surface a dedicated `FinalizeError` (with `SighashType` and `Satisfy` variants) instead of `miniscript::Error`, so the new BIP-174 failure mode is inspectable. The `SighashTypeMismatch` payload reports the declared and found sighash types. BREAKING CHANGE: `Finalizer::finalize_input` and `FinalizeMap::results` now return `FinalizeError` instead of `miniscript::Error`. https://claude.ai/code/session_0128PfKcSQhUitSsfwMYAYQ4
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.
Closes the two BIP-174 input-finalizer gaps tracked in
bitcoindevkit#75.
Sighash type enforcement (MUST):
finalize_inputnow rejects any inputwhose declared
PSBT_IN_SIGHASH_TYPEdisagrees with one of its signatures.ECDSA, Taproot key-path, and Taproot script-path signatures are all checked
by comparing their sighash type against the declared type (uniformly via the
raw
PsbtSighashTypeu32, which captures the 64-byte vs 65-byte Taprootencoding). Inputs that do not declare a sighash type stay unconstrained, as
the BIP only requires matching a declared type.
Unknown field preservation (SHOULD): finalization previously cleared the
whole
psbt::Inputand restored only the UTXO, dropping theunknownandproprietarykey-value maps. These are now preserved alongside the UTXO.finalize_inputandFinalizeMapnow surface a dedicatedFinalizeError(with
SighashTypeandSatisfyvariants) instead ofminiscript::Error, sothe new BIP-174 failure mode is inspectable. The
SighashTypeMismatchpayloadreports the declared and found sighash types.
BREAKING CHANGE:
Finalizer::finalize_inputandFinalizeMap::resultsnowreturn
FinalizeErrorinstead ofminiscript::Error.https://claude.ai/code/session_0128PfKcSQhUitSsfwMYAYQ4