//! This module defines traits that a step function must implement use bellperson::{gadgets::num::AllocatedNum, ConstraintSystem, SynthesisError}; use core::marker::PhantomData; use ff::PrimeField; /// A helper trait for a step of the incremental computation (i.e., circuit for F) pub trait StepCircuit: Send + Sync + Clone { /// Return the the number of inputs or outputs of each step /// (this method is called only at circuit synthesis time) /// `synthesize` and `output` methods are expected to take as /// input a vector of size equal to arity and output a vector of size equal to arity fn arity(&self) -> usize; /// Sythesize the circuit for a computation step and return variable /// that corresponds to the output of the step z_{i+1} fn synthesize>( &self, cs: &mut CS, z: &[AllocatedNum], ) -> Result>, SynthesisError>; /// return the output of the step when provided with with the step's input fn output(&self, z: &[F]) -> Vec; } /// A trivial step circuit that simply returns the input #[derive(Clone, Debug, Default)] pub struct TrivialTestCircuit { _p: PhantomData, } impl StepCircuit for TrivialTestCircuit where F: PrimeField, { fn arity(&self) -> usize { 1 } fn synthesize>( &self, _cs: &mut CS, z: &[AllocatedNum], ) -> Result>, SynthesisError> { Ok(z.to_vec()) } fn output(&self, z: &[F]) -> Vec { z.to_vec() } }