Step 9: Bitcoin accounts signed with threshold ECDSA #10
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
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 #10"
general
weight: 0.35
b3hr4d
<!-- claude-projects-attribution: {"github_login":"b3hr4d"} -->
_Requested by Behrad · project thread_
Before:
add_accountrefused Bitcoin, so the wallet held only ICP and ICRC tokens.After: an owner adds Bitcoin accounts on mainnet, testnet or regtest. Each one holds its coins at the P2WPKH address of a threshold ECDSA key,
balancereads its confirmed satoshis from the Bitcoin canister, and aTransferfrom it builds, signs and sends a transaction through the Bitcoin canister, at most once.Keys. Account index
non a Bitcoin network is the key of pathwallet / bitcoin-<network> / n, withnas 4 big-endian bytes, asdocs/design.mdplanned. The keys arekey_1on mainnet,test_key_1on testnet anddfx_test_keyon regtest.add_accountasks the management canister for the public key once and stores it, so the address never needs another call. While it waits, other calls run, so it checks again that the caller is still an owner and that no other account took the index.Transactions. A transfer is built on its first
execute. It spends the account's confirmed outputs that no open transfer has reserved, those with 100 confirmations first and then the largest first, and pays the recipient in output 0 and the change back to the account in output 1. Change too small to relay goes to the fee.feeis the whole fee in satoshis; with none, the wallet pays the median rate the Bitcoin canister reports, at least 1 sat/vB, and 2 sat/vB when it reports none. Afeebelow 1 sat/vB of the transaction it pays for fails the transfer; one that covers an exact-balance payment without change passes, but change the network would relay never goes to the fee (Codex's first finding). Each input is signed in a bounded-waitsign_with_ecdsacall, and every signature is normalized to low-s and checked against the account's key before the transaction goes to the Bitcoin canister.At most once. The transaction is stored once it is built, its outputs are reserved in a new memory 12, and every later
executesends that same transaction, signing it first if it is not signed yet. Its id covers no signature, so signing it again cannot make a second payment. One execution runs at a time, with a heartbeat after every await, and one stuck for an hour is taken over. Once a send may have reached the Bitcoin canister, the action stays ready, cannot be rejected and never expires:executesends the same transaction again until the Bitcoin canister accepts it. As in step 8, only a reject by the IC before the Bitcoin canister ran counts as not sent. A transfer that ends without sending (failed, rejected or expired) releases its outputs.Daily limit. A Bitcoin transfer's fee counts toward its chain's limit, both when it is proposed (the explicit fee) and when it runs (the real fee, checked again once the transaction is built). It is checked once more just before each send until one may have reached the Bitcoin canister, so a policy executed while the transaction was being signed applies (Codex's third finding); a transaction that may have been sent still goes. A transfer stored in memory 6 now carries its fee. Ledger fees still do not count.
How:
btc.rs(addresses, checks, coin selection, the transaction and its signatures) and the Bitcoin attempt state inactions.rsare pure;signer.rsmakes the threshold ECDSA calls andbitcoin_canister.rsthe Bitcoin canister's;calls.rsis the bounded-wait call thatledger.rsnow uses too, with step 8's error texts unchanged.lib.rsmakesadd_accountasync and givesexecuteits Bitcoin branch.Worth your review
Executedand the reward stays reserved. You chose this over holding every incoming output for 100 confirmations; decision 0003 records both.executerebroadcasts it. Telling a dropped transaction from a slow one needs the outputs read again, which a later step can add. For the same reason, the outputs of a sent transaction stay in memory 12 for good, one small entry per output spent.bitcoin0.32.102 with no default features, DFINITY'sic-cdk-bitcoin-canister0.2.0 for the Bitcoin canister's types and prices, andsecp256k10.29.1, already underbitcoin, named only to build it with itslowmemorytables.StoredAccount.public_key,StoredPending.bitcoinandStoredTransfer.feeare new optional fields, and memory 12 is new. The upgrade test carries step 8's state across.add_accountkeeps its Candid type but now awaits the management canister for a Bitcoin account.bitcoin-core/guix.sigs.Tests. Unit tests cover addresses against the BIP-173 vector, the checks at
propose, the fee rate, coin selection and its maturity boundary, dust change, the fee floor, the 32-input cap, and signing with a known key, including a high-s signature. The attempt state has tests for the execution lock and its takeover, a kept transaction, sends that did not run or may have, and a property test (1,024 cases) against a model Bitcoin canister that takes a send, takes it unheard, loses it, is full, or stalls, with the wallet's code sometimes trapping after it: it checks that at most one transaction is sent, that a transfer endsExecutedonly if it was, and that one maybe sent stays open. Six regtest tests start Bitcoin Core and a PocketIC instance whose Bitcoin canister follows it. They check that an account receives at its key's address, sends once with the change back, and still spends after an upgrade; the checks atpropose; twoexecutecalls at once; two transfers that never spend the same output, even unconfirmed; failed transfers that reserve nothing; the daily limit with the fee; a send whose outcome is unknown, which keeps its output reserved, cannot be rejected, and later sends the same transaction; a transfer that spends a change output 100 blocks old rather than a larger mining reward 1 block old; and a policy lowered while a transfer waits for its signatures, which fails that transfer and frees its outputs, while one that may have been sent still sends.Faults. Injected one at a time, each made at least one test fail: a lost execution not marking its send as maybe sent; an unknown send not marked; no execution lock; a maybe-sent transfer expiring;
resumeignoring a takeover; outputs released after a maybe-sent transaction; fees not counted as spent; a little-endian index in the path; no low-s normalization; the change output dropped; dust change kept; the fee floor ignored, or checked only on the transaction with change; the signature check skipped; no reserved outputs filtered out; no outputs reserved; the transaction rebuilt on everyexecute; no daily-limit check with the real fee; signing with the next account's key; maturity ignored in the coin order, every coin taken as mature, or maturity counted one block late; no daily-limit check before the send, or that check or the one at the start ofexecutemade even after a send that may have reached the Bitcoin canister. The fourth regtest test is the only one that catches the rebuilt transaction, the fifth every coin taken as mature, and the sixth the three faults around the check before the send.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 with Bitcoin Core 31.1, including the upgrade from step 8.🤖 Generated with Claude Code
https://claude.ai/code/session_013Vgh2De8Zarye1iDyGSRbe