diff --git a/Cargo.lock b/Cargo.lock index 7d362077c1..124a72ffd2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -286,6 +286,7 @@ dependencies = [ "poly-commitment", "rand", "rayon", + "serde", "strum", "strum_macros", ] diff --git a/arrabiata/Cargo.toml b/arrabiata/Cargo.toml index 64e50b49ae..599b627ec9 100644 --- a/arrabiata/Cargo.toml +++ b/arrabiata/Cargo.toml @@ -31,5 +31,6 @@ once_cell.workspace = true poly-commitment.workspace = true rand.workspace = true rayon.workspace = true +serde.workspace = true strum.workspace = true strum_macros.workspace = true \ No newline at end of file diff --git a/arrabiata/src/columns.rs b/arrabiata/src/columns.rs index 3402b55d76..42c32236aa 100644 --- a/arrabiata/src/columns.rs +++ b/arrabiata/src/columns.rs @@ -1,8 +1,11 @@ -use kimchi::circuits::{ - berkeley_columns::BerkeleyChallengeTerm, - expr::{CacheId, ConstantExpr, Expr, FormattedOutput}, +use ark_ff::Field; +use kimchi::circuits::expr::{AlphaChallengeTerm, CacheId, ConstantExpr, Expr, FormattedOutput}; +use serde::{Deserialize, Serialize}; +use std::{ + collections::HashMap, + fmt::{Display, Formatter, Result}, + ops::Index, }; -use std::collections::HashMap; use strum_macros::{EnumCount as EnumCountMacro, EnumIter}; /// This enum represents the different gadgets that can be used in the circuit. @@ -48,8 +51,64 @@ pub enum Column { X(usize), } -// FIXME: We should use something different than BerkeleyChallengeTerm here -pub type E = Expr, Column>; +pub struct Challenges { + /// Challenge used to aggregate the constraints + pub alpha: F, + + /// Both challenges used in the permutation argument + pub beta: F, + pub gamma: F, + + /// Challenge to homogenize the constraints + pub homogenous_challenge: F, + + /// Random coin used to aggregate witnesses while folding + pub r: F, +} + +#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub enum ChallengeTerm { + /// Challenge used to aggregate the constraints + Alpha, + /// Both challenges used in the permutation argument + Beta, + Gamma, + /// Challenge to homogenize the constraints + HomogenousChallenge, + /// Random coin used to aggregate witnesses while folding + R, +} + +impl Display for ChallengeTerm { + fn fmt(&self, f: &mut Formatter) -> Result { + match self { + ChallengeTerm::Alpha => write!(f, "alpha"), + ChallengeTerm::Beta => write!(f, "beta"), + ChallengeTerm::Gamma => write!(f, "gamma"), + ChallengeTerm::HomogenousChallenge => write!(f, "u"), + ChallengeTerm::R => write!(f, "r"), + } + } +} +impl Index for Challenges { + type Output = F; + + fn index(&self, term: ChallengeTerm) -> &Self::Output { + match term { + ChallengeTerm::Alpha => &self.alpha, + ChallengeTerm::Beta => &self.beta, + ChallengeTerm::Gamma => &self.gamma, + ChallengeTerm::HomogenousChallenge => &self.homogenous_challenge, + ChallengeTerm::R => &self.r, + } + } +} + +impl<'a> AlphaChallengeTerm<'a> for ChallengeTerm { + const ALPHA: Self = Self::Alpha; +} + +pub type E = Expr, Column>; // Code to allow for pretty printing of the expressions impl FormattedOutput for Column {