Skip to content

psbt: add new fields for MuSig2 - #2198

Open
guggero wants to merge 10 commits into
btcsuite:masterfrom
guggero:bip-musig2-psbt
Open

guggero wants to merge 10 commits into
btcsuite:masterfrom
guggero:bip-musig2-psbt

Conversation

@guggero

@guggero guggero commented Jun 14, 2024 •

Copy link
Copy Markdown
Collaborator

Implements the new input and output fields to the PSBT library according to BIP-0373.

@coveralls

coveralls commented Jun 14, 2024 •

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 9513655947

Details

  • 4 of 240 (1.67%) changed or added relevant lines in 3 files are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.2%) to 56.774%

Changes Missing Coverage Covered Lines Changed/Added Lines %
btcutil/psbt/partial_output.go 1 22 4.55%
btcutil/psbt/partial_input.go 3 63 4.76%
btcutil/psbt/musig2.go 0 155 0.0%
Files with Coverage Reduction New Missed Lines %
connmgr/connmanager.go 3 86.27%
Totals Coverage Status
Change from base Build 9348961734: -0.2%
Covered Lines: 29625
Relevant Lines: 52181

💛 - Coveralls

@coveralls

coveralls commented Jun 14, 2024 •

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 9519109524

Details

  • 4 of 381 (1.05%) changed or added relevant lines in 5 files are covered.
  • 8 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.4%) to 56.6%

Changes Missing Coverage Covered Lines Changed/Added Lines %
btcutil/psbt/partial_output.go 1 22 4.55%
btcutil/psbt/utils.go 0 22 0.0%
btcutil/psbt/partial_input.go 3 63 4.76%
btcutil/psbt/finalizer.go 0 119 0.0%
btcutil/psbt/musig2.go 0 155 0.0%
Files with Coverage Reduction New Missed Lines %
connmgr/connmanager.go 3 86.27%
txscript/taproot.go 5 95.31%
Totals Coverage Status
Change from base Build 9348961734: -0.4%
Covered Lines: 29614
Relevant Lines: 52322

💛 - Coveralls

@coveralls

coveralls commented Jun 15, 2024 •

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 9528732501

Details

  • 4 of 381 (1.05%) changed or added relevant lines in 5 files are covered.
  • 11 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.4%) to 56.603%

Changes Missing Coverage Covered Lines Changed/Added Lines %
btcutil/psbt/partial_output.go 1 22 4.55%
btcutil/psbt/utils.go 0 22 0.0%
btcutil/psbt/partial_input.go 3 63 4.76%
btcutil/psbt/finalizer.go 0 119 0.0%
btcutil/psbt/musig2.go 0 155 0.0%
Files with Coverage Reduction New Missed Lines %
connmgr/connmanager.go 2 87.32%
peer/peer.go 9 73.72%
Totals Coverage Status
Change from base Build 9348961734: -0.4%
Covered Lines: 29616
Relevant Lines: 52322

💛 - Coveralls

@coveralls

coveralls commented Jun 15, 2024 •

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 9528834149

Details

  • 4 of 381 (1.05%) changed or added relevant lines in 5 files are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.4%) to 56.626%

Changes Missing Coverage Covered Lines Changed/Added Lines %
btcutil/psbt/partial_output.go 1 22 4.55%
btcutil/psbt/utils.go 0 22 0.0%
btcutil/psbt/partial_input.go 3 63 4.76%
btcutil/psbt/finalizer.go 0 119 0.0%
btcutil/psbt/musig2.go 0 155 0.0%
Files with Coverage Reduction New Missed Lines %
connmgr/connmanager.go 3 86.97%
Totals Coverage Status
Change from base Build 9348961734: -0.4%
Covered Lines: 29628
Relevant Lines: 52322

💛 - Coveralls

@coveralls

coveralls commented Jun 15, 2024 •

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 9528865705

Details

  • 4 of 387 (1.03%) changed or added relevant lines in 5 files are covered.
  • 12 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.4%) to 56.607%

Changes Missing Coverage Covered Lines Changed/Added Lines %
btcutil/psbt/partial_output.go 1 22 4.55%
btcutil/psbt/utils.go 0 22 0.0%
btcutil/psbt/partial_input.go 3 63 4.76%
btcutil/psbt/finalizer.go 0 125 0.0%
btcutil/psbt/musig2.go 0 155 0.0%
Files with Coverage Reduction New Missed Lines %
connmgr/connmanager.go 3 86.27%
peer/peer.go 9 73.72%
Totals Coverage Status
Change from base Build 9348961734: -0.4%
Covered Lines: 29621
Relevant Lines: 52327

💛 - Coveralls

@coveralls

coveralls commented Jun 15, 2024 •

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 9528900206

Details

  • 6 of 389 (1.54%) changed or added relevant lines in 5 files are covered.
  • 12 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.4%) to 56.587%

