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

Expr: move domain into domains.rs #2704

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions kimchi/src/circuits/berkeley_columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

use crate::{
circuits::{
domains::EvaluationDomains,
domains::{Domain, EvaluationDomains},
expr::{
CacheId, ColumnEnvironment, ColumnEvaluations, ConstantExpr, ConstantTerm, Constants,
Domain, Expr, ExprError, FormattedOutput,
Expr, ExprError, FormattedOutput,
},
gate::{CurrOrNext, GateType},
lookup::{index::LookupSelectors, lookups::LookupPattern},
Expand Down
53 changes: 31 additions & 22 deletions kimchi/src/circuits/domains.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
//! This module describes the evaluation domains that can be used by the
//! polynomials.

use ark_ff::FftField;
use ark_poly::{EvaluationDomain, Radix2EvaluationDomain as Domain};
use ark_poly::{EvaluationDomain, Radix2EvaluationDomain};
use serde::{Deserialize, Serialize};
use serde_with::serde_as;

use crate::error::DomainCreationError;

/// The different multiplicaive domain sizes that can be used by the polynomials.
/// We do support up to 8 times the size of the original domain for now.
#[derive(Clone, Copy, Debug, PartialEq, FromPrimitive, ToPrimitive)]
pub enum Domain {
D1 = 1,
D2 = 2,
D4 = 4,
D8 = 8,
}

#[serde_as]
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct EvaluationDomains<F: FftField> {
#[serde_as(as = "o1_utils::serialization::SerdeAs")]
pub d1: Domain<F>, // size n
pub d1: Radix2EvaluationDomain<F>, // size n
#[serde_as(as = "o1_utils::serialization::SerdeAs")]
pub d2: Domain<F>, // size 2n
pub d2: Radix2EvaluationDomain<F>, // size 2n
#[serde_as(as = "o1_utils::serialization::SerdeAs")]
pub d4: Domain<F>, // size 4n
pub d4: Radix2EvaluationDomain<F>, // size 4n
#[serde_as(as = "o1_utils::serialization::SerdeAs")]
pub d8: Domain<F>, // size 8n
pub d8: Radix2EvaluationDomain<F>, // size 8n
}

impl<F: FftField> EvaluationDomains<F> {
Expand All @@ -24,30 +37,26 @@ impl<F: FftField> EvaluationDomains<F> {
/// `g`, the generator of `d4` is `g^2`, the generator of `d2` is `g^4`, and
/// the generator of `d1` is `g^8`.
pub fn create(n: usize) -> Result<Self, DomainCreationError> {
let n = Domain::<F>::compute_size_of_domain(n)
let n = Radix2EvaluationDomain::<F>::compute_size_of_domain(n)
.ok_or(DomainCreationError::DomainSizeFailed(n))?;

let d1 = Domain::<F>::new(n).ok_or(DomainCreationError::DomainConstructionFailed(
"d1".to_string(),
n,
))?;
let d1 = Radix2EvaluationDomain::<F>::new(n).ok_or(
DomainCreationError::DomainConstructionFailed("d1".to_string(), n),
)?;

// we also create domains of larger sizes
// to efficiently operate on polynomials in evaluation form.
// (in evaluation form, the domain needs to grow as the degree of a
// polynomial grows)
let d2 = Domain::<F>::new(2 * n).ok_or(DomainCreationError::DomainConstructionFailed(
"d2".to_string(),
2 * n,
))?;
let d4 = Domain::<F>::new(4 * n).ok_or(DomainCreationError::DomainConstructionFailed(
"d4".to_string(),
4 * n,
))?;
let d8 = Domain::<F>::new(8 * n).ok_or(DomainCreationError::DomainConstructionFailed(
"d8".to_string(),
8 * n,
))?;
let d2 = Radix2EvaluationDomain::<F>::new(2 * n).ok_or(
DomainCreationError::DomainConstructionFailed("d2".to_string(), 2 * n),
)?;
let d4 = Radix2EvaluationDomain::<F>::new(4 * n).ok_or(
DomainCreationError::DomainConstructionFailed("d4".to_string(), 4 * n),
)?;
let d8 = Radix2EvaluationDomain::<F>::new(8 * n).ok_or(
DomainCreationError::DomainConstructionFailed("d8".to_string(), 8 * n),
)?;

// ensure the relationship between the three domains in case the
// library's behavior changes
Expand Down
9 changes: 1 addition & 8 deletions kimchi/src/circuits/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
berkeley_columns,
berkeley_columns::BerkeleyChallengeTerm,
constraints::FeatureFlags,
domains::Domain,
gate::CurrOrNext,
lookup::lookups::{LookupPattern, LookupPatterns},
polynomials::{
Expand Down Expand Up @@ -992,14 +993,6 @@ where
}
}

#[derive(Clone, Copy, Debug, PartialEq, FromPrimitive, ToPrimitive)]
pub enum Domain {
D1 = 1,
D2 = 2,
D4 = 4,
D8 = 8,
}

#[derive(Clone)]
enum EvalResult<'a, F: FftField> {
Constant(F),
Expand Down
4 changes: 2 additions & 2 deletions msm/src/column_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use ark_poly::{Evaluations, Radix2EvaluationDomain};
use crate::{logup, logup::LookupTableID, witness::Witness};
use kimchi::circuits::{
berkeley_columns::{BerkeleyChallengeTerm, BerkeleyChallenges},
domains::EvaluationDomains,
expr::{ColumnEnvironment as TColumnEnvironment, Constants, Domain},
domains::{Domain, EvaluationDomains},
expr::{ColumnEnvironment as TColumnEnvironment, Constants},
};

/// The collection of polynomials (all in evaluation form) and constants
Expand Down
11 changes: 6 additions & 5 deletions o1vm/src/pickles/column_env.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use ark_ff::FftField;
use ark_poly::{Evaluations, Radix2EvaluationDomain};

use crate::interpreters::mips::{column::N_MIPS_SEL_COLS, witness::SCRATCH_SIZE};
use crate::{
interpreters::mips::{column::N_MIPS_SEL_COLS, witness::SCRATCH_SIZE},
pickles::proof::WitnessColumns,
};
use kimchi::circuits::{
berkeley_columns::{BerkeleyChallengeTerm, BerkeleyChallenges},
domains::EvaluationDomains,
expr::{ColumnEnvironment as TColumnEnvironment, Constants, Domain},
domains::{Domain, EvaluationDomains},
expr::{ColumnEnvironment as TColumnEnvironment, Constants},
};

use super::proof::WitnessColumns;

type Evals<F> = Evaluations<F, Radix2EvaluationDomain<F>>;

/// The collection of polynomials (all in evaluation form) and constants
Expand Down