Skip to content

Conversation

achow101
Copy link
Member

@achow101 achow101 commented Jul 26, 2021

Implements the Taproot fields for PSBT described in BIP 371.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 27, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #23578 (Add external signer taproot support by Sjors)
  • #23502 (wallet: Avoid underpaying transaction fees when signing taproot spends by achow101)
  • #21283 (Implement BIP 370 PSBTv2 by achow101)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@mjdietzx
Copy link
Contributor

mjdietzx commented Sep 1, 2021

Concept and Approach ACK. I was experimenting with a basic taproot n-of-m multisig using a single OP_CHECKSIGADD based script on top of this branch. Taproot fields in the PSBTs I was creating (and attempting to sign - although I haven't got that working yet) looked good when I inspected them. I did some very light testing of this, mostly sanity checks

@Sjors
Copy link
Member

Sjors commented Nov 22, 2021

Needs rebase due to silent merge conflict in descriptor.cpp.

@achow101 achow101 force-pushed the taproot-psbt branch 2 times, most recently from 687eaaa to 58af891 Compare November 25, 2021 04:07
achow101 added 13 commits June 27, 2022 16:47
TaprootSpendData can be gotten from TaprootBuilder, however for PSBT, we
also need TaprootBuilders directly (for the outputs). So we store the
TaprootBuilder in the FlatSigningProvider and when the TaprootSpendData
is needed, we generate it on the fly using the stored builder.
GetSpendData needs to be finalized in order to be used. To avoid future
bugs, assert `!m_output_key.IsNull()` as m_output_key is only set during
Finalize.
If all inputs are segwit v1+, the non_witness_utxos can be removed.
Actually use pre-existing signatures in CreateTaprootScriptSig if a
signature is found for the given key and leaf hash.
The taproot spenddata stored in a sigdata is the combination of data
existing previously (e.g. in a PSBT) and the data stored in a
SigningProvider. In order to use the external data when signing, we need
to be using the sigdata's spenddata.
When filling a PSBT, we search the listed pubkeys in order to determine
whether the current DescriptorScriptPubKeyMan could sign the transaction
even if it is not watching the scripts. With Taproot, the taproot
pubkeys need to be searched as well.
@laanwj
Copy link
Member

laanwj commented Jun 28, 2022

Code review ACK b80de4c

@laanwj laanwj merged commit 5bf65ec into bitcoin:master Jun 28, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 28, 2022
@maflcko
Copy link
Member

maflcko commented Jun 30, 2022

@bitcoin bitcoin deleted a comment Jun 30, 2022
@Sjors
Copy link
Member

Sjors commented Jun 30, 2022

@MarcoFalke that's a different one than we found: #22558 (review)

(not that that's great news)

s_tree >> depth;
s_tree >> leaf_ver;
s_tree >> script;
m_tap_tree->Add((int)depth, script, (int)leaf_ver, true /* track */);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only place where we call TaprootBuilder::Add (in this PR). We're not checking leaf_ver here, so with a corrupt PSBT the leaf_version & ~TAPROOT_LEAF_MASK assert gets hit.

azuchi added a commit to chaintope/bitcoinrb that referenced this pull request Jul 7, 2022
@maflcko
Copy link
Member

maflcko commented Jul 19, 2022

@achow101
Copy link
Member Author

fanquake added a commit that referenced this pull request Jul 19, 2022
76fb300 psbt: Check Taproot tree depth and leaf versions (Andrew Chow)

Pull request description:

  Since TaprootBuilder has assertions for the depth and leaf versions, the
  PSBT decoder should check these values before calling
  TaprootBuilder::Add so that the assertions are not triggered on
  malformed taproot trees.

  Fixes #22558 (comment)

ACKs for top commit:
  Sjors:
    utACK 76fb300
  sipa:
    utACK 76fb300
  w0xlt:
    ACK 76fb300

Tree-SHA512: 94b288bc1453d10bce9a8a6389bc866f2c71c76579b7908e22d6b5770ac387086f6221af8597668e62977d4d6861fe2d72ec7b052002a2c36769d056b2e66360
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jul 20, 2022
76fb300 psbt: Check Taproot tree depth and leaf versions (Andrew Chow)

Pull request description:

  Since TaprootBuilder has assertions for the depth and leaf versions, the
  PSBT decoder should check these values before calling
  TaprootBuilder::Add so that the assertions are not triggered on
  malformed taproot trees.

  Fixes bitcoin#22558 (comment)

ACKs for top commit:
  Sjors:
    utACK 76fb300
  sipa:
    utACK 76fb300
  w0xlt:
    ACK bitcoin@76fb300

Tree-SHA512: 94b288bc1453d10bce9a8a6389bc866f2c71c76579b7908e22d6b5770ac387086f6221af8597668e62977d4d6861fe2d72ec7b052002a2c36769d056b2e66360
fanquake added a commit that referenced this pull request Oct 26, 2022
796b020 wallet: add taproot support to external signer (Sjors Provoost)

Pull request description:

  Builds on #22558 (merged on 2022-06-28).

  [HWI 2.1.0](https://github.com/bitcoin-core/HWI/releases/tag/2.1.0) or newer is required to import and use taproot descriptors. Older versions will work, but won't import a taproot descriptor.

  Tested with HWI 2.1.1:
  * Trezor T (firmware v2.5.1) on Signet: signs, change detection works
  * Ledger Nano S (firmware 2.1.0, Bitcoin app 2.0.6): signs, change detection works

  Only the most basic `tr(key)` descriptor is supported, script path spending is completely untested (if it works at all).

ACKs for top commit:
  jb55:
    utACK 796b020
  achow101:
    ACK 796b020

Tree-SHA512: 6dcb7eeb45421a3bbf2bdabeacd29979867db69077d7bf192bb77faa4bfefe446487b8df07bc40f9457009a88e598bdc09f769e6106fed2833ace7ef205a157a
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Oct 27, 2022
796b020 wallet: add taproot support to external signer (Sjors Provoost)

Pull request description:

  Builds on bitcoin#22558 (merged on 2022-06-28).

  [HWI 2.1.0](https://github.com/bitcoin-core/HWI/releases/tag/2.1.0) or newer is required to import and use taproot descriptors. Older versions will work, but won't import a taproot descriptor.

  Tested with HWI 2.1.1:
  * Trezor T (firmware v2.5.1) on Signet: signs, change detection works
  * Ledger Nano S (firmware 2.1.0, Bitcoin app 2.0.6): signs, change detection works

  Only the most basic `tr(key)` descriptor is supported, script path spending is completely untested (if it works at all).

ACKs for top commit:
  jb55:
    utACK 796b020
  achow101:
    ACK 796b020

Tree-SHA512: 6dcb7eeb45421a3bbf2bdabeacd29979867db69077d7bf192bb77faa4bfefe446487b8df07bc40f9457009a88e598bdc09f769e6106fed2833ace7ef205a157a
@bitcoin bitcoin locked and limited conversation to collaborators Jul 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.