Skip to content

Conversation

sipa
Copy link
Member

@sipa sipa commented Jun 6, 2021

Includes:

  • First commit from Basic Taproot signing support for descriptor wallets #21365, adding TaprootSpendData in SigningProvider
  • A refactor to expose ComputeTapleafHash and ComputeTaprootMerkleRoot from script/interpreter
  • A tiny change to make getaddressinfo report tr() descriptors as solvable (so that inferred descriptors are shown), despite not having signing code for them.
  • Logic to infer the script tree back from TaprootSpendData, and then use that to infer descriptors.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 6, 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:

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.

Copy link
Member

@achow101 achow101 left a comment

Choose a reason for hiding this comment

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

ACK 77466ae

@sipa sipa force-pushed the 202106_infer_tap branch from 77466ae to f9d6f9a Compare June 8, 2021 00:37
@achow101
Copy link
Member

achow101 commented Jun 8, 2021

ACK f9d6f9a

@sipa sipa force-pushed the 202106_infer_tap branch from f9d6f9a to d81b193 Compare June 9, 2021 19:19
@meshcollider meshcollider added this to the 22.0 milestone Jun 9, 2021
@sipa sipa force-pushed the 202106_infer_tap branch from d81b193 to 13c6ab6 Compare June 12, 2021 21:02
@laanwj
Copy link
Member

laanwj commented Jun 14, 2021

Reviewed that the consensus commit (e3739fb) is a pure refactor.

Code review ACK 13c6ab6

@achow101
Copy link
Member

re-ACK 13c6ab6

KeyOriginInfo info;
if (provider.GetKeyOrigin(pubkey.GetID(), info)) {
return std::make_unique<OriginPubkeyProvider>(0, std::move(info), std::move(key_provider));
}
return key_provider;
}

