Skip to content

Commit

Permalink
docs(ivc): improve for ValuePowers
Browse files Browse the repository at this point in the history
  • Loading branch information
cyphersnake committed Nov 5, 2024
1 parent 06bd873 commit 6d14858
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/ivc/protogalaxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ mod verify_chip {
/// Powers of one assigned value counted on-circuit
///
/// Since powers are required many times during synthesis, let's keep these values separate
/// ```math
/// x^0, x^1, x^2, x^3, ... x^i, ...
/// ```
pub struct ValuePowers<F: PrimeField> {
powers: Vec<AssignedValue<F>>,
}
Expand All @@ -207,24 +210,27 @@ mod verify_chip {
.expect("Cannot be created without at least one element inside")
}

/// Get from cache or calculate the `exp` degree of original value
///
/// `self.value^exp`
pub fn get_or_eval<const T: usize>(
&mut self,
region: &mut RegionCtx<F>,
main_gate: &MainGate<F, T>,
index: usize,
exp: usize,
) -> Result<AssignedValue<F>, Halo2PlonkError> {
if let Some(value) = self.powers.get(index) {
if let Some(value) = self.powers.get(exp) {
return Ok(value.clone());
}

while self.powers.len() <= index {
while self.powers.len() <= exp {
let value = self.value();
let last = self.powers.last().unwrap();
let new = main_gate.mul(region, value, last)?;
self.powers.push(new);
}

Ok(self.powers.get(index).cloned().unwrap())
Ok(self.powers.get(exp).cloned().unwrap())
}
}

Expand Down

0 comments on commit 6d14858

Please sign in to comment.