Skip to content

nzengi/zk-sql

Repository files navigation

ZK-SQL Engine

Zero-knowledge proof SQL engine for verifiable query execution.

Rust License Version

Overview

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.

Features

  • 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

Architecture

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.

Installation

git clone https://github.com/nzengi/zk-sql
cd zk-sql
cargo build --release
cargo test
cargo run --release -- demo

WASM builds:

cargo install wasm-pack
wasm-pack build --target web --features wasm
wasm-pack build --target nodejs --features wasm

Usage

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

CLI

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 10000

Supported Operations

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

Performance

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.

Implementation Details

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.

Status

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.

Contributing

Pull requests welcome. See CONTRIBUTING.md for guidelines.

License

MIT

References

  • Plonky2 - Proving system reference
  • Poseidon - Hash function specification
  • STARK - Proof system design

About

Zero-knowledge proof SQL engine for verifiable query execution.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages