Skip to content

feat: enforce k_max limit (2323) for silent payments groups - #31

Closed
IsaqueFranklin wants to merge 1 commit into
BlueWallet:masterfrom
IsaqueFranklin:feat/kmax-limit
Closed

IsaqueFranklin wants to merge 1 commit into
BlueWallet:masterfrom
IsaqueFranklin:feat/kmax-limit

Conversation

@IsaqueFranklin

Copy link
Copy Markdown

This PR implements the K_MAX limit for the recipient group as specified in BIP-352.

According to the specification for creating outputs:
"If any of the groups exceed the limit of K_MAX (=2323) silent payment addresses, fail."

This PR includes the following changes:

  • Added K_MAX constant.
  • Added a fail-fast check for the recipient group size before performing any calculations.

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

Subject 31 adds BIP-352 K_MAX (2323) enforcement on sender-side recipient groups — a compliance feature, not a bugfix. The constant and > K_MAX boundary are spec-correct. No tests were added for the only behavior this PR introduces. Validation runs inside the per-group loop instead of upfront, so an oversize later group still burns ECDH work on earlier groups. Minor formatting slop in the diff.

Inline findings (could not anchor on diff)

  • tests/silent-payment.test.ts:47 — [HIGH] You bolted on a spec limit and wrote zero tests. No 2323-boundary pass, no 2324 throw — this chamber's safety interlocks are decorative. Add real coverage or admit you're guessing.

Comment thread src/index.ts
@@ -82,12 +85,18 @@ export class SilentPayment {

// Generating Pmk for each Bm in the group
for (const group of silentPaymentGroups) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[MEDIUM] BIP-352 validates all groups before output generation; you check inside the loop. A valid group still gets full ECDH before a later oversize group detonates. Fail fast once, like the reference implementation.

Comment thread src/index.ts
// Generating Pmk for each Bm in the group
for (const group of silentPaymentGroups) {
// Checking for the K_MAX limit of elements in a group defined by BIP0352
if(group.BmValues.length > K_MAX) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LOW] if(group — even your spacing failed the formatting test. Prettier exists; use it.

Comment thread src/index.ts
for (const group of silentPaymentGroups) {
// Checking for the K_MAX limit of elements in a group defined by BIP0352
if(group.BmValues.length > K_MAX) {
throw new Error(`Silent payment elements for a single recipient group

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[LOW] Multiline error string embeds a newline — log parsers and callers get an ugly surprise. One line, like every other throw in this file.

@Overtorment

Copy link
Copy Markdown
Member

sorry for the delay.

glados remars look legit

@Overtorment

Copy link
Copy Markdown
Member

merged it #34

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.

3 participants