diff --git a/zokrates_bellperson/src/nova.rs b/zokrates_bellperson/src/nova.rs index 7ab65cd2..7d3850b2 100644 --- a/zokrates_bellperson/src/nova.rs +++ b/zokrates_bellperson/src/nova.rs @@ -251,11 +251,26 @@ mod tests { use zokrates_ast::ir::Prog; use zokrates_field::PallasField; - fn test(program: Prog, initial_state: Vec, step_privates: Vec>, expected_final_state: Vec) { + fn test( + program: Prog, + initial_state: Vec, + step_privates: Vec>, + expected_final_state: Vec, + ) { let steps_count = step_privates.len(); let params = generate_public_parameters(program.clone()).unwrap(); - let proof = prove(¶ms, program.clone(), initial_state.clone(), step_privates).unwrap().unwrap(); - assert_eq!(verify(¶ms, proof, steps_count, initial_state).unwrap(), expected_final_state); + let proof = prove( + ¶ms, + program.clone(), + initial_state.clone(), + step_privates, + ) + .unwrap() + .unwrap(); + assert_eq!( + verify(¶ms, proof, steps_count, initial_state).unwrap(), + expected_final_state + ); } #[test] @@ -272,7 +287,12 @@ mod tests { statements: vec![Statement::constraint(Variable::new(0), Variable::public(0))], }; - test(program, vec![PallasField::from(0)], vec![vec![]; 3], vec![PallasField::from(0)]); + test( + program, + vec![PallasField::from(0)], + vec![vec![]; 3], + vec![PallasField::from(0)], + ); } #[test] @@ -286,7 +306,12 @@ mod tests { )], }; - test(program, vec![PallasField::from(3)], vec![vec![]; 3], vec![PallasField::from(6)]); + test( + program, + vec![PallasField::from(3)], + vec![vec![]; 3], + vec![PallasField::from(6)], + ); } #[test] @@ -346,7 +371,7 @@ mod tests { vec![PallasField::from(2)], vec![PallasField::from(3)], ], - vec![PallasField::from(8)] + vec![PallasField::from(8)], ); } @@ -367,14 +392,16 @@ mod tests { Parameter::private(Variable::new(3)), ], return_count: 2, - statements: vec![Statement::constraint( - LinComb::from(Variable::new(0)) + LinComb::from(Variable::new(2)), - Variable::public(0), - ), - Statement::constraint( - LinComb::from(Variable::new(1)) + LinComb::from(Variable::new(3)), - Variable::public(1), - )], + statements: vec![ + Statement::constraint( + LinComb::from(Variable::new(0)) + LinComb::from(Variable::new(2)), + Variable::public(0), + ), + Statement::constraint( + LinComb::from(Variable::new(1)) + LinComb::from(Variable::new(3)), + Variable::public(1), + ), + ], }; test( diff --git a/zokrates_book/src/SUMMARY.md b/zokrates_book/src/SUMMARY.md index 5d2830cb..84c8ef69 100644 --- a/zokrates_book/src/SUMMARY.md +++ b/zokrates_book/src/SUMMARY.md @@ -27,6 +27,7 @@ - [ZIR](toolbox/ir.md) - [JSON ABI](toolbox/abi.md) - [zokrates.js](toolbox/zokrates_js.md) + - [Experimental](toolbox/experimental.md) - [Examples](examples/index.md) - [A SNARK Powered RNG](examples/rng_tutorial.md) diff --git a/zokrates_book/src/toolbox/experimental.md b/zokrates_book/src/toolbox/experimental.md new file mode 100644 index 00000000..57f5c6c5 --- /dev/null +++ b/zokrates_book/src/toolbox/experimental.md @@ -0,0 +1,45 @@ +# Experimental features + +ZoKrates supports some experimental features. + +## Nova + +ZoKrates supports the `nova` proof system using the `bellperson` backend. Nova is accessed with the subcommand `nova`. + +### API + +To use Nova, programs must have the following signature, for any types `State` and `StepInput`: + +``` +def main(public State state, private StepInput step_input) -> State +``` + +Then, using Nova lets the user prove many steps of this program, given an initial state. + +For example: + +``` +{{#include ../../../zokrates_cli/examples/book/nova_step.zok}} +``` + +We compile this program using the Pallas curve: + +```bash +zokrates compile -i sum.zok --curve pallas +``` + +Then we can prove three iterations as follows: + +```bash +echo "\"0\"" > init.json +echo "[\"1\", \"7\", \"42\"]" > steps.json +zokrates nova prove +``` + +The proof created at `proof.json` proves the statement `0 + 1 + 7 + 42 == 50`. + +### Limitations + +- The step circuit must be compiled with `--curve pallas` +- The resulting recursive proof cannot currently be verified on the EVM +- The public parameters are currently computed for each proof \ No newline at end of file diff --git a/zokrates_cli/examples/book/nova_step.zok b/zokrates_cli/examples/book/nova_step.zok new file mode 100644 index 00000000..15072a56 --- /dev/null +++ b/zokrates_cli/examples/book/nova_step.zok @@ -0,0 +1,3 @@ +def main(public field sum, private field element) -> field { + return sum + element; +} \ No newline at end of file