Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

docs(contracts): publish the audit scope, static-analysis findings, and economy threat model

nirholasb64bf6e0186e
diff --git a/contracts/AUDIT-README.md b/contracts/AUDIT-README.md
new file mode 100644
index 000000000..8b8c7aca0
--- /dev/null
+++ b/contracts/AUDIT-README.md
@@ -0,0 +1,221 @@
+# Audit pack: three.ws economy contracts
+
+Start here if you are reviewing these contracts. This document is the single
+entry point: what is in scope, what each contract is for, what it claims about
+itself, what is already proven, what is already known, and the exact commands to
+reproduce every number quoted below.
+
+Nothing in this pack asks you to take a claim on trust. Every number has a command
+next to it, and every "this is safe because" resolves to an invariant id whose
+test you can run.
+
+- **Invariants** (what the code claims must always be true): [`specs/ECONOMY_CONTRACT_INVARIANTS.md`](../specs/ECONOMY_CONTRACT_INVARIANTS.md)
+- **Threat model** (assets, actors, failure modes): [`specs/ECONOMY_CONTRACT_THREAT_MODEL.md`](../specs/ECONOMY_CONTRACT_THREAT_MODEL.md)
+- **Static analysis + dispositions**: [`audit/static-analysis.md`](./audit/static-analysis.md)
+- **Deploy status and address provenance**: [`DEPLOYMENTS.md`](./DEPLOYMENTS.md)
+- **Registration-layer threat model** (upstream of these contracts): [`specs/SECURITY.md`](../specs/SECURITY.md)
+
+## Scope
+
+The economy set is the code that moves value or records the economic state value
+is priced against. The roadmap names three of them specifically: **reputation**
+(`ReputationRegistry`), **royalty** (`AgentPayments` on EVM, `skill_license` on
+Solana), and **delegation** (`IdentityRegistry`). The rest of the set is included
+because it shares the same review surface and two of them are already live.
+
+Solana leads on this platform, so the two Anchor programs are first-class scope,
+not an appendix.
+
+| Contract | Source | Lines | Role | Deploy status | Invariants | Tests |
+|---|---|---|---|---|---|---|
+| IdentityRegistry | [`src/IdentityRegistry.sol`](src/IdentityRegistry.sol) | 295 | Delegation: ERC-721 agent identity, EIP-712 wallet binding, per-agent balances, spend allowances | Canonical ERC-8004 address live on 12 mainnets + 7 testnets; bytecode read verified 2026-06-19. Deployed by the ERC-8004 reference project, not from this tree | `ID-1` .. `ID-11` | 37 |
+| ReputationRegistry | [`src/ReputationRegistry.sol`](src/ReputationRegistry.sol) | 210 | Reputation: one review per reviewer per agent, optional refundable ETH stake | Same as above | `REP-1` .. `REP-10` | 31 |
+| AgentPayments | [`src/AgentPayments.sol`](src/AgentPayments.sol) | 411 | Royalty (EVM): payments in, split into authority and buyback shares, buyback swaps and burns | Not deployed. Address table in `DEPLOYMENTS.md` is unfilled | `AP-1` .. `AP-13` | 57 |
+| skill_license | [`skill-license/src/lib.rs`](skill-license/src/lib.rs) | 464 | Royalty (Solana): 1-of-1 NFT access key per purchased skill, revocable on refund | Not deployed. Program id reserved via `declare_id!`; runbook in [`skill-license/DEPLOYMENT.md`](skill-license/DEPLOYMENT.md) | `SL-1` .. `SL-8` | 21 |
+| GreenfieldVault | [`src/GreenfieldVault.sol`](src/GreenfieldVault.sol) | 338 | Pay-to-unlock marketplace over a real BNB Greenfield cross-chain permission grant | Not deployed to a public chain; proven on an anvil fork | `GV-1` .. `GV-9` | 41 |
+| ValidationRegistry | [`src/ValidationRegistry.sol`](src/ValidationRegistry.sol) | 166 | Allow-listed validators attest to off-chain proofs | Not deployed from this tree; the platform uses the ERC-8004 reference registry | `VR-1` .. `VR-6` | 22 |
+| WorldMoves | [`src/WorldMoves.sol`](src/WorldMoves.sol) | 146 | Event-only move stream, no value, no admin | Not deployed to a public chain | `WM-1` .. `WM-4` | 19 |
+| agent_invocation | [`agent-invocation/src/lib.rs`](agent-invocation/src/lib.rs) | 129 | Verifiable agent-to-agent invocation events, no value | Not deployed. Program id reserved via `declare_id!` | `AI-1` .. `AI-4` | 11 |
+| **ThreeWSPayments** | [`ThreeWSPayments.sol`](ThreeWSPayments.sol) | 97 | x402 pay-per-call USDC receiver | **LIVE on BNB Smart Chain, Base, Arbitrum One.** Custodies real USDC | `TWP-1` .. `TWP-6` | 22 |
+| **ThreeWSFactory** | [`ThreeWSFactory.sol`](ThreeWSFactory.sol) | 20 | CREATE2 deployer behind the platform's vanity addresses | **LIVE on the same three chains** | `TWF-1` .. `TWF-4` | 13 |
+
+Cross-contract invariants (`X-1` .. `X-5`) apply to the whole set.
+
+**Out of scope:** `lib/` (vendored OpenZeppelin and forge-std), `test/`, `script/`,
+`src/greenfield/*.sol` (reproduced ABIs of already-deployed BNB Greenfield
+contracts, included so this tree compiles against the real bridge), and
+`contracts/idl/pump/*` (third-party IDLs consumed read-only).
+
+## Where to spend your time
+
+Ranked by what a mistake would cost, not by line count:
+
+1. **`AgentPayments.buybackTrigger`** ([`src/AgentPayments.sol`](src/AgentPayments.sol)).
+ The only place in the set that makes an arbitrary external call with
+ caller-supplied calldata, while the contract holds every agent's revenue and
+ long-lived payer allowances. Controls are an owner gate, a router allow-list, a
+ token-address exclusion, a reentrancy guard, effects-before-interaction, a
+ measured balance delta, and a same-call allowance reset. Threat rows `F-AP-2`,
+ `F-AP-3`, `F-AP-9`.
+2. **`AgentPayments` conservation** (`AP-7`). One identity governs custody:
+ `paymentVault + buybackVault + withdrawVault + totalWithdrawn + totalBuybacks
+ == totalPayments`, per `(agentToken, currencyToken)`. Any path that breaks it is
+ a loss of funds.
+3. **`ThreeWSPayments`** is live and holds real USDC. Small, but the only contract
+ in the set where a finding is an incident rather than a bug.
+4. **`IdentityRegistry` delegation** (`ID-3`, `ID-7`, `ID-8`). Signature replay and
+ cross-agent balance isolation. Capturing a delegation is as valuable as
+ capturing funds, and quieter.
+5. **`skill_license` authority model** (`SL-1`, `SL-3`, `SL-5`). The marketplace
+ deliberately keeps freeze authority over every license so refunds can revoke.
+ Confirm that power cannot be reached by anyone but the minter.
+6. **`GreenfieldVault` async settlement** (`GV-2`, `GV-6`, `GV-9`). Money moves at
+ `buy()`, but the permission is minted later by a cross-chain ack. Every state
+ machine gap lives in that window.
+
+## Reproduce everything
+
+### Solidity
+
+Foundry, `solc 0.8.24`, optimizer on at 200 runs (see [`foundry.toml`](foundry.toml)).
+
+```bash
+cd contracts
+forge build
+forge test # 242 tests, all passing
+forge coverage --no-match-coverage "(script|test)" # 100% lines/statements/branches/functions
+```
+
+Coverage as of 2026-08-14, and the standard this set holds:
+
+| File | Lines | Statements | Branches | Functions |
+|---|---|---|---|---|
+| ThreeWSFactory.sol | 100% (6/6) | 100% (4/4) | 100% (2/2) | 100% (2/2) |
+| ThreeWSPayments.sol | 100% (27/27) | 100% (26/26) | 100% (5/5) | 100% (9/9) |
+| src/AgentPayments.sol | 100% (108/108) | 100% (149/149) | 100% (35/35) | 100% (14/14) |
+| src/GreenfieldVault.sol | 100% (84/84) | 100% (118/118) | 100% (31/31) | 100% (8/8) |
+| src/IdentityRegistry.sol | 100% (81/81) | 100% (94/94) | 100% (18/18) | 100% (20/20) |
+| src/ReputationRegistry.sol | 100% (57/57) | 100% (67/67) | 100% (16/16) | 100% (10/10) |
+| src/ValidationRegistry.sol | 100% (40/40) | 100% (43/43) | 100% (9/9) | 100% (10/10) |
+| src/WorldMoves.sol | 100% (18/18) | 100% (21/21) | 100% (3/3) | 100% (6/6) |
+| **Total** | **100% (421/421)** | **100% (522/522)** | **100% (119/119)** | **100% (79/79)** |
+
+### Solana
+
+The Anchor programs are tested against their **real compiled SBF bytecode** in
+[LiteSVM](https://github.com/LiteSVM/litesvm), with the real SPL Token and
+Associated Token Account programs loaded. Nothing is stubbed: a test failure means
+the program is wrong.
+
+```bash
+cd contracts/skill-license && cargo-build-sbf
+cd contracts/agent-invocation && cargo-build-sbf
+cd contracts/program-tests && cargo test # 32 tests, all passing
+```
+
+Line coverage is deliberately not quoted for these two. The unit under test is
+bytecode executing inside a VM, so a host-side line-coverage tool would measure
+the harness rather than the program. The coverage standard here is instruction and
+invariant coverage instead, which is stronger and directly checkable:
+
+| Program | Instructions | Instructions covered | Invariants | Positive + negative |
+|---|---|---|---|---|
+| `skill_license` | 5 (`initialize_marketplace`, `set_minter`, `mint_skill_license`, `burn_skill_license`, `revoke_skill_license`) | 5/5 | `SL-1` .. `SL-8` | every id |
+| `agent_invocation` | 1 (`invoke_skill`) | 1/1 | `AI-1` .. `AI-4` | every id |
+
+Seven of `skill_license`'s eight error variants are asserted by an
+individually-named test. The eighth, `NotLicenseOwner`, is defense in depth behind
+the PDA seed derivation: a stranger's derivation does not resolve to the victim's
+license account, so the seeds constraint rejects the transaction first. The
+stranger-burn test (`a_stranger_cannot_burn_someone_elses_license`) proves the
+outcome that matters.
+
+Harness details, including why the VM's clock must be set to a realistic value
+before either program behaves correctly, are in
+[`program-tests/README.md`](program-tests/README.md).
+
+### Static analysis
+
+```bash
+cd contracts && slither . --filter-paths "lib/|test/|script/" # 17 results, all dispositioned
+cd contracts/skill-license && cargo clippy --all-targets
+cd contracts/agent-invocation && cargo clippy --all-targets
+```
+
+Every result is dispositioned in writing in
+[`audit/static-analysis.md`](./audit/static-analysis.md), with raw output
+committed under [`audit/static-analysis/`](./audit/static-analysis).
+
+## How invariants are proven
+
+Every invariant has a stable id. The test that proves it names that id in a
+comment, so the proof is greppable:
+
+```bash
+grep -rn "AP-7" contracts/test # Solidity
+grep -rn "SL-3" contracts/program-tests # Solana
+```
+
+Every id is covered by at least one positive test (the property holds when it
+should) and at least one negative test (a caller trying to break it is rejected).
+That rule is the reason the negative half is called out explicitly in each test's
+doc comment.
+
+## Known issues and accepted risks
+
+These are already understood. If you find one of them, we agree; the value is in
+what you find beyond them.
+
+1. **`buybackTrigger` takes attacker-shaped input by construction.** Arbitrary
+ calldata to an external address is what makes the contract DEX-agnostic. The
+ residual risk after the allow-list and the token-address exclusion is execution
+ quality (slippage, MEV), bounded by the buyback vault balance at call time.
+2. **The skill-license marketplace keeps freeze authority** over every license mint,
+ permanently, so refunds can revoke without the holder's signature. Intended, and
+ asserted by `SL-3` rather than treated as a defect.
+3. **`revoked_at == 0` is the "not revoked" sentinel** in `skill_license`. Safe on a
+ real cluster (`Clock::unix_timestamp` is never 0) but it is a sentinel rather
+ than a discriminated option. Changing it is an account-layout migration.
+4. **Both Solana programs are upgradeable** by their deploy authority. Key custody
+ is documented in [`skill-license/DEPLOYMENT.md`](skill-license/DEPLOYMENT.md).
+5. **Nothing on EVM is upgradeable** (`X-1`). This removes proxy risk and adds
+ migration risk: a fix is a redeploy plus a migration.
+6. **Reputation sybil resistance is economic, not cryptographic.** The 0.001 ETH
+ stake floor sets a price, it does not prevent a funded fleet. The market layer
+ is expected to weight by stake size and staker history.
+7. **`IdentityRegistry` has no admin recovery.** An owner who loses their key loses
+ the agent, deliberately.
+8. **`agent_invocation` events are a claim by the invoker**, not a receipt: the
+ target does not sign. Settlement lives on the payments rail, not this log.
+9. **The three registries this repo ships as reference implementations are not the
+ bytecode live at `0x8004...` on most chains.** Consumers bind by address to
+ whichever registry is canonical per chain. Read `DEPLOYMENTS.md` before assuming
+ a source file corresponds to a live contract.
+
+## Reporting
+
+Send findings with a severity, a concrete failure scenario (inputs, ordering, and
+the resulting wrong state), and the invariant id the finding breaks if one applies.
+A finding that breaks a stated invariant is unambiguous by construction, which is
+most of why the invariants are written down. Security contact and disclosure
+process: [`.github/SECURITY.md`](../.github/SECURITY.md), or email [email protected].
+
+## Repository map
+
+```
+contracts/
+ AUDIT-README.md this file
+ DEPLOYMENTS.md addresses, chains, provenance
+ AGENT_PAYMENTS.md AgentPayments deploy + wiring guide
+ foundry.toml solc 0.8.24, optimizer 200 runs
+ src/*.sol the EVM economy set
+ src/greenfield/*.sol reproduced ABIs of live BNB Greenfield contracts
+ test/*.t.sol Solidity invariant tests
+ skill-license/ Anchor program: skill licenses (Solana royalty half)
+ agent-invocation/ Anchor program: invocation events
+ program-tests/ LiteSVM invariant tests for both Anchor programs
+ audit/ static-analysis output and dispositions
+ idl/ generated IDLs consumed by the backend and SDKs
+ script/ Foundry deploy scripts
+ vanity/ CREATE2 salt records for the vanity addresses
+```
diff --git a/contracts/audit/static-analysis.md b/contracts/audit/static-analysis.md
new file mode 100644
index 000000000..03e1401c8
--- /dev/null
+++ b/contracts/audit/static-analysis.md
@@ -0,0 +1,73 @@
+# Static analysis: findings and dispositions
+
+Every finding the analyzers report against this repo's contract sources, with a
+written disposition. Raw tool output is committed next to this file in
+[`static-analysis/`](./static-analysis) so a reviewer can diff their own run
+against ours rather than take this table on trust.
+
+Nothing here is suppressed with an inline pragma or a filter file. The counts
+below are the analyzers' full output for the source tree, minus vendored
+dependencies and the test/script trees (which are not deployed).
+
+## Tools and versions
+
+| Target | Tool | Version | Command |
+|---|---|---|---|
+| Solidity | [Slither](https://github.com/crytic/slither) | 0.11.6 | `cd contracts && slither . --filter-paths "lib/\|test/\|script/"` |
+| Rust (Solana) | Clippy | shipped with the pinned Rust toolchain | `cd contracts/<program> && cargo clippy --all-targets` |
+
+Add `--json audit/static-analysis/slither.json` to the Slither command for the
+machine-readable form. The JSON is regenerated on demand rather than committed,
+because it is half a megabyte of mostly source positions.
+
+## Slither
+
+Run of 2026-08-14 against `contracts/src/**` plus the two root `.sol` files:
+44 contracts, 102 detectors, **17 results across 7 detectors**. Full output:
+[`static-analysis/slither-report.txt`](./static-analysis/slither-report.txt).
+
+Three results were **fixed** in the same change that produced this document,
+taking the count from 20 to 17. The remaining 17 are dispositioned below.
+
+### Fixed
+
+| Detector | Where | Fix |
+|---|---|---|
+| `unused-return` (2 results) | `GreenfieldVault.buy`, `GreenfieldVault.revoke` | The real PermissionHub can decline a request by returning `false` instead of reverting. Both call sites ignored the return value, so a declined `createPolicy` would have credited the seller and burned the buyer's relay fee for a permission that was never going to be minted, and a declined `deletePolicy` would have marked a sale Revoked while the buyer kept a live grant. Both now revert with `PolicyRequestRejected`. This is a new invariant, `GV-9`, with tests on both sides. |
+| `solc-version` (1 result) | `src/greenfield/*.sol` | The four vendored Greenfield interfaces carried `pragma solidity ^0.8.0`, which admits compiler versions with known severe bugs. Pinned to `^0.8.24`, matching every other file in the tree and the `solc_version` in `foundry.toml`. |
+
+### Dispositioned
+
+| Detector | Results | Impact/Confidence | Disposition |
+|---|---|---|---|
+| `reentrancy-eth` | 1 | High/Medium | `AgentPayments.buybackTrigger`. The flagged write is `acct.tokensBurned += bought` after the swap. It is unavoidable: the amount bought is not knowable until the router returns. It is also not part of the conservation identity (`AP-7`) that governs custody, only a cumulative statistic. Every write that *is* knowable up front (`buybackVault = 0`, `totalBuybacks += spend`) already happens before the external call, the function is `onlyOwner` and `nonReentrant`, and the router must be allow-listed and must not be the currency or agent token. The cross-function reentrancy Slither pairs it with is `distributePayments`, which only moves value between vaults and therefore preserves `AP-7` whenever it runs. Accepted. |
+| `reentrancy-balance` | 2 | High/Medium | Same function. Slither flags `agentBefore` as a balance read that spans the external call. That is the point: the contract deliberately measures the delta across the swap rather than trusting a router-reported amount, exactly as `AP-5` does for fee-on-transfer payments. A stale read is impossible because both reads are of `address(this)` in the same call frame. Accepted. |
+| `incorrect-equality` | 2 | Medium/High | `received == 0` in `_settle` and `bought == 0` in `buybackTrigger`. Neither is an equality test against a balance; both are "did this transfer or swap deliver anything at all" guards that revert on zero. There is no strict-equality dependence on an attacker-controllable amount. Accepted. |
+| `timestamp` | 2 | Low/Medium | Invoice windows in `AgentPayments._settle` and the EIP-712 deadline in `IdentityRegistry.setAgentWallet`. Both are coarse deadlines measured in minutes or longer, where validator timestamp drift of a few seconds is immaterial. No value is priced off `block.timestamp`. Accepted. |
+| `low-level-calls` | 8 | Informational/High | Seven are `recipient.call{value: ...}("")` for native transfers, which is the correct pattern (`transfer`'s 2300-gas stipend breaks smart-account recipients). Every one checks the returned success flag and reverts on failure. The eighth is the router call in `buybackTrigger`, which must be a raw call because the calldata is DEX-specific. Accepted. |
+| `missing-inheritance` | 1 | Informational/High | Slither suggests `IdentityRegistry` should inherit `IIdentityRegistry`. It deliberately does not. On most chains the canonical registry is the ERC-8004 reference deployment at `0x8004A1...`, not this repo's bytecode (see `DEPLOYMENTS.md`), so the consumers bind to an *address* and must keep working against a registry this repo did not compile. Inheriting would also force an `ownerOf` override disambiguating `ERC721`, `IERC721` and the new interface, adding bytecode for no safety. The duplication Slither was really seeing (two identical interface declarations, one per consumer) was removed in this change: both now import the single [`src/IIdentityRegistry.sol`](../src/IIdentityRegistry.sol). Accepted. |
+| `naming-convention` | 1 | Informational/High | `IdentityRegistry.DOMAIN_SEPARATOR()`. The name is fixed by EIP-2612 and EIP-712 tooling convention; renaming it to mixedCase would break every wallet and library that looks it up. Accepted. |
+
+## Clippy
+
+Both Solana programs, `--all-targets`. Output:
+[`static-analysis/clippy-skill-license.txt`](./static-analysis/clippy-skill-license.txt),
+[`static-analysis/clippy-agent-invocation.txt`](./static-analysis/clippy-agent-invocation.txt).
+
+| Program | Warnings | Disposition |
+|---|---|---|
+| `skill-license` | 17 (5 duplicates) | Every warning resolves to a line inside an Anchor macro expansion, not to program source: `unexpected cfg condition value` for `custom-heap`, `custom-panic`, `solana` and `anchor-debug` (feature flags Anchor's own codegen tests for), and one `use of deprecated method AccountInfo::realloc` emitted by the `#[program]` attribute macro. All are attributable to `anchor-lang 0.31.1` and are fixed upstream by an Anchor bump, not by a change here. Zero warnings originate in `src/lib.rs` outside macro expansion. |
+| `agent-invocation` | 13 (7 duplicates) | Identical set, same origin, same disposition. |
+
+A reviewer can confirm the attribution by re-running with
+`cargo clippy --all-targets -- -Z macro-backtrace` on a nightly toolchain: every
+warning's backtrace terminates in `anchor_lang`'s `#[program]` or
+`#[derive(Accounts)]`.
+
+## What static analysis does not cover
+
+Slither and Clippy find shapes, not intent. The properties that actually protect
+funds here are stated as invariants in
+[`specs/ECONOMY_CONTRACT_INVARIANTS.md`](../../specs/ECONOMY_CONTRACT_INVARIANTS.md)
+and proven by the test suites described in
+[`AUDIT-README.md`](../AUDIT-README.md). Neither tool checks any of them.
diff --git a/specs/ECONOMY_CONTRACT_THREAT_MODEL.md b/specs/ECONOMY_CONTRACT_THREAT_MODEL.md
new file mode 100644
index 000000000..83aa4b827
--- /dev/null
+++ b/specs/ECONOMY_CONTRACT_THREAT_MODEL.md
@@ -0,0 +1,287 @@
+# Economy Contract Threat Model v1
+
+The attacker's-eye companion to [`ECONOMY_CONTRACT_INVARIANTS.md`](./ECONOMY_CONTRACT_INVARIANTS.md).
+That document states what must always be true; this one states what is worth
+stealing, who could try, and how each attempt is stopped. An auditor reads this
+first to decide where to spend their time, then reads the invariants to see what
+the code claims, then reads the tests to see what is proven.
+
+Entry point for a review engagement: [`contracts/AUDIT-README.md`](../contracts/AUDIT-README.md).
+
+Related: [`SECURITY.md`](./SECURITY.md) covers abuse of agent *registration*, which
+sits upstream of these contracts. [`VALIDATORS.md`](./VALIDATORS.md) covers who may
+write attestations. This file covers the contracts themselves.
+
+## How to read a failure mode
+
+Every failure mode has a stable id (`F-REP-2`, `F-AP-5`, ...) that is permanent
+and never reused. Each row names the attacker's goal, the control that stops it,
+and the invariant id whose test proves the control holds. A row with no invariant
+id is a risk that is accepted or handled operationally rather than in code, and it
+says so explicitly.
+
+Severity is the impact if the control failed, not the likelihood that it will:
+
+| Severity | Meaning |
+|---|---|
+| Critical | Direct theft, or permanent loss, of user or protocol funds. |
+| High | Loss of an economic right (a paid license, an agent's earnings authority) or forged economic state that money keys on. |
+| Medium | Denial of service against a paying user, or corruption of state an indexer or a verifier trusts. |
+| Low | Griefing, noise, or gas waste with no economic effect. |
+
+---
+
+## Global model
+
+### Trust boundaries
+
+1. **Anonymous internet → contract.** Anyone can call any external function with
+ any arguments, in any order, from a contract or an EOA, and can reenter during
+ any payout. Nothing about a caller is assumed.
+2. **Platform-operated key → contract.** Four privileged roles exist across the
+ set (below). Each is a real key held by three.ws, and each is modeled as
+ *compromisable*: the question for every role is not "will it behave" but "what
+ is the blast radius if it does not".
+3. **Contract → third-party contract.** `AgentPayments` calls a DEX router,
+ `GreenfieldVault` calls BNB Greenfield's PermissionHub and CrossChain, the
+ reputation and validation registries call the Identity Registry, and
+ `skill_license` CPIs into SPL Token. Each counterparty is untrusted code that
+ can revert, lie in a return value, or reenter.
+4. **Chain → off-chain reader.** The platform's servers, indexers, and SDKs key
+ real behavior (settlement, access grants, reputation display) on events and
+ account state. A contract that emits a false event is therefore an attack on
+ the off-chain system even when no on-chain value moves.
+
+### Privileged roles
+
+| Role | Where | Powers | Blast radius if the key is stolen |
+|---|---|---|---|
+| Protocol owner | `AgentPayments.owner` | Register agent tokens, allow-list swap routers, trigger buybacks. | Can spend a buyback vault through an allow-listed router at a bad price. Cannot touch `withdrawVault` (agent-owned) or `paymentVault` before distribution, cannot change an agent's authority, cannot mint. Held by the platform multisig. |
+| Agent authority | `AgentPayments._agents[token].authority` | Withdraw that agent's earnings, change its buyback split, hand the role on. | Loses one agent's accrued earnings. Isolated per agent token: no cross-agent reach. |
+| Registry owner | `ValidationRegistry.owner`, `ThreeWSPayments.owner` | Add/remove validators; set the pay-per-call price and withdraw USDC. | Forged attestations (no funds), or price manipulation plus theft of undrawn USDC receipts on the x402 receiver. |
+| Marketplace minter | `skill_license.marketplace.minter` | Mint and revoke skill licenses. | Can issue unpaid licenses and revoke paid ones. Rotatable by the admin authority without redeploying, which is exactly why `set_minter` exists. |
+| Marketplace admin | `skill_license.marketplace.authority` | Rotate the minter. | Can install a hostile minter. This is the root key of the Solana royalty half; it is the one key whose loss cannot be recovered from in-contract. |
+
+None of these roles can upgrade a contract: nothing in the EVM set is upgradeable
+or proxied (`X-1`). The Solana programs are upgradeable by their deploy authority,
+which is the standard Solana posture and is called out as an accepted risk below.
+
+### Assets
+
+| Asset | Where it lives | Worst case |
+|---|---|---|
+| Agent earnings (ERC-20 and native) | `AgentPayments` vaults | Theft or permanent lock of an agent's revenue. |
+| Buyback capital | `AgentPayments.buybackVault` | Drained through a hostile "router". |
+| x402 receipts (USDC) | `ThreeWSPayments` | Theft of settled pay-per-call revenue. |
+| Agent deposits (native) | `IdentityRegistry.agentBalance` | Theft of an agent's operating balance by a delegated spender. |
+| Reputation stakes (native) | `ReputationRegistry.stakeOf` | Theft of another staker's refundable stake. |
+| Sale proceeds (native) | `GreenfieldVault.pendingWithdrawals` | Theft of a seller's unclaimed proceeds. |
+| The delegation itself | `IdentityRegistry` agent wallet + spend allowance | Silent capture of the right to act as an agent. |
+| A paid skill license | `skill_license` PDA + 1/1 NFT | Free access, or destruction of purchased access. |
+| Reputation and attestation records | `ReputationRegistry`, `ValidationRegistry` | Forged trust signals that the marketplace prices against. |
+
+---
+
+## IdentityRegistry: the delegation contract
+
+[`contracts/src/IdentityRegistry.sol`](../contracts/src/IdentityRegistry.sol).
+Decides who may act, and spend, as an agent. Everything downstream that asks
+"is this caller the agent" resolves here.
+
+**Actors:** the agent NFT owner, a delegated agent wallet, an authorized spender,
+an NFT marketplace holding the token in escrow, and the anonymous internet.
+
+| Id | Failure mode | Severity | Control | Proven by |
+|---|---|---|---|---|
+| F-ID-1 | An attacker replays a captured `setAgentWallet` signature to re-bind the agent's wallet to themselves after the owner rotated it back. | High | Per-owner nonce consumed on every accepted signature, plus a deadline. | `ID-3` |
+| F-ID-2 | An attacker gets a signature signed by a *previous* owner accepted after the NFT changed hands. | High | The signature is checked against the current `ownerOf`, not against the signer of record. | `ID-3` |
+| F-ID-3 | A buyer of the agent NFT finds the seller still holds spend rights. | High | Every owner-gated right reads `ownerOf` live, so the transfer moves them atomically. | `ID-2` |
+| F-ID-4 | A spender authorized on a cheap agent drains a valuable agent's balance. | Critical | Balances and allowances are keyed per agent id; `spend` debits both. | `ID-7`, `ID-8` |
+| F-ID-5 | A malicious recipient reenters during a payout and withdraws the same balance twice. | Critical | Checks-effects-interactions plus a reentrancy guard on both payout paths. | `ID-9`, `ID-10` |
+| F-ID-6 | ETH arrives with no owning agent and is stranded forever. | Medium | `receive` and `fallback` both revert; deposits only through `deposit(agentId)`. | `ID-5`, `ID-6` |
+| F-ID-7 | A mistyped withdrawal burns an agent's balance to the zero address. | Medium | Zero recipient rejected. | `ID-11` |
+| F-ID-8 | A contract owner (smart-account agent) cannot sign, so its wallet can never be bound. | Low | Signature verification goes through `SignatureChecker`, so ERC-1271 owners work. | `ID-3` |
+
+**Accepted:** the agent NFT is the root of authority, so an owner who loses their
+key loses the agent. There is deliberately no admin recovery path, because an
+admin able to reassign agents would be a larger risk than the one it removes.
+
+## ReputationRegistry: the reputation contract
+
+[`contracts/src/ReputationRegistry.sol`](../contracts/src/ReputationRegistry.sol).
+Holds refundable stakes and the aggregate score the marketplace prices against.
+
+**Actors:** reviewers (staking and non-staking), the agent's own owner, sybil
+fleets, and the anonymous internet.
+
+| Id | Failure mode | Severity | Control | Proven by |
+|---|---|---|---|---|
+| F-REP-1 | One address inflates an agent by reviewing it repeatedly, or by using the non-staking entry point after the staking one. | Medium | A single `hasReviewed` flag gates both entry points. | `REP-1` |
+| F-REP-2 | An agent owner reviews their own agent. | Medium | The owner is rejected on both entry points, read live from the Identity Registry. | `REP-3` |
+| F-REP-3 | A reviewer withdraws their stake and keeps the score, renting reputation for free. | Medium | Withdrawal refunds the stake but never retracts the review, so the review's cost is the capital lockup the reviewer chose to end. | `REP-8` |
+| F-REP-4 | A staker withdraws more than they staked, or twice, taking another staker's capital. | Critical | The refund pays exactly `stakeOf[agent][sender]` and zeroes it first. | `REP-6`, `REP-7` |
+| F-REP-5 | A contract staker reenters `withdrawStake` during its refund. | Critical | Reentrancy guard plus effects-before-interaction. | `REP-10` |
+| F-REP-6 | Scores are written against an agent id that does not exist, poisoning an indexer. | Low | Existence is checked against the Identity Registry. | `REP-4` |
+| F-REP-7 | An out-of-range score skews the aggregate. | Medium | Range enforced per entry point (`[-100,100]` and `[1,5]`). | `REP-2` |
+| F-REP-8 | Dust stakes make a sybil fleet cheap. | Medium | A 0.001 ETH floor per stake. | `REP-9` |
+
+**Accepted:** sybil resistance here is economic, not cryptographic. A funded
+attacker with many addresses can buy score, and the stake floor only sets the
+price. The market layer that reads this registry is expected to weight by stake
+size and staker history rather than by raw count. See
+[`REPUTATION_STAKING_MARKET.md`](./REPUTATION_STAKING_MARKET.md).
+
+## AgentPayments: the royalty contract (EVM)
+
+[`contracts/src/AgentPayments.sol`](../contracts/src/AgentPayments.sol).
+The highest-value contract in the set: it holds every agent's revenue and the
+buyback capital, and it makes an arbitrary external call by design.
+
+**Actors:** payers, the agent authority, the protocol owner, DEX routers,
+fee-on-transfer and rebasing tokens, and MEV searchers watching the buyback.
+
+| Id | Failure mode | Severity | Control | Proven by |
+|---|---|---|---|---|
+| F-AP-1 | A third party front-runs registration of an agent token and installs their own authority. | High | Registration is restricted to the protocol owner or to the authority registering itself, and is one-shot. | `AP-1` |
+| F-AP-2 | The protocol owner points the "router" at the currency token itself and drains the maxUint256 allowances payers grant. | Critical | The router must be allow-listed, and is explicitly rejected when equal to the currency or agent token. | `AP-9` |
+| F-AP-3 | A standing router allowance survives a buyback and is spent later. | Critical | The approval is set and reset to zero inside the same call. | `AP-10` |
+| F-AP-4 | A fee-on-transfer currency credits more than it delivered, so the vaults promise money the contract does not hold. | Critical | Credit is the measured balance delta, never the requested amount. | `AP-5` |
+| F-AP-5 | A payer replays a settled invoice, or the SDK and the contract disagree on an invoice id. | High | Ids are a pure function of the invoice fields and are single-use on-chain. | `AP-3` |
+| F-AP-6 | A payment lands outside its window and is still credited. | Medium | Both bounds enforced, with `0` meaning unbounded. | `AP-4` |
+| F-AP-7 | Rounding in the split strands dust, or credits it twice. | Medium | The split drains the payment vault to zero and gives the exact remainder to the withdraw vault. | `AP-7`, `AP-8` |
+| F-AP-8 | Native accounting is reached through the ERC-20 path (or the reverse), double-counting a balance. | High | The native sentinel and the zero address are rejected as ERC-20 currencies. | `AP-6` |
+| F-AP-9 | A malicious router or receiver reenters to spend a vault twice. | Critical | Reentrancy guards on every value-moving path, effects written before the external call. | `AP-13` |
+| F-AP-10 | An agent becomes unmanageable because its authority is set to the zero address. | High | Authority transfer rejects zero and is restricted to the current authority. | `AP-12` |
+| F-AP-11 | A searcher sandwiches the buyback swap and the protocol burns fewer tokens than the market price implies. | Medium | Not a contract control: the swap calldata is built off-chain with slippage limits, and the call reverts if it returns nothing. Operational, see accepted risks. | `AP-9` |
+
+**Accepted:** `buybackTrigger` takes attacker-shaped input (arbitrary calldata to
+an external address) by construction, because the contract must work with any DEX.
+The mitigations are the allow-list, the token-address exclusion, the owner gate,
+and the burn-everything-bought rule. The residual risk is execution quality
+(slippage, MEV) rather than custody, and it is bounded by the buyback vault
+balance at call time. A firm should spend a disproportionate share of its time
+here.
+
+## skill_license: the royalty contract (Solana)
+
+[`contracts/skill-license/src/lib.rs`](../contracts/skill-license/src/lib.rs).
+What a paid skill purchase actually buys, and what a refund takes back.
+
+**Actors:** the license holder, the backend minter, the marketplace admin, and
+anyone who can craft a transaction.
+
+| Id | Failure mode | Severity | Control | Proven by |
+|---|---|---|---|---|
+| F-SL-1 | A user self-mints a license without paying. | High | Minting requires the minter's signature; the marketplace admin cannot mint either. | `SL-1` |
+| F-SL-2 | The same purchase mints two licenses, or two purchases collide onto one. | High | Every address is a PDA of `(owner, agent_mint, sha256(skill_name))`; a duplicate `init` fails. | `SL-2`, `SL-8` |
+| F-SL-3 | The 1/1 access key is inflated after issue. | High | The mint authority is removed in the same instruction that mints the single token. | `SL-3` |
+| F-SL-4 | A refunded holder keeps working access, or a revoked license is silently deleted so verifiers cannot see the revocation. | High | Revocation freezes the holder's token account and stamps `revoked_at` while keeping the record readable. | `SL-5` |
+| F-SL-5 | A revocation is replayed to overwrite the original timestamp. | Medium | A license with a non-zero `revoked_at` cannot be revoked again. | `SL-5` |
+| F-SL-6 | A stranger burns someone else's license, destroying paid access and taking its rent. | High | The license PDA is derived from the signer, so a stranger's derivation does not resolve to the victim's account. | `SL-6` |
+| F-SL-7 | A burn is pointed at a different license's NFT mint. | Medium | The mint must equal the one recorded on the license. | `SL-6` |
+| F-SL-8 | The lifetime counter wraps and corrupts marketplace accounting. | Low | Checked addition; the instruction fails closed at the boundary. | `SL-7` |
+| F-SL-9 | A hostile minter mints unpaid licenses at scale. | High | Not prevented in-contract by design: it is contained by rotating the minter (`set_minter`) and by the fact that the minter cannot rotate itself. | `SL-1` |
+
+**Accepted, and worth an auditor's attention:**
+
+- **The marketplace deliberately keeps freeze authority** on every license mint so
+ a refund can revoke without the holder's cooperation. This is a real power over
+ a user's asset and it is the intended design, not an oversight. It is why
+ `SL-3` asserts the freeze authority is retained rather than removed.
+- **`revoked_at == 0` is the "live" sentinel.** The value comes from
+ `Clock::unix_timestamp`, which is never 0 on a real cluster, so the guard holds
+ in production. It is nonetheless a sentinel rather than a discriminated
+ `Option`, and the invariant test suite has to set a realistic clock for the
+ program to behave correctly, which is exactly the shape of assumption an audit
+ should record. Hardening it to an `Option<i64>` is an account-layout change and
+ therefore a migration, not a patch.
+- **Program upgradeability.** Both Solana programs are upgradeable by their deploy
+ authority. Key custody is documented in
+ [`contracts/skill-license/DEPLOYMENT.md`](../contracts/skill-license/DEPLOYMENT.md).
+
+## agent_invocation
+
+[`contracts/agent-invocation/src/lib.rs`](../contracts/agent-invocation/src/lib.rs).
+Records agent-to-agent invocations as events. It moves no funds, so its threat
+surface is entirely about what an indexer will believe.
+
+| Id | Failure mode | Severity | Control | Proven by |
+|---|---|---|---|---|
+| F-AI-1 | An attacker emits invocations attributed to an agent they do not control, inflating that agent's apparent usage. | Medium | The invoker must sign, and the invoker agent must be the PDA derived from that signer. | `AI-1` |
+| F-AI-2 | An arbitrary account is presented as the target, so an indexer records traffic to an agent that does not exist. | Medium | The target must be the PDA derived from the presented target authority. | `AI-2` |
+| F-AI-3 | Unbounded strings make the event expensive to emit or to index. | Low | Both fields are length-bounded before the event is emitted. | `AI-3` |
+| F-AI-4 | A bug here causes a loss of funds. | Low | The program has no value-moving instruction and creates no account. | `AI-4` |
+
+**Accepted:** the target agent does not sign, so an invocation event does not
+prove the target consented or performed work. Consumers must treat it as a claim
+by the invoker, not as a receipt. This is intentional: the program is a public
+log, and the settlement layer for real work is the payments rail, not this event.
+
+## GreenfieldVault
+
+[`contracts/src/GreenfieldVault.sol`](../contracts/src/GreenfieldVault.sol).
+Pay-to-unlock over a genuinely asynchronous cross-chain grant, which is where its
+interesting failure modes live.
+
+| Id | Failure mode | Severity | Control | Proven by |
+|---|---|---|---|---|
+| F-GV-1 | A seller lists an object they do not control and takes payment for access they cannot grant. | High | Listing requires a live `ROLE_CREATE` grant checked against the real ObjectHub. | `GV-1` |
+| F-GV-2 | A buyer pays and the hub silently declines the request, so the seller is credited for a grant that never happens. | High | A declined hub call (a `false` return, not a revert) reverts the whole purchase. | `GV-9` |
+| F-GV-3 | A seller whose address rejects ETH blocks every purchase of their object. | Medium | Proceeds are credited pull-style; nothing is pushed during `buy`. | `GV-4` |
+| F-GV-4 | The relay fee is stale or caller-supplied, so the cross-chain call underpays and the buyer loses the payment. | High | The fee is quoted live from the real CrossChain oracle at call time. | `GV-3` |
+| F-GV-5 | A failed settlement leaves the pair permanently unable to transact. | Medium | The purchase guard clears on failure and on revoke. | `GV-2` |
+| F-GV-6 | A forged ack marks a sale Granted with an attacker-chosen policy id. | High | Acks are accepted only from the real PermissionHub, and only on the permission channel. | `GV-6` |
+| F-GV-7 | A refund callback reenters `buy` or `withdraw`. | Critical | Reentrancy guards, including against cross-function reentrancy. | `GV-8` |
+
+**Accepted:** a buyer's practical access depends on BNB Greenfield honoring the
+policy, which is outside this contract. The vault proves the payment-to-permission
+link on-chain and surfaces the pending state honestly rather than pretending the
+async grant is synchronous.
+
+## ThreeWSPayments and ThreeWSFactory (live bytecode)
+
+Both are deployed on BNB Smart Chain, Base, and Arbitrum One, so a violation here
+is an incident rather than a bug. Addresses in
+[`contracts/DEPLOYMENTS.md`](../contracts/DEPLOYMENTS.md).
+
+| Id | Failure mode | Severity | Control | Proven by |
+|---|---|---|---|---|
+| F-TWP-1 | A token that returns false without reverting produces a receipt event, so the server settles a call that was never paid for. | Critical | The transfer's success is checked before the event is emitted. | `TWP-1` |
+| F-TWP-2 | A caller chooses their own price. | High | The amount is always the stored `pricePerCall`. | `TWP-2` |
+| F-TWP-3 | Ownership is renounced to the zero address, stranding the USDC balance. | High | Zero rejected on transfer and in the constructor. | `TWP-3`, `TWP-5` |
+| F-TWP-4 | Native currency accumulates with no way to withdraw it. | Low | No payable function, no fallback. | `TWP-6` |
+| F-TWF-1 | A failed CREATE2 deployment is reported as a success and the platform trusts an empty address. | High | A zero return reverts. | `TWF-1` |
+| F-TWF-2 | An existing deployment is silently replaced at a predicted address. | High | CREATE2 returns zero for an occupied address, which reverts. | `TWF-3` |
+
+## WorldMoves and ValidationRegistry
+
+Neither holds value. `WorldMoves` is an event-only move stream whose risk is
+indexer-facing (`WM-1` .. `WM-4`), and it has no owner, admin, pause, or upgrade
+path at all. `ValidationRegistry` gates who may write attestations (`VR-1` ..
+`VR-6`); its worst case is a forged attestation, and its allow-list policy is
+[`VALIDATORS.md`](./VALIDATORS.md). The one structural risk in either is that
+`ValidationRegistry` ownership could be transferred to an address that cannot act,
+freezing the allow-list, which is why the zero address is rejected (`VR-2`).
+
+---
+
+## Cross-cutting assumptions an audit should challenge
+
+1. **Solidity 0.8 checked arithmetic** is relied on for overflow safety; `unchecked`
+ appears only where an adjacent check proves the bound (`X-5`).
+2. **No upgradeability on EVM** (`X-1`). A fix means a new deployment and a
+ migration. This removes proxy risk and adds migration risk.
+3. **Authority is never taken from a caller** (`X-3`), and prices and fees are never
+ taken from a caller (`X-4`).
+4. **Every value-moving path has both** checks-effects-interactions and an explicit
+ guard (`X-2`), rather than relying on either alone.
+5. **Key custody is out of scope for the code review but in scope for the system.**
+ The protocol owner, the marketplace admin, and the Solana upgrade authority are
+ the three keys whose compromise is not recoverable in-contract.
+
+## Change control
+
+A new external function, a new privileged role, or a new external counterparty
+means a new row here and a new invariant in
+[`ECONOMY_CONTRACT_INVARIANTS.md`](./ECONOMY_CONTRACT_INVARIANTS.md), in the same
+change as the code.