← Back to Pull requests

Rewrite the chain layer around account kinds, with EVM accounts (steps 16 and 17) #24

Closed
unknown closed this pull request without merging on Oct 23, 2026 08:42 UTC
View on GitHub
unknown unknown commented on Oct 22, 2026 12:21 UTC
Author

This PR now holds steps 16 and 17 of docs/plan-v0.md: #25 (EVM accounts) and #26 (the receive, account, members, settings and notifications pages) were merged into this branch, and it is merged with main's recovery controller (#27). The chain code is rewritten rather than adapted.

Before: an owner added an ICP account, an ICRC account per token and a Bitcoin account by hand, and an ICP account and an ICRC account with the same index were two entries for one subaccount. A transfer whose outcome the wallet could not tell waited for someone to press execute again, and a Bitcoin transaction the network dropped kept its outputs reserved for good. Nothing in the wallet could hold or send ETH.

After: every wallet starts with one Internet Computer account, one Bitcoin account and one EVM account (decision 0008).

  • An Internet Computer account holds ICP and every ICRC-1 token the owners track, and the send page picks the token.

  • An EVM account receives at one address on every EVM chain, and shows and sends the native token of each chain the owners track. A new wallet tracks Ethereum, and owners switch Sepolia, Arbitrum One, Base and Optimism on or off on the start page without approval. A wallet on test keys (testnet or regtest) holds Sepolia alone.

  • The wallet settles what it sent on its own:

  • - It retries a ledger call it could not tell every 10 minutes with the same created_at_time.
    - It watches a Bitcoin transaction until it has 6 confirmations. While the transaction's inputs are unspent, it sends it again after 1 hour, then 2, and so on up to once a day.
    - It watches an EVM transaction until a finalized block uses its nonce.
  • An upgrade merges a wallet's ICP and ICRC accounts that share a subaccount into one account, and its open transfers and history follow the merged account.
  • How (step 16, accounts and settling):

  • Accounts and assets. accounts.rs gives each account a kind. assets.rs keeps the tracked list:

  • - ICP is always tracked.
    - ICRC-1 ledgers are added with track_asset once they answer as one.
    - Bitcoin needs no tracking.

    balance and Transfer name an asset, or take the account's default. icp_account_id shows the ICP ledger's account identifier for exchanges.

  • Default accounts. The Internet Computer and EVM accounts are made in init and post_upgrade. The Bitcoin account is made by the timer once the subnet gives the wallet its key, with a growing wait between tries. None of them is in the audit log.

  • Bitcoin network. The network is an install setting, mainnet unless named, as the factory leaves it. An upgrade may set it while the wallet has no Bitcoin account; after that it is fixed.

  • Settling. sending.rs holds execution and settling. Watched Bitcoin transactions settle from one read of the account's outputs.

  • - When an account holds more outputs than the wallet reads, a transaction's own change output in the list still shows the block that holds it.
    - In that case the balance comes from the Bitcoin canister's total, less what each transaction not seen confirmed spends, plus its change.
  • Migration. storage::migrate gives old accounts their kind.

  • - An ICP account and an ICRC account with the same index become one account under the oldest id. The newer id leads to it and is no longer listed.
    - The ICRC-1 ledgers they held become tracked.
    - Transfers name their asset and their new account.
    - Anything still unknown is queued for settling.
  • Local wallets. scripts/try-local.sh --upgrade upgrades the wallet it installed last to the checkout, in place, with the regtest network.
  • How (step 17, EVM accounts):

  • Talking to chains. The wallet only talks to chains through the EVM RPC canister's own providers (no custom RPC URL), and every read needs two of its three providers to agree.

  • Accounts and keys. An EVM account's address is the Keccak-256 of its threshold ECDSA key (wallet / evm / n), written with its EIP-55 checksum. Keccak comes from tiny-keccak, approved in the thread.

  • Building a transfer. It is one EIP-1559 transaction, signed by the threshold key and checked against the account's key before it is sent.

  • - Fees. They come from eth_feeHistory: the higher median base fee and the lower median tip of the providers that answered. Ethereum and Sepolia tip at least 1 gwei. The fee cap is twice the base fee plus the tip, at most 50,000 gwei a gas.
    - Gas. It comes from eth_estimateGas. A plain transfer uses exactly 21,000, and anything else gets half again as much. On Base and Optimism the transfer also budgets twice the L1 data and operator fee that the chain's fee oracle names.
    - A proposer's fixed fee. It caps all of that. A cap below the base fee plus the least tip is refused before signing. The action stays ready and holds no nonce.
    - Count and balance. They are read last. The whole most the transfer may pay counts against the balance and the daily limit.
  • Nonces. A transfer takes the next nonce only once the chain has used every earlier one from the account on that chain.

  • - A transaction no provider can have seen is built again by the next execution.
    - If one of the account's transactions settles while a nonce is being read, the execution stops and is run again.
  • Sending and settling.

  • - A send that may have reached a provider is kept, and is only ever sent again as it is.
    - The wallet looks at it less often each time: 10 minutes, doubling up to a day.
    - It settles by its receipt once a finalized block used its nonce, and records what it really paid.
    - A missing receipt means the wallet looks again later, never that the transaction failed.
  • Upgrades. A wallet from before this release tracks Ethereum (Sepolia on test keys). One whose network an upgrade changes keeps only the chains its new network holds.

  • Self-upgrade cycles. INSTALL_CYCLES is now 350B. A 5.5 MB release installed with 330.4B cycles to spend and was refused with 329.9B. The UI, README and mainnet-gate figures say 0.35T.

  • Test canister. tests/evm_rpc_mock stands in for the EVM RPC canister and uses the deployed canister's Candid types.

  • - It verifies signed transactions, keeps a pool, mines, finalizes, reverts, hides receipts and fails calls on demand.
    - CI builds it.
    - It uses serde_json (=1.0.154), a test-only dependency that does not ship in the wallet.

    Docs. Only docs/design.md, the README and the mainnet-gate figures change, where the rewrite made them false.

    Merged with main (#27). The Recovery card sits on the Settings page beside the rules, since #26 moved members and the policy there. The controller's tests use account kinds. recovery-tool shows the wallet's install argument as (variant { Upgrade = null }) now that Upgrade takes the Bitcoin network, and the example in docs/recovery.md was regenerated. #26's QR encoder decision becomes 0010, since main took 0009.

    Checks on the merged head:

  • Rust. fmt and clippy, native and Wasm, are clean, and 180 wallet unit tests pass.

  • Recovery tool. Its tests pass, including the two that drive icp-cli 1.7's local network, and vectors.py matches.

  • PocketIC. 109 integration tests pass with bitcoind, 17 of them the recovery controller's. They include:

  • - the previous release upgrading with ICP and ICRC accounts at the same index;
    - a Bitcoin send resent after an hour;
    - a dropped Bitcoin transaction resent again and again;
    - a ledger transfer the wallet finds out about by itself;
    - EVM transfers that run, revert, wait for a finalized block, outlive a hidden receipt, and stop on a fee cap that is too low.
  • UI and MCP server. Typecheck, lint and tests pass (62 and 14). The committed pages are rebuilt, and a fresh build gives the same bytes.

  • On a local network. Before #26 and #27 came in, a wallet installed from the main of the day was upgraded in place with try-local.sh --upgrade, and its accounts, balances and open transfers read right.
  • Known limits in v1:

  • No fee bumping. A sent EVM transaction whose fee cap the base fee outgrows waits, holding its nonce, until fees fall.

  • The OP Stack L1 fee is estimated, not read. On Base and Optimism the recorded fee is gas times price.

  • Wasm size. The wallet Wasm is 5,825,501 bytes, so a release takes 6 chunks.

  • The security checkup and a recovery controller. After a hand-over, the Settings checkup still calls the recovery controller "Others control it", a problem. It cannot yet tell that controller from any other.

  • Not yet run on a real EVM chain. Step 17's "done" needs a real Sepolia transfer with the cost of each call recorded, from a wallet on the IC with cycles.
  • To upgrade your local try-local wallet in place, pull this branch and run:

    scripts/try-local.sh --upgrade
    

    🤖 Generated with Claude Code

    https://claude.ai/code/session_013Vgh2De8Zarye1iDyGSRbe

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: b3hr4d Review duration: 1220m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    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%
    60%
    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
    Real PR Conversation Timeline
    1 comments
    "Review active on #24"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 20.5% · Safe to merge
    20.5%