CircuitProver

Struct CircuitProver 

Source
pub struct CircuitProver<B, C>
where B: Backend,
{ /* private fields */ }
Expand description

Circuit-specific prover for generating and verifying zero-knowledge proofs.

The CircuitProver is created by compiling a specific circuit with a crate::Prover and contains the compiled circuit constraints. It provides methods for performing trusted setup, generating proofs, and verifying proofs for the compiled circuit.

§Type Parameters

  • B - The backend implementation that defines the underlying cryptographic operations
  • C - The circuit witness type that this prover was compiled for

§Workflow

  1. Create via crate::Prover::compile_circuit()
  2. Perform trusted setup with CircuitProver::setup()
  3. Generate proofs with CircuitProver::prove()
  4. Verify proofs with CircuitProver::verify()

Implementations§

Source§

impl<B, C> CircuitProver<B, C>
where B: Backend, C: CircuitWitness,

Source

pub fn setup(&self) -> Result<(B::ProvingKey, B::VerifyingKey)>

Performs the trusted setup phase for this compiled circuit.

This generates the proving and verifying keys that are specific to the compiled circuit constraints. The setup must be performed before any proofs can be generated or verified.

§Returns

Returns a tuple containing the proving key and verifying key on success. The proving key is used for generating proofs, while the verifying key is used for verifying proofs.

§Errors

This function may return an error if the backend’s setup operation fails, which could happen due to:

  • Cryptographic errors during key generation
  • Insufficient randomness for secure setup
  • Backend-specific setup failures
§Security Note

The security of all subsequent proofs depends on this setup being performed correctly and any setup randomness (“toxic waste”) being properly discarded.

Source

pub fn prove( &self, proving_key: &B::ProvingKey, circuit_witness: &C, ) -> Result<Proof>

Generates a zero-knowledge proof for the given circuit witness.

This method creates a proof that demonstrates knowledge of a valid witness satisfying the circuit constraints, without revealing the private components of the witness.

§Arguments
  • proving_key - The proving key generated by CircuitProver::setup()
  • circuit_witness - The complete witness including both public and private values
§Returns

Returns the generated zero-knowledge proof on success.

§Errors

This function may return an error if:

  • The circuit witness does not satisfy the circuit constraints
  • The proving key is incompatible with the circuit
  • Cryptographic operations fail during proof generation
  • The witness values are malformed or invalid
Source

pub fn verify( &self, verifying_key: &B::VerifyingKey, proof: &Proof, public_witness: C::PublicWitness, ) -> Result<()>

Verifies a zero-knowledge proof against the given public witness.

This method checks whether a proof is valid for the specified public inputs, without requiring knowledge of the private witness components that were used to generate the proof.

§Arguments
  • verifying_key - The verifying key generated by CircuitProver::setup()
  • proof - The proof to verify
  • public_witness - The public inputs and outputs that should match the proof
§Returns

Returns Ok(()) if the proof is valid, or an error if verification fails.

§Errors

This function may return an error if:

  • The proof is invalid or malformed
  • The public witness does not match the proof
  • The verifying key is incompatible with the circuit
  • Cryptographic verification operations fail
§Type Constraints

The public witness type must implement CircuitPublicWitness to ensure it can be properly converted to the internal witness format.

Auto Trait Implementations§

§

impl<B, C> Freeze for CircuitProver<B, C>

§

impl<B, C> RefUnwindSafe for CircuitProver<B, C>

§

impl<B, C> Send for CircuitProver<B, C>
where B: Send, <B as Backend>::CircuitConstraint: Send, C: Send,

§

impl<B, C> Sync for CircuitProver<B, C>
where B: Sync, <B as Backend>::CircuitConstraint: Sync, C: Sync,

§

impl<B, C> Unpin for CircuitProver<B, C>
where B: Unpin, <B as Backend>::CircuitConstraint: Unpin, C: Unpin,

§

impl<B, C> UnwindSafe for CircuitProver<B, C>

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, 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.