Skip to content

Conversation

@OttoAllmendinger
Copy link
Contributor

This PR improves test coverage of the p2tr and p2trMusig2 script types.

  • Adds the official BIP-327 python reference implementation with test vectors
  • Adds support for the deprecated key aggregation method to the python reference implementation
  • Adds comprehensive test fixtures for p2tr and p2trMusig2 output scripts
  • Clarifies documentation on the differences between:
    • Legacy p2tr (chains 30/31) using BitGo's MuSig2 variant
    • Recommended p2trMusig2 (chains 40/41) using standard MuSig2

The implementation ensures consistent behavior across both variants and
includes detailed tests to validate key aggregation, tree structure,
output script generation, and proper key ordering.

Issue: BTC-2652

@OttoAllmendinger OttoAllmendinger force-pushed the BTC-2652.improve-p2tr-tests branch from 0d2d2f5 to 38a3d69 Compare October 16, 2025 15:02
@OttoAllmendinger OttoAllmendinger marked this pull request as ready for review October 16, 2025 16:12
@OttoAllmendinger OttoAllmendinger requested a review from a team as a code owner October 16, 2025 16:12
@OttoAllmendinger OttoAllmendinger marked this pull request as draft October 17, 2025 05:39
@OttoAllmendinger OttoAllmendinger force-pushed the BTC-2652.improve-p2tr-tests branch from 38a3d69 to d55c540 Compare October 17, 2025 11:24
OttoAllmendinger and others added 4 commits October 17, 2025 13:49
Add the BIP-327 reference implementation for MuSig2 multi-signature protocol
including Python code and test vectors.

Issue: BTC-2652

1: https://github.com/bitcoin/bips/blob/ab9d5b8/bip-0327/reference.py

Co-authored-by: llm-git <llm-git@ttll.de>
This adds a helper to verify that a fixture matches an expected value.

Issue: BTC-2652

Co-authored-by: llm-git <llm-git@ttll.de>
This adds a modified version of BIP-0327 reference implementation to
support BitGo's legacy p2tr aggregation method. The implementation adds:

1. Support for x-only pubkeys in key aggregation
2. Legacy p2tr aggregation function that converts to x-only format before
   sorting
3. Enhanced sign and verify functions to handle both pubkey formats
4. Comprehensive test cases to verify both standard MuSig2 (p2trMusig2)
   and legacy p2tr behavior

Issue: BTC-2652

Co-authored-by: llm-git <llm-git@ttll.de>
This commit adds comprehensive documentation to explain the differences
between BitGo's legacy p2tr (chains 30, 31) and standard p2trMusig2
(chains 40, 41) address types. It clarifies how their key aggregation
algorithms differ, particularly regarding when x-only conversion happens.

Additionally, it adds thorough tests with fixtures for both address types
to demonstrate their behavior and ensure compatibility.

Issue: BTC-2652

Co-authored-by: llm-git <llm-git@ttll.de>
@OttoAllmendinger OttoAllmendinger force-pushed the BTC-2652.improve-p2tr-tests branch from d55c540 to cb5bed1 Compare October 17, 2025 11:50
@OttoAllmendinger OttoAllmendinger marked this pull request as ready for review October 17, 2025 13:07
Copy link
Contributor

@davidkaplanbitgo davidkaplanbitgo left a comment

Choose a reason for hiding this comment

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

I dont know how useful having the python fixture generation documentation in here is. Maybe just a link to it is fine

@OttoAllmendinger
Copy link
Contributor Author

I dont know how useful having the python fixture generation documentation in here is. Maybe just a link to it is fine

The bips/bip-0327 actually contains the modified bip-0327 reference impl that works with the legacy p2tr code. I decided to copy the full directory so I have to keep modifications to the reference impl to a minimum.

@lcovar lcovar merged commit 8609b2c into master Oct 20, 2025
13 checks passed
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.

4 participants