Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BIP 371 noncompliance: Taproot fields remain after adding PSBT_IN_FINAL_SCRIPTWITNESS in finalize_psbt #1243

Closed
DanGould opened this issue Dec 18, 2023 · 3 comments · Fixed by #1310
Assignees
Labels
bug Something isn't working module-wallet
Milestone

Comments

@DanGould
Copy link

Describe the bug

Finalizers should remove PSBT_IN_TAP_* and PSBT_OUT_TAP_BIP32_DERIVATION after PSBT_IN_FINAL_SCRIPTWITNESS is constructed according to BIP 371 spec

To Reproduce

Fund a psbt with a taproot input. Call wallet.sign on it. See PSBT_IN_TAP_KEY_SIG present on output.

Expected behavior

Fund a psbt with a taproot input. Call wallet.sign on it. See PSBT_IN_TAP_KEY_SIG not present.

Build environment

  • BDK-CLI tag/commit: 1.0.0-alpha.1
  • Rust/Cargo version: 1.63.0, 1.76.0-nightly
  • Rust/Cargo target: wasm32-unknown-unknown

Additional context

I ran into this problem trying to take payjoin BDK-output Original PSBTs and process them at the receiver with walletprocesspsbt on bitcoind, and bitcoind failed to skip the inputs that it encountered having PSBT_IN_TAP_KEY_SIG belonging to the sender. Typically it'd just skip them.

I believe the issue could be fixed by calling clear() on the aforementioned fields here

psbt_input.final_script_sig = Some(tmp_input.script_sig);
psbt_input.final_script_witness = Some(tmp_input.witness);
if sign_options.remove_partial_sigs {
psbt_input.partial_sigs.clear();
}

@DanGould DanGould added the bug Something isn't working label Dec 18, 2023
@nondiremanuel nondiremanuel added this to BDK Jan 2, 2024
@nondiremanuel nondiremanuel modified the milestones: 1.0.0-alpha.4, 1.0.0 Jan 2, 2024
@nondiremanuel nondiremanuel moved this to Todo in BDK Jan 6, 2024
@ValuedMammal
Copy link
Contributor

I did verify the faulty behavior as you described - fields in a Psbt taproot input, such as tap_key_sig and others, hanging around after finalization, where the BIP clearly states they should be removed. I'll look at implementing a fix and report on any other findings. Thanks @DanGould for spotting the issue and giving a detailed description of what's expected.

ValuedMammal added a commit to ValuedMammal/bdk that referenced this issue Jan 31, 2024
… constructed

We currently allow removing `partial_sigs` from a finalized `Psbt`, which
is relevant to non-taproot inputs, however taproot related fields
were left in place despite the recommendation of BIP371 to remove them
once the `final_script_witness` is constructed. This may cause
confusion for parsers that encounter extra taproot metadata in an already
satisfied input.

Fix this by introducing a new memeber to SignOptions
`remove_taproot_extras`, which when true will remove extra taproot related
data from a `Psbt` upon successful finalization. This change makes
removal of all taproot extras the default.

fixes bitcoindevkit#1243
ValuedMammal added a commit to ValuedMammal/bdk that referenced this issue Jan 31, 2024
…cted

We currently allow removing `partial_sigs` from a finalized `Psbt`,
which is relevant to non-taproot inputs, however taproot related `Psbt`
fields were left in place despite the recommendation of BIP371 to remove
them once the `final_script_witness` is constructed. This can cause
confusion for parsers that encounter extra taproot metadata in an
already satisfied input.

Fix this by introducing a new memeber to SignOptions
`remove_taproot_extras`, which when true will remove extra taproot
related data from a `Psbt` upon successful finalization. This change
makes removal of all taproot extras the default but configurable.

fixes bitcoindevkit#1243
ValuedMammal added a commit to ValuedMammal/bdk that referenced this issue Feb 4, 2024
We currently allow removing `partial_sigs` from a finalized `Psbt`,
which is relevant to non-taproot inputs, however taproot related `Psbt`
fields were left in place despite the recommendation of BIP371 to remove
them once the `final_script_witness` is constructed. This can cause
confusion for parsers that encounter extra taproot metadata in an
already satisfied input.

Fix this by introducing a new member to SignOptions
`remove_taproot_extras`, which when true will remove extra taproot
related data from a `Psbt` upon successful finalization. This change
makes removal of all taproot extras the default but configurable.

fixes bitcoindevkit#1243
@notmandatory notmandatory moved this from Todo to In Progress in BDK Feb 5, 2024
ValuedMammal added a commit to ValuedMammal/bdk that referenced this issue Feb 7, 2024
We currently allow removing `partial_sigs` from a finalized `Psbt`,
which is relevant to non-taproot inputs, however taproot related `Psbt`
fields were left in place despite the recommendation of BIP371 to remove
them once the `final_script_witness` is constructed. This can cause
confusion for parsers that encounter extra taproot metadata in an
already satisfied input.

Fix this by introducing a new member to SignOptions
`remove_taproot_extras`, which when true will remove extra taproot
related data from a `Psbt` upon successful finalization. This change
makes removal of all taproot extras the default but configurable.

fixes bitcoindevkit#1243
@nondiremanuel nondiremanuel moved this from In Progress to Needs Review in BDK Mar 21, 2024
@github-project-automation github-project-automation bot moved this from Needs Review to Done in BDK Mar 22, 2024
@DanGould
Copy link
Author

Thanks for tackling this @evanlinjin

@evanlinjin
Copy link
Member

Thanks for tackling this @evanlinjin

It was mostly @ValuedMammal! I only reviewed and merged 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working module-wallet
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants