rSnark
Write zero-knowledge circuits in Rust for multiple prover systems.
rSnark is a Rust library for writing zero-knowledge circuits and generating proofs. It provides a core library to write circuits and a provers library to generate proofs using various backend implementations like Gnark.
Features
- Simple Circuit Definition: Use derive macros to easily define circuits
- Multiple Backend Support: Write circuit once, prover on multiple prover system
- Nested Circuits: Compose complex circuits from simpler ones
- Type Safety: Leverage Rust's type system for circuit safety
Getting Started
Add rSnark to your Cargo.toml:
[]
= "0.1.3"
or use cargo add:
Writing Your First Circuit
Defining a circuit requires two simple steps:
- Define the circuit's inputs and outputs using the
#[derive(Circuit)]macro - Implement the
Circuittrait to define the circuit's constraint rules
Use the following way to define circuit:
use ;
Use these code to generate proof:
let prover = new;
let circuit_prover = prover..unwrap;
let = circuit_prover.setup.unwrap;
let circuit_witness = TestCircuit ;
let proof = circuit_prover.prove.unwrap;
let public_witness = circuit_witness.into_public_witness;
circuit_prover.verify.unwrap;
Circuit Private / Public Inputs
The #[derive(Circuit)] macro treats Rust's visibility modifiers as indicators:
- Fields without
pubare treated as private inputs - Fields with
pubare treated as public inputs
Note: Private inputs has higher priority, This will effect with subcircuit struction.
Export Verifier and Proof
// Export solidity contract from verifying key.
let solidity_contract = vk.export_solidity.unwrap;
// Export solidity proof.
let solidity_proof = proof.to_solidity.unwrap;
We will support these following platform:
- Solidity (with BN256 curve)
- Solana
- Ton
- Move
- ArkWorks
Supported Prover Triples
Similar to compiler target triples, rSnark uses backend triples to define which backend, curve, and proving system to use. The format is: {proving_system}-{curve}-{backend}.
Currently supported backend triples:
Groth16 Proof System
| Triple | Description |
|---|---|
groth16-bn254-gnark |
Groth16 with BN254 curve using Gnark backend |
groth16-bls12_381-gnark |
Groth16 with BLS12-381 curve using Gnark backend |
groth16-bls12_377-gnark |
Groth16 with BLS12-377 curve using Gnark backend |
groth16-bls24_317-gnark |
Groth16 with BLS24-317 curve using Gnark backend |
groth16-bls24_315-gnark |
Groth16 with BLS24-315 curve using Gnark backend |
groth16-bw6_761-gnark |
Groth16 with BW6-761 curve using Gnark backend |
groth16-bw6_633-gnark |
Groth16 with BW6-633 curve using Gnark backend |
plonk-bn254-gnark |
PLONK with BN254 curve using Gnark backend |
plonk-bls12_381-gnark |
PLONK with BLS12-381 curve using Gnark backend |
plonk-bls12_377-gnark |
PLONK with BLS12-377 curve using Gnark backend |
plonk-bls24_317-gnark |
PLONK with BLS24-317 curve using Gnark backend |
plonk-bls24_315-gnark |
PLONK with BLS24-315 curve using Gnark backend |
plonk-bw6_761-gnark |
PLONK with BW6-761 curve using Gnark backend |
plonk-bw6_633-gnark |
PLONK with BW6-633 curve using Gnark backend |
Project Structure
This workspace contains several crates:
rsnark- Main library and unified APIrsnark-core- Core circuit definition and API traitsrsnark-macros- Derive macros for circuit definitionrsnark-provers-core- Common prover traits and interfacesrsnark-provers-gnark- Gnark backend implementationrsnark-provers-mock- Mock prover for testing
Examples
Check out the examples/ directory for more detailed examples of how to use rSnark.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
I'm working on more feature, refer to TODO
Contributions are welcome! Please feel free to submit a Pull Request.