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>,
) -> Result<AllocatedNum<F>, SynthesisError> {
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() {
// Allocate four variables for holding non-deterministic advice: x_i, y_i, x_i_plus_1, y_i_plus_1
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)
})?;
// non deterministic advice
let x_i_plus_1 =
AllocatedNum::alloc(cs.namespace(|| format!("x_i_plus_1_iter_{}", i)), || {
Ok(self.seq[i].x_i_plus_1)
@@ -135,10 +137,14 @@ where
if i == self.seq.len() - 1 {
z_out = poseidon_hash(
cs.namespace(|| "output hash"),
vec![x_i_plus_1, x_i.clone()],
vec![x_i_plus_1.clone(), x_i.clone()],
&self.pc,
);
}
// update x_i and y_i for the next iteration
y_i = x_i;
x_i = x_i_plus_1;
}
z_out
@@ -164,9 +170,12 @@ where
}
fn main() {
let num_steps = 10;
let num_iters_per_step = 10; // number of iterations of MinRoot per Nova's recursive step
println!("Nova-based VDF with MinRoot delay function");
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 circuit_primary = MinRootCircuit {
seq: vec![
@@ -183,8 +192,6 @@ fn main() {
let circuit_secondary = TrivialTestCircuit::default();
println!("Nova-based VDF with MinRoot delay function");
println!("==========================================");
println!(
"Proving {} iterations of MinRoot per step",
num_iters_per_step
@@ -303,4 +310,6 @@ fn main() {
start.elapsed()
);
assert!(res.is_ok());
println!("=========================================================");
}
}