How zorp-corp/nockchain works
Project Type and Purpose
• Nockchain is an open‐source, Rust‐based lightweight blockchain node plus tooling suite, augmented by Hoon smart‐contract code and ZK-proof components. Its goal is on-chain verification of off-chain proofs, supporting verifiable computation and lightweight consensus.
File‐Structure Analysis
• Top‐level crates/ directory holds a federation of Rust packages:
• crates/nockchain → core node logic (consensus, block processing)
• crates/nockchain-libp2p-io → P2P networking layer (libp2p abstractions, metrics)
• crates/nockchain-bitcoin-sync → Bitcoin‐block synchronization as an external data oracle
• crates/wallet → CLI wallet for transaction creation and node interaction
• crates/nockapp → Hoon runtime host, app bootstrap, driver plugins
• crates/sword & crates/zkvm-jetpack → Nock interpreter/JIT (“Sword”), ZK-VM kernels and jets
• crates/kernels, crates/equix-latency → performance kernels and measurement binaries
• hoon/ directory contains pure‐Hoon source: smart contracts, common libraries, proofs, test-jams.
• Key build scripts and toolchain files: Makefile orchestrates choo (Hoon compiler) → Rust code generation, Cargo.toml for each crate, nested-workspace.toml for Hoon→Rust integration.
README Insights
• Workflow:
a. Install choo to compile Hoon code → Rust lib crates under crates/nockapp and hoon/common, hoon/apps
b. Cargo build assembles all Rust crates
c. make run-nockchain-{leader,follower} launches node roles
d. Wallet CLI uses main.rs in crates/wallet to send RPCs to the node
• Off-chain proving: Sword and zkvm-jetpack perform private proofs; crown kernel in nockapp handles on-chain verification.
a. Main Components
• Wallet CLI (crates/wallet)
• Node Core (crates/nockchain)
• P2P Layer (crates/nockchain-libp2p-io)
• Bitcoin‐Sync Oracle (crates/nockchain-bitcoin-sync)
• Hoon Runtime Host (crates/nockapp → crown kernel + drivers)
• Nock Interpreter & ZK-VM (crates/sword, crates/zkvm-jetpack)
• Performance Kernels & Metrics (crates/kernels, crates/equix-latency)
• Persistent Storage (e.g., on-chain database)
• External Services: Bitcoin blockchain network, libp2p peers
b. Relationships & Data Flow
1. Wallet → HTTP/RPC → Node Core
2. Node Core ↔ P2P Layer ↔ Other Peers
3. Node Core → Storage (blocks, chain state)
4. Node Core → Bitcoin-Sync → Bitcoin network
5. Node Core → Hoon Runtime Host (load compiled Hoon smart contracts)
6. Hoon Runtime → Sword & ZK-VM (run/verify proofs)
7. Performance Kernels invoked by Node Core for benchmarking/metrics
c. Architectural Patterns
• Layered modular architecture: CLI, Node Core, Network, Runtime, VM
• Plugin/driver pattern in crown kernel (nockapp/crown/src/drivers)
• Code‐generation pipeline: Hoon → choo → Rust crates → Cargo build
• Off‐chain proving → on‐chain verification separation
d. Technologies & Frameworks
• Rust + Cargo
• libp2p for networking
• choo Hoon compiler
• Nock smart‐contract language (Hoon)
• ZK‐proof VM (zkvm-jetpack)
• Sword Nock interpreter
• Makefile orchestration