Skip to content

Commit

Permalink
feat: cache alpha powers in static verifier (#1238)
Browse files Browse the repository at this point in the history
* feat: use horner eval in static verifier

* feat: optimize for loop

* feat: remove unnecessary expr

* feat: allocate alpha_c_pow less

* feat: try different order

* feat: cache alpha pow

* feat: add missing alpha

* feat: optimize alpha caching

* feat: minor optimization for alpha caching

* fix: bound
  • Loading branch information
yi-sun authored Jan 21, 2025
1 parent 2da1713 commit a94d0bb
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions extensions/native/recursion/src/fri/two_adic_pcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub fn verify_two_adic_pcs<C: Config>(
builder.set_value(&alpha_pow, j, one_ef);
}
}
let mut alpha_pow_cache = Vec::new();

compile_zip!(builder, query_proof.input_proof, rounds).for_each(|ptr_vec, builder| {
let batch_opening = builder.iter_ptr_get(&query_proof.input_proof, ptr_vec[0]);
Expand Down Expand Up @@ -203,10 +204,34 @@ pub fn verify_two_adic_pcs<C: Config>(
let p_at_x = builder.get(&mat_opening, t);
let p_at_z = builder.get(&ps_at_z, t);

builder.assign(&n, cur_alpha_pow * (p_at_z - p_at_x) + n);
builder.assign(&cur_alpha_pow, cur_alpha_pow * alpha);
if ptr_vec[0].value() == 0 {
if t.value() == 0 && alpha_pow_cache.is_empty() {
alpha_pow_cache.push(builder.constant(C::EF::ONE));
} else if t.value() >= alpha_pow_cache.len() {
let next: Ext<_, _> = builder.uninit();
alpha_pow_cache.push(next);
builder.assign(
&alpha_pow_cache[t.value()],
alpha_pow_cache[t.value() - 1] * alpha,
);
}
}
builder
.assign(&n, (p_at_z - p_at_x) * alpha_pow_cache[t.value()] + n);
});
builder.assign(&cur_ro, cur_ro + n / (z - x));
if ps_at_z.len().value() >= alpha_pow_cache.len() {
let next: Ext<_, _> = builder.uninit();
alpha_pow_cache.push(next);
builder.assign(
&alpha_pow_cache[ps_at_z.len().value()],
alpha_pow_cache[ps_at_z.len().value() - 1] * alpha,
);
}
builder.assign(&cur_ro, cur_ro + cur_alpha_pow * n / (z - x));
builder.assign(
&cur_alpha_pow,
cur_alpha_pow * alpha_pow_cache[ps_at_z.len().value()],
);
} else {
let mat_ro = builder.fri_single_reduced_opening_eval(
alpha,
Expand Down

0 comments on commit a94d0bb

Please sign in to comment.