Prover

Struct Prover 

Source
pub struct Prover<B> { /* private fields */ }
Expand description

High-level prover that orchestrates the zero-knowledge proof generation process.

The Prover serves as the main entry point for creating zero-knowledge proofs using a specific backend implementation. It handles the circuit compilation process and creates circuit-specific provers for actual proof generation.

§Type Parameters

  • B - The backend implementation that defines the underlying cryptographic operations

Implementations§

Source§

impl<B> Prover<B>
where B: Backend,

Source

pub fn new() -> Prover<B>

Creates a new prover instance with the specified backend.

This initializes the backend and prepares the prover for circuit compilation. The backend is created using its Backend::new() method.

§Returns

A new Prover instance ready for circuit compilation.

Examples found in repository?
examples/simple.rs (line 42)
41fn run<B: Backend>() {
42    let prover = Prover::<B>::new();
43
44    let circuit_prover = prover.compile_circuit::<TestCircuit>().unwrap();
45    let (pk, vk) = circuit_prover.setup().unwrap();
46
47    let circuit_witness = Witness::<TestCircuit> {
48        a: 3,
49        b: 4,
50        c: 7, // 3 + 4 = 7
51    };
52
53    let proof = circuit_prover.prove(&pk, &circuit_witness).unwrap();
54
55    let public_witness = circuit_witness.into_public_witness();
56    circuit_prover.verify(&vk, &proof, public_witness).unwrap();
57}
More examples
Hide additional examples
examples/constant.rs (line 45)
44fn run<B: Backend>() {
45    let prover = Prover::<B>::new();
46
47    let circuit_prover = prover.compile_circuit::<TestCircuit>().unwrap();
48    let (pk, vk) = circuit_prover.setup().unwrap();
49
50    let circuit_witness = Witness::<TestCircuit> {
51        a: 3,
52        b: 4,
53        c: 17, // 3 + 4 = 7
54    };
55
56    let proof = circuit_prover.prove(&pk, &circuit_witness).unwrap();
57
58    let public_witness = circuit_witness.into_public_witness();
59    circuit_prover.verify(&vk, &proof, public_witness).unwrap();
60}
examples/generics.rs (line 30)
29fn run() {
30    let prover = Groth16BN254GnarkProver::new();
31
32    let circuit_prover = prover.compile_circuit::<TestCircuit<u32>>().unwrap();
33    let (pk, vk) = circuit_prover.setup().unwrap();
34
35    let circuit_witness = Witness::<TestCircuit<u32>> {
36        a: 3,
37        b: 4,
38        c: 7, // 3 + 4 = 7
39    };
40
41    let proof = circuit_prover.prove(&pk, &circuit_witness).unwrap();
42
43    let public_witness = circuit_witness.into_public_witness();
44    circuit_prover.verify(&vk, &proof, public_witness).unwrap();
45}
examples/subcircuit.rs (line 59)
58fn main() {
59    let prover = PlonkBN254GnarkProver::new();
60
61    let circuit_prover = prover.compile_circuit::<CompositeCircuit>().unwrap();
62    let (pk, vk) = circuit_prover.setup().unwrap();
63
64    // let solidity_contract = vk.export_solidity().unwrap();
65    // println!("Solidity contract: {}", solidity_contract);
66
67    let circuit_witness = Witness::<CompositeCircuit> {
68        adder: Witness::<AdderCircuit> { a: 1, b: 2, sum: 3 },
69        multiplier: Witness::<MultiplierCircuit> {
70            x: 2,
71            y: 3,
72            product: 6,
73        },
74        final_result: 9,
75    };
76
77    let proof = circuit_prover.prove(&pk, &circuit_witness).unwrap();
78
79    let solidity_proof = proof.to_solidity().unwrap();
80    println!("Solidity proof: {:#?}", solidity_proof);
81
82    let public_witness = circuit_witness.into_public_witness();
83    circuit_prover.verify(&vk, &proof, public_witness).unwrap();
84}
Source

pub fn compile_circuit<C>( self, ) -> Result<CircuitProver<B, <C as CircuitElement>::CircuitWitness>, Error>

Compiles a circuit and creates a circuit-specific prover.

