Repository navigation
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
⛔ Final review complete — 1 blocking finding(s) (commit 5b133c5) · triage: critical |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
Changes requested: 4 blockers
- A restored DashPay wallet can pay beyond its contact’s watch window —
packages/rs-platform-wallet/src/wallet/address_pool_restore.rs:132-136(new)
Impact: After the sender repairs a missing payout row, an undamaged recipient can miss a confirmed payment in their balance and history. - A Core rescan can fill the last stored gap and erase the issuance floor —
packages/rs-platform-wallet/src/changeset/changeset.rs:2211-2223(new)
Impact: After catch-up and another restart, a wallet can reissue an invitation key or payout address that it previously handed out. - A documented whole-pool replacement can delete the rows the issuance floor protects —
packages/rs-platform-wallet/src/changeset/changeset.rs:2220-2225(new)
Impact: A Rust persister that replaces a pool with its latest snapshot deletes the saved prefix when it receives a nonempty suffix above a floor. - A startup contact rebuild can make an old payout address available again —
packages/rs-platform-wallet/src/manager/load.rs:1893-1898(new; not shown inline, see below)
Impact: A wallet with a repaired payout pool and no trusted outbound-account marker can reissue an address on its first reservation after startup.
This PR changes how the wallet restores damaged invitation-funding and DashPay payout pools, adds a shared payout issuance check, and filters selected persistence snapshots. The Kotlin SDK build and emulator tests passed; the automated review check is pending, and no code checks have failed.
🔴 4 blocking | 🟡 2 suggestion(s)
1 finding(s) not shown inline (the lines are not part of this PR's diff)
🔴 Blocking: A startup contact rebuild can make an old payout address available again
Impact: A wallet with a repaired payout pool and no trusted outbound-account marker can reissue an address on its first reservation after startup.
packages/rs-platform-wallet/src/manager/load.rs:1893-1898
Rebuilding the account can discard the only protection against reuse. When restore fills a gap and reaches the highest stored row, it creates no floor; the protection is in the pool’s used flags. A missing outbound-account marker, including one unset by a host that cannot keep it durably, makes the startup sweep remove that pool. register_external_contact_account then creates and persists a fresh pool from the request’s xpub. If the xpub is unchanged, the fresh pool contains the same early addresses as available, and its transaction history cannot recover an off-chain reservation. Preserve the issuance boundary through same-xpub rebuilds and test the first reservation after the startup sweep.
source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, platform-versioning, rust-quality, security-auditor)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — The diff changes key handling in address_pool_restore.rs and payout destination selection in next_contact_payout_address, with correctness depending on how restore, issuance floors, and snapshot writes interact across restarts. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— platform-versioning (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— security-auditor (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/rs-platform-wallet/src/wallet/address_pool_restore.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/address_pool_restore.rs:132-136: A restored DashPay wallet can pay beyond its contact’s watch window
Impact: After the sender repairs a missing payout row, an undamaged recipient can miss a confirmed payment in their balance and history.
A payment can reach an address the contact owns but does not monitor. In `should_not_reissue_a_lost_dashpay_payment_address_after_restart`, row 10 is missing, index 11 is the last used address, and indices 12–21 are unused lookahead. The pinned key-wallet gives the recipient a gap limit of 10, so after seeing payment 11 it watches through 21. Restore marks 12–21 used on the sender and selects 22, even though no payment advanced the recipient’s window. The shared payout selector allows it because the restore reached the highest stored row and recorded no floor. Keep the no-reuse guarantee, but refuse to issue a payout beyond the window supported by observed payments. Test the selected script against a separate recipient pool.
In `packages/rs-platform-wallet/src/changeset/changeset.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/changeset/changeset.rs:2211-2223: A Core rescan can fill the last stored gap and erase the issuance floor
Impact: After catch-up and another restart, a wallet can reissue an invitation key or payout address that it previously handed out.
The restart guard disappears if Core sync makes the stored rows contiguous. In the pinned key-wallet, a transaction matching a watched address extends the pool through the highest used index plus the gap limit. Successive historical matches can fill the entire missing range without a transaction paying every address in it. `build_core_changeset` forwards those derived rows for both transaction and block events, and the FFI callback upserts them as unused unless a usage delta marks them used. An off-chain handout has no such delta. The next load neither detects a gap nor sets a floor, and the selector can take that now-available row. Persist the floor independently of row continuity, or protect the evidence across Core event writes as well as snapshots. Exercise a reload after the final gap has closed; the current regression stops after one refill.
- [BLOCKING] packages/rs-platform-wallet/src/changeset/changeset.rs:2220-2225: A documented whole-pool replacement can delete the rows the issuance floor protects
Impact: A Rust persister that replaces a pool with its latest snapshot deletes the saved prefix when it receives a nonempty suffix above a floor.
A backend can erase saved used rows while following the public API contract. `AccountAddressPoolEntry` says `addresses` contains every row and tells consumers to treat the last entry for a pool as authoritative. The filter emits only rows above the floor through that same type. For example, once a Core refill grows a damaged invitation pool past its floor, an asset-lock build using a different funding account can snapshot that suffix because the build collects all funding pools. In-tree row upserts preserve omitted rows, but the public contract allows replacement. Use an explicit row-update payload or require an upsert capability before emitting partial entries, and test that applying a suffix retains the saved prefix.
In `packages/rs-platform-wallet/src/manager/load.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/manager/load.rs:1893-1898: A startup contact rebuild can make an old payout address available again
Impact: A wallet with a repaired payout pool and no trusted outbound-account marker can reissue an address on its first reservation after startup.
Rebuilding the account can discard the only protection against reuse. When restore fills a gap and reaches the highest stored row, it creates no floor; the protection is in the pool’s used flags. A missing outbound-account marker, including one unset by a host that cannot keep it durably, makes the startup sweep remove that pool. `register_external_contact_account` then creates and persists a fresh pool from the request’s xpub. If the xpub is unchanged, the fresh pool contains the same early addresses as available, and its transaction history cannot recover an off-chain reservation. Preserve the issuance boundary through same-xpub rebuilds and test the first reservation after the startup sweep.
In `packages/rs-platform-wallet/src/error.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/error.rs:95-103: FFI hosts receive a generic error when a damaged contact pool refuses a payout
Impact: A host that branches on result codes cannot distinguish this no-send refusal from other unknown failures without parsing the message.
Hosts can display the refusal text, but cannot use a typed result to tell users that retrying against the same unrestored pool will not help. The new variant falls through to code 99 in `rs-platform-wallet-ffi/src/error.rs:1417`, as the PR description notes. The book’s “Error enums stay exhaustive” rule explicitly covers per-variant FFI result-code mappings. Make the mapping explicit; use a dedicated code if hosts need to handle the refusal differently, or document the deliberate generic-code fallback and its retry semantics.
In `packages/rs-platform-wallet/src/wallet/identity/network/payments.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/identity/network/payments.rs:1458-1468: Checking one contact’s payout clones every issuance floor
Impact: When the floor map is nonempty, send, prepare, and reserve copy it under the manager write lock, even if the scan produces no changeset.
`record_contact_addresses_paid_on_chain` clones the map before it knows whether any address needs marking, but the eventual snapshot contains only this contact’s pool. Copy that contact’s `Option<u32>` before taking the mutable account borrow, as `next_contact_payout_address` already does, and filter against that value.
Out-of-scope follow-up suggestions (2)
These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.
- SQLite does not reconstruct issuance floors from indexed pool rows — The SQLite adapter on this base restores used scripts through a separate, incomplete read path and does not attest
WALLET_RESTORE. This PR does not change that path.- Follow-up: Continue the indexed SQLite pool-restore work in #5210 and verify damaged one-time funding and DashPay payout pools there.
- A refused row inside the initial window can leave its pre-derived key available — A conflicting normal-index row can be rejected without a gap fill while
highest_generated()already covers it. This predates the PR; the linked sibling explicitly treats refused rows as missing forGapRows::Usedpools.- Follow-up: Preserve #6035’s accepted-row tracking when integrating the two restore changes, and exercise it for both invitation and payout pools.
|
Per maintainer decision, not addressed in this PR: "A startup contact rebuild can make an old payout address available again" ( A restart comes blocks after any reservation: by then it has either reached the chain, where payout selection re-marks the address from the wallet's transactions, or was abandoned with nothing on chain to link, so handing that address out again reuses nothing. The rebuild doubles as a way to recover those wasted addresses. Documented on 🤖 Co-authored by Claudius the Magnificent AI Agent |
e8ac99f to
3d0a9a9
Compare
…fter restart Preserve the final PR scope, including merge resolutions, on the updated native stack. Co-Authored-By: Codex <[email protected]>
…eAddressEntryFFI Preserve the final PR scope, including merge resolutions, on the updated native stack. Co-Authored-By: Codex <[email protected]>
Preserve the final PR scope, including merge resolutions, on the updated native stack. Co-Authored-By: Codex <[email protected]>
…ap-refill guard Preserve the final PR scope, including merge resolutions, on the updated native stack. Co-Authored-By: Codex <[email protected]>
Preserve the final PR scope, including merge resolutions, on the updated native stack. Co-Authored-By: Codex <[email protected]>
…uance floors Co-Authored-By: Codex <[email protected]>
3d0a9a9 to
5b133c5
Compare
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
Changes requested: 1 blocker
- Removing the address-row field breaks mixed native and Swift/Kotlin wallet artifacts —
packages/rs-unified-sdk-jni/src/persistence.rs:995-996(new)
Impact: Users who update the Rust dylib or JNI library without rebuilding the matching host SDK can lose restored address-pool rows, fail persistence callbacks, or crash while reading the callback buffer.
New on this head: This head keeps issuance floors through wallet reloads and updates restore, payout selection, and per-row persistence behavior; it also removes the unused per-address balance from the native persistence ABI. The Kotlin SDK build passed, while Rust wallet/workspace checks were skipped and the dedicated review check remains in progress.
🔴 1 blocking
Review provenance
Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 3: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.2-sol(effort low) — This is a large, cross-cutting change that alters wallet address issuance and payment destination selection, including key-handling and persistence behavior inrestore_account_address_poolsandnext_contact_payout_address, which directly affects funds movement and address reuse. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- New since the last final review (
fe4553e9): 1 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 1 confirmed - Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-astra— general (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— ffi-engineer (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.2-astra— security-auditor (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/rs-unified-sdk-jni/src/persistence.rs`:
- [BLOCKING] packages/rs-unified-sdk-jni/src/persistence.rs:995-996: Removing the address-row field breaks mixed native and Swift/Kotlin wallet artifacts
Impact: Users who update the Rust dylib or JNI library without rebuilding the matching host SDK can lose restored address-pool rows, fail persistence callbacks, or crash while reading the callback buffer.
The native and host persistence artifacts no longer have a compatible ABI. `CoreAddressEntryFFI` is `#[repr(C)]`; removing `balance` shifts both C-string pointers and reduces the row stride from the layout expected by previously compiled Swift code. The Swift callback indexes the imported `CoreAddressEntryFFI` array directly at `PlatformWalletPersistenceHandler.swift:10468`; an old host therefore reads the new row's path as its address and reads past the new row for the derivation path, while a new host paired with an old library uses the new offsets against the old row layout and can read the old zero balance as a null address pointer. The JNI boundary has the same problem: this library now looks up `onPersistAccountAddressPoolEntry` with a descriptor without `J`, while an older `NativePersistenceBridge` only exposes the descriptor containing the `Long` balance parameter, producing `NoSuchMethodError` and preventing address-pool persistence. `platform_wallet_ffi_version` and the persistence-capability version do not enforce coordinated host/native upgrades, and no dual-version callback or ABI negotiation exists. Preserve the old layout/signature or introduce an explicitly versioned callback and enforce a coordinated native-and-host upgrade before shipping.
_Confirmed by an independent pass: A wallet using an older Swift host with this newer native library reaches the account-address-pool persistence callback with a contiguous `CoreAddressEntryFFI` array whose rows are now 80 bytes instead of the old 88-byte layout; the old host therefore reads the new row's derivation-path pointer as its address and indexes subsequent rows at the wrong offsets, potentially reading out of bounds and corrupting or crashing address persistence. An older Kotlin `NativePersistenceBridge` likewise exposes `onPersistAccountAddressPoolEntry` with the `Long` balance parameter, while the new JNI shim probes and invokes the descriptor without `J`; the probe consequently disables the pool writer (or a callback invocation raises `NoSuchMethodError`), so address-pool rows are not persisted. These mixed artifacts are not rejected by the existing FFI or persistence capability versions, leaving shipped wallet state vulnerable whenever native and host artifacts are upgraded independently._
| const ACCOUNT_ADDRESS_POOL_ENTRY_DESCRIPTOR: &str = | ||
| "([BBBIII[B[BB[BZBIZJLjava/lang/String;Ljava/lang/String;)I"; | ||
| "([BBBIII[B[BB[BZBIZLjava/lang/String;Ljava/lang/String;)I"; |
There was a problem hiding this comment.
🔴 Blocking: Removing the address-row field breaks mixed native and Swift/Kotlin wallet artifacts
Impact: Users who update the Rust dylib or JNI library without rebuilding the matching host SDK can lose restored address-pool rows, fail persistence callbacks, or crash while reading the callback buffer.
The native and host persistence artifacts no longer have a compatible ABI. CoreAddressEntryFFI is #[repr(C)]; removing balance shifts both C-string pointers and reduces the row stride from the layout expected by previously compiled Swift code. The Swift callback indexes the imported CoreAddressEntryFFI array directly at PlatformWalletPersistenceHandler.swift:10468; an old host therefore reads the new row's path as its address and reads past the new row for the derivation path, while a new host paired with an old library uses the new offsets against the old row layout and can read the old zero balance as a null address pointer. The JNI boundary has the same problem: this library now looks up onPersistAccountAddressPoolEntry with a descriptor without J, while an older NativePersistenceBridge only exposes the descriptor containing the Long balance parameter, producing NoSuchMethodError and preventing address-pool persistence. platform_wallet_ffi_version and the persistence-capability version do not enforce coordinated host/native upgrades, and no dual-version callback or ABI negotiation exists. Preserve the old layout/signature or introduce an explicitly versioned callback and enforce a coordinated native-and-host upgrade before shipping.
Confirmed by an independent pass: A wallet using an older Swift host with this newer native library reaches the account-address-pool persistence callback with a contiguous CoreAddressEntryFFI array whose rows are now 80 bytes instead of the old 88-byte layout; the old host therefore reads the new row's derivation-path pointer as its address and indexes subsequent rows at the wrong offsets, potentially reading out of bounds and corrupting or crashing address persistence. An older Kotlin NativePersistenceBridge likewise exposes onPersistAccountAddressPoolEntry with the Long balance parameter, while the new JNI shim probes and invokes the descriptor without J; the probe consequently disables the pool writer (or a callback invocation raises NoSuchMethodError), so address-pool rows are not persisted. These mixed artifacts are not rejected by the existing FFI or persistence capability versions, leaving shipped wallet state vulnerable whenever native and host artifacts are upgraded independently.
source: gpt-6.2-astra (phase2-reviewer: ffi-engineer)
TL;DR: After a damaged address-list restore, a wallet could hand out an already-used invitation-funding or DashPay payout address again after the next app restart; this PR keeps such addresses out of circulation across restarts.
User story
As a wallet user sending DashPay invitations, I want every invitation to be funded from a fresh address, to achieve invitations that cannot be claimed by someone holding an earlier invitation key.
As a wallet user paying a DashPay contact, I want every payment to go to an address I have not used for that contact before, to achieve payments that are not linked to earlier ones.
Scenario
Base flow
The wallet loads an invitation-funding or DashPay payout address list whose saved rows have a gap too large to rebuild, so it cannot vouch for the addresses inside that gap. A new payment arrives and the wallet adds fresh addresses after the last used one; the app saves them as available.
Actual behavior
On the next start the gap is small enough to rebuild (or the newly saved rows hide it), so no protection is set. One of the newly saved "available" addresses can be handed out again, although its key may already have been given away in an earlier invitation or payment.
Expected behavior
Once the store shows damage, no address the wallet cannot vouch for is issued again, on this start or any later one. Undamaged wallets behave exactly as before.
Detailed discussion
What was done
Follow-up to review threads on #5951 (invitation floor, DashPay payout rows). No new persisted data and no FFI, Swift or Kotlin change: the stored rows themselves carry the damage evidence on every load.
wallet/address_pool_restore.rs) — in asset-lock funding pools, filling a gap marks every address in the pool used, including rows the host saved as unused on top of a damaged store. InDashpayExternalAccountpools (GapRows::UsedThroughHighestUsed) it marks only the addresses through the highest used or lost row, so the next payout stays inside the gap-limit window the contact watches; a lookahead row stored as unused may be paid again, an address reuse only, as payout selection re-marks the addresses the wallet's transactions paid. The fresh gap-limit window is derived only when no row was refused, so a refused row stays unreached and keeps its issuance floor.manager/load.rs) —restore_account_address_poolssets a floor for everyGapRows::Usedpool, so DashPay contact payout pools get one too. It travels through the existingfunding_issuance_floorspath (the field now also covers contact pools; docs updated).identity/network/payments.rs,prepared_payment.rs) — newnext_contact_payout_addressenforces the floor forreserve_payment_address,send_paymentandprepare_payment; refusal isPlatformWalletError::ContactPayoutPoolNotRestored { contact, floor }, mapped explicitly to FFIErrorUnknown.changeset/changeset.rs,asset_lock/build.rs,payments.rs) — newdrop_rows_at_or_below_issuance_floorsremoves rows at or below a floor from funding-pool and paid-contact snapshots, so the stored damage evidence is never overwritten while keys issued above the floor are still persisted before broadcast.AccountAddressPoolEntrynow documents that an entry may hold a subset of a pool and that persisters upsert per row and never delete omitted rows, as every in-tree persister does.Trade-offs: a damaged account whose gap stays unreachable may keep refusing issuance (the floor rises with newly stored rows above it); recovering lost rows is out of scope. The floor is recomputed from store damage on each load, not persisted, so a store that heals its gap loses it; such a store needs a fresh resync.
Testing
cargo nextest -p platform-wallet -p platform-wallet-ffi --all-features: 2827 passed; clippy--all-targets --all-features -D warningsclean;cargo fmtclean.Breaking changes
Rust only:
PlatformWalletErrorgainsContactPayoutPoolNotRestored. FFI maps it to the existingErrorUnknownwith its message.Prior work
address_pool_restore.rs(both rules apply after the restore loop).Checklist
🤖 Generated with Claude Code
https://claude.ai/code/session_01WunYYhpfoE88XJoyRt4hcR
🤖 Co-authored by Claudius the Magnificent AI Agent