sonobe-docs/src/usage/frontend.md
src/usage/frontend.mdRaw
1# Frontend
2
3The frontend interface allows to define the circuit to be folded. The currently available frontends are [`circom`](https://github.com/iden3/circom) and [arkworks](https://github.com/arkworks-rs/r1cs-std). We will show here how to define a circuit using `arkworks`.
4
5# The `FCircuit` trait
6
7To be folded with sonobe, a circuit needs to implement the [`FCircuit` trait](https://github.com/privacy-scaling-explorations/sonobe/blob/main/sonobe/src/frontend/mod.rs). This trait defines the methods that sonobe expects from the circuit to be folded. It corresponds to the $F$ function that is being folded. The trait has the following methods:
8
9```rust
10/// FCircuit defines the trait of the circuit of the F function, which is the one being folded (ie.
11/// inside the agmented F' function).
12/// The parameter z_i denotes the current state, and z_{i+1} denotes the next state after applying
13/// the step.
14pub trait FCircuit<F: PrimeField>: Clone + Debug {
15 type Params: Debug;
16
17 /// Returns a new FCircuit instance
18 fn new(params: Self::Params) -> Self;
19
20 /// Returns the number of elements in the state of the FCircuit, which corresponds to the
21 /// FCircuit inputs.
22 fn state_len(&self) -> usize;
23
24 /// Computes the next state values in place, assigning z_{i+1} into z_i, and computing the new
25 /// z_{i+1}
26 fn step_native(
27 // this method uses self, so that each FCircuit implementation (and different frontends)
28 // can hold a state if needed to store data to compute the next state.
29 &self,
30 i: usize,
31 z_i: Vec<F>,
32 ) -> Result<Vec<F>, Error>;
33
34 /// Generates the constraints for the step of F for the given z_i
35 fn generate_step_constraints(
36 // this method uses self, so that each FCircuit implementation (and different frontends)
37 // can hold a state if needed to store data to generate the constraints.
38 &self,
39 cs: ConstraintSystemRef<F>,
40 i: usize,
41 z_i: Vec<FpVar<F>>,
42 ) -> Result<Vec<FpVar<F>>, SynthesisError>;
43}
44```
45