Changes Missing Coverage Covered Lines Changed/Added Lines %
btcutil/psbt/partial_output.go 1 22 4.55%
btcutil/psbt/utils.go 0 22 0.0%
btcutil/psbt/partial_input.go 3 63 4.76%
btcutil/psbt/finalizer.go 2 127 1.57%
btcutil/psbt/musig2.go 0 155 0.0%
Files with Coverage Reduction New Missed Lines %
connmgr/connmanager.go 3 86.27%
peer/peer.go 9 73.49%
Totals Coverage Status
Change from base Build 9348961734: -0.4%
Covered Lines: 29611
Relevant Lines: 52328

💛 - Coveralls

@coveralls

coveralls commented Jan 19, 2025 •

Copy link
Copy Markdown

Coverage Report for CI Build 43187535476

Coverage increased (+0.8%) to 54.631%

Details

  • Coverage increased (+0.8%) from the base build.
  • Patch coverage: 223 uncovered changes across 8 files (975 of 1198 lines covered, 81.39%).
  • 12 coverage regressions across 2 files.

Uncovered Changes

File Changed Covered %
psbt/finalizer.go 546 441 80.77%
psbt/musig2_signing.go 181 145 80.11%
psbt/musig2.go 191 169 88.48%
psbt/partial_input.go 86 68 79.07%
psbt/updater.go 68 54 79.41%
psbt/utils.go 41 27 65.85%
psbt/partial_output.go 29 21 72.41%
psbt/signer.go 50 44 88.0%
Total (10 files) 1198 975 81.39%

Coverage Regressions

12 previously-covered lines in 2 files lost coverage.

File Lines Losing Coverage Coverage
btcec/v2/ellswift/ellswift.go 10 75.45%
wire/v2/message.go 2 52.26%

Coverage Stats

Coverage Status
Relevant Lines: 58223
Covered Lines: 31808
Line Coverage: 54.63%
Coverage Strength: 263826.02 hits per line

💛 - Coveralls

@guggero
guggero force-pushed the bip-musig2-psbt branch from 8e879e1 to 35a2775 Compare May 12, 2025 05:18
@guggero
guggero force-pushed the bip-musig2-psbt branch 2 times, most recently from e4bb95c to 04ec8d7 Compare May 20, 2026 13:03
@guggero

guggero commented May 20, 2026

Copy link
Copy Markdown
Collaborator Author

The BIP-0373 PR was merged a while ago. I also rebased on latest master that has the Golang module fixes and addressed all TODOs. This is ready for review IMO.

@guggero
guggero marked this pull request as ready for review May 20, 2026 13:04
Comment thread psbt/musig2.go Resolved
Comment thread psbt/musig2.go Resolved
Comment thread psbt/musig2.go Resolved
Comment thread psbt/utils.go Resolved
Comment thread psbt/finalizer.go Resolved
Comment thread psbt/finalizer.go Resolved
@guggero
guggero force-pushed the bip-musig2-psbt branch 2 times, most recently from 6fc877f to c9f6407 Compare August 12, 2026 19:35
@guggero

guggero commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator Author

@TechLateef thank you very much for the thorough review! I've addressed all your comments.

@sputn1ck sputn1ck left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

BIP-373 implementation review. Inline findings below.

Comment thread psbt/finalizer.go Resolved
Comment thread psbt/finalizer.go Resolved
Comment thread psbt/finalizer.go Resolved
Comment thread psbt/finalizer.go Resolved
Comment thread psbt/utils.go Resolved
Comment thread psbt/finalizer.go Resolved
Comment thread psbt/updater.go Resolved
Comment thread psbt/partial_input.go Resolved
@guggero
guggero requested a review from sputn1ck August 14, 2026 08:51

@TechLateef TechLateef left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM!

@guggero
guggero force-pushed the bip-musig2-psbt branch 2 times, most recently from b6c1164 to e1f6af4 Compare September 29, 2026 12:56
@fametrano

Copy link
Copy Markdown
Contributor

tACK e1f6af4: the BIP373 fields serialize byte for byte the way btclib-wallet's independent implementation does, in both directions. We checked whether a PSBT written by one implementation reads back unchanged in the other, and whether the MuSig2 sessions it carries still sign and finalize. Both hold for every case we tried. This tests interop, not the finalizer's code.

Of BIP373's 24 vectors, both libraries re-serialize the 14 valid ones to identical bytes and reject the 10 invalid ones. We then ran full sessions on cases 1a to 4a twice: once signed by btcd through MuSig2SigningInfos, once by btclib-wallet. Each session included an output participants record that was not in sorted order. Each library re-serialized the other's PSBTs to identical bytes. btclib-wallet also verified btcd's partial signatures one by one. Each library then aggregated and finalized them, and its script engine accepted the spend. This covered key-path, script-path and BIP328-derived sessions. We added a PSBT with several participant records per map and reversed every MuSig2 slice before serializing. btcd still wrote the same canonical order as btclib-wallet. We ran this as a scratch _test.go in psbt plus a Python script over btclib-wallet, and can share both.

