A Rust implementation of the Libra zero-knowledge proof protocol for verifiable computation on layered circuits.
Libra is an efficient zero-knowledge argument system that enables a prover to convince a verifier that they correctly executed a computation represented as a layered arithmetic circuit. This implementation provides:
- Two-phase sumcheck protocol for efficient verification
- Support for layered circuits with addition and multiplication gates
- Integration with Plonky3 field arithmetic and extensions
- Non-interactive proofs via Fiat-Shamir transformation
src/proof.rs- Libra proof data structuressrc/libra_sumcheck.rs- Two-phase Libra sumcheck implementationsrc/prover.rs- Proof generation logicsrc/verifier.rs- Proof verification logicsrc/utils.rs- Utility functions and algorithmssrc/tests.rs- Comprehensive test suite
- Rust 1.70 or later
- Cargo
Add to your Cargo.toml:
[dependencies]
libra = { git = "https://github.com/sublinearlabs/libra.git" }
circuits = { git = "https://github.com/sublinearlabs/sl-core.git" }
p3-mersenne-31 = "0.2.0"p3-field = "0.2.0"use circuits::{
interface::CircuitTr,
layered_circuit::{LayeredCircuit,
primitives::{Gate,GateOp,Layer},},};use p3_mersenne_31::Mersenne31;use p3_field::extension::BinomialExtensionField;use libra::{prover::prove, verifier::verify, proof::LibraProof};typeF = Mersenne31;typeE = BinomialExtensionField<Mersenne31,3>;fnmain() -> Result<(),Box<dyn std::error::Error>>{// Create a layered circuitlet circuit = LayeredCircuit::new(vec![Layer::new(vec![Gate::new(GateOp::Mul,[0,1]),Gate::new(GateOp::Add,[2,3]),Gate::new(GateOp::Add,[4,5]),Gate::new(GateOp::Mul,[6,7]),]),Layer::new(vec![Gate::new(GateOp::Mul,[0,1]),Gate::new(GateOp::Add,[2,3]),]),Layer::new(vec![Gate::new(GateOp::Mul,[0,1])]),]);// Prepare inputlet input:Vec<F> = [1,2,3,2,1,2,4,1].into_iter().map(F::from_canonical_usize).collect();// Execute the circuitlet output = circuit.execute(&input);// Generate prooflet proof:LibraProof<F,E> = prove(&circuit, output);// Verify prooflet is_valid = verify(&circuit, proof, input)?;println!("Proof verification: {}", is_valid);Ok(())}Run the test suite:
cargo testRun with output:
cargo test -- --nocaptureRun specific tests:
cargo test test_libra_protocolThe Libra protocol provides:
- Prover time: O(C log C) where C is circuit size
- Verifier time: O(log C)
- Proof size: O(log C)
- Memory usage: Linear in circuit size
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Format code:
cargo fmtRun clippy:
cargo clippy --all-targets --all-features -- -D warningsWe acknowledge the awesome work of the Plonky3 team and the original Libra authors.
This project is licensed under the MIT License - see the LICENSE file for details.