Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding comments for clarifying accum #313

Merged
merged 8 commits into from
Jan 16, 2023
Merged
12 changes: 10 additions & 2 deletions risc0/zkp/src/prove/accum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ use crate::{
field::{Elem, ExtElem, Field},
};

/// Tracks plonk accumulations for an execution.
/// Tracks grand product accumulations for PLONK-style permutation arguments.
pub struct Accum<E: Elem> {
/// Total number of cycles in this run.
cycles: usize,

// Plonk kinds and their data.
// We use two PLONK-style grand product accumulation checks;
// one for the memory permutation and a second for a lookup table.
// We have two `kinds`: memory and bytes.
kinds: BTreeMap<String, Vec<E>>,
}

Expand All @@ -38,6 +40,7 @@ impl<E: Elem> Accum<E> {
}
}

// Generates prefix products for grand product accumulation
pub fn calc_prefix_products(&mut self) {
for (_kind, elems) in self.kinds.iter_mut() {
let mut tot = E::ONE;
Expand All @@ -57,6 +60,7 @@ impl<E: Elem> Accum<E> {
}

pub struct Handler<'a, F: Field> {
// p is a mutex lock that contains an Accum structure.
p: &'a Mutex<Accum<F::ExtElem>>,
cycles: usize,
kinds: BTreeMap<String, *mut F::ExtElem>,
Expand Down Expand Up @@ -85,10 +89,14 @@ impl<'a, F: Field> Handler<'a, F> {
}

impl<'a, F: Field> CircuitStepHandler<F::Elem> for Handler<'a, F> {
/// Performs an extern call
fn call(
&mut self,
cycle: usize,
// The name of the extern call to perform.
// Examples include getMajor, ramRead, syscall, etc
name: &str,
// This is an extra string argument that is only used by the `log` extern call.
extra: &str,
args: &[F::Elem],
outs: &mut [F::Elem],
Expand Down