Grand Diomande Research · Full HTML Reader

EPOCH Appchain: Stacks Fork + Native Rust Services

Instead of 5 external services talking to the chain via HTTP, they become native chain modules. Graph Kernel queries happen at chain speed, not network speed. N'Ko inscriptions render inside the block validator. RAG++ vector search is part of consensus.

Protocol and Compute architecture technical paper candidate score 22 .md

Full Public Reader

EPOCH Appchain: Stacks Fork + Native Rust Services

The Vision

Instead of 5 external services talking to the chain via HTTP, they become native chain modules. Graph Kernel queries happen at chain speed, not network speed. N'Ko inscriptions render inside the block validator. RAG++ vector search is part of consensus.

What Exists

96,682 lines of production Rust across 6 crates ready for embedding:

CrateLinesAppchain Role
cc-rag-plus-plus33,274Native vector similarity precompile
cc-inscription22,881Native inscription validator (the killer feature)
cc-graph-kernel14,953Native context slicing with admissibility tokens
cc-protocol7,429Smart contract type definitions
cc-kernel4,357Ledger/storage layer
cc-semantic-language4,000N'Ko text processing primitives

Appchain spec: 764 lines at `docs/appchain-mining-spec.md` covering mining rules, bridge contracts, economic model, security analysis.

Fork base: Stacks `feat/app-chain-mvp` branch. Alpha quality, predates Nakamoto upgrade. Needs rebase against v3.[ip].

What Gets Embedded as Clarity Native Functions

5 new native functions that no other Stacks appchain has:

(graph-query context predicate depth)     -> context-slice
(verify-admissibility token principal)    -> bool
(rag-search embedding-hash k)            -> (list results)
(render-inscription dynamics claim-type)  -> inscription-id
(analyze-semantic-state text)             -> operator-tree

These run inside the block validator at Rust speed, not Clarity interpreter speed.

5-Phase Build Sequence

### Phase A: Standalone Appchain (4-6 weeks)
- Fork stacks-core, rebase against v3.[ip]
- Write mining contract (agent-weighted, 2-second blocks)
- Boot testnet node
- Gate: Node boots, produces blocks, mines correctly

### Phase B: Graph Kernel Embedding (2-3 weeks)
- Replace PostgresGraphStore with embedded SQLite
- Port 14,953 lines into stacks-node as a Rust module
- Expose `graph-query` and `verify-admissibility` as native functions
- Gate: Clarity contract calls `(graph-query ...)` and gets deterministic results

### Phase C: N'Ko Inscription Native (2 weeks)
- Port cc-inscription (22,881 lines) into node
- `render-inscription` becomes native function
- InscriptionId computation happens in consensus (all validators agree)
- Gate: Inscription committed via Clarity, verified by all nodes

### Phase D: RAG++ Vector Search (3-4 weeks)
- Extract core algorithm from cc-rag-plus-plus (remove pgvector dependency)
- Fixed-size embeddings (u8[256])
- `rag-search` as native precompile (500 gas per query)
- Gate: Contract queries vector similarity, gets ranked results

### Phase E: ΨChain Activation (2 weeks)
- Connect all 5 native functions
- Deploy EPOCH V2 contracts on the appchain
- Migrate inscriptions from Stacks L1 to appchain
- Revenue ring operates on dedicated chain
- Gate: Full epoch rotation (6-phase) running with native services

Why This Matters

MetricCurrent (L1 + Docker)Appchain (Native Rust)
Block time10 min (Stacks L1)2 seconds
GK query~50ms (HTTP + network)~1ms (in-process)
InscriptionExternal service callConsensus-validated
RAG searchDocker container + pgvectorNative precompile
ThroughputShared with all Stacks appsDedicated blockspace
Daily inscriptionsLimited by L1 fees~3.6 MB/year, feasible

Critical Risks

1. Rebase risk: feat/app-chain-mvp predates Nakamoto. Rebase may break.
- Fallback: Cosmos SDK with Bitcoin sidechain bridge
2. GPL v3: All code in stacks-core fork inherits GPL v3. EPOCH Rust crates become open source.
3. Validator determinism: All native functions must produce identical results across all nodes. No floating point, no randomness, no external I/O.
4. Maintenance burden: Keeping a Stacks fork in sync with upstream requires ongoing effort.

First Step

bash
git clone https://github.com/stacks-network/stacks-blockchain.git Desktop/stacks-appchain
cd Desktop/stacks-appchain
git checkout feat/app-chain-mvp
git checkout -b epoch-appchain-v1
# Attempt rebase against latest
git rebase origin/develop

If rebase succeeds, the path is clear. If it fails catastrophically, evaluate Cosmos SDK alternative.

Promotion Decision

Promote into a technical note or architecture paper with implementation anchors.

Source Anchor

omega-output/epoch-v2-upgrade-20260320/06-appchain-architecture.md

Detected Structure

Method · Evaluation · Architecture · is Stage Research