Holdfast

Under the hood

The rules aren't in this website or the app. They're in one CashScript contract that Bitcoin Cash miners check on every spend. Here's how it's built.

contracts/Holdfast.cash, the allowance rule
function spend(sig ownerSig, int amount, bool fresh) {
    require(checkSig(ownerSig, ownerPk));
    ...
    require(int(level) < 2);
    require(used <= amount + 2500);
    require(spent + used <= allowance);
    ...
}

One address, four kinds of coin

Everything a vault owns sits at a single contract address. Coins there are told apart by the CashToken NFT they carry, all of one category that only the vault can mint.

  • The vault coin carries the minting NFT. Its 13-byte commitment holds the freeze level, the allowance spent in the current window, and four approval flags.
  • A waiting withdrawal carries a mutable NFT naming its one recipient. Its age is the clock.
  • A guardian-replacement ticket carries an immutable NFT. Its age is the 7-day clock.
  • A deposit carries no token. It waits until a vault key merges it in.

One address means the app reads the whole vault with a single lookup, and nobody can hide a withdrawal somewhere else.

Every function

FunctionWho signsWhat the contract checks
spendPhoneNot fully frozen; the payment equals the amount; payment plus fee within the allowance. With fresh, the vault coin must be 144 blocks old (about a day) and the window restarts.
startWithdrawalPhoneVault open; its fee fits the allowance; at least 5,000 sats. Mints a waiting-withdrawal NFT holding exactly the amount and the recipient's locking bytecode.
releaseAnyoneThe withdrawal coin is at least the wait old (CHECKSEQUENCEVERIFY). Pays only the recorded recipient and burns the NFT.
approveFast, releaseFastGuardian, then anyoneMarks one withdrawal fast; it can then be released after about an hour (6 blocks). Refused when the vault has no guardian.
mergeAny vault key; not the phone or panic key on a fully frozen vault; tickets only by the home codePulls a deposit, waiting withdrawal or ticket back into the vault coin, paying the fee from that coin. Cancelling is merging.
freezeHome code or guardian; panic keyLevel 2 stops the vault coin: no spends and no new withdrawals. The duress key can only set level 1, which still lets the allowance go. Always allowed; its fee is recorded against the allowance. Withdrawals already waiting are cancelled with merge, which the app does right after a home code or duress freeze.
approveHome code, guardianSets one approval flag per transaction, and must change one. Its fee must fit the allowance (with fresh after a quiet day). When both unfreeze flags are set, the same spend opens the vault and clears every approval.
recoverHome codeOnly during a full freeze with both recovery flags set. With no guardian, one home-code approval sets both, and the vault coin must also be your wait old. Moves everything, normally to a new vault for a new phone.
startEvict, evictPhone and home codeMints a ticket; a week later the ticket lets them move everything, even while frozen. A guardian who freezes and vanishes can't lock you out.

Design choices

A

Approvals one signer at a time

Unfreezing needs two people, but they never have to sign the same transaction. Each approval is its own spend that flips one flag. Your guardian approves from their own phone, whenever they're free.

B

Time from coin age, not the clock

Waits use relative time locks on each withdrawal coin. Nothing depends on a timestamp the spender could choose.

C

No admin key

No function lets Holdfast, or anyone outside your keys, move or freeze your coins. If this site disappears, the open-source app from GitHub can still drive the contract with your vault code, home code and wallet.

D

Fees come from the vault

Your wallet only ever signs; it never adds coins to pay. Phone spends and withdrawal starts count their fee against the daily allowance. Merges pay from the coin being merged. Freeze, approval and guardian-replacement fees are recorded against the allowance too (capped at 2,500, 2,500 and 3,500 sats), and release is capped at 2,000. Starting and cancelling withdrawals in a loop can still burn a few times the allowance a day in fees; it can't move money out. Recovery and guardian removal move everything, so they have no cap.

Tests that try to break it

Contract tests run every function through the Bitcoin Cash VM on CashScript's mock network, including the wrong keys, the wrong amounts and the wrong timing. Three attacks were found while reviewing the design; an independent security review on Nov 19 found more in that first contract, and version 2 blocks every one of them. Each is a test that must fail:

  • Minting a second, fake vault coin during an allowance spend. Blocked: an allowance spend must have exactly two outputs, the payment must equal the amount, and it can't carry a token.

  • Keeping a released withdrawal's NFT alive to fake a fast withdrawal. Blocked: release burns it.

  • Skipping the 7-day ticket check by spending the ticket as a merge. Blocked: a merge can only go back into the vault, with the vault's state and value unchanged.

  • Paying out more than the allowance by hiding it in the fee. Blocked (Nov 19 review): the payment must equal the amount, and the payment plus its fee count against the allowance.

  • Burning the vault to fees with merges, repeated approvals or freeze-and-unfreeze loops. Blocked (Nov 19 reviews): merges pay from the coin merged in, the phone can't touch a fully frozen vault, every approval must change a flag, and approval fees must fit the daily allowance.

  • A guardian destroying the replacement ticket so they can never be removed. Blocked (Nov 19 review): only the home code can merge a ticket.

  • Emptying a no-guardian vault on the spot with a forced home code. Blocked (Nov 19 reviews): moving everything needs a full freeze and the normal wait, and the fast lane is refused when there is no guardian.

Not yet done Not yet done: an outside audit.

Read the contract, read the tests and the attack tests, and the Nov 19 review.