use ark_ff::FftField;
use ark_poly::{EvaluationDomain, Radix2EvaluationDomain};
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use crate::error::DomainCreationError;
#[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: Radix2EvaluationDomain<F>, #[serde_as(as = "o1_utils::serialization::SerdeAs")]
pub d2: Radix2EvaluationDomain<F>, #[serde_as(as = "o1_utils::serialization::SerdeAs")]
pub d4: Radix2EvaluationDomain<F>, #[serde_as(as = "o1_utils::serialization::SerdeAs")]
pub d8: Radix2EvaluationDomain<F>, }
impl<F: FftField> EvaluationDomains<F> {
pub fn create(n: usize) -> Result<Self, DomainCreationError> {
let n = Radix2EvaluationDomain::<F>::compute_size_of_domain(n)
.ok_or(DomainCreationError::DomainSizeFailed(n))?;
let d1 = Radix2EvaluationDomain::<F>::new(n).ok_or(
DomainCreationError::DomainConstructionFailed("d1".to_string(), 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),
)?;
assert_eq!(d2.group_gen.square(), d1.group_gen);
assert_eq!(d4.group_gen.square(), d2.group_gen);
assert_eq!(d8.group_gen.square(), d4.group_gen);
Ok(EvaluationDomains { d1, d2, d4, d8 })
}
}