# spirizeon/dense-zkvm architecture

> Architecture diagram of the GitHub repository spirizeon/dense-zkvm, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/spirizeon/dense-zkvm
- Repository: https://github.com/spirizeon/dense-zkvm

## Overview

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: [`densezk_mobile_app/lib/main.dart`](https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/main.dart) (Mobile app), [`src/lib.rs`](https://github.com/spirizeon/dense-zkvm/blob/main/src/lib.rs) (SDK API), [`densezk_mobile_app/lib/services/densezk_api_service.dart`](https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/services/densezk_api_service.dart) (API service), [`src/prover/mod.rs`](https://github.com/spirizeon/dense-zkvm/blob/main/src/prover/mod.rs) (Prover API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_rust_core["Rust SDK"]
  node_lib["SDK API<br/>rust crate entry<br/>[lib.rs]"]
  node_client["Client<br/>witness builder<br/>[mod.rs]"]
  node_client_prover["Client prover<br/>witness orchestration<br/>[prover.rs]"]
  node_prover_mod["Prover API<br/>proof facade<br/>[mod.rs]"]
  node_local_prover["Local prover<br/>groth16 engine<br/>[local.rs]"]
  node_crypto_mod["Crypto<br/>hashing boundary<br/>[mod.rs]"]
  node_poseidon["Poseidon<br/>hash function<br/>[poseidon.rs]"]
  node_rel1cs_mod["R1CS types<br/>circuit types<br/>[mod.rs]"]
  node_rel1cs_types["Proof inputs<br/>data model<br/>[types.rs]"]
  node_error["Errors<br/>error model<br/>[error.rs]"]
end

subgraph group_adapters["Adapters"]
  node_wasm["WASM bridge<br/>js binding<br/>[wasm.rs]"]
  node_rn_sdk_index["RN API<br/>ts wrapper<br/>[index.ts]"]
  node_rn_sdk_types["RN types<br/>ts types<br/>[types.ts]"]
end

subgraph group_flutter_app["Flutter App"]
  node_mobile_main["Mobile app<br/>flutter shell<br/>[main.dart]"]
  node_mobile_provider["State provider<br/>flutter state"]
  node_mobile_service["API service<br/>flutter service"]
  node_mobile_models["Models"]
  node_mobile_execute["Execute flow<br/>screen"]
  node_mobile_witness["Witness screen"]
  node_mobile_prove["Prove screen<br/>[prove_screen.dart]"]
  node_mobile_hash["Hash screen"]
  node_mobile_stress["Stress screen"]
end

node_lib -->|"exports"| node_client
node_lib -->|"exports"| node_prover_mod
node_lib -->|"exports"| node_crypto_mod
node_lib -->|"exports"| node_rel1cs_mod
node_lib -->|"exports"| node_error
node_lib -->|"binds"| node_wasm
node_client -->|"orchestrates"| node_client_prover
node_client_prover -->|"builds"| node_rel1cs_types
node_rel1cs_types -->|"feeds"| node_prover_mod
node_prover_mod -->|"implements"| node_local_prover
node_local_prover -->|"uses"| node_poseidon
node_local_prover -->|"returns"| node_error
node_poseidon -->|"part of"| node_crypto_mod
node_wasm -->|"consumed by"| node_rn_sdk_index
node_rn_sdk_index -->|"uses"| node_rn_sdk_types
node_rn_sdk_index -->|"drives"| node_mobile_main
node_mobile_main -->|"uses"| node_mobile_provider
node_mobile_provider -->|"calls"| node_mobile_service
node_mobile_service -->|"witness path"| node_client
node_mobile_service -->|"prove path"| node_prover_mod
node_mobile_service -->|"hash path"| node_poseidon
node_mobile_main -->|"shapes"| node_mobile_models
node_mobile_main -->|"navigates"| node_mobile_execute
node_mobile_main -->|"navigates"| node_mobile_witness
node_mobile_main -->|"navigates"| node_mobile_prove
node_mobile_main -->|"navigates"| node_mobile_hash
node_mobile_main -->|"navigates"| node_mobile_stress

click node_lib "https://github.com/spirizeon/dense-zkvm/blob/main/src/lib.rs"
click node_client "https://github.com/spirizeon/dense-zkvm/blob/main/src/client/mod.rs"
click node_client_prover "https://github.com/spirizeon/dense-zkvm/blob/main/src/client/prover.rs"
click node_prover_mod "https://github.com/spirizeon/dense-zkvm/blob/main/src/prover/mod.rs"
click node_local_prover "https://github.com/spirizeon/dense-zkvm/blob/main/src/prover/local.rs"
click node_crypto_mod "https://github.com/spirizeon/dense-zkvm/blob/main/src/crypto/mod.rs"
click node_poseidon "https://github.com/spirizeon/dense-zkvm/blob/main/src/crypto/poseidon.rs"
click node_rel1cs_mod "https://github.com/spirizeon/dense-zkvm/blob/main/src/rel1cs/mod.rs"
click node_rel1cs_types "https://github.com/spirizeon/dense-zkvm/blob/main/src/rel1cs/types.rs"
click node_error "https://github.com/spirizeon/dense-zkvm/blob/main/src/error.rs"
click node_wasm "https://github.com/spirizeon/dense-zkvm/blob/main/src/wasm.rs"
click node_rn_sdk_index "https://github.com/spirizeon/dense-zkvm/blob/main/react-native-sdk/src/index.ts"
click node_rn_sdk_types "https://github.com/spirizeon/dense-zkvm/blob/main/react-native-sdk/src/types.ts"
click node_mobile_main "https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/main.dart"
click node_mobile_provider "https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/providers/densezk_provider.dart"
click node_mobile_service "https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/services/densezk_api_service.dart"
click node_mobile_models "https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/models/densezk_models.dart"
click node_mobile_execute "https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/screens/execute_flow_screen.dart"
click node_mobile_witness "https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/screens/witness_screen.dart"
click node_mobile_prove "https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/screens/prove_screen.dart"
click node_mobile_hash "https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/screens/poseidon_hash_screen.dart"
click node_mobile_stress "https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/screens/stress_test_screen.dart"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_lib,node_client,node_client_prover,node_prover_mod,node_local_prover,node_crypto_mod,node_poseidon,node_rel1cs_mod,node_rel1cs_types,node_error toneBlue
class node_wasm,node_rn_sdk_index,node_rn_sdk_types toneAmber
class node_mobile_main,node_mobile_provider,node_mobile_service,node_mobile_models,node_mobile_execute,node_mobile_witness,node_mobile_prove,node_mobile_hash,node_mobile_stress toneMint
```

## Components

### Rust SDK

Local witness and Groth16 proving core.

- [SDK API](https://github.com/spirizeon/dense-zkvm/blob/main/src/lib.rs): rust crate entry · Assembles the public DenseZK surface and re-exports core subsystems. · `src/lib.rs`
- [Client](https://github.com/spirizeon/dense-zkvm/blob/main/src/client/mod.rs): witness builder · Computes lightweight witness data from graph-edge inputs. · `src/client/mod.rs`
- [Client prover](https://github.com/spirizeon/dense-zkvm/blob/main/src/client/prover.rs): witness orchestration · Coordinates the client-side data preparation used before proving. · `src/client/prover.rs`
- [Prover API](https://github.com/spirizeon/dense-zkvm/blob/main/src/prover/mod.rs): proof facade · Defines the proving subsystem interface for local Groth16 execution. · `src/prover/mod.rs`
- [Local prover](https://github.com/spirizeon/dense-zkvm/blob/main/src/prover/local.rs): groth16 engine · Generates, verifies, and serializes proofs entirely in-process. · `src/prover/local.rs`
- [Crypto](https://github.com/spirizeon/dense-zkvm/blob/main/src/crypto/mod.rs): hashing boundary · Cryptographic subsystem boundary for field hashing utilities. · `src/crypto/mod.rs`
- [Poseidon](https://github.com/spirizeon/dense-zkvm/blob/main/src/crypto/poseidon.rs): hash function · Poseidon hashing over the BN254 scalar field. · `src/crypto/poseidon.rs`
- [R1CS types](https://github.com/spirizeon/dense-zkvm/blob/main/src/rel1cs/mod.rs): circuit types · Circuit-facing types that bridge domain inputs into proving structures. · `src/rel1cs/mod.rs`
- [Proof inputs](https://github.com/spirizeon/dense-zkvm/blob/main/src/rel1cs/types.rs): data model · Witness and public-input shapes consumed by the prover. · `src/rel1cs/types.rs`
- [Errors](https://github.com/spirizeon/dense-zkvm/blob/main/src/error.rs): error model · Unified failure handling across client, hashing, and proving. · `src/error.rs`

### Adapters

Bindings and consumer-facing wrappers around the core SDK.

- [WASM bridge](https://github.com/spirizeon/dense-zkvm/blob/main/src/wasm.rs): js binding · Exposes the Rust SDK to JavaScript via wasm-bindgen. · `src/wasm.rs`
- [RN API](https://github.com/spirizeon/dense-zkvm/blob/main/react-native-sdk/src/index.ts): ts wrapper · TypeScript-facing entrypoint for the React Native package. · `react-native-sdk/src/index.ts`
- [RN types](https://github.com/spirizeon/dense-zkvm/blob/main/react-native-sdk/src/types.ts): ts 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](https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/main.dart): flutter shell · Flutter application shell for local DenseZK flows. · `densezk_mobile_app/lib/main.dart`
- [State provider](https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/providers/densezk_provider.dart): flutter state · Manages app state and coordinates DenseZK actions. · `densezk_mobile_app/lib/providers/densezk_provider.dart`
- [API service](https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/services/densezk_api_service.dart): flutter service · Service layer that invokes DenseZK operations from the UI. · `densezk_mobile_app/lib/services/densezk_api_service.dart`
- [Models](https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/models/densezk_models.dart): flutter models · App-side data structures for results and flow state. · `densezk_mobile_app/lib/models/densezk_models.dart`
- [Execute flow](https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/screens/execute_flow_screen.dart): screen · End-to-end screen for running the DenseZK pipeline. · `densezk_mobile_app/lib/screens/execute_flow_screen.dart`
- [Witness screen](https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/screens/witness_screen.dart): screen · UI for witness generation and inspection. · `densezk_mobile_app/lib/screens/witness_screen.dart`
- [Prove screen](https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/screens/prove_screen.dart): screen · UI for local proving and proof output. · `densezk_mobile_app/lib/screens/prove_screen.dart`
- [Hash screen](https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/screens/poseidon_hash_screen.dart): screen · UI for Poseidon hash computation. · `densezk_mobile_app/lib/screens/poseidon_hash_screen.dart`
- [Stress screen](https://github.com/spirizeon/dense-zkvm/blob/main/densezk_mobile_app/lib/screens/stress_test_screen.dart): screen · UI for throughput and load testing. · `densezk_mobile_app/lib/screens/stress_test_screen.dart`

## Connections

- 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.
