Zero-knowledge proof SQL engine for verifiable query execution.
ZK-SQL executes SQL queries and generates zero-knowledge proofs that verify correctness without revealing underlying data. Built on Goldilocks field arithmetic and FRI-based proving.
- Goldilocks field for fast arithmetic
- Recursive proof aggregation
- Poseidon hash-based Merkle commitments
- SQL operations: SELECT, WHERE, JOIN, subqueries, INSERT/UPDATE/DELETE
- GPU-accelerated proving
- WASM bindings for browser/Node.js
Data layer (Poseidon hash, Merkle trees, commitments) → Compiler (SQL parser, circuit generation) → Prover (FRI proofs, recursive aggregation, GPU acceleration). SQL layer handles queries, mutations, and WASM bindings.
git clone https://github.com/nzengi/zk-sql
cd zk-sql
cargo build --release
cargo test
cargo run --release -- demoWASM builds:
cargo install wasm-pack
wasm-pack build --target web --features wasm
wasm-pack build --target nodejs --features wasmCreate tables, commit them to Merkle trees, then execute queries that generate zero-knowledge proofs. The engine supports standard SQL operations including JOINs, subqueries, aggregations, window functions, and mutations.
See the examples directory for implementation details.
zk-sql demo
zk-sql query --sql "SELECT * FROM employees WHERE age > 30" --verbose
zk-sql commit --data employees.csv
zk-sql verify --proof proof.bin --root 0x1234...
zk-sql bench --rows 10000WHERE clauses (equality, inequality, comparisons), boolean operators (AND/OR/NOT), aggregations (COUNT, SUM, AVG, MIN, MAX), JOINs (INNER, LEFT, RIGHT, CROSS), subqueries (IN, EXISTS, scalar), mutations (INSERT, UPDATE, DELETE), GROUP BY with HAVING, and window functions (ROW_NUMBER, RANK, DENSE_RANK, running aggregates, LEAD/LAG, FIRST_VALUE/LAST_VALUE).
Rough benchmarks on M1 Pro: Merkle commits scale linearly (~50ms for 10K rows), query execution ~10ms for 10K rows, proof generation ~1s for 10K rows. GPU acceleration provides ~3x speedup for Merkle tree operations. Distributed proving with 8 workers reduces proof time proportionally.
Uses Goldilocks field (p = 2^64 - 2^32 + 1) for fast arithmetic. Poseidon hash (width 12, rate 8, capacity 4, 8 full + 22 partial rounds) for Merkle commitments. FRI-based proving with folding factor 4, blowup 8, targeting ~100 bits security.
Core features implemented: Poseidon hash, Merkle trees, SQL parser/executor, R1CS constraints, FRI proving, recursive proofs, JOINs, subqueries, mutations, GPU acceleration, WASM bindings, GROUP BY/HAVING, window functions, distributed proving.
Pull requests welcome. See CONTRIBUTING.md for guidelines.
MIT