← Back to Pull requests

Step 8: ICP and ICRC accounts #9

Closed
unknown closed this pull request without merging on Oct 21, 2026 02:56 UTC
View on GitHub
unknown unknown commented on Oct 21, 2026 01:30 UTC
Author

<!-- claude-projects-attribution: {"github_login":"b3hr4d"} -->
_Requested by Behrad · project thread_

Before: the wallet had no accounts. accounts, add_account and balance did not exist, and a Transfer proposal was refused.

After: an owner adds ICP and ICRC accounts, every member lists them and reads their balances from the ledgers, and Transfer actions send tokens, at most once each. A transfer that keeps its chain's spending over the last 24 hours within the daily limit is released at once.

Accounts. An account is an ICRC-1 account of the wallet's own principal. Index n of a chain is subaccount n as 32 big-endian bytes, so index 0 is the plain principal and the address of index 1 ends in .1, as you chose on 2026-10-21 (recorded as docs/decisions/0002-subaccounts.md). Adding one needs no approval, since it moves nothing, and a wallet has at most 64. The wallet reaches the ICP ledger through its ICRC-1 interface, and an Icrc chain may not name it, so ICP tokens have one daily limit. Bitcoin and EVM accounts are refused for now.

At most once. Each execute of a transfer makes one bounded-wait icrc1_transfer, and a second execute while it is in flight is refused. The call carries a created_at_time. When the wallet cannot tell whether a call ran (it timed out, its answer does not decode, or the wallet's code after it trapped, which a drop guard records), the next execute reuses that time, so the ledger answers with the earlier block; Duplicate counts as sent. Ledgers find a repeated transfer for 24 hours, so such an action stays open that long and cannot be rejected. Only a reject by the IC before the ledger ran the call (SysFatal, SysTransient, DestinationInvalid) counts as not run; a reject from the ledger itself, a stopped ledger's included, may follow a committed transfer, so it counts as unknown (Codex's finding). A refusal (too little in the account, a wrong fee) ends the action Failed, unless an earlier call may have run: a ledger checks the fee before it looks for a repeat, so then the action stays ready (Codex's finding).

Daily limit. A chain's spending is what it sent in the last 24 hours plus what its open transfers under the limit may still send, so several small proposals cannot pass the limit together. execute checks the limit again, so a lowered limit stops a transfer proposed under the old one. Under a Transfer rule of one approval and no timelock, as in the default policy, the limit changes nothing.

How: accounts.rs (accounts and their addresses), transfers.rs (checks, the ledger argument, reading the answer) and the attempt state in actions.rs are pure; ledger.rs makes the calls; lib.rs adds accounts, add_account, balance and the transfer branch of execute. Sent transfers go to memory 6, which the daily limit reads; accounts to memory 3, both as docs/design.md planned. Memory 11 is a transfer clock: every fresh ledger call gets a created_at_time no other call has, so two identical transfers executed in one round are both sent (Codex's finding).

Worth your review

  • Interface: AuditEvent gains AccountAdded : AccountId, one entry per add_account. Pending.expires_at_ns can now be later than its window, for a transfer whose call may have run.

  • New dependency: icrc-ledger-types 0.2.0, DFINITY's, for the ICRC-1 account text form and the ledger's transfer types.

  • Stored format: StoredPending gains two optional fields; actions stored by step 7 decode with both absent, and the upgrade test now carries an open action across the upgrade.

  • ICP's 64-character hex account identifiers are not accepted as a to yet; only ICRC-1 account text is.

  • history is not exported yet: memory 6 holds only what the wallet sent, and incoming transfers need the ledgers' index canisters.

  • The Wasm is 3.10 MB, or 715 KB gzipped (step 7: 2.74 MB and 656 KB), mostly Candid decoding of the ledger types.
  • Tests. The PocketIC tests install the ICRC-1 ledger Wasm from the dfinity/ic release ledger-suite-icrc-2025-09-01 (CI pins the checksum its SHA256SUMS lists) at the ICP ledger's mainnet id on the NNS subnet, and as a token on the wallet's subnet. They check addresses against the mapping written out in the test; balances; a transfer with a memo and fee to the wallet's own subaccount and on from it; a stopped ledger, then started, sending once; two execute calls at once; two identical actions executed together; insufficient funds and a wrong fee; the checks at propose; the daily limit with open transfers and its 24-hour window; and the check again at execute. A property test drives the attempt state against a model ledger that sends, loses the answer, traps the callback, stalls or refuses, and checks that the tokens are sent at most once, that a transfer ends Executed only if they were, and that one sent unheard stays open while the ledger can find it.

    Faults. Injected one at a time, each made at least one test fail: little-endian subaccounts; every transfer sent from the default subaccount; no in-flight lock; open transfers not counted against the daily limit; no limit check at execute; sent transfers not recorded; a call that did not run failing the transfer; balance asking for the caller's account; add_account not audited; Icrc allowed to name the ICP ledger; Duplicate not counted as sent; a refused transfer left ready; the memo dropped; every fresh call created at now; a ledger's CanisterError counted as not run; a refusal after an unknown call ending the action. The last three are Codex's findings, and the property test's model ledger now refuses before deduplication too. The property test also catches an expiry that ignores an unknown outcome, in 5 of 5 runs.

    Checks run locally: cargo fmt --all --check, clippy native and wasm32 with -D warnings, unit and interface tests, the release Wasm build, and the PocketIC tests against server 16.1.0, including the upgrade from step 7.

    🤖 Generated with Claude Code

    https://claude.ai/code/session_013Vgh2De8Zarye1iDyGSRbe

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: b3hr4d Review duration: 86m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.57) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #9"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.7% · Safe to merge
    24.7%