Repository navigation
Derive the withdraw auditor checkpoint pad from the second sponge squeeze (audit N-07) - #792
Conversation
…eeze The withdraw balance checkpoint previously padded with the first squeeze of the sender-auditor sponge, which is the transfer circuit's amount-pad slot; under (r_e, sigma) reuse a known transfer amount would decrypt a later withdrawal's balance checkpoint. All circuits now use the second squeeze for balance/allowance masks. Regenerates the withdraw VK and fixtures; documents the unique-(r_e, sigma)-per-proof requirement.
WalkthroughThe sender-auditor balance checkpoint now derives its mask from the second ChangesAuditor checkpoint padding
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/tokens/src/confidential/circuits/lib/src/lib.nr (1)
288-298: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUpdate the
sponge_squeeze_2"Used by" list.
encrypt_auditor_sender_balance(Withdraw's W_a3/W_a4) is now a consumer ofsponge_squeeze_2, but the doc comment on this function only lists Transfer and SpenderTransfer.✏️ Proposed doc update
/// Used by: Transfer (T_a2 recipient-auditor amount + randomness, T_a6 -/// sender-auditor amount + balance) and SpenderTransfer (O_a2, O_a6). +/// sender-auditor amount + balance), SpenderTransfer (O_a2, O_a6), and +/// Withdraw (W_a3, via `encrypt_auditor_sender_balance`, second squeeze only).🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/tokens/src/confidential/circuits/lib/src/lib.nr` around lines 288 - 298, Update the doc comment for sponge_squeeze_2 to include encrypt_auditor_sender_balance as a consumer, noting its use by Withdraw’s W_a3/W_a4 alongside the existing Transfer and SpenderTransfer references. Do not alter the function implementation or existing squeeze-order documentation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/tokens/src/confidential/circuits/lib/src/lib.nr`:
- Around line 288-298: Update the doc comment for sponge_squeeze_2 to include
encrypt_auditor_sender_balance as a consumer, noting its use by Withdraw’s
W_a3/W_a4 alongside the existing Transfer and SpenderTransfer references. Do not
alter the function implementation or existing squeeze-order documentation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8e595abd-3f98-436d-b406-be472d162c19
📒 Files selected for processing (7)
packages/tokens/src/confidential/circuits/lib/src/lib.nrpackages/tokens/src/confidential/circuits/lib/src/tests.nrpackages/tokens/src/confidential/circuits/lib/testdata/encrypt_auditor_sender_balance.jsonpackages/tokens/src/confidential/circuits/vks/withdraw.vk.jsonpackages/tokens/src/confidential/circuits/withdraw/src/main.nrpackages/tokens/src/confidential/circuits/withdraw/src/tests.nrpackages/tokens/src/confidential/docs/DESIGN.md
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #792 +/- ##
=======================================
Coverage 96.56% 96.56%
=======================================
Files 71 71
Lines 7346 7346
=======================================
Hits 7094 7094
Misses 252 252 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ozgunozerk
left a comment
There was a problem hiding this comment.
Let put my understanding here, to confirm whether I got it correct. I'm approving in case I got it right. If my understanding is incorrect, please don't merge, I'll have to review again.
My understanding:
- info is encrypted as: ciphertext = plaintext + pad -> one-time pad pattern
- pad is derived using nonce (technical detail, "how" part is not relevant to this PR)
- anyone who knows the plaintext and the ciphertext, can derive the pad. This means, the receiver of the transfer, can decipher to pad, due to they know they received
100(plaintext), and ciphertext is already public info - so, if the same pad is used elsewhere, considering the ciphertext is public info, they can decipher the plaintext. For example, the receiver can also decipher the remaining balance of the sender, which they shouldn't know ideally...
Pre-fix (before this PR), the same pad was used for 2 different things, potentially creating a private info leak, now different/unique pads are used for different inputs, fixing the problem
|
Yes, just to precise that it happens only if the same r_e and sigma are used for both, the transfer and the withdrawal. |
Resolve conflicts from the confidential-token changes that landed on main (#792 withdraw checkpoint pad, #790 typed-payload doc renames). The withdraw sender-auditor checkpoint now composes both changes: the bound ECDH scalar (this PR) feeds the second sponge squeeze (#792). Regenerated the withdraw VK and the B_TILDE_AUD_S fixture (0x288ff488…) from the combined circuit — the merged value matches neither side. Other four VKs and the constraint baseline re-extract byte-identical to this branch; register.vk.json is byte-identical to main. nargo test: 155 green.
Fixes #785 (audit finding N-07).
The collision.
encrypt_auditor_sender_balancepadded the withdraw balance checkpoint withPoseidon2(AUDITOR_SENDER, [s_x, sigma])— the first output of the sender-auditor sponge, which is exactly the transfer circuit's amount-pad slot.transfer,set_spender, andrevoke_spenderall already pad balances/allowances with the second squeeze; withdraw was the lone divergence. Under(r_e, sigma)reuse across a transfer and a later withdraw, anyone who knows the transfer amount (e.g. its recipient) can recover the shared pad from the publishedv_tilde_aud_sand decrypt the withdrawal's balance checkpoint.The fix. The helper now returns
v_new + sponge_squeeze_2(AUDITOR_SENDER, s_x, sigma)[1], restoring a uniform slot assignment across every circuit: first squeeze = amount masks, second squeeze = balance/allowance masks. The checkpoint pad can no longer coincide with any amount pad, even under nonce reuse. This also makes the clawback decryption recipe in COMPLIANCE.md §5 (which already assumed the uniform two-squeeze form) correct for withdraw checkpoints.Changes:
circuits/lib/src/lib.nr: pad derivation + docstring (which also wrongly listed SetSpender/RevokeSpender as consumers — only withdraw calls this helper)circuits/withdraw/: W_a3 constraint comment; regenerated pinned fixtureB_TILDE_AUD_Svks/withdraw.vk.json: regenerated with the pinned toolchain (only VK that changed);constraints.baselineis unchanged (same permutation count)lib/testdata/encrypt_auditor_sender_balance.json: regenerated vector + corrected description — cross-language contract change, downstream SDK/prover implementations of the withdraw checkpoint must switch to the second squeezedocs/DESIGN.md: W_a3 formula updated; §2.5 now states the canonical slot assignment and the normative requirement that a(r_e, sigma)pair be unique per proof, with the residual risk under reuse spelled outResidual note: two balance checkpoints under a reused
(r_e, sigma)still share their (second-slot) pad and leak their difference — inherent to any deterministic pad, hence the uniqueness requirement in §2.5.Validation:
nargo testpasses across all circuit packages (153 tests);cargo test -p stellar-tokens(676) unaffected.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Documentation
Tests