sonobe-docs/src/usage/fold.md
src/usage/fold.mdRaw
1# Fold
2
3We plug our `FCircuit` into the library:
4
5```rust
6// The idea here is that eventually we could replace the next line chunk that defines the
7// `type NOVA = Nova<...>` by using another folding scheme that fulfills the `FoldingScheme`
8// trait, and the rest of our code would be working without needing to be updated.
9type NOVA = Nova<
10 Projective,
11 GVar,
12 Projective2,
13 GVar2,
14 Sha256FCircuit<Fr>,
15 KZG<'static, Bn254>,
16 Pedersen<Projective2>,
17>;
18
19let num_steps = 10;
20let initial_state = vec![Fr::from(1_u32)];
21
22let F_circuit = Sha256FCircuit::<Fr>::new(());
23
24println!("Prepare Nova ProverParams & VerifierParams");
25let (prover_params, verifier_params) = nova_setup::<Sha256FCircuit<Fr>>(F_circuit);
26
27println!("Initialize FoldingScheme");
28let mut folding_scheme = NOVA::init(&prover_params, F_circuit, initial_state.clone()).unwrap();
29
30// compute a step of the IVC
31for i in 0..num_steps {
32 let start = Instant::now();
33 // here we pass an empty vec since it does not use external_inputs
34 folding_scheme.prove_step(vec![]).unwrap();
35 println!("Nova::prove_step {}: {:?}", i, start.elapsed());
36}
37
38let (running_instance, incoming_instance, cyclefold_instance) = folding_scheme.instances();
39
40println!("Run the Nova's IVC verifier");
41NOVA::verify(
42 verifier_params,
43 initial_state,
44 folding_scheme.state(), // latest state
45 Fr::from(num_steps as u32),
46 running_instance,
47 incoming_instance,
48 cyclefold_instance,
49)
50.unwrap();
51```