This method takes a circuit witness type and compiles it into a form suitable for the backend. It creates the circuit definition by instantiating the circuit with fresh variables and then compiling it using the backend.

§Type Parameters
§Returns

Returns a CircuitProver instance that can be used for setup, proving, and verification operations on the compiled circuit.

§Errors

This function may return an error if:

  • Circuit compilation fails due to invalid constraints
  • The backend cannot represent the circuit
  • Internal compilation errors occur
Examples found in repository?
examples/simple.rs (line 44)
41fn run<B: Backend>() {
42    let prover = Prover::<B>::new();
43
44    let circuit_prover = prover.compile_circuit::<TestCircuit>().unwrap();
45    let (pk, vk) = circuit_prover.setup().unwrap();
46
47    let circuit_witness = Witness::<TestCircuit> {
48        a: 3,
49        b: 4,
50        c: 7, // 3 + 4 = 7
51    };
52
53    let proof = circuit_prover.prove(&pk, &circuit_witness).unwrap();
54
55    let public_witness = circuit_witness.into_public_witness();
56    circuit_prover.verify(&vk, &proof, public_witness).unwrap();
57}
More examples
Hide additional examples
examples/constant.rs (line 47)
44fn run<B: Backend>() {
45    let prover = Prover::<B>::new();
46
47    let circuit_prover = prover.compile_circuit::<TestCircuit>().unwrap();
48    let (pk, vk) = circuit_prover.setup().unwrap();
49
50    let circuit_witness = Witness::<TestCircuit> {
51        a: 3,
52        b: 4,
53        c: 17, // 3 + 4 = 7
54    };
55
56    let proof = circuit_prover.prove(&pk, &circuit_witness).unwrap();
57
58    let public_witness = circuit_witness.into_public_witness();
59    circuit_prover.verify(&vk, &proof, public_witness).unwrap();
60}
examples/generics.rs (line 32)
29fn run() {
30    let prover = Groth16BN254GnarkProver::new();
31
32    let circuit_prover = prover.compile_circuit::<TestCircuit<u32>>().unwrap();
33    let (pk, vk) = circuit_prover.setup().unwrap();
34
35    let circuit_witness = Witness::<TestCircuit<u32>> {
36        a: 3,
37        b: 4,
38        c: 7, // 3 + 4 = 7
39    };
40
41    let proof = circuit_prover.prove(&pk, &circuit_witness).unwrap();
42
43    let public_witness = circuit_witness.into_public_witness();
44    circuit_prover.verify(&vk, &proof, public_witness).unwrap();
45}
examples/subcircuit.rs (line 61)
58fn main() {
59    let prover = PlonkBN254GnarkProver::new();
60
61    let circuit_prover = prover.compile_circuit::<CompositeCircuit>().unwrap();
62    let (pk, vk) = circuit_prover.setup().unwrap();
63
64    // let solidity_contract = vk.export_solidity().unwrap();
65    // println!("Solidity contract: {}", solidity_contract);
66
67    let circuit_witness = Witness::<CompositeCircuit> {
68        adder: Witness::<AdderCircuit> { a: 1, b: 2, sum: 3 },
69        multiplier: Witness::<MultiplierCircuit> {
70            x: 2,
71            y: 3,
72            product: 6,
73        },
74        final_result: 9,
75    };
76
77    let proof = circuit_prover.prove(&pk, &circuit_witness).unwrap();
78
79    let solidity_proof = proof.to_solidity().unwrap();
80    println!("Solidity proof: {:#?}", solidity_proof);
81
82    let public_witness = circuit_witness.into_public_witness();
83    circuit_prover.verify(&vk, &proof, public_witness).unwrap();
84}

Trait Implementations§

Source§

impl<B> Default for Prover<B>
where B: Backend,

Source§

fn default() -> Prover<B>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<B> Freeze for Prover<B>
where B: Freeze,

§

impl<B> RefUnwindSafe for Prover<B>
where B: RefUnwindSafe,

§

impl<B> Send for Prover<B>
where B: Send,

§

impl<B> Sync for Prover<B>
where B: Sync,

§

impl<B> Unpin for Prover<B>
where B: Unpin,

§

impl<B> UnwindSafe for Prover<B>
where B: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.