Recovery controller: owners repair a broken wallet with their own keys (decision 0009) #27
All Vouch review confidence checks passed
Residual risk 0.23 = Change Risk (0.57) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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 #27"
general
weight: 0.35
b3hr4d
<!-- claude-projects-attribution: {"github_login":"b3hr4d"} -->
_Requested by Behrad · project thread_
Step 18, [decision 0009](docs/decisions/0009-recovery-controller.md): owners can repair a wallet whose pages, sign-in, API or own upgrade method broke, with their own recovery keys and no help from the wallet, a release service or us. It supersedes decision 0005 once accepted.
Passing tests do not make this production-ready. It has had one independent review inside this work and no external audit, and nothing has run on mainnet. The residual risks are in the ADR and below.
What it does
canisters/controller: one small controller per wallet. It becomes the wallet's only controller and has no controller itself, so nobody can upgrade it. It stores its own policy: 3 to 10 Ed25519 recovery keys, a normal and a sovereign threshold and delay, and optional release signers. It acts only on an operation the keys signed, once its threshold and delay are met: install code on the wallet, change its policy, or hand the wallet to a new controller. Any key can cancel.- It takes messages from outside the IC only from its keys (
inspect_message). A call from the wallet carries no weight.- Policy floors: the sovereign threshold is at least 2 and at most keys − 1, the normal threshold is below it, and the sovereign delay is longer. Release signers cannot also be recovery keys. Labels are printable ASCII and distinct.
- Defaults (Behrad's choice): 3 keys, 1 key + 48h for a signed release, 2 keys + 7 days for everything else.
crates/recovery): every operation names the controller, the wallet, the policy version, a nonce, an expiry (after its delay, at most 60 days ahead), the install mode, the Wasm and chunk hashes, the argument's hash and, on the release route, the release's fields. Keys sign a domain-separated digest of a fixed byte encoding.docs/recovery.mdspecifies it with test vectors, and an independent Python implementation (tools/recovery-tool/vectors.py, in CI) reproduces them from the text alone. Each key may propose 8 operations a day and keep 4 open.- An upgrade stops the wallet, so no call is in flight across the install.
- A reinstall uninstalls the code instead, which also ends calls that hostile code never lets finish.
- The controller pays whatever cycles the wallet lacks for the install.
- It stages the module in the wallet's own chunk store, installs it with
install_chunked_code, then starts the wallet again whatever failed.- The canister id, threshold-key derivation paths and funds stay. No snapshot is taken or restored.
- A retry after a lost answer checks the IC's canister history for the controller's own change, at the canister version it sent.
HandOverControl, runs under the wallet'sSetPolicyquorum and timelock. Owners propose it from a new Recovery controller card on the start page. Before the wallet sets its controllers to exactly the controller, it checks:- the controller's module, and that it has no controller;
- that its whole history is one install of that module (
canister_info);- that it serves this wallet with the named policy and has taken no operation;
- its
health: it must run on the wallet's subnet, with settings that cannot strand the wallet (freezing threshold of 30 to 365 days, no allocations, the IC's default limits or higher).The ADR and the guide list every point where a hand-over can stop.
tools/recovery-tool: the owners' client. It makes policies, proofs of possession, install arguments and operations. It shows what an operation does before a key signs it, signs, cancels, and splits a module into chunk calls. It also checks a controller and wallet (module, controllers, state, health, subnet) from what icp-cli reads. icp-cli sends everything, including calls signed on a computer that never goes online.scripts/build-controller.sh: builds the controller to the same bytes in any directory, so owners can compare its hash. Today that hash is8455334b712142130bf3a405a75b2834bc615ab692f23c88e5983e057971b9e3.docs/recovery.md: the owners' step-by-step guide, with the interruption table, troubleshooting, the reinstall path and the encoding spec.Orbit
I read Orbit's source (
dfinity/orbit@c766e61), not its docs; the comparison table is in the ADR. In short:caller == station.We took three ideas and none of the code: one helper canister per wallet, a quorum on the same module hash and argument, and stop, install, start around every install.
Evidence
All of this ran locally, minus the 6 bitcoind tests: bitcoincore.org is blocked from this container, so only CI runs them (they passed on the first push).
cargo fmt --check, clippy with-D warnings(native, and Wasm for every canister),git diff --check.| Crate | Tests |
| --- | --- |
| recovery | 24 |
| controller | 8 |
| wallet | 119 |
| recovery-tool | 5 + 12 CLI |
| release | 16 |
| release-tool | 6 + 8 CLI |
| release_channel | 5 |
| factory | 10 |
| Suite | Tests |
| --- | --- |
| controller | 17 |
| wallet | 51 (6 bitcoind tests skipped) |
| release_channel | 11 |
| self_upgrade | 7 |
| factory | 5 |
- Hand-over to a verified controller.
- Refusing controllers the wallet cannot verify: wrong module or policy, controllers left, another wallet, reinstalled, snapshot-loaded, a 400-day freezing threshold, one that has taken an operation, one on another subnet.
- An interrupted hand-over.
- Repairing broken and hostile wallet code with no release service.
- Code that holds a call so the wallet never stops: the upgrade fails, the reinstall succeeds, the owner claims again, and the same accounts come back with their tokens and send.
- A wallet whose code drained its cycles, topped up by the controller and repaired.
- The release route.
- A trapping
post_upgrade.- A rejected install that is not mistaken for one that ran later.
- Operations bound to the controller, wallet, policy version, nonce and window.
- Ingress from strangers dropped, with no cycles charged.
- The daily proposal limit.
- Thresholds, delays, cancellation and rotation.
- Refusals for lack of cycles before anything stops.
-
ReplaceController, including a costly new controller and a wallet already pointed at the target.- A controller nobody can upgrade.
- A transfer and an install started together.
recovery-tool: 2 PocketIC tests drive a controller from the tool's files, one directly and one through icp-cli 1.7.0 over PocketIC's HTTP gateway, including an offline-signedapprove.docs/recovery.mdwith icp-cli 1.7.0 on a fresh local network, run again after the review fixes with the updated guide:- A claimed, self-controlled wallet and three openssl keys.
- The controller built and created on the wallet's subnet with
--subnet. Itshealthwas read by a key before its controllers were removed.- A stranger's update was refused with
Canister rejected the message, and a query still answered.- A 2-key policy and a signer that is also a key were refused.
-
checkrefused a wrong--wallet-subnet, then passed with--before-hand-over.-
HandOverControlwas refused during its 7-day timelock, executed after it, thencheckpassed.- An upgrade was proposed with 2 keys and its chunks uploaded. It was refused while its delay ran. An expiry before the delay was refused, and a cancel went through. A third key executed the upgrade after the delay, the wallet's owner was intact, and
checkpassed.- The controller spent about 34B cycles from proposal to execution.
- To pass the delays, I moved the network's clock forward through PocketIC's API, and icp-cli's clock with a shim.
| Fault | Caught by |
| --- | --- |
| the wallet skips the controller's history check |
the_wallet_refuses_a_controller_it_cannot_verify|| the wallet keeps itself as a co-controller |
a_wallet_hands_itself_to_a_verified_controller_and_keeps_running|| the controller stages chunks in its own store |
a_controller_on_another_subnet_installs_the_wallets_code|| any caller may change the controller's state |
operations_are_bound_to_one_controller_wallet_policy_nonce_and_window,thresholds_delays_cancellation_and_key_rotation|| an operation runs before its delay ends |
thresholds_delays_cancellation_and_key_rotation,the_delay_starts_when_the_threshold_is_met|| one key's approval counts twice |
operations_are_bound_to_one_controller_wallet_policy_nonce_and_window,a_key_approves_once|| an approval the operation holds already makes the request fail |
a_key_approves_once(and the tool's PocketIC test) || the controller takes ingress from anyone |
operations_are_bound_to_one_controller_wallet_policy_nonce_and_window|| no daily proposal limit |
one_key_proposes_a_bounded_number_of_operations_a_day|| the controller does not pay what the wallet lacks |
a_wallet_its_code_drained_is_topped_up_by_the_controller_and_repaired,code_that_never_lets_the_wallet_stop_is_reinstalled_and_the_funds_stay|| a reinstall stops the wallet instead of uninstalling |
owners_repair_broken_and_hostile_wallet_code_without_any_release_service,code_that_never_lets_the_wallet_stop_is_reinstalled_and_the_funds_stay|| a lost-answer retry takes any install for its own |
a_rejected_install_is_not_taken_for_one_that_ran_later||
ReplaceControllerskips the new controller's health |replace_controller_hands_the_wallet_to_a_verified_new_controller||
ReplaceControllertakes a controller that ran operations |replace_controller_hands_the_wallet_to_a_verified_new_controller||
ReplaceControllertakes a wallet already pointed at the target as handed over |replace_controller_hands_the_wallet_to_a_verified_new_controller|| the wallet skips the controller's health |
a_controller_on_another_subnet_installs_the_wallets_code,the_wallet_refuses_a_controller_it_cannot_verify|| the wallet takes a controller that ran operations |
the_wallet_refuses_a_controller_it_cannot_verify|| expiries before the delay are accepted |
operations_are_bound_to_one_controller_wallet_policy_nonce_and_window,a_proposal_is_bound_to_this_controller_wallet_version_nonce_and_window|| a release signer may be a recovery key |
release_signers_are_optional_but_well_formed|| a two-key policy is accepted |
a_policy_needs_keys_that_are_distinct_valid_and_few,thresholds_take_two_keys_and_leave_room_for_one_lost_key|| health accepts any subnet |
a_controller_on_another_subnet_installs_the_wallets_code,settings_that_could_strand_the_wallet_fail|| a proof for a key enrolled already goes unchecked |
every_new_key_needs_a_proof_for_this_controller_and_wallet|Independent review
A reviewer who had not written the code read the controller, the hand-over and the encoding against the ADR. Everything it found is fixed, with a test:
| Finding | Change |
| --- | --- |
| High: wallet code that keeps a call in flight never lets the wallet stop, and code that spends the wallet's cycles keeps it below what an install needs, so hostile code could block its own repair | A reinstall uninstalls the code instead of stopping it, and the controller pays what the wallet lacks |
| A two-key policy had to be 1 of 2, so one stolen key took everything | 3 to 10 keys, sovereign threshold 2 or more, normal below sovereign, a longer sovereign delay |
| A recovery key that was also a release signer made the sovereign route one key's | Release signers and recovery keys must be separate |
| One key could store operations without end, with expiries a nanosecond away | The expiry must come after the delay; 8 proposals per key per day |
| Strangers could send reads as updates, which the controller pays for |
inspect_messageaccepts messages from keys only || A creator's settings (freezing threshold, limits) or another subnet could strand a wallet | A new
healthmethod; the hand-over andReplaceControllercheck the settings, the subnet, and that the controller is fresh from its install || A retried install could take another operation's install of the same module for its own | A rejected install is forgotten, and the history change must carry the controller's version from the send |
|
ReplaceControllertreated any wallet already controlled by the target as handed over | Only after it sent the change itself || Labels could imitate other labels with look-alike or direction characters | Printable ASCII, unlike every other label |
Codex's review of this PR found two more defects, fixed in 5fcd1e0:
After that fix, the controller's hash changed and the rehearsal ran again end to end.
Residual risks
ReplaceController, and a bug there leaves the wallet running its last code, unable to upgrade again.SetPolicyremoves it.canister_infoor a controller's settings directly. The client relies on the controller's ownhealthand on the wallet's checks at hand-over.health.- the controller's timer after an execution died part way;
- the retry of an install or hand-over whose answer was lost;
- the Recovery card in a browser with a signed-in owner.
Not in this PR
No mainnet deploy, no funds moved, no live controllers changed, nothing made immutable on any network.
This overlaps #24 (account kinds) in
canisters/wallet/src/{lib.rs,types.rs},candid/wallet.did, the docs and CI. Whichever merges second needs a rebase; I can do it.🤖 Generated with Claude Code
https://claude.ai/code/session_01CMXHbQaDWZQihgM3sLG7o1