Skip to content

btcutil: Add library functions for BIP-0352 silent payment _send_ support - #2244

Open
guggero wants to merge 8 commits into
btcsuite:masterfrom
guggero:silent-payments
Open

guggero wants to merge 8 commits into
btcsuite:masterfrom
guggero:silent-payments

Conversation

@guggero

@guggero guggero commented Sep 1, 2024 •

Copy link
Copy Markdown
Collaborator

Adds library/API functionality for Silent Payment send support.

Implements the following BIPs (or pull requests to BIPs):

Goal is to address send support first as that's rather straightforward. Receive support is much more involved as it requires scanning the chain in a specific manner.

@coveralls

coveralls commented Oct 20, 2024 •

Copy link
Copy Markdown

Coverage Report for CI Build 43187531181

Coverage increased (+0.07%) to 53.905%

Details

  • Coverage increased (+0.07%) from the base build.
  • Patch coverage: 34 uncovered changes across 4 files (164 of 198 lines covered, 82.83%).
  • 35 coverage regressions across 5 files.

Uncovered Changes

File Changed Covered %
psbt/partial_output.go 42 26 61.9%
psbt/partial_input.go 44 36 81.82%
psbt/psbt.go 53 45 84.91%
psbt/silentpayments.go 59 57 96.61%

Coverage Regressions

35 previously-covered lines in 5 files lost coverage.

File Lines Losing Coverage Coverage
wire/v2/netaddressv2.go 12 21.37%
btcec/v2/ellswift/ellswift.go 9 70.09%
wire/v2/msgaddrv2.go 8 10.42%
peer/peer.go 4 72.23%
integration/rpctest/utils.go 2 36.84%

Coverage Stats

Coverage Status
Relevant Lines: 57052
Covered Lines: 30754
Line Coverage: 53.91%
Coverage Strength: 240445.97 hits per line

💛 - Coveralls

@guggero
guggero force-pushed the silent-payments branch 4 times, most recently from 2a9a931 to 996c4d3 Compare December 31, 2024 08:19
@saubyk saubyk added this to the v0.25 milestone Feb 13, 2025
@saubyk
saubyk requested a review from kcalvinalvin February 18, 2025 00:48
@guggero
guggero marked this pull request as ready for review March 28, 2025 20:37
@guggero
guggero force-pushed the silent-payments branch 2 times, most recently from 88fa441 to 8a4fe70 Compare March 28, 2025 20:47
@benma

benma commented Aug 14, 2025

Copy link
Copy Markdown
Contributor

