groth16_solana/
lib.rs

1//! # groth16-solana
2//!
3//! Groth16 zero-knowledge proof verification with Solana altbn254 syscalls.
4//!
5//! Verification takes less than 200,000 compute units.
6//!
7//! The syscalls are contained in Solana releases 1.18.x onwards and are active on mainnet-beta.
8//!
9//! Inputs need to be in u8 arrays in big endian.
10//!
11//! See functional test as an example how to use this library.
12//!
13//! This crate is compatible with Groth16 proofs of circom circuits.
14//!
15//! The verifier file can be generated with the java script script from a verifyingkey.json file generated by snarkjs.
16//!
17//! ## Usage:
18//!
19//! ```rust,ignore
20//! let mut public_inputs_vec = Vec::new();
21//! for input in PUBLIC_INPUTS.chunks(32) {
22//!     public_inputs_vec.push(input);
23//! }
24//!
25//! let proof_a: G1 =
26//!     <G1 as FromBytes>::read(&*[&change_endianness(&PROOF[0..64])[..], &[0u8][..]].concat())
27//!         .unwrap();
28//! let mut proof_a_neg = [0u8; 65];
29//! <G1 as ToBytes>::write(&proof_a.neg(), &mut proof_a_neg[..]).unwrap();
30//!
31//! let proof_a = change_endianness(&proof_a_neg[..64]).try_into().unwrap();
32//! let proof_b = PROOF[64..192].try_into().unwrap();
33//! let proof_c = PROOF[192..256].try_into().unwrap();
34//!
35//! let mut verifier = Groth16Verifier::new(
36//!     &proof_a,
37//!     &proof_b,
38//!     &proof_c,
39//!     public_inputs_vec.as_slice(),
40//!     &VERIFYING_KEY,
41//! )
42//! .unwrap();
43//! verifier.verify().unwrap();
44//! ```
45//!
46//! See functional test for a running example how to use this library.
47//!
48pub mod decompression;
49pub mod errors;
50pub mod groth16;