- Rust engine: real bootstrap/wiring preflight (guardrail-agent), execution layer (retry/router/pre-trade/post-trade/reconciliation), guardrail-doctor diagnostics with allowlist-drift guard. - guardrail-cli: extracted pure helpers into util.rs (split in progress). - 6 Track-2 skills + ensemble; python-lab analytics (regime/drawdown/montecarlo/dossier/ensemble/journal/seed); clients (ts/py/go/mcp/langchain/web-lite/proof-verifier); alert relay; scenarios; helm/k8s/compose; docs. - dashboard/vercel.json + docs/VERCEL_DEPLOY.md for Vercel deployment. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
4.5 KiB
Self-Custody
Guardrail Alpha is fully self-custodial: the user's wallet (via the Trust Wallet Agent Kit, TWAK) holds the keys and the sole signing authority end to end. The trading engine only builds intents and approvals; it can never sign or move funds. This document explains how that property is enforced in code and maps it to the Track 1 self-custody penalty ladder. It elaborates on ADR 0003 — All execution flows through TWAK.
The invariant
Nothing in the workspace except
twak-clientcan produce a signature or an on-chain trade, and eventwak-clientonly executes an order the risk engine has already approved.
How the keys stay with the user
-
Keys live in the wallet, not the process. No raw private key is loaded by the engine. The agent never holds key material;
custodial_signingis a forbidden action in the risk policy (configs/risk_policy.production.json::forbidden_actions). -
The engine only builds intents. Strategy produces
OrderIntents (crates/agent-runtime/src/runtime.rs). The risk engine turns an approved intent into anApprovedOrder(crates/risk-engine). Neither type carries signing authority — they are plain data describing what should happen. -
Execution authority is a type, and only the risk engine mints it. The
TwakExecutor::execute_swapsignature requires anApprovedOrder(crates/twak-client/src/lib.rs):async fn execute_swap(&self, approved: &ApprovedOrder) -> Result<TxReceipt, TwakError>;ApprovedOrderis constructed only insiderisk-engine(returned fromRiskEngine::approve). There is no public constructor a caller can use to forge one. Therefore "execute without a risk approval" is unrepresentable — it is a compile error, not a runtime check. -
Quoting is authority-free; executing is not.
quote_swaptakes a bareOrderIntent(read-only, no keys).execute_swapis the only method that can move funds, and it is gated by theApprovedOrdertype above. -
TWAK does the signing. The actual signature and broadcast happen inside the TWAK transport (Mock/REST/MCP/CLI — see TWAK_INTEGRATION.md). For x402-gated data, the engine builds the payment payload but TWAK signs it (
twak-client::x402::sign_authorization) — keys never leave the wallet. -
Non-execution components physically cannot trade. The dashboard, API, and Python analytics do not depend on
twak-client, so they have no path to signing or execution. The dependency graph itself enforces least privilege. -
Paper mode preserves the same shape, offline.
MockTwakClientis the default executor: deterministic, no keys, no network. It exercises the exact samequote → approve → executepath, so the self-custody guarantees are the same whether running offline or against a live TWAK transport.
The risk gate is the only door to TWAK
Per order, agent-runtime::process_order runs:
OrderIntent
→ RiskEngine::pre_trade (reject early)
→ TwakExecutor::quote_swap (read-only, no keys)
→ RiskEngine::approve(quote) (mints ApprovedOrder, or rejects/clips)
→ TwakExecutor::execute_swap (TWAK signs; only an ApprovedOrder admitted)
→ portfolio reconcile + event log
Policy reinforces this: execution_layer = "twak_only" and bypass_twak is a
forbidden action (configs/risk_policy.*.json). The risk engine is the only
gate; see ADR 0002 — The risk engine is the only gate.
Self-custody penalty ladder
Track 1 penalizes any erosion of self-custody; fully self-custodial agents sit in the top band. Guardrail Alpha targets that top band:
| Band | Behavior | Guardrail Alpha |
|---|---|---|
| Top — fully self-custodial | Keys + signing authority remain with the user's wallet end to end; the agent only proposes. | This design. Engine builds intents/approvals; TWAK holds keys and signs; custodial_signing forbidden. |
| Penalized | Agent holds delegated keys or co-signs | Not used — no key material in process. |
| Heavily penalized | Agent custodies funds / signs autonomously without the user's wallet | Structurally impossible: execute_swap requires an engine-minted ApprovedOrder and all signing is in TWAK. |
Because the top-band guarantee is enforced by the type system and the dependency graph (not just convention), it cannot be silently regressed by a future code change without breaking compilation.