Skip to content

feat(finalizer)!: enforce BIP-174 sighash type and preserve unknown fields#8

Open
evanlinjin wants to merge 1 commit into
masterfrom
claude/vibrant-goodall-QurkF
Open

feat(finalizer)!: enforce BIP-174 sighash type and preserve unknown fields#8
evanlinjin wants to merge 1 commit into
masterfrom
claude/vibrant-goodall-QurkF

Conversation

@evanlinjin
Copy link
Copy Markdown
Owner

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

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants