optimize MinRoot constraint system (#101)

* optimize MinRoot constraint system to not allocate unneeded advice variables

run with multiple MinRoot iterations per Nova step in a loop

* fix clippy warnings
This commit is contained in:
Srinath Setty
2022-07-27 15:48:03 -07:00
committed by GitHub
parent 06192ac3d4
commit 111abcab38

View File

@@ -87,14 +87,16 @@ where
z: AllocatedNum<F>, z: AllocatedNum<F>,
) -> Result<AllocatedNum<F>, SynthesisError> { ) -> Result<AllocatedNum<F>, SynthesisError> {
let mut z_out: Result<AllocatedNum<F>, SynthesisError> = Err(SynthesisError::AssignmentMissing); let mut z_out: Result<AllocatedNum<F>, SynthesisError> = Err(SynthesisError::AssignmentMissing);
// allocate variables to hold x_0 and y_0
let x_0 = AllocatedNum::alloc(cs.namespace(|| "x_0"), || Ok(self.seq[0].x_i))?;
let y_0 = AllocatedNum::alloc(cs.namespace(|| "y_0"), || Ok(self.seq[0].y_i))?;
// variables to hold running x_i and y_i
let mut x_i = x_0;
let mut y_i = y_0;
for i in 0..self.seq.len() { for i in 0..self.seq.len() {
// Allocate four variables for holding non-deterministic advice: x_i, y_i, x_i_plus_1, y_i_plus_1 // non deterministic advice
let x_i = AllocatedNum::alloc(cs.namespace(|| format!("x_i_iter_{}", i)), || {
Ok(self.seq[i].x_i)
})?;
let y_i = AllocatedNum::alloc(cs.namespace(|| format!("y_i_iter_{}", i)), || {
Ok(self.seq[i].y_i)
})?;
let x_i_plus_1 = let x_i_plus_1 =
AllocatedNum::alloc(cs.namespace(|| format!("x_i_plus_1_iter_{}", i)), || { AllocatedNum::alloc(cs.namespace(|| format!("x_i_plus_1_iter_{}", i)), || {
Ok(self.seq[i].x_i_plus_1) Ok(self.seq[i].x_i_plus_1)
@@ -135,10 +137,14 @@ where
if i == self.seq.len() - 1 { if i == self.seq.len() - 1 {
z_out = poseidon_hash( z_out = poseidon_hash(
cs.namespace(|| "output hash"), cs.namespace(|| "output hash"),
vec![x_i_plus_1, x_i.clone()], vec![x_i_plus_1.clone(), x_i.clone()],
&self.pc, &self.pc,
); );
} }
// update x_i and y_i for the next iteration
y_i = x_i;
x_i = x_i_plus_1;
} }
z_out z_out
@@ -164,9 +170,12 @@ where
} }
fn main() { fn main() {
let num_steps = 10; println!("Nova-based VDF with MinRoot delay function");
let num_iters_per_step = 10; // number of iterations of MinRoot per Nova's recursive step println!("=========================================================");
let num_steps = 10;
for num_iters_per_step in [1024, 2048, 4096, 8192, 16384, 32768, 65535] {
// number of iterations of MinRoot per Nova's recursive step
let pc = PoseidonConstants::<<G1 as Group>::Scalar, U2>::new_with_strength(Strength::Standard); let pc = PoseidonConstants::<<G1 as Group>::Scalar, U2>::new_with_strength(Strength::Standard);
let circuit_primary = MinRootCircuit { let circuit_primary = MinRootCircuit {
seq: vec![ seq: vec![
@@ -183,8 +192,6 @@ fn main() {
let circuit_secondary = TrivialTestCircuit::default(); let circuit_secondary = TrivialTestCircuit::default();
println!("Nova-based VDF with MinRoot delay function");
println!("==========================================");
println!( println!(
"Proving {} iterations of MinRoot per step", "Proving {} iterations of MinRoot per step",
num_iters_per_step num_iters_per_step
@@ -303,4 +310,6 @@ fn main() {
start.elapsed() start.elapsed()
); );
assert!(res.is_ok()); assert!(res.is_ok());
println!("=========================================================");
}
} }