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:
4- [arkworks](https://github.com/arkworks-rs/r1cs-std)
5- [Circom](https://github.com/iden3/circom)
6- [Noir](https://noir-lang.org/)
7- [Noname](https://github.com/zksecurity/noname)
8
9Defining a circuit to be folded is as simple as fulfilling the `FCircuit` trait interface. Henceforth, integrating a new zk circuits language into Sonobe, can be done by building a wrapper on top of it that satisfies the `FCircuit` trait.
10
11# The `FCircuit` trait
12
13To 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:
14
15```rust
16/// FCircuit defines the trait of the circuit of the F function, which is the one being folded (ie.
17/// inside the agmented F' function).
18/// The parameter z_i denotes the current state, and z_{i+1} denotes the next state after applying
19/// the step.
20pub trait FCircuit<F: PrimeField>: Clone + Debug {
21 type Params: Debug;
22
23 /// returns a new FCircuit instance
24 fn new(params: Self::Params) -> Result<Self, Error>;
25
26 /// returns the number of elements in the state of the FCircuit, which corresponds to the
27 /// FCircuit inputs.
28 fn state_len(&self) -> usize;
29
30 /// returns the number of elements in the external inputs used by the FCircuit. External inputs
31 /// are optional, and in case no external inputs are used, this method should return 0.
32 fn external_inputs_len(&self) -> usize;
33
34 /// computes the next state values in place, assigning z_{i+1} into z_i, and computing the new
35 /// z_{i+1}
36 fn step_native(
37 // this method uses self, so that each FCircuit implementation (and different frontends)
38 // can hold a state if needed to store data to compute the next state.
39 &self,
40 i: usize,
41 z_i: Vec<F>,
42 external_inputs: Vec<F>, // inputs that are not part of the state
43 ) -> Result<Vec<F>, Error>;
44
45 /// generates the constraints for the step of F for the given z_i
46 fn generate_step_constraints(
47 // this method uses self, so that each FCircuit implementation (and different frontends)
48 // can hold a state if needed to store data to generate the constraints.
49 &self,
50 cs: ConstraintSystemRef<F>,
51 i: usize,
52 z_i: Vec<FpVar<F>>,
53 external_inputs: Vec<FpVar<F>>, // inputs that are not part of the state
54 ) -> Result<Vec<FpVar<F>>, SynthesisError>;
55}
56```
57