| Crates.io | zyga |
| lib.rs | zyga |
| version | 0.5.1 |
| created_at | 2025-09-03 09:40:36.511877+00 |
| updated_at | 2025-09-26 11:50:44.075865+00 |
| description | ZYGA zero-knowledge proof system - CLI and library for generating ZK proofs |
| homepage | https://github.com/darklakefi/zyga |
| repository | https://github.com/darklakefi/zyga |
| max_upload_size | |
| id | 1822255 |
| size | 9,149,734 |
A high-performance zero-knowledge proof system implementation in Rust, featuring the ZYGA proof system with BN254 elliptic curve pairings. Now with no_std support for embedded and blockchain environments!
cargo install zyga
git clone https://github.com/darklakefi/py-zk-tiago
cd py-zk-tiago/rust
cargo build --release
ZYGA now uses a setup/prove workflow:
zyga setup -c constraints.aoa -o test --prefix test
Outputs:
test.zyga (proving key)test_public_coefficients.rs (public coefficients for on-chain)test_proving_key.rs (static VK elements for on-chain)zyga prove -s test.zyga -w witness.json -o proof.json
Flags:
-v, --verbose: verbose logs--debug-matrices: embed matrices and witness info in output JSONuse zyga::{compile_constraints, generate_trusted_setup, create_pairing_proof};
// Load and compile constraints
let constraints_str = std::fs::read_to_string("constraints.aoa")?;
let compilation_result = compile_constraints(&constraints_str)?;
// Generate trusted setup
let rng = &mut rand::thread_rng();
let trusted_setup = generate_trusted_setup(compilation_result.num_constraints, rng)?;
// Create proof
let proof = create_pairing_proof(
&compilation_result,
&processed_witness,
&trusted_setup,
)?;
--prefixAOA (Arithmetic Operation Algebra) files define the constraint system:
# Variable declarations
decl a[4] privat # Private variables (known only to prover)
decl b[4] public # Public variables (known to verifier)
decl c defer # Deferred variables (provided at verification time)
# Constraints (must be in the form A*B == C)
constraint a[0]*a[0] == b[0]
constraint a[1]*a[1] == b[1]
constraint (a[2]+a[3])*(a[2]-a[3]) == b[2]
Variable types:
privat: Secret inputs known only to the proverpublic: Public inputs known to both prover and verifierdefer: Variables provided by the verifier at verification timeWhen generating a proof, ZYGA automatically creates a public_coefficients.rs file that maps public inputs to their contributions in the verification equation:
// Auto-generated public coefficients for on-chain verification
pub const NUM_PUBLIC_INPUTS: usize = 4;
pub const PUBLIC_INPUT_NAMES: [&str; 4] = ["b[0]", "b[1]", "b[2]", "b[3]"];
// Coefficients for computing a2, b2, c2 from public inputs
pub const PUBLIC_COEFFICIENTS: [InputCoefficients; 4] = [
InputCoefficients { coeff_a: 0, coeff_b: 1, coeff_c: 0 },
// ... more coefficients
];
This file is used by the on-chain verifier to compute the verification equation without needing the full constraint system. It is auto-generated during setup and should not be edited.
The crate is organized into several modules:
constraint: Constraint system compilation and processing (std only)polynomial: Polynomial arithmetic and Lagrange interpolation (std only)pairing: BN254 pairing-based proof generation (std only)symbol: Symbolic value processing for witness handling (std only)code_generation: Generate verifier code for on-chain deployment (std only)verification: On-chain proof verification for Solana BPF (no_std compatible)dag: Expression DAG for constraint evaluation (std only)errors: Error types (always available)common: Shared types for G1/G2 points and proof elements (always available)Create a proof that you know values whose squares equal public values:
# constraints.aoa
decl secret[4] privat
decl squares[4] public
constraint secret[0]*secret[0] == squares[0]
constraint secret[1]*secret[1] == squares[1]
constraint secret[2]*secret[2] == squares[2]
constraint secret[3]*secret[3] == squares[3]
# witness.json
{
"secret": [1, 2, 3, 4],
"squares": [1, 4, 9, 16]
}
# Generate proof
zyga -c constraints.aoa -w witness.json -o proof.json
Prove that one 64-bit number is greater than another:
# uint64-gt.aoa contains bit-by-bit comparison logic
zyga setup -c uint64-gt.aoa -o uint64gt --prefix uint64gt
zyga prove -s uint64gt.zyga -w witness-64.json -o uint64gt_output.json
# Copy generated coefficients for on-chain verification
cp uint64gt_public_coefficients.rs ../onchain-verifier/src/
proof.json contains a single proof object and optional debug data:
{
"pairing_proof": {
"proof": {
"a_curve": "…64-byte hex…",
"g2_b2": "…128-byte hex…",
"c_curve": "…64-byte hex…",
"g1_a2": "…64-byte hex…",
"g1_c2": "…64-byte hex…",
"g1_hz": "…64-byte hex…"
},
"trusted_setup": { "h1": "…", "h2": "…", "alpha": "…", "beta": "…" },
"n_constraints": 1
},
"public_inputs": { "b[0]": 1, "b[1]": 0, … }
}
The on-chain verifier expects:
Proof serialized fields in order: a_curve, g2_b2, c_curve, g1_a2, g1_c2, g1_hz.Vec<i64> (values only) in the transaction; names are used only off-chain.Run the test suite:
# Unit tests
cargo test
# Build and test everything
cargo build --release
cargo test --all-features
MIT
Contributions are welcome! Please feel free to submit a Pull Request.
For more information, visit the GitHub repository.