From 4ce243b22d06272652a09ea73859f1f812acf070 Mon Sep 17 00:00:00 2001 From: Neo Date: Wed, 10 Jan 2024 12:02:48 +0100 Subject: [PATCH] domains impl --- src/common/consts.cairo | 2 ++ src/domains.cairo | 47 +++++++++++++++++++++++++++++++++++++++++ src/lib.cairo | 1 + src/stark.cairo | 4 ++-- 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/domains.cairo diff --git a/src/common/consts.cairo b/src/common/consts.cairo index 56ffa41ea..45399a7ea 100644 --- a/src/common/consts.cairo +++ b/src/common/consts.cairo @@ -1,5 +1,7 @@ const STARK_PRIME: u256 = 3618502788666131213697322783095070105623107215331596699973092056135872020481; +const STARK_PRIME_MINUS_ONE: felt252 = + 3618502788666131213697322783095070105623107215331596699973092056135872020480; const STARK_PRIME_MINUS_TWO: felt252 = 3618502788666131213697322783095070105623107215331596699973092056135872020479; diff --git a/src/domains.cairo b/src/domains.cairo new file mode 100644 index 000000000..26247ed40 --- /dev/null +++ b/src/domains.cairo @@ -0,0 +1,47 @@ +use core::traits::Div; +use cairo_verifier::{ + common::{consts::{FIELD_GENERATOR, STARK_PRIME_MINUS_ONE}, math::{pow, mul_inverse}}, + stark::StarkConfig, +}; + +// Information about the domains that are used in the stark proof. +#[derive(Drop)] +struct StarkDomains { + // Log2 of the evaluation domain size. + log_eval_domain_size: felt252, + // The evaluation domain size. + eval_domain_size: felt252, + // The generator of the evaluation domain (a primitive root of unity of order eval_domain_size). + eval_generator: felt252, + // Log2 of the trace domain size. + log_trace_domain_size: felt252, + // The trace domain size. + trace_domain_size: felt252, + // The generator of the trace domain (a primitive root of unity of order trace_domain_size). + trace_generator: felt252, +} + +#[generate_trait] +impl StarkDomainsImpl of StarkDomainsTrait { + fn new(stark_config: @StarkConfig) -> StarkDomains { + // Compute stark_domains. + let log_eval_domain_size = *stark_config.log_trace_domain_size + *stark_config.log_n_cosets; + let eval_domain_size = pow(2, log_eval_domain_size); + let eval_generator = pow( + FIELD_GENERATOR, STARK_PRIME_MINUS_ONE * mul_inverse(eval_domain_size) + ); + let trace_domain_size = pow(2, *stark_config.log_trace_domain_size); + let trace_generator = pow( + FIELD_GENERATOR, STARK_PRIME_MINUS_ONE * mul_inverse(trace_domain_size) + ); + + StarkDomains { + log_eval_domain_size, + eval_domain_size, + eval_generator, + log_trace_domain_size: *stark_config.log_trace_domain_size, + trace_domain_size, + trace_generator, + } + } +} diff --git a/src/lib.cairo b/src/lib.cairo index 101a3d8a5..f3ee6f613 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -2,6 +2,7 @@ mod air; mod channel; mod common; mod deserialization; +mod domains; mod fri; mod oods; mod proof_of_work; diff --git a/src/stark.cairo b/src/stark.cairo index a65ad411d..61fd55aa2 100644 --- a/src/stark.cairo +++ b/src/stark.cairo @@ -7,7 +7,7 @@ use cairo_verifier::{ config::{TracesConfig}, public_input::PublicInput, traces::{TracesUnsentCommitment, TracesDecommitment, TracesWitness} }, - fri::{fri_config::FriConfig, fri::{FriUnsentCommitment, FriWitness}}, + domains::StarkDomainsImpl, fri::{fri_config::FriConfig, fri::{FriUnsentCommitment, FriWitness}}, table_commitment::{TableCommitmentConfig, TableCommitmentWitness, TableDecommitment}, proof_of_work::{config::ProofOfWorkConfig, proof_of_work::ProofOfWorkUnsentCommitment}, }; @@ -33,10 +33,10 @@ struct StarkProof { impl StarkProofImpl of StarkProofTrait { fn verify(self: @StarkProof) { self.config.validate(SECURITY_BITS); + let stark_domains = StarkDomainsImpl::new(self.config); } } - #[derive(Drop, Copy)] struct StarkConfig { traces: TracesConfig,