Skip to content

Commit

Permalink
Change the starting point of logup elements (#837)
Browse files Browse the repository at this point in the history
* modify logup elements

* add the test

* fmt
  • Loading branch information
weikengchen authored Sep 17, 2024
1 parent cdf66f3 commit a51f630
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
37 changes: 27 additions & 10 deletions crates/prover/src/constraint_framework/logup.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ops::{Mul, Sub};

use itertools::Itertools;
use itertools::{zip_eq, Itertools};
use num_traits::{One, Zero};

use super::EvalAtRow;
Expand Down Expand Up @@ -109,14 +109,9 @@ impl<const N: usize> LookupElements<N> {
where
EF: Copy + Zero + From<F> + From<SecureField> + Mul<F, Output = EF> + Sub<EF, Output = EF>,
{
EF::from(values[0])
+ values[1..]
.iter()
.zip(self.alpha_powers.iter())
.fold(EF::zero(), |acc, (&value, &power)| {
acc + EF::from(power) * value
})
- EF::from(self.z)
zip_eq(values, self.alpha_powers).fold(EF::zero(), |acc, (&value, power)| {
acc + EF::from(power) * value
}) - EF::from(self.z)
}
// TODO(spapini): Try to remove this.
pub fn dummy() -> Self {
Expand Down Expand Up @@ -253,9 +248,12 @@ impl<'a> LogupColGenerator<'a> {
mod tests {
use num_traits::One;

use super::LogupAtRow;
use super::{LogupAtRow, LookupElements};
use crate::constraint_framework::InfoEvaluator;
use crate::core::channel::Blake2sChannel;
use crate::core::fields::m31::BaseField;
use crate::core::fields::qm31::SecureField;
use crate::core::fields::FieldExpOps;
use crate::core::lookups::utils::Fraction;

#[test]
Expand All @@ -267,4 +265,23 @@ mod tests {
Fraction::new(SecureField::one(), SecureField::one()),
);
}

#[test]
fn test_lookup_elements_combine() {
let mut channel = Blake2sChannel::default();
let lookup_elements = LookupElements::<3>::draw(&mut channel);
let values = [
BaseField::from_u32_unchecked(123),
BaseField::from_u32_unchecked(456),
BaseField::from_u32_unchecked(789),
];

assert_eq!(
lookup_elements.combine::<BaseField, SecureField>(&values),
BaseField::from_u32_unchecked(123)
+ BaseField::from_u32_unchecked(456) * lookup_elements.alpha
+ BaseField::from_u32_unchecked(789) * lookup_elements.alpha.pow(2)
- lookup_elements.z
);
}
}
2 changes: 1 addition & 1 deletion crates/prover/src/examples/poseidon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const INTERNAL_ROUND_CONSTS: [BaseField; N_PARTIAL_ROUNDS] =

pub type PoseidonComponent = FrameworkComponent<PoseidonEval>;

pub type PoseidonElements = LookupElements<{ N_STATE * 2 }>;
pub type PoseidonElements = LookupElements<N_STATE>;

#[derive(Clone)]
pub struct PoseidonEval {
Expand Down

0 comments on commit a51f630

Please sign in to comment.