How spirizeon/dense-zkvm works
1. This repository is a multi-target DenseZK SDK plus consumer apps. The core product is a Rust crate that generates and verifies Groth16 proofs locally; around it are a React Native WASM package, a Flutter mobile app, and a few native/web shell projects for packaging and testing.
2. The central architecture lives in the Rust crate at src/. Its public surface is assembled in src/lib.rs and split into clear subsystems: client for witness generation, prover for Groth16 proving, crypto for Poseidon hashing, rel1cs for circuit-facing data types, error for unified failure handling, and wasm for JavaScript bindings.
3. The main data flow is intentionally two-stage. First, the client computes a lightweight witness from graph-edge inputs such as sender, receiver, and weight. Second, the local prover takes that witness plus public inputs like graph root and threshold, produces a Groth16 proof, verifies it immediately, and returns the proof bytes only if verification succeeds.
4. The cryptographic boundary is explicit. src/crypto/poseidon.rs handles Poseidon hashing over the BN254 scalar field, while the prover layer uses arkworks crates for Groth16, BN254 elliptic-curve arithmetic, serialization, and constraint-system handling. This keeps hash computation separate from proof construction.
5. src/rel1cs/ holds the circuit-oriented types that connect application inputs to the proving system. These types represent the witness/public-input shape that the prover expects, which is the architectural seam between domain data and zero-knowledge machinery.
6. The proving subsystem is local and self-contained. The README makes clear that setup, proving, verification, and serialization all happen in-process; there is no required remote proving service in the main path. The proof artifact returned to callers is a compressed canonical serialization of the Groth16 proof plus the root commitment echoed back for context.
7. There are two Rust entrypoints beyond the library. src/main.rs is the runnable example path, src/bin/stress.rs is for throughput/load testing, and src/bin/server.rs suggests an optional server wrapper or demo endpoint built on top of the same SDK core.
8. The WASM boundary is handled in src/wasm.rs. That module exists to expose the Rust SDK to JavaScript environments, enabling React Native and web usage through wasm-bindgen and serde-wasm-bindgen. The repo’s react-native-sdk/ package is the TypeScript-facing wrapper around those bindings.
9. react-native-sdk/src/index.ts and types.ts are the JS/TS API layer. This package is not the prover itself; it is the consumption layer that initializes the WASM module and presents a small client/prover API to React Native apps.
10. The Flutter app under densezk_mobile_app/ is a separate cross-platform client shell. Its lib/ tree is organized into screens, provider/state management, a service layer, models, and a reusable result card widget. The named screens indicate user flows for executing the DenseZK pipeline, generating witnesses, computing Poseidon hashes, proving, and running stress tests.
11. Platform folders under the Flutter app (android, ios, web, linux, macos, windows) are standard Flutter host targets, not distinct business logic. Their role is to package the same UI/state flow across devices; the core architectural decision is that proof generation remains local to the device/runtime, while the host layers only provide app shells.
12. The repo also includes docs (docs/ARCHITECTURE.md, docs/API_REFERENCE.md) and a tau.ptau trusted-setup artifact at the root, which reinforces that this is a ZK proving SDK with setup material checked into the project boundary. Overall, the diagram should center on a local witness-and-proof pipeline, with separate adapters for Rust CLI/native, WASM/React Native, and Flutter UI consumers.
Main entry points: main.dart Mobile app · lib.rs SDK API · densezk_api_service.dart API service · mod.rs Prover API
Components 22
Rust SDK
Local witness and Groth16 proving core.
- SDK API · Assembles the public DenseZK surface and re-exports core subsystems.
src/lib.rs - Client · Computes lightweight witness data from graph-edge inputs.
src/client/mod.rs - Client prover · Coordinates the client-side data preparation used before proving.
src/client/prover.rs - Prover API · Defines the proving subsystem interface for local Groth16 execution.
src/prover/mod.rs - Local prover · Generates, verifies, and serializes proofs entirely in-process.
src/prover/local.rs - Crypto · Cryptographic subsystem boundary for field hashing utilities.
src/crypto/mod.rs - Poseidon · Poseidon hashing over the BN254 scalar field.
src/crypto/poseidon.rs - R1CS types · Circuit-facing types that bridge domain inputs into proving structures.
src/rel1cs/mod.rs - Proof inputs · Witness and public-input shapes consumed by the prover.
src/rel1cs/types.rs - Errors · Unified failure handling across client, hashing, and proving.
src/error.rs
Adapters
Bindings and consumer-facing wrappers around the core SDK.
- WASM bridge · Exposes the Rust SDK to JavaScript via wasm-bindgen.
src/wasm.rs - RN API · TypeScript-facing entrypoint for the React Native package.
react-native-sdk/src/index.ts - RN types · Shared TypeScript surface for the React Native wrapper.
react-native-sdk/src/types.ts
Flutter App
Cross-platform mobile and desktop shell for exercising the pipeline.
- Mobile app · Flutter application shell for local DenseZK flows.
densezk_mobile_app/lib/main.dart - State provider · Manages app state and coordinates DenseZK actions.
densezk_mobile_app/lib/providers/densezk_provider.dart - API service · Service layer that invokes DenseZK operations from the UI.
densezk_mobile_app/lib/services/densezk_api_service.dart - Models · App-side data structures for results and flow state.
densezk_mobile_app/lib/models/densezk_models.dart - Execute flow · End-to-end screen for running the DenseZK pipeline.
densezk_mobile_app/lib/screens/execute_flow_screen.dart - Witness screen · UI for witness generation and inspection.
densezk_mobile_app/lib/screens/witness_screen.dart - Prove screen · UI for local proving and proof output.
densezk_mobile_app/lib/screens/prove_screen.dart - Hash screen · UI for Poseidon hash computation.
densezk_mobile_app/lib/screens/poseidon_hash_screen.dart - Stress screen · UI for throughput and load testing.
densezk_mobile_app/lib/screens/stress_test_screen.dart
Connections 27
- SDK API → Client: exports · Public SDK surface includes client witness generation.
- SDK API → Prover API: exports · Public SDK surface includes local proving.
- SDK API → Crypto: exports · Public SDK surface includes cryptographic utilities.
- SDK API → R1CS types: exports · Public SDK surface includes circuit-facing types.
- SDK API → Errors: exports · Unified errors are part of the public API.
- SDK API → WASM bridge: binds · Rust library is exposed to JavaScript through the WASM bridge.
- Client → Client prover: orchestrates · Client prepares witness data for the proving path.
- Client prover → Proof inputs: builds · Witness generation populates circuit-oriented input types.
- Proof inputs → Prover API: feeds · Circuit inputs are consumed by the proving subsystem.
- Prover API → Local prover: implements · Local prover provides the concrete Groth16 execution path.
- Local prover → Poseidon: uses · Proving pipeline depends on Poseidon hashing where needed.
- Local prover → Errors: returns · Proof failures are normalized through the shared error type.
- Poseidon → Crypto: part of · Poseidon is the main crypto primitive exposed by the subsystem.
- WASM bridge → RN API: consumed by · React Native wrapper calls into the WASM module.
- RN API → RN types: uses · TS API is shaped by shared type definitions.
- RN API → Mobile app: drives · Mobile UI consumes the SDK through a higher-level app flow.
- Mobile app → State provider: uses · Flutter app state is managed through provider logic.
- State provider → API service: calls · Provider delegates DenseZK operations to the service layer.
- API service → Client: witness path · App-side service can invoke witness generation in the core pipeline.
- API service → Prover API: prove path · App-side service can invoke local proving in the core pipeline.
- API service → Poseidon: hash path · App-side service can invoke Poseidon hashing in the core pipeline.
- Mobile app → Models: shapes · Screens and providers exchange app-specific result models.
- Mobile app → Execute flow: navigates · Primary UI includes the end-to-end execution flow.
- Mobile app → Witness screen: navigates · Primary UI includes witness generation tooling.
- Mobile app → Prove screen: navigates · Primary UI includes proof generation tooling.
- Mobile app → Hash screen: navigates · Primary UI includes hash computation tooling.
- Mobile app → Stress screen: navigates · Primary UI includes throughput testing tooling.