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 operationsC- The circuit witness type that this prover was compiled for
§Workflow
- Create via
crate::Prover::compile_circuit() - Perform trusted setup with
CircuitProver::setup() - Generate proofs with
CircuitProver::prove() - Verify proofs with
CircuitProver::verify()
Implementations§
Source§impl<B, C> CircuitProver<B, C>where
B: Backend,
C: CircuitWitness,
impl<B, C> CircuitProver<B, C>where
B: Backend,
C: CircuitWitness,
Sourcepub fn setup(&self) -> Result<(B::ProvingKey, B::VerifyingKey)>
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.
Sourcepub fn prove(
&self,
proving_key: &B::ProvingKey,
circuit_witness: &C,
) -> Result<Proof>
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 byCircuitProver::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
Sourcepub fn verify(
&self,
verifying_key: &B::VerifyingKey,
proof: &Proof,
public_witness: C::PublicWitness,
) -> Result<()>where
C::PublicWitness: CircuitPublicWitness,
pub fn verify(
&self,
verifying_key: &B::VerifyingKey,
proof: &Proof,
public_witness: C::PublicWitness,
) -> Result<()>where
C::PublicWitness: CircuitPublicWitness,
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 byCircuitProver::setup()proof- The proof to verifypublic_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.