Skip to content

plan: add Plan::tap_sighash_default accessor#949

Closed
evanlinjin wants to merge 1 commit into
rust-bitcoin:release-13.xfrom
evanlinjin:13.x-plan-tap-sighash-default
Closed

plan: add Plan::tap_sighash_default accessor#949
evanlinjin wants to merge 1 commit into
rust-bitcoin:release-13.xfrom
evanlinjin:13.x-plan-tap-sighash-default

Conversation

@evanlinjin
Copy link
Copy Markdown
Contributor

Summary

Adds a public accessor on Plan that exposes the existing per-Schnorr-placeholder size assumption — recorded when the plan was built from TaprootCanSign::sighash_default — as a single Option<bool>.

impl Plan {
    /// Returns whether the witness was sized assuming `SIGHASH_DEFAULT` (the
    /// 64-byte Taproot signature encoding).
    pub fn tap_sighash_default(&self) -> Option<bool>;
}
  • Some(true) — every Schnorr placeholder is sized for a 64-byte signature (the SIGHASH_DEFAULT encoding).
  • 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 Plan need to populate PSBT_IN_SIGHASH_TYPE consistently with the plan's witness-size assumption — otherwise weight estimates drift from reality. The information already lives inside the plan (on every Schnorr placeholder's size field); this just surfaces it as a single readable answer.

Concretely: bdk-tx is reworking per-input sighash handling and needs to derive the PSBT sighash policy from the plan rather than carrying separate state on its Input type (see bitcoindevkit/bdk-tx#69 for the full design). Without this accessor it would have to walk Plan::witness_template() and infer the bool from placeholder sizes, which leaks internals.

Test plan

  • cargo test --lib tap_sighash_default — new test covers Default-Taproot, non-Default-Taproot, and non-Taproot (wsh) plans.
  • cargo test — full suite still passes (139 / 0 / 0).

🤖 Generated with Claude Code

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`.
@evanlinjin evanlinjin marked this pull request as draft May 17, 2026 08:03
@evanlinjin
Copy link
Copy Markdown
Contributor Author

Fully AI generated - I need to ensure it didn't screw up before I take it out of draft.

@evanlinjin
Copy link
Copy Markdown
Contributor Author

Closing — wrong target branch. Superseded by #951 (targets master) and #950 (12.x backport). Sorry for the noise.

@evanlinjin evanlinjin closed this May 17, 2026
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.

1 participant