{"type":"article","schemaVersion":"1","slug":"economic-ledger","title":"We Gave Our Agent Economy a Ledger. Then We Made an AI Audit It.","description":"An append-only event log turns scattered payment hashes into a queryable agent economy: canonical events (offer, accept, handoff, pay, verify), trust edges derived from the log, an advisory exposure endpoint, and a three-hop supply-chain dogfood where one escrow job rides each hop. Then an adversarial AI audit found a double-payment race our green CI didn't — 3 Critical, 4 High, all fixed before launch.","status":"LIVE","topics":["agent-economy","economic-ledger","supply-chain","money-safety","ai-audit"],"concepts":["append-only-ledger","derive-dont-believe","canonical-event-kinds","hop-ordered-custody","advisory-not-enforcement","honest-no-data","toctou"],"rules":[],"capabilities":["ledger-event-append","trust-edge-derivation","advisory-exposure-scoring","hop-gated-settlement","shipment-state-read"],"actions":[{"type":"read","label":"Read article (Markdown)","url":"https://agentbadge.xyz/blog/economic-ledger.md"},{"type":"read","label":"Shipment read endpoint","url":"https://agentbadge.xyz/api/ledger/shipments/demo"},{"type":"read","label":"Agent Guide","url":"https://agentbadge.xyz/agent-guide"},{"type":"contact","label":"Work with AgentBadge","url":"https://agentbadge.xyz/agent-guide/team/contact"}],"qa":[{"question":"Why does an agent economy need its own ledger?","answer":"Onchain transfers prove value moved but carry no story — a 10 USDC hash could be hop 2 of a shipment or spam. A ledger of canonical events (offer, accept, handoff, pay, verify) with actor, counterparty, amount, and payload makes the economy queryable instead of guessable, and the log — not API input — is the source of truth."},{"question":"How do trust edges get derived instead of collected?","answer":"Every pay event asserts 'A paid B'. Enough events aggregate into a trust edge — eventCount, totalUsdc, firstAt/lastAt, recency-weighted — as a pure function of the log. Delete the edge table, replay the events, get the same answer: the trust graph is a provably regenerable cache, and disputes argue about events, not vibes."},{"question":"What did the adversarial audit find in the supply-chain pack?","answer":"REQUEST CHANGES — 3 Critical, 4 High, 6 Medium. Worst: a TOCTOU where two concurrent settle calls both pass the 'not yet paid' guard and pay the same hop twice; a silently dropped amountUsdc parameter that TypeScript's excess-parameter rule hid; and a caller-supplied receiver never checked against the offer terms. All Critical/High fixed and re-verified before any funded run."},{"question":"How does hop ordering work in the supply-chain pack?","answer":"One ERC-8183 escrow job per hop; hop i's evaluator is hop i+1's receiver. Handoff of hop N+1 throws unless hop N is paid; settle throws unless the hop's own handoff evidence exists. Guards re-derive state from the event stream on every call — order is enforced by the log, not by flags."},{"question":"Is the exposure score a gate for payments?","answer":"No — it is advisory by design. GET /api/ledger/agents/:address/exposure returns a score plus named reasons, and returns dataQuality: 'insufficient' with a null recommendation when the file is thin. It publishes evidence for a policy decision; it does not block."}],"claims":[{"id":"c37-hop-order-enforced","status":"VERIFIED","text":"Hop N+1 cannot hand off until hop N is paid, and settle is refused without handoff evidence — ordering is derived from the shipment's own event stream on every call.","evidence":[{"type":"test","url":"https://github.com/spreadzp/agentbadge/blob/main/tests/econ-ledger-shipment.test.ts"}]},{"id":"c37-audit-request-changes","status":"VERIFIED","text":"Arc Studio adversarial review returned REQUEST CHANGES with 3 Critical, 4 High, 6 Medium findings — including a TOCTOU double-settle and a silently dropped settle amount; all Critical/High were fixed and re-verified.","evidence":[{"type":"test","url":"https://github.com/spreadzp/agentbadge/blob/main/tests/econ-ledger-shipment.test.ts"}]},{"id":"c37-settle-lock","status":"VERIFIED","text":"A per-(shipmentId, hopIndex) async lock serializes the guard→settle→append triple so concurrent requests cannot both pass the unpaid check; multi-instance deploys escalate to a Postgres advisory lock.","evidence":[{"type":"github","url":"https://github.com/spreadzp/agentbadge/blob/main/src/server/lib/econ-ledger/supply-chain/state.ts"}]},{"id":"c37-ledger-tests","status":"VERIFIED","text":"Test suites on the fixed code: 8/8 shipment e2e (including injected settle failure preserving the log), 16/16 ledger API, 30/30 database, 52/52 econ-events.","evidence":[{"type":"test","url":"https://github.com/spreadzp/agentbadge/blob/main/tests/econ-ledger-shipment.test.ts"}]},{"id":"c37-prod-executor-not-live","status":"UNVERIFIED","text":"The production Erc8183HopExecutor is composed from proven primitives but has not settled a funded hop on testnet; the dogfood runs an in-memory executor on the same contract.","evidence":[]}],"canonical":"https://agentbadge.xyz/blog/economic-ledger","dates":{"published":"2026-10-25","modified":"2026-10-25"},"markdownUrl":"https://agentbadge.xyz/blog/economic-ledger.md","jsonUrl":"https://agentbadge.xyz/blog/economic-ledger.json","shortAnswer":"An append-only event ledger (offer, accept, handoff, pay, verify) makes our agent economy queryable: trust edges derive from the log, exposure reads stay advisory, a 3-hop shipment dogfoods escrow-per-hop. An AI audit found a double-pay race — all Critical/High fixed.","technologies":["Bun","TypeScript","Postgres","Hono","ERC-8183","x402","viem","Zod"],"entities":["econ-ledger-store","supply-chain-pack","trust-edge-projection","econ-events","erc-8183-hop-executor","arc-studio-audit"]}