plan: add Plan::tap_sighash_default accessor#951
Conversation
Exposes the existing per-Schnorr-placeholder size assumption — recorded when the plan was built from `TaprootCanSign::sighash_default` — as a single `Option<bool>` on the Plan. Returns `Some(true)` when every Schnorr placeholder is sized for a 64-byte signature (SIGHASH_DEFAULT), `Some(false)` when every one is sized for 65 bytes (any non-Default Taproot sighash flag), and `None` for non-Taproot plans or mixed plans that cannot be expressed by a single uniform sighash policy per BIP-174. Callers constructing a PSBT can use this to populate `PSBT_IN_SIGHASH_TYPE` consistently with the witness-size assumption baked into `Plan::satisfaction_weight`.
a7eee98 to
0e6ce80
Compare
nymius
left a comment
There was a problem hiding this comment.
This is a guess based on information which was available at the moment of providing the assets. Why not surfacing directly the SIGHASH value obtained from the assets?
I agree we should expose what's available directly. But the asset model only tracks sighash to the extent it affects witness size and the detailed sighash type isn't carried. Look at To expose without inferring, I can bubble |
|
I agree that this method does not seem useful for the claimed motivation. Also, if there are multiple sighash types, we ought to return a vector of them. Maybe we should return |
Summary
Adds a public accessor on
Planthat exposes the existing per-Schnorr-placeholder size assumption — recorded when the plan was built fromTaprootCanSign::sighash_default— as a singleOption<bool>.Some(true)— every Schnorr placeholder is sized for a 64-byte signature (theSIGHASH_DEFAULTencoding).Some(false)— every Schnorr placeholder is sized for a 65-byte signature (any non-Default Taproot sighash flag).None— non-Taproot plans (signature size is invariant under the sighash flag for ECDSA), or mixed plans whose Schnorr placeholders have differing sizes — these cannot be expressed by a single uniform sighash policy per BIP-174.Motivation
Callers building a PSBT from a
Planneed to populatePSBT_IN_SIGHASH_TYPEconsistently with the plan's witness-size assumption — otherwise weight estimates drift from reality. The information already lives inside the plan (on every Schnorr placeholder'ssizefield); this just surfaces it as a single readable answer.Concretely:
bdk-txis reworking per-input sighash handling and needs to derive the PSBT sighash policy from the plan rather than carrying separate state on itsInputtype (see bitcoindevkit/bdk-tx#69 for the full design). Without this accessor it would have to walkPlan::witness_template()and infer the bool from placeholder sizes, which leaks internals.A 12.x backport is up at #950.
A 13.x backport is up at #952.
Test plan
cargo test --lib tap_sighash_default— new test covers Default-Taproot, non-Default-Taproot, and non-Taproot (wsh) plans.cargo test --lib— full suite still passes (157 / 0 / 0).🤖 Generated with Claude Code