This is great work and very welcome. However, BIP-375 specifies exclusion for PSBTv0, so this will not be compatible with other PSBT libraries/wallets. Imho it would be best to focus on adding support for PSBTv2 first (#2328).

@myxmaster

Copy link
Copy Markdown

Hey, just wanted to drop a quick note as an LND user who's been following this PR and the overall silent payments effort.

I understand that PSBTv2 support (#2328) would be needed for full BIP375 compliance and interoperability with external signers/hardware wallets. But even without that, having SP send support land in btcutil would already be a huge step forward, since it would unblock LND PR lightningnetwork/lnd#9398 and allow LND users to send to silent payment addresses using LND's internal wallet and signer.

Would love to see this land. Thanks for all the great work on this @guggero!

@TechLateef

Copy link
Copy Markdown

Hey @guggero and @benma , just a heads up that I'm starting work on the PSBTv2 support requested in #2328. Hopefully, that will help unblock full BIP375 compliance for this PR soon!

Comment thread silentpayments/dleq.go Resolved
Comment thread silentpayments/dleq.go Resolved
Comment thread silentpayments/input.go Resolved
Comment thread silentpayments/address.go Resolved
Comment thread psbt/partial_output.go Resolved
Comment thread psbt/partial_output.go Resolved
Comment thread silentpayments/dleq.go Resolved
Comment thread silentpayments/address.go Resolved

@yyforyongyu yyforyongyu 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.

Fired some agents to review it while catching up with the bip🤓

@ping-localhost

Copy link
Copy Markdown

I currently use btcutil.DecodeAddress to validate if a provided Bitcoin address is valid. Seeing how it hasn't been changed, I'll have to make a fallback for Silent Payments once this is merged?

Is it maybe a good idea to add a more generic ValidateAddress-function that can deal with all types? Just brain dumping, so feel free to ignore me.

@guggero

guggero commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator Author

I currently use btcutil.DecodeAddress to validate if a provided Bitcoin address is valid. Seeing how it hasn't been changed, I'll have to make a fallback for Silent Payments once this is merged?

Is it maybe a good idea to add a more generic ValidateAddress-function that can deal with all types? Just brain dumping, so feel free to ignore me.

Hmm, that's a valid point. But I'm not sure what would be best here. Adding anything to the existing DecodeAddress in the now-extracted address/v2 package can't be done, as that would introduce a circular package dependency.
And adding a new DecodeAnyAddress would need to return an address.Address interface. But that interface requires the ScriptAddress() []byte method to be defined that can be used to produce the pkScript of a receiver output.
But that's exactly the complication with Silent Payment addresses: They are dependent on the inputs being spent.
So for safety reasons, the ScriptAddress method would need to panic for Silent Payment addresses and any caller would need to know how to deal with them.

So perhaps a simple silentpayments.IsValidAddress() would be enough to make the detection easier?

@guggero

guggero commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks a lot for the review, @yyforyongyu! I addressed all your points and did a full (agentic) review against the three updated BIPs and made sure all updated test vectors also pass. Should be quite solid now.

@ping-localhost

Copy link
Copy Markdown

So perhaps a simple silentpayments.IsValidAddress() would be enough to make the detection easier?

Yeah, that would help already! Anything to make the process easier is very much appreciated.

@guggero

guggero commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator Author

So perhaps a simple silentpayments.IsValidAddress() would be enough to make the detection easier?

Yeah, that would help already! Anything to make the process easier is very much appreciated.

Okay, I've added IsValidAddress(string) bool.

@fametrano fametrano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed at 55d755d.

I checked the sending side against btclib-wallet on 200 random cases: P2PKH, P2WPKH, P2SH-P2WPKH and P2TR inputs with odd and even keys, 1 to 5 inputs, 1 to 6 addresses, labels including m = 0 and 2^32-1, repeated addresses. CreateOutputs gives the same 730 output keys. 200 BIP374 proofs, half with a message, are byte-equal to btclib's and pass DLEQVerify. The 28 BIP352 sending vectors run, and go test passes in silentpayments and psbt.

Findings are inline. One more, on the test data: two vector files are behind bitcoin/bips master (927b6de). bip-0374_test_vectors_verify_proof.csv lacks rows 15 and 16 (e = n, s = n); all 17 upstream rows pass. bip375_test_vectors.json lacks the valid vector "bare OP_2 script is not a segwit v2 witness program" (e726d13) and the invalid one for a wrong PSBT_OUT_SP_V0_LABEL length (7ccde10). With the upstream file, ReadSilentPaymentLabel rejects that vector and the SP fields of all 20 valid vectors round-trip.

Comment thread silentpayments/input.go Resolved
Comment thread silentpayments/input.go Resolved
Comment thread silentpayments/dleq.go Resolved
Comment thread silentpayments/address.go Resolved
Comment thread silentpayments/address.go Resolved
Comment thread silentpayments/input.go Resolved
Comment thread silentpayments/output.go Resolved
@guggero

guggero commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

Thank you very much for your review, @fametrano!
I've addressed all your comments (and rebased on latest master to fix a merge conflict) in the latest push.

@fametrano

Copy link
Copy Markdown
Contributor

I re-checked my seven earlier comments on 35b72df, and all are fixed. The test vector files now match bitcoin/bips master, and go test and go vet pass in silentpayments and psbt. Two things are left: the Makefile's unit, unit-cover and unit-race targets don't include the new silentpayments module, so CI never runs its tests. Its go.mod also says go 1.26.0, while the other modules say go 1.26.9, which scripts/check_go_versions.sh requires. With those fixed I'm happy to ACK.

@guggero

guggero commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator Author

Great catch, thank you! I've updated the go.mod and added the submodule to the Makefile.

@fametrano

Copy link
Copy Markdown
Contributor

ACK 94eecd6

Both points are fixed: unit, unit-cover and unit-race now run the silentpayments tests, and its go.mod says go 1.26.9. A range-diff against 35b72df shows no other change besides the first commit's subject, and CI is green.

@fametrano

Copy link
Copy Markdown
Contributor

reACK bdeaa78

Since 94eecd6 the branch was rebased on master, and the range-diff only removes two duplicate lines from silentpayments/go.sum. go test and go vet pass again in silentpayments and psbt, and CI is green.

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.

9 participants