Skip to content

Bip352/fix kmax#1

Closed
edilmedeiros wants to merge 5 commits into
masterfrom
bip352/fix_kmax
Closed

Bip352/fix kmax#1
edilmedeiros wants to merge 5 commits into
masterfrom
bip352/fix_kmax

Conversation

@edilmedeiros

@edilmedeiros edilmedeiros commented May 2, 2026

Copy link
Copy Markdown
Owner

bitcoin#2106 introduced a limit on how many keys the receiver is allowed to scan. But the sender specification still allows for creating outputs that exceed that limit, risking loosing funds. This PR:

  1. 4b9b490: Adds an additional check in the sender specification to disallow creating more keys/outputs than the receiver will surely scan (as per the specification).
  2. 2028356: Adds an additional functional test requirement for wallet implementors.
  3. 0de6dfb: Changes the reference implementation so that groups of silent payment addresses are calculated in a more sensible way (see details below). This commit WILL FAIL with the test vectors.
  4. c14fd21: Implement the additional check in the reference implementation.

About the reference implementation

bitcoin#2106 introduced a field count on the recipients specification for tests and added a test case in which the sender is given a single silent payment address and wants to create 2324 outputs for it. Before calling create_outputs(), which is the implementation of this specification, the test harness will clone the silent payment address count times and pass it to create_outputs(). Thus, in the sender process, it will create a group with 2324 elements, all of which carry the same silent payment address, and will fail as per the spec.

If any of the groups exceed the limit of Kmax (=2323) silent payment addresses, fail.[18]

I don't believe this to be what any developer would implement from reading the specification:

  • Group receiver silent payment addresses by ''Bscan'' (e.g. each group consists of one B_scan and one or more B_m)

The sensible thing to do in this scenario is to create one group with one address, after all, we got one silent payment address which gives us one B_scan and one B_m. That will not fail the required check and will result in a transaction with more outputs that the receiver will scan, resulting in loss of funds.

Commit 0de6dfb changes the reference implementation to reflect this behavior and c14fd21 introduces the additional check introduced by 4b9b490.

@edilmedeiros edilmedeiros force-pushed the bip352/fix_kmax branch 5 times, most recently from c214081 to c14fd21 Compare May 2, 2026 20:40

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

ACK c14fd21

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

ACK c14fd21

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

ACK c14fd21

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

ACK c14fd21

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

ACK c14fd21

@edilmedeiros

Copy link
Copy Markdown
Owner Author

Adicionei um último commit corrigindo typos e sugerindo melhorias na redação de alguns trechos. Vou abrir o PR assim, mas mencionar que esse commit pode ser removido sem problema.

Valeu pelo trabalho em conjunto, agora é acompanhar a discussão no repo dos bips.

edilmedeiros and others added 5 commits May 8, 2026 11:13
The specification limits how many keys the receiver is allowed to scan.
Thus, we should not allow the sender to generate more than that many
keys/outputs to prevent loss of funds.

Co-authored-by: themhv <themhv@proton.me>
Co-authored-by: joaozinhom <joaomcr@proton.me>
Co-authored-by: IsaqueFranklin <isaque@harlock.xyz>
Co-authored-by: lucasdcf <lucasdcf@users.noreply.github.com>
Co-authored-by: oleonardolima <oleonardolima@users.noreply.github.com>
Co-authored-by: Lorenzo <maturanolorenzo@gmail.com>
Co-Authored-By: themhv <themhv@proton.me>
Co-Authored-By: joaozinhom <joaomcr@proton.me>
Co-Authored-By: IsaqueFranklin <isaque@harlock.xyz>
Co-Authored-By: lucasdcf <lucasdcf@users.noreply.github.com>
Co-Authored-By: oleonardolima <oleonardolima@users.noreply.github.com>
Co-Authored-By: Lorenzo <maturanolorenzo@gmail.com>
The original implementation references does a trick to avoid generating
more outputs thatn the receiver is allowed to scan: it clones the
payment specification before calling the crate_outputs() function. Then,
when creating groups, the function will see the same address many times
and create an artifically big group.

This is not a reasonable interpretation of the spec, i.e., if I want to
send 2324 outputs for the same address, this should be interpretated as
a single group containing a single address. This is what this commit
implements.

Note that this will NOT pass the unit tests. Next commit will fix this.

Co-Authored-By: themhv <themhv@proton.me>
Co-Authored-By: joaozinhom <joaomcr@proton.me>
Co-Authored-By: IsaqueFranklin <isaque@harlock.xyz>
Co-Authored-By: lucasdcf <lucasdcf@users.noreply.github.com>
Co-Authored-By: oleonardolima <oleonardolima@users.noreply.github.com>
Co-Authored-By: Lorenzo <maturanolorenzo@gmail.com>
Co-Authored-By: themhv <themhv@proton.me>
Co-Authored-By: joaozinhom <joaomcr@proton.me>
Co-Authored-By: IsaqueFranklin <isaque@harlock.xyz>
Co-Authored-By: lucasdcf <lucasdcf@users.noreply.github.com>
Co-Authored-By: oleonardolima <oleonardolima@users.noreply.github.com>
Co-Authored-By: Lorenzo <maturanolorenzo@gmail.com>
@edilmedeiros

Copy link
Copy Markdown
Owner Author

Closing this in favor of bitcoin#2153

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.

6 participants