Nova/src/traits/circuit.rs
src/traits/circuit.rsRaw
1//! This module defines traits that a step function must implement
2use bellperson::{gadgets::num::AllocatedNum, ConstraintSystem, SynthesisError};
3use core::marker::PhantomData;
4use ff::PrimeField;
5
6/// A helper trait for a step of the incremental computation (i.e., circuit for F)
7pub trait StepCircuit<F: PrimeField>: Send + Sync + Clone {
8 /// Sythesize the circuit for a computation step and return variable
9 /// that corresponds to the output of the step z_{i+1}
10 fn synthesize<CS: ConstraintSystem<F>>(
11 &self,
12 cs: &mut CS,
13 z: AllocatedNum<F>,
14 ) -> Result<AllocatedNum<F>, SynthesisError>;
15
16 /// return the output of the step when provided with with the step's input
17 fn output(&self, z: &F) -> F;
18}
19
20/// A trivial step circuit that simply returns the input
21#[derive(Clone, Debug, Default)]
22pub struct TrivialTestCircuit<F: PrimeField> {
23 _p: PhantomData<F>,
24}
25
26impl<F> StepCircuit<F> for TrivialTestCircuit<F>
27where
28 F: PrimeField,
29{
30 fn synthesize<CS: ConstraintSystem<F>>(
31 &self,
32 _cs: &mut CS,
33 z: AllocatedNum<F>,
34 ) -> Result<AllocatedNum<F>, SynthesisError> {
35 Ok(z)
36 }
37
38 fn output(&self, z: &F) -> F {
39 *z
40 }
41}