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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
docs(contracts): point every entry surface at the new audit pack and the LiteSVM proofs
nirholasbde0e70b607a
diff --git a/STRUCTURE.md b/STRUCTURE.mdindex bb4063d5c..7fe2675f8 100644--- a/STRUCTURE.md+++ b/STRUCTURE.md@@ -144,6 +144,8 @@ bottom.| Production server (Google Cloud Run) | [server/](server) + [Dockerfile](Dockerfile) | Live | Single Express container serving the static frontend, the vercel.json route table, and all `api/**` handlers with Vercel-parity routing; deploy via `npm run deploy:gcp` ([server/cloudbuild.yaml](server/cloudbuild.yaml)), crons via [scripts/create-gcp-scheduler.mjs](scripts/create-gcp-scheduler.mjs) · see [server/README.md](server/README.md) || Multiplayer 3D world (world.three.ws) | [deploy/world/](deploy/world) — [Dockerfile](deploy/world/Dockerfile), [cloudrun.yaml](deploy/world/cloudrun.yaml), [apply-hardening.sh](deploy/world/apply-hardening.sh), patches in [deploy/world/patches/](deploy/world/patches); health monitor [api/cron/world-health.js](api/cron/world-health.js) | Live · `hyperfy-world` on Cloud Run | [Hyperfy](https://github.com/hyperfy-xyz/hyperfy) pinned to an exact upstream commit and rebuilt with three local patches (server-side upload cap, `/status` blueprint-asset enumeration, fail-closed-without-`ADMIN_CODE`). World state (SQLite + uploaded assets) lives in the GCS bucket `world-three-ws-data` mounted at `/app/world`, so the container is stateless. **The world is gated:** without `ADMIN_CODE` Hyperfy's `effectiveRank` falls back to `Ranks.ADMIN` and every anonymous visitor gets server-side build rights — the fail-open default that emptied the world on 2026-06-12. Deploy + verify with `bash deploy/world/apply-hardening.sh`; builders unlock in-world with `/admin <code>`. See [deploy/world/README.md](deploy/world/README.md) || On-chain identity | [contracts/](contracts) | In-repo | Foundry-based on-chain agent identity, ERC-8004 |+| Contract audit pack | [contracts/AUDIT-README.md](contracts/AUDIT-README.md), invariants [specs/ECONOMY_CONTRACT_INVARIANTS.md](specs/ECONOMY_CONTRACT_INVARIANTS.md), threat model [specs/ECONOMY_CONTRACT_THREAT_MODEL.md](specs/ECONOMY_CONTRACT_THREAT_MODEL.md), static analysis [contracts/audit/](contracts/audit) | In-repo | Everything a review firm needs on day one for the reputation, royalty and delegation contracts: scope + deploy status per contract, stable invariant ids with a positive and a negative test each, an assets/actors/failure-modes threat model, and committed Slither + Clippy output with every finding fixed or dispositioned in writing |+| Solana program invariant tests | [contracts/program-tests/](contracts/program-tests) | In-repo | LiteSVM suite running the real compiled SBF bytecode of `skill_license` and `agent_invocation` against invariants `SL-*` and `AI-*`, with the real SPL Token and ATA programs loaded || Reputation Staking Market | spec [specs/REPUTATION_STAKING_MARKET.md](specs/REPUTATION_STAKING_MARKET.md), engine [src/shared/reputation-staking.js](src/shared/reputation-staking.js), server [api/_lib/reputation-market.js](api/_lib/reputation-market.js) + [api/reputation/market*.js](api/reputation), surface [public/reputation/market/](public/reputation/market) `→ /reputation/market` | In-repo · devnet open, mainnet owner-gated | Phase 3 roadmap: stake conviction on an agent and earn from its attested action history. A stake is a staker-signed Solana transfer to the market escrow carrying an `rsm.v1` SPL-Memo, so the chain (not the database) defines a position; the server only verifies it by reading the transaction back. Yield comes from a fixed per-epoch pool split by `principal × time × agentWeight`, where the weight is derived purely from the agent's signed `threews.*` attestations (work concave in `log2`, faults charged double), so conviction never pays itself. Principal is never slashed and settlement clamps earnings to the escrow surplus. Extends the SPL-Memo attestation layer in [docs/solana-reputation.md](docs/solana-reputation.md). Storage: [reputation_staking_market migration](api/_lib/migrations/20260811140000_reputation_staking_market.sql). Walkthrough: [docs/reputation-staking-market.md](docs/reputation-staking-market.md). Devnet proof: `node scripts/reputation-market-proof.mjs`. Tests: [tests/reputation-staking.test.js](tests/reputation-staking.test.js) || On-chain skill licenses | [contracts/skill-license/](contracts/skill-license) `→ /api/skills/license-onchain` | In-repo | Anchor program: each purchased skill = a 1/1 SPL NFT + `SkillLicense` PDA, a trustless alternative to DB-backed access checks. Backend: [api/_lib/skill-license-onchain.js](api/_lib/skill-license-onchain.js) || Tokenized 3D (mint an avatar as an NFT) | [api/_lib/tokenize-3d.js](api/_lib/tokenize-3d.js) + [api/_lib/tokenize-3d-metadata.js](api/_lib/tokenize-3d-metadata.js), MCP tools [api/_mcp/tools/tokenize.js](api/_mcp/tools/tokenize.js) (`mint_3d_asset`, `get_3d_asset_onchain`), signed ledger provenance [api/_lib/asset-provenance.js](api/_lib/asset-provenance.js), launch directory [api/v1/tokenized/launches.js](api/v1/tokenized/launches.js) `→ GET /api/v1/tokenized/launches`, public gallery [pages/minted.html](pages/minted.html) + [src/minted.js](src/minted.js) `→ /minted` | In-repo | Mint a generated/owned GLB as a Metaplex Core NFT whose media is a live 3D viewer (GLB under `animation_url`), with baked provenance + enforced capped royalties (10%), idempotent, devnet-default. Every generated avatar AND every mint also appends an ERC-191-signed record to the `agent_actions` ledger (verifiable via `@three-ws/provenance-mcp`'s `query_action`). A mint naming `parent_mint` (a remix) routes the parent creator's royalty out of the mint fee as a real on-chain USDC transfer (mainnet, x402-collected calls only) — [api/_lib/remix-royalty.js](api/_lib/remix-royalty.js) split math, [api/_lib/remix-settlement.js](api/_lib/remix-settlement.js) payout wallet. Premium/token-gated generation: the Forge High tier (200k poly + PBR) is $THREE hold-or-pay gated — [api/forge.js](api/forge.js) `requireFeatureAccess('forge.high')` + [api/_lib/three-tier.js](api/_lib/three-tier.js) tier ladder, x402 pay-per-use or credits fallback; Draft/Standard stay free and ungated. Launch record: [tokenized_3d_assets](api/_lib/migrations/20260707120000_tokenized_3d_assets.sql) + [remix-royalty columns](api/_lib/migrations/20260708130000_tokenized_3d_remix_royalty.sql). Public gallery: `/minted` renders the launch directory live (model-viewer thumbnails, network toggle, royalty + remix badges) — the NFT counterpart of `/launches`. Docs: [docs/mcp.md](docs/mcp.md#mint_3d_asset). E2E: [scripts/tokenize-3d-devnet-e2e.mjs](scripts/tokenize-3d-devnet-e2e.mjs). Tests: [tests/tokenize-3d.test.js](tests/tokenize-3d.test.js), [tests/tokenize-3d-remix-royalty.test.js](tests/tokenize-3d-remix-royalty.test.js), [tests/asset-provenance.test.js](tests/asset-provenance.test.js) |diff --git a/contracts/README.md b/contracts/README.mdindex 5108285c7..09c555468 100644--- a/contracts/README.md+++ b/contracts/README.md@@ -7,6 +7,10 @@> as a local reference implementation — useful if you ever need to fork, audit,> or run a private deployment.+> **Reviewing these contracts?** Start at [`AUDIT-README.md`](./AUDIT-README.md):+> scope, deploy status, where the money is, the invariant ids, and the exact+> commands that reproduce every coverage and static-analysis number.+Three registries implementing [ERC-8004](https://eips.ethereum.org/EIPS/eip-8004) for the `3d-agent` project:- **IdentityRegistry** — ERC-721 agents with `tokenURI`, delegated wallet (EIP-712), and key/value metadata.diff --git a/contracts/program-tests/README.md b/contracts/program-tests/README.mdnew file mode 100644index 000000000..529477e91--- /dev/null+++ b/contracts/program-tests/README.md@@ -0,0 +1,100 @@+# `program-tests`++Invariant tests for the two three.ws Solana programs, run against their **real+compiled bytecode** in [LiteSVM](https://github.com/LiteSVM/litesvm).++Nothing in here re-implements program logic. The crate builds instructions,+derives addresses, and decodes account bytes; the behavior under test is the+`.so` produced by `cargo-build-sbf`, executing in a VM with the real SPL Token and+Associated Token Account programs loaded. A failing test therefore means the+program is wrong, not that a stub drifted.++| Program | Source | Tests | Invariants |+|---|---|---|---|+| `skill_license` | [`../skill-license/src/lib.rs`](../skill-license/src/lib.rs) | 21 | `SL-1` .. `SL-8` |+| `agent_invocation` | [`../agent-invocation/src/lib.rs`](../agent-invocation/src/lib.rs) | 11 | `AI-1` .. `AI-4` |++Invariants are defined in+[`specs/ECONOMY_CONTRACT_INVARIANTS.md`](../../specs/ECONOMY_CONTRACT_INVARIANTS.md).+Every id has a positive test (the property holds when it should) and a negative+test (a caller trying to break it is rejected), and every test names its id in a+doc comment, so `grep -rn "SL-3" .` finds the proof.++## Run++The bytecode has to exist first. `cargo test` does not build it, and will fail+with the exact command to run if a `.so` is missing.++```bash+cd contracts/skill-license && cargo-build-sbf+cd contracts/agent-invocation && cargo-build-sbf+cd contracts/program-tests && cargo test+```++`cargo-build-sbf` ships with the Solana (Agave) toolchain:++```bash+sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)"+export PATH="$HOME/.local/share/solana/install/active_release/bin:$PATH"+```++A cold SBF build of `skill_license` takes about ten minutes; the tests themselves+run in seconds.++## Writing a test++`src/lib.rs` holds the shared harness. The pieces you need:++```rust+use litesvm::LiteSVM;+use program_tests::*;++let mut svm = LiteSVM::new();+set_realistic_clock(&mut svm); // see below+load_program(&mut svm, pk(SKILL_LICENSE_ID), "skill-license", "skill_license.so");++// Anchor instruction data: 8-byte discriminator + borsh args.+let data = ix_data("mint_skill_license", &borsh_string("summarize"));++// Account state, decoded from the SPL wire layouts.+let mint = decode_mint(&svm.get_account(&nft_mint).unwrap().data);+let token = decode_token_account(&svm.get_account(&ata).unwrap().data);++// Assert on the program's own error name rather than a raw code.+assert!(logs_have_anchor_error(&logs, "UnauthorizedMinter"));+```++Account order in an instruction must match the field order of the program's+`#[derive(Accounts)]` struct, and the `is_signer` / `is_writable` flags must match+its `Signer` types and `mut` / `init` attributes. Each test file builds its+instructions through a `Harness` whose builders take every account as a parameter,+so a negative test can substitute exactly one wrong account and prove that the+constraint on *that* account is what rejects the transaction.++### The clock must be set++`set_realistic_clock` is not optional. LiteSVM boots with+`Clock::unix_timestamp == 0`, which no real cluster ever reports, and+`skill_license` writes that timestamp into `SkillLicense.revoked_at` where `0`+means "not revoked". Against the default clock a revocation records nothing and+the `AlreadyRevoked` guard never trips. The programs are correct on a real+cluster; the harness has to look like one. This is recorded as an accepted risk in+[`specs/ECONOMY_CONTRACT_THREAT_MODEL.md`](../../specs/ECONOMY_CONTRACT_THREAT_MODEL.md)+because it is exactly the kind of environmental assumption an audit should know+about.++## Dependency pins++`Cargo.toml` pins `litesvm` to `=0.15.2` and three `solana-*` runtime crates to+`=4.1.1`. LiteSVM 0.15.2 destructures `ExecutionRecord` exhaustively, so a later+patch release of those crates (which added fields) stops it from compiling. The+harness also depends on the granular `solana-instruction` / `solana-keypair` /+`solana-transaction` crates rather than the `solana-sdk` umbrella, because the+umbrella's version range conflicts with LiteSVM's. Loosen either at your own risk;+`cargo build --tests` tells you immediately.++## Context++- Audit entry point: [`../AUDIT-README.md`](../AUDIT-README.md)+- Solidity counterpart: [`../test/`](../test) (Foundry, 242 tests)+- Deploy runbooks: [`../skill-license/DEPLOYMENT.md`](../skill-license/DEPLOYMENT.md)diff --git a/specs/ECONOMY_CONTRACT_INVARIANTS.md b/specs/ECONOMY_CONTRACT_INVARIANTS.mdindex ea58ac0ed..9f65f0774 100644--- a/specs/ECONOMY_CONTRACT_INVARIANTS.md+++ b/specs/ECONOMY_CONTRACT_INVARIANTS.md@@ -12,11 +12,8 @@ Read this together with:- [`contracts/DEPLOYMENTS.md`](../contracts/DEPLOYMENTS.md) - the deploy-status table: which bytecode is live, at which address, on which chains, and how each address is verified.- [`SECURITY.md`](./SECURITY.md) - the abuse vectors against agent registration that sit upstream of these contracts.-A dedicated audit pack (a single review entry point plus a per-contract threat-model and committed static-analysis findings) is scoped in-[`prompts/swarm-100/roadmap-p3-contracts-audit-pack.md`](../prompts/swarm-100/roadmap-p3-contracts-audit-pack.md)-and has not been written yet. Until it lands, this document plus the two files-above are the review surface.+- [`ECONOMY_CONTRACT_THREAT_MODEL.md`](./ECONOMY_CONTRACT_THREAT_MODEL.md) - the attacker's-eye companion: assets, actors, and the failure mode each invariant exists to stop.+- [`contracts/AUDIT-README.md`](../contracts/AUDIT-README.md) - the entry point for a review engagement, with the commands that reproduce every coverage and static-analysis number quoted anywhere in this pack.## How to read an invariant@@ -29,7 +26,10 @@ states and **all** callers, not as a description of the happy path. Each one iscovered by at least one positive test (the property holds when it should) and atleast one negative test (the property is enforced against a caller who tries tobreak it). The test that proves an invariant names its id in a comment, so-`grep -rn "AP-7" contracts/test` finds the proof.+`grep -rn "AP-7" contracts/test` finds the proof for a Solidity contract and+`grep -rn "SL-3" contracts/program-tests` finds it for a Solana program. The+Solana proofs run the real compiled bytecode in LiteSVM, not a stub; see+[`contracts/program-tests/README.md`](../contracts/program-tests/README.md).Invariants marked **[deployed]** govern bytecode that is already live on a publicchain (see the deploy-status table in [`contracts/DEPLOYMENTS.md`](../contracts/DEPLOYMENTS.md)). Those are the@@ -134,6 +134,7 @@ cross-chain on payment. The wire format for the objects it sells is| GV-6 | `greenfieldCall` is accepted only from the real PermissionHub and only on the permission channel. Success records the real policy id and marks the sale Granted; failure marks it Failed and clears the purchase guard. || GV-7 | `revoke` is restricted to the sale's seller and to a sale in the Granted state, and it moves the sale to Revoked exactly once. || GV-8 | `buy`, `revoke`, and `withdraw` are non-reentrant, including against cross-function reentrancy from a refund callback. |+| GV-9 | A PermissionHub request that is declined rather than reverted (a `false` return) fails the whole call. `buy` never credits a seller for a permission that will not be minted, and `revoke` never marks a sale Revoked while the buyer keeps a live grant. |## WorldMoves (`WM-*`)diff --git a/specs/README.md b/specs/README.mdindex bb8393085..1469e7aac 100644--- a/specs/README.md+++ b/specs/README.md@@ -18,6 +18,8 @@ The specifications that define the three.ws embodied-agent platform: on-chain id- [`ENS_AGENT_CLAIM.md`](./ENS_AGENT_CLAIM.md) — ENS / DNS Agent Claim v1. A convention of two cheap-to-set records that bidirectionally bind a human-readable name to an on-chain agent identity, with no new on-chain infrastructure.- [`VALIDATORS.md`](./VALIDATORS.md) — Validator Allow-list Policy. Who may write to the on-chain `ValidationRegistry`, how attestations are formed, and how the allow-list is changed.- [`SECURITY.md`](./SECURITY.md) — Security & Threat Model for three.ws Card v1. Enumerates abuse vectors specific to three.ws registration on the ERC-8004 registries and the current mitigation for each.+- [`ECONOMY_CONTRACT_INVARIANTS.md`](./ECONOMY_CONTRACT_INVARIANTS.md) — Economy Contract Invariants v1. The properties every value-bearing contract in [`contracts/`](../contracts) must hold for all reachable states and all callers, each with a stable id and a positive plus negative test that cites it.+- [`ECONOMY_CONTRACT_THREAT_MODEL.md`](./ECONOMY_CONTRACT_THREAT_MODEL.md) — Economy Contract Threat Model v1. The attacker's-eye companion to the invariants: what is worth stealing, which actor could try, what stops each attempt, and which risks are accepted rather than mitigated. Entry point for a review engagement is [`contracts/AUDIT-README.md`](../contracts/AUDIT-README.md).- [`PROVENANCE_3D.md`](./PROVENANCE_3D.md): Verifiable 3D Provenance v1. C2PA-style signed content credentials for AI-generated 3D: creator, prompt, model, lineage and the GLB's content hash, ed25519-signed and anchored on Solana. Verification is free and public.- [`SIM_READINESS.md`](./SIM_READINESS.md): Simulation Readiness v1. The physics grade a 3D asset carries: watertightness, metric scale, mass and inertia, and a convex collision proxy, in four verdicts. Everything is derived from the mesh; anything unknowable from the geometry is reported as unknown rather than invented. Rides the provenance credential when signed.