add to book
This commit is contained in:
parent
64b8693f91
commit
eef763321a
4 changed files with 90 additions and 14 deletions
|
@ -251,11 +251,26 @@ mod tests {
|
|||
use zokrates_ast::ir::Prog;
|
||||
use zokrates_field::PallasField;
|
||||
|
||||
fn test<T: NovaField>(program: Prog<T>, initial_state: Vec<T>, step_privates: Vec<Vec<T>>, expected_final_state: Vec<T>) {
|
||||
fn test<T: NovaField>(
|
||||
program: Prog<T>,
|
||||
initial_state: Vec<T>,
|
||||
step_privates: Vec<Vec<T>>,
|
||||
expected_final_state: Vec<T>,
|
||||
) {
|
||||
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(
|
||||
|
|
|
@ -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)
|
||||
|
|
45
zokrates_book/src/toolbox/experimental.md
Normal file
45
zokrates_book/src/toolbox/experimental.md
Normal file
|
@ -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
|
3
zokrates_cli/examples/book/nova_step.zok
Normal file
3
zokrates_cli/examples/book/nova_step.zok
Normal file
|
@ -0,0 +1,3 @@
|
|||
def main(public field sum, private field element) -> field {
|
||||
return sum + element;
|
||||
}
|
Loading…
Reference in a new issue