std::unique_ptr<PubkeyProvider> InferXOnlyPubkey(const XOnlyPubKey& xkey, ParseScriptContext ctx, const SigningProvider& provider)
{
unsigned char full_key[33] = {0x02};
Copy link
Member

@laanwj laanwj Jun 15, 2021

Choose a reason for hiding this comment

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

I would have a slight preference to use constants here instead of hardcoding 0x02 (and 0x03 below) and 33.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with this, but prefer keeping it for a follow-up. There are several places where this is already done, and I'd like to introduce constants for it, as well as using them everywhere in the same PR - doing so here would be a distraction.

@sipa sipa force-pushed the 202106_infer_tap branch 2 times, most recently from 3f2ffb2 to 8349355 Compare June 15, 2021 21:56
@sipa
Copy link
Member Author

sipa commented Jun 15, 2021

Addressed some comments, and also made this observable change:

             if (permit_uncompressed || key.IsCompressed()) {
                 CPubKey pubkey = key.GetPubKey();
                 out.keys.emplace(pubkey.GetID(), key);
-                return std::make_unique<ConstPubkeyProvider>(key_exp_index, pubkey);
+                return std::make_unique<ConstPubkeyProvider>(key_exp_index, pubkey, ctx == ParseScriptContext::P2TR);
             } else {

Which will make descriptors with a provided private key inside tr() be interpreted as the equivalent xonly pubkey rather than the compressed or uncompressed one.

@achow101
Copy link
Member

re-ACK 8349355

@Sjors
Copy link
Member

Sjors commented Jun 16, 2021

It's too hot here to review code, but I can confirm that this correctly infers my tr(xpub...) and tr(xpub1, pk(xpub2)) descriptors (and surviving a roundtrip through deriveaddresses). Might be a good sanity check to try with a rebased #21329 too.

@laanwj
Copy link
Member

laanwj commented Jun 17, 2021

It's too hot here to review code

Same, I propose we postpone the feature freeze a bit. Not able to concentrate at the moment.

Copy link
Member

@Sjors Sjors left a comment

Choose a reason for hiding this comment

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

tACK 8349355

However I glanced over InferTaprootTree. I think it would help to include tests for the various problems that function is checking for.

subdesc = InferScript(script, ParseScriptContext::P2TR, provider);
}
if (!subdesc) {
ok = false;
Copy link
Member

Choose a reason for hiding this comment

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

8349355: rather than failing, could we return raw() (at least for leaf_ver == TAPROOT_LEAF_TAPSCRIPT)? That can wait for a followup though, since we can't have tr() descriptors with raw leaves in the wallet anyway atm, and raw() is still limited to the top level.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that's exactly what this code does.

@sipa
Copy link
Member Author

sipa commented Jun 18, 2021

Rebased, will work on adding some tests for failure cases of InferTaprootTree.

Copy link
Member

@Sjors Sjors left a comment

Choose a reason for hiding this comment

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

I think something went wrong in your rebase.

For example in the original 8349355 you changed the argument bool xonly = false to bool xonly in the ConstPubkeyProvider provider.

@sipa sipa force-pushed the 202106_infer_tap branch from 9d1d054 to d637a9b Compare June 18, 2021 18:30
@sipa
Copy link
Member Author

sipa commented Jun 18, 2021

@Sjors Oops, thanks for catching that. I redid the rebase; does it look better now?

@achow101
Copy link
Member

re-ACK d637a9b

Rebase looks good.

@Sjors
Copy link
Member

Sjors commented Jun 21, 2021

re-utACK d637a9b

Much better

Copy link
Contributor

@meshcollider meshcollider left a comment

Choose a reason for hiding this comment

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

Code review ACK d637a9b

std::vector<std::tuple<int, CScript, int>> ret;
if (spenddata.merkle_root.IsNull()) return ret;

/** Data structure to represent the nodes of the tree we're going to be build. */
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: to build

Copy link
Member

Choose a reason for hiding this comment

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

touched up the various nits in #22323, feel free to add any others there


/** Data structure to represent the nodes of the tree we're going to be build. */
struct TreeNode {
/** Hash of this none, if known; 0 otherwise. */
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: node

bool done = false;
};

// Build tree from the provides branches.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: provided

@meshcollider meshcollider merged commit 567670b into bitcoin:master Jun 23, 2021
@jonatack jonatack mentioned this pull request Jun 23, 2021
maflcko pushed a commit to bitcoin-core/gui that referenced this pull request Jun 23, 2021
184d453 script, doc: spelling update (Jon Atack)

Pull request description:

  Clears out the report from `test/lint/lint-spelling.sh` and touches up the leftover nits in bitcoin/bitcoin#22166 (review). Happy to add any others people are aware of.

ACKs for top commit:
  MarcoFalke:
    cr ACK 184d453
  Sjors:
    utACK 184d453

Tree-SHA512: 3b0ef6bd5ff227363b0bda79eeb66763151c74f607bc3a2a7bfe7823e3eef196587bccfe639e714e8e27b918ba57e8317eda06f225143c32c736685087dbcd24
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 24, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jun 24, 2021
184d453 script, doc: spelling update (Jon Atack)

Pull request description:

  Clears out the report from `test/lint/lint-spelling.sh` and touches up the leftover nits in bitcoin#22166 (review). Happy to add any others people are aware of.

ACKs for top commit:
  MarcoFalke:
    cr ACK 184d453
  Sjors:
    utACK 184d453

Tree-SHA512: 3b0ef6bd5ff227363b0bda79eeb66763151c74f607bc3a2a7bfe7823e3eef196587bccfe639e714e8e27b918ba57e8317eda06f225143c32c736685087dbcd24
fanquake added a commit that referenced this pull request Aug 23, 2021
08f57a0 Assert that IsComplete() in GetSpendData() (Pieter Wuille)
d8f4b97 Remove default nHashTypeIn arguments to MutableTransactionSignatureCreator (Pieter Wuille)
c7048aa Simplify SignTransaction precomputation loop (Pieter Wuille)
addb9b5 Improve comments in taproot signing logic (Pieter Wuille)

Pull request description:

  This addresses a few review comments from #21365 that were left at the time of merge (as well as some from #22166 applying to the commit it shared with #21365).

  I do not think any are blockers for a 22.0 release.

ACKs for top commit:
  theStack:
    re-ACK 08f57a0 🌴
  Zero-1729:
    crACK 08f57a0
  jonatack:
    Code review ACK 08f57a0 per `git range-diff e9d6eb1 9336670 08f57a0` followed by re-code review per commit to swap context back into memory and debug build/run unit tests + feature_taproot.py as a sanity check

Tree-SHA512: 968750109ba8d6faf3016035a38f81c6aefb724c632a3cab0bbf43cf31b9d187b6b0fddd8772768f57338df11eb07ab9c4c6dacdf3cf35b71f29699c67a301ea
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Aug 23, 2021
08f57a0 Assert that IsComplete() in GetSpendData() (Pieter Wuille)
d8f4b97 Remove default nHashTypeIn arguments to MutableTransactionSignatureCreator (Pieter Wuille)
c7048aa Simplify SignTransaction precomputation loop (Pieter Wuille)
addb9b5 Improve comments in taproot signing logic (Pieter Wuille)

Pull request description:

  This addresses a few review comments from bitcoin#21365 that were left at the time of merge (as well as some from bitcoin#22166 applying to the commit it shared with bitcoin#21365).

  I do not think any are blockers for a 22.0 release.

ACKs for top commit:
  theStack:
    re-ACK 08f57a0 🌴
  Zero-1729:
    crACK 08f57a0
  jonatack:
    Code review ACK 08f57a0 per `git range-diff e9d6eb1 9336670 08f57a0` followed by re-code review per commit to swap context back into memory and debug build/run unit tests + feature_taproot.py as a sanity check

Tree-SHA512: 968750109ba8d6faf3016035a38f81c6aefb724c632a3cab0bbf43cf31b9d187b6b0fddd8772768f57338df11eb07ab9c4c6dacdf3cf35b71f29699c67a301ea
gwillen pushed a commit to ElementsProject/elements that referenced this pull request Jun 1, 2022
@@ -1847,16 +1847,14 @@ static bool ExecuteWitnessScript(const Span<const valtype>& stack_span, const CS
return true;
}

static bool VerifyTaprootCommitment(const std::vector<unsigned char>& control, const std::vector<unsigned char>& program, const CScript& script, uint256& tapleaf_hash)
uint256 ComputeTapleafHash(uint8_t leaf_version, const CScript& script)
Copy link
Contributor

Choose a reason for hiding this comment

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

I mildly object the the use of the type CScript here. While it is true that BIP-341 names this stack item "script", this value is only interpreted as a CScript in the case of BIP-342 where the leaf_version is equal to TAPROOT_LEAF_TAPSCRIPT (modulo TAPROOT_LEAF_MASK). Otherwise it is simply a bytestring.

@bitcoin bitcoin locked and limited conversation to collaborators Aug 12, 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.

8 participants