Overview
When users deposit assets into a Cartesi Rollups application, those assets are held by the application contract on the base layer, and the application's off-chain state (an in-app ledger of who owns what) decides how they can be spent. In normal operation the operator runs a node that keeps this state moving and settles it on-chain. But what happens to those funds if the operator stops running the node?
Foreclosure and emergency withdrawal are the answer. They let a designated guardian freeze an application, after which any user can withdraw their in-app balance straight from the base-layer contracts by proving their account, with no running node required.
The feature is opt-in: an application only supports it if it was deployed with a WithdrawalConfig. Applications deployed without one behave exactly as before. In addition to that, the application is also expected to record the assets deposited into it using the CMA ledger library. This library keeps those balances inside the accounts drive in a recoverable, provable layout that matches the WithdrawalConfig. See the Asset Management Library section for more details about the CMA library.
The two parts
Foreclosure freezes the application. A guardian address, set in the withdrawal config, calls foreclose(). From that moment the application is frozen at its last settled state, and it stays frozen forever. See FOR-005 for the guardian-only rule.
Emergency withdrawal is the recovery path that foreclosure unlocks, and it is built on the application's accounts drive.
The accounts drive is a dedicated drive, a region of the Cartesi Machine's memory, that the application uses as its balance ledger. It records how much each account owns, in a fixed layout described by the WithdrawalConfig. Like every drive, it sits at a known, fixed address in the machine's memory.
The machine's whole memory is a single Merkle tree whose root, the machine state root hash, is finalized on-chain as part of the settled claim. Because the accounts drive occupies a known address, its own Merkle root is a fixed branch of that tree, so it can be proven up to the machine state root hash with a short list of sibling hashes. After foreclosure, anyone submits that proof once to anchor the accounts-drive root on-chain against the application's last settled machine state. The ledger is then fixed on-chain, and each user withdraws their own balance by proving their account against that anchored drive. Everything happens directly against the contracts, so it keeps working even if the operator and its node are gone.
When funds are recoverable
All of the following must hold:
- the application was deployed with a valid
WithdrawalConfig(a guardian, an accounts-drive layout, and a withdrawal output builder); - the guest application actually maintains the accounts drive in the layout the config describes;
- the application has been foreclosed by its guardian; and
- the account's balance was part of the last settled state.
Where to go next
- Claim & Foreclosure Lifecycle explains how inputs become settled state, and how foreclosure fits into that lifecycle.
- Emergency Withdrawal Recovery Guide is the step-by-step procedure for foreclosing and withdrawing.
- The Application and Withdrawal contract pages are the on-chain reference.