pmazzocchi added a commit to btclib-org/btclib-wallet that referenced this pull request Oct 23, 2026
…loses #498)

rust-psbt's vector files are vendored under tests/psbt/_data/rust-psbt/,
each pinned at the tip of its path, and tests/psbt/rust_psbt_test.py runs
every case by its task: parse or refuse, BIP174's Creator, Updater, Signer,
Combiner, Finalizer and Extractor walk-through, and BIP370's lock time. A
task it has no test for fails the module.

Where rust-psbt's file and btclib-wallet part, the test says so. One case
of bip371.json holds the hex in its base64 field and is xfail. rust-psbt's
runner reads supplementary.psbts alone, so it parses none of the psbts
that bip371.json and bip174.json keep under expected; the test reads both.
bip375.json asks a parser to refuse BIP375's role failures, which
btclib-wallet refuses in its silent payment roles: the test asks such a
psbt to be one of BIP375's own invalid ones. The walk-through's Signer
cases are signed without low-R grinding, as BIP174's example was.

The psbts btcd's MuSig2 code signed (btcsuite/btcd#2198 at
e1f6af43) from BIP373's participants-only vectors are vendored under
tests/psbt/_data/btcd/ with btcd's ISC license and the Go program that
made them. musig2_test.py reads each back byte for byte, checks btcd added
only nonces and partial signatures to BIP373's psbt, verifies every
partial signature, aggregates them and has the script engine accept the
finalized spend. tests/_data/README.md records both provenances and the
commands that redo them.

The BIP174 entry points at rust-psbt's file for the walk-through, and
psbt_test.py's comment about missing Updater tests points at the new
module. .secrets.baseline takes the new files' keys and psbts, and
pyproject.toml's typos table btcd's SignSuccesful.

Closes #485
Closes #498

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: pmazzocchi <paolo@checksig.io>
pmazzocchi added a commit to btclib-org/btclib-wallet that referenced this pull request Oct 23, 2026
…loses #498)

rust-psbt's vector files are vendored under tests/psbt/_data/rust-psbt/,
each pinned at the latest commit touching its path on rust-psbt's master
at 51b0ea82. tests/psbt/rust_psbt_test.py runs every case by its task:
parse or refuse, BIP174's Creator, Updater, Signer, Combiner, Finalizer
and Extractor, and BIP370's lock time. A task it has no test for fails
test_every_task_is_replayed. It reads a psbt both from
supplementary.psbts and from expected, as rust-psbt's runner does at
51b0ea82, and no case is xfail.

bip375.json asks a parser to refuse BIP375's invalid psbts.
btclib-wallet's codec refuses those with a field of the wrong shape and
its silent payment roles the rest, so the test asks a psbt the codec
reads to be one of BIP375's own invalid ones. The Signer cases are
signed without low-R grinding, as BIP174's example was.

The psbts btcd's MuSig2 code (btcsuite/btcd#2198 at e1f6af43) signed
from BIP373's participants-only vectors are vendored under
tests/psbt/_data/btcd/, with btcd's ISC license and the Go program that
made them. musig2_test.py reads each back byte for byte, checks that btcd
added only nonces and partial signatures to the BIP373 psbt its
description names, verifies every partial signature, aggregates them and
has the script engine accept the finalized spend. tests/_data/README.md
records both provenances and the commands that redo them.

The BIP174 entry points at rust-psbt's file for the walk-through, and
psbt_test.py's comment about missing Updater tests points at the new
module. .gitattributes keeps the new JSON files' bytes as they are,
.secrets.baseline takes their keys and psbts, and pyproject.toml's typos
table takes btcd's SignSuccesful.

Closes #485
Closes #498

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Signed-off-by: pmazzocchi <paolo@checksig.io>
Allows other packages to use the ComputeSigningNonce function.
A MuSig2 signer needs the same facts the finalizer infers when combining
partial signatures: the participants record to aggregate in, the key to
record in the nonce and partial signature key data, the tweaks that turn
the bare aggregate into the key the signature is checked against, and
the message to sign. Until now that inference was private to the
finalizer, so every signer would have had to re-implement it and could
silently disagree with it.

MuSig2SigningInfos exposes it for one participant of one input. It
reuses the finalizer's BIP-328 derivation and taproot tweak helpers and
only returns a context once the inferred tweaks reproduce the output key
or the key found in the leaf script, so a signer following it produces
partial signatures the finalizer can combine.
@fametrano

Copy link
Copy Markdown
Contributor

reACK f3d665a

Since e1f6af4 the branch was rebased on master. The only change to the PR's own lines is that it no longer adds the testify import, which master's psbt/utils_test.go now has. On this head go test passes in psbt and btcec/schnorr/musig2, and btcd signed BIP373's cases 1a to 4a again; the cross-check from my earlier review read back, verified and finalized all four.

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.

5 participants