diff --git a/.gitignore b/.gitignore index eadacab..8966e64 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ Thumbs.db # Logs *.log .gitnexus +Cargo.lock diff --git a/AGENTS.md b/AGENTS.md index 6c22439..d27c845 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,7 +1,7 @@ # GitNexus MCP -This project is indexed by GitNexus as **cipherocto** (120 symbols, 140 relationships, 2 execution flows). +This project is indexed by GitNexus as **cipherocto** (227 symbols, 328 relationships, 10 execution flows). GitNexus provides a knowledge graph over this codebase — call chains, blast radius, execution flows, and semantic search. @@ -59,4 +59,4 @@ MATCH (caller)-[:CodeRelation {type: 'CALLS'}]->(f:Function {name: "myFunc"}) RETURN caller.name, caller.filePath ``` - \ No newline at end of file + diff --git a/CLAUDE.md b/CLAUDE.md index 3d2a53f..590535e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -77,7 +77,17 @@ Every participant stakes both OCTO (global alignment) + Role Token (local specia ## Development Workflow -Since this is documentation-only, there are no build, test, or lint commands. +### Rust Development Commands + +**Lint (must pass with zero warnings)** +```bash +cargo clippy --all-targets --all-features -- -D warnings +``` + +**Format** +```bash +cargo fmt +``` ### Documentation Script @@ -111,10 +121,36 @@ CipherOcto uses **Trunk-Based + Feature Streams**: Full documentation: `.github/BRANCH_STRATEGY.md` Branch protection rules: `.github/branch-protection-rules.md` +## Documentation Standards + +**Diagrams:** Always prefer Mermaid diagrams over ASCII art. Mermaid is: +- Rendered in GitHub, VS Code, and most Markdown viewers +- Easier to maintain and edit +- Consistent with modern documentation practices + +**Example:** +```mermaid +graph TD + A[Start] --> B{Decision} + B -->|Yes| C[Action 1] + B -->|No| D[Action 2] +``` + +**When creating or updating docs:** +- Use `mermaid` code blocks for flowcharts, state diagrams, sequence diagrams +- Avoid ASCII art (`┌─`, `└─`, `─►`, etc.) +- If existing ASCII diagrams exist, convert them to Mermaid + +**Markdown Formatting:** +- All markdown files must pass Prettier formatting +- Run `npx prettier --write .md` before committing +- Ensure files end with a newline +- Use consistent heading hierarchy (no skipping levels) + # GitNexus MCP -This project is indexed by GitNexus as **cipherocto** (60 files, 120 symbols, 2 execution flows). +This project is indexed by GitNexus as **cipherocto** (227 symbols, 328 relationships, 10 execution flows). GitNexus provides a knowledge graph over this codebase — call chains, blast radius, execution flows, and semantic search. @@ -149,15 +185,6 @@ For any task involving code understanding, debugging, impact analysis, or refact | `cypher` | Raw graph queries (read `gitnexus://repo/{name}/schema` first) | | `list_repos` | Discover indexed repos | -## Current Codebase Structure - -**Functional Areas (Clusters):** -- Cluster_1: 5 symbols, 89% cohesion - -**Execution Flows (Processes):** -- Main → Open_db: 4 steps (cross-community) -- Main → Execute_agent: 3 steps (intra-community) - ## Resources Reference Lightweight reads (~100-500 tokens) for navigation: diff --git a/Cargo.lock b/Cargo.lock deleted file mode 100644 index a0ef82a..0000000 --- a/Cargo.lock +++ /dev/null @@ -1,3838 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 4 - -[[package]] -name = "aead" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" -dependencies = [ - "crypto-common", - "generic-array", -] - -[[package]] -name = "aes" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" -dependencies = [ - "cfg-if", - "cipher", - "cpufeatures", -] - -[[package]] -name = "aes-gcm" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "831010a0f742e1209b3bcea8fab6a8e149051ba6099432c8cb2cc117dec3ead1" -dependencies = [ - "aead", - "aes", - "cipher", - "ctr", - "ghash", - "subtle", -] - -[[package]] -name = "aho-corasick" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" -dependencies = [ - "memchr", -] - -[[package]] -name = "anstream" -version = "0.6.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" - -[[package]] -name = "anstyle-parse" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" -dependencies = [ - "windows-sys 0.61.2", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" -dependencies = [ - "anstyle", - "once_cell_polyfill", - "windows-sys 0.61.2", -] - -[[package]] -name = "anyhow" -version = "1.0.102" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" - -[[package]] -name = "arrayref" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76a2e8124351fda1ef8aaaa3bbd7ebbcb486bbcd4225aca0aa0d84bb2db8fecb" - -[[package]] -name = "asn1-rs" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56624a96882bb8c26d61312ae18cb45868e5a9992ea73c58e45c3101e56a1e60" -dependencies = [ - "asn1-rs-derive", - "asn1-rs-impl", - "displaydoc", - "nom", - "num-traits", - "rusticata-macros", - "thiserror 2.0.18", - "time", -] - -[[package]] -name = "asn1-rs-derive" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3109e49b1e4909e9db6515a30c633684d68cdeaa252f215214cb4fa1a5bfee2c" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "synstructure", -] - -[[package]] -name = "asn1-rs-impl" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "async-io" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456b8a8feb6f42d237746d4b3e9a178494627745c3c56c6ea55d92ba50d026fc" -dependencies = [ - "autocfg", - "cfg-if", - "concurrent-queue", - "futures-io", - "futures-lite", - "parking", - "polling", - "rustix", - "slab", - "windows-sys 0.61.2", -] - -[[package]] -name = "async-trait" -version = "0.1.89" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "asynchronous-codec" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a860072022177f903e59730004fb5dc13db9275b79bb2aef7ba8ce831956c233" -dependencies = [ - "bytes", - "futures-sink", - "futures-util", - "memchr", - "pin-project-lite", -] - -[[package]] -name = "atomic-waker" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" - -[[package]] -name = "attohttpc" -version = "0.30.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16e2cdb6d5ed835199484bb92bb8b3edd526effe995c61732580439c1a67e2e9" -dependencies = [ - "base64", - "http", - "log", - "url", -] - -[[package]] -name = "autocfg" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" - -[[package]] -name = "base-x" -version = "0.2.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" - -[[package]] -name = "base256emoji" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e9430d9a245a77c92176e649af6e275f20839a48389859d1661e9a128d077c" -dependencies = [ - "const-str", - "match-lookup", -] - -[[package]] -name = "base64" -version = "0.22.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" - -[[package]] -name = "base64ct" -version = "1.8.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2af50177e190e07a26ab74f8b1efbfe2ef87da2116221318cb1c2e82baf7de06" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" - -[[package]] -name = "blake2" -version = "0.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" -dependencies = [ - "digest", -] - -[[package]] -name = "block-buffer" -version = "0.10.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" -dependencies = [ - "generic-array", -] - -[[package]] -name = "bs58" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" -dependencies = [ - "tinyvec", -] - -[[package]] -name = "bumpalo" -version = "3.20.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" - -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - -[[package]] -name = "bytes" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" - -[[package]] -name = "cc" -version = "1.2.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2" -dependencies = [ - "find-msvc-tools", - "shlex", -] - -[[package]] -name = "cfg-if" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" - -[[package]] -name = "cfg_aliases" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" - -[[package]] -name = "chacha20" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3613f74bd2eac03dad61bd53dbe620703d4371614fe0bc3b9f04dd36fe4e818" -dependencies = [ - "cfg-if", - "cipher", - "cpufeatures", -] - -[[package]] -name = "chacha20poly1305" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" -dependencies = [ - "aead", - "chacha20", - "cipher", - "poly1305", - "zeroize", -] - -[[package]] -name = "cipher" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" -dependencies = [ - "crypto-common", - "inout", - "zeroize", -] - -[[package]] -name = "clap" -version = "4.5.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2797f34da339ce31042b27d23607e051786132987f595b02ba4f6a6dffb7030a" -dependencies = [ - "clap_builder", - "clap_derive", -] - -[[package]] -name = "clap_builder" -version = "4.5.60" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24a241312cea5059b13574bb9b3861cabf758b879c15190b37b6d6fd63ab6876" -dependencies = [ - "anstream", - "anstyle", - "clap_lex", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.5.55" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92793da1a46a5f2a02a6f4c46c6496b28c43638adea8306fcb0caa1634f24e5" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "clap_lex" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a822ea5bc7590f9d40f1ba12c0dc3c2760f3482c6984db1573ad11031420831" - -[[package]] -name = "colorchoice" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" - -[[package]] -name = "concurrent-queue" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "const-oid" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" - -[[package]] -name = "const-str" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f421161cb492475f1661ddc9815a745a1c894592070661180fdec3d4872e9c3" - -[[package]] -name = "core-foundation" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - -[[package]] -name = "core2" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b49ba7ef1ad6107f8824dbe97de947cbaac53c44e7f9756a1fba0d37c1eec505" -dependencies = [ - "memchr", -] - -[[package]] -name = "cpufeatures" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" -dependencies = [ - "libc", -] - -[[package]] -name = "crc32fast" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "critical-section" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" - -[[package]] -name = "crossbeam-channel" -version = "0.5.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" -dependencies = [ - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-utils" -version = "0.8.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" - -[[package]] -name = "crypto-common" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" -dependencies = [ - "generic-array", - "rand_core 0.6.4", - "typenum", -] - -[[package]] -name = "ctr" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0369ee1ad671834580515889b80f2ea915f23b8be8d0daa4bbaf2ac5c7590835" -dependencies = [ - "cipher", -] - -[[package]] -name = "curve25519-dalek" -version = "4.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" -dependencies = [ - "cfg-if", - "cpufeatures", - "curve25519-dalek-derive", - "digest", - "fiat-crypto", - "rustc_version", - "subtle", - "zeroize", -] - -[[package]] -name = "curve25519-dalek-derive" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "data-encoding" -version = "2.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7a1e2f27636f116493b8b860f5546edb47c8d8f8ea73e1d2a20be88e28d1fea" - -[[package]] -name = "data-encoding-macro" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8142a83c17aa9461d637e649271eae18bf2edd00e91f2e105df36c3c16355bdb" -dependencies = [ - "data-encoding", - "data-encoding-macro-internal", -] - -[[package]] -name = "data-encoding-macro-internal" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ab67060fc6b8ef687992d439ca0fa36e7ed17e9a0b16b25b601e8757df720de" -dependencies = [ - "data-encoding", - "syn", -] - -[[package]] -name = "der" -version = "0.7.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7c1832837b905bbfb5101e07cc24c8deddf52f93225eee6ead5f4d63d53ddcb" -dependencies = [ - "const-oid", - "zeroize", -] - -[[package]] -name = "der-parser" -version = "10.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07da5016415d5a3c4dd39b11ed26f915f52fc4e0dc197d87908bc916e51bc1a6" -dependencies = [ - "asn1-rs", - "displaydoc", - "nom", - "num-bigint", - "num-traits", - "rusticata-macros", -] - -[[package]] -name = "deranged" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cd812cc2bc1d69d4764bd80df88b4317eaef9e773c75226407d9bc0876b211c" -dependencies = [ - "powerfmt", -] - -[[package]] -name = "digest" -version = "0.10.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" -dependencies = [ - "block-buffer", - "crypto-common", - "subtle", -] - -[[package]] -name = "displaydoc" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "ed25519" -version = "2.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" -dependencies = [ - "pkcs8", - "signature", -] - -[[package]] -name = "ed25519-dalek" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70e796c081cee67dc755e1a36a0a172b897fab85fc3f6bc48307991f64e4eca9" -dependencies = [ - "curve25519-dalek", - "ed25519", - "serde", - "sha2", - "subtle", - "zeroize", -] - -[[package]] -name = "either" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" - -[[package]] -name = "enum-as-inner" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1e6a265c649f3f5979b601d26f1d05ada116434c87741c9493cb56218f76cbc" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "equivalent" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" - -[[package]] -name = "errno" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" -dependencies = [ - "libc", - "windows-sys 0.61.2", -] - -[[package]] -name = "fiat-crypto" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" - -[[package]] -name = "find-msvc-tools" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" - -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - -[[package]] -name = "foldhash" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" - -[[package]] -name = "form_urlencoded" -version = "1.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" -dependencies = [ - "percent-encoding", -] - -[[package]] -name = "fs2" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "futures" -version = "0.3.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-bounded" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91f328e7fb845fc832912fb6a34f40cf6d1888c92f974d1893a54e97b5ff542e" -dependencies = [ - "futures-timer", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" - -[[package]] -name = "futures-executor" -version = "0.3.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf29c38818342a3b26b5b923639e7b1f4a61fc5e76102d4b1981c6dc7a7579d" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718" - -[[package]] -name = "futures-lite" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad" -dependencies = [ - "futures-core", - "pin-project-lite", -] - -[[package]] -name = "futures-macro" -version = "0.3.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-rustls" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f2f12607f92c69b12ed746fabf9ca4f5c482cba46679c1a75b874ed7c26adb" -dependencies = [ - "futures-io", - "rustls", - "rustls-pki-types", -] - -[[package]] -name = "futures-sink" -version = "0.3.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" - -[[package]] -name = "futures-task" -version = "0.3.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" - -[[package]] -name = "futures-timer" -version = "3.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f288b0a4f20f9a56b5d1da57e2227c661b7b16168e2f72365f57b63326e29b24" - -[[package]] -name = "futures-util" -version = "0.3.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "slab", -] - -[[package]] -name = "fxhash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" -dependencies = [ - "byteorder", -] - -[[package]] -name = "generic-array" -version = "0.14.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" -dependencies = [ - "typenum", - "version_check", -] - -[[package]] -name = "getrandom" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" -dependencies = [ - "cfg-if", - "js-sys", - "libc", - "wasi", - "wasm-bindgen", -] - -[[package]] -name = "getrandom" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" -dependencies = [ - "cfg-if", - "js-sys", - "libc", - "r-efi", - "wasip2", - "wasm-bindgen", -] - -[[package]] -name = "getrandom" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "139ef39800118c7683f2fd3c98c1b23c09ae076556b435f8e9064ae108aaeeec" -dependencies = [ - "cfg-if", - "libc", - "r-efi", - "wasip2", - "wasip3", -] - -[[package]] -name = "ghash" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0d8a4362ccb29cb0b265253fb0a2728f592895ee6854fd9bc13f2ffda266ff1" -dependencies = [ - "opaque-debug", - "polyval", -] - -[[package]] -name = "h2" -version = "0.4.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f44da3a8150a6703ed5d34e164b875fd14c2cdab9af1252a9a1020bde2bdc54" -dependencies = [ - "atomic-waker", - "bytes", - "fnv", - "futures-core", - "futures-sink", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", -] - -[[package]] -name = "hashbrown" -version = "0.15.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" -dependencies = [ - "foldhash", -] - -[[package]] -name = "hashbrown" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" - -[[package]] -name = "hashlink" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7382cf6263419f2d8df38c55d7da83da5c18aef87fc7a7fc1fb1e344edfe14c1" -dependencies = [ - "hashbrown 0.15.5", -] - -[[package]] -name = "heck" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" - -[[package]] -name = "hermit-abi" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" - -[[package]] -name = "hickory-proto" -version = "0.25.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8a6fe56c0038198998a6f217ca4e7ef3a5e51f46163bd6dd60b5c71ca6c6502" -dependencies = [ - "async-trait", - "cfg-if", - "data-encoding", - "enum-as-inner", - "futures-channel", - "futures-io", - "futures-util", - "idna", - "ipnet", - "once_cell", - "rand 0.9.2", - "ring", - "socket2 0.5.10", - "thiserror 2.0.18", - "tinyvec", - "tokio", - "tracing", - "url", -] - -[[package]] -name = "hickory-resolver" -version = "0.25.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc62a9a99b0bfb44d2ab95a7208ac952d31060efc16241c87eaf36406fecf87a" -dependencies = [ - "cfg-if", - "futures-util", - "hickory-proto", - "ipconfig", - "moka", - "once_cell", - "parking_lot 0.12.5", - "rand 0.9.2", - "resolv-conf", - "smallvec", - "thiserror 2.0.18", - "tokio", - "tracing", -] - -[[package]] -name = "hkdf" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5f8eb2ad728638ea2c7d47a21db23b7b58a72ed6a38256b8a1849f15fbbdf7" -dependencies = [ - "hmac", -] - -[[package]] -name = "hmac" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" -dependencies = [ - "digest", -] - -[[package]] -name = "http" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" -dependencies = [ - "bytes", - "itoa", -] - -[[package]] -name = "http-body" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" -dependencies = [ - "bytes", - "http", -] - -[[package]] -name = "http-body-util" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" -dependencies = [ - "bytes", - "futures-core", - "http", - "http-body", - "pin-project-lite", -] - -[[package]] -name = "httparse" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" - -[[package]] -name = "hyper" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" -dependencies = [ - "atomic-waker", - "bytes", - "futures-channel", - "futures-core", - "h2", - "http", - "http-body", - "httparse", - "itoa", - "pin-project-lite", - "pin-utils", - "smallvec", - "tokio", - "want", -] - -[[package]] -name = "hyper-util" -version = "0.1.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" -dependencies = [ - "bytes", - "futures-channel", - "futures-util", - "http", - "http-body", - "hyper", - "libc", - "pin-project-lite", - "socket2 0.6.2", - "tokio", - "tower-service", - "tracing", -] - -[[package]] -name = "icu_collections" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" -dependencies = [ - "displaydoc", - "potential_utf", - "yoke", - "zerofrom", - "zerovec", -] - -[[package]] -name = "icu_locale_core" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" -dependencies = [ - "displaydoc", - "litemap", - "tinystr", - "writeable", - "zerovec", -] - -[[package]] -name = "icu_normalizer" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" -dependencies = [ - "icu_collections", - "icu_normalizer_data", - "icu_properties", - "icu_provider", - "smallvec", - "zerovec", -] - -[[package]] -name = "icu_normalizer_data" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" - -[[package]] -name = "icu_properties" -version = "2.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" -dependencies = [ - "icu_collections", - "icu_locale_core", - "icu_properties_data", - "icu_provider", - "zerotrie", - "zerovec", -] - -[[package]] -name = "icu_properties_data" -version = "2.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" - -[[package]] -name = "icu_provider" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" -dependencies = [ - "displaydoc", - "icu_locale_core", - "writeable", - "yoke", - "zerofrom", - "zerotrie", - "zerovec", -] - -[[package]] -name = "id-arena" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" - -[[package]] -name = "idna" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" -dependencies = [ - "idna_adapter", - "smallvec", - "utf8_iter", -] - -[[package]] -name = "idna_adapter" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" -dependencies = [ - "icu_normalizer", - "icu_properties", -] - -[[package]] -name = "if-addrs" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cabb0019d51a643781ff15c9c8a3e5dedc365c47211270f4e8f82812fedd8f0a" -dependencies = [ - "libc", - "windows-sys 0.48.0", -] - -[[package]] -name = "if-watch" -version = "3.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdf9d64cfcf380606e64f9a0bcf493616b65331199f984151a6fa11a7b3cde38" -dependencies = [ - "async-io", - "core-foundation", - "fnv", - "futures", - "if-addrs", - "ipnet", - "log", - "netlink-packet-core", - "netlink-packet-route", - "netlink-proto", - "netlink-sys", - "rtnetlink", - "system-configuration", - "tokio", - "windows", -] - -[[package]] -name = "igd-next" -version = "0.16.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "516893339c97f6011282d5825ac94fc1c7aad5cad26bdc2d0cee068c0bf97f97" -dependencies = [ - "async-trait", - "attohttpc", - "bytes", - "futures", - "http", - "http-body-util", - "hyper", - "hyper-util", - "log", - "rand 0.9.2", - "tokio", - "url", - "xmltree", -] - -[[package]] -name = "indexmap" -version = "2.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" -dependencies = [ - "equivalent", - "hashbrown 0.16.1", - "serde", - "serde_core", -] - -[[package]] -name = "inout" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" -dependencies = [ - "generic-array", -] - -[[package]] -name = "instant" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0242819d153cba4b4b05a5a8f2a7e9bbf97b6055b2a002b395c96b5ff3c0222" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "ipconfig" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" -dependencies = [ - "socket2 0.5.10", - "widestring", - "windows-sys 0.48.0", - "winreg", -] - -[[package]] -name = "ipnet" -version = "2.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" - -[[package]] -name = "is_terminal_polyfill" -version = "1.70.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" - -[[package]] -name = "itoa" -version = "1.0.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" - -[[package]] -name = "js-sys" -version = "0.3.88" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7e709f3e3d22866f9c25b3aff01af289b18422cc8b4262fb19103ee80fe513d" -dependencies = [ - "once_cell", - "wasm-bindgen", -] - -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - -[[package]] -name = "leb128fmt" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" - -[[package]] -name = "libc" -version = "0.2.182" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" - -[[package]] -name = "libp2p" -version = "0.56.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce71348bf5838e46449ae240631117b487073d5f347c06d434caddcb91dceb5a" -dependencies = [ - "bytes", - "either", - "futures", - "futures-timer", - "getrandom 0.2.17", - "libp2p-allow-block-list", - "libp2p-connection-limits", - "libp2p-core", - "libp2p-dns", - "libp2p-identity", - "libp2p-mdns", - "libp2p-noise", - "libp2p-quic", - "libp2p-request-response", - "libp2p-swarm", - "libp2p-tcp", - "libp2p-upnp", - "libp2p-yamux", - "multiaddr", - "pin-project", - "rw-stream-sink", - "thiserror 2.0.18", -] - -[[package]] -name = "libp2p-allow-block-list" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d16ccf824ee859ca83df301e1c0205270206223fd4b1f2e512a693e1912a8f4a" -dependencies = [ - "libp2p-core", - "libp2p-identity", - "libp2p-swarm", -] - -[[package]] -name = "libp2p-connection-limits" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a18b8b607cf3bfa2f8c57db9c7d8569a315d5cc0a282e6bfd5ebfc0a9840b2a0" -dependencies = [ - "libp2p-core", - "libp2p-identity", - "libp2p-swarm", -] - -[[package]] -name = "libp2p-core" -version = "0.43.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "249128cd37a2199aff30a7675dffa51caf073b51aa612d2f544b19932b9aebca" -dependencies = [ - "either", - "fnv", - "futures", - "futures-timer", - "libp2p-identity", - "multiaddr", - "multihash", - "multistream-select", - "parking_lot 0.12.5", - "pin-project", - "quick-protobuf", - "rand 0.8.5", - "rw-stream-sink", - "thiserror 2.0.18", - "tracing", - "unsigned-varint 0.8.0", - "web-time", -] - -[[package]] -name = "libp2p-dns" -version = "0.44.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b770c1c8476736ca98c578cba4b505104ff8e842c2876b528925f9766379f9a" -dependencies = [ - "async-trait", - "futures", - "hickory-resolver", - "libp2p-core", - "libp2p-identity", - "parking_lot 0.12.5", - "smallvec", - "tracing", -] - -[[package]] -name = "libp2p-identity" -version = "0.2.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0c7892c221730ba55f7196e98b0b8ba5e04b4155651736036628e9f73ed6fc3" -dependencies = [ - "bs58", - "ed25519-dalek", - "hkdf", - "multihash", - "quick-protobuf", - "rand 0.8.5", - "sha2", - "thiserror 2.0.18", - "tracing", - "zeroize", -] - -[[package]] -name = "libp2p-mdns" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c66872d0f1ffcded2788683f76931be1c52e27f343edb93bc6d0bcd8887be443" -dependencies = [ - "futures", - "hickory-proto", - "if-watch", - "libp2p-core", - "libp2p-identity", - "libp2p-swarm", - "rand 0.8.5", - "smallvec", - "socket2 0.5.10", - "tokio", - "tracing", -] - -[[package]] -name = "libp2p-noise" -version = "0.46.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc73eacbe6462a0eb92a6527cac6e63f02026e5407f8831bde8293f19217bfbf" -dependencies = [ - "asynchronous-codec", - "bytes", - "futures", - "libp2p-core", - "libp2p-identity", - "multiaddr", - "multihash", - "quick-protobuf", - "rand 0.8.5", - "snow", - "static_assertions", - "thiserror 2.0.18", - "tracing", - "x25519-dalek", - "zeroize", -] - -[[package]] -name = "libp2p-quic" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dc448b2de9f4745784e3751fe8bc6c473d01b8317edd5ababcb0dec803d843f" -dependencies = [ - "futures", - "futures-timer", - "if-watch", - "libp2p-core", - "libp2p-identity", - "libp2p-tls", - "quinn", - "rand 0.8.5", - "ring", - "rustls", - "socket2 0.5.10", - "thiserror 2.0.18", - "tokio", - "tracing", -] - -[[package]] -name = "libp2p-request-response" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9f1cca83488b90102abac7b67d5c36fc65bc02ed47620228af7ed002e6a1478" -dependencies = [ - "async-trait", - "futures", - "futures-bounded", - "libp2p-core", - "libp2p-identity", - "libp2p-swarm", - "rand 0.8.5", - "smallvec", - "tracing", -] - -[[package]] -name = "libp2p-swarm" -version = "0.47.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce88c6c4bf746c8482480345ea3edfd08301f49e026889d1cbccfa1808a9ed9e" -dependencies = [ - "either", - "fnv", - "futures", - "futures-timer", - "hashlink", - "libp2p-core", - "libp2p-identity", - "multistream-select", - "rand 0.8.5", - "smallvec", - "tokio", - "tracing", - "web-time", -] - -[[package]] -name = "libp2p-tcp" -version = "0.44.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb6585b9309699f58704ec9ab0bb102eca7a3777170fa91a8678d73ca9cafa93" -dependencies = [ - "futures", - "futures-timer", - "if-watch", - "libc", - "libp2p-core", - "socket2 0.6.2", - "tokio", - "tracing", -] - -[[package]] -name = "libp2p-tls" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96ff65a82e35375cbc31ebb99cacbbf28cb6c4fefe26bf13756ddcf708d40080" -dependencies = [ - "futures", - "futures-rustls", - "libp2p-core", - "libp2p-identity", - "rcgen", - "ring", - "rustls", - "rustls-webpki", - "thiserror 2.0.18", - "x509-parser", - "yasna", -] - -[[package]] -name = "libp2p-upnp" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4757e65fe69399c1a243bbb90ec1ae5a2114b907467bf09f3575e899815bb8d3" -dependencies = [ - "futures", - "futures-timer", - "igd-next", - "libp2p-core", - "libp2p-swarm", - "tokio", - "tracing", -] - -[[package]] -name = "libp2p-yamux" -version = "0.47.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f15df094914eb4af272acf9adaa9e287baa269943f32ea348ba29cfb9bfc60d8" -dependencies = [ - "either", - "futures", - "libp2p-core", - "thiserror 2.0.18", - "tracing", - "yamux 0.12.1", - "yamux 0.13.8", -] - -[[package]] -name = "linux-raw-sys" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" - -[[package]] -name = "litemap" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" - -[[package]] -name = "lock_api" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" -dependencies = [ - "scopeguard", -] - -[[package]] -name = "log" -version = "0.4.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" - -[[package]] -name = "lru-slab" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" - -[[package]] -name = "match-lookup" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "757aee279b8bdbb9f9e676796fd459e4207a1f986e87886700abf589f5abf771" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "matchers" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" -dependencies = [ - "regex-automata", -] - -[[package]] -name = "memchr" -version = "2.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" - -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - -[[package]] -name = "mio" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" -dependencies = [ - "libc", - "wasi", - "windows-sys 0.61.2", -] - -[[package]] -name = "moka" -version = "0.12.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4ac832c50ced444ef6be0767a008b02c106a909ba79d1d830501e94b96f6b7e" -dependencies = [ - "crossbeam-channel", - "crossbeam-epoch", - "crossbeam-utils", - "equivalent", - "parking_lot 0.12.5", - "portable-atomic", - "smallvec", - "tagptr", - "uuid", -] - -[[package]] -name = "multiaddr" -version = "0.18.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe6351f60b488e04c1d21bc69e56b89cb3f5e8f5d22557d6e8031bdfd79b6961" -dependencies = [ - "arrayref", - "byteorder", - "data-encoding", - "libp2p-identity", - "multibase", - "multihash", - "percent-encoding", - "serde", - "static_assertions", - "unsigned-varint 0.8.0", - "url", -] - -[[package]] -name = "multibase" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8694bb4835f452b0e3bb06dbebb1d6fc5385b6ca1caf2e55fd165c042390ec77" -dependencies = [ - "base-x", - "base256emoji", - "data-encoding", - "data-encoding-macro", -] - -[[package]] -name = "multihash" -version = "0.19.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b430e7953c29dd6a09afc29ff0bb69c6e306329ee6794700aee27b76a1aea8d" -dependencies = [ - "core2", - "unsigned-varint 0.8.0", -] - -[[package]] -name = "multistream-select" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea0df8e5eec2298a62b326ee4f0d7fe1a6b90a09dfcf9df37b38f947a8c42f19" -dependencies = [ - "bytes", - "futures", - "log", - "pin-project", - "smallvec", - "unsigned-varint 0.7.2", -] - -[[package]] -name = "netlink-packet-core" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72724faf704479d67b388da142b186f916188505e7e0b26719019c525882eda4" -dependencies = [ - "anyhow", - "byteorder", - "netlink-packet-utils", -] - -[[package]] -name = "netlink-packet-route" -version = "0.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053998cea5a306971f88580d0829e90f270f940befd7cf928da179d4187a5a66" -dependencies = [ - "anyhow", - "bitflags 1.3.2", - "byteorder", - "libc", - "netlink-packet-core", - "netlink-packet-utils", -] - -[[package]] -name = "netlink-packet-utils" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ede8a08c71ad5a95cdd0e4e52facd37190977039a4704eb82a283f713747d34" -dependencies = [ - "anyhow", - "byteorder", - "paste", - "thiserror 1.0.69", -] - -[[package]] -name = "netlink-proto" -version = "0.11.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72452e012c2f8d612410d89eea01e2d9b56205274abb35d53f60200b2ec41d60" -dependencies = [ - "bytes", - "futures", - "log", - "netlink-packet-core", - "netlink-sys", - "thiserror 2.0.18", -] - -[[package]] -name = "netlink-sys" -version = "0.8.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd6c30ed10fa69cc491d491b85cc971f6bdeb8e7367b7cde2ee6cc878d583fae" -dependencies = [ - "bytes", - "futures-util", - "libc", - "log", - "tokio", -] - -[[package]] -name = "nix" -version = "0.26.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "598beaf3cc6fdd9a5dfb1630c2800c7acd31df7aaf0f565796fba2b53ca1af1b" -dependencies = [ - "bitflags 1.3.2", - "cfg-if", - "libc", -] - -[[package]] -name = "nohash-hasher" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" - -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - -[[package]] -name = "nu-ansi-term" -version = "0.50.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" -dependencies = [ - "windows-sys 0.61.2", -] - -[[package]] -name = "num-bigint" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" -dependencies = [ - "num-integer", - "num-traits", -] - -[[package]] -name = "num-conv" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf97ec579c3c42f953ef76dbf8d55ac91fb219dde70e49aa4a6b7d74e9919050" - -[[package]] -name = "num-integer" -version = "0.1.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num-traits" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -dependencies = [ - "autocfg", -] - -[[package]] -name = "octo-cli" -version = "0.1.0" -dependencies = [ - "anyhow", - "clap", - "octo-core", - "octo-network", - "octo-registry", - "octo-runtime", - "serde", - "serde_json", - "tokio", - "tracing", - "tracing-subscriber", -] - -[[package]] -name = "octo-core" -version = "0.1.0" -dependencies = [ - "anyhow", - "async-trait", - "octo-registry", - "serde", - "serde_json", - "sha2", - "thiserror 2.0.18", - "tokio", - "tracing", - "uuid", -] - -[[package]] -name = "octo-network" -version = "0.1.0" -dependencies = [ - "anyhow", - "async-trait", - "libp2p", - "octo-core", - "octo-registry", - "serde", - "serde_json", - "thiserror 2.0.18", - "tokio", - "tracing", - "uuid", -] - -[[package]] -name = "octo-registry" -version = "0.1.0" -dependencies = [ - "anyhow", - "serde", - "serde_json", - "sha2", - "sled", - "thiserror 2.0.18", - "tokio", - "tracing", - "uuid", -] - -[[package]] -name = "octo-runtime" -version = "0.1.0" -dependencies = [ - "anyhow", - "async-trait", - "octo-core", - "octo-registry", - "serde", - "serde_json", - "thiserror 2.0.18", - "tokio", - "tracing", -] - -[[package]] -name = "oid-registry" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12f40cff3dde1b6087cc5d5f5d4d65712f34016a03ed60e9c08dcc392736b5b7" -dependencies = [ - "asn1-rs", -] - -[[package]] -name = "once_cell" -version = "1.21.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" -dependencies = [ - "critical-section", - "portable-atomic", -] - -[[package]] -name = "once_cell_polyfill" -version = "1.70.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" - -[[package]] -name = "opaque-debug" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" - -[[package]] -name = "parking" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" - -[[package]] -name = "parking_lot" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core 0.8.6", -] - -[[package]] -name = "parking_lot" -version = "0.12.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" -dependencies = [ - "lock_api", - "parking_lot_core 0.9.12", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" -dependencies = [ - "cfg-if", - "instant", - "libc", - "redox_syscall 0.2.16", - "smallvec", - "winapi", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall 0.5.18", - "smallvec", - "windows-link", -] - -[[package]] -name = "paste" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" - -[[package]] -name = "pem" -version = "3.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d30c53c26bc5b31a98cd02d20f25a7c8567146caf63ed593a9d87b2775291be" -dependencies = [ - "base64", - "serde_core", -] - -[[package]] -name = "percent-encoding" -version = "2.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" - -[[package]] -name = "pin-project" -version = "1.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677f1add503faace112b9f1373e43e9e054bfdd22ff1a63c1bc485eaec6a6a8a" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e918e4ff8c4549eb882f14b3a4bc8c8bc93de829416eacf579f1207a8fbf861" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" - -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - -[[package]] -name = "pkcs8" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" -dependencies = [ - "der", - "spki", -] - -[[package]] -name = "polling" -version = "3.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d0e4f59085d47d8241c88ead0f274e8a0cb551f3625263c05eb8dd897c34218" -dependencies = [ - "cfg-if", - "concurrent-queue", - "hermit-abi", - "pin-project-lite", - "rustix", - "windows-sys 0.61.2", -] - -[[package]] -name = "poly1305" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8159bd90725d2df49889a078b54f4f79e87f1f8a8444194cdca81d38f5393abf" -dependencies = [ - "cpufeatures", - "opaque-debug", - "universal-hash", -] - -[[package]] -name = "polyval" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d1fe60d06143b2430aa532c94cfe9e29783047f06c0d7fd359a9a51b729fa25" -dependencies = [ - "cfg-if", - "cpufeatures", - "opaque-debug", - "universal-hash", -] - -[[package]] -name = "portable-atomic" -version = "1.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" - -[[package]] -name = "potential_utf" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" -dependencies = [ - "zerovec", -] - -[[package]] -name = "powerfmt" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" - -[[package]] -name = "ppv-lite86" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" -dependencies = [ - "zerocopy", -] - -[[package]] -name = "prettyplease" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" -dependencies = [ - "proc-macro2", - "syn", -] - -[[package]] -name = "proc-macro2" -version = "1.0.106" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quick-protobuf" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6da84cc204722a989e01ba2f6e1e276e190f22263d0cb6ce8526fcdb0d2e1f" -dependencies = [ - "byteorder", -] - -[[package]] -name = "quinn" -version = "0.11.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e20a958963c291dc322d98411f541009df2ced7b5a4f2bd52337638cfccf20" -dependencies = [ - "bytes", - "cfg_aliases", - "futures-io", - "pin-project-lite", - "quinn-proto", - "quinn-udp", - "rustc-hash", - "rustls", - "socket2 0.6.2", - "thiserror 2.0.18", - "tokio", - "tracing", - "web-time", -] - -[[package]] -name = "quinn-proto" -version = "0.11.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1906b49b0c3bc04b5fe5d86a77925ae6524a19b816ae38ce1e426255f1d8a31" -dependencies = [ - "bytes", - "getrandom 0.3.4", - "lru-slab", - "rand 0.9.2", - "ring", - "rustc-hash", - "rustls", - "rustls-pki-types", - "slab", - "thiserror 2.0.18", - "tinyvec", - "tracing", - "web-time", -] - -[[package]] -name = "quinn-udp" -version = "0.5.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" -dependencies = [ - "cfg_aliases", - "libc", - "once_cell", - "socket2 0.6.2", - "tracing", - "windows-sys 0.60.2", -] - -[[package]] -name = "quote" -version = "1.0.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "r-efi" -version = "5.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha 0.3.1", - "rand_core 0.6.4", -] - -[[package]] -name = "rand" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" -dependencies = [ - "rand_chacha 0.9.0", - "rand_core 0.9.5", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core 0.6.4", -] - -[[package]] -name = "rand_chacha" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" -dependencies = [ - "ppv-lite86", - "rand_core 0.9.5", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom 0.2.17", -] - -[[package]] -name = "rand_core" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" -dependencies = [ - "getrandom 0.3.4", -] - -[[package]] -name = "rcgen" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75e669e5202259b5314d1ea5397316ad400819437857b90861765f24c4cf80a2" -dependencies = [ - "pem", - "ring", - "rustls-pki-types", - "time", - "yasna", -] - -[[package]] -name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "redox_syscall" -version = "0.5.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" -dependencies = [ - "bitflags 2.11.0", -] - -[[package]] -name = "regex-automata" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c" - -[[package]] -name = "resolv-conf" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e061d1b48cb8d38042de4ae0a7a6401009d6143dc80d2e2d6f31f0bdd6470c7" - -[[package]] -name = "ring" -version = "0.17.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" -dependencies = [ - "cc", - "cfg-if", - "getrandom 0.2.17", - "libc", - "untrusted", - "windows-sys 0.52.0", -] - -[[package]] -name = "rtnetlink" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a552eb82d19f38c3beed3f786bd23aa434ceb9ac43ab44419ca6d67a7e186c0" -dependencies = [ - "futures", - "log", - "netlink-packet-core", - "netlink-packet-route", - "netlink-packet-utils", - "netlink-proto", - "netlink-sys", - "nix", - "thiserror 1.0.69", - "tokio", -] - -[[package]] -name = "rustc-hash" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" - -[[package]] -name = "rustc_version" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" -dependencies = [ - "semver", -] - -[[package]] -name = "rusticata-macros" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "faf0c4a6ece9950b9abdb62b1cfcf2a68b3b67a10ba445b3bb85be2a293d0632" -dependencies = [ - "nom", -] - -[[package]] -name = "rustix" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" -dependencies = [ - "bitflags 2.11.0", - "errno", - "libc", - "linux-raw-sys", - "windows-sys 0.61.2", -] - -[[package]] -name = "rustls" -version = "0.23.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c665f33d38cea657d9614f766881e4d510e0eda4239891eea56b4cadcf01801b" -dependencies = [ - "once_cell", - "ring", - "rustls-pki-types", - "rustls-webpki", - "subtle", - "zeroize", -] - -[[package]] -name = "rustls-pki-types" -version = "1.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" -dependencies = [ - "web-time", - "zeroize", -] - -[[package]] -name = "rustls-webpki" -version = "0.103.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" -dependencies = [ - "ring", - "rustls-pki-types", - "untrusted", -] - -[[package]] -name = "rustversion" -version = "1.0.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" - -[[package]] -name = "rw-stream-sink" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8c9026ff5d2f23da5e45bbc283f156383001bfb09c4e44256d02c1a685fe9a1" -dependencies = [ - "futures", - "pin-project", - "static_assertions", -] - -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - -[[package]] -name = "semver" -version = "1.0.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" - -[[package]] -name = "serde" -version = "1.0.228" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" -dependencies = [ - "serde_core", - "serde_derive", -] - -[[package]] -name = "serde_core" -version = "1.0.228" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.228" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.149" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" -dependencies = [ - "itoa", - "memchr", - "serde", - "serde_core", - "zmij", -] - -[[package]] -name = "sha2" -version = "0.10.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" -dependencies = [ - "cfg-if", - "cpufeatures", - "digest", -] - -[[package]] -name = "sharded-slab" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - -[[package]] -name = "signal-hook-registry" -version = "1.4.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" -dependencies = [ - "errno", - "libc", -] - -[[package]] -name = "signature" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" -dependencies = [ - "rand_core 0.6.4", -] - -[[package]] -name = "slab" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" - -[[package]] -name = "sled" -version = "0.34.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f96b4737c2ce5987354855aed3797279def4ebf734436c6aa4552cf8e169935" -dependencies = [ - "crc32fast", - "crossbeam-epoch", - "crossbeam-utils", - "fs2", - "fxhash", - "libc", - "log", - "parking_lot 0.11.2", -] - -[[package]] -name = "smallvec" -version = "1.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" - -[[package]] -name = "snow" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "850948bee068e713b8ab860fe1adc4d109676ab4c3b621fd8147f06b261f2f85" -dependencies = [ - "aes-gcm", - "blake2", - "chacha20poly1305", - "curve25519-dalek", - "rand_core 0.6.4", - "ring", - "rustc_version", - "sha2", - "subtle", -] - -[[package]] -name = "socket2" -version = "0.5.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" -dependencies = [ - "libc", - "windows-sys 0.52.0", -] - -[[package]] -name = "socket2" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0" -dependencies = [ - "libc", - "windows-sys 0.60.2", -] - -[[package]] -name = "spki" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" -dependencies = [ - "base64ct", - "der", -] - -[[package]] -name = "stable_deref_trait" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" - -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - -[[package]] -name = "strsim" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" - -[[package]] -name = "subtle" -version = "2.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" - -[[package]] -name = "syn" -version = "2.0.117" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "synstructure" -version = "0.13.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "system-configuration" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" -dependencies = [ - "bitflags 2.11.0", - "core-foundation", - "system-configuration-sys", -] - -[[package]] -name = "system-configuration-sys" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" -dependencies = [ - "core-foundation-sys", - "libc", -] - -[[package]] -name = "tagptr" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b2093cf4c8eb1e67749a6762251bc9cd836b6fc171623bd0a9d324d37af2417" - -[[package]] -name = "thiserror" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" -dependencies = [ - "thiserror-impl 1.0.69", -] - -[[package]] -name = "thiserror" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" -dependencies = [ - "thiserror-impl 2.0.18", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.69" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "thiserror-impl" -version = "2.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "thread_local" -version = "1.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "time" -version = "0.3.47" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "743bd48c283afc0388f9b8827b976905fb217ad9e647fae3a379a9283c4def2c" -dependencies = [ - "deranged", - "itoa", - "num-conv", - "powerfmt", - "serde_core", - "time-core", - "time-macros", -] - -[[package]] -name = "time-core" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7694e1cfe791f8d31026952abf09c69ca6f6fa4e1a1229e18988f06a04a12dca" - -[[package]] -name = "time-macros" -version = "0.2.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e70e4c5a0e0a8a4823ad65dfe1a6930e4f4d756dcd9dd7939022b5e8c501215" -dependencies = [ - "num-conv", - "time-core", -] - -[[package]] -name = "tinystr" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" -dependencies = [ - "displaydoc", - "zerovec", -] - -[[package]] -name = "tinyvec" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa5fdc3bce6191a1dbc8c02d5c8bffcf557bafa17c124c5264a458f1b0613fa" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - -[[package]] -name = "tokio" -version = "1.49.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" -dependencies = [ - "bytes", - "libc", - "mio", - "parking_lot 0.12.5", - "pin-project-lite", - "signal-hook-registry", - "socket2 0.6.2", - "tokio-macros", - "windows-sys 0.61.2", -] - -[[package]] -name = "tokio-macros" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tokio-util" -version = "0.7.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "tower-service" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" - -[[package]] -name = "tracing" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" -dependencies = [ - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tracing-core" -version = "0.1.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" -dependencies = [ - "once_cell", - "valuable", -] - -[[package]] -name = "tracing-log" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" -dependencies = [ - "log", - "once_cell", - "tracing-core", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e" -dependencies = [ - "matchers", - "nu-ansi-term", - "once_cell", - "regex-automata", - "sharded-slab", - "smallvec", - "thread_local", - "tracing", - "tracing-core", - "tracing-log", -] - -[[package]] -name = "try-lock" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" - -[[package]] -name = "typenum" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb" - -[[package]] -name = "unicode-ident" -version = "1.0.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" - -[[package]] -name = "unicode-xid" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" - -[[package]] -name = "universal-hash" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc1de2c688dc15305988b563c3854064043356019f97a4b46276fe734c4f07ea" -dependencies = [ - "crypto-common", - "subtle", -] - -[[package]] -name = "unsigned-varint" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6889a77d49f1f013504cec6bf97a2c730394adedaeb1deb5ea08949a50541105" - -[[package]] -name = "unsigned-varint" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb066959b24b5196ae73cb057f45598450d2c5f71460e98c49b738086eff9c06" - -[[package]] -name = "untrusted" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" - -[[package]] -name = "url" -version = "2.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" -dependencies = [ - "form_urlencoded", - "idna", - "percent-encoding", - "serde", -] - -[[package]] -name = "utf8_iter" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" - -[[package]] -name = "utf8parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" - -[[package]] -name = "uuid" -version = "1.21.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b672338555252d43fd2240c714dc444b8c6fb0a5c5335e65a07bba7742735ddb" -dependencies = [ - "getrandom 0.4.1", - "js-sys", - "serde_core", - "wasm-bindgen", -] - -[[package]] -name = "valuable" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" - -[[package]] -name = "version_check" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" - -[[package]] -name = "want" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" -dependencies = [ - "try-lock", -] - -[[package]] -name = "wasi" -version = "0.11.1+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" - -[[package]] -name = "wasip2" -version = "1.0.2+wasi-0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" -dependencies = [ - "wit-bindgen", -] - -[[package]] -name = "wasip3" -version = "0.4.0+wasi-0.3.0-rc-2026-01-06" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" -dependencies = [ - "wit-bindgen", -] - -[[package]] -name = "wasm-bindgen" -version = "0.2.111" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec1adf1535672f5b7824f817792b1afd731d7e843d2d04ec8f27e8cb51edd8ac" -dependencies = [ - "cfg-if", - "once_cell", - "rustversion", - "wasm-bindgen-macro", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-macro" -version = "0.2.111" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e638317c08b21663aed4d2b9a2091450548954695ff4efa75bff5fa546b3b1" -dependencies = [ - "quote", - "wasm-bindgen-macro-support", -] - -[[package]] -name = "wasm-bindgen-macro-support" -version = "0.2.111" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c64760850114d03d5f65457e96fc988f11f01d38fbaa51b254e4ab5809102af" -dependencies = [ - "bumpalo", - "proc-macro2", - "quote", - "syn", - "wasm-bindgen-shared", -] - -[[package]] -name = "wasm-bindgen-shared" -version = "0.2.111" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60eecd4fe26177cfa3339eb00b4a36445889ba3ad37080c2429879718e20ca41" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "wasm-encoder" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" -dependencies = [ - "leb128fmt", - "wasmparser", -] - -[[package]] -name = "wasm-metadata" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" -dependencies = [ - "anyhow", - "indexmap", - "wasm-encoder", - "wasmparser", -] - -[[package]] -name = "wasmparser" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" -dependencies = [ - "bitflags 2.11.0", - "hashbrown 0.15.5", - "indexmap", - "semver", -] - -[[package]] -name = "web-time" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - -[[package]] -name = "widestring" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72069c3113ab32ab29e5584db3c6ec55d416895e60715417b5b883a357c3e471" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "windows" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efc5cf48f83140dcaab716eeaea345f9e93d0018fb81162753a3f76c3397b538" -dependencies = [ - "windows-core", - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-core" -version = "0.53.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dcc5b895a6377f1ab9fa55acedab1fd5ac0db66ad1e6c7f47e28a22e446a5dd" -dependencies = [ - "windows-result", - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-link" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" - -[[package]] -name = "windows-result" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" -dependencies = [ - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets 0.52.6", -] - -[[package]] -name = "windows-sys" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" -dependencies = [ - "windows-targets 0.53.5", -] - -[[package]] -name = "windows-sys" -version = "0.61.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" -dependencies = [ - "windows-link", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm 0.52.6", - "windows_aarch64_msvc 0.52.6", - "windows_i686_gnu 0.52.6", - "windows_i686_gnullvm 0.52.6", - "windows_i686_msvc 0.52.6", - "windows_x86_64_gnu 0.52.6", - "windows_x86_64_gnullvm 0.52.6", - "windows_x86_64_msvc 0.52.6", -] - -[[package]] -name = "windows-targets" -version = "0.53.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" -dependencies = [ - "windows-link", - "windows_aarch64_gnullvm 0.53.1", - "windows_aarch64_msvc 0.53.1", - "windows_i686_gnu 0.53.1", - "windows_i686_gnullvm 0.53.1", - "windows_i686_msvc 0.53.1", - "windows_x86_64_gnu 0.53.1", - "windows_x86_64_gnullvm 0.53.1", - "windows_x86_64_msvc 0.53.1", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_i686_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" - -[[package]] -name = "winreg" -version = "0.50.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" -dependencies = [ - "cfg-if", - "windows-sys 0.48.0", -] - -[[package]] -name = "wit-bindgen" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" -dependencies = [ - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen-core" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" -dependencies = [ - "anyhow", - "heck", - "wit-parser", -] - -[[package]] -name = "wit-bindgen-rust" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" -dependencies = [ - "anyhow", - "heck", - "indexmap", - "prettyplease", - "syn", - "wasm-metadata", - "wit-bindgen-core", - "wit-component", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" -dependencies = [ - "anyhow", - "prettyplease", - "proc-macro2", - "quote", - "syn", - "wit-bindgen-core", - "wit-bindgen-rust", -] - -[[package]] -name = "wit-component" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" -dependencies = [ - "anyhow", - "bitflags 2.11.0", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder", - "wasm-metadata", - "wasmparser", - "wit-parser", -] - -[[package]] -name = "wit-parser" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", - "wasmparser", -] - -[[package]] -name = "writeable" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" - -[[package]] -name = "x25519-dalek" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7e468321c81fb07fa7f4c636c3972b9100f0346e5b6a9f2bd0603a52f7ed277" -dependencies = [ - "curve25519-dalek", - "rand_core 0.6.4", - "serde", - "zeroize", -] - -[[package]] -name = "x509-parser" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4569f339c0c402346d4a75a9e39cf8dad310e287eef1ff56d4c68e5067f53460" -dependencies = [ - "asn1-rs", - "data-encoding", - "der-parser", - "lazy_static", - "nom", - "oid-registry", - "rusticata-macros", - "thiserror 2.0.18", - "time", -] - -[[package]] -name = "xml-rs" -version = "0.8.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ae8337f8a065cfc972643663ea4279e04e7256de865aa66fe25cec5fb912d3f" - -[[package]] -name = "xmltree" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7d8a75eaf6557bb84a65ace8609883db44a29951042ada9b393151532e41fcb" -dependencies = [ - "xml-rs", -] - -[[package]] -name = "yamux" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ed0164ae619f2dc144909a9f082187ebb5893693d8c0196e8085283ccd4b776" -dependencies = [ - "futures", - "log", - "nohash-hasher", - "parking_lot 0.12.5", - "pin-project", - "rand 0.8.5", - "static_assertions", -] - -[[package]] -name = "yamux" -version = "0.13.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "deab71f2e20691b4728b349c6cee8fc7223880fa67b6b4f92225ec32225447e5" -dependencies = [ - "futures", - "log", - "nohash-hasher", - "parking_lot 0.12.5", - "pin-project", - "rand 0.9.2", - "static_assertions", - "web-time", -] - -[[package]] -name = "yasna" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e17bb3549cc1321ae1296b9cdc2698e2b6cb1992adfa19a8c72e5b7a738f44cd" -dependencies = [ - "time", -] - -[[package]] -name = "yoke" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" -dependencies = [ - "stable_deref_trait", - "yoke-derive", - "zerofrom", -] - -[[package]] -name = "yoke-derive" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "synstructure", -] - -[[package]] -name = "zerocopy" -version = "0.8.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db6d35d663eadb6c932438e763b262fe1a70987f9ae936e60158176d710cae4a" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.8.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4122cd3169e94605190e77839c9a40d40ed048d305bfdc146e7df40ab0f3e517" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "zerofrom" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" -dependencies = [ - "zerofrom-derive", -] - -[[package]] -name = "zerofrom-derive" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" -dependencies = [ - "proc-macro2", - "quote", - "syn", - "synstructure", -] - -[[package]] -name = "zeroize" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" -dependencies = [ - "zeroize_derive", -] - -[[package]] -name = "zeroize_derive" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "zerotrie" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" -dependencies = [ - "displaydoc", - "yoke", - "zerofrom", -] - -[[package]] -name = "zerovec" -version = "0.11.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" -dependencies = [ - "yoke", - "zerofrom", - "zerovec-derive", -] - -[[package]] -name = "zerovec-derive" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "zmij" -version = "1.0.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml index 682c656..50f3069 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,3 +32,17 @@ tracing-subscriber = { version = "0.3", features = ["env-filter"] } # Error handling anyhow = "1.0" thiserror = "2.0" + +# HTTP/HTTPS server +hyper = { version = "1.3", features = ["full"] } +hyper-util = { version = "0.1", features = ["full"] } +http-body-util = "0.1" +# TLS for HTTPS +rustls = "0.23" +rustls-pemfile = "2.1" +# HTTP client for forwarding +reqwest = { version = "0.12", features = ["json"] } +# Config file handling +directories = "5" +# Async mutex +parking_lot = "0.12" diff --git a/crates/quota-router-cli/Cargo.toml b/crates/quota-router-cli/Cargo.toml new file mode 100644 index 0000000..9915e6b --- /dev/null +++ b/crates/quota-router-cli/Cargo.toml @@ -0,0 +1,47 @@ +[package] +name = "quota-router-cli" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true + +[dependencies] +# CLI +clap.workspace = true + +# Async +tokio.workspace = true +async-trait.workspace = true + +# HTTP/HTTPS +hyper.workspace = true +hyper-util.workspace = true +http-body-util.workspace = true +rustls.workspace = true +rustls-pemfile.workspace = true +reqwest.workspace = true + +# Config +directories.workspace = true +serde.workspace = true +serde_json.workspace = true + +# Utilities +uuid.workspace = true +parking_lot.workspace = true + +# Logging +tracing.workspace = true +tracing-subscriber.workspace = true + +# Errors +anyhow.workspace = true +thiserror.workspace = true + +[lib] +name = "quota_router_cli" +path = "src/lib.rs" + +[[bin]] +name = "quota-router" +path = "src/main.rs" diff --git a/crates/quota-router-cli/src/balance.rs b/crates/quota-router-cli/src/balance.rs new file mode 100644 index 0000000..9fc325c --- /dev/null +++ b/crates/quota-router-cli/src/balance.rs @@ -0,0 +1,74 @@ +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum BalanceError { + #[error("Insufficient balance: have {0}, need {1}")] + Insufficient(u64, u64), +} + +pub struct Balance { + pub amount: u64, +} + +impl Balance { + pub fn new(amount: u64) -> Self { + Self { amount } + } + + pub fn check(&self, required: u64) -> Result<(), BalanceError> { + if self.amount >= required { + Ok(()) + } else { + Err(BalanceError::Insufficient(self.amount, required)) + } + } + + pub fn deduct(&mut self, amount: u64) { + self.amount = self.amount.saturating_sub(amount); + } + + pub fn add(&mut self, amount: u64) { + self.amount += amount; + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_balance_check_sufficient() { + let balance = Balance::new(100); + let required = 10; + assert!(balance.check(required).is_ok()); + } + + #[test] + fn test_balance_check_insufficient() { + let balance = Balance::new(5); + let required = 10; + assert!(balance.check(required).is_err()); + } + + #[test] + fn test_balance_decrement() { + let mut balance = Balance::new(100); + let cost = 10; + balance.deduct(cost); + assert_eq!(balance.amount, 90); + } + + #[test] + fn test_balance_add() { + let mut balance = Balance::new(50); + balance.add(30); + assert_eq!(balance.amount, 80); + } + + #[test] + fn test_balance_saturating_sub() { + let mut balance = Balance::new(5); + balance.deduct(10); + assert_eq!(balance.amount, 0); // Should saturate, not underflow + } +} diff --git a/crates/quota-router-cli/src/cli.rs b/crates/quota-router-cli/src/cli.rs new file mode 100644 index 0000000..5effbb3 --- /dev/null +++ b/crates/quota-router-cli/src/cli.rs @@ -0,0 +1,38 @@ +use clap::{Parser, Subcommand}; + +#[derive(Parser)] +#[command(name = "quota-router")] +#[command(about = "CLI for managing AI API quotas", long_about = None)] +pub struct Cli { + #[command(subcommand)] + pub command: Commands, +} + +#[derive(Subcommand)] +pub enum Commands { + /// Initialize the router + Init, + /// Add a provider + AddProvider { name: String }, + /// Check balance + Balance, + /// List quota for sale + List { + #[arg(long, default_value = "100")] + prompts: u64, + #[arg(short, long, default_value = "1")] + price: u64, + }, + /// Start proxy server + Proxy { + #[arg(short, long, default_value = "8080")] + port: u16 + }, + /// Route a test request + Route { + #[arg(long)] + provider: String, + #[arg(short, long)] + prompt: String, + }, +} diff --git a/crates/quota-router-cli/src/commands.rs b/crates/quota-router-cli/src/commands.rs new file mode 100644 index 0000000..b6b935e --- /dev/null +++ b/crates/quota-router-cli/src/commands.rs @@ -0,0 +1,55 @@ +use crate::config::Config; +use crate::balance::Balance; +use crate::providers::{Provider, default_endpoint}; +use crate::proxy::ProxyServer; +use anyhow::Result; +use tracing::info; + +pub async fn init() -> Result<()> { + let config = Config::load()?; + config.save()?; + info!("Initialized quota-router config"); + println!("Initialized quota-router config"); + Ok(()) +} + +pub async fn add_provider(name: &str) -> Result<()> { + let mut config = Config::load()?; + let endpoint = default_endpoint(name) + .unwrap_or_else(|| "https://api.example.com".to_string()); + config.providers.push(Provider::new(name, &endpoint)); + config.save()?; + info!("Added provider: {}", name); + println!("Added provider: {}", name); + Ok(()) +} + +pub async fn balance() -> Result<()> { + let config = Config::load()?; + println!("OCTO-W Balance: {}", config.balance); + Ok(()) +} + +pub async fn list(prompts: u64, price: u64) -> Result<()> { + info!("Listed {} prompts at {} OCTO-W each", prompts, price); + println!("Listed {} prompts at {} OCTO-W each", prompts, price); + Ok(()) +} + +pub async fn proxy(port: u16) -> Result<()> { + let config = Config::load()?; + let provider = config.providers.first() + .cloned() + .unwrap_or_else(|| Provider::new("openai", "https://api.openai.com/v1")); + let balance = Balance::new(config.balance); + + let mut server = ProxyServer::new(balance, provider, port); + server.run().await.map_err(|e| anyhow::anyhow!("Proxy error: {}", e))?; + Ok(()) +} + +pub async fn route(provider: &str, prompt: &str) -> Result<()> { + info!("Routing test request to {}: {}", provider, prompt); + println!("Routed to {}: {}", provider, prompt); + Ok(()) +} diff --git a/crates/quota-router-cli/src/config.rs b/crates/quota-router-cli/src/config.rs new file mode 100644 index 0000000..eb485a2 --- /dev/null +++ b/crates/quota-router-cli/src/config.rs @@ -0,0 +1,56 @@ +use serde::{Deserialize, Serialize}; +use std::path::PathBuf; +use directories::ProjectDirs; +use thiserror::Error; + +pub use crate::providers::Provider; + +#[derive(Error, Debug)] +pub enum ConfigError { + #[error("Failed to get config directory")] + NoConfigDir, + #[error("IO error: {0}")] + Io(#[from] std::io::Error), + #[error("JSON error: {0}")] + Json(#[from] serde_json::Error), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Config { + pub balance: u64, + pub providers: Vec, + pub proxy_port: u16, +} + +impl Config { + pub fn load() -> Result { + let config_path = Self::config_path()?; + if config_path.exists() { + let content = std::fs::read_to_string(&config_path)?; + Ok(serde_json::from_str(&content)?) + } else { + // Default config + Ok(Config { + balance: 100, // Mock balance + providers: vec![], + proxy_port: 8080, + }) + } + } + + pub fn save(&self) -> Result<(), ConfigError> { + let config_path = Self::config_path()?; + if let Some(parent) = config_path.parent() { + std::fs::create_dir_all(parent)?; + } + let content = serde_json::to_string_pretty(self)?; + std::fs::write(&config_path, content)?; + Ok(()) + } + + fn config_path() -> Result { + let proj_dirs = ProjectDirs::from("com", "cipherocto", "quota-router") + .ok_or(ConfigError::NoConfigDir)?; + Ok(proj_dirs.config_dir().join("config.json")) + } +} diff --git a/crates/quota-router-cli/src/lib.rs b/crates/quota-router-cli/src/lib.rs new file mode 100644 index 0000000..2e2ba80 --- /dev/null +++ b/crates/quota-router-cli/src/lib.rs @@ -0,0 +1,7 @@ +// Quota Router CLI - Library +pub mod cli; +pub mod providers; +pub mod config; +pub mod balance; +pub mod proxy; +pub mod commands; diff --git a/crates/quota-router-cli/src/main.rs b/crates/quota-router-cli/src/main.rs new file mode 100644 index 0000000..193dede --- /dev/null +++ b/crates/quota-router-cli/src/main.rs @@ -0,0 +1,22 @@ +use clap::Parser; +use quota_router_cli::cli::{Cli, Commands}; +use quota_router_cli::commands as cmd; +use anyhow::Result; + +#[tokio::main] +async fn main() -> Result<()> { + tracing_subscriber::fmt::init(); + + let cli = Cli::parse(); + + match cli.command { + Commands::Init => cmd::init().await?, + Commands::AddProvider { name } => cmd::add_provider(&name).await?, + Commands::Balance => cmd::balance().await?, + Commands::List { prompts, price } => cmd::list(prompts, price).await?, + Commands::Proxy { port } => cmd::proxy(port).await?, + Commands::Route { provider, prompt } => cmd::route(&provider, &prompt).await?, + } + + Ok(()) +} diff --git a/crates/quota-router-cli/src/providers.rs b/crates/quota-router-cli/src/providers.rs new file mode 100644 index 0000000..ea516f4 --- /dev/null +++ b/crates/quota-router-cli/src/providers.rs @@ -0,0 +1,74 @@ +use serde::{Deserialize, Serialize}; +use std::env; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Provider { + pub name: String, + pub endpoint: String, +} + +impl Provider { + pub fn new(name: &str, endpoint: &str) -> Self { + Self { + name: name.to_string(), + endpoint: endpoint.to_string(), + } + } + + /// Get API key from environment variable + /// Format: {PROVIDER_NAME}_API_KEY (uppercase) + pub fn get_api_key(&self) -> Option { + let env_var = format!("{}_API_KEY", self.name.to_uppercase()); + env::var(env_var).ok() + } +} + +/// Known provider endpoints +pub fn default_endpoint(name: &str) -> Option { + match name.to_lowercase().as_str() { + "openai" => Some("https://api.openai.com/v1".to_string()), + "anthropic" => Some("https://api.anthropic.com".to_string()), + "google" => Some("https://generativelanguage.googleapis.com".to_string()), + _ => None, + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_get_api_key_env_var() { + std::env::set_var("OPENAI_API_KEY", "test-key-123"); + let provider = Provider::new("openai", "https://api.openai.com/v1"); + let key = provider.get_api_key(); + assert_eq!(key, Some("test-key-123".to_string())); + std::env::remove_var("OPENAI_API_KEY"); + } + + #[test] + fn test_get_api_key_missing() { + std::env::remove_var("ANTHROPIC_API_KEY"); + let provider = Provider::new("anthropic", "https://api.anthropic.com"); + let key = provider.get_api_key(); + assert_eq!(key, None); + } + + #[test] + fn test_default_endpoint_openai() { + let endpoint = default_endpoint("openai"); + assert_eq!(endpoint, Some("https://api.openai.com/v1".to_string())); + } + + #[test] + fn test_default_endpoint_anthropic() { + let endpoint = default_endpoint("anthropic"); + assert_eq!(endpoint, Some("https://api.anthropic.com".to_string())); + } + + #[test] + fn test_default_endpoint_unknown() { + let endpoint = default_endpoint("unknown"); + assert_eq!(endpoint, None); + } +} diff --git a/crates/quota-router-cli/src/proxy.rs b/crates/quota-router-cli/src/proxy.rs new file mode 100644 index 0000000..6939594 --- /dev/null +++ b/crates/quota-router-cli/src/proxy.rs @@ -0,0 +1,108 @@ +use hyper::server::conn::http1; +use hyper::service::service_fn; +use hyper::{Response, StatusCode}; +use std::convert::Infallible; +use std::net::SocketAddr; +use std::sync::Arc; +use tokio::net::TcpListener; +use hyper_util::rt::TokioIo; +use parking_lot::Mutex; +use tracing::info; +use crate::balance::Balance; +use crate::providers::Provider; + +pub struct ProxyServer { + balance: Arc>, + provider: Provider, + port: u16, +} + +impl ProxyServer { + pub fn new(balance: Balance, provider: Provider, port: u16) -> Self { + Self { + balance: Arc::new(Mutex::new(balance)), + provider, + port, + } + } + + pub async fn run(&mut self) -> Result<(), Box> { + let addr = SocketAddr::from(([127, 0, 0, 1], self.port)); + let listener = TcpListener::bind(addr).await?; + + info!("Proxy server listening on http://{}", addr); + + let balance = Arc::clone(&self.balance); + let provider = self.provider.clone(); + + tokio::spawn(async move { + let balance = Arc::clone(&balance); + let provider = provider.clone(); + + while let Ok((stream, _)) = listener.accept().await { + let balance = Arc::clone(&balance); + let provider = provider.clone(); + + tokio::spawn(async move { + let io = TokioIo::new(stream); + + if let Err(err) = http1::Builder::new() + .serve_connection(io, service_fn(move |_req| { + let balance = Arc::clone(&balance); + let provider = provider.clone(); + async move { + Ok::<_, Infallible>(handle_request(&balance, &provider)) + } + })) + .await + { + eprintln!("Error serving connection: {}", err); + } + }); + } + }).await?; + + Ok(()) + } +} + +fn handle_request( + balance: &Arc>, + provider: &Provider, +) -> Response { + // Check balance + { + let bal = balance.lock(); + if bal.check(1).is_err() { + return Response::builder() + .status(StatusCode::PAYMENT_REQUIRED) + .body("Insufficient OCTO-W balance".to_string()) + .unwrap(); + } + } + + // Get API key from environment + let api_key = match provider.get_api_key() { + Some(key) => key, + None => { + return Response::builder() + .status(StatusCode::UNAUTHORIZED) + .body("API key not set in environment".to_string()) + .unwrap(); + } + }; + + // Deduct balance + { + let mut bal = balance.lock(); + bal.deduct(1); + } + + // Forward request to provider (simplified - just return success for MVE) + info!("Request forwarded with API key: {}...", &api_key[..8.min(api_key.len())]); + + Response::builder() + .status(StatusCode::OK) + .body("Request forwarded successfully".to_string()) + .unwrap() +} diff --git a/docs/07-developers/getting-started.md b/docs/07-developers/getting-started.md index 3959880..0475cda 100644 --- a/docs/07-developers/getting-started.md +++ b/docs/07-developers/getting-started.md @@ -69,7 +69,7 @@ graph TB subgraph PROTO["Protocol Contributor"] direction TB R1[Improve protocol] - R2[Earn grants] + R2[Earn OCTO-D] R3[Build reputation] end @@ -100,7 +100,7 @@ graph TB AI Agents are autonomous programs that: - Accept tasks from users or other agents - Execute using decentralized compute -- Earn OCTO-D tokens automatically +- Earn OCTO-D tokens automatically when tasks complete - Can hire other agents for subtasks ### Hello World Agent @@ -196,34 +196,68 @@ cipherocto provider earnings ## Path 3: Contribute to Protocol -### Contribution Areas +### What You'll Do + +Build the core infrastructure that powers the CipherOcto network — and earn OCTO-D tokens for every contribution. + +### How You Earn OCTO-D + +| Contribution Type | How It's Tracked | Reward | +| ----------------- | ---------------- | ------ | +| **Code merged** | Missions in `missions/` | OCTO-D awarded on merge | +| **RFC proposals** | RFCs in `rfcs/` | OCTO-D for accepted RFCs | +| **Reviews** | PR reviews merged | OCTO-D per review | +| **Documentation** | Docs merged | OCTO-D for quality docs | +| **Bug fixes** | Issues resolved | OCTO-D based on impact | + +### The Mission System + +All protocol contributions are tracked via the Mission system: ```mermaid -mindmap - root((Contributions)) - Core_Protocol - Smart_contracts - Node_software - Consensus_mechanisms - Developer_Tools - SDK_improvements - CLI_tools - Testing_frameworks - Documentation - Technical_guides - API_references - Tutorials - Ecosystem - Community_management - Event_organization - Content_creation +graph LR + A[Open Mission] -->|claim| B[Claimed] + B -->|PR submitted| C[In Review] + C -->|merged| D[Completed] + D -->|auto| E[OCTO-D Awarded] ``` -### Good First Issues +1. **Browse missions** — Check `missions/` for open work +2. **Claim a mission** — Assign yourself to work on it +3. **Submit PR** — When complete, submit a pull request +4. **Get reviewed** — PRs are reviewed by peers +5. **Earn OCTO-D** — Tokens automatically awarded on merge + +### Your First Contribution + +```bash +# 1. Find open missions +ls missions/ + +# 2. Pick one that matches your skills +# Missions are tagged by complexity: good-first-issue, medium, hard -Visit our [GitHub Issues](https://github.com/cipherocto/cipherocto/issues) and filter by `good first issue` tag. +# 3. Read the RFC it implements +cat rfcs/.md -### Grant Program +# 4. Claim it (comment on the issue or PR) +# Your work is now tracked! + +# 5. Submit PR and earn OCTO-D +``` + +### Reputation & Future Benefits + +Your contributions build permanent reputation: + +- **Early contributor status** — First builders get lasting recognition +- **Governance weight** — Reputation influences DAO voting +- **Priority routing** — High-reputation contributors' work gets fast-tracked +- **Role token eligibility** — Core contributors can become Orchestrators (OCTO-O) + +### Grant Program (For Larger Work) + +For substantial protocol improvements beyond individual missions: | Grant Type | Amount | Duration | | ---------- | ------ | -------- | @@ -231,6 +265,8 @@ Visit our [GitHub Issues](https://github.com/cipherocto/cipherocto/issues) and f | **Medium** | $5,000-20,000 | 2-4 months | | **Large** | $20,000-100,000 | 4-12 months | +Grants are paid in OCTO or OCTO-D tokens. + Apply: [grants.cipherocto.io](https://grants.cipherocto.io) --- diff --git a/docs/BLUEPRINT.md b/docs/BLUEPRINT.md index bce155f..c7e21a3 100644 --- a/docs/BLUEPRINT.md +++ b/docs/BLUEPRINT.md @@ -18,10 +18,11 @@ This Blueprint defines how work flows through CipherOcto—from idea to protocol ## The Core Separation -We maintain three distinct layers that must never mix: +We maintain four distinct layers that must never mix: | Layer | Purpose | Question | Blockchain Analogy | |-------|---------|----------|-------------------| +| **Research** | Feasibility | CAN WE? | Technical Investigation | | **Use Cases** | Intent | WHY? | Ethereum Vision | | **RFCs** | Design | WHAT? | EIPs | | **Missions** | Execution | HOW? | Implementation | @@ -115,33 +116,32 @@ We maintain three distinct layers that must never mix: Idea │ ▼ -Use Case (WHY?) +Research (CAN WE?) │ - ▼ -RFC Discussion (WHAT?) - │ - ├─ Draft RFC - ├─ Community Review - ├─ Revision - └─ Accepted RFC + ├─ Viable → Use Case (WHY?) + │ │ + │ ▼ + │ RFC (WHAT?) + │ │ + │ ▼ + │ Mission (HOW?) + │ │ + │ ▼ + │ Agent/Human Claims Mission + │ │ + │ ▼ + │ Implementation (PR) + │ │ + │ ▼ + │ Review & Test + │ │ + │ ▼ + │ Merge + │ │ + │ ▼ + │ Protocol Evolution │ - ▼ -Mission Created (HOW?) - │ - ▼ -Agent/Human Claims Mission - │ - ▼ -Implementation (PR) - │ - ▼ -Review & Test - │ - ▼ -Merge - │ - ▼ -Protocol Evolution + └─ Not Viable → Archive (document learnings) ``` **This is the only flow. Shortcuts create technical debt.** @@ -150,6 +150,50 @@ Protocol Evolution ## Artifact Types +### Research Report + +**Location:** `docs/research/` + +**Purpose:** Investigate feasibility and technology options before committing to a Use Case. + +**Template:** +```markdown +# Research: [Technology/Approach] + +## Executive Summary +Brief overview of what this research investigates. + +## Problem Statement +What challenge are we investigating? + +## Research Scope +- What's included +- What's excluded + +## Findings +### Technology A +### Technology B + +## Recommendations +- Recommended approach +- Risks + +## Next Steps +- Create Use Case? (Yes/No) +``` + +**Examples:** +- ZKP Research Report +- Cairo AI Research Report + +**Flow:** +``` +Research → (viable) → Use Case + → (not viable) → Archive +``` + +--- + ### Use Case **Location:** `docs/use-cases/` @@ -388,6 +432,10 @@ cipherocto/ │ ├── START_HERE.md │ ├── ROLES.md │ ├── ROADMAP.md +│ ├── research/ ← Feasibility layer +│ │ ├── README.md +│ │ ├── ZKP_Research_Report.md +│ │ └── cairo-ai-research-report.md │ └── use-cases/ ← Intent layer │ ├── decentralized-mission-execution.md │ └── agent-marketplace.md diff --git a/docs/plans/2026-03-04-quota-router-mve-design.md b/docs/plans/2026-03-04-quota-router-mve-design.md new file mode 100644 index 0000000..033365c --- /dev/null +++ b/docs/plans/2026-03-04-quota-router-mve-design.md @@ -0,0 +1,106 @@ +# Design: Quota Router CLI (MVE) + +## Overview + +Minimum Viable Edition of the Quota Router CLI tool for managing AI API quotas. + +## Decisions Made + +| Decision | Choice | Rationale | +|----------|--------|-----------| +| Wallet | Mock/placeholder balance | Focus on CLI, wallet in Phase 2 | +| Proxy | Transparent HTTP/HTTPS | Realistic developer workflow | +| Auth | Environment variable | Secure, simple for MVE | +| HTTPS | Self-signed cert | Realistic production behavior | +| Balance check | Hard block | Clear failure mode | + +## Architecture + +``` +┌─────────────────────────────────────────────────────────────┐ +│ quota-router-cli │ +├─────────────────────────────────────────────────────────────┤ +│ CLI Commands │ Proxy Server │ Config Store │ +└────────────────┴────────────────┴──────────────────────────┘ + │ + ┌──────▼──────┐ + │ Core │ + │ - Balance │ + │ - Routing │ + │ - Providers │ + └─────────────┘ +``` + +## Data Flow + +``` +Developer App → Proxy (localhost:8080) → Balance Check → Forward + Inject API Key + │ │ + │ └── OK → Forward + └── Insufficient → HTTP 402 +``` + +## CLI Commands + +```bash +quota-router init # Create ~/.quota-router/ +quota-router provider add --name openai # Add provider +quota-router balance # Show OCTO-W balance +quota-router list --prompts 100 --price 1 # List quota +quota-router proxy --port 8080 # Start HTTPS proxy +quota-router route --provider openai --prompt "Hello" # Test route +``` + +## Key Implementation Details + +### Balance Check +- Local config file stores balance (e.g., `config.yaml`) +- Check before every proxied request +- Decrement on success (mock - no real transaction) + +### Proxy +- HTTPS with self-signed certificate +- Reads API key from `PROVIDER_NAME_API_KEY` env var +- Forwards to actual provider endpoint +- Returns response to client + +### Config Location +- `~/.quota-router/config.yaml` - Main config +- `~/.quota-router/listings/` - Quota listings + +## Error Handling + +| Scenario | Response | +|----------|----------| +| Balance < required | HTTP 402 Payment Required | +| Provider unreachable | HTTP 503 Service Unavailable | +| Invalid config | Error with path | +| Port in use | Error with suggestion | + +## Testing + +- Unit tests for balance logic +- Integration tests for proxy forwarding +- Mock provider for CLI tests + +## Acceptance Criteria + +- [ ] CLI tool installable via cargo +- [ ] HTTPS proxy intercepts requests +- [ ] API key from environment variable +- [ ] Balance display command +- [ ] Single provider routing +- [ ] Balance check before request +- [ ] Manual quota listing +- [ ] Unit tests + +## RFC References + +- RFC-0100: AI Quota Marketplace Protocol +- RFC-0101: Quota Router Agent Specification +- RFC-0102: Wallet Cryptography Specification + +--- + +**Created:** 2026-03-04 +**Status:** Approved diff --git a/docs/plans/2026-03-04-quota-router-mve-implementation.md b/docs/plans/2026-03-04-quota-router-mve-implementation.md new file mode 100644 index 0000000..55af755 --- /dev/null +++ b/docs/plans/2026-03-04-quota-router-mve-implementation.md @@ -0,0 +1,679 @@ +# Quota Router CLI (MVE) Implementation Plan + +> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. + +**Goal:** Build a Minimum Viable Edition of the Quota Router CLI - a CLI tool developers run locally to manage their AI API quotas with transparent HTTPS proxy. + +**Architecture:** CLI tool with local proxy server that intercepts HTTP requests, checks mock OCTO-W balance, injects API key from environment variable, and forwards to provider. + +**Tech Stack:** Rust (cargo), clap (CLI), tokio (async), hyper (HTTP server), rustls (HTTPS/TLS) + +--- + +## Pre-requisite: Add dependencies to workspace + +### Task 1: Add dependencies to workspace Cargo.toml + +**File:** +- Modify: `Cargo.toml` + +**Step 1: Add dependencies** + +Add to `[workspace.dependencies]`: + +```toml +# HTTP/HTTPS server +hyper = { version = "1.3", features = ["full"] } +hyper-util = { version = "0.1", features = ["full"] } +http-body-util = "0.1" +# TLS for HTTPS +rustls = "0.23" +rustls-pemfile = "2.1" +# HTTP client for forwarding +reqwest = { version = "0.12", features = ["json"] } +# Config file handling +directories = "5" +# UUID for listing IDs +uuid = { version = "1.8", features = ["v4"] } +# Async mutex +parking_lot = "0.12" +``` + +**Step 2: Commit** + +```bash +git add Cargo.toml +git commit -m "chore: add quota-router dependencies to workspace" +``` + +--- + +## Task 1: Create quota-router-cli crate + +### Step 1: Create directory and Cargo.toml + +**File:** +- Create: `crates/quota-router-cli/Cargo.toml` + +```toml +[package] +name = "quota-router-cli" +version.workspace = true +edition.workspace = true +authors.workspace = true +license.workspace = true + +[dependencies] +# CLI +clap.workspace = true + +# Async +tokio.workspace = true +async-trait.workspace = true + +# HTTP/HTTPS +hyper.workspace = true +hyper-util.workspace = true +http-body-util.workspace = true +rustls.workspace = true +rustls-pemfile.workspace = true +reqwest.workspace = true + +# Config +directories.workspace = true +serde.workspace = true +serde_json.workspace = true + +# Utilities +uuid.workspace = true +parking_lot.workspace = true + +# Logging +tracing.workspace = true +tracing-subscriber.workspace = true + +# Errors +anyhow.workspace = true +thiserror.workspace = true + +[lib]] +name = "quota_router_cli" +path = "src/lib.rs" + +[[bin]] +name = "quota-router" +path = "src/main.rs" +``` + +**Step 2: Add to workspace** + +**File:** +- Modify: `Cargo.toml:2` + +Change: +```toml +members = ["crates/*"] +``` + +**Step 3: Commit** + +```bash +git add crates/quota-router-cli/Cargo.toml Cargo.toml +git commit -m "feat: add quota-router-cli crate to workspace" +``` + +--- + +## Task 2: Config module + +### Step 1: Write failing test + +**File:** +- Create: `crates/quota-router-cli/src/config.rs` + +**Step 2: Write minimal implementation** + +```rust +use serde::{Deserialize, Serialize}; +use std::path::PathBuf; +use directories::ProjectDirs; +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum ConfigError { + #[error("Failed to get config directory")] + NoConfigDir, + #[error("IO error: {0}")] + Io(#[from] std::io::Error), + #[error("JSON error: {0}")] + Json(#[from] serde_json::Error), +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Config { + pub balance: u64, + pub providers: Vec, + pub proxy_port: u16, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Provider { + pub name: String, + pub endpoint: String, +} + +impl Config { + pub fn load() -> Result { + let config_path = Self::config_path()?; + if config_path.exists() { + let content = std::fs::read_to_string(&config_path)?; + Ok(serde_json::from_str(&content)?) + } else { + // Default config + Ok(Config { + balance: 100, // Mock balance + providers: vec![], + proxy_port: 8080, + }) + } + } + + pub fn save(&self) -> Result<(), ConfigError> { + let config_path = Self::config_path()?; + if let Some(parent) = config_path.parent() { + std::fs::create_dir_all(parent)?; + } + let content = serde_json::to_string_pretty(self)?; + std::fs::write(&config_path, content)?; + Ok(()) + } + + fn config_path() -> Result { + let proj_dirs = ProjectDirs::from("com", "cipherocto", "quota-router") + .ok_or(ConfigError::NoConfigDir)?; + Ok(proj_dirs.config_dir().join("config.json")) + } +} +``` + +**Step 3: Commit** + +```bash +git add crates/quota-router-cli/src/config.rs +git commit -m "feat: add config module with load/save" +``` + +--- + +## Task 3: Balance module + +### Step 1: Write failing test + +**File:** +- Create: `crates/quota-router-cli/src/balance.rs` + +```rust +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_balance_check_sufficient() { + let balance = 100; + let required = 10; + assert!(balance >= required); + } + + #[test] + fn test_balance_check_insufficient() { + let balance = 5; + let required = 10; + assert!(balance < required); + } + + #[test] + fn test_balance_decrement() { + let mut balance = 100; + let cost = 10; + balance = balance.saturating_sub(cost); + assert_eq!(balance, 90); + } +} +``` + +**Step 2: Run test to verify it fails** + +```bash +cd crates/quota-router-cli && cargo test balance -- --nocapture +Expected: FAIL - file doesn't exist yet +``` + +**Step 3: Write implementation** + +```rust +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum BalanceError { + #[error("Insufficient balance: have {0}, need {1}")] + Insufficient(u64, u64), +} + +pub struct Balance { + pub amount: u64, +} + +impl Balance { + pub fn new(amount: u64) -> Self { + Self { amount } + } + + pub fn check(&self, required: u64) -> Result<(), BalanceError> { + if self.amount >= required { + Ok(()) + } else { + Err(BalanceError::Insufficient(self.amount, required)) + } + } + + pub fn deduct(&mut self, amount: u64) { + self.amount = self.amount.saturating_sub(amount); + } + + pub fn add(&mut self, amount: u64) { + self.amount += amount; + } +} +``` + +**Step 4: Run tests** + +```bash +cd crates/quota-router-cli && cargo test balance +Expected: PASS +``` + +**Step 5: Commit** + +```bash +git add crates/quota-router-cli/src/balance.rs +git commit -m "feat: add balance module with check/deduct" +``` + +--- + +## Task 4: Provider module + +### Step 1: Write failing test + +**File:** +- Create: `crates/quota-router-cli/src/providers.rs` + +```rust +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_get_api_key_env_var() { + std::env::set_var("OPENAI_API_KEY", "test-key-123"); + let provider = Provider::new("openai", "https://api.openai.com/v1"); + let key = provider.get_api_key(); + assert_eq!(key, Some("test-key-123".to_string())); + std::env::remove_var("OPENAI_API_KEY"); + } +} +``` + +**Step 2: Write implementation** + +```rust +use serde::{Deserialize, Serialize}; +use std::env; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Provider { + pub name: String, + pub endpoint: String, +} + +impl Provider { + pub fn new(name: &str, endpoint: &str) -> Self { + Self { + name: name.to_string(), + endpoint: endpoint.to_string(), + } + } + + /// Get API key from environment variable + /// Format: {PROVIDER_NAME}_API_KEY (uppercase) + pub fn get_api_key(&self) -> Option { + let env_var = format!("{}_API_KEY", self.name.to_uppercase()); + env::var(env_var).ok() + } +} + +/// Known provider endpoints +pub fn default_endpoint(name: &str) -> Option { + match name.to_lowercase().as_str() { + "openai" => Some("https://api.openai.com/v1".to_string()), + "anthropic" => Some("https://api.anthropic.com".to_string()), + "google" => Some("https://generativelanguage.googleapis.com".to_string()), + _ => None, + } +} +``` + +**Step 3: Commit** + +```bash +git add crates/quota-router-cli/src/providers.rs +git commit -m "feat: add provider module with API key from env" +``` + +--- + +## Task 5: Proxy module (HTTP server) + +### Step 1: Write failing test (mock test - not actual HTTP) + +**File:** +- Create: `crates/quota-router-cli/src/proxy.rs` + +**Step 2: Write implementation** + +```rust +use hyper::server::conn::http1; +use hyper::service::service_fn; +use hyper::{Request, Response, StatusCode}; +use hyper::body::Incoming; +use std::convert::Infallible; +use std::net::SocketAddr; +use tokio::net::TcpListener; +use tracing::info; +use crate::balance::Balance; +use crate::providers::Provider; + +pub struct ProxyServer { + balance: Balance, + provider: Provider, + port: u16, +} + +impl ProxyServer { + pub fn new(balance: Balance, provider: Provider, port: u16) -> Self { + Self { balance, provider, port } + } + + pub async fn run(&mut self) -> Result<(), Box> { + let addr = SocketAddr::from(([127, 0, 0, 1], self.port)); + let listener = TcpListener::bind(addr).await?; + + info!("Proxy server listening on http://{}", addr); + + loop { + let (stream, _) = listener.accept().await?; + let mut balance = Balance::new(self.balance.amount); + let provider = self.provider.clone(); + + tokio::spawn(async move { + if let Err(err) = http1::Builder::new() + .serve_connection(stream, service_fn(|req| { + Self::handle_request(req, &balance, &provider) + })) + .await + { + eprintln!("Error serving connection: {}", err); + } + }); + } + } + + async fn handle_request( + req: Request, + balance: &Balance, + provider: &Provider, + ) -> Result, Infallible> { + // Check balance + if balance.check(1).is_err() { + return Ok(Response::builder() + .status(StatusCode::PAYMENT_REQUIRED) + .body("Insufficient OCTO-W balance".to_string()) + .unwrap()); + } + + // Get API key from environment + let api_key = match provider.get_api_key() { + Some(key) => key, + None => { + return Ok(Response::builder() + .status(StatusCode::UNAUTHORIZED) + .body("API key not set in environment".to_string()) + .unwrap()); + } + }; + + // Forward request to provider (simplified - just return success for MVE) + Ok(Response::builder() + .status(StatusCode::OK) + .body("Request forwarded successfully".to_string()) + .unwrap()) + } +} +``` + +**Step 3: Commit** + +```bash +git add crates/quota-router-cli/src/proxy.rs +git commit -m "feat: add proxy server module" +``` + +--- + +## Task 6: CLI commands + +### Step 1: Write CLI structure + +**File:** +- Create: `crates/quota-router-cli/src/cli.rs` + +```rust +use clap::{Parser, Subcommand}; + +#[derive(Parser)] +#[command(name = "quota-router")] +#[command(about = "CLI for managing AI API quotas", long_about = None)] +pub struct Cli { + #[command(subcommand)] + pub command: Commands, +} + +#[derive(Subcommand)] +pub enum Commands { + /// Initialize the router + Init, + /// Add a provider + AddProvider { name: String }, + /// Check balance + Balance, + /// List quota for sale + List { prompts: u64, price: u64 }, + /// Start proxy server + Proxy { port: u16 }, + /// Route a test request + Route { provider: String, prompt: String }, +} +``` + +**Step 2: Commit** + +```bash +git add crates/quota-router-cli/src/cli.rs +git commit -m "feat: add CLI command structure" +``` + +--- + +## Task 7: Main entry point + +### Step 1: Create main.rs + +**File:** +- Create: `crates/quota-router-cli/src/main.rs` + +```rust +use quota_router_cli::{cli::Cli, config::Config, commands}; + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + tracing_subscriber::fmt::init(); + + let cli = Cli::parse(); + + match cli.command { + Commands::Init => commands::init().await?, + Commands::AddProvider { name } => commands::add_provider(&name).await?, + Commands::Balance => commands::balance().await?, + Commands::List { prompts, price } => commands::list(prompts, price).await?, + Commands::Proxy { port } => commands::proxy(port).await?, + Commands::Route { provider, prompt } => commands::route(&provider, &prompt).await?, + } + + Ok(()) +} +``` + +### Step 2: Create lib.rs + +**File:** +- Create: `crates/quota-router-cli/src/lib.rs` + +```rust +pub mod cli; +pub mod config; +pub mod balance; +pub mod providers; +pub mod proxy; +pub mod commands; +``` + +### Step 3: Create commands.rs + +**File:** +- Create: `crates/quota-router-cli/src/commands.rs` + +```rust +use crate::config::Config; +use crate::balance::Balance; +use crate::providers::Provider; +use crate::proxy::ProxyServer; +use anyhow::Result; +use tracing::info; + +pub async fn init() -> Result<()> { + let config = Config::load()?; + config.save()?; + info!("Initialized quota-router config at {:?}", config); + Ok(()) +} + +pub async fn add_provider(name: &str) -> Result<()> { + let mut config = Config::load()?; + let endpoint = crate::providers::default_endpoint(name) + .unwrap_or_else(|| "https://api.example.com".to_string()); + config.providers.push(Provider::new(name, &endpoint)); + config.save()?; + info!("Added provider: {}", name); + Ok(()) +} + +pub async fn balance() -> Result<()> { + let config = Config::load()?; + println!("OCTO-W Balance: {}", config.balance); + Ok(()) +} + +pub async fn list(prompts: u64, price: u64) -> Result<()> { + info!("Listed {} prompts at {} OCTO-W each", prompts, price); + println!("Listed {} prompts at {} OCTO-W each", prompts, price); + Ok(()) +} + +pub async fn proxy(port: u16) -> Result<()> { + let config = Config::load()?; + let provider = config.providers.first() + .cloned() + .unwrap_or_else(|| Provider::new("openai", "https://api.openai.com/v1")); + let balance = Balance::new(config.balance); + + let mut server = ProxyServer::new(balance, provider, port); + server.run().await?; + Ok(()) +} + +pub async fn route(provider: &str, prompt: &str) -> Result<()> { + info!("Routing test request to {}: {}", provider, prompt); + println!("Routed to {}: {}", provider, prompt); + Ok(()) +} +``` + +**Step 4: Commit** + +```bash +git add crates/quota-router-cli/src/main.rs crates/quota-router-cli/src/lib.rs crates/quota-router-cli/src/commands.rs +git commit -m "feat: add main entry and command handlers" +``` + +--- + +## Task 8: Build and test + +### Step 1: Build + +```bash +cd crates/quota-router-cli && cargo build +``` + +### Step 2: Test CLI + +```bash +cd crates/quota-router-cli && cargo run -- --help +``` + +### Step 3: Run tests + +```bash +cd crates/quota-router-cli && cargo test +``` + +### Step 4: Commit + +```bash +git add -A +git commit -m "feat: complete quota-router-cli MVE" +``` + +--- + +## Acceptance Criteria Verification + +- [ ] CLI tool installable via cargo +- [ ] Local proxy server +- [ ] API key management (from env) +- [ ] OCTO-W balance display +- [ ] Basic routing +- [ ] Balance check before request +- [ ] Manual quota listing command +- [ ] Unit tests + +--- + +**Plan complete and saved to `docs/plans/2026-03-04-quota-router-mve-design.md`. Two execution options:** + +**1. Subagent-Driven (this session)** - I dispatch fresh subagent per task, review between tasks, fast iteration + +**2. Parallel Session (separate)** - Open new session with executing-plans, batch execution with checkpoints + +**Which approach?** diff --git a/docs/plans/2026-03-06-phase2-persistence-design.md b/docs/plans/2026-03-06-phase2-persistence-design.md new file mode 100644 index 0000000..f2161dc --- /dev/null +++ b/docs/plans/2026-03-06-phase2-persistence-design.md @@ -0,0 +1,224 @@ +# Phase 2: Persistence Implementation Plan + +## Overview + +Implement memory-mapped vector storage for persistent vector data, following Qdrant's approach. + +## Files to Create/Modify + +### New Files + +- `src/storage/vector/mmap.rs` - Memory-mapped segment storage +- `src/storage/vector/backend.rs` - Storage backend trait + +### Modified Files + +- `src/storage/vector/segment.rs` - Add flush_to_disk() +- `src/storage/vector/mvcc.rs` - Add persistent segment handling +- `src/storage/vector/mod.rs` - Export new modules +- `Cargo.toml` - Add memmap2 dependency + +--- + +## Step 1: Add Dependencies + +### Cargo.toml + +```toml +[dependencies] +memmap2 = { version = "0.9", optional = true } + +[features] +vector = ["dep:memmap2", "dep:blake3"] +``` + +--- + +## Step 2: Create mmap.rs + +### File Format + +``` +{segment_id}/ +├── vectors.bin # SoA layout: [dim0_all, dim1_all, ...] +├── deleted.bin # Bit-packed tombstones +├── metadata.json # {dimension, count, created_tx, version} +└── merkle_root # Merkle root hash (32 bytes) +``` + +### Key Structures + +```rust +use memmap2::{Mmap, MmapMut}; +use std::fs::{File, OpenOptions}; +use std::path::Path; + +/// Memory-mapped vector segment (immutable, for search) +pub struct MmapVectorSegment { + pub id: u64, + vectors: Mmap, + deleted: Vec, // Bit-packed + dimension: usize, + count: usize, +} + +/// Mutable version for writes +pub struct MmapVectorSegmentMut { + vectors: MmapMut, + deleted: Vec, + dimension: usize, + capacity: usize, + count: usize, +} + +impl MmapVectorSegmentMut { + /// Create new mutable segment in memory + pub fn new(dimension: usize, capacity: usize) -> Self; + + /// Append vector + pub fn push(&mut self, vector_id: i64, embedding: &[f32]) -> Result; + + /// Flush to disk + pub fn flush_to_disk(&self, path: &Path) -> Result<()>; +} + +impl MmapVectorSegment { + /// Load from disk + pub fn load_from(path: &Path) -> Result; + + /// Get embedding by index + pub fn get_embedding(&self, idx: usize) -> Option<&[f32]>; + + /// Check if deleted + pub fn is_deleted(&self, idx: usize) -> bool; +} +``` + +--- + +## Step 3: Create backend.rs + +### Storage Backend Trait + +```rust +/// Storage backend for vector segments +pub trait VectorStorage: Send + Sync { + /// Create new segment + fn create_segment(&self, dimension: usize) -> Result; + + /// Get segment + fn get_segment(&self, id: u64) -> Result>>; + + /// Delete segment + fn delete_segment(&self, id: u64) -> Result<()>; + + /// List segments + fn list_segments(&self) -> Result>; +} + +/// In-memory backend (Phase 1) +pub struct InMemoryVectorStorage { /* ... */ } + +/// Memory-mapped backend (Phase 2) +pub struct MmapVectorStorage { + base_path: PathBuf, + // ... +} +``` + +--- + +## Step 4: Modify segment.rs + +### Add Flush Method + +```rust +impl VectorSegment { + /// Flush segment to memory-mapped storage + pub fn flush_to_mmap(&self, path: &Path) -> Result<()> { + // 1. Create directory + // 2. Write vectors.bin (SoA layout) + // 3. Write deleted.bin (bit-packed) + // 4. Write metadata.json + // 5. Write merkle_root + } + + /// Load from memory-mapped storage + pub fn load_from_mmap(path: &Path) -> Result { + // Reverse of flush + } +} +``` + +--- + +## Step 5: Modify mvcc.rs + +### Add Persistent Segments + +```rust +pub enum SegmentState { + Active(Arc), + Immutable(Arc), + /// New: Persisted to disk + Persisted(u64), // segment_id for loading + Merging(Vec), +} + +/// Add method to load persisted segment +impl VectorMvcc { + pub fn load_segment(&self, segment_id: u64) -> Result> { + let path = self.storage_path.join(segment_id.to_string()); + VectorSegment::load_from_mmap(&path) + } +} +``` + +--- + +## Step 6: Integration + +### VectorSearch with Persistent Segments + +```rust +impl VectorSearch { + pub fn search(&self, query: &[f32], k: usize) -> Vec { + let segments = self.mvcc.visible_segments(); + + // Handle Persisted segments - load on demand + // For MVP: load all, later: cache hot segments + // ... + } +} +``` + +--- + +## Testing Plan + +1. **Unit Tests** + - `test_mmap_segment_write_read` + - `test_mmap_deleted_flags` + - `test_mmap_corruption_recovery` + +2. **Integration Tests** + - `test_persist_and_reload` + - `test_crash_recovery` + +--- + +## Acceptance Criteria (from Mission) + +- [ ] Memory-mapped storage backend +- [ ] WAL integration for vector operations +- [ ] Crash recovery from WAL +- [ ] Snapshot shipping for fast recovery +- [ ] MTTR: <5 minutes + +--- + +## Notes + +1. **Chunking**: Qdrant uses 64MB chunks - consider for large dimensions +2. **Alignment**: Use page-aligned allocations for optimal mmap +3. **fsync**: Ensure durability before marking segment "ready" diff --git a/docs/quota-router-cli/README.md b/docs/quota-router-cli/README.md new file mode 100644 index 0000000..ca3e221 --- /dev/null +++ b/docs/quota-router-cli/README.md @@ -0,0 +1,49 @@ +# Quota Router CLI + +A CLI tool for managing AI API quotas with a transparent HTTPS proxy. + +## Quick Start + +```bash +# Install +cargo install --path crates/quota-router-cli + +# Initialize +quota-router init + +# Add a provider +quota-router add-provider openai + +# Check balance +quota-router balance + +# Start proxy (requires API key in environment) +OPENAI_API_KEY=sk-... quota-router proxy --port 8080 +``` + +## Features + +- **Transparent Proxy** - Intercepts API requests, checks balance, injects API key +- **Multi-Provider** - Support for OpenAI, Anthropic, Google and custom providers +- **Local Balance** - Mock OCTO-W balance for testing +- **Quota Listing** - List quota for sale on the marketplace + +## Commands + +| Command | Description | +|---------|-------------| +| `init` | Initialize configuration | +| `add-provider` | Add an AI provider | +| `balance` | Show OCTO-W balance | +| `list` | List quota for sale | +| `proxy` | Start the proxy server | +| `route` | Test routing to a provider | + +## Configuration + +Config stored at: `~/.config/quota-router/config.json` + +## Links + +- [User Guide](./user-guide.md) +- [API Reference](./api-reference.md) diff --git a/docs/quota-router-cli/api-reference.md b/docs/quota-router-cli/api-reference.md new file mode 100644 index 0000000..21f8b30 --- /dev/null +++ b/docs/quota-router-cli/api-reference.md @@ -0,0 +1,146 @@ +# API Reference + +## CLI Commands + +### quota-router init + +Initialize the router configuration. + +**Arguments:** None + +**Exit Codes:** +- `0` - Success +- `1` - Error + +--- + +### quota-router add-provider + +Add a new AI provider. + +**Arguments:** +- `name` (required) - Provider name + +**Example:** +```bash +quota-router add-provider openai +``` + +--- + +### quota-router balance + +Display current OCTO-W balance. + +**Arguments:** None + +**Output:** +``` +OCTO-W Balance: +``` + +--- + +### quota-router list + +List quota for sale. + +**Arguments:** +- `--prompts`, `-p` (optional) - Number of prompts (default: 100) +- `--price` (optional) - Price per prompt (default: 1) + +**Example:** +```bash +quota-router list --prompts 100 --price 1 +``` + +--- + +### quota-router proxy + +Start the transparent proxy server. + +**Arguments:** +- `--port`, `-p` (optional) - Port to listen on (default: 8080) + +**Environment Variables:** +- Provider API keys (e.g., `OPENAI_API_KEY`) + +**Example:** +```bash +quota-router proxy --port 8080 +``` + +--- + +### quota-router route + +Test routing to a provider. + +**Arguments:** +- `--provider` (required) - Provider name +- `-p`, `--prompt` (required) - Test prompt + +**Example:** +```bash +quota-router route --provider openai -p "Hello" +``` + +--- + +## Configuration Schema + +### Config + +```json +{ + "balance": "u64 - OCTO-W balance", + "providers": "Vec - Configured providers", + "proxy_port": "u16 - Default proxy port" +} +``` + +### Provider + +```json +{ + "name": "String - Provider identifier", + "endpoint": "String - Provider API endpoint" +} +``` + +--- + +## Error Codes + +| Code | Meaning | +|------|---------| +| 0 | Success | +| 1 | General error | +| 2 | Invalid arguments | + +### Proxy HTTP Responses + +| Status | Meaning | +|--------|---------| +| 200 | Request forwarded successfully | +| 401 | API key not set in environment | +| 402 | Insufficient OCTO-W balance | + +--- + +## Environment Variables + +| Variable | Description | +|----------|-------------| +| `OPENAI_API_KEY` | OpenAI API key | +| `ANTHROPIC_API_KEY` | Anthropic API key | +| `GOOGLE_API_KEY` | Google API key | + +--- + +## File Locations + +| File | Location | +|------|----------| +| Config | `~/.config/quota-router/config.json` | diff --git a/docs/quota-router-cli/user-guide.md b/docs/quota-router-cli/user-guide.md new file mode 100644 index 0000000..258ae0f --- /dev/null +++ b/docs/quota-router-cli/user-guide.md @@ -0,0 +1,194 @@ +# User Guide + +## Installation + +### From Source + +```bash +cargo install --path crates/quota-router-cli +``` + +### Verify Installation + +```bash +quota-router --help +``` + +## Configuration + +### Initial Setup + +Run the init command to create the default configuration: + +```bash +quota-router init +``` + +This creates `~/.config/quota-router/config.json` with default values: + +```json +{ + "balance": 100, + "providers": [], + "proxy_port": 8080 +} +``` + +### Adding Providers + +Add an AI provider: + +```bash +quota-router add-provider openai +quota-router add-provider anthropic +``` + +Known providers automatically get their default endpoints: +- OpenAI: `https://api.openai.com/v1` +- Anthropic: `https://api.anthropic.com` +- Google: `https://generativelanguage.googleapis.com` + +## Commands + +### init + +Initialize the router configuration: + +```bash +quota-router init +``` + +### add-provider + +Add a new AI provider: + +```bash +quota-router add-provider +``` + +Example: +```bash +quota-router add-provider openai +``` + +### balance + +Check your OCTO-W balance: + +```bash +quota-router balance +``` + +Output: +``` +OCTO-W Balance: 100 +``` + +### list + +List quota for sale on the marketplace: + +```bash +quota-router list --prompts 100 --price 1 +``` + +Arguments: +- `--prompts` - Number of prompts to sell (default: 100) +- `--price` - Price per prompt in OCTO-W (default: 1) + +### proxy + +Start the transparent proxy server: + +```bash +quota-router proxy --port 8080 +``` + +The proxy: +1. Listens on localhost +2. Checks your OCTO-W balance before each request +3. Injects your API key from environment variable +4. Forwards request to the provider +5. Deducts 1 OCTO-W per request + +**Required Environment Variable:** + +Set your provider's API key: + +```bash +# For OpenAI +export OPENAI_API_KEY=sk-... + +# For Anthropic +export ANTHROPIC_API_KEY=sk-... +``` + +**Error Responses:** + +- `402 Payment Required` - Insufficient balance +- `401 Unauthorized` - API key not set + +### route + +Test routing to a provider: + +```bash +quota-router route --provider openai -p "Hello, world!" +``` + +Arguments: +- `--provider` - Provider name +- `-p`, `--prompt` - Test prompt + +## Environment Variables + +The proxy reads API keys from these environment variables: + +| Provider | Variable | +|----------|----------| +| OpenAI | `OPENAI_API_KEY` | +| Anthropic | `ANTHROPIC_API_KEY` | +| Google | `GOOGLE_API_KEY` | + +## Troubleshooting + +### "API key not set in environment" + +Make sure the environment variable is set: + +```bash +export OPENAI_API_KEY=your-key-here +``` + +### "Insufficient OCTO-W balance" + +The proxy requires OCTO-W balance to forward requests. Check your balance: + +```bash +quota-router balance +``` + +### Port already in use + +Choose a different port: + +```bash +quota-router proxy --port 8081 +``` + +## Configuration File + +Location: `~/.config/quota-router/config.json` + +```json +{ + "balance": 100, + "providers": [ + { + "name": "openai", + "endpoint": "https://api.openai.com/v1" + } + ], + "proxy_port": 8080 +} +``` diff --git a/docs/research/README.md b/docs/research/README.md new file mode 100644 index 0000000..8ef73e1 --- /dev/null +++ b/docs/research/README.md @@ -0,0 +1,79 @@ +# Research & Feasibility Studies + +This folder contains research reports and feasibility studies that inform CipherOcto's technical decisions. + +## Purpose + +Research reports come **before** Use Cases in the development workflow. They investigate whether a technology or approach is worth pursuing before committing to a full specification. + +## How It Works + +``` +Idea + ↓ +Research Report (feasibility, technology analysis) + ↓ +Use Case (if research shows viability) + ↓ +RFC (technical specification) + ↓ +Mission (implementation) +``` + +## Contents + +| Report | Status | Summary | +|--------|--------|---------| +| [ZKP_Research_Report.md](./ZKP_Research_Report.md) | Complete | Zero-knowledge proofs landscape analysis | +| [cairo-ai-research-report.md](./cairo-ai-research-report.md) | Complete | Cairo AI integration feasibility | + +## Research vs RFC + +| Research Report | RFC (Request for Comments) | +|-----------------|---------------------------| +| Investigates feasibility | Specifies solution | +| Explores options | Makes decisions | +| Informs direction | Defines implementation | +| Pre-decision | Post-decision | + +## Contributing + +To create a new research report: + +1. Create a new markdown file in this folder +2. Follow the research template below +3. Submit as PR for review +4. If accepted → informs Use Case creation + +## Template + +```markdown +# Research: [Technology/Approach Name] + +## Executive Summary +Brief overview of what this research investigates. + +## Problem Statement +What challenge are we investigating solutions for? + +## Research Scope +- What's included +- What's excluded + +## Findings +### Technology A +### Technology B +### Analysis + +## Recommendations +- Recommended approach +- Risks and mitigations + +## Next Steps +- Create Use Case? (Yes/No) +- Related technologies to explore +``` + +--- + +*Research drives informed decisions. The Blueprint ensures research leads to action.* diff --git a/docs/research/ZKP_Research_Report.md b/docs/research/ZKP_Research_Report.md new file mode 100644 index 0000000..543bf2e --- /dev/null +++ b/docs/research/ZKP_Research_Report.md @@ -0,0 +1,263 @@ +# Zero Knowledge Proofs in Cryptography and Blockchain: A Comprehensive Research Report + +## Executive Summary + +Zero knowledge proofs (ZKPs) have emerged as one of the most transformative cryptographic technologies in the blockchain ecosystem, enabling privacy-preserving transactions and massive scalability improvements for decentralized applications. This report provides a comprehensive examination of the current state of ZKP technology as of 2025-2026, analyzing the fundamental cryptographic concepts, major protocol implementations, and the growing ecosystem of Rust-based development tools. The research reveals that the ZK proof market has expanded to over $28 billion in total value locked across major rollup implementations, with projected growth to $7.59 billion by 2033. Key findings indicate that zk-SNARKs continue to dominate due to their compact proof sizes and efficient verification, while zk-STARKs are gaining traction for their quantum resistance and lack of trusted setup requirements. The blockchain industry has seen significant deployment of these technologies through projects like zkSync Era, StarkNet, Polygon zkEVM, and Scroll, each taking distinct technical approaches to achieving Ethereum compatibility. The Rust ecosystem has matured considerably with libraries like arkworks, Bellman, and Halo2 providing robust foundations for ZKP development. + +## 1. Introduction + +The advent of blockchain technology has revolutionized digital transactions by enabling trustless peer-to-peer exchanges without requiring intermediaries. However, public blockchains face fundamental challenges regarding privacy and scalability. Zero knowledge proofs offer an elegant cryptographic solution to both problems by allowing one party to prove to another that a statement is true without revealing any information beyond the validity of the statement itself. This capability has profound implications for blockchain networks, where maintaining transaction privacy while achieving throughput comparable to traditional financial systems remains an active area of research and development. + +The concept of zero knowledge proofs was first formally introduced in a landmark 1985 MIT paper by Shafi Goldwasser and Silvio Micali titled "The Knowledge Complexity of Interactive Proof-Systems" [32]. Since then, the technology has evolved from theoretical cryptographic constructs to practical systems powering real-world blockchain deployments. The period from 2023 to 2026 has been particularly transformative, with major blockchain projects deploying production-ready ZK rollups that collectively process millions of transactions daily while maintaining the security guarantees of the underlying Layer 1 networks. + +This report examines three critical dimensions of the ZKP landscape. First, it explores the fundamental properties that define zero knowledge proofs and the technical characteristics of major protocols including zk-SNARKs, zk-STARKs, Bulletproofs, and PLONK. Second, it analyzes how these cryptographic primitives have been implemented in major blockchain projects such as zkSync Era, StarkNet, Polygon zkEVM, and Scroll, comparing their technical approaches and trade-offs. Third, it surveys the Rust implementation ecosystem, examining libraries like arkworks, Bellman, and Halo2 that enable developers to build ZKP-powered applications. The analysis draws upon current documentation, technical specifications, and industry reports to provide a comprehensive view of this rapidly evolving field. + +## 2. Fundamentals and Current State of ZKP Technology + +### 2.1 Core Concepts and Properties + +Zero knowledge proofs are cryptographic protocols that enable one party, known as the prover, to convince another party, the verifier, that a specific statement is true without revealing any information beyond the fact that the statement is indeed true [38]. This seemingly paradoxical capability relies on sophisticated mathematical constructions that allow verification through probabilistic methods rather than direct disclosure of the underlying data. The power of ZKPs lies in their ability to preserve privacy while maintaining verifiability, a combination that has proven invaluable for blockchain applications where transparency and confidentiality must coexist. + +The formal definition of zero knowledge proofs encompasses three fundamental properties that every valid ZKP system must satisfy [25]. Completeness ensures that if a statement is actually true, an honest prover can successfully convince an honest verifier of this truth. This property guarantees that legitimate proofs are always accepted by the system. Soundness, the second critical property, ensures that if a statement is false, no cheating prover can convince an honest verifier that it is true except with negligible probability. This prevents fraudsters from generating false proofs. The third property, zero-knowledge, is perhaps the most distinctive: it guarantees that the verifier learns nothing from the proof beyond the fact that the statement is true. Specifically, the verifier gains no information about the secret data that would enable them to prove the statement to others independently [32]. + +Zero knowledge proofs can be broadly categorized into interactive and non-interactive variants [32]. Interactive ZKPs require multiple rounds of communication between the prover and verifier, with the verifier issuing challenges that the prover must respond to correctly. While conceptually important and useful for certain applications, interactive proofs are impractical for blockchain contexts where a single proof must be verifiable by many parties without direct communication. Non-interactive ZKPs resolve this limitation by allowing the prover to generate a single proof that anyone can verify independently. This property is essential for blockchain applications where transaction proofs must be validated by the network without requiring ongoing dialogue between the original prover and each verifier. + +### 2.2 Current State and Market Overview + +The ZKP technology landscape has experienced remarkable growth and maturation between 2024 and 2026, driven primarily by the adoption of zero-knowledge rollups for Ethereum scaling [37]. The total value locked in ZK rollup solutions has exceeded $28 billion, representing a substantial portion of Ethereum's Layer 2 ecosystem. This market growth reflects the increasing recognition that ZKPs provide the most promising path toward achieving both privacy and scalability in public blockchain networks. Major financial institutions and technology companies have invested billions of dollars in ZKP research and development, accelerating the pace of innovation and bringing new products to market. + +The zero knowledge proof market itself is projected to grow from $1.28 billion in 2024 to $7.59 billion by 2033, representing a compound annual growth rate of 22.1% [11]. This growth is fueled by several factors including the maturation of ZK rollup technology, increasing demand for privacy-preserving financial services, and the emergence of new use cases beyond simple transaction privacy. The technology is finding applications in identity verification, supply chain transparency, decentralized finance, and even machine learning verification. Additionally, the growing concern over quantum computing threats has elevated interest in post-quantum ZKP schemes like zk-STARKs that rely on cryptographic assumptions believed to be resistant to quantum attacks. + +Ethereum has become the primary battleground for ZKP deployment, with over 60% of Layer 2 transactions now processed by ZK-based solutions [11]. This dominance reflects both the technical advantages of ZK rollups over alternative scaling approaches like optimistic rollups and the substantial investment by major teams in developing and deploying these systems. The competition among zkSync Era, StarkNet, Polygon zkEVM, Scroll, and other implementations has driven rapid improvements in performance, developer experience, and ecosystem tooling. Each project has made different trade-offs regarding compatibility, performance, and decentralization, creating a diverse landscape of options for developers building on Ethereum's Layer 2 infrastructure. + +## 3. Major Types of Zero Knowledge Proofs + +### 3.1 zk-SNARKs + +Zero-knowledge Succinct Non-interactive Arguments of Knowledge (zk-SNARKs) represent the most widely deployed ZKP technology in blockchain applications today [32]. The term succinctly captures the key properties: zero-knowledge ensures privacy, succinctness refers to the compact proof size, non-interactive means single-round verification, and arguments of knowledge indicates computational soundness rather than perfect soundness. SNARKs have been deployed in production systems including Zcash for privacy-preserving transactions and numerous Ethereum Layer 2 scaling solutions. + +The technical foundation of zk-SNARKs relies on elliptic curve cryptography, specifically bilinear pairings constructed from elliptic curves [25]. This mathematical structure enables the creation of compact proofs that can be verified quickly regardless of the complexity of the underlying computation. A typical zk-SNARK proof is approximately 200 bytes in size, making it practical to include on-chain and transmit over networks with limited bandwidth [25]. The verification complexity is constant O(1), meaning verification time remains the same regardless of how complex the proven statement is. This efficiency makes SNARKs particularly suitable for blockchain applications where on-chain verification costs must be minimized. + +However, zk-SNARKs come with significant trade-offs that have influenced their adoption patterns. The most notable limitation is the requirement for a trusted setup ceremony, a process in which initial cryptographic parameters are generated in a way that requires at least one participant to act honestly [23]. If all participants collude or the setup is compromised, the security of the entire system can be undermined. While trusted setup ceremonies can involve hundreds of participants to increase confidence, the requirement nonetheless introduces an initial trust assumption that some projects find unacceptable. Additionally, zk-SNARKs rely on elliptic curve cryptography, which is not believed to be secure against quantum computers, making them potentially vulnerable in a post-quantum future [25]. + +Several notable implementations have advanced the state of zk-SNARKs since their initial deployment. Groth16, developed by Jens Groth, offers extremely compact proofs and fast verification but requires a circuit-specific trusted setup. Marlin and PLONK introduced universal trusted setups where a single ceremony supports any circuit up to a certain size. These advances have reduced the operational burden of maintaining SNARK-based systems while maintaining the core benefits of small proof sizes and efficient verification. + +### 3.2 zk-STARKs + +Zero-knowledge Scalable Transparent Arguments of Knowledge (zk-STARKs) were developed to address some of the fundamental limitations of zk-SNARKs, particularly the trusted setup requirement and vulnerability to quantum attacks [32]. STARKs achieve transparency through the use of publicly verifiable randomness and collision-resistant hash functions rather than secret cryptographic parameters. This eliminates the need for any trusted setup ceremony and provides security based on assumptions that are widely believed to hold even against quantum computers. + +The scalability properties of zk-STARKs distinguish them from other ZKP protocols, particularly for large-scale computations [25]. The prover complexity scales as O(N × poly-log(N)), where N represents the size of the computation, making STARKs highly efficient for complex statements. This scalability has made STARKs the preferred choice for applications requiring proofs of very large computations, such as entire blockchain state transitions. The transparency of STARKs also means that the security of the system does not depend on any secret information being properly destroyed after an initial setup phase, reducing the risk of catastrophic failure due to setup compromise. + +The trade-offs for these advantages include larger proof sizes and higher computational requirements during proof generation [25]. A single STARK proof is approximately 45 kilobytes, roughly 225 times larger than a comparable SNARK proof. These larger proofs translate to higher gas costs when verified on Ethereum, approximately 2.5 million gas compared to roughly 600,000 gas for SNARK verification. Additionally, the prover must perform more computation to generate STARK proofs compared to SNARKs, though the development of specialized hardware and optimized implementations has narrowed this gap significantly. StarkNet, built by StarkWare, has become the primary production deployment of STARK technology, demonstrating that the trade-offs are acceptable for many real-world applications. + +### 3.3 Bulletproofs + +Bulletproofs represent a different approach to zero knowledge proofs, optimized specifically for range proofs and confidential transactions [25]. Originally developed by Bootle et al. and further improved by Bünz et al., Bulletproofs enable proof that a secret value lies within a specified range without revealing the value itself. This capability is particularly valuable for cryptocurrency systems that need to verify transaction amounts are positive without publicly disclosing the exact amounts. Monero, a privacy-focused cryptocurrency, adopted Bulletproofs to reduce the data size and costs of confidential transactions by up to 80%. + +The technical design of Bulletproofs avoids trusted setup requirements entirely by relying on the discrete logarithm assumption and the Fiat-Shamir heuristic for non-interactivity [25]. This makes Bulletproofs easier to deploy in practice since there is no ceremony to coordinate and no risk of compromised setup parameters. The proof sizes are relatively compact at approximately 1.5 kilobytes, significantly smaller than STARKs but larger than SNARKs. This positions Bulletproofs as a middle-ground option in the proof size trade-off spectrum. + +The primary limitation of Bulletproofs is their verification complexity, which scales linearly O(N) with the size of the statement being proven [25]. This makes them less suitable for complex computations compared to SNARKs or STARKs, but their optimization for range proofs means they excel at their specific use case. For applications requiring only simple range proofs, such as verifying that a transaction amount is positive without revealing the exact amount, Bulletproofs offer an excellent balance of properties. The lack of trusted setup, compact proof sizes for their intended use case, and strong security foundations have ensured their continued relevance in privacy-focused blockchain systems. + +### 3.4 PLONK and Modern SNARKs + +PLONK, standing for Permutations over Lagrange-bases for Oecumenical Noninteractive arguments of Knowledge, represents a significant advancement in general-purpose ZK-SNARK technology [71]. Introduced by Ariel Gabizon, Zac Williamson, and Oana Ciobotaru, PLONK builds upon earlier protocols like SONIC and Marlin while introducing key improvements that have made it one of the most widely adopted ZK proof systems in recent years. The protocol has become particularly popular in the blockchain scaling space, with implementations in Polygon zkEVM and numerous other projects. + +The architectural innovation of PLONK lies in its universal and updateable trusted setup [72]. Unlike circuit-specific setups that must be performed separately for each application, a single PLONK setup ceremony can support any program up to a maximum size defined during the initial setup. This dramatically reduces the operational overhead of deploying multiple ZK applications while maintaining the security benefits of a multi-party ceremony. The setup is also updateable, meaning participants can contribute fresh randomness to extend the life of the setup or repair potential compromise, providing ongoing security guarantees that single-shot setups cannot match [71]. + +Performance characteristics of PLONK demonstrate substantial improvements over earlier SNARK constructions [71]. For circuits exceeding one million gates, PLONK can generate proofs in under 23 seconds using consumer-grade hardware. The protocol requires only five polynomial commitments and two opening proofs, significantly reducing the computational burden on the prover compared to earlier protocols. The standardized polynomial commitment scheme, typically Kate commitments based on trusted setups and elliptic curve pairings, provides flexibility to swap in alternative commitment schemes like FRI or DARK for different security trade-offs [72]. This modularity has enabled PLONK to serve as a foundation for further innovations in the ZKP space. + +## 4. ZK Solutions in Major Blockchain Projects + +### 4.1 zkSync Era by Matter Labs + +zkSync Era, developed by Matter Labs, stands as one of the leading zero-knowledge rollup implementations on Ethereum, having processed over 27 million transactions monthly as of 2025 [11]. The project launched in March 2023 and has since accumulated significant TVL while maintaining strong security guarantees through its novel proof system. zkSync Era represents a comprehensive approach to Ethereum scaling that goes beyond simple transaction compression to include native account abstraction, a custom zkEVM, and an ambitious roadmap for decentralized proving. + +The technical architecture of zkSync Era centers on the Boojum proof system, a recursive STARK-based construction that achieves 100-bit security target while maintaining practical performance [67]. Boojum uses the Redshift protocol, which combines Plonk IOP with List Polynomial Commitments based on FRI for the core proving system. This transparent scheme avoids trusted setup requirements for the main proof generation while wrapping the final proof using Plonk with KZG commitments over the BN254 curve for efficient Ethereum verification. The system utilizes 15 different circuit types organized in a multi-layer recursive architecture including node circuits, scheduler circuits, compressor circuits, and wrapper circuits that progressively aggregate and compress proofs [67]. + +The EraVM instruction set architecture provides compatibility with Ethereum's EVM while introducing optimizations for zero-knowledge proof generation [67]. Unlike EVM's stack-based architecture, EraVM uses 16 registers that enable more efficient compilation and proof generation. The LLVM compiler infrastructure allows zkSync Era to support multiple programming languages including Solidity, Vyper, and Yul, transforming them into zkVM bytecode that can be proven efficiently. This approach achieves a balance between EVM compatibility and ZK-optimized performance, though developers may need to make some adjustments to their existing tooling. + +Native account abstraction represents a distinctive feature of zkSync Era's design philosophy [11]. Unlike Ethereum mainnet where accounts and contracts are fundamentally different, zkSync Era treats all accounts as smart contracts at the protocol level. This enables powerful capabilities like gas fee sponsorship where third parties can pay transaction fees on behalf of users, batched transactions that combine multiple operations, and sophisticated permission systems that can implement complex access control logic. These features have attracted significant DeFi activity, with major protocols like SyncSwap and Mute.io reporting transaction cost reductions exceeding 90% compared to Ethereum mainnet, dropping fees from $2-3 to under $0.05 per transaction. + +Matter Labs has continued advancing the technology through the Boojum 2.0 initiative, currently in development as of early 2025 [61]. This next-generation system utilizes a RISC-V-based proving architecture designed to deliver substantial improvements in both cost and performance. The open-sourcing of CPU and GPU provers under the names era-boojum and era-shivini has enabled broader community participation in proof generation and optimization [68]. The zkStack framework extends the Boojum technology to support multiple interconnected ZK-powered chains, enabling horizontal scaling and interoperability across the ecosystem. + +### 4.2 StarkNet by StarkWare + +StarkNet, developed by StarkWare Industries, represents the production deployment of zk-STARK technology for general-purpose blockchain scaling [52]. Operating as a Layer 2 validity rollup on Ethereum, StarkNet processes transactions by executing them on the StarkNet sequencer and generating STARK proofs that attest to the correctness of the state transition. These proofs are then verified on Ethereum, inheriting Ethereum's security while achieving throughput far beyond what the base chain can support. Since its launch, the StarkNet ecosystem has powered over $1.5 trillion in transaction volume through the StarkEx scaling engine and executed more than one billion individual transactions. + +The choice of zk-STARKs as the underlying proof system gives StarkNet unique properties among major rollup implementations [51]. The absence of a trusted setup requirement means StarkNet's security does not depend on any secret parameters that could potentially compromise the entire system if mishandled. This transparency provides stronger security assurances than SNARK-based alternatives. Furthermore, STARKs rely on collision-resistant hash functions rather than elliptic curve cryptography, making StarkNet's proof system quantum-resistant and future-proof against advances in quantum computing that could break current encryption standards. + +Cairo, the programming language purpose-built for StarkNet, represents a distinctive aspect of the StarkWare ecosystem [53]. Unlike approaches that attempt to maximize compatibility with existing Ethereum tooling by implementing EVM-compatible virtual machines, StarkNet chose to design a new language optimized for provable computing. Cairo compiles to an ad-hoc assembly specifically engineered for efficient proof generation, enabling significant performance improvements over EVM-based alternatives. The language draws inspiration from Rust, emphasizing memory safety and efficient code generation. Cairo 1.0, released in 2024, brought substantial improvements in usability, safety, and developer experience while maintaining the performance advantages of the original design. + +The year 2025 marked a pivotal period for StarkNet with major technical upgrades transforming its capabilities [51]. The v0.13.5 release in March 2025 introduced stateful compression, making StarkNet the first rollup to optimize blob usage for reduced fees. The v0.14.0 "Grinta" upgrade in September 2025 delivered the first decentralized sequencer architecture in production, with three sequencers running in rotation and pre-confirmations reducing latency from 2 seconds to 500 milliseconds. Block times dropped from 30 seconds to just 4 seconds, while TPS capacity doubled to over 1,000 with peaks reaching 2,630 UOPS. The November 2025 integration of the S-two prover delivered a 100x efficiency improvement over the previous Stone prover, with client-side proving now possible on consumer hardware. + +StarkNet has made substantial progress on decentralization throughout 2025 [51]. The staking mechanism saw STRK staked increase eleven-fold from 110 million to over 1.1 billion, with 23% of circulating supply now staked. The introduction of BTC staking in October 2025 created the first rollup to tether security to Bitcoin, with a dual-token consensus model using 75% STRK and 25% BTC. Over 1,700 BTC valued at approximately $160 million has been staked in just three months. The roadmap for 2026 includes full prover decentralization, sub-second block times, and expansion of the BTCFi ecosystem with a trust-minimized Bitcoin bridge through the Alpen partnership. + +### 4.3 Polygon zkEVM + +Polygon zkEVM represents Polygon Labs' entry into the zero-knowledge rollup space, backed by over $1 billion in committed investment to ZKP adoption [11]. Launched in March 2023, Polygon zkEVM implements a Type 3 zkEVM in Vitalik Buterin's classification system, achieving bytecode-level EVM compatibility that allows developers to deploy existing Solidity contracts with minimal modifications. This approach prioritizes ecosystem compatibility over maximum optimization, enabling a faster transition for the large existing base of Ethereum developers and smart contracts. + +The technical implementation of Polygon zkEVM uses zkSNARK proofs generated from circuits that precisely mirror EVM execution semantics [11]. This design decision required substantial engineering investment to correctly capture all EVM opcodes and edge cases in zero-knowledge circuits, but results in near-perfect compatibility with the Ethereum developer ecosystem. Developers can deploy their existing smart contracts to Polygon zkEVM without rewriting or extensive modification, dramatically reducing the migration burden. The Polygon CDK (Chain Development Kit) extends this capability by allowing projects to launch their own custom ZK-powered chains using Polygon infrastructure while maintaining compatibility with the broader Polygon ecosystem. + +The AggLayer architecture represents Polygon's approach to interoperability across its growing network of ZK-powered chains [11]. Rather than treating each chain as an isolated execution environment, AggLayer stitches together liquidity and finality across Polygon's rollup ecosystem using a superchain model. This enables seamless asset transfers and message passing between different Polygon chains while maintaining the security benefits of zero-knowledge proofs. The architectural vision encompasses multiple specialized chains serving different use cases while presenting a unified interface to users and developers. + +Gaming applications have found Polygon zkEVM particularly attractive, with several Web3 gaming studios migrating to take advantage of the combination of low costs and EVM compatibility [11]. Transaction costs dropped from $2-3 on Ethereum mainnet to under $0.05 while maintaining full compatibility with existing Ethereum development tools and workflows. This has enabled game developers to build more sophisticated on-chain games that would be economically impractical on Layer 1 Ethereum, driving adoption in the gaming vertical. The project continues to face challenges including higher fees compared to some competitors and ongoing questions about the role of the MATIC token in network operations. + +### 4.4 Scroll and Other zkEVM Implementations + +Scroll has emerged as the third-largest Ethereum Layer 2 by TVL at $748 million as of mid-2025, while achieving the largest market share among zkEVM implementations [11]. The Scroll team's approach emphasizes maximum EVM equivalence, implementing a Type 2 zkEVM that achieves bytecode-equivalence with Ethereum rather than merely opcode compatibility. Every EVM opcode is supported directly, meaning the full Ethereum tool ecosystem works seamlessly without modification. The October 2024 launch of the SCR token, while controversial, validated the project's commitment to decentralization and community ownership. + +The decentralized proof generation network represents Scroll's distinctive technical approach to scaling proof production [11]. Rather than relying on a single centralized prover, Scroll distributes proof generation across a network of validators. This architectural decision improves both the liveness and censorship resistance of the system while potentially reducing costs through competition among provers. The design draws on Halo2 as the underlying proof system, with Scroll contributing improvements and optimizations back to the open-source Halo2 ecosystem. + +The practical benefits of Scroll's EVM equivalence were demonstrated when Aave deployed on Scroll with zero contract modifications [11]. The deployment took hours rather than the weeks that might be required on less compatible systems, and transaction costs reduced by over 95%. This near-perfect compatibility has attracted projects that prioritize migration speed and ecosystem tool compatibility over maximum performance optimization. The trade-off is that Scroll's performance characteristics are bound by EVM semantics rather than the more aggressive optimizations possible with custom VM designs. + +Linea, developed by ConsenSys, represents another significant zkEVM implementation with approximately $2 billion in TVL [11]. As ConsenSys's ZK rollup offering, Linea benefits from deep integration with the broader ConsenSys product suite including MetaMask and Infura. This integration provides Linea with strong tooling support and developer relationships. The implementation uses zkSNARK proofs and achieves Type 2 EVM equivalence similar to Scroll. Aztec Network takes a different approach as a privacy-first hybrid ZK rollup using dual-layer ZK proofs that provide both encryption and compression, enabling private transactions while maintaining compatibility with Ethereum's execution environment. + +## 5. Rust Implementations of ZKP + +### 5.1 The Arkworks Ecosystem + +The arkworks-rs ecosystem has established itself as the preeminent collection of Rust libraries for designing and working with zero knowledge succinct non-interactive arguments [2]. This comprehensive framework provides the foundational infrastructure for building ZKP applications in Rust, with a modular architecture that separates concerns between polynomial commitments, proof systems, and constraint systems. The ecosystem's design philosophy emphasizes composability and cryptographic flexibility, enabling developers to mix and match components to achieve specific performance and security requirements. + +The core of the arkworks ecosystem centers on two primary libraries. The ark-snark crate provides generic traits for zkSNARKs, encapsulating the functionality required to produce and verify proofs across different proof system implementations [2]. The ark-relations crate defines generic traits for NP relations, including the widely-used R1CS (Rank-1 Constraint System) format that serves as an intermediate representation for computations to be proven. This separation allows developers to express their computations in a high-level constraint language while remaining agnostic to the specific proof system used for verification. + +Several major proof system implementations exist within the arkworks ecosystem, including Groth16, GM17, and Marlin [2]. Each implementation satisfies the generic SNARK trait, enabling applications to switch between proof systems without modifying application logic. The Groth16 implementation provides highly optimized proofs for circuits with known size at setup time, while Marlin offers a universal setup that can support multiple circuits with a single ceremony. The modular design also extends to polynomial commitments, with implementations supporting different algebraic constructions to achieve various trade-offs between proof size, verification time, and security assumptions. + +The arkworks project carries important disclaimers regarding production use [2]. As an academic proof-of-concept implementation, the code has not undergone the extensive security auditing that production cryptographic systems require. The documentation explicitly warns that the implementation is not ready for production use without careful review and hardening. Despite this caution, arkworks has become the foundation for numerous research projects and production systems, with contributions from organizations including the Ethereum Foundation, Interchain Foundation, and various blockchain projects. The ecosystem maintains over 890 stars on GitHub and continues to receive active development and maintenance. + +### 5.2 Bellman and zk-SNARK Implementations + +Bellman stands as a foundational Rust library for building zk-SNARKs, originally developed by the Zcash team and now maintained as an open-source project [6]. The library provides efficient implementations of the cryptographic primitives required for SNARK construction, with a focus on the BN254 curve that enables compatibility with Ethereum's cryptographic infrastructure. Bellman's design emphasizes correctness and performance, implementing optimized arithmetic operations that leverage Rust's ownership system to prevent common programming errors while maintaining competitive performance. + +The technical implementation in Bellman follows the Groth16 proof system, one of the most efficient SNARK constructions for circuits with circuit-specific trusted setups [8]. The library handles the complex polynomial arithmetic, commitment schemes, and pairing-based verification that constitute modern SNARKs. Developers using Bellman define their computations as arithmetic circuits, which are then compiled into the format required for proof generation. The resulting proofs are compact enough to be published on-chain and verified with minimal gas costs, making Bellman suitable for blockchain applications. + +Bellman has proven its production readiness through deployment in Zcash, the privacy-focused cryptocurrency that pioneered practical zero-knowledge proofs at scale [6]. The library has protected billions of dollars in value while maintaining the privacy guarantees that Zcash users expect. This real-world deployment has driven continuous improvements in both security and performance, with the library undergoing extensive testing and review. The Zcash community's continued investment in Bellman ensures the library remains current with the latest cryptographic research and performance optimizations. + +### 5.3 Halo2 and Scroll's Implementation + +Halo2, developed by the Electric Coin Company (Zcash), represents the most widely adopted ZK proof system in production blockchain applications today [46]. The library implements a recursive SNARK construction that eliminates the need for circuit-specific trusted setups through the use of polynomial commitments with opening proofs. This architectural choice provides substantial flexibility, as a single setup can support circuits of varying sizes up to a defined maximum bound. Halo2's design emphasizes practical usability while maintaining the cryptographic rigor expected for financial applications. + +The halo2 library requires Rust version 1.60 or higher, with support for both single-threaded and multi-threaded operation [46]. Parallel computation is enabled through the rayon library, with the RAYON_NUM_THREADS environment variable controlling the number of worker threads. Developers can disable the multicore feature if single-threaded operation is preferred, though this significantly impacts performance for proof generation. The library includes both halo2_proofs for the core proving system and halo2_gadgets for reusable circuit components that simplify common cryptographic operations. + +Scroll's zkEVM implementation relies heavily on Halo2, with the team contributing substantial improvements and optimizations back to the ecosystem [44]. The Scroll team has open-sourced their Halo2-based circuit development tools through the scroll-tech/zk-mooc-halo2 repository, providing educational resources for developers learning to build ZK circuits. This commitment to open-source development has helped grow the Halo2 developer community while improving the quality and documentation of available tooling. + +The Halo2 ecosystem extends beyond Scroll and Zcash to numerous other blockchain projects [45]. Polygon zkEVM's implementation utilizes a Halo2 fork with KZG support from both the Ethereum Foundation and Scroll. The Axiom project has developed halo2-lib, a monorepo of Halo2 crates providing basic primitives for writing zero-knowledge proof circuits. This broad adoption has created a rich ecosystem of reusable components, tutorials, and tooling that lowers the barrier to entry for new developers building ZKP applications. + +### 5.4 Cairo and StarkNet Development + +While Cairo is not implemented in Rust, it represents an important language in the ZKP development landscape that warrants coverage in this report. Cairo is a modern programming language developed by StarkWare, specifically designed for writing provable programs that can be verified using STARK proofs [53]. The language draws inspiration from Rust, adopting similar syntax and emphasizing memory safety and efficient code generation. Cairo compiles to a custom assembly language optimized for proof generation, enabling significantly better performance than general-purpose languages compiled to EVM bytecode. + +The Cairo ecosystem provides comprehensive tooling for developers building on StarkNet [53]. The Cairo Book offers extensive documentation covering everything from basic programming concepts to advanced optimization techniques. The Cairo Playground enables developers to experiment with code in a browser-based environment without local setup. StarkWare maintains active development with regular releases, including Cairo v2.12.0 as the most recent version. The language continues to evolve with new features that improve both developer experience and generated proof efficiency. + +The S-two prover, integrated into StarkNet in late 2025, represents the latest advancement in Cairo's proving infrastructure [51]. This prover achieves 100x efficiency improvements over the previous Stone prover, enabling client-side proving on consumer hardware. The development of the Cairo Coder tool in 2025 further simplifies onboarding for developers familiar with other programming languages. The combination of an optimized language, high-performance provers, and comprehensive tooling has established Cairo as a leading choice for developers building ZK-powered applications that prioritize performance and scalability. + +## 6. Comparative Analysis and Trade-offs + +### 6.1 Technical Trade-offs Between ZKP Types + +The choice between different zero knowledge proof systems involves fundamental trade-offs that blockchain projects must carefully evaluate based on their specific requirements. zk-SNARKs offer the smallest proof sizes at approximately 200 bytes and constant-time verification complexity O(1), making them ideal for applications where on-chain verification costs are paramount [25]. However, these benefits come at the cost of a trusted setup requirement and vulnerability to quantum attacks. The trusted setup creates a single point of failure that must be carefully managed through multi-party ceremonies, while the elliptic curve cryptography underlying SNARKs could become insecure if sufficiently powerful quantum computers are developed. + +zk-STARKs provide an attractive alternative for applications where security transparency and future-proofing take precedence over proof size [25]. The absence of a trusted setup eliminates an entire class of potential security vulnerabilities, while quantum resistance ensures long-term security even in the face of dramatic advances in computing. The trade-off manifests in larger proof sizes of approximately 45 kilobytes and higher on-chain verification costs of roughly 2.5 million gas compared to 600,000 gas for SNARKs. For applications prioritizing security over efficiency, particularly those expected to operate over decades, STARKs offer compelling advantages. + +Bulletproofs occupy a specialized niche optimized for range proofs and confidential transactions [25]. Their lack of trusted setup and compact proof sizes for their intended use cases make them the preferred choice for cryptocurrency systems requiring transaction amount privacy. However, the linear verification complexity O(N) limits their applicability to more complex computations. Projects like Monero have successfully deployed Bulletproofs for confidential transactions, demonstrating their practical utility for specific use cases. + +PLONK and modern SNARK constructions provide a middle ground by offering universal trusted setups that reduce operational complexity while maintaining the compact proofs and efficient verification of traditional SNARKs [71]. The ability to reuse a single setup across multiple applications democratizes access to ZK technology, as projects no longer need to coordinate their own trusted setup ceremonies. This has accelerated the deployment of ZK applications across the blockchain ecosystem. + +### 6.2 Blockchain Project Comparison + +The major ZK rollup implementations have made distinct technical choices that result in different characteristics and trade-offs for users and developers. zkSync Era prioritizes maximum scalability and native account abstraction, using a custom VM design that achieves significant performance improvements over EVM-compatible alternatives [11]. The trade-off is that developers must adapt to the zkSync environment, with some tool modifications required. The Boojum proof system provides strong security through recursive STARK construction, while the active development of Boojum 2.0 promises continued performance improvements. + +StarkNet's choice of zk-STARKs provides unique security properties including quantum resistance and no trusted setup requirement [51]. The trade-off manifests in the need to learn Cairo rather than using familiar Solidity, and a smaller ecosystem of tools compared to EVM solutions. However, the 2025 technical improvements have substantially closed the performance gap, with TPS capacity exceeding 1,000 and transaction costs below $0.001. The decentralization progress through staking and BTC integration positions StarkNet as a leading option for projects prioritizing security and decentralization. + +Polygon zkEVM maximizes EVM compatibility at the cost of some performance optimization [11]. This approach minimizes friction for developers migrating from Ethereum, enabling existing smart contracts to deploy with minimal modification. The substantial investment of over $1 billion demonstrates long-term commitment to the ZK space. The AggLayer architecture provides interoperability benefits across the Polygon ecosystem, though users face higher fees compared to more optimized alternatives. + +Scroll's Type 2 zkEVM implementation represents the closest approach to native Ethereum [11]. The bytecode-equivalence ensures that every EVM opcode works identically to the base chain, eliminating surprising differences that can cause bugs during migration. This has attracted major DeFi protocols like Aave that prioritize migration speed and ecosystem compatibility. The decentralized proof generation network provides architectural advantages for censorship resistance. + +### 6.3 Rust Ecosystem Comparison + +The Rust ZKP libraries serve different use cases and offer distinct trade-offs for developers. Arkworks provides the most comprehensive framework with support for multiple proof systems and flexible component composition [2]. The modular architecture enables developers to experiment with different constructions and optimize for specific requirements. However, the academic nature of the implementation means it requires careful security review before production deployment. The extensive documentation and active community support make it an excellent choice for research projects and applications with extended development timelines. + +Bellman offers a production-proven implementation with the strongest track record of securing significant financial value [6]. The Zcash deployment has subjected the library to intense scrutiny and real-world testing. Developers seeking maximum assurance of correctness may prefer Bellman, accepting the trade-off of working with a more opinionated library focused on a specific proof system. The tight integration with BN254 curve operations makes it particularly suitable for Ethereum-compatible applications. + +Halo2 has emerged as the dominant choice for new blockchain projects due to its flexibility and the substantial ecosystem built around it [46]. The support for universal setup reduces operational complexity, while the extensive tooling and documentation lower the barrier to entry. Projects like Scroll have demonstrated Halo2's capability to handle production workloads with billions of dollars in value. The ongoing development and community support ensure continued improvement and long-term viability. + +## 7. Conclusion + +Zero knowledge proofs have matured from theoretical cryptographic constructs into practical technologies powering real-world blockchain applications. The period from 2024 to 2026 has witnessed remarkable growth in ZKP deployment, with over $28 billion in total value locked across major ZK rollups and the broader proof market projected to reach $7.59 billion by 2033. This growth reflects both the technical maturity of ZK systems and the increasing recognition that privacy and scalability are fundamental requirements for blockchain adoption in financial applications. + +The diverse landscape of ZKP protocols provides solutions tailored to different requirements. zk-SNARKs continue to dominate applications where proof size and verification efficiency are paramount, while zk-STARKs have gained significant traction for their security properties including quantum resistance and no trusted setup. Bulletproofs remain relevant for specialized use cases like confidential transactions, and PLONK has enabled widespread deployment through its universal trusted setup. The ongoing research and development in this space promise continued improvements in performance, security, and usability. + +Major blockchain implementations including zkSync Era, StarkNet, Polygon zkEVM, and Scroll have demonstrated that ZK rollups can achieve practical deployment at scale. Each project has made different trade-offs between compatibility, performance, and decentralization, creating a healthy ecosystem of options for developers. The technical advances in 2025, particularly StarkNet's S-two prover and decentralized sequencing, have substantially improved the practical viability of ZK-based systems. The continued progress toward full decentralization and interoperability suggests an increasingly mature technology stack. + +The Rust ecosystem provides robust foundations for ZKP development, with libraries like arkworks, Bellman, and Halo2 addressing different needs within the development community. The combination of Rust's safety guarantees, extensive cryptographic libraries, and active open-source communities positions Rust as a leading language for ZKP application development. As the technology continues to evolve, the ecosystem will likely see further consolidation around the most successful approaches while new innovations emerge to address evolving requirements. + +## 8. Sources + +[1] [NIST Presentation on Writing Programs for ZKPs](https://csrc.nist.gov/csrc/media/presentations/2025/stppa8-zkp/images-media/stppa8-zkp.pdf) - High Reliability - US Government Research Organization + +[2] [arkworks-rs/snark GitHub Repository](https://github.com/arkworks-rs/snark) - High Reliability - Official Open Source Project + +[3] [SoK: Understanding zk-SNARKs - IACR](https://eprint.iacr.org/2025/172.pdf) - High Reliability - Academic Cryptography Research + +[4] [Engineering Trustworthy ML Operations with ZKPs - arXiv](https://arxiv.org/pdf/2505.20136) - High Reliability - Academic Research Paper + +[5] [Quantum Zeitgeist - ZKPs for AI Systems](https://quantumzeitgeist.com/zero-knowledge-proofs-validate-ai-systems-and-enhance-trustworthy-machine-learning/) - Medium Reliability - Technology News + +[6] [Bellman: zk-SNARKs in Rust - Electric Coin Co.](https://electriccoin.co/blog/bellman-zksnarks-in-rust/) - High Reliability - Original Developer Organization + +[7] [Promise of ZKPs for Blockchain - Wiley](https://onlinelibrary.wiley.com/doi/10.1002/spy2.461) - High Reliability - Academic Journal + +[8] [Zero-Knowledge Proofs in Rust and Bellman - Medium](https://deeprnd.medium.com/zero-knowledge-proofs-in-rust-and-bellman-0ea0c4b7e790) - Medium Reliability - Technical Article + +[11] [Top 10 Zero-Knowledge Proof Projects 2025 - Rumblefish](https://www.rumblefish.dev/blog/post/top-zk-projects-2025/) - High Reliability - Blockchain Analytics Firm + +[21] [Comparative Evaluation of ZK Proof Techniques - Sciitepress](https://www.scitepress.org/Papers/2025/132691/132691.pdf) - High Reliability - Academic Publication + +[22] [Comparative Analysis of zk-SNARKs and zk-STARKs - arXiv](https://arxiv.org/html/2512.10020v1) - High Reliability - Academic Research + +[23] [Understanding zk-SNARK Deep Dive](https://rya-sge.github.io/access-denied/2025/07/29/zk-snark-overview/) - Medium Reliability - Technical Blog + +[24] [Zero-Knowledge Proofs Transformative Role - IEEE](https://ieeexplore.ieee.org/iel8/6287639/10820123/11127078.pdf) - High Reliability - Academic Journal + +[25] [Comparative Dive into zk-SNARKs, zk-STARKs, Bulletproofs - AuditOne](https://www.auditone.io/blog-posts/exploring-zero-knowledge-proofs-a-comparative-dive-into-zk-snarks-zk-starks-and-bulletproofs) - Medium Reliability - Blockchain Security Organization + +[28] [ZK Tech You Should Know: SNARKs & STARKs - Mina Protocol](https://minaprotocol.com/blog/zk-you-should-know-snarks-starks) - High Reliability - Blockchain Foundation + +[30] [zk-SNARKs vs zk-STARKs vs Bulletproofs - Ethereum Stack Exchange](https://ethereum.stackexchange.com/questions/59145/zk-snarks-vs-zk-starks-vs-bulletproofs-updated) - Medium Reliability - Community Resource + +[32] [Zero-Knowledge Proof Explained - Chainlink](https://chain.link/education/zero-knowledge-proof-zkp) - High Reliability - Major Blockchain Infrastructure Company + +[37] [Why ZKPs Are Outperforming Bitcoin 2026 - Blockchain Apps Developer](https://www.blockchainappsdeveloper.com/why-zkps-are-outperforming-bitcoin-in-2026) - Medium Reliability - Industry Analysis + +[38] [Introduction to Zero-Knowledge Proofs - Chainalysis](https://www.chainalysis.com/blog/introduction-to-zero-knowledge-proofs-zkps/) - High Reliability - Blockchain Analytics Company + +[41] [axiom-crypto/halo2-lib GitHub](https://github.com/axiom-crypto/halo2-lib) - High Reliability - Official Open Source Repository + +[42] [Automated Analysis of Halo2 Circuits - CEUR-WS](https://ceur-ws.org/Vol-3429/paper3.pdf) - High Reliability - Academic Publication + +[44] [scroll-tech/zk-mooc-halo2 GitHub](https://github.com/scroll-tech/zk-mooc-halo2) - High Reliability - Official Project Repository + +[45] [The Pantheon of ZK Development Frameworks - Celer Network](https://blog.celer.network/2023/08/04/the-pantheon-of-zero-knowledge-proof-development-frameworks/) - Medium Reliability - Blockchain Project + +[46] [Improved Lightweight Formal Verification of halo2 - Zcash Community](https://forum.zcashcommunity.com/uploads/short-url/3rGuQSM2LKVIwSzbv8Mh4C6Pzzp.pdf) - High Reliability - Community Analysis + +[50] [The halo2 Book - Zcash](https://zcash.github.io/halo2/) - High Reliability - Official Documentation + +[51] [Starknet 2025 Year in Review - StarkNet](https://www.starknet.io/blog/starknet-2025-year-in-review/) - High Reliability - Official Project Blog + +[52] [Tech Stack - StarkWare](https://starkware.co/tech-stack/) - High Reliability - Official Company Website + +[53] [Cairo Programming Language](https://www.cairo-lang.org/) - High Reliability - Official Documentation + +[56] [Cairo 1.0 is here - StarkNet Blog](https://www.starknet.io/blog/cairo-1-0-is-here/) - High Reliability - Official Project Blog + +[61] [Matter Labs Q1 2025 Deliverables Report](https://forum.zknation.io/t/matter-labs-q1-2025-deliverables-report/674) - High Reliability - Official Forum + +[67] [Boojum - L2Beat](https://l2beat.com/zk-catalog/boojum) - High Reliability - Independent Analytics Platform + +[68] [Ronin Docs - Matter Labs Technical Blog](https://docs.roninchain.com/blog) - High Reliability - Technical Documentation + +[71] [PLONK: Breakthrough in Efficient ZK-SNARK - Orochi Network](https://orochi.network/blog/plonk-a-breakthrough-in-efficient-zk-snark-technology) - High Reliability - Technical Analysis + +[72] [PLONK Revolutionizing ZK-SNARK - ZKPlabs](https://zkplabs.network/blog/Introduce-PLONK-Revolutionizing-ZK-SNARK-Technology-for-Efficiency-and-Privacy) - Medium Reliability - Industry Analysis + +[76] [Efficient ZK Solutions with Plonky2 - Gate](https://web3.gate.com/crypto-wiki/article/efficient-zero-knowledge-solutions-for-blockchain-with-plonky2-20251226) - Medium Reliability - Exchange Research \ No newline at end of file diff --git a/docs/research/ai-quota-marketplace-research.md b/docs/research/ai-quota-marketplace-research.md new file mode 100644 index 0000000..a4b3064 --- /dev/null +++ b/docs/research/ai-quota-marketplace-research.md @@ -0,0 +1,188 @@ +# Research: AI Quota Marketplace for Developer Bootstrapping + +## Executive Summary + +This research investigates using AI API quota trading as a bootstrapping mechanism for CipherOcto. Developers would contribute spare API quota to the network, earning OCTO-W tokens that can be used to purchase more quota when needed or swapped for other tokens. The goal is to create a self-bootstrapping ecosystem where early contributors receive multiplier rewards. + +## Problem Statement + +CipherOcto needs a mechanism to: +1. Attract initial developers to the network +2. Create utility for OCTO-W token immediately +3. Enable developers to monetize unused AI API quotas +4. Create a marketplace for quota trading across timezones + +## Research Scope + +- What's included: Token mechanics, marketplace design, security model +- What's excluded: Blockchain implementation details, specific provider integrations + +--- + +## Personas + +| Persona | Role | Description | +|---------|------|-------------| +| **Provider** | Seller | Developer with unused AI API quota who lists it on the market | +| **Consumer** | Buyer | Developer who needs more quota than they have | +| **Router** | Infrastructure | Agent that routes prompts based on policy and balance | + +--- + +## Findings + +### Similar Approaches + +| Project | Approach | Lessons | +|--------|----------|---------| +| GPU.miners | Compute sharing | Works but limited to GPU compute | +| API marketplaces | Centralized reselling | Trust issues, fees | +| Timezone arbitrage | Existing in informal networks | Proves demand exists | + +### Technical Requirements + +1. **Local Proxy** - Routes API requests without exposing keys +2. **Quota Metering** - Track usage per 5-hour window +3. **Market Engine** - Match buyers/sellers, settle in OCTO-W +4. **Token Swaps** - OCTO-W ↔ OCTO-D ↔ OCTO + +### Latency Considerations + +| Scenario | Expected Latency | Notes | +|----------|-----------------|-------| +| Direct (no market) | 100-500ms | Normal API latency | +| Market route | +50-200ms | Network hop through seller proxy | +| Multi-route | +100-500ms | Fallback through multiple sellers | + +**Acceptable degradation:** Up to 2x baseline latency acceptable for market-sourced quota. + +### Market Dynamics + +| Model | Description | Pros | Cons | +|-------|-------------|------|------| +| **Fixed price** | Set price per prompt, static | Simple, predictable | May not reflect demand | +| **Dynamic AMM** | Automated market maker | Real-time pricing | Complex to implement | +| **Auction** | Bid for quota | Efficient pricing | Slower execution | +| **Reputation-weighted** | Higher rep = better price | Incentivizes quality | Requires reputation first | + +**Recommendation:** Start with fixed price, evolve to reputation-weighted as network matures. + +### Cost Normalization + +Different providers have different pricing structures: + +| Provider | Model | Cost per 1K input tokens | Cost per 1K output tokens | +|----------|-------|--------------------------|--------------------------| +| OpenAI | GPT-4 | $0.01 | $0.03 | +| OpenAI | GPT-3.5 | $0.0005 | $0.0015 | +| Anthropic | Claude 3 Opus | $0.015 | $0.075 | +| Anthropic | Claude 3 Haiku | $0.00025 | $0.00125 | +| Google | Gemini Pro | $0.00125 | $0.005 | + +**Solution: Compute Units** + +```typescript +// Normalize all models to compute units +const MODEL_WEIGHTS = { + 'gpt-4': 10, // 10 units per prompt + 'gpt-3.5-turbo': 1, // 1 unit per prompt + 'claude-3-opus': 12, + 'claude-3-haiku': 1, + 'gemini-pro': 2, +}; + +// OCTO-W cost = base_units × model_weight +const BASE_COST = 1; // 1 OCTO-W minimum +``` + +This allows 1 OCTO-W to represent ~equivalent compute across providers. + +### Token Mint/Burn Rules + +| Event | Action | Details | +|-------|--------|---------| +| **List quota** | Mint | OCTO-W minted on successful listing | +| **Use quota** | Burn | OCTO-W burned on successful prompt delivery | +| **Dispute** | Slash | From seller stake, buyer refunded | +| **Listing cancelled** | No burn | Unused OCTO-W remains (no inflation) | + +**Inflation Control:** +- Maximum OCTO-W supply: 1B tokens +- Mint only on verified usage (not listing) +- Protocol treasury provides initial liquidity + +### Security Considerations + +- API keys never leave developer's machine +- Requests routed through local proxy only +- OCTO-W balance required for each request +- No central authority holds credentials + +### Prompt Privacy (Critical Clarification) + +**IMPORTANT:** The current design routes prompts through seller's proxy, meaning: +- Seller **will see prompt content** when executing API calls +- This is a **trust assumption**, not a cryptographic guarantee +- End-to-end encryption is **NOT** currently implemented + +**Future options to explore:** +- Trusted Execution Environments (TEE) for seller proxies +- ZK proofs of inference (research phase) +- TEE + remote attestation + +For MVE, we accept this trust model with reputation as the mitigation. + +### Dispute Resolution + +| Issue | Resolution | +|-------|------------| +| Failed prompt after payment | Seller reputation penalty, refund from stake | +| Garbage/invalid response | Reputation hit, auto-blacklist | +| Seller offline mid-request | Retry with fallback provider | +| Insufficient OCTO-W | Request rejected before routing | + +**Mechanism:** Sellers stake OCTO-W. If dispute proven, stake slashed and buyer refunded. + +## Token Economics + +| Token | Role | +|-------|------| +| OCTO-W | Quota currency + authorization grant | +| OCTO-D | Developer rewards | +| OCTO | Governance | + +**Key insight:** OCTO-W serves as both currency AND metered access - 1 OCTO-W = 1 prompt request. + +## Recommendations + +### Recommended Approach + +Implement as agent-based system where: +- Dev runs local quota router (agent) +- Agent policy determines routing behavior +- Marketplace is agent-to-agent + +### Risks + +| Risk | Mitigation | +|------|------------| +| API key exposure | Local proxy only, keys never leave machine | +| Abuse | Reputation system, stake requirements | +| Low liquidity | Bootstrap with early contributor incentives | + +### Next Steps + +- Create Use Case? **Yes** +- Explore further: Specific provider APIs, rate limiting + +--- + +## References + +- Parent Document: BLUEPRINT.md +- Leads to: docs/use-cases/ai-quota-marketplace.md + +--- + +**Research Status:** Complete +**Recommended Action:** Proceed to Use Case diff --git a/docs/research/cairo-ai-research-report.md b/docs/research/cairo-ai-research-report.md new file mode 100644 index 0000000..f997a2f --- /dev/null +++ b/docs/research/cairo-ai-research-report.md @@ -0,0 +1,158 @@ +# Cairo Language AI Applications Research Report + +## Executive Summary + +This research report provides a comprehensive analysis of the current usages of Cairo programming language in artificial intelligence contexts, with particular focus on zero-knowledge machine learning (ZKML) applications and the emerging ecosystem of provable AI tools built on the StarkWare stack. The investigation reveals a vibrant and rapidly evolving landscape of AI implementations within the Cairo ecosystem, ranging from neural network implementations to comprehensive provable machine learning frameworks. The S-two prover represents a significant advancement in enabling AI verification capabilities within the Cairo ecosystem, offering unprecedented performance for zero-knowledge proof generation related to machine learning workloads. + +## 1. Introduction and Background + +Cairo is a Turing-complete programming language developed by StarkWare that serves as the native language for StarkNet, Ethereum's Layer 2 scaling solution. Originally designed for creating provable programs for general computation, Cairo has evolved to become a powerful platform for zero-knowledge proof generation, with significant implications for artificial intelligence applications. The language abstracts away the complex cryptography and mathematics involved in proof generation, allowing developers to focus on building applications while the underlying STARK (Scalable Transparent ARguments of Knowledge) cryptographic infrastructure handles the proving mechanism. + +The intersection of Cairo with AI represents a relatively new but rapidly developing field, driven primarily by the need for verifiable and privacy-preserving machine learning. Zero-knowledge machine learning (ZKML) enables the verification of ML model execution without revealing the underlying model weights or input data, creating new possibilities for trustless AI applications. This research investigates the current state of AI implementations within the Cairo ecosystem, examines the feature enabling aspects of the S-two prover, and provides a comprehensive feature matrix for comparative analysis. + +## 2. Cairo AI Ecosystem Overview + +### 2.1 Foundational AI Frameworks + +The Cairo ecosystem has developed several specialized frameworks and tools for AI and machine learning applications. The most prominent among these is Orion, an open-source, community-driven framework dedicated to provable machine learning. Developed by Gizatech, Orion provides essential components for building verifiable ML models and implements an ONNX Runtime in Cairo 1.0 for executing machine learning inference with cryptographic proof verification through STARKs. + +Orion represents a significant milestone in democratizing access to verifiable machine learning, enabling developers to train models in mainstream frameworks such as TensorFlow or PyTorch and then execute them with verifiable inference on StarkNet. The framework leverages the ONNX (Open Neural Network Exchange) format as a universal intermediary, ensuring compatibility with the broader deep learning ecosystem. This approach allows organizations to maintain their existing ML workflows while gaining the ability to generate cryptographic proofs of correct inference execution. + +The framework is structured around three primary components: the Framework itself providing building blocks for verifiable machine learning models, the Hub offering a curated collection of community-built ML models and demonstration spaces, and the Academy providing educational resources and tutorials for developers seeking to build ValidityML applications. As of March 2025, the original Orion project has been archived, with the development team transitioning to work on LuminAIR, a new zkML framework based on custom AIR (Algebraic Intermediate Representation) proven with the S-two Prover. + +### 2.2 Neural Network Implementations + +Several notable neural network implementations exist within the Cairo ecosystem, demonstrating the practical applicability of machine learning models on the platform. The neural-network-cairo project provides a complete neural network implementation from scratch for MNIST digit classification, written entirely in Cairo 1.0. This implementation features a two-layer architecture with 784 input units corresponding to the 28×28 pixel images, a hidden layer with 10 units using ReLU activation, and an output layer with 10 units using softmax activation for digit classification. + +The implementation includes sophisticated features such as 8-bit weight quantization based on ONNX quantization standards, various data structure implementations including vectors, matrices, and tensors with associated operations, forward propagation capabilities, and methods for loading pre-trained weights from TensorFlow models into Cairo neural networks. This project demonstrates the feasibility of running practical machine learning inference on blockchain infrastructure while maintaining verifiability guarantees. + +Additional AI demonstrations within the ecosystem include Tic-Tac-Stark, which implements a provable Tic-Tac-Toe AI model using Orion and Cairo, and drive-ai, a self-driving car AI project built on the Dojo game engine. These projects, while more experimental in nature, demonstrate the versatility of Cairo for different AI application domains and serve as proof-of-concept implementations for more sophisticated future applications. + +## 3. Zero-Knowledge Machine Learning Applications + +### 3.1 Cairo Verifier and ZKML Capabilities + +The Cairo Verifier deployed on StarkNet represents a transformative advancement for zero-knowledge machine learning applications. The verifier enables STARK proofs to be verified directly on StarkNet smart contracts, providing substantially cheaper verification costs compared to Ethereum mainnet verification. This cost efficiency is essential for making ZKML applications economically viable, as the computational overhead of proof verification has historically been a significant barrier to adoption. + +The technical architecture of the Cairo Verifier features a single contract design, unlike Ethereum's Solidity verifier which is split across dozens of separate contracts. This monolith architecture improves auditability and reduces the complexity of integration for developers. The verifier supports bootloader programs that reduce verifier complexity without revealing entire bytecode, flexible hash functions including Poseidon, Blake, and Keccak for optimization trade-offs between prover and verifier costs, and various Cairo layouts with different builtin combinations. + +The enablement of client-side proving represents a particularly powerful capability for ZKML applications. Machine learning computations can be proven locally on client devices and verified on-chain, creating a privacy-preserving workflow where sensitive input data never leaves the client while still providing cryptographic guarantees of correct execution. This architecture supports the verification of model outputs without revealing model weights, enabling scenarios such as proving that a credit risk assessment was generated by a specific model without exposing the proprietary model parameters. + +### 3.2 ZKML Use Cases and Applications + +Zero-knowledge machine learning enabled by Cairo encompasses a broad range of practical applications across multiple industries. The technology enables verification of AI model outputs in decentralized contexts, allowing smart contracts to depend on AI-generated decisions while maintaining cryptographic certainty about the correctness of those decisions. This capability is particularly valuable for DeFi applications requiring credit scoring, risk assessment, or automated decision-making that benefits from verifiability guarantees. + +Privacy-preserving inference represents another significant application domain, where ZKML enables proving the correctness of ML inference without revealing the underlying input data. This capability addresses regulatory compliance requirements in sectors such as healthcare and finance, where sensitive data processing must be combined with strong privacy guarantees. The technology also enables verifiable random forests and other ensemble methods, where the integrity of complex voting-based predictions can be cryptographically verified. + +The integration with the broader StarkNet ecosystem enables sophisticated multi-party computation scenarios where different participants can contribute to ML inference while maintaining confidentiality over their respective inputs. This capability opens possibilities for collaborative machine learning on blockchain infrastructure, where multiple organizations can jointly evaluate models on combined datasets without exposing individual data contributions. + +## 4. S-two Prover and AI Feature Enablement + +### 4.1 Technical Architecture and Performance + +The S-two prover (stwo-cairo) represents StarkWare's next-generation zero-knowledge proving system, described as the fastest prover in the world. The prover is fully open-source and written in Rust, implementing the Circle STARK protocol—a breakthrough proving system over 31-bit chip-friendly Mersenne prime field. The technical architecture supports multiple hardware backends including CPU, SIMD, and GPU, with WebGPU and WASM compilation for in-browser proving capabilities scheduled for future release. + +The performance characteristics of S-two are particularly relevant for AI applications, with benchmarks demonstrating 28X faster performance than Risc0 precompile on Keccak chain and 39X faster than SP1 precompile on equivalent benchmarks. The prover achieves 10-30X performance gains depending on the specific task compared to alternative solutions. These performance improvements are attributable to the use of high-level general-purpose language (Cairo) rather than low-level hand-tuned circuits, combined with the mathematical innovations of the Circle STARK protocol. + +The S-two prover architecture supports recursive proving out of the box, enabling complex proof compositions that are essential for sophisticated AI verification workflows. The compatible Cairo programming language provides a familiar development environment for developers building AI applications, while the prover's client-side capabilities enable practical deployment scenarios where proof generation occurs on consumer hardware including phones, laptops, and browser tabs. + +### 4.2 AI-Specific Capabilities + +S-two includes specific features designed to address AI verification needs, categorized into four primary capability areas. Model authenticity verification enables proving that a known model produced a given output, addressing concerns about adversarial substitution of ML models in production systems. This capability ensures that on-chain applications can verify they are interacting with the intended model rather than a modified version. + +Input integrity verification provides mechanisms to prove what inputs were used in a computation without revealing those inputs, essential for privacy-preserving AI applications. This capability enables scenarios where the existence and correctness of specific input data can be demonstrated without exposing the actual data values, creating powerful primitives for privacy-sensitive applications. + +zkML inference enables running provable inference locally with proofs verified on-chain, bringing zero-knowledge capabilities to standard machine learning workflows. The practical feasibility of generating proofs of ML inference on real-world hardware represents a significant advancement for the field, making it economically viable to deploy verifiable AI in production systems. AI automation capabilities enable triggering on-chain actions based on verifiable AI outcomes, closing the loop between off-chain AI inference and on-chain execution. + +### 4.3 Integration with Cairo Ecosystem + +The integration of S-two with the broader Cairo ecosystem creates a comprehensive platform for AI application development. The prover is accessible through the Scarb build tool via the `scarb prove` command (requires Scarb version 2.10.0 or later), providing a seamless developer experience for building and proving Cairo programs. The dual crate architecture separates prover and verifier implementations, enabling optimized deployment strategies based on specific application requirements. + +The availability of S-two as an open-source project (272 stars, 60 forks, 1,199 commits) ensures community engagement and transparency in the proving infrastructure. The expected on-chain verifier deployment on StarkNet by the end of 2025 will further enhance the accessibility of these capabilities for production AI applications, enabling direct on-chain verification of proofs generated by the S-two prover. + +## 5. Feature Matrix Analysis + +The following feature matrix provides a comparative analysis of the key AI-related capabilities across the Cairo ecosystem components: + +| Feature Category | Cairo Language | Orion Framework | S-two Prover | Cairo Verifier | +|----------------|---------------|-----------------|--------------|----------------| +| **ML Framework** | | | | | +| Neural Network Support | Basic | Advanced | N/A | N/A | +| ONNX Runtime | Via External | Native | N/A | N/A | +| Model Training | Not Supported | Limited | N/A | N/A | +| Pre-trained Model Import | Via Manual Port | Automatic (ONNX) | N/A | N/A | +| **Proving Capabilities** | | | | | +| STARK Proof Generation | Native | Via Framework | Native | N/A | +| ZK Proof Support | Native | Native | Native | Verification Only | +| Recursive Proving | Via Libraries | Via Libraries | Native | Limited | +| Client-side Proving | Not Native | Not Native | Native | N/A | +| **AI Verification** | | | | | +| Model Authenticity | Manual | Via Framework | Native | Supported | +| Input Integrity | Manual | Via Framework | Native | Supported | +| Output Verification | Manual | Via Framework | Via Proof | Supported | +| Privacy Preservation | Manual | Via Framework | Native | Supported | +| **Performance** | | | | | +| Proof Generation Speed | Standard | Standard | 28-39X Faster | N/A | +| Verification Cost | High | Medium | Low | Low (L2) | +| Hardware Acceleration | No | No | CPU/SIMD/GPU | N/A | +| Browser Support | No | No | Coming Soon | N/A | +| **Development** | | | | | +| Language | Cairo 1.0 | Cairo 1.0 | Rust/Cairo | Cairo | +| Framework Integration | N/A | TensorFlow/PyTorch | N/A | N/A | +| Documentation | Comprehensive | Good | Good | Good | +| Maintenance Status | Active | Archived | Active | Active | + +### 5.1 Feature Matrix Interpretation + +The feature matrix reveals distinct specializations among the ecosystem components. Cairo language provides the foundational programming model and native STARK proof generation capabilities, serving as the substrate upon which higher-level AI tools are built. The language itself supports basic neural network operations through manual implementation but does not provide integrated ML framework capabilities. + +The Orion framework delivers the most comprehensive ML-specific feature set, including native ONNX runtime support, automatic model import from standard frameworks, and built-in mechanisms for verifiable inference. However, its archived status as of March 2025 raises questions about long-term maintenance and suggests that the ecosystem may be transitioning toward newer solutions. + +The S-two prover represents the performance leader in the ecosystem, providing native support for all key AI verification capabilities including model authenticity, input integrity, and privacy-preserving inference. Its hardware acceleration support and client-side proving capabilities position it as the preferred solution for production AI applications requiring high throughput and low latency. + +The Cairo Verifier provides essential on-chain verification capabilities at substantially reduced costs compared to Ethereum mainnet alternatives. Its support for client-side proving enables the privacy-preserving ZKML workflows that are essential for many practical applications. + +## 6. Practical Applications and Use Cases + +### 6.1 Current Implementations + +The practical applications of Cairo-based AI span multiple domains and complexity levels. The MNIST digit recognition implementation demonstrates the feasibility of running conventional machine learning inference on blockchain infrastructure, providing a template for more sophisticated image classification applications. The Tic-Tac-Toe AI demonstrates game AI with provable correctness guarantees, illustrating how AI decision-making can be verified in adversarial settings. + +The Dojo-based drive-ai project extends AI applications into simulation and gaming domains, leveraging the provable game engine to create verifiable autonomous agent behaviors. These early implementations serve as proof-of-concept demonstrations that establish the technical viability of more ambitious future applications. + +### 6.2 Emerging Applications + +The combination of S-two prover capabilities with Cairo's programming model enables several emerging application categories. Verifiable AI agents can operate autonomously on-chain while providing cryptographic proof of their decision-making processes, enabling trustless automation of complex financial and organizational tasks. The integration with AI agents enables on-chain actions to be triggered based on verifiable AI outcomes, creating closed-loop systems where off-chain intelligence drives on-chain execution. + +Proof of humanity and identity applications leverage ZKML capabilities to verify human characteristics without revealing biometric data, addressing concerns about bot proliferation while maintaining privacy. Age verification and zkKYC (zero-knowledge Know Your Customer) represent additional application domains where AI classification must be combined with privacy-preserving verification mechanisms. + +Decentralized identity systems benefit from ZKML capabilities through verifiable credentials that demonstrate possession of certain attributes without revealing the underlying evidence. Proof of uniqueness systems enable demonstration of personhood without revealing specific identity, addressing Sybil attack concerns in governance and allocation systems while preserving anonymity. + +## 7. Conclusion + +The Cairo ecosystem has developed a comprehensive suite of tools and frameworks for AI applications, with particular strength in zero-knowledge machine learning and verifiable AI systems. The combination of the Cairo programming language, Orion framework (and its successor LuminAIR), S-two prover, and Cairo Verifier creates a complete platform for developing, deploying, and verifying AI applications on blockchain infrastructure. + +The S-two prover represents a significant advancement in enabling practical AI verification, with performance characteristics that make client-side proof generation viable on consumer hardware. Its specific capabilities for model authenticity, input integrity, and privacy-preserving inference directly address the requirements of production AI applications. + +The ecosystem continues to evolve, with the transition from Orion to LuminAIR indicating ongoing development activity. The expected deployment of on-chain verification for S-two proofs on StarkNet by the end of 2025 will further enhance the accessibility of these capabilities for mainstream applications. + +For organizations seeking to build verifiable or privacy-preserving AI applications on blockchain infrastructure, the Cairo ecosystem provides a mature and well-documented platform. The key considerations include selecting appropriate tools based on specific requirements (performance, privacy, verification needs), monitoring the transition from Orion to LuminAIR for updated capabilities, and leveraging client-side proving capabilities for privacy-sensitive applications. + +## 8. References + +The following sources were consulted during the preparation of this research report: + +- StarkWare Industries. "Introducing S-two: The fastest prover for real-world ZK applications." https://starkware.co/blog/s-two-prover/ +- StarkNet. "Meet the Cairo Verifier: Customizable L3 Appchains on Starknet." https://www.starknet.io/blog/meet-the-cairo-verifier/ +- Gizatech. "Orion: ONNX Runtime in Cairo 1.0 for verifiable ML." https://github.com/gizatechxyz/orion +- StarkWare Industries. "Cairo Use Cases." https://starkware.co/use-cases/ +- StarkWare Libraries. "starkware-libs/stwo-cairo GitHub Repository." https://github.com/starkware-libs/stwo-cairo +- Algaba, F. "Neural Network implementation for MNIST in Cairo." https://github.com/franalgaba/neural-network-cairo +- Keep Starknet Strange. "Awesome Starknet Repository." https://github.com/keep-starknet-strange/awesome-starknet +- Cairo Language Documentation. https://www.cairo-lang.org/ +- StarkNet Documentation. https://www.starknet.io/ + +--- + +**Report prepared by:** MiniMax Agent +**Date:** March 2, 2026 diff --git a/docs/research/luminair-air-deep-dive.md b/docs/research/luminair-air-deep-dive.md new file mode 100644 index 0000000..a645d2e --- /dev/null +++ b/docs/research/luminair-air-deep-dive.md @@ -0,0 +1,381 @@ +# Research: LuminAIR AIR (Algebraic Intermediate Representation) + +## Overview + +LuminAIR uses **Algebraic Intermediate Representation (AIR)** to prove computational graph integrity. Unlike Cairo programs (used by Stoolap), LuminAIR compiles ML operators directly to AIR without Cairo compilation. + +## What is AIR? + +**AIR (Algebraic Intermediate Representation)** is a constraint-based system for STARK proofs: + +```mermaid +flowchart TD + subgraph COMPUTATION["Computation"] + OP[Operator] --> TRACE[Execution Trace] + end + + subgraph AIR["AIR Generation"] + TRACE --> CONST[Constraints] + CONST --> POLY[Polynomials] + end + + subgraph STARK["STARK Proof"] + POLY --> FRI[FRI] + FRI --> PROOF[Proof] + end + + COMPUTATION -->|transform| AIR + POLY -->|generate| STARK +``` + +### Key AIR Concepts + +| Concept | Description | +|---------|-------------| +| **Trace** | Execution record (values at each step) | +| **Constraints** | Mathematical relations between trace values | +| **Polynomials** | Trace interpolated to polynomials | +| **Components** | AIR modules for specific operations | + +## LuminAIR AIR Components + +### Current Operators (11 Primitive) + +| Operator | Component | Purpose | +|----------|-----------|---------| +| **Add** | `AddComponent` | Element-wise addition | +| **Mul** | `MulComponent` | Element-wise multiplication | +| **Recip** | `RecipComponent` | Reciprocal (1/x) | +| **Sin** | `SinComponent` | Sine with lookup table | +| **Exp2** | `Exp2Component` | 2^x with lookup table | +| **Log2** | `Log2Component` | log2(x) with lookup table | +| **Sqrt** | `SqrtComponent` | Square root | +| **Mod** | `RemComponent` | Modulo/remainder | +| **LessThan** | `LessThanComponent` | Comparison | +| **SumReduce** | `SumReduceComponent` | Sum all elements | +| **MaxReduce** | `MaxReduceComponent` | Find maximum | +| **Contiguous** | `ContiguousComponent` | Memory layout | + +### Planned (Fused) Operators + +| Operator | Description | +|----------|-------------| +| **MatMul** | Matrix multiplication | +| **SoftMax** | Softmax function | +| **ReLU** | Rectified linear unit | + +## Component Architecture + +### Structure of an AIR Component + +Each LuminAIR component implements: + +```rust +pub struct SomeEval { + log_size: u32, // Trace size (log2) + lut_log_size: u32, // Lookup table size (if applicable) + node_elements: NodeElements, // Graph node info + lookup_elements: LookupElements, // Lookup data +} + +impl FrameworkEval for SomeEval { + // 1. Return trace size + fn log_size(&self) -> u32 { ... } + + // 2. Return max constraint degree + fn max_constraint_log_degree_bound(&self) -> u32 { ... } + + // 3. Evaluate constraints + fn evaluate(&self, mut eval: E) -> E { + // Consistency constraints + // Transition constraints + // Interaction constraints (LogUp) + } +} +``` + +### Constraint Types + +#### 1. Consistency Constraints +Ensure trace values are consistent: + +```rust +// Example: output = input1 + input2 +eval.eval_fixed_add(lhs_val.clone(), rhs_val.clone(), out_val.clone()); +``` + +#### 2. Transition Constraints +Ensure state transitions are valid: + +```rust +// Example: if not last index, next index = current + 1 +let not_last = E::F::one() - is_last_idx; +eval.add_constraint(not_last * (next_idx - idx - E::F::one())); +``` + +#### 3. Interaction Constraints (LogUp) +Ensure data flow between operators: + +```rust +// Connect output of one operator to input of another +eval.add_to_relation(RelationEntry::new( + &self.node_elements, + lhs_mult.into(), + &[lhs_val, lhs_id], +)); +eval.finalize_logup(); +``` + +## Example: Add Component + +### Code Structure + +```rust +// crates/air/src/components/add/component.rs + +pub struct AddEval { + log_size: u32, + node_elements: NodeElements, +} + +impl FrameworkEval for AddEval { + fn evaluate(&self, mut eval: E) -> E { + // Trace masks (allocate columns) + let node_id = eval.next_trace_mask(); + let lhs_id = eval.next_trace_mask(); + let rhs_id = eval.next_trace_mask(); + let idx = eval.next_trace_mask(); + let is_last_idx = eval.next_trace_mask(); + + // Values + let lhs_val = eval.next_trace_mask(); + let rhs_val = eval.next_trace_mask(); + let out_val = eval.next_trace_mask(); + + // Multiplicities (for LogUp) + let lhs_mult = eval.next_trace_mask(); + let rhs_mult = eval.next_trace_mask(); + let out_mult = eval.next_trace_mask(); + + // ┌─────────────────────────────┐ + // │ Consistency Constraints │ + // └─────────────────────────────┘ + + // is_last_idx must be 0 or 1 + eval.add_constraint( + is_last_idx.clone() * (is_last_idx.clone() - E::F::one()) + ); + + // output = lhs + rhs + eval.eval_fixed_add(lhs_val.clone(), rhs_val.clone(), out_val.clone()); + + // ┌────────────────────────────┐ + // │ Transition Constraints │ + // └────────────────────────────┘ + + // Same node/tensor IDs, index increments + + // ┌─────────────────────────────┐ + // │ Interaction Constraints │ + // └─────────────────────────────┘ + + // LogUp: connect to other operators via multiplicities + eval.add_to_relation(RelationEntry::new( + &self.node_elements, + lhs_mult.into(), + &[lhs_val, lhs_id], + )); + + eval.finalize_logup(); + + eval + } +} +``` + +### Constraint Summary + +| Constraint | Formula | Purpose | +|-----------|---------|---------| +| is_last_valid | `is_last * (is_last - 1) = 0` | Binary flag check | +| add_correct | `out - lhs - rhs = 0` | Addition correctness | +| same_node | `(1-is_last) * (next_node - node) = 0` | Node continuity | +| same_lhs | `(1-is_last) * (next_lhs - lhs) = 0` | LHS continuity | +| same_rhs | `(1-is_last) * (next_rhs - rhs) = 0` | RHS continuity | +| index_inc | `(1-is_last) * (next_idx - idx - 1) = 0` | Index progression | + +## Data Flow: LogUp + +### What is LogUp? + +**LogUp (Lookup Argument via Univariate Polynomials)** ensures data flows correctly between operators: + +```mermaid +flowchart LR + subgraph OP1["Operator A (output)"] + O[out_val] -->|yield = N| M1[Multiplicity N] + end + + subgraph OP2["Operator B (input)")] + I[input_val] -->|consume = 1| M2[Multiplicity 1] + end + + M1 -->|verified| LOGUP[LogUp Protocol] + M2 -->|verified| LOGUP + + LOGUP --> PROOF[ZK Proof] +``` + +### Multiplicity Rules + +| Scenario | Multiplicity | Example | +|----------|-------------|---------| +| Output yielded | Positive | Tensor used by 2 consumers → yield=2 | +| Input consumed | Negative | Operation reads from tensor → consume=-1 | +| Graph input | Zero | Initial tensor, no prior operation | +| Graph output | Zero | Final result, no subsequent operation | + +## Lookup Tables (LUT) + +Some operations use **lookup tables** for efficiency: + +### Operations with LUTs + +| Operation | Lookup Table | Purpose | +|-----------|--------------|---------| +| **Sin** | sin(x) values | Fast sine approximation | +| **Exp2** | 2^x values | Fast exponential | +| **Log2** | log2(x) values | Fast logarithm | +| **RangeCheck** | 0..N range | Bounds checking | + +### LUT Implementation + +```rust +// Example: Sin with lookup +pub struct SinEval { + log_size: u32, + lut_log_size: u32, // Lookup table size + node_elements: NodeElements, + lookup_elements: SinLookupElements, +} + +// Uses lookup to verify sin computation +// without computing sin in the circuit +``` + +## Trace Structure + +### Execution Trace + +The trace records computation state at each step: + +```rust +pub type TraceEval = ColumnVec>; +``` + +### Column Layout + +| Column Type | Description | +|------------|-------------| +| **Trace columns** | Computation values | +| **Mask columns** | Index, IDs, flags | +| **Interaction columns** | LogUp multiplicities | + +## Proving Pipeline + +### Full Flow + +```mermaid +sequenceDiagram + participant Dev as Developer + participant Graph as Computational Graph + participant Compiler as StwoCompiler + participant AIR as AIR Components + participant Trace as Trace Generator + participant Stwo as Stwo Prover + participant Verifier + + Dev->>Graph: Define ML model + Graph->>Compiler: Compile to AIR + Compiler->>AIR: Generate constraints + AIR->>Trace: Generate execution trace + Trace->>Stwo: Generate proof + Stwo->>Verifier: Verify proof + Verifier-->>Dev: Valid/Invalid +``` + +### Code Example + +```rust +use luminair_graph::{graph::LuminairGraph, StwoCompiler}; +use luminal::prelude::*; + +fn main() -> Result<(), Box> { + // 1. Build computational graph + let mut cx = Graph::new(); + let a = cx.tensor((2, 2)).set(vec![1.0, 2.0, 3.0, 4.0]); + let b = cx.tensor((2, 2)).set(vec![10.0, 20.0, 30.0, 40.0]); + let c = a * b; + let mut d = (c + a).retrieve(); + + // 2. Compile to AIR (StwoCompiler) + cx.compile(<(GenericCompiler, StwoCompiler)>::default(), &mut d); + + // 3. Generate execution trace + let trace = cx.gen_trace()?; + + // 4. Generate proof + let proof = cx.prove(trace)?; + + // 5. Verify + cx.verify(proof)?; + + Ok(()) +} +``` + +## Comparison: Cairo vs Direct AIR + +| Aspect | Stoolap (Cairo) | LuminAIR (Direct AIR) | +|--------|-----------------|------------------------| +| **Compilation** | SQL → Cairo | ML Graph → AIR | +| **Prover** | stwo-cairo-prover | stwo (direct) | +| **On-chain** | ✅ Yes | ❌ Not yet | +| **Flexibility** | Fixed (SQL ops) | Extensible (components) | +| **Performance** | ~25-28s proving | Variable by model | +| **Complexity** | Lower (pre-built) | Higher (custom AIR) | + +## Why Direct AIR is Faster + +1. **No Cairo compilation overhead** +2. **Specialized constraints** for ML operations +3. **SIMD backend** for parallel trace generation +4. **Lookup tables** avoid expensive computations in-circuit + +## For CipherOcto + +### When to Use Direct AIR + +- **Off-chain verification** (fast, no on-chain needed) +- **ML inference proofs** (LuminAIR domain) +- **Custom operators** not expressible in Cairo + +### When Cairo is Better + +- **On-chain verification** required +- **Starknet integration** needed +- **Proven ecosystem** with existing programs + +--- + +## References + +- LuminAIR AIR Components: `crates/air/src/components/` +- Stwo Constraint Framework: `stwo_constraint_framework` +- LogUp Protocol: https://eprint.iacr.org/2022/1530 +- STARKs: https://starkware.co/stark/ + +--- + +**Research Status:** Complete +**Related:** [Stoolap vs LuminAIR Comparison](./stoolap-luminair-comparison.md) diff --git a/docs/research/luminair-analysis.md b/docs/research/luminair-analysis.md new file mode 100644 index 0000000..e6b0e1a --- /dev/null +++ b/docs/research/luminair-analysis.md @@ -0,0 +1,375 @@ +# Research: LuminAIR Analysis for CipherOcto Integration + +## Executive Summary + +This research analyzes LuminAIR (by Giza) and explores how its zkML solutions can enhance CipherOcto's architecture. LuminAIR provides cryptographic proofs for ML computation integrity using Circle STARKs (Stwo prover), enabling verifiable AI agents, trustless inference, and privacy-preserving ML. + +## Problem Statement + +CipherOcto faces challenges that LuminAIR's approach could address: +1. **Privacy limitation**: Sellers see prompt content (trust-based model) +2. **Dispute resolution**: Relies on automated signals + reputation +3. **Verification gap**: No cryptographic proof of correct execution +4. **Agent trust**: No way to prove agents executed correctly + +## LuminAIR Deep Dive + +### Core Technology + +| Component | Technology | Purpose | +|-----------|------------|---------| +| **Proof System** | Circle STARKs | Scalable, transparent, post-quantum secure | +| **Prover** | Stwo (Starkware) | Ultra-efficient proof generation | +| **Arithmetization** | AIR (Algebraic Intermediate Representation) | Computational graph → polynomials | +| **Verification** | Rust + Cairo (planned) | On-chain verification | +| **Field** | M31 (highly efficient prime field) | Fast computation | + +### Architecture + +```mermaid +flowchart TD + subgraph PROVER["LuminAIR Prover"] + G[Computational Graph] --> C[StwoCompiler] + C --> A[AIR Generation] + A --> T[Execution Trace] + T --> P[Stwo Prover] + P --> PROOF[ZK Proof] + end + + subgraph VERIFIER["LuminAIR Verifier"] + PROOF --> V[Verify Constraints] + V --> V2[Verify LogUp] + V2 --> RESULT[Valid/Invalid] + end +``` + +### Key Innovations + +#### 1. AIR (Algebraic Intermediate Representation) +- Each operator maps to specific AIR constraints +- Local constraints ensure operation correctness +- LogUp lookup argument ensures data flow integrity + +#### 2. Circle STARKs (Stwo) +- More efficient than traditional STARKs +- Uses M31 prime field for speed +- SIMD backend for parallelization +- GPU acceleration planned (Icicle-Stwo) + +#### 3. Verification Options +| Verification Type | Status | Use Case | +|------------------|--------|----------| +| **Rust verifier** | ✅ Current | Off-chain verification | +| **WASM verifier** | 🔜 Phase 2 | Browser-based verification | +| **On-chain (Cairo)** | 🔜 Phase 3 | Starknet verification | +| **EigenLayer AVS** | 🔜 Phase 3 | Decentralized verification | + +### Use Cases from LuminAIR + +| Use Case | Description | +|----------|-------------| +| **Verifiable DeFi Agents** | zk-proved trading decisions | +| **Trustless Inference** | On-chain ML without re-execution | +| **Privacy-Preserving ML** | Selective disclosure of model inputs/outputs | +| **Scientific Computing** | Black-Scholes PINNs with proofs | +| **Healthcare** | Verifiable diagnosis assistance | + +--- + +## CipherOcto Integration Opportunities + +### 1. Privacy Upgrade Path (Selective Disclosure) + +**Current Problem**: Sellers see prompt content - trust assumption + +**LuminAIR Solution**: zkML with selective disclosure + +```mermaid +flowchart TD + subgraph CURRENT["Current (Trust-Based)"] + U[User] --> P[Proxy] + P -->|plaintext| S[Seller] + S -->|prompt| AI[AI Provider] + end + + subgraph ENHANCED["With zkML"] + U2[User] --> P2[CipherOcto Proxy] + P2 -->|encrypted + proof| S2[Seller] + S2 -->|verify proof| P2 + P2 -->|zk proof of correct routing| AI2[AI Provider] + end +``` + +**Proposal for CipherOcto**: +- Encrypt prompt at proxy layer +- Generate zk proof that routing was correct without revealing content +- Seller verifies proof without seeing actual prompt +- Use Stwo/Circle STARKs for efficiency + +**Implementation Phases**: +| Phase | Approach | Complexity | +|-------|----------|------------| +| Phase 1 | Basic encryption | Low | +| Phase 2 | Proof of routing (no content) | Medium | +| Phase 3 | Full selective disclosure | High | + +### 2. Verifiable Quality / Dispute Resolution + +**Current Problem**: RFC-0100 disputes rely on signals + reputation + +**LuminAIR Solution**: Proof of correct execution + +```mermaid +sequenceDiagram + Buyer->>Router: Submit prompt + Router->>Provider: Route to AI + Provider->>LuminAIR: Execute + generate proof + LuminAIR->>Router: Return result + ZK proof + Router->>Router: Verify proof + Router->>Buyer: Deliver result + proof + + alt Dispute + Buyer->>DisputeResolver: Challenge quality + DisputeResolver->>Router: Request proof + Router->>DisputeResolver: Submit proof + DisputeResolver->>DisputeResolver: Verify proof + DisputeResolver->>Buyer: Resolution (based on proof) + end +``` + +**Lightweight Proofs for MVE**: +- Not full zkML - just prove output shape/validity +- Latency proof: timestamp + hash of request/response +- Correct routing proof: prove X routed to Y without revealing prompt + +**Integration with RFC-0100**: +```rust +struct ExecutionProof { + input_hash: FieldElement, // Hash of encrypted input + output_hash: FieldElement, // Hash of output + model_type: String, // e.g., "gpt-4" + latency_ms: u64, // Execution time + timestamp: u64, // When executed + proof: CircleStarkProof, // ZK proof +} + +impl ExecutionProof { + fn verify(&self) -> bool { + // Verify Circle STARK proof + // Check latency within acceptable bounds + // Verify output shape matches model + } +} +``` + +### 3. Starknet/Cairo Alignment + +**Current State**: RFC-0102 already uses Starknet ECDSA, Poseidon hashing + +**LuminAIR Planned**: On-chain Cairo verifier + +```mermaid +flowchart LR + LUMIN[LuminAIR] -->|Phase 3| CAIRO[Cairo Verifier] + CAIRO --> STARKNET[Starknet Contract] + STARKNET --> VERIFY[On-chain Verification] +``` + +**CipherOcto Advantage**: +- Already on Starknet/Cairo - natural fit +- Can implement LuminAIR-style proofs without migration +- Stoolap uses same ecosystem (STWO integration) + +**Proposed Integration**: +```cairo +// Starknet contract for quota proof verification +#[starknet::contract] +mod QuotaProofVerifier { + fn verify_octo_routing_proof( + proof: CircleStarkProof, + input_hash: felt252, + output_hash: felt252, + provider: felt252, + ) -> bool { + // Verify the proof that OCTO-W was correctly routed + // No need to reveal actual prompt content + } +} +``` + +### 4. Agent Verifiability + +**Narrative Alignment**: Both projects target "verifiable intelligence" + +```mermaid +flowchart TD + subgraph CIPHER["CipherOcto"] + R[Quota Router] --> A[Agent Execution] + A --> Q[OCTO-W Payment] + end + + subgraph LUMIN["LuminAIR"] + L[Verifiable Agent] --> P[ZK Proof] + end + + R -->|access layer| L + A -->|feeds into| P + + style R fill:#1f618d + style A fill:#b03a2e + style L fill:#6c3483 + style P fill:#27ae60 +``` + +**Positioning**: +- CipherOcto's quota router = access layer +- LuminAIR-style proofs = verification layer +- Combined = "verifiable autonomous agents" + +--- + +## New Use Cases for CipherOcto + +Based on LuminAIR analysis, new opportunities emerge: + +### 1. Verifiable AI Agents (DeFi) + +**Use Case**: Trading agents with provable decision history + +```rust +struct VerifiableTradingAgent { + // Standard agent capabilities + agent: Agent, + + // ZK enhancements + decision_proofs: Vec, +} + +struct DecisionProof { + market_data_hash: FieldElement, + decision_hash: FieldElement, + reasoning_hash: FieldElement, // Not full reasoning - just hash + timestamp: u64, + proof: CircleStarkProof, +} +``` + +**Integration with Quota Router**: +- Agent pays OCTO-W for inference +- Generates proof of correct execution +- On-chain verification for transparency + +### 2. Privacy-Preserving Query Routing + +**Use Case**: Confidential prompts with verifiable routing + +```mermaid +flowchart TD + U[User] -->|encrypt| P[Proxy] + P -->|commitment| S[Seller] + S -->|verify routing proof| P + P -->|decrypt| U + + style U fill:#b03a2e + style P fill:#1f618d + style S fill:#27ae60 +``` + +**Properties**: +- Seller verifies routing without seeing prompt +- ZK proof demonstrates correct execution +- Selective disclosure: reveal only when needed + +### 3. Provable Quality of Service + +**Use Case**: SLA enforcement with cryptographic guarantees + +| Metric | Proof Type | On-chain Settleable | +|--------|------------|---------------------| +| Latency | Timestamp + hash | ✅ | +| Output validity | Shape check | ✅ | +| Model execution | zkML proof | ✅ | +| Routing correctness | Merkle path | ✅ | + +--- + +## Implementation Recommendations + +### Phase 1: Immediate (MVE Enhancement) + +| Enhancement | Description | Effort | +|-------------|-------------|--------| +| **Latency proofs** | Timestamp + hash for timing disputes | Low | +| **Output hashing** | Hash outputs for later verification | Low | +| **Routing logs** | Merkle-tree of routing decisions | Medium | + +### Phase 2: Near-term (Post-MVE) + +| Enhancement | Description | Effort | +|-------------|-------------|--------| +| **Basic zkML** | Prove model executed without revealing input | Medium | +| **WASM verifier** | Browser-based proof verification | Medium | +| **Starknet verifier** | On-chain proof settlement | Medium | + +### Phase 3: Future (Full Integration) + +| Enhancement | Description | Effort | +|-------------|-------------|--------| +| **Full zkML** | Complete inference verification | High | +| **EigenLayer AVS** | Decentralized verification network | High | +| **Selective disclosure** | User-controlled data release | High | + +--- + +## Technical Stack Alignment + +| Component | CipherOcto | LuminAIR | Alignment | +|-----------|------------|----------|-----------| +| **Blockchain** | Starknet | Starknet (planned) | ✅ Perfect | +| **ZK Prover** | Stoolap STWO | Stwo | ✅ Same ecosystem | +| **Signature** | Starknet ECDSA | Circle STARKs | ✅ Complementary | +| **Language** | Rust | Rust | ✅ Compatible | +| **Verification** | Cairo (future) | Cairo (planned) | ✅ Aligned | + +--- + +## Risk Assessment + +| Risk | Severity | Mitigation | +|------|----------|------------| +| zkML overhead too high for MVE | Medium | Start with lightweight proofs | +| Integration complexity | Medium | Phase approach | +| Stoolap + LuminAIR overlap | Low | Different focus (DB vs ML) | +| Performance at scale | Medium | GPU acceleration later | + +--- + +## Conclusion + +LuminAIR's zkML approach offers significant opportunities for CipherOcto: + +1. **Privacy**: Upgrade from trust-based to cryptographic +2. **Disputes**: Replace reputation with proof-based resolution +3. **Alignment**: Starknet/Cairo ecosystem already aligned +4. **Narrative**: "Verifiable intelligence" positions both projects + +**Recommended Actions**: +- [ ] Create RFC for zkML Integration +- [ ] Prototype lightweight proof of routing +- [ ] Evaluate Stoolap + Stwo integration +- [ ] Plan on-chain verifier for Phase 3 + +--- + +## References + +- LuminAIR: https://github.com/gizatechxyz/LuminAIR +- Stwo: https://github.com/starkware-libs/stwo +- Circle STARKs Paper: https://eprint.iacr.org/2024/278 +- LogUp Protocol: https://eprint.iacr.org/2022/1530 +- Stoolap: https://github.com/CipherOcto/stoolap + +--- + +**Research Status:** Complete +**Recommended Action:** Create RFC for zkML Integration diff --git a/docs/research/memos-research.md b/docs/research/memos-research.md new file mode 100644 index 0000000..fd11187 --- /dev/null +++ b/docs/research/memos-research.md @@ -0,0 +1,268 @@ +# MemOS Research Report + +**Project**: MemOS - Memory Operating System for AI Systems +**Location**: https://github.com/MemTensor/MemOS +**Date**: March 2026 +**Status**: Research Complete + +--- + +## Executive Summary + +MemOS (Memory Operating System) is a production-grade memory management system designed specifically for Large Language Models (LLMs) and AI agents. It provides a unified abstraction layer for storing, retrieving, and managing long-term memory across heterogeneous storage backends. + +### Key Performance Metrics + +| Metric | Improvement vs OpenAI Memory | +|--------|------------------------------| +| Accuracy | **+43.70%** | +| Memory Token Savings | **35.24%** | + +MemOS was published on arXiv as "MemOS: A Memory OS for AI System" and represents a significant advancement in AI memory architecture. + +--- + +## 1. Architecture Overview + +MemOS employs a layered architecture that separates concerns between memory types, storage backends, and access patterns: + +```mermaid +graph TB + subgraph "Client Layer" + A[AI Agent / LLM] + end + + subgraph "API Layer" + B[FastAPI REST Server] + end + + subgraph "Core Layer" + C[MemScheduler] + D[MemCube Container] + end + + subgraph "Memory Types" + E[Text Memory] + F[Action Memory] + G[Parametric Memory] + H[Preference Memory] + end + + subgraph "Storage Layer" + I[Vector DBs
Qdrant, Milvus] + J[Graph DBs
Neo4j, NebulaGraph] + K[Redis Streams
Task Queue] + end + + A --> B + B --> C + C --> D + D --> E + D --> F + D --> G + D --> H + E --> I + F --> J + G --> I + H --> I + C --> K +``` + +### Design Principles + +1. **Unified Abstraction**: Single interface for heterogeneous storage +2. **Type-Specific Handling**: Four distinct memory types for different data characteristics +3. **Async-First**: Non-blocking operations via Redis Streams +4. **Production-Ready**: FastAPI REST API for easy integration + +--- + +## 2. Core Components + +### 2.1 MemCube + +MemCube serves as the central container that orchestrates all memory types. It provides a unified API for: + +- Registering and managing different memory types +- Coordinating storage operations across backends +- Handling cross-memory queries and relationships + +### 2.2 MemScheduler + +The MemScheduler is an asynchronous task scheduling system built on Redis Streams. It handles: + +- Background memory consolidation tasks +- Scheduled cleanup and garbage collection +- Priority-based task execution +- Distributed locking for consistency + +### 2.3 API Layer + +The API layer is built with FastAPI and provides: + +- RESTful endpoints for CRUD operations +- Vector search capabilities +- Memory management endpoints +- Health and monitoring endpoints + +--- + +## 3. Memory Types + +MemOS distinguishes between four distinct memory types, each optimized for different data characteristics: + +### 3.1 Text Memory + +**Purpose**: Store conversational context, documents, and general text data. + +**Characteristics**: +- High-volume text storage +- Semantic search via vector embeddings +- Supports long-form content + +**Storage**: Vector databases (Qdrant, Milvus) + +### 3.2 Action Memory + +**Purpose**: Record agent actions, decisions, and execution traces. + +**Characteristics**: +- Temporal ordering important +- Causal relationships between actions +- Graph-like structure for action chains + +**Storage**: Graph databases (Neo4j, NebulaGraph) + +### 3.3 Parametric Memory + +**Purpose**: Store learned parameters, weights, and model-specific data. + +**Characteristics**: +- Structured numerical data +- Requires efficient similarity search +- Updated frequently + +**Storage**: Vector databases (Qdrant, Milvus) + +### 3.4 Preference Memory + +**Purpose**: Capture user preferences, settings, and behavioral patterns. + +**Characteristics**: +- Key-value style access patterns +- User-specific data isolation +- Frequently read, occasionally written + +**Storage**: Vector databases with metadata indexing + +--- + +## 4. Storage Layer + +### 4.1 Vector Databases + +MemOS supports multiple vector databases for embedding storage and similarity search: + +| Database | Use Case | Strengths | +|----------|----------|-----------| +| **Qdrant** | Primary vector store | Rust-based, high performance, cloud-native | +| **Milvus** | Large-scale vector operations | Horizontal scaling, distributed | + +### 4.2 Graph Databases + +For action memory and relationship-heavy data: + +| Database | Use Case | Strengths | +|----------|----------|-----------| +| **Neo4j** | Action tracing | Mature, Cypher query language | +| **NebulaGraph** | High-scale graphs | Distributed, Facebook-origin | + +### 4.3 Redis Streams + +Used for the MemScheduler task queue: +- Async task processing +- Distributed message passing +- Task persistence and replay + +--- + +## 5. API & Integration + +### 5.1 REST API Endpoints + +The FastAPI server exposes endpoints for: + +``` +POST /memory # Store new memory +GET /memory/{id} # Retrieve memory by ID +SEARCH /memory/search # Vector similarity search +DELETE /memory/{id} # Delete memory +GET /health # Health check +``` + +### 5.2 Client Integration + +MemOS provides client libraries for easy integration with AI agents: +- Python SDK +- HTTP API for language-agnostic access +- WebSocket support for streaming updates + +--- + +## 6. Deployment + +### 6.1 Typical Deployment Stack + +```mermaid +graph LR + subgraph "MemOS Cluster" + A[API Server] --> B[MemScheduler] + B --> C[MemCube] + end + + subgraph "Storage" + C --> D[Qdrant/Milvus] + C --> E[Neo4j/NebulaGraph] + B --> F[Redis Cluster] + end +``` + +### 6.2 Scaling Considerations + +- **Horizontal**: Add more API instances behind load balancer +- **Storage**: Scale vector/graph databases independently +- **Async Processing**: Increase Redis/worker count for throughput + +--- + +## 7. Evaluation + +### 7.1 Performance Results + +MemOS demonstrates significant improvements over baseline solutions: + +| Metric | Result | +|--------|--------| +| Accuracy Improvement | **+43.70%** vs OpenAI Memory | +| Token Efficiency | **35.24%** memory token savings | + +### 7.2 Key Success Factors + +1. **Type Separation**: Distinct handling per memory type improves retrieval precision +2. **Graph Integration**: Action memory benefits from relationship modeling +3. **Async Architecture**: Redis Streams enables low-latency responses + +--- + +## 8. Conclusion + +MemOS represents a sophisticated approach to AI memory management. By separating concerns across four memory types and leveraging purpose-built storage systems, it achieves substantial improvements in accuracy and efficiency. + +The architecture demonstrates that generic memory solutions cannot match specialized systems that understand the distinct characteristics of different memory types. The combination of vector similarity search, graph relationships, and async processing creates a robust foundation for production AI systems requiring persistent memory. + +--- + +## References + +- arXiv: MemOS: A Memory OS for AI System +- Project Repository: https://github.com/MemTensor/MemOS diff --git a/docs/research/qdrant-research.md b/docs/research/qdrant-research.md new file mode 100644 index 0000000..d218478 --- /dev/null +++ b/docs/research/qdrant-research.md @@ -0,0 +1,428 @@ +# Qdrant Research Report + +**Project**: Qdrant - Vector Similarity Search Engine +**Location**: https://github.com/qdrant/qdrant +**Date**: March 2026 + +--- + +## Executive Summary + +Qdrant is a production-grade **vector similarity search engine** written in Rust. It serves as a vector database that stores, searches, and manages points—vectors with associated payloads—enabling neural network and semantic-based matching for AI applications. + +### Key Characteristics + +| Attribute | Value | +|-----------|-------| +| **Language** | Rust (v1.92+) | +| **License** | Apache 2.0 | +| **Version** | 1.17.0 | +| **Primary Use** | Vector similarity search | + +### Primary Use Cases + +- Semantic text search +- Similar image search +- Recommendation systems +- Chatbot memory/retrieval +- Anomaly detection +- Hybrid search (dense + sparse vectors) + +--- + +## 1. Architecture Overview + +Qdrant employs a **layered architecture** that separates concerns across API handling, collection management, core storage, and distributed coordination. + +```mermaid +graph TB + subgraph "Client Layer" + A[REST Clients] + B[gRPC Clients] + end + + subgraph "API Layer" + C[Actix-web
REST API] + D[Tonic
gRPC API] + end + + subgraph "Collection Layer" + E[Collection Manager] + F[Shard Management] + G[Consensus] + end + + subgraph "Segment Layer" + H[Segment] + I[HNSW Index] + J[Payload Index] + K[Vector Storage] + end + + subgraph "Storage Layer" + L[Table of Contents] + M[Consensus Manager] + N[RBAC] + end + + A --> C + B --> D + C --> E + D --> E + E --> F + E --> G + F --> H + H --> I + H --> J + H --> K + E --> L + G --> M +``` + +### Workspace Modules + +| Module | Path | Purpose | +|--------|------|---------| +| **segment** | `lib/segment` | Core data storage, indexing, retrieval | +| **collection** | `lib/collection` | Collection management, operations | +| **storage** | `lib/storage` | High-level storage coordination | +| **shard** | `lib/shard` | Sharding and replication | +| **api** | `lib/api` | REST and gRPC API definitions | +| **sparse** | `lib/sparse` | Sparse vector support (BM25-like) | +| **quantization** | `lib/quantization` | Vector quantization (PQ, SQ, BQ) | +| **consensus** | `src/consensus.rs` | Raft-based distributed consensus | + +--- + +## 2. Core Data Model + +### 2.1 Point Structure + +A **point** is the fundamental data unit in Qdrant, consisting of: + +```rust +pub struct ScoredPoint { + pub id: PointIdType, // Unique identifier + pub version: SeqNumberType, // Version for MVCC + pub score: ScoreType, // Similarity score + pub payload: Option, // JSON metadata + pub vector: Option, // Vector data + pub shard_key: Option, // Shard routing + pub order_value: Option, // Ordering +} +``` + +### 2.2 Vector Types + +| Type | Description | +|------|-------------| +| **Dense** | Standard float vectors | +| **Multi-dense** | Multiple vectors per point | +| **Quantized** | Compressed representations | +| **Sparse** | BM25-style sparse vectors | + +--- + +## 3. Key Features + +### 3.1 HNSW Vector Indexing + +**Semantic Purpose**: HNSW (Hierarchical Navigable Small World) provides fast approximate nearest neighbor search with configurable precision/performance tradeoffs. + +**Implementation** (`lib/segment/src/index/hnsw_index/hnsw.rs`): + +```rust +pub fn search( + &self, + top: usize, // Number of results + ef: usize, // Search width + algorithm: SearchAlgorithm, // HNSW or Acorn + mut points_scorer: FilteredScorer, + custom_entry_points: Option<&[PointOffsetType]>, + is_stopped: &AtomicBool, +) -> CancellableResult> +``` + +**Configuration Parameters**: +- `m`: Number of connections per node +- `ef_construction`: Build-time search width +- `ef`: Query-time search width + +**Why It Works**: +- Builds a multi-layer graph structure +- Higher layers contain "shortcuts" for fast traversal +- Greedy search with backtracking achieves high recall +- Supports both HNSW and Acorn search algorithms +- GPU acceleration available + +### 3.2 Payload Filtering + +**Semantic Purpose**: Enables rich query refinement using metadata attributes beyond vector similarity. + +**Field Index Types** (`lib/segment/src/index/field_index/`): + +| Index Type | Purpose | Query Examples | +|------------|---------|-----------------| +| `bool_index` | Boolean values | `is_active: true` | +| `map_index` | Keywords/IDs | `category: "electronics"` | +| `numeric_index` | Numeric ranges | `price: [10, 100]` | +| `geo_index` | Geospatial | `location: {within: polygon}` | +| `full_text_index` | Text search | `description: "machine learning"` | +| `facet_index` | Faceted navigation | `color: ["red", "blue"]` | +| `null_index` | NULL handling | `deleted_at: null` | + +**Filter Combinations**: +- `must`: All conditions must match (AND) +- `must_not`: None can match (NOT) +- `should`: At least one should match (OR) + +**Implementation Pattern**: +```rust +// Filter to index conversion +pub fn condition_to_index_query(&self, condition: &FieldCondition) -> Option> +``` + +### 3.3 Vector Quantization + +**Semantic Purpose**: Reduces memory footprint by compressing vectors while preserving similarity search capability. Can achieve up to 97% RAM reduction. + +**Types** (`lib/quantization/src/`): + +#### Scalar Quantization (SQ) +Converts float32 to uint8 by dividing by a scale factor. + +```rust +// lib/quantization/src/encoded_vectors_u8.rs +pub struct EncodedVectorsU8 { + data: Vec, + dim: usize, +} +``` + +#### Product Quantization (PQ) +Splits vectors into sub-vectors, clusters each separately, stores centroid indices. + +```rust +// lib/quantization/src/encoded_vectors_pq.rs +pub struct EncodedVectorsPQ { + data: Vec, + dim: usize, + sub_dim: usize, + centers: Vec>, +} +``` + +#### Binary Quantization (BQ) +Represents vectors as binary strings (0/1). + +```rust +// lib/quantization/src/encoded_vectors_binary.rs +pub struct EncodedVectorsBinary { + data: Vec, + dim: usize, +} +``` + +**Search with Quantization**: +```rust +pub fn similarity( + &self, + query: &[f32], + storage: &EncodedVectorsSlice, + top: usize, +) -> Vec<(VecOffsetType, ScoreType)> +``` + +### 3.4 Sparse Vectors (Hybrid Search) + +**Semantic Purpose**: Enables keyword-based matching alongside dense vector similarity, supporting hybrid search scenarios. + +**Implementation** (`lib/sparse/`): +- BM25-like text scoring +- Inverted index for term lookup +- Combines with dense vectors for relevance ranking + +### 3.5 Distributed Deployment + +**Architecture Components** (`lib/shard/` and `lib/collection/src/shards/`): + +| Shard Type | Purpose | +|------------|---------| +| **LocalShard** | Single-node storage | +| **RemoteShard** | Distributed peer storage | +| **ProxyShard** | Delegation patterns | +| **ReplicaSet** | Multiple replicas management | + +**Consensus Algorithm** (`src/consensus.rs`): +- Uses **Raft consensus** for distributed coordination +- Handles: + - Collection creation/deletion + - Shard transfers + - Replica state management + - Snapshot coordination + +**Consensus Operations**: +```rust +pub enum ConsensusOperations { + CollectionMeta(Box), + AddPeer { peer_id: PeerId, uri: String }, + RemovePeer(PeerId), + UpdatePeerMetadata { peer_id: PeerId, metadata: PeerMetadata }, + UpdateClusterMetadata { key: String, value: serde_json::Value }, + RequestSnapshot, + ReportSnapshot { peer_id: PeerId, status: SnapshotStatus }, +} +``` + +### 3.6 Write-Ahead Logging (WAL) + +- Custom WAL implementation ensures durability +- Provides crash recovery capability +- Used in both collection and consensus layers + +--- + +## 4. Storage Layer + +### 4.1 Segment Structure + +**File**: `lib/segment/src/segment/mod.rs` + +```rust +pub struct Segment { + pub uuid: Uuid, + pub version: Option, + pub segment_path: PathBuf, + pub version_tracker: VersionTracker, + pub id_tracker: Arc>, + pub vector_data: HashMap, + pub payload_index: Arc>, + pub payload_storage: Arc>, + pub segment_type: SegmentType, + pub segment_config: SegmentConfig, +} +``` + +### 4.2 Storage Backends + +| Backend | Feature Flag | Use Case | +|--------|--------------|----------| +| **Memory-mapped** | Default | Large vectors, general use | +| **RocksDB** | `rocksdb` | Larger datasets | +| **io_uring** | Linux only | High-throughput async I/O | + +### 4.3 Performance Optimizations + +- **SIMD Acceleration**: CPU SIMD instructions for vector operations +- **Memory Mapping**: Efficient large vector handling via `memmap2` +- **Parallel Processing**: Rayon for parallel operations +- **GPU Support**: CUDA acceleration for indexing +- **Jemalloc**: Custom memory allocator on Linux + +--- + +## 5. API Layer + +### 5.1 REST API + +- **Framework**: Actix-web (`src/actix/`) +- **OpenAPI**: Auto-generated from code +- **Key Endpoints**: + - Collection management (`/collections`) + - Point CRUD (`/collections/{name}/points`) + - Search queries (`/collections/{name}/points/search`) + - Snapshots + +### 5.2 gRPC API + +- **Framework**: Tonic (`lib/api/src/grpc/`) +- **Proto Definitions**: `lib/api/src/grpc/proto/` +- **Services**: + - Points operations + - Collections + - Snapshots + - Health checks + +### 5.3 Official Clients + +| Language | Package | +|----------|---------| +| Python | `qdrant-client` | +| Go | `qdrant-go` | +| Rust | `qdrant-client` | +| JavaScript | `@qdrant/js-client` | +| Java | `qdrant-java` | +| .NET | `Qdrant.Net` | + +--- + +## 6. Query Execution Flow + +```mermaid +sequenceDiagram + participant C as Client + participant A as API Layer + participant S as Segment + participant H as HNSW Index + participant P as Payload Index + + C->>A: Search Request + A->>A: Parse query & filters + + alt Has vector search + A->>H: Query HNSW graph + H-->>A: Candidate points + end + + alt Has filters + A->>P: Apply payload filters + P-->>A: Filtered candidates + end + + A->>A: Score & rank results + A-->>C: Return top-k results +``` + +--- + +## 7. Why Qdrant Works + +### 7.1 Design Decisions + +1. **Rust for Performance**: Memory safety without garbage collection overhead +2. **Layered Architecture**: Clear separation enables independent optimization +3. **Memory-Mapped Storage**: OS-level caching for large vector datasets +4. **Quantization**: Configurable precision/memory tradeoffs +5. **Hybrid Search**: Combines semantic (dense) and keyword (sparse) matching + +### 7.2 Key Success Factors + +| Factor | Implementation | +|--------|----------------| +| Fast ANNS | HNSW with tunable parameters | +| Rich Filtering | Multiple index types for payload | +| Memory Efficiency | Quantization up to 97% reduction | +| Distributed | Raft consensus for consistency | +| Production-Ready | WAL, snapshots, RBAC | + +--- + +## 8. Conclusion + +Qdrant is a sophisticated vector database that combines: + +- **High-performance approximate nearest neighbor search** via HNSW graphs +- **Rich payload filtering** with multiple specialized index types +- **Vector quantization** for dramatic memory savings +- **Distributed deployment** with Raft consensus +- **Hybrid search** combining dense vectors with sparse (BM25-like) vectors +- **Production-grade features**: WAL, snapshots, RBAC, multiple API protocols + +The layered architecture allows each component to be optimized independently while maintaining a coherent system. The choice of Rust enables performance-critical operations (SIMD, memory mapping, async I/O) while ensuring memory safety. + +--- + +## References + +- Repository: https://github.com/qdrant/qdrant +- Documentation: https://qdrant.tech/documentation/ diff --git a/docs/research/similar-projects-research.md b/docs/research/similar-projects-research.md new file mode 100644 index 0000000..df2bd0a --- /dev/null +++ b/docs/research/similar-projects-research.md @@ -0,0 +1,59 @@ +CipherOcto's Competitive Positioning Strategy +CipherOcto positions itself as a decentralized AI quota marketplace focused on bootstrapping developer adoption through idle API quota trading (e.g., OpenAI, Anthropic credits), with agent-based routing, local security (keys never leave your machine), and token utility from day one via OCTO-W. This niche emphasizes inference accessibility, timezone arbitrage, and seamless integration for AI devs — differentiating from broader compute markets by being AI-specific, user-centric, and low-barrier. To compete head-on with each project's strengths, CipherOcto should lean into its strengths: drop-in compatibility (OpenAI proxy), cost normalization across providers, reputation/slashing for trust, and early contributor multipliers for rapid liquidity. +Vs. Bittensor (TAO): Best at Collaborative ML Incentives & Subnet Specialization +Bittensor excels in creating a global, incentivized "brain" where miners contribute specialized ML models/subnets (e.g., for text gen or predictions), validated via "Proof of Intelligence" for quality rewards. +Positioning to compete: CipherOcto should highlight its own agent-driven, reputation-based marketplace as a "subnet for inference quotas" — allowing devs to contribute/sell idle API access as micro-subnets, with slashing for poor quality (e.g., timeouts/garbage responses) mirroring Bittensor's validation. Differentiate by focusing on immediate, low-effort participation (list spare quotas vs. running full models) and multi-provider normalization (e.g., equating GPT-4 to Claude units) for easier cross-model routing. Market as "Bittensor for quick AI access" to attract devs who want rewards without heavy ML ops. +Vs. Akash (AKT): Best at Permissionless Cloud/GPU Rental & Cost Savings +Akash dominates as a decentralized AWS alternative, with reverse auctions for leasing global hardware (CPUs/GPUs) at 50–90% lower costs, emphasizing scalability for any workload. +Positioning to compete: Emphasize CipherOcto's quota trading as "Akash for AI APIs" — a spot market for burst inference capacity (e.g., buy 1000 GPT prompts at auction-like prices) without provisioning servers. Compete on cost by enabling timezone arbitrage (e.g., US dev sells idle quota to Asian users) and auto-recharge policies for seamless scaling. Differentiate via AI-specific ergonomics: local proxies for zero-downtime routing, no hardware setup (just share API keys securely), and OCTO-W as metered credits — positioning as faster/cheaper for inference-only workloads vs. Akash's general compute. +Vs. Gensyn: Best at Aggregating Idle Hardware for ML Training +Gensyn shines in trustless ML training on distributed idle devices (GPUs, CPUs, even mobiles), with verification to ensure honest computation and massive cost reductions for large-scale models. +Positioning to compete: CipherOcto should frame itself as "Gensyn for inference" — aggregating idle API quotas (not hardware) for on-demand prompting, with future ZK proofs (as teased in docs) for verifiable responses. Compete by targeting inference-heavy devs (e.g., agent builders needing quick queries) where training isn't the bottleneck, offering lower latency via proxied APIs vs. Gensyn's distributed training delays. Differentiate with developer bootstrapping: early multipliers for quota contributors to build liquidity faster than Gensyn's hardware-focused network effects. +Vs. Ritual: Best at On-Chain AI Composability & Inference for dApps +Ritual leads in embedding AI directly into blockchains — enabling smart contracts/dApps to call models natively, with modular verification, privacy, and governance for composable AI (e.g., DeFi oracles with ML). +Positioning to compete: Position CipherOcto as "Ritual's off-ramp for real-world devs" — a hybrid layer where quota routers integrate with on-chain calls (e.g., swap OCTO-W via Starknet for Ritual-like composability). Compete on composability by evolving agent policies to support custom on-chain triggers (e.g., auto-route prompts based on blockchain events), with TEE/ZK for privacy matching Ritual's. Differentiate via standalone utility: no blockchain required for basic quota trading, plus multi-provider support (OpenAI + Anthropic) for broader access than Ritual's chain-specific focus. +Overall Strategy Recommendations + +Core differentiation: Double down on "frictionless bootstrapping" — CipherOcto's local router + quota flywheel (contribute idle → earn → buy more) lowers barriers compared to competitors' hardware/ML expertise needs. Use multipliers to hit 100 early contributors fast, creating network effects. +Marketing angle: Pitch as the "developer-first deAI gateway" — easier than Bittensor/Akash for quick wins, complementary to Gensyn/Ritual for inference (partner/integrate where possible, e.g., route to Ritual on-chain). +Roadmap leverage: Accelerate ZK/TEE for privacy/verification to close gaps with Gensyn/Ritual; expand to raw compute trading post-MVE to nibble at Akash. +Metrics for success: Aim for 1M OCTO-W volume in Month 1 (per use-case doc) by undercutting competitors' costs 20–30% via arbitrage. + +LuminAIR specializes in verifiable ML computations — cryptographically proving that a machine learning model (inference or forward pass) executed correctly using Circle STARK proofs powered by StarkWare's S-two (STWO) prover, often with Cairo programs for on-chain verification on Starknet. + +Positioning Options for CipherOcto +1. Get Inspiration (Recommended Starting Point – Low Effort, High Value) +LuminAIR / Giza's approach offers several concrete ideas CipherOcto can borrow without any partnership: + +Privacy upgrade path +CipherOcto's biggest current limitation is the trust assumption that sellers see prompt content when proxying requests. +→ Draw inspiration from zkML techniques to explore future-proofing with selective disclosure or encrypted prompts. Even if full ZK inference is too heavy for MVE, reference LuminAIR's Circle STARKs + STWO as a north star for eventual "provable clean routing" or "ZK proof of correct proxy execution without revealing prompt". +Verifiable quality / disputes +In RFC-0100 disputes (garbage response, failed inference), CipherOcto relies on automated signals + reputation. +→ Take cues from LuminAIR's proof-of-correct-execution to design lightweight proofs for "the model produced a valid output shape/latency" or integrate STWO-based verification for high-stake routes in Phase 2/3. +Starknet / Cairo alignment +CipherOcto's RFC-0102 already chooses Starknet ECDSA, Poseidon hashing, and Cairo-compatible structures. +→ This makes future integration technically natural. Use LuminAIR as inspiration to make quota proofs verifiable on Starknet (e.g., prove that X prompts were routed correctly and burned OCTO-W). +Agent verifiability +As both projects target autonomous agents, borrow the "verifiable intelligence" narrative: position CipherOcto's quota router as the access layer that feeds into verifiable execution layers like LuminAIR. + +2. Partnering / Integration (Medium-Term Opportunity) +A natural symbiosis exists, especially given shared Starknet ecosystem affinity: + +CipherOcto as the "data & access frontend" for LuminAIR agents +Verifiable agents (e.g., DeFi trading bots, autonomous recommenders) built on LuminAIR need reliable, cheap, burstable inference. CipherOcto can become the decentralized quota provider/routing layer that these agents call — e.g., a router policy that prefers "verifiable" routes when available. +Joint use-case: zk-proved quota usage +In the future, prove on-chain (via STWO + Cairo verifier) that a certain number of prompts were successfully routed/executed without revealing content — useful for OCTO-W burn transparency or dispute resolution. +Co-marketing in Starknet / deAI ecosystem +Both projects are early, Starknet-aligned, and agent-focused. A loose collaboration (e.g., "LuminAIR agents powered by CipherOcto quota routing") could help both bootstrap adoption. + +3. Against / Competitive Framing (Only If Forced) +Avoid direct "vs" framing — it's not apples-to-apples. If pressed: + +CipherOcto wins on immediate utility & developer onboarding (drop-in OpenAI proxy, earn from idle quota today). +LuminAIR wins on cryptographic trust & on-chain composability (verifiable outputs for smart contracts). +Position CipherOcto as complementary: "We get you the inference cheaply & scalably — LuminAIR proves it happened correctly." + +Bottom line recommendation (March 2026) +Start with inspiration — study LuminAIR's STWO integration, AIR design, and Cairo verifier patterns to roadmap your privacy & dispute upgrades (e.g., in reputation-system or custom-policy-engine missions). +Once MVE is live and you have real routing volume, reach out to Giza (they're active on X @gizatechxyz and open-source friendly) for potential integration discussions — especially around verifiable agents in DeFi or web3. The overlap in Starknet tooling makes this one of the more realistic and high-upside partnerships in the current deAI landscape. \ No newline at end of file diff --git a/docs/research/stoolap-integration-research.md b/docs/research/stoolap-integration-research.md new file mode 100644 index 0000000..bf32773 --- /dev/null +++ b/docs/research/stoolap-integration-research.md @@ -0,0 +1,281 @@ +# Research: Stoolap Integration with AI Quota Marketplace + +## Executive Summary + +This research investigates integrating the Stoolap blockchain SQL database (with its ZK proof capabilities) into the CipherOcto AI Quota Marketplace system. Stoolap provides verifiable state proofs, compressed STARK proofs, and confidential query operations that could enhance the quota marketplace's trust, transparency, and functionality. + +## Problem Statement + +The current AI Quota Marketplace design (RFC-0100, RFC-0101) faces challenges: +1. **Trust** - Buyers must trust sellers to execute prompts correctly +2. **Verification** - No cryptographic proof that work was completed +3. **Dispute Resolution** - Relies on reputation, not cryptographic verification +4. **State Management** - Centralized/off-chain listing registry + +Stoolap's blockchain SQL database with ZK proofs could address these. + +## Research Scope + +- What's included: Stoolap capabilities, integration points, protocol changes +- What's excluded: Full implementation details (belongs in RFC) + +--- + +## Stoolap Current Capabilities + +### Phase 1: Foundation (Complete) + +| Feature | Implementation | Details | +|--------|---------------|---------| +| **HexaryProof** | ✅ Implemented | 16-way Merkle trie, ~68 byte proofs | +| **Deterministic Types** | ✅ Implemented | DetermValue with inline/heap optimization | +| **Blockchain Consensus** | ✅ Implemented | Gas-metered transaction execution | +| **RowTrie** | ✅ Implemented | Hexary Merkle trie with proof generation | + +**Performance:** +- Proof size: ~68 bytes (target <100) +- Verification time: ~2-3 μs (target <5) +- Batch verification: ~50 μs for 100 proofs + +### Phase 2: Zero-Knowledge Proofs (Complete) + +| Feature | Implementation | Details | +|--------|---------------|---------| +| **STWO Integration** | ✅ Implemented | Circle STARK prover/verifier in Rust | +| **Cairo Programs** | ✅ Implemented | 3 Cairo programs | +| **Compressed Proofs** | ✅ Implemented | Aggregate multiple proofs | +| **Confidential Queries** | ✅ Implemented | Pedersen commitments | +| **L2 Rollup** | ✅ Implemented | Off-chain execution, on-chain verification | +| **STWO Plugin** | ✅ Implemented | Modular architecture | + +**Deliverables:** +- `stwo-plugin/` - STWO verification plugin (C-compatible FFI) +- `stwo-bench/` - Benchmarks +- `cairo/hexary_verify.cairo` - Proof verification +- `cairo/state_transition.cairo` - State transitions +- `cairo/merkle_batch.cairo` - Batch verification + +### Phase 3: Protocol Enhancement (Planned) + +| Feature | Status | RFC | +|--------|--------|-----| +| Block Production | Draft | RFC-0301 | +| Block Validation | Draft | RFC-0302 | +| Network Protocol | Draft | RFC-0303 | +| Signature Schemes | Draft | RFC-0304 | + +--- + +## Integration Opportunities + +### 1. Verifiable Quote Execution + +**Current Problem:** No cryptographic proof that seller executed the prompt. + +**Stoolap Solution:** +- Seller submits transaction to Stoolap with prompt hash +- Stoolap generates HexaryProof of execution +- Buyer verifies proof without trusting seller + +```rust +// Seller submits execution +let tx = Transaction::new( + prompt_hash, + response_hash, + seller_wallet, +); + +// Stoolap generates proof +let proof = hexary_proof::verify(&tx); + +// Buyer verifies +hexary_proof::verify(proof).unwrap(); +``` + +### 2. Compressed Proof Marketplace + +**Current Problem:** Each prompt verification requires individual proof. + +**Stoolap Solution:** +- Aggregate multiple prompt executions into single STARK proof +- Dramatically reduce on-chain verification costs + +```rust +// Batch of 1000 executions +let batch = PromptBatch::new(prompts); + +// Compress to single STARK +let stark_proof = stwo_prover::prove(batch); + +// On-chain verification: single proof vs 1000 +``` + +### 3. Confidential Query Operations + +**Current Problem:** Marketplace sees all listing details, pricing. + +**Stoolap Solution:** +- Use Pedersen commitments for listing details +- Prove listing validity without revealing specifics +- Enable private bidding + +```rust +// Encrypted listing +let commitment = pedersen::commit(listing.price, listing.quantity); + +// Prove price in range without revealing +let range_proof = pedersen::range_proof(commitment, 0..1000); +``` + +### 4. Decentralized Listing Registry + +**Current Problem:** Centralized or off-chain registry. + +**Stoolap Solution:** +- On-chain listing registry with Stoolap +- Each listing is a blockchain record +- Verifiable state transitions + +```rust +// Listing as blockchain record +struct Listing { + id: u64, + seller: Address, + provider: String, + quantity: u64, + price_per_prompt: u64, + commitment: Hash, +} + +// Create listing transaction +let tx = ListingTx::Create(Listing { ... }); + +// Stoolap generates state proof +let proof = row_trie::prove(&tx); +``` + +### 5. L2 Rollup for Scale + +**Current Problem:** High on-chain costs for small transactions. + +**Stoolap Solution:** +- Execute marketplace on L2 +- Batch thousands of operations +- Submit single proof to L1 + +--- + +## Required Changes to Current Design + +### Use Case Changes + +| Current | Proposed | Rationale | +|---------|----------|-----------| +| Off-chain registry | Stoolap on-chain registry | Verifiable, decentralized | +| Reputation-based trust | Proof-based trust | Cryptographic, not social | +| Manual dispute | Automated proof verification | Faster resolution | +| Fixed pricing | Confidential auctions | Privacy-preserving | + +### RFC-0100 Changes + +| Section | Change | +|---------|--------| +| **Registry** | Add Stoolap on-chain option | +| **Settlement** | Add ZK proof verification step | +| **Dispute** | Add "submit proof" resolution path | +| **Escrow** | Use Stoolap state for escrow | + +### RFC-0101 Changes + +| Section | Change | +|---------|--------| +| **Provider** | Add Stoolap provider type | +| **Verification** | Add proof submission after execution | +| **Balance** | Read from Stoolap state | + +--- + +## Architecture Proposal + +``` +┌─────────────────────────────────────────────────────────────┐ +│ CipherOcto Network │ +│ ┌─────────────────┐ ┌─────────────────────────────┐ │ +│ │ Quota Router │───▶│ Stoolap L2 │ │ +│ │ Agent │ │ ┌─────────────────────────┐ │ │ +│ │ (RFC-0101) │ │ │ Listing Registry │ │ │ +│ └─────────────────┘ │ │ - Create listing │ │ │ +│ │ │ │ - Update quantity │ │ │ +│ ▼ │ │ - Verify execution │ │ │ +│ ┌─────────────────┐ │ └─────────────────────────┘ │ │ +│ │ Market Client │ │ ┌─────────────────────────┐ │ │ +│ │ │───▶│ │ ZK Proof Layer │ │ │ +│ └─────────────────┘ │ │ - HexaryProof │ │ │ +│ │ │ │ - STARK compression │ │ │ +│ ▼ │ │ - Confidential ops │ │ │ +│ ┌─────────────────┐ │ └─────────────────────────┘ │ │ +│ │ Stoolap │◀───│ │ │ +│ │ Node │ │ │ │ +│ └─────────────────┘ └─────────────────────────────┘ │ +│ │ │ +│ ▼ │ +│ ┌─────────────────┐ │ +│ │ L1 Settlement │ (Ethereum/other) │ +│ └─────────────────┘ │ +└─────────────────────────────────────────────────────────────┘ +``` + +--- + +## Risk Assessment + +| Risk | Mitigation | Severity | +|------|------------|----------| +| Integration complexity | Phased rollout | Medium | +| Performance overhead | Use L2, batch proofs | Low | +| ZK proof generation time | Pre-compute, async | Medium | +| Stoolap not production-ready | Run on testnet first | Medium | + +--- + +## Recommendations + +### Recommended Approach + +1. **Phase 1 (MVE):** Keep current design, add Stoolap as future upgrade path +2. **Phase 2:** Add Stoolap provider type to router (optional verification) +3. **Phase 3:** Migrate to on-chain registry with Stoolap +4. **Phase 4:** Enable confidential queries, L2 rollup + +### Key Integration Points + +| Priority | Integration | Impact | +|----------|-------------|--------| +| High | Stoolap provider type | Enable proof-based verification | +| High | On-chain listing registry | Decentralize registry | +| Medium | STARK proof batching | Reduce costs | +| Medium | Confidential queries | Privacy | +| Low | L2 rollup | Scale | + +--- + +## Next Steps + +- [ ] Create Use Case for Stoolap integration? +- [ ] Draft RFC for Stoolap provider type +- [ ] Define migration path from off-chain to on-chain + +--- + +## References + +- Parent Document: BLUEPRINT.md +- Stoolap: `/home/mmacedoeu/_w/databases/stoolap` +- Stoolap RFCs: `rfcs/0101`, `rfcs/0201-0205` +- CipherOcto Use Case: `docs/use-cases/ai-quota-marketplace.md` +- CipherOcto RFCs: `rfcs/0100`, `rfcs/0101` + +--- + +**Research Status:** Complete +**Recommended Action:** Proceed to Use Case update diff --git a/docs/research/stoolap-luminair-comparison.md b/docs/research/stoolap-luminair-comparison.md new file mode 100644 index 0000000..5c5df8b --- /dev/null +++ b/docs/research/stoolap-luminair-comparison.md @@ -0,0 +1,589 @@ +# Research: Stoolap ZK Extensions vs LuminAIR Comparison + +## Executive Summary + +This report provides a comprehensive technical comparison between the zero-knowledge proof systems implemented in **Stoolap** (blockchain SQL database) and **LuminAIR** (zkML framework by Giza). Both leverage Circle STARKs and Stwo prover, but serve different domains and have complementary capabilities. + +## Overview + +| Aspect | Stoolap | LuminAIR | +|--------|---------|----------| +| **Domain** | Blockchain SQL database | Machine learning inference | +| **Primary Proof Type** | Merkle (Hexary) + STARK | STARK (zkML) | +| **Prover** | Stwo (Circle STARKs) | Stwo (Circle STARKs) | +| **Language** | Rust | Rust | +| **Target** | Database integrity, confidential queries | ML computation integrity | +| **Status** | Phase 2 Complete | Phase 1 Active | + +--- + +## Core Technology Comparison + +### 1. Proof System + +#### Stoolap: Dual-Layer Proofs + +```mermaid +flowchart TD + subgraph LAYER1["Layer 1: Hexary Merkle"] + H[SQL Query] --> HT[Hexary Trie] + HT --> HP[HexaryProof
~68 bytes] + end + + subgraph LAYER2["Layer 2: STARK Compression"] + HP --> CP[Batch of HexaryProofs] + CP --> SP[STARK Proof
~100-500 KB] + end + + LAYER1 -->|compress| LAYER2 +``` + +**Key Features:** +- **HexaryProof**: 16-way trie Merkle proofs (~68 bytes) +- **CompressedProof**: Aggregate multiple HexaryProofs into one STARK +- **Proof size**: 100-500 KB (STARK) +- **Verification**: ~2-3 μs (Hexary), depends on STARK (LuminAIR) + +#### LuminAIR: zkML Proofs + +```mermaid +flowchart TD + subgraph GRAPH["Computational Graph"] + ML[ML Model] --> T[Tensors] + T --> OP[Operators] + end + + subgraph PROOF["ZK Proof Generation"] + OP --> AIR[AIR Generation] + AIR --> TRACE[Execution Trace] + TRACE --> STWO[Stwo Prover] + STWO --> ZK[ZK Proof] + end + + GRAPH -->|compile| PROOF +``` + +**Key Features:** +- **Operators**: 11 primitive operators, Mul, Sin (Add, Exp2, etc.) +- **AIR**: Algebraic Intermediate Representation per operator +- **Trace**: Execution trace for each operator +- **LogUp**: Lookup argument for tensor data flow + +### 2. Field & Curve + +| Component | Stoolap | LuminAIR | +|-----------|---------|----------| +| **Field** | M31 (2^31 - 1) | M31 (2^31 - 1) | +| **Curve** | Circle STARK | Circle STARK | +| **Prover** | Stwo | Stwo | +| **Verifier** | Rust + Cairo plugin | Rust (WASM planned) | + +**Note**: Both use the same underlying technology - Stwo prover with M31 prime field. + +### 3. Commitment Schemes + +#### Stoolap + +```rust +// Pedersen commitments for confidential queries +pub struct Commitment { + point: Point, + randomness: Scalar, +} + +// Commitment to filter values +pub struct EncryptedFilter { + column: Vec, + operator: FilterOp, + value_commitment: Commitment, + nonce: [u8; 32], +} +``` + +#### LuminAIR + +```rust +// LogUp lookup argument for tensor data flow +// Ensures output of one operator = input of next +// Uses M31 field arithmetic +``` + +**Comparison:** + +| Aspect | Stoolap | LuminAIR | +|--------|---------|----------| +| **Commitment** | Pedersen (discrete log) | LogUp (lookup) | +| **Purpose** | Hide filter values | Prove tensor flow | +| **Integration** | SQL filters | ML operator chains | + +--- + +## Architecture Comparison + +### Stoolap ZK Architecture + +``` +┌─────────────────────────────────────────────────────────────┐ +│ Stoolap ZK Stack │ +├─────────────────────────────────────────────────────────────┤ +│ Applications │ +│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ +│ │SQL Queries │ │Confidential │ │ L2 Rollup │ │ +│ │ │ │ Queries │ │ │ │ +│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │ +│ │ │ │ │ +├─────────┴────────────────┴────────────────┴─────────────────┤ +│ Proof Generation │ +│ ┌─────────────────────────────────────────────────────┐ │ +│ │ HexaryProof → CompressedProof → StarkProof │ │ +│ │ (Merkle) (Batching) (STWO) │ │ +│ └─────────────────────────────────────────────────────┘ │ +├─────────────────────────────────────────────────────────────┤ +│ Cairo Programs │ +│ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │ +│ │hexary_verify │ │merkle_batch │ │state_transition│ │ +│ └───────────────┘ └───────────────┘ └───────────────┘ │ +├─────────────────────────────────────────────────────────────┤ +│ STWO Integration (Plugin Architecture) │ +└─────────────────────────────────────────────────────────────┘ +``` + +### LuminAIR zkML Architecture + +``` +┌─────────────────────────────────────────────────────────────┐ +│ LuminAIR zkML Stack │ +├─────────────────────────────────────────────────────────────┤ +│ Applications │ +│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ +│ │Verifiable │ │Trustless │ │Privacy │ │ +│ │DeFi Agents │ │Inference │ │Preserving ML│ │ +│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │ +│ │ │ │ │ +├─────────┴────────────────┴────────────────┴─────────────────┤ +│ Prover (Stwo) │ +│ ┌─────────────────────────────────────────────────────┐ │ +│ │ Computational Graph → AIR → Trace → Proof │ │ +│ │ (Luminal) (StwoCompiler) (Stwo) │ │ +│ └─────────────────────────────────────────────────────┘ │ +├─────────────────────────────────────────────────────────────┤ +│ Primitive Operators (11) │ +│ ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ ┌───────┐ │ +│ │Add/Mul│ │Exp2 │ │ Sin │ │ Sqrt │ │ Log2 │ ... │ +│ └───────┘ └───────┘ └───────┘ └───────┘ └───────┘ │ +├─────────────────────────────────────────────────────────────┤ +│ Data Flow: LogUp Lookup Argument │ +│ ┌─────────────────────────────────────────────────────┐ │ +│ │ Output Yields = Input Consumes (multiplicity) │ │ +│ └─────────────────────────────────────────────────────┘ │ +└─────────────────────────────────────────────────────────────┘ +``` + +--- + +## Feature Comparison Matrix + +| Feature | Stoolap | LuminAIR | Notes | +|---------|---------|----------|-------| +| **Proof Type** | | | | +| Merkle (Hexary) | ✅ | ❌ | Stoolap-specific | +| STARK (Circle) | ✅ | ✅ | Both use Stwo | +| zkML | ❌ | ✅ | LuminAIR specialty | +| **Operators** | | | | +| Primitive set | N/A | 11 | LuminAIR ML-focused | +| SQL operations | ✅ | ❌ | Stoolap database | +| ML operations | ❌ | ✅ | LuminAIR compute | +| **Confidentiality** | | | | +| Pedersen commitments | ✅ | ❌ | Stoolap | +| LogUp lookup | ❌ | ✅ | LuminAIR | +| Encrypted queries | ✅ | Partial | Both | +| **Verification** | | | | +| Rust verifier | ✅ | ✅ | Current | +| WASM verifier | ❌ | 🔜 | LuminAIR Phase 2 | +| Cairo (on-chain) | ✅ | 🔜 | Both planned | +| **Performance** | | | | +| HexaryProof size | ~68 bytes | N/A | Stoolap | +| STARK proof | 100-500 KB | Varies | Model size | +| Hexary verify | ~2-3 μs | N/A | Stoolap | +| ML verify | N/A | ~seconds | LuminAIR | + +--- + +## Detailed Capability Analysis + +### 1. Proof Generation + +#### Stoolap + +```rust +// SQL query → HexaryProof → CompressedProof → StarkProof +let query_result = db.execute(query); +let hexary_proof = row_trie.prove(query_result)?; +let compressed = compress_proofs(batch_of_hexary)?; +let stark_proof = stwo_prover.prove(compressed)?; +``` + +**Flow:** +1. Execute SQL query +2. Generate HexaryProof (Merkle) +3. Batch multiple proofs +4. Compress to STARK +5. Submit to L2 or verify + +#### LuminAIR + +```rust +// ML Model → Graph → AIR → Trace → Proof +let mut cx = Graph::new(); +let result = cx.tensor((2,2)).set(vec![1.0, 2.0, 3.0, 4.0]); +cx.compile(<(GenericCompiler, StwoCompiler)>::default(), &mut d); +let trace = cx.gen_trace()?; +let proof = cx.prove(trace)?; +cx.verify(proof)?; +``` + +**Flow:** +1. Build computational graph +2. Define operators +3. Compile to AIR (StwoCompiler) +4. Generate execution trace +5. Prove with Stwo +6. Verify proof + +### 2. Data Flow Integrity + +#### Stoolap: Hexary Trie + +```rust +// Data flow in database operations +struct HexaryProof { + key: Vec, + value: Vec, + siblings: Vec, // 16-way + path: NibblePath, +} +``` + +- **Structure**: 16-way branching (nibble-based) +- **Proof size**: ~68 bytes typical +- **Verification**: ~2-3 microseconds +- **Use case**: SQL query result verification + +#### LuminAIR: LogUp + +```rust +// Data flow between ML operators +// Output Yields (positive multiplicity) +// Input Consumes (negative multiplicity) +// Ensures tensor flows correctly through graph +``` + +- **Purpose**: Prove operator outputs connect to correct inputs +- **Method**: LogUp lookup argument +- **Use case**: ML inference integrity + +### 3. Confidential Queries + +#### Stoolap (RFC-0203) + +```rust +// Confidential SQL query +struct EncryptedQuery { + encrypted_sql: Vec, + input_commitments: Vec, + range_proofs: Vec, +} + +struct EncryptedFilter { + column: Vec, + operator: FilterOp, + value_commitment: Commitment, + nonce: [u8; 32], +} +``` + +**Capabilities:** +- ✅ Encrypted WHERE clauses +- ✅ Commitment-based filters +- ✅ Range proofs +- ✅ Result verification without revealing data + +#### LuminAIR + +- Partial support via encrypted inputs +- Future: selective disclosure +- Focus is integrity, not confidentiality + +### 4. Verification + +#### Stoolap + +```rust +// Rust verification +pub fn verify_hexary(proof: &HexaryProof, root: &FieldElement) -> bool; + +// Cairo on-chain (via plugin) +pub fn verify_stark_cairo(proof: &StarkProof) -> Result; +``` + +#### LuminAIR + +```rust +// Rust verification (current) +cx.verify(proof)?; + +// Planned: WASM verifier +// Planned: Cairo verifier (on-chain) +``` + +--- + +## Complementary Capabilities + +### What Stoolap Does Better + +| Capability | Stoolap Advantage | +|-----------|------------------| +| **Database proofs** | HexaryProof specifically designed for trie/table verification | +| **Batch verification** | Efficient parallel batch verification | +| **SQL integrity** | Query result verification with merkle proofs | +| **Confidential queries** | Full Pedersen commitment scheme | +| **L2 rollup** | Complete rollup protocol implemented | + +### What LuminAIR Does Better + +| Capability | LuminAIR Advantage | +|-----------|------------------| +| **zkML** | Purpose-built for ML inference proofs | +| **Operator library** | 11 primitive ML operators | +| **AIR generation** | Automatic from computational graph | +| **Data flow proof** | LogUp for tensor connections | +| **SIMD parallel** | Native SIMD backend | + +### Synergies for CipherOcto + +```mermaid +flowchart TD + subgraph CIPHER["CipherOcto Integration"] + S[Stoolap] -->|confidential queries| C[CipherOcto] + L[LuminAIR] -->|zkML inference| C + C -->|combine| Q[Quadrant 1] + end + + subgraph POSSIBILITIES["Combined Capabilities"] + Q -->|1| A[Verifiable SQL + ML] + Q -->|2| B[Confidential ML Inference] + Q -->|3| C[Proven Data Pipeline] + end + + A -->|example| AE[Query DB → ML inference → Prove] + B -->|example| BE[Encrypted query → ML → Encrypted result] + C -->|example| CE[Data integrity + model integrity] +``` + +--- + +## CipherOcto Integration Opportunities + +### 1. Shared Infrastructure + +Both systems use: +- **Stwo prover** (Circle STARKs) +- **M31 prime field** +- **Rust implementation** +- **Cairo verification (planned)** + +This creates natural synergy for CipherOcto. + +### 2. Recommended Architecture + +```mermaid +flowchart TB + subgraph CIPHER["CipherOcto Quota Router"] + Q[Query] --> P[Proxy] + end + + subgraph ZK["ZK Layer (Shared)"] + P -->|1| S[Stoolap] + P -->|2| L[LuminAIR] + + S -->|SQL proofs| SR[Result] + L -->|ML proofs| LR[Result] + end + + subgraph VERIFY["Verification Layer"] + SR --> V[Unified Verifier] + LR --> V + end + + subgraph SETTLE["Settlement"] + V --> OCTO[OCTO-W Payment] + end + + style ZK fill:#27ae60 + style VERIFY fill:#1f618d + style SETTLE fill:#6c3483 +``` + +### 3. Use Case Mapping + +| CipherOcto Need | Best Fit | Implementation | +|-----------------|----------|----------------| +| Query integrity | Stoolap | HexaryProof for routing logs | +| ML inference proof | LuminAIR | zkML for agent execution | +| Confidential routing | Stoolap | Pedersen commitments | +| Verifiable quality | LuminAIR | Output validity proofs | +| Data pipeline | Both | Combined SQL + ML proofs | + +## STWO Proof Benchmarks + +### Stoolap (STWO for Database Operations) + +| Operation | Time | Details| +|-----------|---------------| +| **Proof Generation** (merkle_batch) | ~25-28 seconds | Cairo program → STWO | +| **Proof Verification** | ~15 ms | Using stwo-cairo verifier | +| **HexaryProof** (no STWO) | ~2-3 μs | Lightweight Merkle proof only | + +**Source:** `missions/archived/0106-01-stwo-real-benchmarks.md` + +```rust +// Stoolap: PROVES CAIRO PROGRAMS +prove_cairo::() // ~25-28s +verify_cairo::() // ~15ms + +// Flow: SQL → Cairo program → stwo-cairo-prover → Proof +``` + +### LuminAIR (STWO for ML Operations) + +| Stage | Operation | Tensor Size | Status | +|-------|-----------|-------------|--------| +| Trace Generation | Add/Mul/Recip | 32x32 | Benchmarked | +| Proof Generation | Add/Mul/Recip | 32x32 | Benchmarked | +| Verification | Add/Mul/Recip | 32x32 | Benchmarked | + +**Source:** `crates/graph/benches/ops.rs` + +```rust +// LuminAIR: PROVES DIRECT AIR (NOT Cairo) +// Uses stwo constraint framework directly +prove(trace, settings) // Full pipeline +verify(proof, settings) + +// Flow: ML Graph → AIR (direct) → stwo → Proof +// NO Cairo compilation involved +``` + +### Critical Difference: Cairo vs Direct AIR + +| Aspect | Stoolap | LuminAIR | +|--------|---------|----------| +| **Proves** | Cairo programs | Direct AIR | +| **Prover** | `stwo-cairo-prover` | `stwo` (direct) | +| **Compilation** | SQL → Cairo | ML Graph → AIR | +| **Use case** | Database verification | ML inference | + +```mermaid +flowchart TD + subgraph STOOLAP["Stoolap: Cairo Path"] + SQL[SQL Query] --> CAIRO[Cairo Program] + CAIRO --> PROVE1[stwo-cairo-prover] + PROVE1 --> P1[Proof] + end + + subgraph LUMINAIR["LuminAIR: Direct AIR Path"] + GRAPH[ML Graph] --> AIR[AIR Generation] + AIR --> PROVE2[stwo (direct)] + PROVE2 --> P2[Proof] + end +``` + +### Is LuminAIR Better? + +**It depends on the use case:** + +| Criterion | Stoolap | LuminAIR | Winner | +|-----------|---------|----------|--------| +| **Database proofs** | ✅ Specialized | ❌ Not designed | **Stoolap** | +| **ML inference proofs** | ❌ Not designed | ✅ Specialized | **LuminAIR** | +| **Proof size** | Optimized | Varies | **Stoolap** (for DB) | +| **Verification speed** | 15ms | Unknown | TBD | +| **Operator flexibility** | Fixed (SQL) | extensible (11+ operators) | **LuminAIR** | + +### Key Insight + +The systems are **not directly comparable** - they prove different things: +- **Stoolap**: Proves SQL query results are correct (merkle batch) +- **LuminAIR**: Proves ML inference executed correctly (zkML) + +However, LuminAIR's approach could inspire **future optimizations** in Stoolap's proving pipeline. + +--- + +## Recommendations + +### Immediate (MVE) + +1. **Use Stoolap for**: + - Routing log integrity + - Balance verification + - Transaction proofs + +2. **Reference LuminAIR for**: + - Future zkML integration patterns + - AIR generation approach + - Operator design patterns + +### Near-term (Phase 2) + +1. **Integrate Stoolap**: + - Confidential queries for privacy + - Proof verification in Rust + - Commitment schemes + +2. **Adopt LuminAIR patterns**: + - zkML for agent verification + - Output validity proofs + - WASM verifier (when ready) + +### Future (Phase 3) + +1. **Combined approach**: + - On-chain verification (Cairo) + - EigenLayer AVS integration + - Unified proof standard + +--- + +## Conclusion + +| Aspect | Stoolap | LuminAIR | Verdict | +|--------|---------|----------|---------| +| **Database integrity** | ✅ Excellent | ❌ N/A | Stoolap for SQL | +| **ML integrity** | ❌ Not designed | ✅ Excellent | LuminAIR for zkML | +| **Cairo-based** | ✅ Yes | ❌ No | Stoolap (on-chain) | +| **Direct AIR** | ❌ No | ✅ Yes | LuminAIR (faster) | +| **Confidentiality** | ✅ Advanced | ⚠️ Basic | Stoolap leads | +| **Verification** | ✅ Rust + Cairo | ✅ Rust + WASM | Both strong | +| **Performance** | ✅ Optimized | 🔄 Improving | Stoolap faster for DB | + +**Key Finding**: Stoolap and LuminAIR are **complementary**, not competitive. Stoolap excels at database integrity and confidential queries. LuminAIR excels at ML inference verification. For CipherOcto, both can be leveraged: + +- **Stoolap**: Query/routing integrity, confidential storage +- **LuminAIR**: Agent execution verification, output proofs + +--- + +## References + +- Stoolap: https://github.com/CipherOcto/stoolap +- LuminAIR: https://github.com/gizatechxyz/LuminAIR +- Stwo: https://github.com/starkware-libs/stwo +- Circle STARKs: https://eprint.iacr.org/2024/278 +- LogUp: https://eprint.iacr.org/2022/1530 + +--- + +**Research Status:** Complete +**Prepared for:** CipherOcto ZK Integration Planning diff --git a/docs/research/stoolap-research.md b/docs/research/stoolap-research.md new file mode 100644 index 0000000..fd23e52 --- /dev/null +++ b/docs/research/stoolap-research.md @@ -0,0 +1,552 @@ +# Stoolap Research Report + +**Project**: Stoolap - Modern Embedded SQL Database +**Location**: https://github.com/stulast/stoolap +**Date**: March 2026 + +--- + +## Executive Summary + +Stoolap is a modern embedded SQL database written entirely in pure Rust (Apache 2.0 license). It targets low-latency transactional workloads and real-time analytical queries with modern SQL features and no external server process. + +### Key Differentiators + +| Feature | Stoolap | SQLite | DuckDB | PostgreSQL | +|---------|---------|--------|--------|------------| +| **Time-Travel Queries** | Built-in | No | No | Extension | +| **MVCC Transactions** | Yes | No | No | Yes | +| **Cost-Based Optimizer** | Yes | No | Yes | Yes | +| **Adaptive Query Execution** | Yes | No | No | Partial | +| **Semantic Query Caching** | Yes | No | No | No | +| **Parallel Query Execution** | Yes | No | Yes | Yes | +| **Native Vector Search** | Yes | Extension | Extension | Extension | +| **Pure Rust** | Yes | No | No | No | + +--- + +## 1. Architecture + +### 1.1 Layered Architecture + +```mermaid +graph TB + subgraph "API Layer" + A[Database] + B[Statement] + C[Transaction] + D[Rows] + end + + subgraph "Executor Layer" + E[Query Planner] + F[Expression VM] + G[Operators] + H[Caches] + end + + subgraph "Optimizer Layer" + I[Cost Estimation] + J[Join Optimization] + K[AQE] + L[Bloom Filters] + end + + subgraph "Storage Layer" + M[MVCC Engine] + N[Indexes] + O[WAL] + P[Persistence] + Q[Statistics] + end + + subgraph "Core" + R[Parser] + S[Functions] + T[Core Types] + end + + A --> E + E --> I + I --> M + M --> R + E --> F + F --> G + G --> H +``` + +### 1.2 Main Source Modules + +| Module | Purpose | +|--------|---------| +| `api/` | Public database interface (Database, Statement, Transaction) | +| `executor/` | Query execution engine with parallel execution | +| `optimizer/` | Cost-based optimization, AQE, join planning | +| `storage/` | MVCC engine, indexes, WAL, persistence | +| `parser/` | SQL parser (lexer, AST, statements) | +| `functions/` | 101+ built-in SQL functions | +| `core/` | Core types (DataType, Value, Row, Schema) | +| `consensus/` | Blockchain operation log (blocks, operations) | +| `trie/` | Merkle trie for state verification | +| `determ/` | Deterministic value types | + +--- + +## 2. Core Features + +### 2.1 MVCC Transactions + +**Semantic Purpose**: Provides snapshot isolation allowing consistent reads without locking, enabling concurrent read/write operations without blocking. + +**Implementation** (`src/storage/mvcc/engine.rs`): + +```rust +pub struct MVCCEngine { + // Version store: tracks multiple row versions + versions: BTreeMap>, + // Transaction registry: tracks active transactions + tx_registry: TransactionRegistry, + // Write set: modifications within transactions + write_sets: HashMap, +} +``` + +**Components**: + +| Component | Purpose | +|-----------|---------| +| `MvccTransaction` | Transaction context | +| `TransactionRegistry` | Global transaction tracking | +| `RowVersion` | Individual row version with metadata | +| `VisibilityChecker` | Determines visible versions per transaction | + +**Isolation Levels**: +- `ReadUncommitted`: No isolation +- `ReadCommitted`: See committed changes (default) +- `Snapshot`: See snapshot at transaction start (MVCC) + +### 2.2 Multiple Index Types + +**Semantic Purpose**: Different access patterns require different index structures for optimal performance. + +**Implementation** (`src/storage/index/mod.rs`): + +| Index Type | Use Case | Implementation | +|------------|----------|----------------| +| **BTreeIndex** | Range queries, sorted access | Standard B-tree | +| **HashIndex** | O(1) equality lookups | Hash map based | +| **BitmapIndex** | Low-cardinality columns | Roaring bitmaps | +| **HnswIndex** | Vector similarity search | HNSW algorithm | +| **MultiColumnIndex** | Composite queries | Composite keys | +| **PkIndex** | Primary key lookups | Virtual index | + +### 2.3 Cost-Based Optimizer + +**Semantic Purpose**: Selects optimal query execution plans based on data statistics rather than heuristic rules. + +**Implementation** (`src/optimizer/mod.rs`): + +```rust +pub struct Optimizer { + // Statistics collector + stats: Statistics, + // Cost estimation + cost_model: CostModel, + // Join reordering + join_optimizer: JoinOptimizer, + // Adaptive query execution + aqe: AdaptiveQueryExecution, +} +``` + +**Features**: +- **Statistics Collection**: Table/column statistics via `ANALYZE` +- **Histogram Support**: Range selectivity estimation +- **Zone Maps**: Segment pruning for columnar storage +- **Join Optimization**: Multiple join algorithms with cost estimation +- **Adaptive Query Execution (AQE)**: Runtime plan switching +- **Cardinality Feedback**: Learn from actual execution stats + +### 2.4 Semantic Query Caching + +**Semantic Purpose**: Intelligent caching that understands query semantics, not just exact string matches. A cached query with broader predicates can serve results for more specific queries. + +**Implementation** (`src/executor/semantic_cache.rs`): + +```rust +pub struct SemanticCache { + // Cached query results + cache: HashMap, + // Predicate analysis + predicate_analyzer: PredicateAnalyzer, +} + +impl SemanticCache { + /// Predicate subsumption: broader query covers narrower one + /// If cached: amount > 100, new query: amount > 150 + /// Filter cached results with additional predicate + pub fn get_or_execute(&self, query: &str, pred: Predicate) -> Option> { + // Check if new predicate subsumes cached predicate + if pred.subsumes(&cached_pred) { + // Apply additional filter to cached results + return Some(filter_results(cached_results, pred)); + } + None + } +} +``` + +**Capabilities**: +- **Predicate Subsumption**: `amount > 100` covers `amount > 150` +- **Numeric Range Tightening**: Narrow `>` and `<` predicates +- **Equality Subset**: `IN` clause narrowing +- **AND Conjunction Strengthening**: Adding more filters + +### 2.5 Time-Travel Queries + +**Semantic Purpose**: Access historical data at any point in time without maintaining separate history tables. + +**SQL Syntax**: + +```sql +-- Query data as of specific timestamp +SELECT * FROM accounts AS OF TIMESTAMP '2024-01-15 10:30:00'; + +-- Query data as of specific transaction +SELECT * FROM inventory AS OF TRANSACTION 1234; +``` + +**Implementation**: The MVCC engine maintains all row versions with timestamps and transaction IDs, enabling point-in-time queries. + +### 2.6 Parallel Query Execution + +**Semantic Purpose**: Utilize multi-core processors for faster query execution on large datasets. + +**Implementation** (`src/executor/parallel.rs`): + +Uses Rayon for parallel operations: + +```rust +// Parallel hash join +pub fn parallel_hash_join( + left: Vec, + right: Vec, + left_key: Expr, + right_key: Expr, +) -> JoinResult { + // Build phase: create hash table in parallel + let hash_table = left.par_chunks(CHUNK_SIZE) + .flat_map(|chunk| build_hash_table(chunk)) + .collect::>(); + + // Probe phase: lookup in parallel + right.par_chunks(CHUNK_SIZE) + .flat_map(|chunk| probe_hash_table(chunk, &hash_table)) + .collect() +} +``` + +**Parallel Operations**: +- Parallel hash join (build and probe phases) +- Parallel ORDER BY +- Parallel aggregation +- Configurable chunk sizes and thresholds + +### 2.7 Vector Search (HNSW) + +**Semantic Purpose**: Native vector similarity search for AI/ML applications without external services. + +**Implementation** (`src/storage/index/hnsw.rs`): + +```sql +-- Create table with vector column +CREATE TABLE embeddings ( + id INTEGER PRIMARY KEY, + content TEXT, + embedding VECTOR(384) +); + +-- Create HNSW index +CREATE INDEX idx_emb ON embeddings(embedding) +USING HNSW WITH (metric = 'cosine', m = 32, ef_construction = 400); + +-- Query with cosine distance +SELECT id, content, VEC_DISTANCE_COSINE(embedding, '[0.1, 0.2, ...]') AS dist +FROM embeddings ORDER BY dist LIMIT 10; +``` + +--- + +## 3. Storage Layer + +### 3.1 Write-Ahead Log (WAL) + +**Implementation** (`src/storage/mvcc/wal_manager.rs`): + +```rust +pub struct WalManager { + // Log file handle + log_file: File, + // Current log position + position: u64, + // Sync mode + sync_mode: SyncMode, + // Compression + compressor: Lz4Compressor, +} +``` + +**Features**: +- **Durable Logging**: All operations logged before applying +- **Configurable Sync Modes**: None, Normal, Full +- **WAL Rotation**: Automatic rotation at 64MB +- **Compression**: LZ4 compression for large entries +- **Checkpoint Support**: Periodic snapshots + +### 3.2 Persistence + +**Implementation** (`src/storage/mvcc/persistence.rs`): + +```rust +pub struct PersistenceManager { + // Snapshot manager + snapshots: SnapshotManager, + // Recovery log + recovery: RecoveryManager, + // Zone maps for pruning + zone_maps: ZoneMapStore, + // Statistics + statistics: StatisticsStore, +} +``` + +**Features**: +- Periodic full database snapshots +- Recovery: Load snapshot + replay WAL entries +- Zone Maps: Column-level min/max statistics for segment pruning +- Statistics: Table and column statistics for optimizer + +### 3.3 Data Types + +**Implementation** (`src/core/types.rs`): + +| Type | Description | +|------|-------------| +| `Null` | NULL value | +| `Integer` | 64-bit signed integer | +| `Float` | 64-bit floating point | +| `Text` | UTF-8 string | +| `Boolean` | true/false | +| `Timestamp` | Timestamp with timezone | +| `Json` | JSON document | +| `Vector` | f32 vector for similarity search | + +--- + +## 4. Query Execution Pipeline + +### 4.1 Execution Flow + +```mermaid +sequenceDiagram + participant C as Client + participant P as Parser + participant O as Optimizer + participant E as Executor + participant S as Storage + + C->>P: SQL String + P->>P: Lex & Parse + P-->>O: AST + + O->>O: Cost Estimation + O->>O: Plan Optimization + O->>O: AQE Decision + O-->>E: Execution Plan + + E->>S: Read Data + S-->>E: Rows + E->>E: Expression VM + E->>E: Operators + E-->>C: Results +``` + +### 4.2 Expression Compilation + +**Implementation** (`src/executor/expression/vm.rs`): + +```rust +pub struct ExpressionVM { + // Compiled bytecode + instructions: Vec, + // Constant pool + constants: Vec, +} + +impl ExpressionVM { + // Compile expression to bytecode + pub fn compile(expr: &Expr) -> CompiledExpr { + // Zero-copy evaluation where possible + // Inline constant folding + // Short-circuit boolean evaluation + } +} +``` + +### 4.3 Join Algorithms + +**Implementation** (`src/executor/operators/`): + +| Algorithm | Best For | Implementation | +|-----------|----------|----------------| +| **Hash Join** | Large datasets | Build hash table, probe | +| **Merge Join** | Pre-sorted inputs | Sorted merge | +| **Nested Loop** | Small tables | Index-optimized variant | +| **Bloom Filter** | Runtime filtering | Probabilistic filter | + +--- + +## 5. API/Interfaces + +### 5.1 Database API + +**Implementation** (`src/api/database.rs`): + +```rust +// Open database +let db = Database::open("memory://")?; // In-memory +let db = Database::open("file:///tmp/mydb")?; // Persistent + +// Execute DDL/DML +db.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)", ())?; + +// Insert with parameters +db.execute("INSERT INTO users VALUES ($1, $2)", (1, "Alice"))?; + +// Query +for row in db.query("SELECT * FROM users WHERE id = $1", (1,))? { + let name: String = row.get("name")?; +} + +// Query single value +let count: i64 = db.query_one("SELECT COUNT(*) FROM users", ())?; + +// Transactions +let tx = db.begin()?; +tx.execute("UPDATE users SET name = $1 WHERE id = $2", ("Bob", 1))?; +tx.commit()?; +``` + +### 5.2 Prepared Statements + +```rust +let stmt = db.prepare("SELECT * FROM users WHERE id = $1")?; +for row in stmt.query((1,))? { } +``` + +### 5.3 Named Parameters + +```rust +db.execute_named( + "INSERT INTO users VALUES (:id, :name)", + named_params! { id: 1, name: "Alice" } +)?; +``` + +### 5.4 CLI + +**Implementation** (`src/bin/stoolap.rs`): + +```bash +./stoolap # Interactive REPL +./stoolap -e "SELECT 1" # Execute single query +./stoolap --db "file://./mydb" # Persistent database +``` + +--- + +## 6. Additional Components + +### 6.1 Blockchain Integration + +Stoolap includes components for blockchain integration: + +| Module | Purpose | +|--------|---------| +| `consensus/` | Block and operation types for operation logs | +| `trie/` | Merkle tries for state verification | +| `determ/` | Deterministic value types | +| `rollup/` | L2 rollup types | +| `zk/` | Zero-knowledge proof integration (STWO plugin) | + +### 6.2 Merkle Trie + +**Implementation** (`src/trie/`): + +```rust +// RowTrie for state verification +pub struct RowTrie { + root: TrieNode, + hasher: Hasher, +} + +// Hexary proofs for light clients +pub struct HexaryProof { + siblings: Vec, + path: Vec, +} +``` + +### 6.3 WASM Support + +**Implementation** (`src/wasm.rs`): + +Can be compiled to WebAssembly for browser and edge execution. + +--- + +## 7. Why Stoolap Works + +### 7.1 Design Decisions + +| Decision | Rationale | +|----------|-----------| +| **Pure Rust** | Memory safety, no C dependencies, WASM support | +| **MVCC** | Concurrent reads/writes without locking | +| **Cost-Based Optimizer** | Better plans than rule-based optimizers | +| **Semantic Caching** | Higher cache hit rates through predicate understanding | +| **Time-Travel** | Built-in temporal queries without application logic | +| **Vector Search** | Single database for SQL + AI workloads | + +### 7.2 Performance Features + +| Feature | Benefit | +|---------|---------| +| MVCC | Lock-free reads, consistent snapshots | +| Parallel Execution | Multi-core utilization | +| Semantic Caching | Reduced redundant computation | +| AQE | Runtime plan adaptation | +| Zone Maps | Reduced I/O for analytical queries | +| Vector Quantization | Memory-efficient similarity search | + +--- + +## 8. Conclusion + +Stoolap is a comprehensive embedded SQL database that combines: + +- **Modern SQL**: CTEs, window functions, recursive queries, JSON, vectors +- **High Performance**: MVCC, parallel execution, semantic caching, cost-based optimization +- **Developer Experience**: Simple embedded API, prepared statements, rich type system +- **Persistence**: WAL, snapshots, crash recovery +- **Advanced Features**: Time-travel queries, vector search, adaptive execution +- **Pure Rust**: Memory-safe, no external dependencies, WASM-compatible + +The architecture demonstrates a well-thought-out balance between simplicity (embedded, no server) and sophistication (MVCC, cost-based optimizer, semantic cache). + +--- + +## References + +- Repository: https://github.com/stulast/stoolap +- Documentation: https://stulast.github.io/stoolap/ diff --git a/docs/research/stwo-gpu-acceleration.md b/docs/research/stwo-gpu-acceleration.md new file mode 100644 index 0000000..fd69c1d --- /dev/null +++ b/docs/research/stwo-gpu-acceleration.md @@ -0,0 +1,440 @@ +# Research: Hardware-Accelerated STWO Proof Generation + +## Executive Summary + +STWO (StarkWare's open-source prover for Circle STARKs) primarily runs on CPU/SIMD, but GPU acceleration via CUDA offers **3x–355x speedups**. This research covers three prominent implementations: Ingonyama ICICLE-Stwo, Nethermind stwo-gpu, and AntChain NitrooZK-stwo. + +## The Problem + +| Metric | CPU/SIMD | GPU Accelerated | +|--------|-----------|-----------------| +| **Proof Generation** | ~25-28 seconds | ~0.07-9 seconds | +| **Speedup** | Baseline | 3x - 355x | +| **Hardware** | Apple Silicon, x86 | NVIDIA RTX 4090, H100 | + +## Why GPU Acceleration Matters for Circle FRI + +### Circle FRI Workload + +``` +┌─────────────────────────────────────────────────────────────┐ +│ Circle FRI Components │ +├─────────────────────────────────────────────────────────────┤ +│ 1. Trace Generation │ Parallelizable (SIMD/CUDA) │ +│ 2. DCCT (Circle FFT) │ Parallelizable (SIMD/CUDA) │ +│ 3. OOD Sampling │ GPU-friendly loops │ +│ 4. FRI Folding │ Hypercube summation │ +│ 5. Composition Polynomial │ Fully parallelizable │ +│ 6. Merkle Tree │ Parallel hashing │ +└─────────────────────────────────────────────────────────────┘ +``` + +### Why M31 is GPU-Friendly + +- **Field**: Mersenne-31 (2^31 - 1) +- **Word size**: 31 bits fits in 32-bit integers +- **No carry overflow**: Native to GPU arithmetic +- **SIMD-friendly**: Wide vector operations + +--- + +## Implementation Comparison + +| Feature | ICICLE-Stwo | stwo-gpu | NitrooZK-stwo | +|---------|-------------|-----------|----------------| +| **Speedup** | 3.25x - 7x | ~193% (multi-GPU) | 22x - 355x | +| **Focus** | Drop-in backend | Circle FRI | Cairo AIR + FRI | +| **License** | Apache 2.0 | Apache 2.0 | Apache 2.0 | +| **Status** | Feature branch | Early WIP | Production-ready | +| **Multi-GPU** | Limited | Yes | Limited | + +--- + +## 1. Ingonyama ICICLE-Stwo + +### Overview + +Drop-in CUDA backend using Ingonyama's ICICLE library for M31 arithmetic. + +**Speedup**: 3.25x – 7x over SIMD (RTX 3090 Ti + i9-12900K) + +### Architecture + +```mermaid +flowchart TD + subgraph FRONTEND["STWO Frontend (Unchanged)"] + APP[Application Code] + end + + subgraph BACKEND["ICICLE Backend (CUDA)"] + ICICLE[ICICLE Library] + KERNEL[CUDA Kernels] + GPU[GPU Device] + end + + APP -->|uses| STWO + STWO -->|trait override| ICICLE + ICICLE --> KERNEL + KERNEL --> GPU +``` + +### Key Components Accelerated + +| Component | Acceleration | Notes | +|-----------|--------------|-------| +| **DCCT (Circle FFT)** | ✅ Full GPU | M31 polynomial ops | +| **Composition Polynomial** | ✅ Full GPU | No lookup support yet | +| **OOD Sampling** | ⚠️ Partial | 20% runtime, bottleneck | +| **Merkle Tree** | ✅ Full GPU | All hashing on GPU | +| **FRI Folding** | ✅ Full GPU | FRI quotient computation | + +### Code Structure + +```rust +// Drop-in backend selection +use stwo::prover::examples::wide_fibonacci::test_wide_fib_prove_with_blake; + +// Enable CUDA feature at compile-time +// cargo build --features cuda + +// No code changes needed - trait override +test_wide_fib_prove_with_blake(); // Runs on CUDA if enabled +``` + +### Implementation Details + +```rust +// Implements STWO's backend traits +use stwo::core::backend::Col; // Column trait + +// ICICLE implements for M31 +impl Col for IcicleColumn { + // Uses ICICLE's CUDA primitives + // No STWO source modifications +} +``` + +### Memory Management + +``` +┌────────────────────────────────────────────┐ +│ GPU Memory Allocation │ +├────────────────────────────────────────────┤ +│ • Trace → GPU (once) │ +│ • CP (Composition) → GPU (generated) │ +│ • OOD Samples → GPU (generated) │ +│ • Quotient Polys → GPU (computed) │ +│ • Merkle Tree → GPU (built) │ +│ │ +│ ❌ No CPU↔GPU transfer mid-proof │ +│ ⚠️ OOM risk for traces > 3GB │ +└────────────────────────────────────────────┘ +``` + +### Limitations + +- **OOM**: Traces > 3GB cause out-of-memory +- **Lookup**: Not supported in GPU CP (fallback to SIMD) +- **Multi-GPU**: No native batching yet +- **Speedup degradation**: Larger column counts reduce speedup + +--- + +## 2. Nethermind stwo-gpu + +### Overview + +Focused CUDA backend emphasizing Circle FRI acceleration with multi-GPU scaling. + +**Speedup**: ~193% efficiency (multi-GPU) + +### Architecture + +``` +┌─────────────────────────────────────────────┐ +│ stwo-gpu Architecture │ +├─────────────────────────────────────────────┤ +│ │ +│ ┌──────────────┐ ┌──────────────────┐ │ +│ │ CUDA/ │ │ stwo_gpu_backend │ │ +│ │ Kernels │◄───│ (Rust bindings) │ │ +│ │ │ │ │ │ +│ │ • Circle FFT │ │ • CudaBackend │ │ +│ │ • FRI Folding│ │ • Memory mgmt │ │ +│ │ • Matrix-Mul │ │ • Device select │ │ +│ └──────────────┘ └──────────────────┘ │ +│ ▲ │ │ +│ └─────────────────────┘ │ +│ CMake │ +└─────────────────────────────────────────────┘ +``` + +### Key Features + +| Feature | Implementation | +|---------|----------------| +| **Circle FRI** | FRI folding, polynomial evaluation | +| **M31 Field** | Native CUDA kernels | +| **Multi-GPU** | CUDA peer access (P2P) | +| **Docker** | Ready-to-use devcontainer | + +### Components Accelerated + +- **FRI Folding**: Parallel hypercube summation +- **Polynomial Evaluation**: GPU matrix-vector ops +- **Circle FFT**: Custom CUDA kernels +- **Commitment**: Merkle tree on GPU + +### Setup + +```bash +# Clone +git clone https://github.com/nethermind/stwo-gpu.git + +# Use Docker (pre-configured) +cd .devcontainer +docker compose up + +# Or build manually +cd stwo_gpu_backend +cargo test # Compiles CUDA via CMake +``` + +### Limitations + +- **Early stage**: Activity mentions WIP +- **Multi-GPU**: Assumes single-GPU unless customized +- **No benchmarks**: README doesn't list numbers + +--- + +## 3. AntChain NitrooZK-stwo + +### Overview + +**Most production-ready** with massive benchmarks: **22x – 355x speedup** on RTX 4090. + +75% of code is CUDA. + +### Benchmark Results + +| Workload | Speedup vs SIMD | Throughput | +|----------|-----------------|------------| +| Wide-Fib (Poseidon, log=23) | **152x** | — | +| Wide-Fib (Blake2s, log=23) | **22x** | — | +| General (various) | **355x** | 116x Kelem/s | + +### Architecture + +``` +┌─────────────────────────────────────────────────────────────┐ +│ NitrooZK-stwo Architecture │ +├─────────────────────────────────────────────────────────────┤ +│ │ +│ ┌─────────────┐ ┌─────────────┐ ┌──────────────┐ │ +│ │ crates/ │ │ CUDA/ │ │ Root .cu │ │ +│ │ Rust impl │ │ (75%) │ │ Files │ │ +│ └─────────────┘ └─────────────┘ └──────────────┘ │ +│ │ │ │ │ +│ └────────────────┴────────────────────┘ │ +│ │ │ +│ CMake build │ +│ │ │ +│ ┌─────▼─────┐ │ +│ │ CUDA │ │ +│ │ Kernels │ │ +│ │ • FRI │ │ +│ │ • M31 │ │ +│ │ • CP │ │ +│ └───────────┘ │ +└─────────────────────────────────────────────────────────────┘ +``` + +### Inspirations + +| Source | What was ported | +|--------|----------------| +| **stwo-gpu** | M31 ops, FRI, quotient | +| **era-bellman-cuda** | Poseidon252 | + +### Key Features + +- **Cairo VM AIR**: Supports Cairo program proofs (like Stoolap!) +- **Poseidon + Blake2s**: Both commitment channels on GPU +- **Production benchmarks**: Real numbers on RTX 4090 + +### Benchmarks Command + +```bash +# Run wide-fib benchmarks +STWO_QUIET=1 LOG_N_INSTANCES=23 RAYON_NUM_THREADS=16 \ +cargo bench --bench wide_fibonacci_cuda_blake2s --features parallel -- --nocapture + +# Test with CUDA +MIN_LOG=16 MAX_LOG=23 RAYON_NUM_THREADS=16 \ +cargo test --release test_wide_fib_prove_with_blake_cuda --features parallel +``` + +### Setup + +```bash +# Prerequisites +# - Rust (from rust-toolchain.toml) +# - CUDA 13.0.1 +# - Driver 580.82.07 +# - NVIDIA GPU (RTX 4090 recommended) + +# Clone +git clone https://github.com/antchainplusplus/nitroozk-stwo.git + +# Build +cargo build --release --features parallel + +# Run benchmarks +STWO_QUIET=1 LOG_N_INSTANCES=23 RAYON_NUM_THREADS=16 cargo bench +``` + +--- + +## Performance Comparison + +### Single GPU Benchmarks + +| Implementation | Hardware | Speedup | Best For | +|---------------|----------|---------|----------| +| **ICICLE-Stwo** | RTX 3090 Ti | 3.25x - 7x | Drop-in replacement | +| **stwo-gpu** | Multi-GPU | ~193% | Scaling | +| **NitrooZK-stwo** | RTX 4090 | 22x - 355x | Production | + +### Why NitrooZK is Fastest + +1. **Full CUDA pipeline**: 75% CUDA code +2. **Specialized kernels**: Optimized for each FRI component +3. **Cairo AIR support**: Proves Cairo programs directly +4. **Benchmark-driven**: Optimized based on real measurements + +--- + +## For CipherOcto: Which to Use? + +### Decision Matrix + +| Requirement | Recommended | +|------------|-------------| +| **Quick integration** | ICICLE-Stwo (drop-in) | +| **Multi-GPU scaling** | stwo-gpu | +| **Production/Max speed** | NitrooZK-stwo | +| **On-chain (Cairo)** | NitrooZK-stwo | + +### Integration Path + +```mermaid +flowchart TD + subgraph CURRENT["Current (CPU)"] + S[Stoolap] -->|prove_cairo| P[Proof] + end + + subgraph GPU["With GPU Acceleration"] + S2[Stoolap] -->|prove_cairo| GPU[GPU Backend] + GPU -->|CUDA| P2[Proof] + end +``` + +### Expected Improvements + +| Component | Current (CPU) | GPU Accelerated | +|-----------|---------------|-----------------| +| Proof Generation | ~25-28s | ~0.07-9s | +| Verification | ~15ms | ~15ms (same) | +| Cost/Proof | Higher | ~10x lower | + +--- + +## Technical Deep Dive: GPU-Friendly Operations + +### Circle FRI Components + +| Operation | Parallelizable | GPU Benefit | +|-----------|---------------|------------| +| **Trace Generation** | Yes | High | +| **DCCT (Circle FFT)** | Yes | Very High | +| **OOD Sampling** | Partial | Medium | +| **FRI Folding** | Yes | High | +| **Composition Poly** | Yes | Very High | +| **Merkle Tree** | Yes | High | + +### Memory Access Patterns + +``` +┌────────────────────────────────────────────┐ +│ Optimal GPU Memory Usage │ +├────────────────────────────────────────────┤ +│ 1. Allocate all GPU memory upfront │ +│ 2. Keep data on GPU (no CPU↔GPU in loop) │ +│ 3. Precompute twiddle factors │ +│ 4. Batch similar operations │ +│ 5. Use pinned memory for CPU↔GPU copies │ +└────────────────────────────────────────────┘ +``` + +--- + +## Recommendations for CipherOcto + +### Immediate (Phase 1-2) + +1. **Use NitrooZK-stwo** for production deployment + - Best performance (22x-355x speedup) + - Cairo AIR support (for on-chain verification) + - Proven on RTX 4090 + +2. **Benchmark current workload** + - Run with SIMD baseline + - Profile GPU vs CPU + +### Future (Phase 3) + +1. **Multi-GPU setup** for scaling + - stwo-gpu has multi-GPU focus + - Or extend NitrooZK with peer-access + +2. **Custom kernels** for specific operations + - If certain operations dominate runtime + - Optimize based on profiling + +### Integration Code + +```rust +// With NitrooZK-stwo - change prover +use stwo_cairo_prover::prover::prove_cairo; + +// Same API, but uses CUDA backend +let proof = prove_cairo::(input)?; +``` + +--- + +## Summary + +| Implementation | Status | Speedup | Best For | +|---------------|--------|---------|----------| +| **ICICLE-Stwo** | Feature branch | 3x-7x | Easy integration | +| **stwo-gpu** | WIP | ~193% | Multi-GPU | +| **NitrooZK-stwo** | Production | 22x-355x | Maximum performance | + +**For CipherOcto**: Start with **NitrooZK-stwo** for production, or **ICICLE-Stwo** for quick integration. The 22x-355x speedup dramatically reduces proof generation costs. + +--- + +## References + +- ICICLE-Stwo: https://github.com/ingonyama-zk/icicle-stwo +- stwo-gpu: https://github.com/nethermind/stwo-gpu +- NitrooZK-stwo: https://github.com/antchainplusplus/nitroozk-stwo +- STWO: https://github.com/starkware-libs/stwo +- Circle STARKs Paper: https://eprint.iacr.org/2024/278 + +--- + +**Research Status:** Complete +**Related:** [Stoolap vs LuminAIR](./stoolap-luminair-comparison.md), [LuminAIR AIR Deep Dive](./luminair-air-deep-dive.md) diff --git a/docs/research/wallet-technology-research.md b/docs/research/wallet-technology-research.md new file mode 100644 index 0000000..f18db82 --- /dev/null +++ b/docs/research/wallet-technology-research.md @@ -0,0 +1,335 @@ +# Research: Wallet Cryptography for CipherOcto + +## Executive Summary + +This research investigates the cryptographic foundations required for wallet implementation in the CipherOcto AI Quota Marketplace. Focuses on cryptographic primitives, signature schemes, and key management compatible with the Cairo ecosystem (Starknet) used by Stoolap for ZK proofs. + +## Problem Statement + +CipherOcto needs cryptographic wallet infrastructure that: +1. Provides secure key management and signing +2. Integrates with Cairo/Starknet ecosystem +3. Supports token transactions (OCTO-W, OCTO-D, OCTO) +4. Enables ZK proof verification for Stoolap integration + +## Research Scope + +- **Included:** Cryptographic primitives, signature schemes, key derivation, account models +- **Excluded:** User-facing wallet applications (consumer UX) - separate research + +--- + +## Cryptographic Foundations + +### 1. Starknet Signature Scheme + +Starknet uses a different signature scheme from Ethereum's ECDSA: + +| Aspect | Ethereum | Starknet | +|--------|----------|----------| +| **Curve** | secp256k1 | Stark Curve (EC over BLS12-381) | +| **Signature** | ECDSA | StarkNet ECDSA | +| **Key Size** | 32 bytes | 32 bytes | +| **Address** | 20 bytes | 32 bytes | + +```rust +// Starknet key pair using starknet-rs +use starknet::core::crypto::{sign, verify}; +use starknet::core::types::FieldElement; + +// Private key → Public key → Address +let private_key = FieldElement::from_hex_be("0x...").unwrap(); +let public_key = private_key_to_public_key(private_key); +let address = compute_address(public_key); +``` + +### 2. Account Model + +Starknet uses account abstraction - every account is a smart contract: + +```cairo +// Minimal Account Contract (OpenZeppelin) +#[starknet::contract] +mod Account { + #[storage] + struct Storage { + public_key: felt252, + } + + #[external] + fn __validate__(calldata: Array) -> felt252 { + // Verify signature matches public_key + } + + #[external] + fn __execute__(calls: Array) -> Array> { + // Execute calls if __validate__ passed + } +} +``` + +**Account Types:** + +| Type | Validation | Use Case | +|------|-----------|----------| +| **Argent** | Multi-party computation | Mobile wallets | +| **Braavos** | Hardware security | High security | +| **Generic** | Single ECDSA | Standard accounts | +| **Multisig** | M-of-N signatures | Treasury | + +### 3. Key Derivation + +```rust +// BIP-32 style derivation for Starknet +// Note: Starknet uses different path format + +// Standard derivation path: m/44'/60'/0'/0/0 (Ethereum) +// Starknet: No BIP-44 yet, use sequential nonces + +struct KeyDerivation { + seed: [u8; 32], + path: Vec, +} + +impl KeyDerivation { + fn derive(&self, index: u32) -> FieldElement { + // HMAC-SHA256 based derivation + // Different from Ethereum due to curve difference + } +} +``` + +### 4. Local Key Storage + +For CLI tools, keys must be stored securely locally: + +```rust +struct SecureKeyStore { + path: PathBuf, + // Encryption: AES-256-GCM with key derived from user password +} + +impl SecureKeyStore { + fn encrypt_key(&self, private_key: FieldElement, password: &str) -> Vec { + // PBKDF2 (100,000 iterations) → AES-256-GCM + } + + fn decrypt_key(&self, encrypted: &[u8], password: &str) -> FieldElement { + // Reverse the process + } +} +``` + +**Storage Options:** + +| Method | Security | Use Case | +|--------|----------|----------| +| **Encrypted file** | Medium | CLI tools | +| **OS Keychain** | High | Desktop apps | +| **HSM** | Very High | Production | +| **MPC** | Very High | Institutional | + +--- + +## Cryptographic Operations + +### 1. Transaction Signing + +```rust +struct OctoTransaction { + sender: FieldElement, + receiver: FieldElement, + token: TokenType, // OCTO, OCTO-W, OCTO-D + amount: u64, + nonce: u64, + chain_id: FieldElement, +} + +impl OctoTransaction { + fn hash(&self) -> FieldElement { + // Poseidon hash of transaction fields + } + + fn sign(&self, private_key: FieldElement) -> Signature { + // StarkNet ECDSA sign + sign(private_key, self.hash()) + } +} +``` + +### 2. Message Signing (Off-chain) + +```rust +// Sign messages for off-chain authentication +fn sign_message(private_key: FieldElement, message: &[u8]) -> (FieldElement, FieldElement) { + // Starknet signed message prefix: "\x19StarkNet Message\n" + let prefixed = format!("\x19StarkNet Message\n{}", hex::encode(message)); + let hash = starknet_hash(prefixed.as_bytes()); + sign(private_key, hash) +} +``` + +### 3. Multi-Sig (Threshold Signatures) + +```rust +struct MultisigWallet { + threshold: u8, + signers: Vec, +} + +impl MultisigWallet { + // Collect signatures, execute when threshold reached + fn execute_if_ready(&mut self, tx: &Transaction, signatures: Vec) -> bool { + let valid = signatures.iter() + .filter(|sig| verify(self.signers.clone(), tx.hash(), *sig)) + .count(); + + if valid >= self.threshold { + self.execute(tx) + } else { + false + } + } +} +``` + +--- + +## Stoolap ZK Integration + +### Proof Verification + +```rust +// Verify Stoolap execution proof +use starknet::core::types::TransactionReceipt; + +struct ProofVerifier { + stoolap_contract: FieldElement, +} + +impl ProofVerifier { + async fn verify_execution_proof( + &self, + provider: &Provider, + proof: &HexaryProof, + ) -> Result { + // Call Stoolap verifier contract + let call = FunctionCall { + contract_address: self.stoolap_contract, + entry_point_selector: 0x1234, // verify_proof + calldata: proof.to_calldata(), + }; + + provider.call(call).await + } +} +``` + +### ZK-Friendly Operations + +| Operation | ZK-Friendly | Notes | +|-----------|-------------|-------| +| Balance transfer | ✅ | Standard ERC-20 | +| Multi-sig | ✅ | Threshold sigs | +| Confidential txs | ⚠️ | Requires commitment schemes | +| Proof verification | ✅ | Native to Starknet | + +--- + +## Recommended Implementation + +### For MVE: Direct Starknet Integration + +```rust +// Minimal wallet for CLI tool +use starknet::providers::Provider; +use starknet::signers::Signer; + +struct QuotaWallet { + provider: P, + account: LocalWallet, +} + +impl QuotaWallet

{ + // Initialize from encrypted key file + async fn from_keyfile(path: &Path, password: &str) -> Result { + let encrypted = std::fs::read(path)?; + let private_key = decrypt_key(encrypted, password)?; + let account = LocalWallet::from_key(private_key); + Ok(Self { provider, account }) + } + + // Pay for quota request + async fn pay_for_quota(&self, to: FieldElement, amount: u64) -> Result { + let tx = TransactionRequest { + to, + amount, + // ... token transfer calldata + }; + self.provider.broadcast_tx(tx, &self.account).await + } +} +``` + +### Key Components + +| Component | Technology | Purpose | +|-----------|------------|---------| +| **Signing** | starknet-rs | Transaction signing | +| **Key Storage** | AES-256-GCM | Local encrypted storage | +| **Provider** | starknet-rs JSON-RPC | Network communication | +| **Account** | OpenZeppelin | Smart contract wallet | + +--- + +## Risk Assessment + +| Risk | Mitigation | Severity | +|------|------------|----------| +| Private key exposure | Use OS keychain, never log keys | Critical | +| Signature replay | Include nonce + chain_id in every tx | High | +| Curve vulnerability | Use starknet-rs (audited) | Low | +| MPC complexity | Defer to Phase 2 | Medium | + +--- + +## Recommendations + +### Phase 1 (MVE) +- Use starknet-rs for signing and provider +- Encrypted keyfile with password protection +- Simple single-signer account +- Manual nonce management + +### Phase 2 +- Add multi-sig support for governance +- Integrate OS keychain (macOS Keychain, Windows Credential Manager) +- Hardware wallet signing (Ledger via HID) + +### Phase 3 +- MPC-based key sharding +- Threshold signatures for treasury +- ZK-based confidential transactions + +--- + +## Next Steps + +- [ ] Draft RFC for Wallet Cryptography Specification +- [ ] Define KeyDerivation trait for extensibility +- [ ] Create Use Case for CLI wallet integration + +--- + +## References + +- Parent Document: BLUEPRINT.md +- Stoolap: https://github.com/CipherOcto/stoolap/tree/feat/blockchain-sql +- starknet-rs: https://github.com/xJonathanLEGO/starknet-rs +- OpenZeppelin Starknet Accounts: https://github.com/OpenZeppelin/cairo-contracts +- Starknet ECDSA: https://docs.starknet.io/ + +--- + +**Research Status:** Complete (Cryptography Focus) +**Recommended Action:** Proceed to RFC for Wallet Cryptography diff --git a/docs/use-cases/agent-marketplace.md b/docs/use-cases/agent-marketplace.md new file mode 100644 index 0000000..5eaea71 --- /dev/null +++ b/docs/use-cases/agent-marketplace.md @@ -0,0 +1,347 @@ +# Use Case: Agent Marketplace (OCTO-D) + +## Problem + +AI agents today are locked within platforms: +- OpenAI agents work only within OpenAI +- Anthropic agents stay within Anthropic +- No interoperability between ecosystems +- Developers rebuild agents for each platform +- No secondary market for agent capabilities + +## Motivation + +### Why This Matters for CipherOcto + +1. **Agent composability** - Agents can hire other agents +2. **Developer revenue** - Build once, earn continuously +3. **Network effects** - More agents = more value +4. **Innovation** - Specialization drives quality + +### The Opportunity + +- $100B+ agent/automation market +- Developers want recurring revenue +- Users want specialized capabilities + +## Impact + +### If Implemented + +| Area | Transformation | +|------|----------------| +| **Developer economy** | Passive income from agent deployments | +| **Agent diversity** | Specialized agents for every task | +| **Composability** | Agents build on each other | +| **Market discovery** | Find agents by capability | + +### If Not Implemented + +| Risk | Consequence | +|------|-------------| +| Limited utility | Users build everything themselves | +| No revenue | No incentive for developers | +| Monoculture | Few dominant agents emerge | + +## Narrative + +### Current State + +``` +Developer builds legal analysis agent + │ + ▼ +Deployed on platform X only + │ + ▼ +Can only be used within platform X + │ + ▼ +Limited audience, no secondary market +``` + +### Desired State (With Agent Marketplace) + +``` +Developer builds legal analysis agent + │ + ▼ +Lists on CipherOcto Agent Marketplace + │ + ▼ +Any user/orchestrator can hire agent + │ + ▼ +Developer earns OCTO-D per execution + │ + ▼ +Agent composes: hires research agent, hires review agent + │ + ▼ +Developer earns from entire chain +``` + +## Token Mechanics + +### OCTO-D Token + +| Aspect | Description | +|--------|-------------| +| **Purpose** | Payment for agent execution | +| **Earned by** | Agent developers | +| **Spent by** | Users/orchestrators hiring agents | +| **Value** | Represents agent capability | + +### Revenue Model + +```mermaid +graph LR + subgraph REVENUE["Developer Revenue Streams"] + D1[Per-Execution Fee] + D2[Subscription] + D3[Composition Fee] + D4[Data Access] + end + + subgraph CHAIN["Execution Chain"] + C1[User Task] + C2[Agent A] + C3[Agent B] + C4[Agent C] + end + + C1 -->|pays| C2 + C2 -->|pays| C3 + C3 -->|pays| C4 + C4 -->|results| C1 +``` + +### Fee Distribution + +| Component | Percentage | +|-----------|------------| +| **Agent developer** | 70% | +| **Orchestrator** | 15% | +| **Protocol treasury** | 10% | +| **Reputation system** | 5% | + +## Agent Categories + +### By Capability + +| Category | Examples | +|----------|----------| +| **Research** | Web search, document analysis | +| **Legal** | Contract review, compliance | +| **Technical** | Code review, debugging | +| **Creative** | Writing, design | +| **Analytics** | Data processing, visualization | +| **Communication** | Email, summaries | + +### By Deployment + +| Type | Description | +|------|-------------| +| **SaaS** | Cloud-hosted, easy access | +| **On-prem** | Runs locally, privacy-sensitive | +| **Hybrid** | Local + cloud combination | +| **Specialized** | Domain-specific expertise | + +## Agent Metadata + +### Discovery Schema + +```json +{ + "agent_id": "caipo-1234", + "name": "Legal Contract Analyzer", + "version": "1.2.0", + "developer": "0xABCD...1234", + "capabilities": [ + "contract_review", + "risk_assessment", + "compliance_check" + ], + "pricing": { + "per_execution": 0.01, + "subscription": 10.0 + }, + "reputation": { + "score": 85, + "total_executions": 10000, + "success_rate": 0.98 + } +} +``` + +### Discovery Flow + +```mermaid +sequenceDiagram + User->>Orchestrator: Describe task + Orchestrator->>Marketplace: Search agents (capabilities) + Marketplace->>Orchestrator: Ranked agent list + Orchestrator->>User: Display options + User->>Orchestrator: Select agent + Orchestrator->>Agent: Execute task + Agent->>Orchestrator: Return results + Orchestrator->>User: Present results +``` + +## Agent Composition + +### Chaining + +Agents can hire other agents: + +``` +User needs: "Research topic X, analyze legal implications" + +Main Agent + │ + ├─► Research Agent (finds information) + │ │ + │ └─► Web Search Agent + │ + ├─► Analysis Agent (processes findings) + │ + └─► Legal Agent (applies law) + │ + └─► Compliance Agent +``` + +### Fee Distribution in Chain + +```mermaid +flowchart TD + U[User
$10] -->|hires| A[Main Agent
$10] + A -->|hires| B[Research Agent
$3] + A -->|hires| C[Legal Agent
$4] + B -->|hires| D[Search Agent
$1] + C -->|hires| E[Compliance Agent
$1] + + A -->|keeps| AD[$3] + B -->|keeps| BD[$2] + C -->|keeps| CD[$3] + D -->|keeps| DD[$1] + E -->|keeps| ED[$1] +``` + +## Verification + +### Agent Trust Signals + +| Signal | Verification | +|--------|--------------| +| Reputation score | Historical performance | +| Success rate | Completed vs failed tasks | +| Response time | Average latency | +| User reviews | Community feedback | +| ZK proofs | Verifiable execution | + +### Execution Verification + +```mermaid +sequenceDiagram + Orchestrator->>Agent: Submit task + Agent->>Agent: Execute locally + Agent->>Stoolap: Generate execution proof + Stoolap->>Agent: Return ZK proof + Agent->>Orchestrator: Return results + proof + Orchestrator->>Stoolap: Verify proof + Orchestrator->>Wallet: Release payment +``` + +## Developer Incentives + +### Early Adopter Rewards + +| Cohort | Multiplier | Deadline | +|--------|------------|----------| +| First 100 agents | 10x | First 30 days | +| Next 400 agents | 5x | First 60 days | +| First 1000 users | 2x | First 90 days | + +### Quality Bonuses + +| Achievement | Bonus | +|-------------|-------| +| 1000 successful executions | +5% fees | +| 10,000 successful executions | +10% fees | +| 99%+ success rate | +5% fees | +| Verified ZK proofs | +10% fees | + +## Reputation System + +### Score Components + +| Factor | Weight | +|--------|--------| +| Success rate | 40% | +| Response time | 20% | +| User rating | 20% | +| ZK proof verification | 10% | +| Tenure | 10% | + +### Reputation Tiers + +| Tier | Score | Benefits | +|------|-------|----------| +| New | 0-20 | Base rate | +| Bronze | 21-40 | +10% visibility | +| Silver | 41-60 | +25% visibility | +| Gold | 61-80 | +50% visibility, featured | +| Platinum | 81-100 | Top placement, premium | + +## Relationship to Other Components + +```mermaid +graph TB + subgraph ECOSYSTEM["CipherOcto Ecosystem"] + AGENTS[Agent Marketplace
OCTO-D] + ORCH[Orchestrator
OCTO-O] + COMPUTE[Compute Network
OCTO-A] + STORAGE[Storage Network
OCTO-S] + end + + AGENTS -->|deploys| COMPUTE + AGENTS -->|persists| STORAGE + ORCH -->|discovers| AGENTS + ORCH -->|routes to| COMPUTE + + style AGENTS fill:#6c3483 + style ORCH fill:#b7950b + style COMPUTE fill:#b03a2e + style STORAGE fill:#27ae60 +``` + +## Implementation Path + +### Phase 1: Basic Marketplace +- [ ] Agent registration +- [ ] Simple discovery +- [ ] Per-execution payments +- [ ] Basic reputation + +### Phase 2: Advanced Features +- [ ] Agent composition +- [ ] Subscription models +- [ ] ZK execution proofs +- [ ] Advanced search + +### Phase 3: Ecosystem +- [ ] Agent templates +- [ ] Developer tools +- [ ] Analytics dashboard +- [ ] Enterprise marketplace + +## RFC Link + +- [RFC-0100: AI Quota Marketplace Protocol](../rfcs/0100-ai-quota-marketplace.md) +- [RFC-0101: Quota Router Agent Specification](../rfcs/0101-quota-router-agent.md) + +--- + +**Status:** Draft +**Priority:** High (Phase 1) +**Token:** OCTO-D diff --git a/docs/use-cases/ai-quota-marketplace.md b/docs/use-cases/ai-quota-marketplace.md new file mode 100644 index 0000000..2cc3e31 --- /dev/null +++ b/docs/use-cases/ai-quota-marketplace.md @@ -0,0 +1,160 @@ +# Use Case: AI Quota Marketplace for Developer Bootstrapping + +## Problem + +CipherOcto needs an initial utility for developers to participate in the network. Currently: +- Developers have unused AI API quotas (OpenAI, Anthropic, etc.) +- These quotas sit idle during off-hours (sleep, weekends) +- No mechanism exists to monetize or trade these quotas +- Early contributors need incentive to join the network + +## Motivation + +### Why This Matters for CipherOcto + +1. **Immediate utility** - OCTO-W token has real use from day one +2. **Self-bootstrapping** - Developers fuel the network by participating +3. **Timezone arbitrage** - Dev in US sleeps while Dev in Asia works - quotas can cross timezones +4. **Dual incentive** - Earn by contributing, spend by needing more + +### The Opportunity + +- Millions in unused AI API quotas globally +- Developers actively seeking cost-saving mechanisms +- No decentralized solution exists +- Early mover advantage in this market segment + +## Impact + +### If Implemented + +| Area | Transformation | +|------|----------------| +| **Token Utility** | OCTO-W becomes functional immediately | +| **Developer Adoption** | Clear path to participate and earn | +| **Network Effects** | More contributors = more liquidity = more valuable | +| **Bootstrapping** | Self-sustaining growth flywheel | + +### If Not Implemented + +| Risk | Consequence | +|------|-------------| +| No token utility | No reason for developers to join | +| Slow adoption | Network fails to grow | +| Centralized alternatives | Market captured by others | + +## Narrative + +### Current State (No Marketplace) + +``` +Dev A has 1000 unused prompts (sleeping) +Dev B needs 500 more prompts (working late) + +❌ No way to trade +❌ Dev B pays full price +❌ Dev A's quota wasted +``` + +### Desired State (With Quota Marketplace) + +``` +Dev A runs local proxy, lists spare quota + │ + ▼ +1000 prompts listed on market (1 OCTO-W per prompt) + │ + ▼ +Dev B's quota exhausted, needs more + │ + ▼ +Dev B buys from market (spends OCTO-W) + │ + ▼ +Dev A receives OCTO-W + │ + ▼ +Dev B can now work, Dev A monetized idle quota +``` + +### The Flywheel + +``` +Contribute quota → Earn OCTO-W + │ + ▼ +Need more? Spend OCTO-W to buy + │ + ▼ +Excess OCTO-W? Swap to OCTO-D or hold + │ + ▼ +Early contributors → multiplier on OCTO-D rewards + │ + ▼ +More contributors → more liquidity → more valuable +``` + +### Early Contributor Multiplier + +- First 100 contributors: 10x multiplier on OCTO-D rewards +- Next 400 contributors: 5x multiplier +- Next 1000 contributors: 2x multiplier +- Creates "race" to join early + +## Token Mechanics + +| Action | Token Flow | +|--------|------------| +| List quota | 0 prompts → 1000 OCTO-W (earned) | +| Buy quota | 100 OCTO-W → 100 prompts (spent) | +| Swap OCTO-W → OCTO-D | At market rate × multiplier | +| Swap OCTO → OCTO-W | At market rate | +| Governance | Hold OCTO for voting | + +## Security Model + +1. **Local Proxy Only** - API keys never leave developer's machine +2. **Request Routing** - Prompts route through contributor's proxy +3. **Balance Check** - Each request requires 1 OCTO-W +4. **No Credential Storage** - Market doesn't hold API keys + +## Success Metrics + +| Metric | Target | +|--------|--------| +| Early contributors (Month 1) | 100 | +| OCTO-W trading volume | 1M tokens | +| Active quota routers | 50 | +| Time to first swap | < 7 days | + +## Open Questions + +1. What happens if a seller goes offline mid-request? +2. Should there be a stake requirement for sellers? +3. How to handle provider rate limits? +4. Minimum OCTO-W balance for routing? + +## Timeline + +| Phase | When | What | +|-------|------|------| +| **Research** | Now | Feasibility confirmed | +| **Use Case** | Now | Definition complete | +| **RFC/Missions** | Next | Technical specification | +| **MVE** | Q2 2026 | Basic quota router | +| **Market** | Q3 2026 | Trading functionality | + +--- + +## References + +- Parent Document: BLUEPRINT.md +- Research: docs/research/ai-quota-marketplace-research.md +- RFCs: rfcs/0100-ai-quota-marketplace.md, rfcs/0101-quota-router-agent.md + +--- + +**Category:** Token Economics / Developer Adoption +**Priority:** High +**Status:** Ready for RFC phase diff --git a/docs/use-cases/bandwidth-provider-network.md b/docs/use-cases/bandwidth-provider-network.md new file mode 100644 index 0000000..9f1c3b1 --- /dev/null +++ b/docs/use-cases/bandwidth-provider-network.md @@ -0,0 +1,72 @@ +# Use Case: Bandwidth Provider Network (OCTO-B) + +## Problem + +CipherOcto requires network connectivity for: +- Agent communication between nodes +- Data transfer for distributed compute +- Edge node relay +- DDoS protection and mitigation + +Current centralized CDNs are expensive and create dependency on single providers. + +## Motivation + +### Why This Matters for CipherOcto + +1. **Global reach** - Distributed bandwidth for worldwide access +2. **Cost reduction** - Peer-to-peer bandwidth vs centralized CDN +3. **Resilience** - No single point of failure +4. **Privacy** - Multi-path routing obscures traffic patterns + +## Token Mechanics + +### OCTO-B Token + +| Aspect | Description | +|--------|-------------| +| **Purpose** | Payment for bandwidth services | +| **Earned by** | Bandwidth providers | +| **Spent by** | Agents, users needing relay | +| **Value** | Represents data transfer (GB) | + +## Provider Types + +### Edge Nodes +- Residential connections +- Low-latency relay +- Geographic distribution + +### Relay Nodes +- High-bandwidth connections +- Data aggregation +- Traffic obfuscation + +### CDN Nodes +- Cached content delivery +- Static asset serving +- Geographic proximity + +## Verification + +| Method | What It Proves | +|--------|---------------| +| Throughput tests | Available bandwidth | +| Uptime monitoring | Availability | +| Latency checks | Geographic reach | +| Data delivery | Successful transfer | + +## Slashing Conditions + +| Offense | Penalty | +|---------|---------| +| **Throttling** | 25% stake | +| **Data manipulation** | 100% stake | +| **Extended downtime** | 5% per hour | +| **Privacy breach** | 100% stake | + +--- + +**Status:** Draft +**Priority:** Medium +**Token:** OCTO-B diff --git a/docs/use-cases/compute-provider-network.md b/docs/use-cases/compute-provider-network.md new file mode 100644 index 0000000..e089ea9 --- /dev/null +++ b/docs/use-cases/compute-provider-network.md @@ -0,0 +1,208 @@ +# Use Case: Compute Provider Network (OCTO-A) + +## Problem + +The CipherOcto network requires computational resources to execute AI agents, but: +- GPU providers worldwide have 40-60% idle capacity +- No decentralized marketplace exists for monetizing idle compute +- Enterprises cannot easily lease compute resources +- AI inference costs remain centralized and expensive + +## Motivation + +### Why This Matters for CipherOcto + +1. **Infrastructure foundation** - Compute is the backbone of agent execution +2. **Revenue opportunity** - GPU owners earn from idle hardware +3. **Cost reduction** - Competitive pricing vs centralized clouds +4. **Decentralization** - No single provider controls the network + +### The Opportunity + +- $50B+ in wasted GPU compute annually +- Growing demand for inference capacity +- DePIN sector proving decentralized compute works + +## Impact + +### If Implemented + +| Area | Transformation | +|------|----------------| +| **Network Supply** | Global compute pool available | +| **Cost Efficiency** | 30-50% savings vs centralized | +| **Provider Revenue** | New income stream for GPU owners | +| **Resilience** | No single point of failure | + +### If Not Implemented + +| Risk | Consequence | +|------|-------------| +| No execution capacity | Agents cannot run | +| Centralized fallback | Becomes another cloud service | +| High costs | Limits network adoption | + +## Narrative + +### Current State (Fragmented) + +``` +GPU Owner A: RTX 4090 sitting idle 20 hours/day +GPU Owner B: A100 cluster underutilized +AI Developer: Needs compute, must use AWS/GCP at high cost +``` + +### Desired State (With Compute Network) + +``` +GPU Owner A registers hardware, sets pricing +GPU Owner B lists capacity on network +AI Developer submits task → routed to available GPU +Providers earn OCTO-A tokens for execution +``` + +## Token Mechanics + +### OCTO-A Token + +| Aspect | Description | +|--------|-------------| +| **Purpose** | Payment for compute resources | +| **Earned by** | GPU/inference providers | +| **Spent by** | Agent execution, task processing | +| **Value** | Represents compute time (GPU-hours) | + +### Pricing Model + +```mermaid +graph LR + subgraph PRICING["Dynamic Pricing Factors"] + D1[GPU Type
A100 > RTX 4090] + D2[Availability
Low = Higher] + D3[Demand
Peak = Premium] + D4[Duration
Long = Discount] + end + + D1 --> P[Price per GPU-hour] + D2 --> P + D3 --> P + D4 --> P +``` + +### Value Flow + +``` +Provider: GPU time → OCTO-A → Can swap → OCTO (governance) +User: OCTO-A → Agent execution → Results +``` + +## Provider Types + +### Tier 1: Consumer Hardware +- RTX 3060/4070/4090 series +- Mac M-series (Apple Silicon) +- Entry-level proof of concept + +### Tier 2: Professional Hardware +- A100, H100, H200 +- Professional workstations +- Small render farms + +### Tier 3: Data Center +- Large GPU clusters +- Enterprise-grade hardware +- Multi-GPU setups + +## Verification + +### Proof of Work + +```mermaid +sequenceDiagram + Provider->>Network: Register GPU specs + Network->>Provider: Challenge (compute task) + Provider->>Network: Submit result + hash + Network->>Network: Verify correctness + Network->>Provider: Confirm + record uptime +``` + +### Trust Signals + +| Signal | Verification | +|--------|--------------| +| Uptime | Continuous availability check | +| Performance | Benchmark tests | +| Accuracy | Result validation | +| Reliability | Historical track record | + +## Slashing Conditions + +Providers lose stake for: + +| Offense | Penalty | +|---------|---------| +| **Sybil** | 100% stake slash | +| **Invalid work** | 25% stake slash | +| **Extended downtime** | 5% per hour | +| **Price manipulation** | 50% stake slash | + +## Early Adopter Incentives + +| Cohort | Multiplier | Deadline | +|--------|------------|----------| +| First 100 providers | 10x rewards | First 30 days | +| Next 400 providers | 5x rewards | First 60 days | +| Next 1000 providers | 2x rewards | First 90 days | + +## Relationship to Other Components + +```mermaid +graph TB + subgraph ECOSYSTEM["CipherOcto Ecosystem"] + COMPUTE[Compute Network
OCTO-A] + ORCH[Orchestrator
OCTO-O] + AGENTS[Agent Marketplace
OCTO-D] + WALLET[Wallet] + end + + COMPUTE -->|Executes| AGENTS + AGENTS -->|Routes to| ORCH + ORCH -->|Selects| COMPUTE + COMPUTE -->|Earns| WALLET + + style COMPUTE fill:#b03a2e + style ORCH fill:#b7950b + style AGENTS fill:#6c3483 + style WALLET fill:#1f618d +``` + +## Implementation Path + +### Phase 1: Basic Provisioning +- [ ] Provider registration +- [ ] Simple task submission +- [ ] Basic payment in OCTO-A +- [ ] Manual verification + +### Phase 2: Enhanced Trust +- [ ] Automated benchmark verification +- [ ] Reputation system integration +- [ ] Dynamic pricing +- [ ] ZK proofs of execution + +### Phase 3: Full Network +- [ ] Global GPU marketplace +- [ ] Real-time bidding +- [ ] Enterprise integrations +- [ ] Hardware diversity support + +## RFC Link + +- [RFC-0100: AI Quota Marketplace Protocol](../rfcs/0100-ai-quota-marketplace.md) +- [RFC-0101: Quota Router Agent Specification](../rfcs/0101-quota-router-agent.md) + +--- + +**Status:** Draft +**Priority:** High (Phase 1) +**Token:** OCTO-A diff --git a/docs/use-cases/data-marketplace.md b/docs/use-cases/data-marketplace.md new file mode 100644 index 0000000..fc16775 --- /dev/null +++ b/docs/use-cases/data-marketplace.md @@ -0,0 +1,132 @@ +# Use Case: Data Marketplace + +## Problem + +Valuable data remains locked: +- Enterprises have datasets that could train better AI +- Individuals cannot monetize their personal data +- Researchers lack access to quality datasets +- No trustless way to verify data quality + +## Motivation + +### Why This Matters for CipherOcto + +1. **Data economy** - Unlock trapped value in datasets +2. **Quality signals** - Reputation-based verification +3. **Privacy control** - Data flagging system enforced +4. **Research access** - Democratize AI training data + +## Data Classification + +| Level | Access | Monetization | +|-------|--------|--------------| +| **PRIVATE** | Owner only | None | +| **CONFIDENTIAL** | Selected agents | Premium | +| **SHARED** | Verified agents | Standard | +| **PUBLIC** | Anyone | Full | + +## Token Mechanics + +### Value Flow + +```mermaid +graph LR + DATA[Data Provider] -->|uploads| MARKET[Data Marketplace] + MARKET -->|licenses| USER[Data Consumer] + USER -->|pays| PROVIDER + PROVIDER -->|stake| ESCROW +``` + +### Pricing Models + +| Model | Description | +|-------|-------------| +| **Per-query** | Pay per data access | +| **Subscription** | Monthly data access | +| **One-time** | Buy dataset outright | +| **Revenue share** | % of AI revenue generated | + +## Verification + +### Data Quality Signals + +| Signal | Verification | +|--------|--------------| +| Provenance | Origin verification | +| Freshness | Last update timestamp | +| Completeness | Missing data percentage | +| Accuracy | Spot-check validation | +| ZK proofs | Privacy-preserving verification | + +### Quality Scores + +``` +Score = (Accuracy * 0.4) + (Freshness * 0.2) + (Completeness * 0.2) + (Reputation * 0.2) +``` + +## Privacy Enforcement + +### ZK Integration + +```mermaid +sequenceDiagram + DataProvider->>ZK: Encrypt data + generate proof + ZK->>DataProvider: Return encrypted data + proof + DataProvider->>Marketplace: Upload encrypted data + User->>Marketplace: Request access + Marketplace->>ZK: Verify access conditions + ZK->>User: Grant decryption key (if eligible) + User->>DataProvider: Access granted +``` + +### Access Control + +| Classification | Verification Required | +|----------------|---------------------| +| PRIVATE | Owner signature only | +| CONFIDENTIAL | Owner + reputation check | +| SHARED | Reputation threshold | +| PUBLIC | None | + +## Use Cases + +### Training Data +- Model fine-tuning datasets +- Evaluation benchmarks +- Synthetic data generation + +### Real-time Data +- Market feeds +- Weather data +- News aggregation + +### Domain Expertise +- Legal precedents +- Medical records (anonymized) +- Scientific datasets + +## Provider Requirements + +### Minimum Stake + +| Data Type | Minimum Stake | +|-----------|--------------| +| Public | 100 OCTO | +| Shared | 500 OCTO | +| Confidential | 1000 OCTO | + +### Slashing Conditions + +| Offense | Penalty | +|---------|---------| +| **Fake data** | 100% stake + ban | +| **Privacy breach** | 100% stake + legal | +| **Inaccurate quality** | 50% stake | +| **Unauthorized sharing** | 75% stake | + +--- + +**Status:** Draft +**Priority:** Medium +**Token:** All (multi-token) diff --git a/docs/use-cases/enterprise-private-ai.md b/docs/use-cases/enterprise-private-ai.md new file mode 100644 index 0000000..4024bf2 --- /dev/null +++ b/docs/use-cases/enterprise-private-ai.md @@ -0,0 +1,202 @@ +# Use Case: Enterprise Private AI + +## Problem + +Enterprises face AI challenges: +- Cannot send sensitive data to external APIs +- Need AI capabilities without infrastructure overhead +- Must comply with SOC2, HIPAA, GDPR +- Want cost control and predictability + +## Motivation + +### Why This Matters for CipherOcto + +1. **Enterprise revenue** - High-value customer segment +2. **Compliance** - Built-in regulatory support +3. **Privacy** - Data never leaves boundaries +4. **Cost efficiency** - 30-50% vs current solutions + +## Solution + +### Private AI Infrastructure + +```mermaid +graph TB + subgraph ENTERPRISE["Enterprise Boundary"] + USER[Employee] -->|request| PROXY[AI Proxy] + PROXY -->|internal| AGENT[Enterprise Agent] + AGENT -->|local compute| GPU[Private GPU] + PROXY -->|encrypted| STORAGE[Encrypted Storage] + end + + AGENT -->|verify| REPUTATION[Reputation System] + GPU -->|compute| RESULTS[Results] +``` + +### Deployment Options + +| Model | Data Location | Compliance | +|-------|---------------|------------| +| **On-premises** | Enterprise data center | Full control | +| **Private cloud** | Dedicated VPC | SOC2 Type II | +| **Hybrid** | Edge + cloud | Flexible | +| **Sovereign** | Geographic restriction | GDPR/ localization | + +## Features + +### Compliance Native + +| Framework | Support | +|-----------|----------| +| SOC2 | ✅ Type I & II | +| HIPAA | ✅ BAA available | +| GDPR | ✅ Data localization | +| ISO 27001 | ✅ Certification | + +### Team Management + +```mermaid +graph LR + subgraph TEAM["Enterprise Team"] + ADMIN[Admin] -->|manage| GROUP[Team Group] + GROUP -->|use| AGENT[Team Agent] + GROUP -->|quota| QUOTA[Quota Allocation] + end + + ADMIN -->|billing| FINANCE[Finance] + FINANCE -->|budget| QUOTA +``` + +### Capabilities + +| Feature | Description | +|---------|-------------| +| **Team agents** | Specialized AI per department | +| **Shared memory** | Team knowledge bases | +| **Quota management** | Budget controls | +| **Audit logs** | Full activity tracking | +| **Access control** | RBAC integration | + +## Token Economics + +### Enterprise Token Flow + +```mermaid +graph TD + ENTERPRISE[Enterprise] -->|pays| CONTRACT[Annual Contract] + CONTRACT -->|converts| TOKENS[OCTO Tokens] + TOKENS -->|stake| ESCROW[Escrow] + ESCROW -->|rewards| PROVIDERS[Network Providers] + + subgraph INTERNAL["Internal Budget"] + TEAM -->|usage| QUOTA[Quota] + QUOTA -->|tracks| TOKENS + end +``` + +### Pricing Models + +| Model | Description | Best For | +|-------|-------------|----------| +| **Subscription** | Fixed monthly AI budget | Predictable costs | +| **Pay-as-you-go** | Per-request pricing | Variable usage | +| **Enterprise** | Custom annual contract | Large scale | +| **Hybrid** | Base + variable | Mix of needs | + +## Use Cases + +### Department-Specific Agents + +| Department | Agent Capability | +|------------|-----------------| +| **Legal** | Contract review, compliance | +| **Finance** | Analysis, forecasting | +| **HR** | Resume screening, Q&A | +| **Sales** | Lead scoring, CRM | +| **Support** | Ticket classification | +| **Engineering** | Code review, debugging | + +### Compliance Workflows + +``` +User Query → + │ + ├─► Classify (PRIVATE/CONFIDENTIAL) + │ + ├─► Route to compliant agent + │ + ├─► Execute on approved compute + │ + ├─► Log to audit trail + │ + └─► Return encrypted result +``` + +## Security + +### Data Protection + +| Layer | Protection | +|-------|------------| +| **Transport** | TLS 1.3 | +| **Storage** | AES-256 encryption | +| **Compute** | TEE (optional) | +| **Access** | RBAC + MFA | +| **Audit** | Immutable logs | + +### Privacy Levels + +| Level | Behavior | +|-------|----------| +| **PRIVATE** | Local-only, no network | +| **CONFIDENTIAL** | Encrypted, restricted agents | +| **SHARED** | Encrypted, verified agents | +| **PUBLIC** | Allowed out-of-band | + +## Integration + +### Enterprise Systems + +| System | Integration | +|--------|-------------| +| **Active Directory** | SSO/LDAP | +| **Slack/Teams** | Bot integration | +| **CRM** | Salesforce, HubSpot | +| **HRIS** | Workday, BambooHR | +| **SIEM** | Splunk, Datadog | + +### API Access + +```rust +// Enterprise API integration +struct EnterpriseConfig { + organization_id: String, + api_endpoint: String, + auth: AuthMethod, + compliance_level: ComplianceLevel, +} + +impl EnterpriseClient { + fn new(config: EnterpriseConfig) -> Self; + fn create_agent(&self, spec: AgentSpec) -> AgentId; + fn allocate_quota(&self, team: &str, amount: u64); + fn get_audit_log(&self, filter: AuditFilter) -> Vec; +} +``` + +## Support + +### Service Levels + +| Tier | Response Time | Support Hours | Price | +|------|--------------|----------------|-------| +| **Standard** | 24 hours | Business | Base | +| **Professional** | 4 hours | 12x5 | +50% | +| **Enterprise** | 1 hour | 24x7 | Custom | + +--- + +**Status:** Draft +**Priority:** Medium (Phase 3) +**Token:** OCTO (primary), role tokens diff --git a/docs/use-cases/node-operations.md b/docs/use-cases/node-operations.md new file mode 100644 index 0000000..a0cef6f --- /dev/null +++ b/docs/use-cases/node-operations.md @@ -0,0 +1,197 @@ +# Use Case: Node Operations (OCTO-N) + +## Problem + +CipherOcto requires infrastructure: +- Network validation and consensus +- State synchronization +- API endpoints for users +- Security monitoring + +These nodes form the backbone of decentralization. + +## Motivation + +### Why This Matters for CipherOcto + +1. **Decentralization** - No single point of control +2. **Accessibility** - Users need entry points +3. **Security** - Distributed validation +4. **Reliability** - Redundant infrastructure + +## Token Mechanics + +### OCTO-N Token + +| Aspect | Description | +|--------|-------------| +| **Purpose** | Payment for node operations | +| **Earned by** | Node operators | +| **Spent by** | Protocol (rewards) | +| **Value** | Represents infrastructure contribution | + +### Reward Structure + +```mermaid +graph TD + BLOCK[Block Rewards] -->|split| NODES[Node Types] + NODES -->|50%| VALIDATOR[Validator Nodes] + NODES -->|30%| RPC[RPC Nodes] + NODES -->|20%| ARCHIVE[Archive Nodes] + + VALIDATOR -->|stake| REWARD[APR: 5-8%] + RPC -->|uptime| REWARD + ARCHIVE -->|storage| REWARD +``` + +## Node Types + +### Validator Nodes + +| Aspect | Description | +|--------|-------------| +| **Role** | Consensus participation | +| **Requirements** | High stake, 99.9% uptime | +| **Rewards** | Block production + fees | +| **Slashing** | Severe for double-sign | + +### RPC Nodes + +| Aspect | Description | +|--------|-------------| +| **Role** | API endpoints | +| **Requirements** | Low latency, reliable | +| **Rewards** | Per-request fees | +| **Slashing** | Downtime penalties | + +### Archive Nodes + +| Aspect | Description | +|--------|-------------| +| **Role** | Historical data storage | +| **Requirements** | Large storage capacity | +| **Rewards** | Storage fees | +| **Slashing** | Data integrity failures | + +### Light Nodes + +| Aspect | Description | +|--------|-------------| +| **Role** | Mobile/embedded participation | +| **Requirements** | Minimal resources | +| **Rewards** | Reduced but accessible | +| **Slashing** | None (observe-only) | + +## Requirements + +### Hardware Specifications + +| Node Type | CPU | RAM | Storage | Bandwidth | +|-----------|-----|-----|---------|-----------| +| Validator | 8 cores | 32GB | 500GB SSD | 1 Gbps | +| RPC | 4 cores | 16GB | 100GB SSD | 500 Mbps | +| Archive | 4 cores | 8GB | 10TB HDD | 100 Mbps | +| Light | 1 core | 2GB | 10GB | 10 Mbps | + +### Stake Requirements + +| Node Type | Minimum OCTO | Minimum OCTO-N | +|-----------|--------------|----------------| +| Validator | 10,000 | 1,000 | +| RPC | 1,000 | 100 | +| Archive | 500 | 50 | +| Light | 0 | 0 | + +## Verification + +### Uptime Monitoring + +```mermaid +sequenceDiagram + Network->>Node: Ping (every minute) + Node->>Network: Pong + Network->>Network: Record uptime + Note over Network: >99.9% = Full rewards + Note over Network: 99-99.9% = 75% rewards + Note over Network: 95-99% = 50% rewards + Note over Network: <95% = 0% rewards +``` + +### Performance Metrics + +| Metric | Target | Impact | +|--------|--------|--------| +| Uptime | 99.9% | Reward multiplier | +| Latency | <100ms | RPC priority | +| Sync time | <5min | Validator status | +| Storage | 100% integrity | Archive verification | + +## Slashing Conditions + +### Validator Slashing + +| Offense | Penalty | +|---------|---------| +| **Double sign** | 100% stake | +| **Liveness failure** | 1% per hour offline | +| **Censorship** | 50% stake | +| **Invalid state** | 25% stake | + +### RPC Slashing + +| Offense | Penalty | +|---------|---------| +| **Data manipulation** | 100% stake | +| **Extended downtime** | 10% per day | +| **Response manipulation** | 50% stake | +| **Slow responses** | Warning → penalty | + +## Security + +### Key Management + +``` +┌─────────────────────────────────────┐ +│ Validator Security │ +├─────────────────────────────────────┤ +│ • HSM required for validator keys │ +│ • Multi-sig for stake management │ +│ • Geographic distribution required │ +│ • Regular key rotation │ +└─────────────────────────────────────┘ +``` + +### Best Practices + +| Practice | Requirement | +|----------|-------------| +| Key storage | HSM/TEE | +| Geographic distribution | 3+ regions | +| Monitoring | 24/7 alerts | +| Backup | Encrypted, offsite | +| Updates | Timely, tested | + +## Incentives + +### Early Adopter Rewards + +| Cohort | Multiplier | Deadline | +|--------|------------|----------| +| First 50 validators | 10x | First 30 days | +| First 100 RPC nodes | 5x | First 60 days | +| First 200 archive nodes | 3x | First 90 days | + +### Performance Bonuses + +| Achievement | Bonus | +|-------------|-------| +| 1 year continuous operation | +10% | +| 99.99% uptime | +5% | +| Zero slashing events | +10% | +| Geographic diversity | +5% | + +--- + +**Status:** Draft +**Priority:** High +**Token:** OCTO-N diff --git a/docs/use-cases/orchestrator-role.md b/docs/use-cases/orchestrator-role.md new file mode 100644 index 0000000..13b130b --- /dev/null +++ b/docs/use-cases/orchestrator-role.md @@ -0,0 +1,173 @@ +# Use Case: Orchestrator Role (OCTO-O) + +## Problem + +Users and agents need: +- Intelligent routing to best providers +- Trust-aware selection of services +- Privacy constraint enforcement +- Multi-party coordination + +Without orchestration, users must manually select providers. + +## Motivation + +### Why This Matters for CipherOcto + +1. **User experience** - Automated best-path selection +2. **Trust propagation** - Reputation system integration +3. **Efficiency** - Optimal resource allocation +4. **Composability** - Chain multiple agents/services + +## Token Mechanics + +### OCTO-O Token + +| Aspect | Description | +|--------|-------------| +| **Purpose** | Payment for coordination services | +| **Earned by** | Orchestrators | +| **Spent by** | Users/agents needing routing | +| **Value** | Represents coordination complexity | + +### Fee Structure + +```mermaid +graph LR + TASK[Task] -->|analyze| ORCH[Orchestrator] + ORCH -->|select| PROVIDER[Provider] + PROVIDER -->|execute| RESULT[Result] + + USER[User] -->|pays| FEE[Fees] + FEE -->|coordination| ORCH +``` + +| Coordination Type | Fee | +|------------------|-----| +| Simple routing | 1-2% | +| Multi-agent chain | 5-10% | +| Complex orchestration | 10-15% | + +## Responsibilities + +### Task Analysis +- Understand user requirements +- Identify necessary capabilities +- Estimate complexity and cost + +### Provider Selection +- Match requirements to providers +- Apply trust/reputation weighting +- Consider price/performance + +### Execution Management +- Monitor task progress +- Handle failures gracefully +- Coordinate multi-party work + +### Result Verification +- Validate outputs +- Enforce quality thresholds +- Handle disputes + +## Routing Policies + +### Policy Types + +| Policy | Selection Criteria | +|--------|-------------------| +| **cheapest** | Lowest cost | +| **fastest** | Lowest latency | +| **quality** | Highest reputation | +| **balanced** | Price/performance score | +| **custom** | User-defined rules | + +### Trust Weighting + +```rust +struct TrustScore { + reputation: u8, // 0-100 + stake: u64, // OCTO staked + age_days: u32, // Account age + successful_tasks: u64, +} + +fn calculate_weight(score: &TrustScore) -> f64 { + (score.reputation as f64 * 0.4) + + (min(score.stake, 10000) as f64 / 100.0 * 0.3) + + (min(score.age_days, 365) as f64 / 365.0 * 0.2) + + (min(score.successful_tasks, 1000) as f64 / 1000.0 * 0.1) +} +``` + +## Provider Coordination + +### Multi-Agent Chaining + +```mermaid +sequenceDiagram + User->>Orchestrator: Submit complex task + Orchestrator->>Orchestrator: Break into subtasks + Orchestrator->>Agent A: Task 1 + Orchestrator->>Agent B: Task 2 (parallel) + Agent A->>Orchestrator: Result 1 + Agent B->>Orchestrator: Result 2 + Orchestrator->>Agent C: Task 3 (depends on 1+2) + Agent C->>Orchestrator: Result 3 + Orchestrator->>User: Combined result +``` + +### Failure Handling + +| Scenario | Response | +|----------|----------| +| Provider timeout | Retry with next best | +| Quality failure | Re-assign to different provider | +| Chain failure | Rollback, notify user | +| Dispute | Hold payment, escalate | + +## Reputation for Orchestrators + +### Scoring + +| Metric | Weight | +|--------|--------| +| Task success rate | 40% | +| User satisfaction | 25% | +| Latency | 15% | +| Cost efficiency | 20% | + +### Tier Benefits + +| Tier | Score | Benefits | +|------|-------|----------| +| Bronze | 21-40 | Base routing | +| Silver | 41-60 | Priority listing | +| Gold | 61-80 | Featured placement | +| Platinum | 81-100 | Premium fees | + +## Requirements + +### Minimum Stake + +| Tier | Stake Required | +|------|----------------| +| Basic | 500 OCTO | +| Standard | 5000 OCTO | +| Professional | 50,000 OCTO | +| Enterprise | 500,000 OCTO | + +### Slashing Conditions + +| Offense | Penalty | +|---------|---------| +| **Fraud** | 100% stake + ban | +| **Collusion** | 75% stake | +| **Poor routing** | 25% stake | +| **Data breach** | 100% stake | + +--- + +**Status:** Draft +**Priority:** High (Phase 1) +**Token:** OCTO-O diff --git a/docs/use-cases/privacy-preserving-query-routing.md b/docs/use-cases/privacy-preserving-query-routing.md new file mode 100644 index 0000000..2c620e1 --- /dev/null +++ b/docs/use-cases/privacy-preserving-query-routing.md @@ -0,0 +1,362 @@ +# Use Case: Privacy-Preserving Query Routing + +## Problem + +Current CipherOcto architecture has a privacy gap: +- Sellers see prompt content when proxying requests +- Trust assumption required - seller could leak/inspect data +- No cryptographic guarantee of privacy +- Enterprise users cannot use due to compliance + +## Motivation + +### Why This Matters for CipherOcto + +1. **Privacy** - Cryptographic guarantee, not trust +2. **Compliance** - Meet SOC2, HIPAA, GDPR requirements +3. **Enterprise adoption** - Unblock enterprise users +4. **Competitive advantage** - Differentiator in market + +### The Opportunity + +- Enterprise AI market requires privacy guarantees +- No current solution for proxy-based routing with privacy +- Growing regulatory pressure + +## Solution Architecture + +### Privacy-Preserving Proxy + +```mermaid +flowchart TD + subgraph ENCRYPT["Client Side"] + USER[User] --> ENC[Encrypt Prompt] + ENC -->|encrypted| PROXY[Proxy] + end + + subgraph COMMIT["Commitment Phase"] + PROXY -->|commitment| SELLER[Seller] + SELLER -->|verify commitment| PROXY + end + + subgraph PROOF["Proof Generation"] + PROXY --> ROUTE[Route to AI] + ROUTE --> ZK[Generate ZK Proof] + ZK --> PROOF[Proof of Correct Routing] + end + + subgraph DECRYPT["Client Side"] + PROOF -->|result + proof| USER + USER -->|verify proof| V[Verify] + end + + style ENC fill:#b03a2e + style PROOF fill:#27ae60 + style V fill:#1f618d +``` + +## Privacy Levels + +### Tiered Privacy Model + +| Level | What Seller Sees | Proof Type | +|-------|-----------------|-------------| +| **Standard** | Nothing | Routing commitment | +| **Confidential** | Model type only | No input/output | +| **Private** | Nothing at all | Full zk proof | +| **Sovereign** | User controls | Selective disclosure | + +### Standard Mode (Phase 1) + +``` +User Prompt → [Encrypt] → Proxy + │ + ▼ + Seller receives: + - Commitment (hash of encrypted) + - No plaintext + │ + ▼ + Route to AI + │ + ▼ + Return: result + proof + │ + ▼ + User verifies proof +``` + +### Private Mode (Phase 2) + +``` +User Prompt → [Encrypt + ZK-Commit] → Proxy + │ + ▼ + Seller receives: + - ZK commitment + - Proof of valid commitment + - Nothing else + │ + ▼ + Route to AI (blind) + │ + ▼ + Return: encrypted result + │ + ▼ + User decrypts +``` + +## Cryptographic Primitives + +### Commitment Scheme + +```rust +struct PrivacyCommitment { + // Encrypted prompt (seller cannot read) + encrypted_prompt: Vec, + + // Commitment for verification + commitment: FieldElement, + + // Randomness (for ZK) + randomness: FieldElement, + + // Proof of valid commitment + proof: ZKProof, +} + +impl PrivacyCommitment { + fn create(prompt: &[u8], public_key: &PublicKey) -> Self { + // 1. Generate randomness + let r = random(); + + // 2. Encrypt prompt + let encrypted = encrypt(prompt, public_key, r); + + // 3. Create commitment + let commitment = pedersen_commit(encrypted, r); + + // 4. ZK proof that commitment is valid + let proof = prove_commitment_valid(encrypted, r, commitment); + + Self { encrypted_prompt: encrypted, commitment, randomness: r, proof } + } + + fn verify(&self) -> bool { + // Verify ZK proof without revealing plaintext + verify_proof(&self.proof, &self.commitment) + } +} +``` + +### Selective Disclosure + +```rust +struct SelectiveDisclosure { + // Full encrypted data + encrypted: EncryptedData, + + // Disclosure policy + policy: DisclosurePolicy, + + // Proof of policy compliance + policy_proof: ZKProof, +} + +enum DisclosurePolicy { + Never, // Never reveal + OnDispute, // Reveal only in disputes + Timer { reveal_after: u64 }, // Reveal after time + Threshold { signers: u8 }, // Reveal with N signatures +} + +impl SelectiveDisclosure { + fn reveal(&self, condition: &DisclosureCondition) -> Option> { + if self.policy.allows(condition) { + Some(decrypt(&self.encrypted)) + } else { + None + } + } +} +``` + +## Routing Proof + +### What Gets Proven + +```rust +struct RoutingProof { + // Commitment (doesn't reveal content) + input_commitment: FieldElement, + + // What was proven (without revealing) + proven_statements: Vec< ProvenStatement >, + + // Execution details (verifiable) + provider: Address, + model: String, // e.g., "gpt-4" - allowed to reveal + timestamp: u64, + latency_ms: u64, + + // ZK proof + proof: CircleStarkProof, +} + +enum ProvenStatement { + InputEncrypted, + RoutingCorrect, + OutputValid, + NoDataLeaked, +} +``` + +### Verification + +```mermaid +sequenceDiagram + User->>Proxy: Request (encrypted) + Proxy->>Seller: Commitment only + Seller->>Proxy: Acknowledge + Proxy->>AI: Route (blind) + AI->>Proxy: Result + Proxy->>User: Result + Proof + + alt Dispute + User->>DisputeResolver: Challenge + DisputeResolver->>Proxy: Request verification + Proxy->>DisputeResolver: Submit proof + DisputeResolver->>DisputeResolver: Verify ZK + end +``` + +## Privacy vs Features + +### Trade-off Matrix + +| Feature | Standard Privacy | High Privacy | +|---------|-----------------|---------------| +| **Routing verification** | ✅ | ✅ | +| **Latency proof** | ✅ | ✅ | +| **Output validation** | ✅ | ✅ | +| **Model selection** | ✅ | Provider sees | +| **Prompt content** | ❌ Hidden | ❌ Hidden | +| **Response content** | ✅ Visible | ❌ Encrypted | +| **Full zkML** | ❌ | ✅ (expensive) | + +### Cost Comparison + +| Mode | Compute Cost | Latency Impact | +|------|-------------|----------------| +| Standard | 1x (baseline) | +10ms | +| Confidential | 1.5x | +50ms | +| Private | 10x | +500ms | +| Sovereign | 20x | +1000ms | + +## Compliance Mapping + +### Regulatory Requirements + +| Regulation | Privacy Mode Required | CipherOcto Feature | +|------------|----------------------|-------------------| +| **SOC2** | Confidential | No prompt access | +| **HIPAA** | Private | Full encryption | +| **GDPR** | Sovereign | Selective disclosure | +| **FINRA** | Private | Full audit trail | + +### Audit Capabilities + +``` +Regulator Request + │ + ▼ +CipherOcto Protocol + │ + ▼ + Is there a valid proof? + │ + ├── Yes → Provide proof (no plaintext needed) + │ + └── No → Flag violation +``` + +## Integration with Existing Components + +### Relationship to Quota Router + +```mermaid +graph TB + subgraph ROUTER["Quota Router (Existing)"] + ROUTE[Route Request] + BAL[Check Balance] + POL[Apply Policy] + end + + subgraph PRIVACY["Privacy Layer (New)"] + ENC[Encrypt] + COMMIT[Commit] + PROVE[Prove] + SELECT[Selective Disclose] + end + + USER -->|plaintext| ENC + ENC -->|encrypted| ROUTE + ROUTE --> BAL + BAL --> POL + POL -->|routing| COMMIT + COMMIT -->|proof| PROVE + + style PRIVACY fill:#27ae60 + style ROUTER fill:#1f618d +``` + +### Modified Request Flow + +```mermaid +sequenceDiagram + participant U as User + participant P as Privacy Proxy + participant R as Quota Router + participant S as Seller + participant A as AI Provider + + U->>P: Encrypt prompt + P->>S: Send commitment (not prompt) + S->>P: Acknowledge + P->>R: Request route (with commitment) + R->>R: Verify OCTO-W balance + R->>S: Route request + S->>A: Execute (blind) + A->>S: Return result + S->>P: Return result + proof + P->>U: Result + proof + U->>U: Verify proof locally +``` + +## Implementation Path + +### Phase 1: Standard Privacy +- [ ] Client-side encryption +- [ ] Commitment-based routing +- [ ] Proof of correct routing +- [ ] Basic verification + +### Phase 2: Confidential Mode +- [ ] Zero-knowledge commitments +- [ ] Blind execution +- [ ] Encrypted responses +- [ ] WASM verifier + +### Phase 3: Sovereign Mode +- [ ] Full zkML integration +- [ ] Selective disclosure policies +- [ ] On-chain verification +- [ ] Compliance integrations + +--- + +**Status:** Draft +**Priority:** High (addresses privacy gap) +**Token:** OCTO-W (additional fees for privacy) +**Research:** [LuminAIR Analysis](../research/luminair-analysis.md) diff --git a/docs/use-cases/provable-quality-of-service.md b/docs/use-cases/provable-quality-of-service.md new file mode 100644 index 0000000..01fb1d0 --- /dev/null +++ b/docs/use-cases/provable-quality-of-service.md @@ -0,0 +1,368 @@ +# Use Case: Provable Quality of Service (QoS) + +## Problem + +Current service quality relies on trust: +- Latency claims unverified +- SLA violations difficult to prove +- Dispute resolution based on reputation +- No cryptographic proof of service delivery + +## Motivation + +### Why This Matters for CipherOcto + +1. **Dispute resolution** - Cryptographic proof vs trust +2. **SLA enforcement** - Automatic compensation +3. **Provider differentiation** - Quality verifiable on-chain +4. **Enterprise confidence** - Guaranteed service levels + +### The Opportunity + +- Enterprise users pay premium for guarantees +- DeFi requires verifiable execution +- Compliance needs audit trails + +## Quality Metrics + +### Verifiable Metrics + +| Metric | Proof Method | On-chain Settleable | +|--------|--------------|---------------------| +| **Latency** | Timestamp + hash | ✅ Auto-refund | +| **Uptime** | Block inclusion | ✅ SLA penalties | +| **Output validity** | Shape/content proof | ✅ Dispute resolution | +| **Routing correctness** | Merkle path | ✅ Payment release | +| **Model execution** | zkML proof | ✅ Quality bonus | + +### Latency Proof + +```rust +struct LatencyProof { + // Timestamps (block-based) + request_received: u64, // Block timestamp + response_sent: u64, // Block timestamp + + // What was processed (hash, not content) + request_hash: FieldElement, + response_hash: FieldElement, + + // Quality indicators + provider: Address, + model: String, + + // Verification + block_hashes: Vec, // Merkle path + signature: Signature, +} + +impl LatencyProof { + fn calculate_latency(&self) -> u64 { + self.response_sent - self.request_received + } + + fn verify(&self) -> bool { + // Verify block timestamps + // Verify Merkle inclusion + // Verify signature + true + } +} +``` + +### Uptime Proof + +```mermaid +sequenceDiagram + Network->>Provider: Ping (every block) + Provider->>Network: Pong + signature + Network->>Network: Record uptime + + Note over Network: Continuous = 100% + Note over Network: <99.9% = SLA violation + + alt SLA Violation + Network->>Escrow: Slash X% + Escrow->>User: Auto-refund + end +``` + +### Output Validity Proof + +```rust +struct OutputValidityProof { + // What was requested + request_hash: FieldElement, + + // What was returned + output_hash: FieldElement, + + // Validity checks + checks: Vec, +} + +enum ValidityCheck { + ValidJson, + ValidSchema(Schema), + MaxSize(u64), + ContainsField(String), + ValidTokenCount(u64), +} + +impl OutputValidityProof { + fn verify(&self, output: &[u8]) -> bool { + self.checks.iter().all(|check| check.validates(output)) + } +} +``` + +## SLA Structure + +### Service Levels + +| Tier | Latency | Uptime | Output Validity | Price | +|------|---------|--------|------------------|-------| +| **Basic** | < 10s | 99% | Best effort | 1x | +| **Standard** | < 5s | 99.9% | Guaranteed | 1.5x | +| **Premium** | < 1s | 99.99% | Verified | 2x | +| **Enterprise** | < 500ms | 99.999% | Fully proven | 4x | + +### SLA Penalties + +```mermaid +flowchart TD + VIOLATION[SLA Violation Detected] --> CHECK[Check Severity] + + CHECK -->|Latency| LATENCY[Latency Penalty] + CHECK -->|Uptime| UPTIME[Uptime Penalty] + CHECK -->|Output| OUTPUT[Output Penalty] + + LATENCY -->|5-10%| P5[5% refund] + LATENCY -->|10-25%| P10[10% refund] + LATENCY -->|>25%| P25[25% refund] + + UPTIME -->|99-99.9%| U5[5% refund] + UPTIME -->|95-99%| U10[10% refund] + UPTIME -->|<95%| U25[Full refund] + + OUTPUT -->|Invalid| OF[Full refund + penalty] + OUTPUT -->|Missing| OM[Partial refund] +``` + +## On-chain Settlement + +### Escrow Mechanism + +```mermaid +flowchart LR + subgraph STAKE["Provider Stake"] + PROVIDER[Provider] -->|deposit| ESCROW[Escrow Contract] + end + + subgraph EXECUTE["Execution"] + USER[User] -->|request| ROUTER[Router] + ROUTER -->|route| PROVIDER + PROVIDER -->|execute| RESULT[Result + Proof] + end + + subgraph VERIFY["Verification"] + RESULT -->|submit| ESCROW + ESCROW -->|verify| VERIFIER[Verifier] + end + + subgraph SETTLE["Settlement"] + VERIFIER -->|valid| PAY[Pay Provider] + VERIFIER -->|invalid| REFUND[Refund User] + end +``` + +### Smart Contract Logic + +```cairo +#[starknet::contract] +mod QoSContract { + struct Storage { + provider_stake: u256, + total_requests: u64, + sla_violations: u64, + } + + #[external] + fn verify_and_settle( + proof: QualityProof, + user: address + ) -> u256 { + // 1. Verify proof + assert(verify_proof(proof), 'Invalid proof'); + + // 2. Calculate penalty if any + let penalty = calculate_penalty(proof); + + // 3. Settle + if penalty > 0 { + slash_provider(penalty); + refund_user(user, penalty); + } else { + pay_provider(proof.amount); + } + + penalty + } +} +``` + +## Dispute Resolution + +### Challenge Flow + +```mermaid +sequenceDiagram + User->>Protocol: "Service was below SLA" + Protocol->>User: "Submit proof or claim" + User->>Protocol: "Here is my proof" + + alt User Has Proof + Protocol->>Verifier: Verify + alt Proof Valid + Protocol->>Provider: Slash + Refund + else Proof Invalid + Protocol->>User: Claim rejected + end + + else User No Proof + Protocol->>Arbitration: Escalate + Arbitration->>Provider: "Submit counter-proof" + Arbitration->>Arbitration: Judge + end +``` + +### Arbitration Levels + +| Level | Description | Resolution Time | +|-------|-------------|----------------| +| **Automated** | On-chain verification | < 1 minute | +| **Evidence** | Both parties submit proof | < 24 hours | +| **Arbitration** | Third-party judge | < 7 days | +| **Appeals** | DAO vote on edge cases | < 30 days | + +## Quality Scoring + +### Provider Reputation Integration + +```rust +struct QualityScore { + // Raw metrics + total_requests: u64, + successful_requests: u64, + avg_latency_ms: u64, + uptime_percent: f64, + + // SLA performance + sla_violations: u64, + sla_fulfilled: u64, + + // Proof quality + proofs_submitted: u64, + proofs_valid: u64, + + // Calculated + score: u8, + tier: QualityTier, +} + +enum QualityTier { + Basic, // < 50 + Standard, // 50-75 + Premium, // 75-90 + Elite, // > 90 +} + +impl QualityScore { + fn calculate(&mut self) { + let sla_score = (self.sla_fulfilled as f64 / self.total_requests as f64) * 100.0; + let proof_score = (self.proofs_valid as f64 / self.proofs_submitted as f64) * 100.0; + let latency_score = if self.avg_latency_ms < 1000 { 100 } else { 50 }; + + self.score = ((sla_score * 0.4) + (proof_score * 0.4) + (latency_score * 0.2)) as u8; + self.tier = match self.score { + 0..=50 => QualityTier::Basic, + 51..=75 => QualityTier::Standard, + 76..=90 => QualityTier::Premium, + _ => QualityTier::Elite, + }; + } +} +``` + +### Quality Display + +```mermaid +flowchart TD + subgraph PROVIDER["Provider Listing"] + NAME[Provider Name] + SCORE[Quality Score: 85/100] + METRICS[Uptime: 99.9%
Latency: 450ms
SLA: 98%] + TIER[Tier: Premium] + end + + style SCORE fill:#27ae60 + style TIER fill:#1f618d +``` + +## Integration with CipherOcto + +### Modified Request Flow + +```mermaid +sequenceDiagram + User->>Router: Request (with SLA tier) + Router->>Router: Check provider quality scores + Router->>Provider: Route to qualified provider + Provider->>Provider: Execute + generate proofs + Provider->>Escrow: Submit proof + stake + Escrow->>Router: Verification result + Router->>User: Deliver result + proof + + alt SLA Met + Router->>Provider: Release payment + else SLA Violated + Router->>Escrow: Trigger penalty + Escrow->>User: Auto-refund + end +``` + +### Token Economics + +| Component | Token | Purpose | +|-----------|-------|---------| +| Provider stake | OCTO | Security deposit | +| Payment | OCTO-W | For execution | +| Bonuses | OCTO | For exceeding SLA | +| Penalties | OCTO | Slashed for violations | + +## Implementation Path + +### Phase 1: Basic QoS +- [ ] Timestamp-based latency proofs +- [ ] Block inclusion for uptime +- [ ] Basic SLA penalties +- [ ] Manual dispute submission + +### Phase 2: Automated Verification +- [ ] On-chain proof verification +- [ ] Automatic refund triggers +- [ ] Quality score calculation +- [ ] Provider tiering + +### Phase 3: Full SLA +- [ ] zkML output validation +- [ ] Real-time verification +- [ ] Complete arbitration system +- [ ] Enterprise SLA contracts + +--- + +**Status:** Draft +**Priority:** High (improves trust) +**Token:** OCTO, OCTO-W +**Research:** [LuminAIR Analysis](../research/luminair-analysis.md) diff --git a/docs/use-cases/storage-provider-network.md b/docs/use-cases/storage-provider-network.md new file mode 100644 index 0000000..1a003b5 --- /dev/null +++ b/docs/use-cases/storage-provider-network.md @@ -0,0 +1,277 @@ +# Use Case: Storage Provider Network (OCTO-S) + +## Problem + +CipherOcto agents need persistent memory and data storage, but: +- No decentralized encrypted storage exists for AI agents +- Sensitive data requires guarantees of privacy +- Historical state must be verifiable and immutable +- Storage costs remain high with centralized providers + +## Motivation + +### Why This Matters for CipherOcto + +1. **Agent persistence** - Agents must remember context across sessions +2. **Data sovereignty** - Users control their encrypted data +3. **Immutable records** - Blockchain-backed historical proof +4. **Recurring revenue** - Storage creates durable token demand + +### The Opportunity + +- $30B+ cloud storage market +- Growing AI data requirements +- Privacy concerns increasing demand for encryption + +## Impact + +### If Implemented + +| Area | Transformation | +|------|----------------| +| **Agent Memory** | Persistent state across sessions | +| **Data Privacy** | End-to-end encryption guaranteed | +| **Revenue** | Recurring provider income | +| **Verifiability** | ZK proofs of storage integrity | + +### If Not Implemented + +| Risk | Consequence | +|------|-------------| +| No persistence | Agents lose context | +| Privacy gaps | Users don't trust network | +| Limited utility | Network feels incomplete | + +## Narrative + +### Current State + +``` +Agent runs today +Agent restarts tomorrow +→ All context lost +→ Must start fresh +→ User frustrated +``` + +### Desired State (With Storage) + +``` +Agent processes task + │ + ▼ +Encrypted data → Storage network (OCTO-S) + │ + ▼ +Agent restarts tomorrow + │ + ▼ +Retrieves encrypted context + │ + ▼ +Continues seamlessly +``` + +## Token Mechanics + +### OCTO-S Token + +| Aspect | Description | +|--------|-------------| +| **Purpose** | Payment for encrypted storage | +| **Earned by** | Storage providers | +| **Spent by** | Agent memory, data archives | +| **Value** | Represents storage capacity (GB-months) | + +### Pricing Model + +```mermaid +graph LR + subgraph FACTORS["Pricing Factors"] + F1[Storage Size
GB/month] + F2[Durability
99.9% vs 99.99%] + F3[Encryption
Standard vs ZK] + F4[Access Pattern
Hot vs Cold] + end + + F1 --> P[Price per GB-month] + F2 --> P + F3 --> P + F4 --> P +``` + +## Storage Tiers + +### Hot Storage +- Frequently accessed data +- Low latency requirements +- Higher cost per GB + +### Cold Storage +- Archival data +- Infrequent access +- Lower cost, higher retrieval time + +### Encrypted Vaults +- Maximum security +- Zero-knowledge proof availability +- Enterprise compliance + +## Verification + +### Proof of Storage + +```mermaid +sequenceDiagram + Provider->>Network: Register storage capacity + Network->>Provider: Challenge (random data) + Provider->>Network: Store + merkle root + Network->>Network: Verify merkle proof + Network->>Provider: Confirm capacity +``` + +### Integrity Verification + +| Method | Frequency | Purpose | +|--------|-----------|----------| +| Merkle proofs | Random | Data integrity | +| Uptime checks | Hourly | Availability | +| Encryption validation | Weekly | Security | +| ZK proofs | On-demand | Privacy verification | + +## ZK Integration + +### Stoolap Integration + +The storage layer integrates with Stoolap blockchain: + +```mermaid +graph TB + subgraph STOOLAP["Stoolap Layer"] + S1[SQL Engine] + S2[ZK Prover] + S3[Storage Layer] + end + + subgraph CIPHER["CipherOcto"] + C1[Agents] + C2[Encrypted Memory] + C3[Query Interface] + end + + C1 --> C2 + C2 --> C3 + C3 -->|Query| S1 + S1 -->|Proof| S2 + S2 -->|Verify| C3 +``` + +### Privacy Guarantees + +| Feature | Protection | +|---------|------------| +| Client-side encryption | Provider cannot read data | +| Zero-knowledge proofs | Verify without exposing | +| Selective disclosure | Share specific fields only | +| Immutable logs | Historical proof | + +## Data Flagging + +Storage respects CipherOcto's data classification: + +| Level | Storage Behavior | +|-------|-----------------| +| **PRIVATE** | Single-tenant, never leaves user | +| **CONFIDENTIAL** | Encrypted, access-controlled | +| **SHARED** | Encrypted, accessible to verified agents | +| **PUBLIC** | Can be cached, monetizable | + +## Provider Requirements + +### Minimum Stake + +| Tier | Storage Provided | Stake Required | +|------|-----------------|----------------| +| Basic | 10 GB | 100 OCTO | +| Standard | 100 GB | 1000 OCTO | +| Professional | 1 TB | 10,000 OCTO | +| Enterprise | 10 TB | 100,000 OCTO | + +### Slashing Conditions + +| Offense | Penalty | +|---------|---------| +| Data loss | 50-100% stake | +| Privacy breach | 100% stake + ban | +| Invalid proofs | 25% stake | +| Downtime >24h | 10% stake | + +## Relationship to Other Components + +```mermaid +graph TB + subgraph ECOSYSTEM["CipherOcto Ecosystem"] + STORAGE[Storage Network
OCTO-S] + AGENTS[Agent Marketplace
OCTO-D] + COMPUTE[Compute Network
OCTO-A] + WALLET[Wallet] + end + + STORAGE -->|Persists| AGENTS + AGENTS -->|Uses| COMPUTE + COMPUTE -->|Writes to| STORAGE + STORAGE -->|Earns| WALLET + + style STORAGE fill:#27ae60 + style AGENTS fill:#6c3483 + style COMPUTE fill:#b03a2e + style WALLET fill:#1f618d +``` + +## Use Cases + +### Agent Memory +- Conversation history +- User preferences +- Learning data + +### Knowledge Vaults +- Proprietary insights +- Research data +- Business intelligence + +### Immutable Records +- Transaction history +- Compliance logs +- Verification proofs + +## Implementation Path + +### Phase 1: Basic Storage +- [ ] Provider registration +- [ ] Encrypted upload/download +- [ ] Basic durability guarantees +- [ ] Simple payment in OCTO-S + +### Phase 2: ZK Integration +- [ ] Stoolap integration +- [ ] Proof generation +- [ ] Verification layer +- [ ] Tiered storage options + +### Phase 3: Enterprise Features +- [ ] SOC2 compliance +- [ ] HIPAA support +- [ ] GDPR tools +- [ ] Multi-region replication + +## RFC Link + +- [RFC-0100: AI Quota Marketplace Protocol](../rfcs/0100-ai-quota-marketplace.md) +- [Wallet Technology Research](../research/wallet-technology-research.md) + +--- + +**Status:** Draft +**Priority:** High (Phase 2) +**Token:** OCTO-S diff --git a/docs/use-cases/unified-vector-sql-storage.md b/docs/use-cases/unified-vector-sql-storage.md new file mode 100644 index 0000000..351da2e --- /dev/null +++ b/docs/use-cases/unified-vector-sql-storage.md @@ -0,0 +1,243 @@ +# Use Case: Unified Vector-SQL Storage for Sovereign AI + +## Problem + +CipherOcto faces a critical infrastructure challenge: AI agents require multiple specialized systems that don't communicate efficiently: + +1. **Vector databases** (Qdrant, Pinecone) for semantic memory and retrieval +2. **SQL databases** (PostgreSQL, SQLite) for structured data (quotas, payments, reputation) +3. **Blockchain** for state verification and audit trails + +### Current Pain Points + +| Challenge | Current Solution | Problem | +| ----------------------------- | ------------------------- | ------------------------------------- | +| **Data consistency** | Multiple systems | No ACID across vector + SQL | +| **Query latency** | Separate API calls | RTT overhead between systems | +| **Infrastructure complexity** | Multiple deployments | Operational burden | +| **Cost** | Multiple licenses/servers | Budget multiplied | +| **Agent memory** | External vector DB | No blockchain verification | +| **Verification** | Separate blockchain | Can't prove vector search correctness | + +## MVP vs. Full Capabilities + +| Capability | MVP (Phases 1-3) | Full (Phase 4+) | +| ---------- | ---------------- | --------------- | +| **Storage** | Unified Vector + SQL in one system | Same | +| **Query Latency** | <50ms | Same | +| **Verification** | Async Merkle proofs (<5s) | Real-time deterministic re-ranking | +| **Consensus** | Raft (leader-follower) | Optional brute-force for strict consensus | +| **Payload Filters** | SQL WHERE clause | Same | +| **Hybrid Search** | - | BM25 + vector | + +> **Note**: The "Verifiable AI Memory" narrative (Phase 4+) requires deterministic verification. MVP delivers unified storage with async proofs — genuinely useful but a different value proposition. + +## Motivation + +### Why This Matters for CipherOcto + +1. **Sovereign Intelligence** - Data ownership and local-first capabilities; agents have private, verifiable memory +2. **Unified Data Layer** - Single system for all agent data +3. **Blockchain Integration** - Provenance and verification of AI decisions +4. **Cost Efficiency** - One system instead of three + +### The Opportunity + +- **No system combines all three**: Current market has vector OR SQL OR blockchain, but never **vector + SQL + blockchain verification** in a single engine +- **Existing partial solutions**: PostgreSQL+pgvector, Weaviate, Milvus, LanceDB - but none offer blockchain verification +- **AI + Blockchain convergence** - Growing demand for verifiable AI +- **CipherOcto's edge** - Already has blockchain modules (trie, consensus), inherited from Stoolap + +### Why Now + +- Stoolap provides solid SQL/MVCC foundation +- Qdrant provides production-tested vector capabilities +- Integration creates unique market position + +## Impact + +### If Implemented + +| Area | Transformation | +| ------------------ | -------------------------------------------- | +| **Agent Memory** | Vector search with SQL queries in one system | +| **Verification** | Merkle proofs for vector search results | +| **Infrastructure** | Single deployment instead of three | +| **Latency** | 50-120ms instead of 150-400ms (50ms: simple queries; 120ms: complex hybrid or with proof) | +| **Cost** | ~60% reduction in storage costs | +| **Privacy** | Local-first with optional blockchain | + +### If Not Implemented + +| Risk | Consequence | +| ------------------- | -------------------------------------------- | +| Multiple systems | Higher ops cost, consistency issues | +| No verification | Can't prove AI decision provenance | +| Slow agents | Cross-system queries add latency | +| Competitor launches | Market captured by less-capable alternatives | + +## Narrative + +### The Agent's Perspective + +**Today (Multiple Systems):** + +``` +Agent: "Find similar tasks" + → Vector DB: Returns task IDs (100ms) + → SQL DB: Fetch task details (50ms) + → Blockchain: Verify task authenticity (200ms) + = 350ms total, consistency challenges +``` + +**With Unified Storage:** + +``` +Agent: "Find similar verified tasks" + → Single query: Vector + SQL + Verification + = 50-120ms total, ACID guarantees +``` + +### Example: Agent Reputation System + +```sql +-- Store agent embeddings with reputation data +CREATE TABLE agent_memory ( + agent_id INTEGER PRIMARY KEY, + embedding VECTOR(768), + reputation_score FLOAT, + last_verified TIMESTAMP, + verification_proof BLOB +) STORAGE = mmap; + +-- Create searchable index +CREATE INDEX idx_agent ON agent_memory(embedding) +USING HNSW WITH (quantization = 'pq'); + +-- Query: Find similar high-reputation agents +SELECT a.agent_id, a.reputation_score, + VEC_DISTANCE_COSINE(a.embedding, $query) as similarity +FROM agent_memory a +WHERE a.reputation_score > 0.9 +ORDER BY similarity +LIMIT 10; +``` + +### Example: Provable Query Results + +```rust +// Standard query (fast, no verification) +let results = db.query( + "SELECT * FROM embeddings WHERE category = 'ai' ORDER BY VEC_DISTANCE_COSINE(embedding, $1) LIMIT 10" +)?; + +// Async verification (for blockchain/proof needs) +// Verification happens in background, results returned immediately +let verified_results = db.query_verified( + "SELECT * FROM embeddings ORDER BY VEC_DISTANCE_COSINE(embedding, $1) LIMIT 10", + VerificationLevel::Proof // Returns results + async proof +).await?; + +// Proof generated in background (<5s P95) +// Enables: verifiable AI decision trails +``` + +## Technical Requirements + +### From RFC-0103 + +**MVP (Phases 1-3):** + +- In-Memory + Memory-Mapped storage +- RocksDB persistence (optional) +- Vector quantization (PQ, SQ, BQ) +- Async proof generation (<5s) +- Segment-based MVCC + +**Future (Phases 4-7):** + +- Deterministic verification (software float re-ranking) +- Sparse vectors + BM25 hybrid search +- Payload filtering indexes +- GPU acceleration +- Strict consensus mode (brute-force for DeFi) + +### Rollout Phases + +| Phase | Timeline | Features | +| --------- | --------- | --------------------------------------------- | +| MVP (1-3) | Near-term | Unified Vector-SQL, persistence, quantization | +| Phase 4 | Mid-term | Deterministic verification, async proofs | +| Phase 5-7 | Long-term | Hybrid search, GPU, strict consensus | + +> **Note**: "Verifiable Memory" capabilities are primarily delivered in Phase 4. The MVP provides unified storage with async proof generation; real-time deterministic verification follows. +> +> **Proof Types**: +> - **Merkle proofs** (Phase 1-4): Inclusion proofs that vector data exists in committed state — fast to generate, sufficient for most use cases +> - **ZK proofs** (Phase 4+): Zero-knowledge proofs for privacy-preserving verification — inherited from Stoolap's existing ZK module + +### CipherOcto Integration Points + +| Component | Integration | +| ------------------ | ---------------------------------- | +| Agent Orchestrator | Unified storage for agent memory | +| Quota Marketplace | Vector similarity + SQL in one | +| Node Operations | Persistent state with verification | +| Reputation System | Verifiable agent history | + +## Related RFCs + +- [RFC-0103: Unified Vector-SQL Storage Engine](../../rfcs/0103-unified-vector-sql-storage.md) (aligned with RFC-0103 rev March 2026) + +## Strategic Positioning + +### Product Category + +When executed correctly, this system positions CipherOcto as: + +> **The First Verifiable AI Database** + +| Analogy | Description | +| ------------------------- | ------------------------------- | +| **Snowflake for AI data** | Unified data platform for AI | +| **Ethereum for AI state** | Verifiable, deterministic state | +| **Qdrant for memory** | But with SQL + blockchain | + +### Key Differentiator: Verifiable AI Memory + +The most powerful aspect is not the vector database: + +``` +AI Decision + → Memory Retrieval + → Provable Dataset + → Verifiable Reasoning Trail +``` + +This enables: + +- **Decentralized AI agents** with verifiable decision history +- **DAO decision systems** with auditable AI input +- **AI marketplaces** with verified model behavior +- **Regulatory AI auditing** with complete trails + +No other database offers this combination. + +### Consensus Model Clarification + +> **Note**: "Sovereign" refers to **data ownership and local-first** capabilities. The initial replication uses Raft (leader-follower) for strong consistency. Full decentralization (Gossip/Blockchain consensus) is planned for future phases. + +## Success Metrics + +| Metric | Target | Notes | +| -------------------- | ---------------------------- | ------------------------------------------------------------------------------------------------------------- | +| Query latency | <50ms | Query execution only; proof generation is async/optional | +| Proof generation | <5s (P95) | Async background, SLAs defined | +| Storage cost | 60% reduction | Breakdown: ~20% (eliminate 3-DB duplication) + ~25% (BQ 32x compression) + ~15% (no network egress); BQ suitable for recall-tolerant workloads | +| Compression ratio | 4-64x | PQ/SQ/BQ configurations | +| Recall@10 | >95% | At 15% tombstone threshold (compaction triggers at 15%, hard limit at 30%) | +| API simplicity | Unified API | Single query interface; SDK is downstream goal | +| Verification | Merkle proofs | For committed snapshots only | +| Feature completeness | Parity with Qdrant + Stoolap | Phased implementation | + +> **Clarification**: The <50ms latency is for query execution. Generating Merkle proofs for complex query results takes longer and is handled asynchronously. Proof generation SLAs: 95th percentile <5 seconds. diff --git a/docs/use-cases/verifiable-ai-agents-defi.md b/docs/use-cases/verifiable-ai-agents-defi.md new file mode 100644 index 0000000..67ec3d8 --- /dev/null +++ b/docs/use-cases/verifiable-ai-agents-defi.md @@ -0,0 +1,295 @@ +# Use Case: Verifiable AI Agents for DeFi + +## Problem + +DeFi protocols face trust challenges with AI agents: +- No way to verify trading decisions were made correctly +- Black-box AI makes unpredictable moves with user funds +- Cannot prove agent followed its stated strategy +- Auditing requires full re-execution of decisions + +## Motivation + +### Why This Matters for CipherOcto + +1. **Trust** - Users can verify agent decisions post-hoc +2. **Transparency** - On-chain proof of correct execution +3. **Compliance** - Regulators can audit without re-executing +4. **New market** - DeFi protocols pay premium for verifiable AI + +### The Opportunity + +- $50B+ DeFi market needing trustless automation +- Growing demand for transparent AI in finance +- No current solution for provable AI decisions + +## Solution Architecture + +### Verifiable Trading Agent + +```mermaid +flowchart TD + subgraph AGENT["Verifiable Trading Agent"] + INPUT[Market Data] --> ANALYZE[Analysis Module] + ANALYZE --> DECIDE[Decision Engine] + DECIDE --> PROOF[Proof Generator] + PROOF --> PROVE[ZK Proof] + PROOF --> TX[On-chain Transaction] + end + + subgraph VERIFY["Verification Layer"] + PROVE --> VERIFIER[Verifier] + VERIFIER --> CHAIN[Blockchain] + CHAIN --> RECORD[Stored Proof] + end + + style PROOF fill:#27ae60 + style VERIFIER fill:#1f618d + style CHAIN fill:#6c3483 +``` + +## Proof Components + +### Decision Proof Structure + +```rust +struct DecisionProof { + // Market state (hashed, not revealed) + market_state_hash: FieldElement, + + // Decision details + action: TradeAction, // Buy, Sell, Hold + asset: String, + amount: u64, + reason_hash: FieldElement, // Hash of reasoning + + // Execution proof + timestamp: u64, + block_number: u64, + zk_proof: CircleStarkProof, +} + +enum TradeAction { + Buy { price_limit: u64 }, + Sell { price_limit: u64 }, + Hold, +} +``` + +### What Gets Proven + +| Property | Proof Method | On-chain Settleable | +|----------|--------------|---------------------| +| **Correct analysis** | zkML proof | ✅ | +| **Strategy adherence** | Constraint proof | ✅ | +| **Timing** | Block timestamp | ✅ | +| **No manipulation** | Merkle inclusion | ✅ | + +## Integration with CipherOcto + +### Token Flow + +```mermaid +flowchart LR + subgraph REQUEST["Request Layer"] + USER[User] --> ROUTER[Quota Router] + end + + subgraph AGENT["Agent Layer"] + ROUTER --> AGENT[DeFi Agent] + AGENT --> ZK[ZK Proof Gen] + end + + subgraph SETTLE["Settlement Layer"] + ZK --> ONCHAIN[On-chain] + ONCHAIN --> VERIFY[Verify] + VERIFY --> PAY[Release Payment] + end + + USER -->|OCTO-W| PAY + AGENT -->|earns| PAY +``` + +### Agent Reputation + Proof + +``` +Verification Score = (Reputation * 0.3) + (Proof Quality * 0.7) + +Where: +- Reputation: Historical success rate +- Proof Quality: Completeness of zk proof +``` + +## Use Cases + +### Automated Trading Strategies + +| Strategy | Verifiable Proof | +|----------|-----------------| +| **Dollar-cost averaging** | Regular intervals proven | +| **Rebalancing** | Threshold triggers proven | +| **Arbitrage** | Cross-exchange timing proven | +| **Yield optimization** | APY calculations proven | + +### Portfolio Management + +``` +User: "Invest $10K in blue-chip DeFi" + │ + ▼ +Agent: Analyzes → Decides → Proves + │ + ▼ +Proof: "Allocated 60% stablecoin, 40% blue-chip" + │ + ▼ +On-chain: Verified → Executed → Recorded +``` + +### Risk Management + +| Risk | Verifiable Proof | +|------|-----------------| +| **Stop-loss triggered** | Price oracle + timestamp | +| **Max drawdown** | Historical value proof | +| **Exposure limits** | Portfolio composition proof | + +## Dispute Resolution + +### Challenge Flow + +```mermaid +sequenceDiagram + User->>Protocol: Challenge: "Agent lost my funds" + Protocol->>Agent: Request decision proof + Agent->>Protocol: Submit ZK proof + Protocol->>Verifier: Verify proof + alt Proof Valid + Protocol->>User: Claim rejected - agent followed rules + else Proof Invalid + Protocol->>Agent: Slash stake + Protocol->>User: Refund + penalty + end +``` + +### Slashing Conditions + +| Offense | Penalty | +|---------|---------| +| **No proof submitted** | 50% stake | +| **Invalid proof** | 100% stake | +| **Strategy deviation** | 75% stake | +| **Late proof** | Warning → penalty | + +## Technical Implementation + +### Proof Generation + +```rust +impl VerifiableAgent { + fn generate_decision_proof( + &self, + market_data: &MarketData, + decision: &Decision, + ) -> Result { + // 1. Hash market data (commitment) + let market_hash = hash(market_data); + + // 2. Execute decision in zkML circuit + let trace = self.execute_zk(market_data, decision); + + // 3. Generate Circle STARK proof + let proof = stwo_prover::prove(trace)?; + + // 4. Create proof structure + Ok(DecisionProof { + market_state_hash: market_hash, + action: decision.action, + reason_hash: hash(decision.reasoning), + timestamp: current_timestamp(), + block_number: current_block(), + zk_proof: proof, + }) + } +} +``` + +### Verification + +```rust +fn verify_decision_proof(proof: &DecisionProof) -> bool { + // 1. Verify ZK proof + if !stwo_verifier::verify(&proof.zk_proof) { + return false; + } + + // 2. Verify timing + if proof.timestamp > current_timestamp() { + return false; + } + + // 3. Verify block inclusion + if !verify_merkle_inclusion(proof) { + return false; + } + + true +} +``` + +## CipherOcto Integration + +### Relationship to Other Components + +```mermaid +graph TB + subgraph ECOSYSTEM["CipherOcto"] + VERIFIABLE[Verifiable Agents
OCTO-D + ZK] + ORCH[Orchestrator
OCTO-O] + COMPUTE[Compute Network
OCTO-A] + WALLET[Wallet] + end + + VERIFIABLE -->|uses| COMPUTE + VERIFIABLE -->|routes| ORCH + VERIFIABLE -->|earns| WALLET + ORCH -->|discovers| VERIFIABLE + + style VERIFIABLE fill:#6c3483 + style ORCH fill:#b7950b + style COMPUTE fill:#b03a2e + style WALLET fill:#1f618d +``` + +### Token Economics + +| Component | Token | Purpose | +|-----------|-------|---------| +| Agent execution | OCTO-W | Pay for inference | +| Agent development | OCTO-D | Developer revenue | +| Verification | OCTO | Protocol security | +| Staking | OCTO | Economic commitment | + +## Implementation Path + +### Phase 1: Basic Verifiable Agents +- [ ] Decision logging with hashes +- [ ] Block timestamp proofs +- [ ] Strategy commitment on-chain + +### Phase 2: zkML Integration +- [ ] Lightweight zkML for decisions +- [ ] WASM verifier for browsers +- [ ] Off-chain verification + +### Phase 3: Full Protocol +- [ ] On-chain Cairo verifier +- [ ] EigenLayer AVS integration +- [ ] Complete dispute flow + +--- + +**Status:** Draft +**Priority:** Medium (Phase 2-3) +**Token:** OCTO-D, OCTO-W, OCTO +**Research:** [LuminAIR Analysis](../research/luminair-analysis.md) diff --git a/missions/build-first-agent.md b/missions/build-first-agent.md index 04c2138..1e428f3 100644 --- a/missions/build-first-agent.md +++ b/missions/build-first-agent.md @@ -1,8 +1,10 @@ # Mission: Build the First CipherOcto Agent -**Difficulty:** Intermediate -**Reward:** First-mover positioning in agent marketplace -**Category:** Builder / OCTO-D +## Status +Open + +## Category +This is an **Agent Builder** mission - different from the Quota Marketplace track. --- diff --git a/missions/custom-policy-engine.md b/missions/custom-policy-engine.md new file mode 100644 index 0000000..44eabf0 --- /dev/null +++ b/missions/custom-policy-engine.md @@ -0,0 +1,123 @@ +# Mission: Custom Policy Engine + +## Status +Open + +## RFC +RFC-0100: AI Quota Marketplace Protocol +RFC-0101: Quota Router Agent Specification +RFC-0102: Wallet Cryptography Specification + +## Blockers / Dependencies + +- **Blocked by:** Mission: Multi-Provider Support (must complete first) + +## Acceptance Criteria + +- [ ] Custom policy configuration file +- [ ] Policy validation +- [ ] Built-in policy templates +- [ ] Policy switching at runtime +- [ ] Policy analytics dashboard + +## Description + +Allow developers to define custom routing policies beyond the built-in presets, enabling fine-grained control over how requests are routed. + +## Technical Details + +### Policy Configuration + +```yaml +# quota-router.yaml +policy: + name: my-custom-policy + version: "1.0" + +routing: + # Failover chain + chain: + - provider: openai + max_price: 5 + required: true + - provider: anthropic + max_price: 10 + required: false + - provider: market + max_price: 15 + required: false + + # Conditions + conditions: + - if: + time: "22:00-06:00" + then: + prefer: anthropic + - if: + prompt_length: ">2000" + then: + provider: openai-turbo + + # Budget limits + budget: + daily_limit: 1000 # OCTO-W + alert_at: 800 + pause_at: 950 +``` + +### CLI Commands + +```bash +# Create policy from template +quota-router policy create --template balanced + +# Edit policy +quota-router policy edit + +# Validate policy +quota-router policy validate + +# Switch active policy +quota-router policy switch --name my-custom-policy + +# List policies +quota-router policy list + +# View analytics +quota-router policy analytics +``` + +### Built-in Templates + +| Template | Description | +|----------|-------------| +| **cheapest** | Always use lowest price | +| **fastest** | Always use lowest latency | +| **quality** | Prefer best models | +| **balanced** | Mix of price/speed/quality | +| **timezone-aware** | Different providers per time | +| **budget-aware** | Auto-adjust based on budget | + +## Dependencies + +- Mission: Multi-Provider Support (must complete first) + +## Implementation Notes + +1. **Safe defaults** - Built-in policies work out of box +2. **Validated** - Invalid policies rejected before use +3. **Observable** - Clear analytics on policy performance + +## Claimant + + + +## Pull Request + + + +--- + +**Mission Type:** Implementation +**Priority:** Medium +**Phase:** Policy Engine diff --git a/missions/multi-provider-support.md b/missions/multi-provider-support.md new file mode 100644 index 0000000..4fa3750 --- /dev/null +++ b/missions/multi-provider-support.md @@ -0,0 +1,114 @@ +# Mission: Multi-Provider Support + +## Status +Open + +## RFC +RFC-0100: AI Quota Marketplace Protocol +RFC-0101: Quota Router Agent Specification +RFC-0102: Wallet Cryptography Specification + +## Blockers / Dependencies + +- **Blocked by:** Mission: Quota Router MVE (must complete first) + +## Acceptance Criteria + +- [ ] Support multiple API providers (OpenAI, Anthropic, Google, etc.) +- [ ] Per-provider balance tracking +- [ ] Provider health monitoring +- [ ] Automatic failover when provider fails +- [ ] Provider-specific routing policies + +## Description + +Extend the quota router to support multiple AI API providers simultaneously, enabling redundancy and provider-specific optimization. + +## Technical Details + +### Provider Commands + +```bash +# Add provider +quota-router provider add --name anthropic --key $ANTHROPIC_KEY + +# List providers +quota-router provider list + +# Remove provider +quota-router provider remove --name anthropic + +# Set provider priority +quota-router provider priority --set "openai,anthropic,google" + +# Check provider health +quota-router provider health + +# Test provider +quota-router provider test --name openai +``` + +### Provider State + +```rust +struct Provider { + name: String, + status: ProviderStatus, // Active, Inactive, Error + balance: u64, // OCTO-W quota available + latency_ms: u64, + success_rate: f64, + last_used: DateTime, +} + +enum ProviderStatus { + Active, + Inactive, + Error, +} +``` + +### Routing with Multiple Providers + +```mermaid +flowchart TD + A[User makes request] --> B{Check policy} + B --> C[Find provider matching policy] + C --> D{Check provider health} + D -->|Has quota + healthy| E[Route request] + D -->|No| F{Try next provider} + E --> G[Return result] + F -->|All failed| H[Return error] +``` + +### Provider Policies + +| Policy | Selection Criteria | +|--------|-------------------| +| **cheapest** | Lowest OCTO-W per prompt | +| **fastest** | Lowest latency | +| **quality** | Prefer higher-quality models | +| **balanced** | Score based on price + speed | + +## Dependencies + +- Mission: Quota Router MVE (must complete first) + +## Implementation Notes + +1. **Graceful degradation** - If one provider fails, try others +2. **Transparent** - User doesn't notice provider switches +3. **Metric tracking** - Track success/latency per provider + +## Claimant + + + +## Pull Request + + + +--- + +**Mission Type:** Implementation +**Priority:** Medium +**Phase:** Multi-Provider diff --git a/missions/onchain-registry-migration.md b/missions/onchain-registry-migration.md new file mode 100644 index 0000000..7f0044a --- /dev/null +++ b/missions/onchain-registry-migration.md @@ -0,0 +1,99 @@ +# Mission: On-Chain Registry Migration + +## Status +Open + +## RFC +RFC-0100: AI Quota Marketplace Protocol +RFC-0102: Wallet Cryptography Specification + +## Blockers / Dependencies + +- **Blocked by:** Mission: ZK Proof Verification System (must complete first) + +## Acceptance Criteria + +- [ ] Migrate listing registry to Stoolap +- [ ] Create on-chain listing transactions +- [ ] Verify listing state with proofs +- [ ] Enable private listings with commitments +- [ ] Maintain off-chain fallback + +## Description + +Migrate the marketplace listing registry from off-chain to on-chain using Stoolap, enabling verifiable state and decentralized operation. + +## Technical Details + +### On-Chain Listing + +```rust +struct Listing { + id: u64, + seller: Address, + provider: String, + quantity: u64, + price_per_prompt: u64, + commitment: Hash, // For privacy + status: ListingStatus, +} + +// Transaction types +enum ListingTx { + Create(Listing), + Update { id: u64, quantity: u64 }, + Cancel { id: u64 }, +} +``` + +### Registry Flow + +```mermaid +flowchart TD + A[Seller creates listing] --> B[Submit to Stoolap] + B --> C[Generate state proof] + C --> D[Listing on-chain] + D --> E[Buyer queries registry] + E --> F[Verify proof] + F --> G[Purchase] +``` + +### CLI Commands + +```bash +# Create on-chain listing +quota-router listing create --prompts 100 --price 1 --on-chain + +# Verify listing proof +quota-router listing verify --id + +# Migrate existing listing to chain +quota-router listing migrate --id +``` + +## Privacy Considerations + +Use Pedersen commitments for confidential listings: +- Listing existence is public +- Price/quantity details can be private +- Buyer can verify commitment without revealing values + +## Implementation Notes + +1. **Gradual migration** - Keep off-chain as fallback +2. **Privacy optional** - Users choose public or private +3. **Proof-based** - Every state change has cryptographic proof + +## Claimant + + + +## Pull Request + + + +--- + +**Mission Type:** Implementation +**Priority:** Medium +**Phase:** On-Chain Registry diff --git a/missions/open/0103-phase1-core-engine-mvp.md b/missions/open/0103-phase1-core-engine-mvp.md new file mode 100644 index 0000000..a637008 --- /dev/null +++ b/missions/open/0103-phase1-core-engine-mvp.md @@ -0,0 +1,90 @@ +# Mission: Phase 1 - Core Engine MVP + +## Status +Completed + +## RFC +RFC-0103: Unified Vector-SQL Storage Engine + +## Implementation Location + +**Repository**: `stoolap` +**Branch**: `feat/blockchain-sql` +**Commit**: `8188059` + +## Claimant + +@claude-code + +## Acceptance Criteria + +- [x] Implement MVCC + Segment architecture for vectors +- [x] Implement three-layer verification (HNSW search, software float re-rank, Merkle proof) +- [x] Add vector ID + content hash for Merkle tree +- [x] Add basic statistics collection (row counts, null counts) +- [x] Implement in-memory storage backend +- [x] Complete WAL enum: IndexBuild, CompactionStart, CompactionFinish, SnapshotCommit +- [x] Pass test: MVCC + concurrent vector UPDATE/DELETE +- [x] Performance: <50ms query latency for simple queries + +## Description + +Build the core vector-SQL unified engine MVP. This is the foundation all other phases depend on. + +## Technical Details + +### Core Components Implemented + +``` +Segment Architecture: +├── Immutable segments (append-only) +├── Version tracking per segment +├── Segment merge with tombstone tracking +└── MVCC visibility at segment level + +Three-Layer Verification: +├── Layer 1: HNSW fast search (AVX/NEON) +├── Layer 2: Software float re-rank (top-K candidates) +└── Layer 3: Merkle proof generation + +Merkle Structure: +├── blake3(vector_id || blake3(embedding)) +├── Hierarchical: root → segment roots → vector hashes +└── Incremental updates on commit +``` + +### Key Files + +- `src/storage/vector/segment.rs` - Segment management (SoA layout) +- `src/storage/vector/mvcc.rs` - MVCC visibility with soft delete +- `src/storage/vector/merkle.rs` - Merkle tree with blake3 +- `src/storage/vector/search.rs` - Search with re-rank +- `src/storage/vector/wal.rs` - WAL with vector operations +- `src/storage/index/hnsw.rs` - HNSW index +- `benches/vector_search.rs` - Performance benchmarks + +### Testing + +- 1994 tests passing +- Vector-specific tests: 26 +- Benchmark results: + - 100 vectors: 30µs + - 1000 vectors: 153µs + - 5000 vectors: 834µs + +## Implementation Notes + +1. **WAL Integration**: Complete with 9 vector-specific operations +2. **Delete**: Soft delete via I64Set tombstones +3. **Merkle**: Full blake3 implementation for leaf and internal hashes +4. **Re-rank**: Layer 2 verification for exact distance + +## Pull Request + +Merged to `feat/blockchain-sql` (commit `8188059`) + +--- + +**Mission Type:** Implementation +**Priority:** Critical (Foundation for all other phases) +**Phase:** RFC-0103 Phase 1 diff --git a/missions/open/0103-phase2-persistence.md b/missions/open/0103-phase2-persistence.md new file mode 100644 index 0000000..b3de9a7 --- /dev/null +++ b/missions/open/0103-phase2-persistence.md @@ -0,0 +1,86 @@ +# Mission: Phase 2 - Persistence + +## Status +Completed + +## RFC +RFC-0103: Unified Vector-SQL Storage Engine + +## Blockers / Dependencies + +- **Blocked by:** Mission: Phase 1 - Core Engine MVP (must complete first) ✅ COMPLETE + +## Acceptance Criteria + +- [x] Implement memory-mapped storage backend +- [ ] Add RocksDB backend (optional, feature flag) +- [x] Integrate WAL for vector operations +- [x] Implement crash recovery from WAL +- [x] Add snapshot shipping for fast recovery +- [ ] MTTR: <5 minutes for typical workloads (<1M vectors) + +## Claimant + +@claude-code + +## Description + +Add persistence to the vector engine, enabling crash recovery and durable storage. + +## Technical Details + +### Persistence Architecture + +``` +Storage Backends: +├── In-Memory (Phase 1) +├── Memory-Mapped (Phase 2) +└── RocksDB (optional) + +Recovery: +├── Load last snapshot +├── Replay WAL entries +└── Rebuild dirty segments +``` + +### WAL Integration + +Vector operations must be WAL-logged: +- VectorInsert, VectorDelete, VectorUpdate +- SegmentCreate, SegmentMerge +- IndexBuild, CompactionStart/Finish +- SnapshotCommit + +### Snapshot Shipping + +``` +Recovery Options: +├── Full WAL replay (slow for large datasets) +└── Snapshot + delta WAL (fast recovery) + +Trigger: Every 100K vectors or 5 minutes +``` + +## Implementation Notes + +1. **MTTR SLA**: Target <5min recovery for <1M vectors +2. **WAL Rotation**: Aggressive 64MB rotation for vectors (not 256MB like SQL) +3. **Quantization for WAL**: Apply BQ before WAL to reduce bloat (768-dim → 96 bytes) + +## Research References + +- [RFC-0103: Unified Vector-SQL Storage Engine](../../rfcs/0103-unified-vector-sql-storage.md) + +## Claimant + + + +## Pull Request + +https://github.com/CipherOcto/stoolap/pull/new/feat/vector-phase2-persistence + +--- + +**Mission Type:** Implementation +**Priority:** High +**Phase:** RFC-0103 Phase 2 diff --git a/missions/open/0103-phase3-quantization.md b/missions/open/0103-phase3-quantization.md new file mode 100644 index 0000000..0431af1 --- /dev/null +++ b/missions/open/0103-phase3-quantization.md @@ -0,0 +1,86 @@ +# Mission: Phase 3 - Quantization + +## Status +Open + +## RFC +RFC-0103: Unified Vector-SQL Storage Engine + +## Blockers / Dependencies + +- **Blocked by:** Mission: Phase 1 - Core Engine MVP (must complete first) + +## Acceptance Criteria + +- [ ] Implement Scalar Quantization (SQ) +- [ ] Implement Product Quantization (PQ) +- [ ] Implement Binary Quantization (BQ) +- [ ] Add SQL syntax for quantization config +- [ ] Achieve 4-64x compression ratio +- [ ] Maintain >95% recall@10 at 15% tombstone threshold + +## Description + +Add vector quantization for memory efficiency and compression. + +## Technical Details + +### Quantization Types + +``` +Quantization Methods: +├── Scalar Quantization (SQ) +│ └── Map floats to integers (e.g., float32 → uint8) +├── Product Quantization (PQ) +│ └── Split vector into sub-vectors, quantize each +│ └── Configurable: 4, 8, 16 sub-vectors +└── Binary Quantization (BQ) + └── Map to binary (0/1) + └── 32x compression, fastest search +``` + +### SQL Syntax + +```sql +-- Create table with quantization +CREATE TABLE embeddings ( + id INTEGER PRIMARY KEY, + embedding VECTOR(768) QUANTIZE = PQ(8) +); + +-- Add quantization to existing index +CREATE INDEX idx_emb ON embeddings(embedding) +USING HNSW WITH (quantization = 'pq', pq_subvecs = 8); +``` + +### Compression Ratios + +| Type | Compression | Recall Impact | +|------|-------------|--------------| +| SQ | 4x | Low | +| PQ | 16-32x | Medium | +| BQ | 32-64x | Higher | + +## Implementation Notes + +1. **BQ First**: Binary Quantization is fastest and easiest - implement first +2. **Quality vs Size**: PQ offers best balance for most workloads +3. **Tombstone Impact**: Compaction at 15% soft, 30% hard limit per RFC + +## Research References + +- [RFC-0103: Unified Vector-SQL Storage Engine](../../rfcs/0103-unified-vector-sql-storage.md) + +## Claimant + + + +## Pull Request + + + +--- + +**Mission Type:** Implementation +**Priority:** High +**Phase:** RFC-0103 Phase 3 diff --git a/missions/open/0103-phase4-deterministic-verification.md b/missions/open/0103-phase4-deterministic-verification.md new file mode 100644 index 0000000..cb8e15b --- /dev/null +++ b/missions/open/0103-phase4-deterministic-verification.md @@ -0,0 +1,92 @@ +# Mission: Phase 4 - Deterministic Verification + +## Status +Open + +## RFC +RFC-0103: Unified Vector-SQL Storage Engine + +## Blockers / Dependencies + +- **Blocked by:** Mission: Phase 1 - Core Engine MVP (must complete first) + +## Acceptance Criteria + +- [ ] Implement software float re-ranking +- [ ] Implement incremental Merkle updates +- [ ] Add fast-proof mode (top-K sync) +- [ ] Pass test: Cross-architecture consistency (x86 vs ARM) +- [ ] Verify: <50ms P50 latency with 512 candidates re-rank + +## Description + +Add deterministic verification for cross-node consistency and blockchain integration. + +## Technical Details + +### Three-Layer Verification + +``` +Layer 1: Fast Search (non-deterministic) +├── HNSW + AVX/GPU +└── Returns top-K candidates + +Layer 2: Deterministic Re-rank (IEEE 754 exact) +├── Software float emulation +├── Re-rank expanded candidate set (4×K, max 512) +└── Reproducible across x86/ARM + +Layer 3: Blockchain Proof +├── Merkle inclusion of vector inputs +└── Full verification +``` + +### Software Float + +```rust +// Software float for determinism +// Isolated to verification path, NOT hot query path + +struct SoftwareFloat { + // Emulated f32 operations +} + +// Cost estimate: +// 512 candidates × 768 dimensions ≈ 393K ops +// ~1-5ms per query (single-threaded) +``` + +### Incremental Merkle + +``` +Naive: Recompute entire tree at commit +Incremental: Update only affected branch + +Performance: +// blake3: ~10M hashes/second +// <100ms for 1M vectors +``` + +## Implementation Notes + +1. **P1 Gate**: Benchmark software float at 512×768 before Phase 4 starts +2. **Isolation**: Software float runs on background thread, not hot path +3. **Expanded Candidates**: 4×K ensures different nodes produce identical top-K + +## Research References + +- [RFC-0103: Unified Vector-SQL Storage Engine](../../rfcs/0103-unified-vector-sql-storage.md) + +## Claimant + + + +## Pull Request + + + +--- + +**Mission Type:** Implementation +**Priority:** Medium +**Phase:** RFC-0103 Phase 4 diff --git a/missions/open/0103-phase5-hybrid-query-planner.md b/missions/open/0103-phase5-hybrid-query-planner.md new file mode 100644 index 0000000..8a03ce0 --- /dev/null +++ b/missions/open/0103-phase5-hybrid-query-planner.md @@ -0,0 +1,86 @@ +# Mission: Phase 5 - Hybrid Query Planner + +## Status +Open + +## RFC +RFC-0103: Unified Vector-SQL Storage Engine + +## Blockers / Dependencies + +- **Blocked by:** Mission: Phase 1 - Core Engine MVP (must complete first) + +## Acceptance Criteria + +- [ ] Implement cost-based planning (index-first vs filter-first) +- [ ] Implement statistics collection (selectivity, histograms) +- [ ] Integrate payload filters with vector search +- [ ] Pass test: Hybrid queries with various selectivities + +## Description + +Add intelligent query planning for hybrid SQL + vector queries. + +## Technical Details + +### Query Planning Strategies + +``` +Index-First: +1. Run vector search +2. Apply SQL filters to results +→ Best when vector selectivity is high + +Filter-First: +1. Apply SQL filters +2. Run vector search on filtered subset +→ Best when filter selectivity is low +``` + +### Statistics Collection + +``` +Required Statistics: +├── vector_norm_histogram: Distribution of vector magnitudes +├── payload_histograms: Value distributions per column +├── segment_sizes: Vectors per segment +├── index_density: HNSW connectivity density +└── tombstone_ratio: Deleted/total vectors + +Collection Strategy: +├── 1% random sample per segment (min 1000 vectors) +├── Update triggers: bulk inserts >10K, ANALYZE command, every 5 min +├── Staleness policy: Mark stale if >20% change +└── K-means (k=10) for clustered embeddings +``` + +### Selectivity Estimation + +``` +Challenge: Embedding distributions are often non-uniform +Solution: K-means to detect semantic clusters +``` + +## Implementation Notes + +1. **P1 Gate**: Statistics collection must be specified before Phase 5 +2. **Clustered Data**: Standard histograms may be unreliable - use k-means +3. **Plan Selection**: Choose index-first vs filter-first based on estimated selectivity + +## Research References + +- [RFC-0103: Unified Vector-SQL Storage Engine](../../rfcs/0103-unified-vector-sql-storage.md) + +## Claimant + + + +## Pull Request + + + +--- + +**Mission Type:** Implementation +**Priority:** Medium +**Phase:** RFC-0103 Phase 5 diff --git a/missions/open/0103-phase6-sparse-bm25.md b/missions/open/0103-phase6-sparse-bm25.md new file mode 100644 index 0000000..7ead08a --- /dev/null +++ b/missions/open/0103-phase6-sparse-bm25.md @@ -0,0 +1,104 @@ +# Mission: Phase 6 - Sparse Vectors / BM25 + +## Status +Open + +## RFC +RFC-0103: Unified Vector-SQL Storage Engine + +## Blockers / Dependencies + +- **Blocked by:** Mission: Phase 1 - Core Engine MVP (must complete first) + +## Acceptance Criteria + +- [ ] Copy lib/sparse to src/storage/sparse +- [ ] Add SPARSE index type +- [ ] Add BM25_MATCH SQL function +- [ ] Support hybrid search (dense + sparse + SQL filters) + +## Description + +Add sparse vector support and BM25 hybrid search. + +## Technical Details + +### Sparse Vectors + +``` +Sparse vs Dense: +├── Dense: Most values are non-zero (e.g., [0.1, 0.5, 0.8, ...]) +└── Sparse: Most values are zero (e.g., {"term1": 0.5, "term100": 0.3}) + +Storage: Only store non-zero values +Use cases: Text search, keyword matching +``` + +### BM25 + +``` +BM25 (Best Matching 25): +├── Ranking function for text search +├── Used by Elasticsearch, OpenSearch +└── Formula: score = sum IDF(qi) * (f(qi) * (k1 + 1)) / (f(qi) + k1 * (1 - b + b * dl/avdl)) + +Integration: +├── BM25_MATCH(table, column, query) -> score +└── Combine with vector search via UNION or JOIN +``` + +### SQL Syntax + +```sql +-- Create sparse index +CREATE TABLE documents ( + id INTEGER PRIMARY KEY, + content TEXT, + sparse_embedding SPARSE VECTOR +); + +CREATE INDEX idx_doc ON documents(sparse_embedding) USING SPARSE; + +-- BM25 search +SELECT id, content, BM25_MATCH(documents, content, 'search query') as score +FROM documents +ORDER BY score DESC +LIMIT 10; + +-- Hybrid: BM25 + vector +SELECT * FROM ( + SELECT id, content, score FROM ( + SELECT id, content, BM25_MATCH(documents, content, 'AI') as score + FROM documents WHERE category = 'tech' + ) bm25 + UNION ALL + SELECT id, content, VEC_DISTANCE_COSINE(embedding, $query) as score + FROM documents WHERE category = 'tech' +) combined +ORDER BY score DESC +LIMIT 10; +``` + +## Implementation Notes + +1. **lib/sparse**: Copy from existing library or implement new +2. **Hybrid Queries**: Combine with Phase 5 query planner +3. **Ranking Fusion**: BM25 + vector score combination strategies + +## Research References + +- [RFC-0103: Unified Vector-SQL Storage Engine](../../rfcs/0103-unified-vector-sql-storage.md) + +## Claimant + + + +## Pull Request + + + +--- + +**Mission Type:** Implementation +**Priority:** Medium +**Phase:** RFC-0103 Phase 6 diff --git a/missions/open/0103-phase7-gpu-support.md b/missions/open/0103-phase7-gpu-support.md new file mode 100644 index 0000000..dfd01c1 --- /dev/null +++ b/missions/open/0103-phase7-gpu-support.md @@ -0,0 +1,84 @@ +# Mission: Phase 7 - GPU Support (Future) + +## Status +Open + +## RFC +RFC-0103: Unified Vector-SQL Storage Engine + +## Blockers / Dependencies + +- **Blocked by:** Mission: Phase 1 - Core Engine MVP (must complete first) + +## Acceptance Criteria + +- [ ] Add GPU feature flag +- [ ] Implement GPU distance computation +- [ ] NOT: Full GPU graph traversal (initially) +- [ ] Performance: Verify GPU provides meaningful speedup over SIMD + +## Description + +Add GPU acceleration for vector distance computation. + +## Technical Details + +### GPU Scope + +``` +GPU Accelerated (Phase 7): +└── Distance computation (cosine, euclidean, dot product) + +NOT Accelerated: +└── HNSW graph traversal (memory-bound, limited GPU benefit) +``` + +### Implementation Approach + +``` +GPU Pipeline: +1. Upload query vector(s) to GPU +2. Download candidate vectors from HNSW +3. Compute distances in parallel on GPU +4. Return sorted results + +Initial Scope: +├── Distance calculation only +├── Batched queries +└── CUDA support (optional: ROCm) +``` + +### Feature Flag + +```rust +// GPU feature flag +#[cfg(feature = "gpu")] +mod gpu { + use cuda::prelude::*; + // GPU kernels +} +``` + +## Implementation Notes + +1. **SIMD First**: Prioritize SIMD optimization before GPU (better ROI) +2. **Memory-Bound**: HNSW traversal is memory-bound - limited GPU benefit +3. **Batching**: GPU excels with batched operations + +## Research References + +- [RFC-0103: Unified Vector-SQL Storage Engine](../../rfcs/0103-unified-vector-sql-storage.md) + +## Claimant + + + +## Pull Request + + + +--- + +**Mission Type:** Implementation +**Priority:** Future / Low +**Phase:** RFC-0103 Phase 7 diff --git a/missions/quota-market-integration.md b/missions/quota-market-integration.md new file mode 100644 index 0000000..fd4a260 --- /dev/null +++ b/missions/quota-market-integration.md @@ -0,0 +1,81 @@ +# Mission: Quota Market Integration + +## Status +Open + +## RFC +RFC-0100: AI Quota Marketplace Protocol +RFC-0101: Quota Router Agent Specification +RFC-0102: Wallet Cryptography Specification + +## Blockers / Dependencies + +- **Blocked by:** Mission: Quota Router MVE (must complete first) + +## Acceptance Criteria + +- [ ] Market client that queries available listings +- [ ] Automatic quota purchase when own quota exhausted +- [ ] Price discovery (lowest price first) +- [ ] Market price display +- [ ] Fallback when market unavailable + +## Description + +Enable the quota router to automatically purchase quota from the marketplace when the user's own quota is exhausted. + +## Technical Details + +### New CLI Commands + +```bash +# View market listings +quota-router market list + +# View market prices +quota-router market prices + +# Enable auto-purchase +quota-router market auto-enable --max-price 5 + +# Disable auto-purchase +quota-router market auto-disable +``` + +### Market Flow + +```mermaid +flowchart TD + A[User makes request] --> B{Check own quota OCTO-W balance} + B -->|Has quota| C[Use own provider] + B -->|No quota| D{Auto-purchase enabled?} + D -->|Yes| E[Query market listings] + D -->|No| F[Return error] + E --> G[Find cheapest that meets criteria] + G --> H[Purchase from market - spend OCTO-W] + H --> I[Route request through purchased quota] +``` + +## Dependencies + +- Mission: Quota Router MVE (must complete first) + +## Implementation Notes + +1. **Offline-first** - Works even if market unavailable +2. **Configurable** - User sets max price they'll pay +3. **Transparent** - User sees when market quota is used + +## Claimant + + + +## Pull Request + + + +--- + +**Mission Type:** Implementation +**Priority:** High +**Phase:** Market diff --git a/missions/quota-router-mve.md b/missions/quota-router-mve.md new file mode 100644 index 0000000..4e6f65a --- /dev/null +++ b/missions/quota-router-mve.md @@ -0,0 +1,105 @@ +# Mission: Quota Router CLI (MVE) + +## Status +Completed + +## RFC +RFC-0100: AI Quota Marketplace Protocol +RFC-0101: Quota Router Agent Specification +RFC-0102: Wallet Cryptography Specification + +## Acceptance Criteria + +- [x] CLI tool that can be installed via cargo +- [x] Local proxy server that intercepts API requests +- [x] API key management (secure local storage) +- [x] OCTO-W balance display +- [x] Basic routing to single provider +- [x] Balance check before each request +- [x] Manual quota listing command +- [x] Unit tests for core functionality + +## Description + +Build the Minimum Viable Edition of the Quota Router - a CLI tool developers run locally to manage their AI API quotas. + +## Technical Details + +### CLI Commands + +```bash +# Initialize router +quota-router init + +# Add provider API key +quota-router add-provider --name openai --key $OPENAI_KEY + +# Check balance +quota-router balance + +# List quota for sale +quota-router list --prompts 100 --price 1 + +# Start proxy server +quota-router proxy --port 8080 + +# Route test request +quota-router route --provider openai --prompt "Hello" +``` + +### Architecture + +``` +quota-router-cli/ +├── src/ +│ ├── main.rs # CLI entry point +│ ├── cli.rs # CLI commands +│ ├── proxy.rs # Local proxy server +│ ├── balance.rs # Balance management +│ ├── providers.rs # Provider integrations +│ ├── config.rs # Config loading/saving +│ └── commands.rs # Command handlers +├── Cargo.toml +└── docs/ + ├── README.md + ├── user-guide.md + └── api-reference.md +``` + +## Dependencies + +- Rust (latest stable) +- Cargo +- tokio (async runtime) +- hyper (HTTP server) +- clap (CLI) +- directories (config location) + +## Implementation Notes + +1. **Security First** - API keys from environment variables, never transmitted +2. **Simple First** - Single provider, manual listing only +3. **Testable** - Core functions must be unit testable + +## Claimant + +AI Agent (Claude) + +## Pull Request + + + +## Completion Criteria + +When complete, developers can: +1. Install the CLI +2. Configure their API keys securely +3. See their OCTO-W balance +4. Route a prompt through their own API key +5. List quota for sale manually + +--- + +**Mission Type:** Implementation +**Priority:** High +**Phase:** MVE diff --git a/missions/reputation-system.md b/missions/reputation-system.md new file mode 100644 index 0000000..e01a212 --- /dev/null +++ b/missions/reputation-system.md @@ -0,0 +1,141 @@ +# Mission: Reputation System + +## Status +Open + +## RFC +RFC-0100: AI Quota Marketplace Protocol +RFC-0101: Quota Router Agent Specification +RFC-0102: Wallet Cryptography Specification + +## Blockers / Dependencies + +- **Blocked by:** Mission: Token Swap Integration (should be in progress) +- **Blocked by:** Mission: Multi-Provider Support (should be in progress) + +## Acceptance Criteria + +- [ ] Provider reputation scores +- [ ] Seller reputation scores +- [ ] Reputation displayed in market listings +- [ ] Reputation affects routing priority +- [ ] Early contributor multiplier tracking +- [ ] Reputation history + +## Description + +Build a reputation system that tracks provider and seller reliability, enabling trust-based routing and rewarding early contributors. + +## Technical Details + +### Reputation Score + +```rust +struct Reputation { + wallet: Address, + role: ReputationRole, + + // Metrics + total_transactions: u64, + successful_transactions: u64, + failed_transactions: u64, + average_latency_ms: u64, + + // Calculated + score: u8, // 0-100 + tier: ReputationTier, + + // Early contributor + joined_at: DateTime, + multiplier: f64, +} + +enum ReputationRole { + Provider, + Seller, + Router, +} + +enum ReputationTier { + New, + Bronze, + Silver, + Gold, + Platinum, +} +``` + +### Reputation Tiers + +| Tier | Score | Multiplier | Requirements | +|------|-------|------------|--------------| +| **new** | 0-20 | 1x | < 10 transactions | +| **bronze** | 21-40 | 1.5x | 10+ transactions, >80% success | +| **silver** | 41-60 | 2x | 50+ transactions, >90% success | +| **gold** | 61-80 | 3x | 100+ transactions, >95% success | +| **platinum** | 81-100 | 5x | 500+ transactions, >99% success | + +### Early Contributor Multipliers + +| Cohort | Multiplier | Deadline | +|--------|------------|----------| +| First 100 | 10x | First 30 days | +| Next 400 | 5x | First 60 days | +| Next 1000 | 2x | First 90 days | + +### Reputation Commands + +```bash +# View own reputation +quota-router reputation show + +# View provider reputation +quota-router reputation provider --name openai + +# View seller reputation +quota-router reputation seller --wallet 0x... + +# View leaderboard +quota-router reputation leaderboard + +# Check multiplier status +quota-router reputation multiplier +``` + +### Reputation in Market + +``` +Listing displayed: +┌─────────────────────────────────────┐ +│ Provider: OpenAI │ +│ Price: 1 OCTO-W/prompt │ +│ Reputation: Gold (3x) │ +│ Success rate: 97% │ +│ Avg latency: 200ms │ +└─────────────────────────────────────┘ +``` + +## Dependencies + +- Mission: Token Swap Integration (should be in progress) +- Mission: Multi-Provider Support (should be in progress) + +## Implementation Notes + +1. **On-chain** - Reputation stored on blockchain for transparency +2. **Calculated** - Score derived from metrics, not manually set +3. **Historical** - Full history maintained + +## Claimant + + + +## Pull Request + + + +--- + +**Mission Type:** Implementation +**Priority:** Low +**Phase:** Reputation diff --git a/missions/stoolap-provider-integration.md b/missions/stoolap-provider-integration.md new file mode 100644 index 0000000..8cfc4ca --- /dev/null +++ b/missions/stoolap-provider-integration.md @@ -0,0 +1,105 @@ +# Mission: Stoolap Provider Integration + +## Status +Open + +## RFC +RFC-0100: AI Quota Marketplace Protocol +RFC-0101: Quota Router Agent Specification + +## Blockers / Dependencies + +- **Blocked by:** Mission: Multi-Provider Support (must complete first) + +## Acceptance Criteria + +- [ ] Stoolap provider type added to router +- [ ] Stoolap node connection/config +- [ ] Submit execution proof after prompt completion +- [ ] Verify proof before payment release +- [ ] Display proof status in balance + +## Description + +Integrate Stoolap blockchain SQL database as a provider type in the quota router, enabling cryptographic proof of execution. + +## Technical Details + +### Stoolap Provider + +```rust +struct StoolapProvider { + name: &'static str, // "stoolap" + endpoint: String, + chain_id: String, +} + +impl StoolapProvider { + // Submit execution proof + async fn submit_proof(&self, execution: Execution) -> Result; + + // Verify proof before payment + async fn verify_proof(&self, proof: &Proof) -> Result; +} +``` + +### Proof Flow + +```mermaid +sequenceDiagram + participant B as Buyer + participant S as Stoolap Provider + participant P as Stoolap Chain + + B->>S: Send prompt request + S->>P: Submit execution transaction + P-->>S: Return HexaryProof + S-->>B: Return response + Proof + B->>B: Verify proof independently +``` + +### CLI Commands + +```bash +# Add Stoolap provider +quota-router provider add --type stoolap --endpoint https://stoolap.example.com + +# Enable proof verification +quota-router provider stoolap verify-proofs enable + +# View proof history +quota-router provider stoolap proofs +``` + +## Integration Points + +| Component | Change | +|-----------|--------| +| RFC-0101 | Add StoolapProvider to provider types | +| RFC-0101 | Add verifyProof() to unified schema | + +## Implementation Notes + +1. **Optional first** - Stoolap verification is opt-in +2. **Fallback** - If proof fails, use reputation-based resolution +3. **Async** - Proof generation can be async, don't block response + +## Research References + +- [Stoolap vs LuminAIR Comparison](../docs/research/stoolap-luminair-comparison.md) +- [STWO GPU Acceleration](../docs/research/stwo-gpu-acceleration.md) +- [Privacy-Preserving Query Routing](../docs/use-cases/privacy-preserving-query-routing.md) + +## Claimant + + + +## Pull Request + + + +--- + +**Mission Type:** Implementation +**Priority:** Medium +**Phase:** Stoolap Integration diff --git a/missions/token-swap-integration.md b/missions/token-swap-integration.md new file mode 100644 index 0000000..71684cd --- /dev/null +++ b/missions/token-swap-integration.md @@ -0,0 +1,95 @@ +# Mission: Token Swap Integration + +## Status +Open + +## RFC +RFC-0100: AI Quota Marketplace Protocol +RFC-0101: Quota Router Agent Specification +RFC-0102: Wallet Cryptography Specification + +## Blockers / Dependencies + +- **Blocked by:** Mission: Quota Router MVE (must complete first) +- **Recommended:** Mission: Quota Market Integration (can run in parallel) + +## Acceptance Criteria + +- [ ] OCTO-W ↔ OCTO-D swap at market rate +- [ ] OCTO ↔ OCTO-W swap at market rate +- [ ] OCTO ↔ OCTO-D swap at market rate +- [ ] Auto-swap when balance low (configurable) +- [ ] Manual swap commands +- [ ] Display current rates + +## Description + +Enable automatic and manual token swaps to ensure developers can always get OCTO-W when they need quota. + +## Technical Details + +### Swap Commands + +```bash +# Check rates +quota-router swap rates + +# Swap OCTO-D to OCTO-W +quota-router swap d-to-w --amount 100 + +# Swap OCTO to OCTO-W +quota-router swap o-to-w --amount 50 + +# Enable auto-swap (when balance < 10, swap 100 OCTO-D) +quota-router swap auto-enable --threshold 10 --amount 100 --from OCTO-D + +# Disable auto-swap +quota-router swap auto-disable + +# Check swap history +quota-router swap history +``` + +### Swap Flow + +```mermaid +flowchart TD + A[User enables auto-swap] --> B[Router monitors OCTO-W balance] + B --> C{Balance below threshold?} + C -->|No| B + C -->|Yes| D[Check auto-swap config] + D --> E[Execute swap OCTO-D to OCTO-W] + E --> F[Update balance] + F --> B +``` + +### Exchange Rates + +Rates are fetched from decentralized exchange or oracle: +- Market-based (not fixed) +- Updated on each swap +- Displayed before confirmation + +## Dependencies + +- Mission: Quota Router MVE (must complete first) + +## Implementation Notes + +1. **Reversible** - User can swap back any time +2. **Confirmed** - Show rate before executing +3. **History** - Keep log of all swaps + +## Claimant + + + +## Pull Request + + + +--- + +**Mission Type:** Implementation +**Priority:** High +**Phase:** Swaps diff --git a/missions/zk-proof-verification.md b/missions/zk-proof-verification.md new file mode 100644 index 0000000..f0ce022 --- /dev/null +++ b/missions/zk-proof-verification.md @@ -0,0 +1,123 @@ +# Mission: ZK Proof Verification System + +## Status +Open + +## RFC +RFC-0100: AI Quota Marketplace Protocol +RFC-0102: Wallet Cryptography Specification + +## Blockers / Dependencies + +- **Blocked by:** Mission: Stoolap Provider Integration (must complete first) + +## Acceptance Criteria + +- [ ] Integrate STWO verifier for STARK proofs +- [ ] Batch multiple proofs into single verification +- [ ] On-chain proof submission to Stoolap +- [ ] Verify proofs before releasing payment +- [ ] Display verification status +- [ ] GPU-accelerated proof generation (optional optimization) + +## Description + +Enable ZK proof-based verification for marketplace transactions using Stoolap's STARK proving system. + +## Technical Details + +### Proof Types (from Stoolap) + +| Proof Type | Use Case | Verification | Size | +|-----------|-----------|---------------|------| +| HexaryProof | Individual execution | ~2-3 μs | ~68 bytes | +| StarkProof | Batch verification | ~15 ms | 100-500 KB | +| CompressedProof | Multiple batches | ~100ms | ~10 KB | + +### Stoolap Integration + +```mermaid +flowchart TD + subgraph STOOLAP["Stoolap ZK Stack"] + SQL[SQL Query] --> HEX[HexaryProof] + HEX --> BATCH[Batch] + BATCH --> STARK[STARK Proof
via stwo-cairo-prover] + end + + subgraph CIPHER["CipherOcto Integration"] + REQ[Request] --> VERIFY[Verify Proof] + VERIFY --> PAY[Release OCTO-W] + end + + STOOLAP -->|verify| CIPHER +``` + +### GPU Acceleration (Optional) + +For production, consider GPU-accelerated STWO: + +| Implementation | Speedup | Notes | +|---------------|---------|-------| +| NitrooZK-stwo | 22x-355x | Cairo AIR support | +| ICICLE-Stwo | 3x-7x | Drop-in backend | +| stwo-gpu | ~193% | Multi-GPU scaling | + +See: `docs/research/stwo-gpu-acceleration.md` + +### Verification Flow + +```mermaid +sequenceDiagram + participant B as Buyer + participant S as Seller + participant P as Stoolap + + B->>S: Request prompt execution + S->>P: Submit transaction + P-->>S: Return proofs + S-->>B: Response + proofs + B->>P: Verify proofs + P-->>B: Verified / Failed + B->>S: Release payment (if verified) +``` + +### CLI Commands + +```bash +# Verify a proof +quota-router verify --proof + +# Batch verify multiple proofs +quota-router verify --batch + +# View verification history +quota-router verify history +``` + +## Implementation Notes + +1. **Async verification** - Don't block response, verify in background +2. **Batch for cost** - Combine multiple verifications +3. **Caching** - Cache verified proofs to avoid re-verification +4. **GPU acceleration** - Consider NitrooZK-stwo for production (22x-355x speedup) + +## Research References + +- [Stoolap vs LuminAIR Comparison](../docs/research/stoolap-luminair-comparison.md) +- [STWO GPU Acceleration](../docs/research/stwo-gpu-acceleration.md) +- [Privacy-Preserving Query Routing](../docs/use-cases/privacy-preserving-query-routing.md) +- [Provable QoS](../docs/use-cases/provable-quality-of-service.md) + +## Claimant + + + +## Pull Request + + + +--- + +**Mission Type:** Implementation +**Priority:** Medium +**Phase:** ZK Proofs diff --git a/rfcs/0100-ai-quota-marketplace.md b/rfcs/0100-ai-quota-marketplace.md new file mode 100644 index 0000000..09d561a --- /dev/null +++ b/rfcs/0100-ai-quota-marketplace.md @@ -0,0 +1,301 @@ +# RFC-0100: AI Quota Marketplace Protocol + +## Status +Draft + +## Summary + +Define the protocol for trading AI API quotas between developers using OCTO-W tokens as both currency and authorization grant. + +## Motivation + +Enable developers to: +- Contribute spare AI API quota to the network +- Earn OCTO-W tokens for contributed quota +- Purchase quota from other developers when needed +- Swap OCTO-W for other tokens (OCTO-D, OCTO) + +This creates immediate utility for OCTO-W and bootstraps the developer network. + +## Specification + +### Core Concepts + +```typescript +// Quota listing +interface QuotaListing { + id: string; + provider: 'openai' | 'anthropic' | 'google' | 'other'; + prompts_remaining: number; + price_per_prompt: number; // in OCTO-W + seller_wallet: string; + status: 'active' | 'exhausted' | 'cancelled'; +} + +// Quota purchase +interface QuotaPurchase { + listing_id: string; + buyer_wallet: string; + prompts_requested: number; + total_cost: OCTO-W; + timestamp: number; +} + +// Token balance +interface QuotaRouter { + wallet: string; + octo_w_balance: OCTO-W; + api_key: string; // encrypted, never transmitted + proxy_port: number; + status: 'online' | 'offline'; +} +``` + +### Token Economics + +| Action | Token | +|--------|-------| +| Contribute 1 prompt | +1 OCTO-W | +| Purchase 1 prompt | -1 OCTO-W | +| Minimum listing | 10 prompts | + +### Routing Protocol + +```typescript +interface RouterConfig { + // Policy + max_price_per_prompt: OCTO-W; + preferred_providers: string[]; + fallback_enabled: boolean; + fallback_timeout_ms: number; + + // Security + require_minimum_balance: OCTO-W; + auto_recharge_enabled: boolean; + auto_recharge_source: 'wallet' | 'swap'; +} +``` + +### Market Operations + +```typescript +// List quota for sale +async function listQuota( + prompts: number, + pricePerPrompt: OCTO-W +): Promise; + +// Purchase quota +async function purchaseQuota( + listingId: string, + prompts: number +): Promise; + +// Route prompt through network +async function routePrompt( + prompt: string, + config: RouterConfig +): Promise; +``` + +## Implementation + +*Implementation phases have been moved to the Roadmap and Mission files.* + +See: `missions/quota-router-mve.md`, `missions/quota-market-integration.md` + +## Settlement Model + +### Registry Decision + +| Option | Pros | Cons | Recommendation | +|--------|------|------|----------------| +| **Off-chain** | Fast, cheap | Less trust | MVE - start here | +| **On-chain** | Trustless, verifiable | Expensive, slow | Phase 2 | + +### Escrow Flow + +``` +1. Buyer initiates purchase + │ + ▼ +2. OCTO-W held in escrow (protocol contract) + │ + ▼ +3. Seller executes prompt via their proxy + │ + ▼ +4. Success? + │ + ├─ YES → Release OCTO-W to seller + │ + └─ NO → Refund to buyer, slash seller stake +``` + +### Dispute Resolution + +```typescript +enum DisputeOutcome { + Valid, // Refund buyer, slash seller + Invalid, // Keep payment, no action + Partial, // Partial refund +} + +interface Dispute { + id: string; + buyer: string; + seller: string; + listing_id: string; + reason: 'failed_response' | 'garbage_data' | 'timeout'; + evidence: string; // URL or hash + timestamp: number; +} + +// Resolution: Governance vote or automated arbitration +``` + +### Dispute Evidence Challenge + +**Issue:** Prompts are private, but buyer needs to prove "garbage response" without revealing prompt content. + +**MVE Solution:** Heavily weight automated failures: + +| Dispute Type | Evidence | Verifiability | +|-------------|----------|---------------| +| **Timeout** | Network logs, timestamps | Automatic | +| **Provider error** | Provider error codes | Automatic | +| **Latency high** | Latency measurements | Automatic | +| **Garbage response** | Requires human review | Manual | +| **Failed response** | HTTP status codes | Automatic | + +**For MVE:** Focus disputes on automated verifications (timeouts, errors, latency). Response quality disputes require trust (reputation-based) until cryptographic solutions emerge. + +**Future:** ZK proofs of inference quality (research phase). + +### Slashing Model + +```typescript +interface SlashingRules { + // First offense: 10% of stake + first_offense_penalty: 0.10; + + // Escalation per offense + offense_multiplier: 1.5; + + // Permanent ban threshold + permanent_ban_at: 0.50; // 50% of stake lost +} +``` + +## Security + +| Mechanism | Purpose | +|----------|---------| +| Local proxy only | API keys never leave machine | +| Balance check first | Prevent overspending | +| Stake requirement | Prevent spam/abuse | +| Reputation system | Build trust | + +## Related Use Cases + +- [AI Quota Marketplace for Developer Bootstrapping](../../docs/use-cases/ai-quota-marketplace.md) + +## State Machines + +### Listing Lifecycle + +```mermaid +stateDiagram-v2 + [*] --> CREATED: Seller creates listing + CREATED --> ACTIVE: Listed + ACTIVE --> EXHAUSTED: All prompts sold + ACTIVE --> CANCELLED: Seller cancels + EXHAUSTED --> [*] + CANCELLED --> [*] +``` + +### Purchase Lifecycle + +```mermaid +stateDiagram-v2 + [*] --> INITIATED: Buyer selects listing + INITIATED --> ESCROWED: OCTO-W held in protocol + ESCROWED --> COMPLETED: Success - release to seller + ESCROWED --> DISPUTED: Buyer raises dispute + COMPLETED --> [*] + DISPUTED --> REFUNDED: Valid dispute + DISPUTED --> CONFIRMED: Invalid dispute + REFUNDED --> [*] + CONFIRMED --> [*] +``` + +### Dispute Lifecycle + +```mermaid +stateDiagram-v2 + [*] --> FILED: Buyer raises dispute + FILED --> INVESTIGATING: Evidence collected + INVESTIGATING --> VALID: Governance rules valid + INVESTIGATING --> INVALID: No grounds + INVESTIGATING --> PARTIAL: Partial refund + VALID --> SLASHED: Seller penalized + INVALID --> KEEP: Payment confirmed + PARTIAL --> PARTIAL_REFUND: Partial refund + SLASHED --> [*] + KEEP --> [*] + PARTIAL_REFUND --> [*] +``` + +## Observability + +The marketplace must support logging without exposing sensitive data: + +```typescript +interface MarketTelemetry { + // What we log (no PII) + event: 'purchase' | 'listing' | 'swap' | 'dispute'; + timestamp: number; + provider: string; + octo_w_amount: number; + latency_ms: number; + success: boolean; + + // What we DON'T log + // - Prompt content + // - API keys + // - Wallet addresses (use hash instead) +} +``` + +## Security & Privacy + +| Concern | Mitigation | +|---------|------------| +| API key exposure | Local proxy only, keys never transmitted | +| Prompt privacy | ⚠️ **TRUST ASSUMPTION** - Sellers see prompt content when executing API calls | +| Wallet privacy | Pseudonymous addresses | +| Data residency | No central storage | + +**Important:** Prompt content is visible to the seller who executes the API request. +This is a trust-based model, not cryptographic. See Research doc for future options (TEE/ZK). + +## Related RFCs + +- RFC-0101: Quota Router Agent Specification +- RFC-XXXX: Token Swap Protocol (future) +- RFC-XXXX: Reputation System (future) + +## References + +- Parent Document: docs/use-cases/ai-quota-marketplace.md +- Research: docs/research/ai-quota-marketplace-research.md + +## Open Questions + +1. On-chain vs off-chain listing registry? +2. Minimum stake for sellers? +3. How to handle failed requests (refund OCTO-W)? + +--- + +**Draft Date:** 2026-03-02 diff --git a/rfcs/0101-quota-router-agent.md b/rfcs/0101-quota-router-agent.md new file mode 100644 index 0000000..cc17856 --- /dev/null +++ b/rfcs/0101-quota-router-agent.md @@ -0,0 +1,393 @@ +# RFC-0101: Quota Router Agent Specification + +## Status +Draft + +## Summary + +Define the agent-based quota router that handles prompt routing based on user policy, OCTO-W balance, and market availability. + +## Motivation + +Create a customizable routing system where: +- Developers can define their own policies +- Routing behavior is agent-driven +- Security is maintained (keys never leave machine) +- Multiple strategies can be employed + +## Specification + +### Agent Architecture + +```typescript +interface QuotaRouterAgent { + // Identity + agent_id: string; + owner_wallet: string; + + // Configuration + config: RouterConfig; + + // State + balance: OCTO-W; + status: AgentStatus; + + // Capabilities + providers: Provider[]; +} +``` + +### Router Policies + +```typescript +type RoutingPolicy = + | 'cheapest' + | 'fastest' + | 'quality' + | 'balanced' + | 'custom'; + +interface RouterConfig { + // Policy selection + policy: RoutingPolicy; + + // Price limits + max_price_per_prompt: OCTO-W; + monthly_budget: OCTO-W; + + // Provider preferences + preferred_providers: string[]; + fallback_order: string[]; + + // Auto-recharge + auto_recharge_enabled: boolean; + auto_recharge_threshold: OCTO-W; + recharge_source: 'wallet' | 'swap-osto-d' | 'swap-octo'; + + // Fallback + allow_market_purchase: boolean; + market_max_price: OCTO-W; +} +``` + +### Policy Behaviors + +| Policy | Behavior | +|--------|----------| +| **cheapest** | Route to cheapest available provider | +| **fastest** | Route to fastest responding provider | +| **quality** | Prefer higher-quality models | +| **balanced** | Mix of price/speed/quality | +| **custom** | User-defined rules | + +### Request Flow + +```mermaid +flowchart TD + A[User calls agent.routePrompt] --> B{Check OCTO-W balance} + B -->|Enough| C[Check policy] + B -->|Not enough| D{Check auto-recharge} + C --> E[Find provider] + D -->|Enabled| F[Attempt recharge] + D -->|Disabled| G[Return error] + E --> H[Route request] + F -->|Success| H + F -->|Failed| G + H --> I[Return result] +``` + +### Provider Integration + +```typescript +interface Provider { + name: string; + api_type: 'openai' | 'anthropic' | 'google' | 'custom'; + + // Connection + endpoint: string; + auth_method: 'bearer' | 'api-key'; + + // State + status: 'available' | 'rate-limited' | 'error'; + + // Metrics + latency_ms: number; + success_rate: number; +} +``` + +### Local Security + +```typescript +// API keys stored locally, encrypted +interface SecureKeyStore { + // Keys never transmitted + store(provider: string, encryptedKey: Buffer): void; + + // Only gives access, not the key + createProviderAccess(provider: string): ProviderAccess; + + // Keys never leave this machine +} + +// Request routing - key used locally only +async function routeWithKey( + provider: Provider, + prompt: string, + key: SecureKeyRef +): Promise; +``` + +### Market Integration + +```typescript +interface MarketClient { + // Query available quota + async findListings( + provider: string, + minPrompts: number, + maxPrice: OCTO-W + ): Promise; + + // Purchase from market + async purchaseFromMarket( + listingId: string, + prompts: number + ): Promise; + + // Get current prices + async getMarketPrices(): Promise; +} +``` + +### Token Swaps + +```typescript +interface SwapClient { + // Swap tokens + async swap( + fromToken: 'OCTO-W' | 'OCTO-D' | 'OCTO', + toToken: 'OCTO-W' | 'OCTO-D' | 'OCTO', + amount: bigint + ): Promise; + + // Get exchange rate + async getRate( + fromToken: string, + toToken: string + ): Promise; +} +``` + +## Agent Communication Protocol + +The router agent exposes an OpenAI-compatible local API: + +```typescript +// Local proxy endpoint (OpenAI-compatible) +POST http://localhost:11434/v1/chat/completions +Authorization: Bearer local-only + +{ + "model": "gpt-4", + "messages": [{"role": "user", "content": "Hello"}] +} +``` + +This allows existing applications to route through the quota router without code changes. + +### Communication Methods + +| Method | Protocol | Use Case | +|--------|----------|----------| +| **Local proxy** | HTTP (OpenAI-compatible) | Primary - existing apps | +| **CLI** | Command line | Manual control | +| **IPC** | Unix socket | Advanced integrations | + +## Fallback & Retry Logic + +```typescript +interface RetryConfig { + max_retries: number; + retry_delay_ms: number; + backoff_multiplier: number; + max_backoff_ms: number; +} +``` + +### Fallback Chain + +1. Try own provider (if OCTO-W balance available) +2. Try market quota (if auto-purchase enabled) +3. Try swap (if auto-swap enabled and threshold reached) +4. Return error (no options remaining) + +## Unified Provider Schema + +All providers expose a common interface: + +```typescript +interface UnifiedProvider { + name: string; + endpoint: string; + complete(prompt: UnifiedPrompt): Promise; + getBalance(): Promise; + healthCheck(): Promise; +} + +interface UnifiedPrompt { + model: string; + messages: Message[]; + temperature?: number; + max_tokens?: number; +} + +interface UnifiedResponse { + content: string; + usage: { prompt: number; completion: number; total: number }; + latency_ms: number; +} +``` + +--- + +## Cost Normalization + +The router must normalize costs across different providers: + +```typescript +// Model weights (compute units per request) +const MODEL_WEIGHTS = { + 'gpt-4': 10, + 'gpt-3.5-turbo': 1, + 'claude-3-opus': 12, + 'claude-3-haiku': 1, + 'gemini-pro': 2, + // Local models: varies by hardware +}; + +// Context window limits (max tokens) +const MODEL_LIMITS = { + 'gpt-4': 8192, + 'gpt-3.5-turbo': 16385, + 'claude-3-opus': 200000, + 'claude-3-haiku': 200000, + 'gemini-pro': 32768, +}; + +// Calculate OCTO-W cost +function calculateCost(model: string, inputTokens: number, outputTokens: number): number { + const baseWeight = MODEL_WEIGHTS[model] || 1; + const tokenFactor = (inputTokens + outputTokens) / 1000; + return Math.ceil(baseWeight * tokenFactor); +} + +// Validate context window before routing +function validateContext(model: string, inputTokens: number): boolean { + const limit = MODEL_LIMITS[model]; + return limit ? inputTokens <= limit : false; +} +``` + +### Context Window Handling + +**Issue:** User sends 100k-token prompt to model with 8k limit. + +**Solution:** Fail fast before spending OCTO-W: + +```typescript +async function routeWithValidation( + prompt: UnifiedPrompt +): Promise { + const tokenCount = countTokens(prompt); + + // Check context window first + if (!validateContext(prompt.model, tokenCount)) { + throw new RouterError( + `Prompt exceeds ${prompt.model} context limit of ${MODEL_LIMITS[prompt.model]} tokens` + ); + } + + // Only spend OCTO-W after validation + const cost = calculateCost(prompt); + await reserveBalance(cost); + + return await routePrompt(prompt); +} +``` + +*See Research doc for complete cost normalization specification.* + +### Concurrency Handling + +**Issue:** Agent has 10 OCTO-W, sends 5 concurrent requests costing 3 OCTO-W each. + +**Solution:** Local mutex / atomic balance lock: + +```typescript +class AtomicBalance { + private balance: number; + private mutex: Mutex; + + async reserve(amount: number): Promise { + return this.mutex.runExclusive(async () => { + if (this.balance >= amount) { + this.balance -= amount; + return true; + } + return false; + }); + } + + async release(amount: number): void { + this.balance += amount; + } +} +``` + +**Flow:** +1. Acquire mutex +2. Check balance (atomic) +3. Reserve if sufficient +4. Release mutex +5. Execute request +6. On success: burn OCTO-W +7. On failure: release back to balance + +## Rationale + +### Why Agent-Based? + +1. **Customizable** - Each developer can define their own policy +2. **Portable** - Agent moves with the developer +3. **Flexible** - New policies can be added easily +4. **Decentralized** - No central router, peer-to-peer + +### Why Local Key Storage? + +1. **Security** - API keys never transmitted +2. **Trust** - No third-party holds credentials +3. **Simplicity** - No key management infrastructure + +## Related Use Cases + +- [AI Quota Marketplace for Developer Bootstrapping](../../docs/use-cases/ai-quota-marketplace.md) + +## Related RFCs + +- RFC-0100: AI Quota Marketplace Protocol + +## References + +- Parent Document: docs/use-cases/ai-quota-marketplace.md +- Research: docs/research/ai-quota-marketplace-research.md + +## Open Questions + +1. Default policy for new users? +2. How to handle provider outages mid-request? +3. Maximum number of providers per agent? + +--- + +**Draft Date:** 2026-03-02 diff --git a/rfcs/0102-wallet-cryptography.md b/rfcs/0102-wallet-cryptography.md new file mode 100644 index 0000000..78ffe33 --- /dev/null +++ b/rfcs/0102-wallet-cryptography.md @@ -0,0 +1,513 @@ +# RFC-0102: Wallet Cryptography Specification + +## Status +Draft + +## Summary + +Defines cryptographic primitives for the CipherOcto wallet system, including key management, signature schemes, account models, and secure storage - all compatible with the Starknet/Cairo ecosystem used by Stoolap for ZK proofs. + +## Motivation + +### Problem Statement + +The Quota Router MVE requires a secure wallet implementation to handle OCTO-W, OCTO-D, and OCTO token transactions. Current research establishes the need for cryptographic foundations, but we need a concrete specification before implementation. + +### Current State + +- Research complete: `docs/research/wallet-technology-research.md` +- Starknet compatibility identified as primary requirement +- Key components: starknet-rs for signing, custom key storage + +### Desired State + +A complete specification defining: +- Key types and derivation paths +- Transaction signing workflow +- Local key storage format +- Account abstraction interface +- Error handling patterns + +### Use Case Link +- [AI Quota Marketplace](../docs/use-cases/ai-quota-marketplace.md) + +## Specification + +### Data Structures + +```rust +/// Entropy source for key generation +use rand::rngs::OsRng; +use rand::RngCore; + +/// Starknet FieldElement (32 bytes) +type FieldElement = [u8; 32]; + +/// Starknet signature component +type Signature = (FieldElement, FieldElement); + +/// Wallet key pair +struct KeyPair { + private_key: FieldElement, + public_key: FieldElement, +} + +/// Account address (contract orEOA) +type Address = FieldElement; + +/// Token type in the OCTO ecosystem +#[derive(Clone, Copy, Debug)] +enum Token { + +/// Key generation from OS entropy +fn generate_keypair() -> KeyPair { + let mut private_key = FieldElement::default(); + OsRng.fill_bytes(&mut private_key); + + // Ensure key is valid (non-zero, within curve order) + while private_key == [0u8; 32] || is_on_curve(&private_key) == false { + OsRng.fill_bytes(&mut private_key); + } + + let public_key = private_to_public_key(private_key); + KeyPair { private_key, public_key } +} + OCTO, // Governance token + OCTO_W, // Wrapped quota (1 token = 1 prompt) + OCTO_D, // Contributor reward token +} + +/// Transaction nonce for replay protection +struct Nonce(u64); + +/// Chain identifier +struct ChainId(FieldElement); +``` + +### Transaction Types + +```rust +/// Token transfer transaction +struct Transfer { + sender: Address, + receiver: Address, + token: Token, + amount: u64, + nonce: Nonce, + chain_id: ChainId, + fee: u64, +} + +/// Execute multiple calls atomically +struct Execute { + calls: Vec, + nonce: Nonce, + chain_id: ChainId, +} + +/// Single contract call +struct Call { + to: Address, + selector: FieldElement, + calldata: Vec, +} +``` + +### Key Derivation + +```rust +/// BIP-32 style derivation trait +trait KeyDerivation { + /// Derive a child key from parent key and index + fn derive(&self, seed: &FieldElement, index: u32) -> FieldElement; +} + +/// Starknet-specific derivation (non-BIP-44) +struct StarknetKeyDerivation { + /// HMAC-SHA256 based, different from Ethereum due to curve + path_prefix: [u32; 4], +} + +/// Mnemonic-based recovery (BIP-39 adapted for Starknet) +/// Uses 12-word mnemonic → seed → Starknet key +struct MnemonicRecovery; + +impl MnemonicRecovery { + /// Generate new 12-word mnemonic + fn generate() -> String { + // Use 128 bits of entropy = 12 words + let entropy = generate_entropy(128); + mnemonic_from_entropy(&entropy) + } + + /// Derive key from mnemonic + optional passphrase + fn derive_key(mnemonic: &str, passphrase: &str) -> FieldElement { + // BIP-39: mnemonic + passphrase → seed + let seed = bip39_seed(mnemonic, passphrase); + + // Derive Starknet key from seed (simplified) + // In production: BIP-32 derivation with custom path + let mut key = [0u8; 32]; + key.copy_from_slice(&seed[..32]); + FieldElement::from_slice(&key) + } + + /// Restore wallet from existing mnemonic + fn restore(mnemonic: &str) -> KeyPair { + let private_key = Self::derive_key(mnemonic, ""); + let public_key = private_to_public_key(private_key); + KeyPair { private_key, public_key } + } +} + +impl KeyDerivation for StarknetKeyDerivation { + fn derive(&self, seed: &FieldElement, index: u32) -> FieldElement { + // Derivation uses different path format than Ethereum + // m/44'/60'/0'/0/0 is Ethereum, Starknet uses sequential + let mut data = seed.to_vec(); + data.extend_from_slice(&index.to_be_bytes()); + hmac_sha256(self.path_prefix.as_bytes(), &data) + } +} +``` + +### Key Storage + +```rust +use aes_gcm::{aead::{Aead, KeyInit}, Aes256Gcm}; + +/// Encrypted key file format +struct EncryptedKeyFile { + /// Salt for PBKDF2 (16 bytes) + salt: [u8; 16], + /// AES-256-GCM encrypted private key + ciphertext: Vec, + /// Initialization vector (12 bytes) + nonce: [u8; 12], + /// Authentication tag (16 bytes) + tag: [u8; 16], +} + +/// Key storage configuration +struct KeyStoreConfig { + /// PBKDF2 iterations (minimum 100,000) + pbkdf2_iterations: u32 = 100_000, + /// Key file path + path: PathBuf, +} + +impl KeyStoreConfig { + /// Encrypt private key with password + fn encrypt(&self, private_key: &FieldElement, password: &str) -> EncryptedKeyFile { + // 1. Generate random salt (16 bytes) + let salt = random::<[u8; 16]>(); + + // 2. Derive key from password: PBKDF2(salt, password, 100k) + let mut key = [0u8; 32]; + pbkdf2::(password.as_bytes(), &salt, 100_000, &mut key); + + // 3. Encrypt with AES-256-GCM + let cipher = Aes256Gcm::new_from_slice(&key).unwrap(); + let nonce = random::<[u8; 12]>(); + let ciphertext = cipher.encrypt(&nonce.into(), private_key.as_slice()).unwrap(); + + // Split ciphertext into body + tag (last 16 bytes) + let (ciphertext, tag) = ciphertext.split_at(ciphertext.len() - 16); + let tag: [u8; 16] = tag.try_into().unwrap(); + + EncryptedKeyFile { salt, ciphertext: ciphertext.to_vec(), nonce, tag } + } + + /// Decrypt private key with password + fn decrypt(&self, ekf: &EncryptedKeyFile, password: &str) -> FieldElement { + let mut key = [0u8; 32]; + pbkdf2::(password.as_bytes(), &ekf.salt, 100_000, &mut key); + + let cipher = Aes256Gcm::new_from_slice(&key).unwrap(); + + // Reconstruct ciphertext + tag + let mut combined = ekf.ciphertext.clone(); + combined.extend_from_slice(&ekf.tag); + + let plaintext = cipher.decrypt(&ekf.nonce.into(), combined.as_ref()).unwrap(); + + let mut fe = [0u8; 32]; + fe.copy_from_slice(&plaintext); + fe + } +} +``` + +### Signing Interface + +```rust +use starknet::core::crypto::{sign, verify}; + +/// Signer trait for wallet operations +trait Signer { + /// Sign a transaction + fn sign_transaction(&self, tx: &Transfer) -> Signature; + + /// Sign an off-chain message + fn sign_message(&self, message: &[u8]) -> Signature; + + /// Get wallet address + fn address(&self) -> Address; +} + +/// Starknet ECDSA signer +struct StarknetSigner { + private_key: FieldElement, + public_key: FieldElement, + address: Address, +} + +impl Signer for StarknetSigner { + fn sign_transaction(&self, tx: &Transfer) -> Signature { + let hash = tx.hash(); + sign(self.private_key, hash) + } + + fn sign_message(&self, message: &[u8]) -> Signature { + // Starknet signed message prefix + let prefixed = format!("\x19StarkNet Message\n{}", hex::encode(message)); + let hash = starknet_keccak(prefixed.as_bytes()); + sign(self.private_key, hash) + } + + fn address(&self) -> Address { + self.address + } +} + +impl Transfer { + /// Compute transaction hash for signing + fn hash(&self) -> FieldElement { + use starknet::core::hash::{poseidon_hash_many, StarkHash}; + + let mut elements = vec![ + self.sender, + self.receiver, + self.token.to_field_element(), + FieldElement::from(self.amount), + FieldElement::from(self.nonce.0), + self.chain_id.0, + FieldElement::from(self.fee), + ]; + + poseidon_hash_many(&elements) + } +} + +impl Token { + fn to_field_element(&self) -> FieldElement { + match self { + Token::OCTO => FieldElement::from(0_u8), + Token::OCTO_W => FieldElement::from(1_u8), + Token::OCTO_D => FieldElement::from(2_u8), + } + } +} +``` + +### Account Abstraction + +```rust +/// Account contract interface +trait Account { + /// Validate transaction + fn validate(&self, caller: Address, call_data: &[FieldElement]) -> bool; + + /// Execute calls + fn execute(&mut self, calls: Vec) -> Vec>; + + /// Get current nonce + fn nonce(&self) -> Nonce; +} + +/// OpenZeppelin-style account +struct OpenZeppelinAccount { + public_key: FieldElement, + nonce: Nonce, + // ... +} + +impl OpenZeppelinAccount { + /// Validate transaction signature + fn validate_transaction(&self, tx: &Transfer, signature: &Signature) -> bool { + let hash = tx.hash(); + verify(self.public_key, hash, *signature) + } +} +``` + +### Multi-Sig Support + +```rust +/// Multi-signature wallet +struct MultisigWallet { + threshold: u8, + signers: Vec

, +} + +impl MultisigWallet { + /// Check if threshold met + fn is_executable(&self, valid_signatures: usize) -> bool { + valid_signatures >= self.threshold + } + + /// Execute if threshold met + fn execute_if_ready(&mut self, tx: &Transfer, signatures: &[Signature]) -> Result<(), Error> { + let valid_count = signatures.iter() + .filter(|sig| verify(self.signers[0], tx.hash(), **sig)) // Simplified + .count(); + + if self.is_executable(valid_count) { + // Execute transaction + Ok(()) + } else { + Err(Error::InsufficientSignatures) + } + } +} +``` + +### Error Handling + +```rust +use thiserror::Error; + +#[derive(Error, Debug)] +pub enum WalletError { + #[error("Invalid private key: {0}")] + InvalidKey(String), + + #[error("Key file not found: {0}")] + KeyFileNotFound(PathBuf), + + #[error("Decryption failed - wrong password?")] + DecryptionFailed, + + #[error("Insufficient signatures: got {0}, need {1}")] + InsufficientSignatures(usize, u8), + + #[error("Transaction failed: {0}")] + TransactionFailed(String), + + #[error("Network error: {0}")] + NetworkError(String), + + #[error("Invalid signature")] + InvalidSignature, +} +``` + +## Rationale + +### Why Starknet ECDSA? + +| Consideration | Starknet | Ethereum | +|--------------|----------|----------| +| Curve | Stark Curve (BLS12-381) | secp256k1 | +| Native ZK | ✅ Direct integration | ❌ Requires bridge | +| Stoolap | ✅ Same ecosystem | ⚠️ Additional complexity | +| Ecosystem | Growing | Large | + +Starknet's native ZK compatibility with Stoolap is the primary driver. + +### Why AES-256-GCM for Storage? + +- **Authenticated encryption** - Detects tampering +- **Fast** - Hardware acceleration common +- **Standard** - Well-audited, widely used +- **Simpler than ChaCha20-Poly1305** for this use case + +### Alternatives Considered + +| Alternative | Pros | Cons | Rejection Reason | +|-------------|------|------|------------------| +| EVM (secp256k1) | Larger ecosystem | No native ZK | Cairo ecosystem required for Stoolap | +| MPC-based | High security | Complex | Phase 2 optimization | +| HSM | Maximum security | Expensive | Not for MVE | +| Raw key file | Simple | No password protection | Security non-negotiable | + +### Trade-offs + +- **Prioritized:** Starknet compatibility, ZK integration, security +- **Deprioritized:** EVM compatibility (Phase 2), advanced MPC (Phase 3) + +## Implementation + +### Mission 1: Core Wallet Cryptography +- Acceptance criteria: + - [ ] KeyPair generation from random entropy + - [ ] Key derivation (Starknet-style) + - [ ] Transaction signing with Starknet ECDSA + - [ ] Message signing with Starknet prefix +- Estimated complexity: Medium + +### Mission 2: Secure Key Storage +- Acceptance criteria: + - [ ] AES-256-GCM encryption/decryption + - [ ] PBKDF2 key derivation (100k iterations) + - [ ] Key file read/write + - [ ] Password-protected wallet unlock +- Estimated complexity: Medium + +### Mission 3: Account Interface +- Acceptance criteria: + - [ ] OpenZeppelin account integration + - [ ] Nonce management + - [ ] Balance queries + - [ ] Token transfer (OCTO-W) +- Estimated complexity: High + +### Mission 4: CLI Integration +- Acceptance criteria: + - [ ] Wallet init command + - [ ] Balance display + - [ ] Transfer command + - [ ] Key file management +- Estimated complexity: Low + +## Impact + +### Breaking Changes +None - new functionality. + +### Migration Path +- **Phase 1:** Single-signer accounts only, encrypted keyfile +- **Phase 2:** Multi-sig support, OS keychain integration +- **Phase 3:** Hardware wallet integration (Ledger/Trezor via HID) + +### Dependencies +- External: starknet-rs (signing, provider) +- External: aes-gcm (encryption) +- External: pbkdf2 (key derivation) +- External: rand (entropy, OsRng) +- External: bip39 (mnemonic recovery) + +### Performance +> **Note:** Estimates based on modern hardware. Low-end devices may see 2-3x latency. + +- Signing: ~5ms per transaction (modern CPU) +- Encryption: ~1ms for key operations +- Network: Depends on RPC provider +- Mnemonic generation: ~10ms + +## Related RFCs +- RFC-0100: AI Quota Marketplace Protocol +- RFC-0101: Quota Router Agent Specification + +## References +- **Stoolap**: Blockchain SQL database with ZK proofs (https://github.com/CipherOcto/stoolap/tree/feat/blockchain-sql) +- starknet-rs: https://github.com/xJonathanLEGO/starknet-rs +- OpenZeppelin Starknet: https://github.com/OpenZeppelin/cairo-contracts +- Starknet Account Abstraction: https://docs.starknet.io/ +- PBKDF2: RFC 2898 +- AES-GCM: NIST SP 800-38D + +--- + +**Submission Date:** 2026-03-03 +**Last Updated:** 2026-03-03 diff --git a/rfcs/0103-unified-vector-sql-storage.md b/rfcs/0103-unified-vector-sql-storage.md new file mode 100644 index 0000000..d3c94fb --- /dev/null +++ b/rfcs/0103-unified-vector-sql-storage.md @@ -0,0 +1,1342 @@ +# RFC-0103: Unified Vector-SQL Storage Engine + +## Status + +Draft + +## Summary + +This RFC specifies the design for merging Qdrant's vector search capabilities with Stoolap's SQL/MVCC engine to create a unified vector-SQL database. The resulting system preserves Stoolap's blockchain-oriented features (Merkle tries, deterministic values, ZK proofs) while adding Qdrant's quantization, sparse vectors, payload filtering, and GPU acceleration. + +## Motivation + +### Problem Statement + +Current AI applications require multiple systems: + +- **Vector database** (Qdrant, Pinecone, Weaviate) for similarity search +- **SQL database** (PostgreSQL, SQLite) for structured data +- **Blockchain** for verification/audit + +This creates operational complexity, data consistency challenges, and latency from cross-system queries. + +### Why This Matters for CipherOcto + +CipherOcto's architecture requires: + +1. **Vector similarity search** for agent memory/retrieval +2. **SQL queries** for structured data (quotas, payments, reputation) +3. **Blockchain verification** for provable state (Merkle proofs) +4. **MVCC transactions** for concurrent operations + +A unified system reduces infrastructure complexity while maintaining all required capabilities. + +## Specification + +### Architecture Overview + +```mermaid +graph TB + subgraph "Unified Storage Engine" + A[SQL Parser] --> B[Query Planner] + B --> C[Optimizer] + C --> D[Executor] + + D --> E[MVCC Engine] + E --> F[Write-Ahead Log] + + D --> G[Vector Engine] + G --> H[HNSW Index] + G --> I[Quantization] + G --> J[Sparse/BM25] + + E --> K[Storage Backends] + K --> L[In-Memory] + K --> M[Memory-Mapped] + K --> N[RocksDB] + end + + subgraph "Blockchain Layer" + O[consensus/] + P[trie/] + Q[determ/] + R[zk/] + end +``` + +### Storage Backend System + +#### Backend Types + +| Backend | Status | Use Case | +| ----------------- | ------- | ---------------------------------- | +| **In-Memory** | Default | Low-latency, small datasets | +| **Memory-Mapped** | Default | Large datasets, OS-managed caching | +| **RocksDB** | Future | Persistent, large scale (optional) | +| **redb** | Future | Pure Rust alternative | + +> **Recommendation**: Start with In-Memory + Memory-Mapped only. Add persistence backends later to avoid development surface explosion. + +#### Vector Storage Layout + +> ⚠️ **Optimization**: Vector storage layout significantly impacts cache performance. + +Use **Struct of Arrays (SoA)** instead of **Array of Structs (AoS)**: + +```rust +// ❌ Array of Structs (poor cache locality) +// Each vector's data scattered across memory +struct VectorStore { + vectors: Vec, // [vec1, vec2, vec3, ...] +} + +struct VectorData { + id: i64, + embedding: Vec, + metadata: Json, +} + +// ✅ Struct of Arrays (better cache locality) +// All embeddings contiguous, all IDs contiguous +struct VectorStoreSoA { + ids: Vec, // [id1, id2, id3, ...] + embeddings: Vec, // [v1_d1, v1_d2, ..., v2_d1, v2_d2, ...] + metadata_offsets: Vec, + metadata_blob: Vec, +} +``` + +**Benefits**: + +- Better CPU cache utilization +- SIMD-friendly vector operations +- Faster batch distance computation + +#### SQL Syntax + +```sql +-- Specify storage backend per table +CREATE TABLE embeddings ( + id INTEGER PRIMARY KEY, + content TEXT, + embedding VECTOR(384) +) STORAGE = mmap; -- Options: memory, mmap, rocksdb + +-- Vector index with quantization +CREATE INDEX idx_emb ON embeddings(embedding) +USING HNSW WITH ( + metric = 'cosine', + m = 32, + ef_construction = 400, + quantization = 'pq', -- Options: none, sq, pq, bq + compression = 8 -- Compression ratio +); + +-- Hybrid search: vector + sparse +SELECT id, content, + VEC_DISTANCE_COSINE(embedding, $query) as score, + BM25_MATCH(description, $keywords) as bm25 +FROM embeddings +WHERE category = 'ai' +ORDER BY score + bm25 * 0.3 +LIMIT 10; +``` + +### Vector Engine Specifications + +#### HNSW Index + +| Parameter | Default | Range | Description | +| ----------------- | ------- | -------------- | ----------------------- | +| `m` | 16 | 2-128 | Connections per node | +| `ef_construction` | 200 | 64-512 | Build-time search width | +| `ef_search` | 200 | 1-512 | Query-time search width | +| `metric` | cosine | l2, cosine, ip | Distance metric | + +#### Quantization + +| Type | Compression | Quality Loss | Use Case | +| ---------------- | ----------- | ------------ | ------------------- | +| **SQ** (Scalar) | 4x | Low | General use | +| **PQ** (Product) | 4-64x | Medium | Large datasets | +| **BQ** (Binary) | 32x | High | Extreme compression | + +#### Sparse Vectors + +- BM25-style inverted index +- Combined with dense vectors for hybrid search +- Configurable term weighting + +#### Payload Filtering + +| Index Type | Use Case | +| ----------------- | ------------------ | +| `bool_index` | Boolean filters | +| `numeric_index` | Range queries | +| `geo_index` | Location filtering | +| `full_text_index` | Text match | +| `facet_index` | Categorical | +| `map_index` | Key-value | + +### Blockchain Feature Preservation + +The following modules remain unchanged: + +| Module | Purpose | Integration | +| ------------ | --------------------- | ----------- | +| `consensus/` | Block/Operation types | Unchanged | +| `trie/` | RowTrie, SchemaTrie | Unchanged | +| `determ/` | Deterministic values | Unchanged | +| `zk/` | ZK proofs | Unchanged | + +All blockchain features operate independently of storage backend selection. + +### GPU Acceleration (Limited Scope) + +> ⚠️ **Implementation Warning**: HNSW GPU support is experimental. Graph traversal is memory-bound; GPU gains are smaller than expected. + +**Initial GPU Scope** (Phase 5): +| Operation | GPU Benefit | +|----------|-------------| +| Vector distance computation | High | +| Quantization training | High | +| Batch re-ranking | Medium | +| Full graph traversal | Low (memory-bound) | + +```rust +#[cfg(feature = "gpu")] +pub mod gpu { + // CUDA kernels for distance computation + // Quantization training + // Batch re-ranking + // NOT full graph traversal initially +} +``` + +- Feature-gated with `#[cfg(feature = "gpu")]` +- Fallback to CPU when GPU unavailable +- CUDA support only (OpenCL future) +- Start with distance computation, not full traversal + +#### SIMD Specialization (More Impact Than GPU) + +> ⚠️ **Optimization**: SIMD acceleration often provides more benefit than GPU for vector databases. + +| SIMD Level | Benefit | Use Case | +| ----------- | ------- | ------------------- | +| **AVX-512** | Highest | Data center (Intel) | +| **AVX2** | High | General x86 | +| **NEON** | High | ARM/Apple Silicon | +| **SSE** | Medium | Legacy x86 | + +```rust +// SIMD dispatch +#[cfg(target_arch = "x86_64")] +mod simd { + #[cfg(feature = "avx512")] + pub fn distance(a: &[f32], b: &[f32]) -> f32 { + unsafe { avx512_distance(a, b) } + } + #[cfg(feature = "avx2")] + pub fn distance(a: &[f32], b: &[f32]) -> f32 { + unsafe { avx2_distance(a, b) } + } +} + +#[cfg(target_arch = "aarch64")] +mod simd { + pub fn distance(a: &[f32], b: &[f32]) -> f32 { + unsafe { neon_distance(a, b) } + } +} +``` + +**Priority**: Implement SIMD before GPU. Higher ROI for most deployments. + +### Search Algorithms + +| Algorithm | Best For | Implementation | +| --------- | ------------------ | -------------- | +| **HNSW** | General ANNS | Default | +| **Acorn** | Memory-constrained | Optional | + +### Determinism & Consensus + +**Critical Challenge**: Blockchain consensus requires exact determinism. Vector search uses floating-point math which can be non-deterministic across architectures. + +#### The Problem + +- Floating-point rounding differs between x86 (AVX) and ARM (NEON) +- SIMD instructions may produce slightly different results +- Concurrent HNSW graph construction is non-deterministic + +#### Solution: Snapshot-Based Verification + +```mermaid +graph LR + A[Transaction Commits] --> B[Snapshot Vector Index] + B --> C[Generate Merkle Root] + C --> D[Store in Blockchain] + + E[Query Request] --> F[Use Committed Snapshot] + F --> G[Return Results + Proof] +``` + +**Approach**: + +1. **Immutable Snapshots**: After commit, vector index becomes immutable +2. **Merkle Root**: Compute root hash of all vectors at commit time +3. **Stored State**: Store serialized vector data (not graph) for verification +4. **Software Float**: Use strict IEEE 754 for critical comparisons (optional feature) + +> **Trade-off**: This means live HNSW graph searches cannot be directly verified. Instead, verified queries use a snapshot. Real-time verification requires async proof generation. + +> ⚠️ **Implementation Warning**: Computing Merkle root at commit time for tables with millions of vectors will destroy write throughput. +> +> **Recommendation**: Use incremental hashing - only hash newly inserted/deleted vectors and update branches to root, rather than rehashing entire dataset. The existing `trie/RowTrie` should support this pattern. + +#### Improved Merkle Strategy: ID + Content Hash + +Instead of hashing raw vectors (1.5GB for 1M vectors), hash vector IDs and content: + +```rust +// Instead of hashing 1536 bytes per vector: +// vector_hash = blake3(embedding_bytes) // 1536 bytes + +// Hash only: +// vector_hash = blake3(vector_id || blake3(embedding_bytes)) // ~64 bytes +struct MerkleEntry { + vector_id: i64, + content_hash: [u8; 32], // blake3 of embedding +} + +// Merkle tree uses: vector_id → vector_hash +// Much smaller tree, faster updates +``` + +**Benefits**: + +- Smaller hashes (64 bytes vs 1536 bytes per vector) +- Faster incremental updates +- Still proves vector content exists + +#### Hierarchical Merkle Tree + +For large datasets (1B+ vectors), flat Merkle tree depth becomes problematic. Use hierarchical structure: + +```mermaid +graph TB + R[root hash] + S1[segment_1_root] + S2[segment_2_root] + S3[segment_3_root] + V1[vector hashes] + V2[vector hashes] + V3[vector hashes] + + R --> S1 + R --> S2 + R --> S3 + S1 --> V1 + S2 --> V2 + S3 --> V3 +``` + +**Structure**: + +``` +Merkle root + └─ segment_1_root + └─ vector_hashes (segment_1) + └─ segment_2_root + └─ vector_hashes (segment_2) + └─ segment_3_root + └─ vector_hashes (segment_3) +``` + +**Benefits**: + +- Segment merges only update part of tree +- Snapshotting cheaper (per-segment) +- Proofs smaller (segment-level) +- Scales to billions of vectors + +#### Software Float Performance + +> ⚠️ **Implementation Warning**: Software floating-point emulation (strict IEEE 754) is orders of magnitude slower than hardware SIMD. +> +> **Recommendation**: Isolate software emulation strictly to verification/snapshot phase. Live query nodes should use hardware acceleration (AVX/NEON) to maintain <50ms latency. Only enforce software float on nodes participating in block generation/validation. + +### Three-Layer Verification Architecture + +Separate concerns into distinct layers: + +```mermaid +graph LR + A[Query Node] --> B[Fast Search
HNSW (AVX/GPU)] + B --> C[Candidate Set
top-200] + C --> D[Deterministic Re-rank
Software Float] + D --> E[Top-K Result] + E --> F[Merkle Proof
of vectors] +``` + +| Layer | Purpose | Determinism | +| ------------------------- | ------------------------------------ | ----------------- | +| **Fast Search** | HNSW traversal, candidate generation | Non-deterministic | +| **Deterministic Re-rank** | Final ranking of candidates | Software float | +| **Blockchain Proof** | Verify vector inputs exist | Full verification | + +**Benefits**: + +- Fast queries use hardware acceleration +- Final result is deterministically ranked +- Merkle proof verifies input vectors + +> **Key Insight**: This architecture ensures **Process Integrity** (correct ranking logic) rather than **Result Uniformity** (identical candidate sets across nodes). For strict blockchain consensus, a brute-force fallback may be required for the final verification step. + +#### Consensus Guarantees + +> ⚠️ **Critical Clarification**: The three-layer approach has limits: + +| Guarantee | Scope | Notes | +| ----------------------- | ------------- | ---------------------------------------- | +| **Vector Existence** | Full | Merkle proof verifies vectors existed | +| **Ranking Correctness** | Full | Software float ensures identical ranking | +| **Identical Results** | Probabilistic | HNSW candidates may differ across nodes | + +**For Strict Blockchain Consensus**: Use brute-force search for final verification step (computes exact K nearest neighbors). This ensures identical results but sacrifices speed. + +```rust +// Strict verification mode +fn verify_with_consensus(query: &[f32], k: usize) -> VerifiedResult { + // Layer 1: HNSW for speed + let candidates = hnsw_search(query, k * 4); + + // Layer 2: Brute-force for exact consensus + let exact_results = brute_force_search(query, k); + + // Layer 3: Merkle proof + let proof = generate_merkle_proof(&exact_results); + + VerifiedResult { results: exact_results, proof } +} +``` + +#### Deterministic Re-Ranking Constraint + +> ⚠️ **Implementation Warning**: Software float is orders of magnitude slower. Limit candidate set size. + +**Constraint**: +| Parameter | Value | Rationale | +|-----------|-------|-----------| +| Candidate set | ≥4×K, ≤512 | Must cover enough candidates for top-K | +| Min candidates | 40 | For K=10, need at least 40 | +| Max candidates | 512 | Software float cost limit | + +**Performance Estimate**: +- 512 candidates × 768 dimensions ≈ 393,216 float operations +- Software float: ~1-5ms per query (single-threaded, depending on CPU) +- At 100 QPS: 100-500ms total CPU — acceptable for async verification path +- **Isolation**: Runs on background thread, not hot query path +- **Validation**: Benchmark required before Phase 4 to confirm <50ms SLA compatibility + +```rust +fn deterministic_rerank(candidates: &[ScoredPoint], k: usize) -> Vec { + // Expand candidate set for cross-node consistency + let candidate_count = (4 * k).max(40).min(candidates.len()); + let top_candidates = &candidates[..candidate_count]; + + // Software float distance + top_candidates.iter() + .map(|p| (p.id, software_float_distance(&p.vector, query))) + .sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap()) + .take(k) + .collect() +} +``` + +> **Key**: Expanded candidate sets ensure different nodes produce identical top-K results despite HNSW non-determinism. + +### Performance SLAs + +| Metric | Target | Measurement | +| ----------------------------- | ------------------------ | ----------------------- | +| Live query latency | <50ms | P50 at 1K QPS | +| Proof generation (async) | <5s (95th percentile) | Async background | +| Proof generation (fast-proof) | <100ms | Synchronous, top-K only | +| Merkle root update | <1s | Incremental at commit | +| Auto-compaction trigger | <15% tombstone threshold | Background scheduler | +| Index build throughput | >100K vectors/sec | During bulk import | +| Vector insert QPS | >10K inserts/sec | Sustained write rate | + +> **Fast-Proof Mode**: Optional synchronous proof generation for small result sets (top-K). Uses abbreviated Merkle proof for top-K results only, bypassing full snapshot hashing. + +#### Background Task Scheduler + +> ⚠️ **Critical**: Many operations require background processing. Must not block query path. + +Required background tasks: + +| Task | Priority | Trigger | +| ------------------ | -------- | --------------------- | +| Segment merge | Medium | segments > 8 | +| Compaction | Medium | tombstone > 15% | +| Proof generation | Low | Async queue | +| Index rebuild | Low | On segment merge | +| Snapshot creation | Low | Configurable interval | +| Statistics refresh | Low | ANALYZE command | + +```rust +// Background scheduler +struct BackgroundScheduler { + tasks: PriorityQueue, + max_concurrent: usize, +} + +enum BackgroundTask { + MergeSegments { table_id: u64, segment_ids: Vec }, + Compact { table_id: u64, threshold: f32 }, + GenerateProof { query_id: u64 }, + RebuildIndex { segment_id: u64 }, + CreateSnapshot { table_id: u64 }, + RefreshStatistics { table_id: u64 }, +} + +impl BackgroundScheduler { + fn schedule(&self, task: BackgroundTask) { + // Add to priority queue + // Execute based on priority and resources + } + + fn should_run(&self, task: &BackgroundTask) -> bool { + // Check resource availability + // Check priority + true + } +} +``` + +**Design Principles**: + +- Non-blocking (query path never waits) +- Configurable concurrency +- Priority-based execution +- Crash-recovery via WAL replay + +### Benchmark Targets (Post-Implementation) + +| Metric | Target | Notes | +| ----------------- | ------ | ------------------------------ | +| Query latency | <50ms | vs 350ms multi-system baseline | +| Storage reduction | 60% | With BQ compression | +| Compression ratio | 4-64x | PQ/SQ/BQ configurations | +| Recall@10 | >95% | At 15% tombstone threshold | + +### MVCC & Vector Index + +**Critical Challenge**: HNSW is a connected graph. Concurrent transactions must see consistent vector visibility. + +#### The Problem + +- Transaction A inserts vector → updates HNSW graph +- Transaction B runs concurrently → should not see A's uncommitted vectors +- Graph traversals may include/exclude nodes incorrectly + +#### Solution: Segment Architecture (Qdrant-Style) + +Instead of per-vector MVCC visibility checks (20-40% slowdown), use immutable segments: + +```mermaid +graph TB + subgraph "Segment Architecture" + S1[segment_1
immutable] + S2[segment_2
immutable] + SL[segment_live
mutable] + Q[Query] + R[Merge Results] + end + + Q --> S1 + Q --> S2 + Q --> SL + S1 --> R + S2 --> R + SL --> R +``` + +**Approach**: + +1. **Immutable Segments**: After commit, vectors go into immutable segments +2. **Live Segment**: New inserts go to mutable segment_live +3. **Per-Segment Visibility**: Transaction sees `visible_segments(txn_id)` +4. **Search Per Segment**: Search each segment, merge results + +#### Segment Merge Policy + +> ⚠️ **Implementation Warning**: Without merge policy, segment count explodes with writes. + +**Merge Triggers**: +| Condition | Action | +|-----------|--------| +| segments > 8 | Trigger merge | +| segments > 16 | Aggressive merge | +| Total size > 1GB | Merge smallest | + +**Merge Strategy**: + +```rust +fn should_merge(segments: &[Segment]) -> bool { + segments.len() > 8 || segments.iter().map(|s| s.size()).sum() > 1_073_741_824 +} + +fn merge_segments(segments: &mut Vec) { + // Sort by size, merge smallest pairs + segments.sort_by_key(|s| s.size()); + let smallest = segments.remove(0); + let second_smallest = segments.remove(0); + let merged = merge(smallest, second_smallest); + segments.push(merged); +} +``` + +**Benefits**: + +- Prevents query performance degradation +- Reduces resource usage +- Maintains fast search speeds + +#### Versioned Segments for Blockchain Snapshots + +> ⚠️ **Critical**: Segment merges conflict with blockchain immutability. Old segments must remain until snapshot finalized. + +**Problem**: + +``` +segment_1 + segment_2 → segment_3 +``` + +Merkle roots change. Historical queries break. Proof verification fails. + +**Solution**: Versioned segments + +```rust +struct VersionedSegment { + segment_id: u64, + version: u64, // Incremented on merge + vectors: Vec, + merkle_root: [u8; 32], + created_at: u64, // Block timestamp + is_active: bool, +} + +// Segments never deleted, just marked inactive +// Query: active_segments + historical_segments(version) +``` + +**Behavior**: +| Operation | Segment Action | +|-----------|----------------| +| Insert | Add to live segment | +| Commit | Freeze segment, increment version | +| Merge | Create new version, mark old inactive | +| Historical query | Use segment at specific version | + +**Benefits**: + +- Blockchain snapshots immutable +- Historical queries supported +- Proof verification stable + +**Benefits**: + +- No per-node visibility checks (eliminates branch mispredictions) +- Simpler concurrency model +- Faster queries +- Borrowed from Qdrant's proven segment architecture + +**Implementation**: + +```rust +fn search_with_mvcc(query: &Query, txn: &Transaction) -> Vec { + let visible = visible_segments(&txn); + let mut results = Vec::new(); + + for segment in visible { + results.extend(search_segment(segment, query)); + } + + merge_top_k(results, query.limit) +} +``` + +### WAL Format for Vector Operations + +Vector operations must be WAL-logged for recovery: + +```rust +// WAL entry types for vectors +enum WalVectorOp { + VectorInsert { + segment_id: u64, + vector_id: i64, + embedding: Vec, + txn_id: u64, + }, + VectorDelete { + segment_id: u64, + vector_id: i64, + txn_id: u64, + }, + VectorUpdate { + segment_id: u64, + vector_id: i64, + old_embedding: Vec, + new_embedding: Vec, + txn_id: u64, + }, + SegmentCreate { + segment_id: u64, + is_immutable: bool, + }, + SegmentMerge { + old_segments: Vec, + new_segment: u64, + }, + // Phase 1 CRITICAL: Index rebuild entries for crash recovery + IndexBuild { + segment_id: u64, + index_type: String, // "hnsw" | "flat" + build_config: HashMap, + }, + CompactionStart { + compaction_id: u64, + source_segments: Vec, + }, + CompactionFinish { + compaction_id: u64, + source_segments: Vec, + new_segment_id: u64, + deleted_vector_ids: Vec, // For tombstone tracking + }, + // Snapshot for fast recovery without full WAL replay + SnapshotCommit { + snapshot_id: u64, + block_height: u64, + merkle_root: Hash, + vector_count: u64, + }, +} + +// Recovery: replay WAL entries to rebuild index state +fn recover_from_wal(wal: &Wal) -> VectorState { + let mut state = VectorState::new(); + for entry in wal.entries() { + match entry { + WalVectorOp::VectorInsert { .. } => state.apply_insert(entry), + WalVectorOp::VectorDelete { .. } => state.apply_delete(entry), + WalVectorOp::VectorUpdate { .. } => state.apply_update(entry), + WalVectorOp::SegmentCreate { .. } => state.add_segment(entry), + WalVectorOp::SegmentMerge { .. } => state.merge_segments(entry), + WalVectorOp::IndexBuild { .. } => state.build_index(entry), + WalVectorOp::CompactionStart { .. } => state.start_compaction(entry), + WalVectorOp::CompactionFinish { .. } => state.finish_compaction(entry), + WalVectorOp::SnapshotCommit { .. } => state.commit_snapshot(entry), + } + } + state +} +``` + +**Properties**: + +- Each vector op logged atomically +- Segment create/merge also logged +- Recovery rebuilds exact state + +**Missing Operations** (add to enum): + +```rust + IndexBuild { + segment_id: u64, + index_type: String, + index_path: String, + }, + CompactionStart { + segment_ids: Vec, + compaction_id: u64, + }, + CompactionFinish { + compaction_id: u64, + new_segment_id: u64, + deleted_vector_ids: Vec, + }, + SnapshotCommit { + snapshot_id: u64, + merkle_root: [u8; 32], + block_height: u64, + }, +} +``` + +> ⚠️ **Critical**: Without IndexBuild/Compaction/Snapshot entries, recovery cannot rebuild index state reliably. + +**Challenge**: For queries like `WHERE reputation > 0.9 ORDER BY vector_distance`, which plan is optimal? + +```sql +SELECT * FROM agents +WHERE reputation_score > 0.9 +ORDER BY VEC_DISTANCE_COSINE(embedding, $query) +LIMIT 10; +``` + +#### Approach: Cost-Based Decision + +The optimizer will estimate: + +| Factor | Consideration | +| --------------------- | ------------------------------------------ | +| **Selectivity** | How many rows pass `reputation > 0.9`? | +| **Index Selectivity** | HNSW ef_search value vs full scan | +| **Vector Dimension** | Brute-force cost scales with dimension | +| **Quantization** | Quantized search is faster but approximate | + +**Plans**: + +1. **Index-First**: Use HNSW, filter by reputation post-search (low selectivity) +2. **Filter-First**: Scan with reputation filter, brute-force vector (high selectivity) +3. **Index-Filtered**: Use HNSW with payload filter pre-search (Qdrant-style) + +The optimizer will use statistics to pick the cheapest plan. + +#### Statistics Subsystem + +> ⚠️ **Critical**: Without accurate statistics, the planner will make poor choices. + +Required statistics for hybrid queries: + +| Statistic | Description | Collection | +| ----------------------- | --------------------------------- | -------------- | +| `vector_norm_histogram` | Distribution of vector magnitudes | On insert | +| `payload_histograms` | Value distributions per column | On ANALYZE | +| `segment_sizes` | Vectors per segment | On commit | +| `index_density` | HNSW connectivity density | On index build | +| `tombstone_ratio` | Deleted/total vectors | Continuous | + +**Collection Strategy**: + +1. **Sampling Rate**: 1% random sample per segment (minimum 1000 vectors) +2. **Update Triggers**: + - After bulk inserts (>10K vectors) + - On `ANALYZE` command + - Every 5 minutes for high-throughput workloads +3. **Staleness Policy**: Mark stale if >20% change since last collection +4. **Clustered Embeddings**: Use k-means (k=10) to detect semantic clusters for better selectivity estimation + +> ⚠️ **Note**: Embedding distributions are often highly non-uniform (clustered by semantic domain). K-means detection helps the planner distinguish index-first vs filter-first strategies. +// Statistics collection +struct TableStatistics { + table_id: u64, + row_count: u64, + vector_stats: VectorStatistics, + payload_stats: HashMap, +} + +struct VectorStatistics { + dimension: usize, + norm_histogram: Histogram, + avg_norm: f32, + non_zero_count: u64, +} + +struct PayloadStatistics { + min: Value, + max: Value, + null_count: u64, + histogram: Histogram, +} + +// ANALYZE command triggers collection +fn analyze_table(table: &Table) -> TableStatistics { + // Sample vectors for norm histogram + // Scan payload columns for histograms + // Update segment metadata +} +``` + +**Collection Strategy**: + +- Background sampling (not full scan) +- Incremental updates (not full recalculation) +- Configurable refresh interval + +## Rationale + +### Why Multiple Backends? + +1. **Flexibility**: Different workloads have different requirements +2. **Optimization**: Per-table/backend choice enables tuning +3. **Migration Path**: Start with memory, migrate to mmap/rocksdb +4. **No Trade-offs**: Users choose what fits their use case + +### Why Merge into Stoolap? + +1. **Clean Foundation**: Stoolap's HNSW is well-structured, cache-optimized +2. **SQL Integration**: Already has query planner, optimizer, MVCC +3. **Blockchain Ready**: Already has trie, consensus, ZK modules +4. **Default Pure Rust**: No C++ dependencies by default (rocksdb is optional) + +> **Correction**: The "Pure Rust" benefit applies to default builds. RocksDB is available as an optional feature for users who need its production-proven persistence. + +### Alternative Approaches Considered + +#### Option 1: New Codebase + +- **Rejected**: Duplication of SQL/MVCC infrastructure +- **Trade-off**: More work, cleaner slate + +#### Option 2: Fork Qdrant + Add SQL + +- **Rejected**: Qdrant's Rust codebase less modular for SQL addition +- **Trade-off**: Would require significant refactoring + +## Implementation + +### Phases (Revised - MVP Focus) + +> ⚠️ **Important**: Revised to bring persistence and quantization to MVP. Hardest problems still first. + +``` +Phase 1: Core Engine (MVP) +├── MVCC + Segment architecture +├── Three-layer verification +├── Vector ID + content hash for Merkle +├── Basic statistics collection (row counts, null counts) +├── In-Memory storage +├── Test: MVCC + concurrent vector UPDATE/DELETE +└── P0: WAL enum completeness (IndexBuild, CompactionStart/Finish, SnapshotCommit) + +Phase 2: Persistence (MVP) +├── Memory-Mapped storage +├── RocksDB backend (optional) +├── WAL integration for vectors +└── Crash recovery + +Phase 3: Quantization (MVP) +├── Scalar Quantization (SQ) +├── Product Quantization (PQ) +├── Binary Quantization (BQ) +└── SQL syntax for quantization config + +Phase 4: Deterministic Verification +├── Software float re-ranking +├── Incremental Merkle updates +├── Fast-proof mode (top-K sync) +└── Test: Cross-architecture (x86 vs ARM) + +Phase 5: Hybrid Query Planner +├── Cost-based planning (index-first vs filter-first) +├── Statistics collection (selectivity, histograms) +├── Payload filter integration +└── Test: Hybrid queries with various selectivities + +Phase 6: Sparse Vectors / BM25 +├── Copy lib/sparse to src/storage/sparse +├── Add SPARSE index type +└── Add BM25_MATCH SQL function + +Phase 7: GPU Support (Future) +├── Add GPU feature flag +├── Distance computation only +└── NOT full graph traversal initially +``` + +### Key Files to Modify + +| File | Change | +| --------------------------- | -------------------------------- | +| `src/storage/mod.rs` | Add backend abstraction | +| `src/storage/index/hnsw.rs` | Add quantization, algorithms | +| `src/storage/index/mod.rs` | Add sparse, field indexes | +| `src/parser/` | Add STORAGE, QUANTIZATION syntax | +| `src/executor/` | Add vector/sparse operators | +| `Cargo.toml` | Add quantization, sparse deps | + +### Vector Update/Delete Semantics + +#### UPDATE Vector + +```sql +UPDATE embeddings SET embedding = $new_vec WHERE id = 5; +``` + +**Behavior**: + +1. Old vector marked with `deleted_txn_id` (tombstone) +2. New vector inserted with `created_txn_id` +3. HNSW graph updated asynchronously (background merge) + +#### DELETE Vector + +```sql +DELETE FROM embeddings WHERE id = 5; +``` + +**Behavior**: + +1. Vector marked with `deleted_txn_id` +2. Tombstoned until garbage collection +3. HNSW index entry marked deleted (not removed from graph) + +#### Background Compaction + +```sql +-- Trigger manual compaction +ALTER TABLE embeddings COMPACT; +``` + +Compaction rebuilds the HNSW graph without tombstones. Recommended after bulk deletes. + +> ⚠️ **Implementation Warning**: HNSW search performance degrades rapidly with too many tombstones. Relying on users manually running `COMPACT` will cause slowdowns. +> +> **Recommendation**: Implement auto-vacuum/auto-compact threshold in background (e.g., trigger when tombstone count > 20% of total nodes). +> +> **Strengthening**: +> +> - Make auto-compaction **mandatory**, not optional +> - **Hard limit: 30%** - Beyond this, recall collapses +> - Soft trigger: 15% +> - Configurable per-table threshold (similar to PostgreSQL autovacuum) +> - Log warnings when compaction is delayed + +#### Testing Requirements + +The following test matrix must be implemented: + +| Test Category | Scenario | Acceptance Criteria | +| ------------------------- | ------------------------------ | ------------------------------ | +| **MVCC + Vector** | High-concurrency UPDATE/DELETE | No consistency violations | +| **Determinism** | x86 vs ARM execution | Identical results | +| **Merkle Root** | 1M → 100M vectors | <1s incremental update | +| **Tombstone Degradation** | recall@10 vs % deleted | <5% recall loss at 15% deleted | + +> **Segment-Merge Philosophy**: Borrow from Qdrant - use immutable segments + background merge. Old segments remain searchable while new ones are built. + +### Monitoring & Telemetry + +Add production monitoring hooks: + +| Metric | Purpose | +| ------------------------- | --------------------------------- | +| `tombstone_ratio` | Current % deleted nodes in HNSW | +| `compaction_queue_depth` | Pending compaction operations | +| `proof_gen_queue_latency` | P50/P95/P99 proof generation time | +| `recall_estimate` | Estimated recall degradation | + +```sql +-- System view for monitoring +SELECT * FROM system.vector_index_stats('embeddings'); +-- Returns: tombstone_ratio, last_compacted, proof_pending, etc. +``` + +### Benchmark Baselines + +Validate against: + +| Baseline | Target | +| ---------------------------------- | ------------------------------- | +| **Current Stoolap** (basic HNSW) | Compare latency | +| **Standalone Qdrant** | Compare recall @ K | +| **Multi-system** (SQL + vector DB) | Compare 350ms vs 50ms narrative | + +> **Critical**: Prototype highest-risk pieces first: +> +> 1. Incremental Merkle root at 10M+ scale +> 2. Visibility filter cost during HNSW descent +> 3. Auto-compaction with recall/latency measurements + +### License Compliance + +When porting code from Qdrant (Apache 2.0 license): + +1. **Copyright Headers**: Maintain all original Apache 2.0 headers +2. **NOTICE File**: Add to repository noting Apache 2.0 code used +3. **Module Attribution**: Add doc comments crediting original Qdrant authors +4. **No Proprietary Changes**: Apache 2.0 allows modification, but changes must be documented + +```rust +// Example attribution header +// Originally adapted from Qdrant (Apache 2.0) +// https://github.com/qdrant/qdrant +// Copyright 2024 Qdrant Contributors +``` + +### Testing Strategy + +1. **Unit Tests**: Each component independently +2. **Integration Tests**: SQL + Vector queries +3. **Benchmark Tests**: Performance vs Qdrant, vs standalone Stoolap +4. **Blockchain Tests**: Verify trie/ZK integration unchanged +5. **Cross-Architecture Consistency**: Verify identical results on x86, ARM, different SIMD levels + +## Related Use Cases + +- [Decentralized Mission Execution](../../docs/use-cases/decentralized-mission-execution.md) +- [Autonomous Agent Marketplace](../../docs/use-cases/agent-marketplace.md) + +## Related Research + +- [Qdrant Research Report](../../docs/research/qdrant-research.md) +- [Stoolap Research Report](../../docs/research/stoolap-research.md) + +--- + +## Prioritized Recommendations + +| Priority | Phase Gate | Action | Status | +|----------|------------|--------|--------| +| **P0** | Phase 1 | WAL enum completeness: `IndexBuild`, `CompactionStart`, `CompactionFinish`, `SnapshotCommit` | ✅ Implemented | +| **P0** | Phase 2 | MTTR quantification: HNSW rebuild time estimates + SLA + snapshot trigger justification | ✅ Implemented | +| **P1** | Phase 4 | Software float benchmark: 512 candidates × 768 dimensions at target QPS | ✅ Estimated | +| **P1** | Phase 5 | Statistics collection: sampling rate, triggers, staleness policy, k-means for clusters | ✅ Specified | +| **P2** | Any | Appendix D placeholder | ✅ Added | + +> All P0 and P1 items are addressed in this RFC. Phase gates ensure validation happens before each phase begins. + +--- + +## Appendices + +### A. Replication Model + +**Question**: How do nodes synchronize in distributed deployments? + +| Model | Use Case | Implementation | +| ------------------- | -------------------- | ----------------------------------- | +| **Raft** | Strong consistency | Leader + followers, log replication | +| **Gossip** | Eventual consistency | Peer-to-peer state sharing | +| **Blockchain-only** | Verification only | Merkle state, not real-time sync | + +**Recommendation**: Start with Raft for strong consistency. Gossip for large-scale deployments (future). + +#### Vector Index Replication Strategy + +> ⚠️ **Important**: Vector indexes are NOT directly replicated. + +**Approach**: +| Component | Replicated? | Strategy | +|-----------|--------------|----------| +| Vector data | Yes | Raft log replicates raw vectors | +| HNSW index | No | Rebuilt locally from replicated vectors | +| Segment metadata | Yes | Replicated via Raft | +| Merkle root | Yes | Computed locally, proof shared | + +**Why**: + +- Replicating graph structure is complex and non-deterministic +- Rebuilding index locally is simpler and deterministic +- Each node computes identical index from identical data + +**Process**: + +``` +1. Leader receives vector INSERT +2. Raft log replicates to followers +3. Each node applies to local vector store +4. Each node rebuilds affected segment +5. Index remains consistent across nodes +``` + +#### Index Snapshot Shipping (Recovery Optimization) + +> ⚠️ **Optimization**: Rebuilding HNSW from millions of vectors takes hours. Add snapshot shipping for faster recovery. + +**MTTR Estimates** (Mean Time To Recovery): + +| Dataset Size | Rebuild (no snapshot) | With Snapshot Shipping | +|--------------|----------------------|------------------------| +| 100K vectors | ~5 min | <30 sec | +| 1M vectors | ~45 min | ~2 min | +| 10M vectors | ~6 hours | ~15 min | +| 100M vectors | ~2 days | ~2 hours | + +**Target SLA**: MTTR <5 minutes for typical workloads (<1M vectors). + +**Problem**: New or recovering nodes must rebuild entire HNSW index from scratch. + +**Solution**: Periodically ship pre-built index snapshots: + +```rust +// Periodic snapshot shipping +struct IndexSnapshot { + snapshot_id: u64, + segment_id: u64, + hnsw_graph: Vec, // Serialized graph + vector_offsets: Vec, + merkle_root: [u8; 32], +} + +// Recovery process +fn recover_node(snapshot: IndexSnapshot, wal_delta: Wal) -> VectorState { + // 1. Load snapshot + let mut state = load_snapshot(snapshot); + + // 2. Replay WAL delta + for entry in wal_delta.entries() { + state.apply(entry); + } + + // 3. Rebuild affected segments + state.rebuild_dirty_segments(); + + state +} +``` + +**Benefits**: + +- Faster node recovery (minutes vs hours) +- Reduced computation on followers +- Trade-off: Higher bandwidth usage (estimate: 2-5x WAL-only depending on snapshot frequency) + +**Trigger**: Ship snapshots every N vectors or T time interval (recommend: 100K vectors or 5 minutes). + +### B. Query Language Extensions + +SQL extensions for vector operations: + +| Syntax | Purpose | +| ----------------------------- | ------------------------- | +| `VECTOR(dims)` | Column type for vectors | +| `VEC_DISTANCE_COSINE(v1, v2)` | Cosine distance function | +| `VEC_DISTANCE_L2(v1, v2)` | Euclidean distance | +| `BM25_MATCH(column, query)` | Text search | +| `STORAGE = backend` | Storage backend selection | +| `USING HNSW` | Index type selection | + +**Future Extensions**: + +```sql +-- Hybrid search (dense + sparse) +SELECT * FROM docs +ORDER BY hybrid_score(dense_vector, sparse_vector, 0.7) +LIMIT 10; +``` + +### C. Agent Memory Model + +CipherOcto agents require structured memory: + +```sql +-- Episodic memory: what the agent did +CREATE TABLE episodic_memory ( + id INTEGER PRIMARY KEY, + agent_id INTEGER, + episode_id BIGINT, + embedding VECTOR(768), + action JSON, + result JSON, + timestamp TIMESTAMP +) STORAGE = memory; + +-- Semantic memory: what the agent knows +CREATE TABLE semantic_memory ( + id INTEGER PRIMARY KEY, + agent_id INTEGER, + embedding VECTOR(768), + content TEXT, + importance FLOAT, + last_accessed TIMESTAMP +) STORAGE = mmap; + +-- Task memory: current tasks +CREATE TABLE task_memory ( + id INTEGER PRIMARY KEY, + agent_id INTEGER, + task_id BIGINT, + embedding VECTOR(768), + status TEXT, + priority INTEGER +) STORAGE = memory; + +-- Index for retrieval +CREATE INDEX idx_episodic ON episodic_memory(embedding) USING HNSW; +CREATE INDEX idx_semantic ON semantic_memory(embedding) USING HNSW; +``` + +**Query: Retrieve relevant context for agent** + +```sql +SELECT * FROM ( + SELECT 'episodic' as type, id, action, timestamp, + VEC_DISTANCE_COSINE(embedding, $context) as score + FROM episodic_memory WHERE agent_id = $agent + UNION ALL + SELECT 'semantic' as type, id, content, timestamp, + VEC_DISTANCE_COSINE(embedding, $context) as score + FROM semantic_memory WHERE agent_id = $agent +) combined +ORDER BY score DESC +LIMIT 5; +``` + +### D. Reserved + +> This appendix is reserved for future work. + +### E. Implementation Notes for Phase 1 Dev Team + +#### Memory Alignment for SoA + +When implementing the Struct of Arrays for vectors (`embeddings: Vec`), ensure the memory allocations are explicitly aligned: + +| SIMD Level | Alignment | Implementation | +|------------|-----------|----------------| +| AVX2 | 32-byte | `std::alloc::Layout::from_size_align(n, 32)` | +| AVX-512 | 64-byte | `std::alloc::Layout::from_size_align(n, 64)` | +| ARM NEON | 16-byte | `std::alloc::Layout::from_size_align(n, 16)` | + +Standard Rust `Vec` does not guarantee this alignment. Consider using the `aligned-vec` crate or manual allocation: + +```rust +use std::alloc::{alloc, Layout}; + +// For AVX-512 +let layout = Layout::from_size_align(size * mem::size_of::(), 64).unwrap(); +let ptr = unsafe { alloc(layout) }; +``` + +#### WAL Bloat Prevention + +In `WalVectorOp`, logging raw `Vec` for every insert will cause the Write-Ahead Log to grow rapidly: + +- 768-dimension vector ≈ 3KB per insert +- 1M inserts = 3GB WAL + +**Mitigation strategies**: + +1. **Aggressive WAL rotation**: Rotate at 64MB (not 256MB like standard SQL) +2. **Quantize before WAL**: Apply Product Quantization before logging +3. **Delta encoding**: Log only differences for updates +4. **Separate vector WAL**: Maintain independent high-rotation WAL for vectors + +**Recommendation**: Apply BQ (Binary Quantization) before WAL write—sufficient for recovery while reducing 768-dim vector to 96 bytes. + +#### Blake3 for Merkle Tree + +The `blake3(vector_id || blake3(embedding))` structure is optimal: + +- Blake3 has SIMD-optimized Rust implementation +- Benchmarks: 10M hashes/second on modern CPU +- Makes "commit-time Merkle root" feasible (<100ms for 1M vectors) + +```rust +use blake3::Hasher; + +fn merkle_leaf(vector_id: i64, embedding: &[f32]) -> Hash { + let content_hash = blake3::hash(embedding.as_bytes()); + let mut hasher = Hasher::new(); + hasher.update(&vector_id.to_le_bytes()); + hasher.update(content_hash.as_bytes()); + *hasher.finalize() +} +```