fix(send): hydrate numPubkeys from server-authoritative num_sends - #125
Closed
TaprootFreak wants to merge 1 commit into
Closed
TaprootFreak wants to merge 1 commit into
TaprootFreak wants to merge 1 commit into
Conversation
The wallet tracks the BIP-32 child-index counter (`numPubkeys`) purely in local state. After a seed restore the counter is reset to 0 — but the server may still hold `account.proof = Some(...)` from a previous session for the same address. The next /send then either omits `prev_commitment_pubkey` (server 400 `"prev_commitment_pubkey required for account update"`, mapped client-side to `Interner Fehler: Vorheriger Public Key fehlt.`) or reuses pubkey[0] and collides on the same SMT slot at commit time. The E2E `07-send.spec.ts::send-success` test exposed this on every retry after the first global-setup minted balance was spent. This is the app side of zk-coins/node PR #129, which adds the authoritative `Account.num_sends` counter and emits it on `/api/balance`. The app: * extends `BalanceResponseSchema` with `num_sends: z.number().default(0)`; * adds `syncNumPubkeys(n)` to the wallet store — a no-op fast-path when the counter is already correct, replace semantics otherwise; * drives a fresh `api.balance` BEFORE every send (SendPage) so the counter is hydrated against the server's source of truth even if the WalletScreen 5-s poll hasn't ticked yet; * hydrates `numPubkeys` on every seed/passkey restore flow; * re-syncs on every WalletScreen balance tick + after the post-send /api/balance refresh. Tests: * `wallet.test.ts` — `syncNumPubkeys` replace semantics + no-op shortcut + multi-account safety. * `send-pipeline.test.tsx` — pre-send balance hydration is mocked in every send-confirm path; the existing `prev_commitment_pubkey` + `numPubkeys` assertions still hold. App-PR depends on node-PR being merged + DEV-deployed first — otherwise the wallet reads `undefined` for `num_sends` against the old server. The schema's `.default(0)` keeps the fallback safe (local counter behaviour preserved).
Contributor
[OK] Button-Inventory-Audit — all clearChecked 71 testid(s) in |
Contributor
Author
|
Superseded by zk-coins/node#132 (merged 2026-05-28, server now owns prev_commitment_pubkey as single source of truth — App-side syncNumPubkeys derivation no longer load-bearing). Closing as obsolete; the case is end-to-end covered by |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Companion to zk-coins/node #129 — fixes
07-send.spec.ts::send-successfailing on DEV withInterner Fehler: Vorheriger Public Key fehlt.(serverprev_commitment_pubkey required for account update, 400).The wallet's BIP-32 child-index counter (
numPubkeys) is reset to 0 on every seed restore — but the server may still holdaccount.proof = Some(...)from a previous session for the same address. The next send then either omitsprev_commitment_pubkey(→ 400) or reuses pubkey[0] and collides on the SMT slot at commit time.Fix: read the counter from the server.
BalanceResponseSchemaextended withnum_sends: z.number().default(0).useWalletStoreaddssyncNumPubkeys(n)(replace-semantics + no-op shortcut).SendPagerunsapi.balanceBEFORE signing every send, hydratesnumPubkeysfromnum_sends, then signs with the correct index.WalletScreen5-s poll + onboarding (seed restore + passkey restore) + post-send balance refresh all sync.Dependencies
This PR must wait for zk-coins/node #129 to merge + DEV-deploy. The schema's
.default(0)keeps the fallback safe if the wire-format is missing the field, but the actual fix requires the server emitting it.Test plan
npx tsc --noEmit(only pre-existing 07-send.spec.ts:197 error)npm run lint(ESLint clean; pre-existing prettier warnings onCONTRIBUTING.md/README.mdonly)npx prettier --check 'src/**/*.{ts,tsx}'npm run buildnpx vitest run(318 passed, 3 skipped — contract.live)07-send.spec.ts::send-successpasses against DEV once node chore: bundle App fixes — Bug #1 + errorMessages + CI tolerate_failures + fresh Goldens #129 is deployed