How Zhi works
Three trust boundaries separate the parts: the LLM can only propose a rule tree, the harness can only propose an intent, and only the Guardrail Vault can place an order. Each layer distrusts the one above it.
1. Compile once, sign the hash
The compiler sends your text to Claude as quoted data with a JSON-schema-constrained output. Deterministic code then decides what is accepted: values not grounded in the text become operator defaults (yellow), values above your presets are clamped (red), unknown keys fail. The canonical JSON (sorted keys, minimal numbers) is hashed with keccak256; you sign that hash with EIP-712 and the vault stores it. TypeScript, Rust and an independent Python implementation produce the same hash for the shared fixture.
2. The deterministic harness
A Rust service (zhi run) samples the Injective oracle precompile, builds candles locally, evaluates the frozen tree in 18-decimal fixed point, asks Synth before entries, and submits intents. Every tick is logged with its inputs and the raw Synth body; zhi replay re-runs the log and must reproduce every intent hash bit-for-bit.
# hash + validate a rule tree zhi hash ruletree.json zhi validate ruletree.json --vault 0xVAULT # run the harness (testnet) HARNESS_PRIVATE_KEY=0x… SYNTH_API_KEY=… zhi run --tree ruletree.json --vault 0xVAULT # prove determinism zhi replay logs/0xvault.jsonl # with vs without the Synth gate, on Injective candle history zhi backtest --tree ruletree.json --days 30 # daily evidence -> Zhi Score -> ERC-8004 feedback zhi attest --vault 0xVAULT --attestor 0xATTESTOR --post # anyone: enforce the drawdown freeze zhi poke --vault 0xVAULT
3. Synth SN50 gate
On the last time step of the horizon the harness interpolates the forecast CDF F at the current oracle price P₀. A long needs P(up) = 1 − F(P₀) ≥ the tree's threshold (shorts mirror it), and the 5–95% band (p95 − p05) / P₀ × 10⁴ must be under the tree's ceiling. Failing either check, or Synth being unreachable, skips the trade and records TradeSkipped(SYNTH_*) on-chain with keccak256 of the raw response. The gate is a filter that reduces bad entries; the backtester reports the same tree with and without it.
4. Guardrail Vault checks
Each failure emits TradeSkipped(reason) and returns false. Nothing reverts, so the evidence and the consumed nonce persist.
| Code | Reason | Meaning |
|---|---|---|
| 0 | FROZEN | Frozen (or credit reduce-only) vaults accept reduce-only exits only |
| 1 | BAD_RULETREE | Intent cites a rule tree hash the owner never signed (or revoked) |
| 2 | EXPIRED | block.timestamp > intent.deadline |
| 3 | MARKET_NOT_ALLOWED | Market not on the vault allowlist |
| 4 | COOLDOWN | Too soon after the previous entry |
| 5 | NOTIONAL | quantity × worstPrice > maxNotional |
| 6 | LEVERAGE | margin = 0 or notional ÷ margin > maxLeverage |
| 7 | ORACLE_STALE | Injective oracle reference missing or older than maxOracleAgeSec (entries only) |
| 8 | PRICE_DEVIATION | worstPrice further than maxDeviationBps from the oracle reference |
| 9 | DRAWDOWN | This intent found the daily drawdown breached and froze the vault |
| 10 | OFF_TICK | Quantity or price not on the market's tick sizes |
| 11 | EQUITY_UNREADABLE | Fail closed: equity could not be read for an entry |
| 12 | ORDER_FAILED | Exchange precompile rejected the order (no revert, evidence kept) |
| 13–15 | SYNTH_* | Off-chain gate verdict recorded on-chain with the forecast hash |
Contracts (Injective EVM testnet, chain 1439)
- ZhiFactory0xc29CD98f79A6701f74d67FB8C76d244a16453497
- ZhiAttestor0xCffA9121FcD58041Df9bc7B51db13F9A0Db9aaD7
- CreditPool0xB61DfbC378321e98f9B4143596860eCFB27ED5E6
- ERC-8004 Identity0x8004A818BFB912233c491871b3d84c89A494BD9e
- ERC-8004 Reputation0x8004B663056A597Dffe9eCcC1965A193B7388713
- USDC0x0C382e685bbeeFE5d3d9C29e29E341fEE8E84C5d
PRD open questions closed during the build
Oracle precompile address
0x…0067, interface IOracleModule (InjectiveLabs/solidity-contracts src/Oracle.sol). Verified live: oraclePricePairState(13, BTC feed, USDC feed) returns a 2-second-old price on testnet.
ERC-8004 registries on Injective
Identity 0x8004A818BFB912233c491871b3d84c89A494BD9e, Reputation 0x8004B663056A597Dffe9eCcC1965A193B7388713 on testnet; reference giveFeedback signature and self-feedback rule confirmed in source and exercised in a fork test.
ExchangeTypes fields
DerivativeOrder {marketID, subaccountID, feeRecipient, price, quantity, cid, orderType, margin, triggerPrice}; reduce-only = margin 0.
Synth API
GET /insights/prediction-percentiles?asset&horizon(&start_time) with Authorization: Apikey; 9 levels 0.005–0.995 per step. Equities use SP500/NVDA/TSLA/AAPL/GOOGL symbols.