From 33436305f75bc4b5749a8b0f12ba96fde8fccb00 Mon Sep 17 00:00:00 2001 From: Neo Date: Wed, 10 Jan 2024 12:02:48 +0100 Subject: [PATCH 1/2] domains impl --- src/common/consts.cairo | 2 ++ src/domains.cairo | 47 +++++++++++++++++++++++++++++++++++++++++ src/lib.cairo | 1 + src/stark.cairo | 3 ++- 4 files changed, 52 insertions(+), 1 deletion(-) 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 dd8b9ec24..a33558d37 100644 --- a/src/stark.cairo +++ b/src/stark.cairo @@ -4,6 +4,7 @@ use cairo_verifier::{ traces::{TracesUnsentCommitment, TracesDecommitment, TracesWitness} }, fri::{fri_config::{FriConfig, FriConfigTrait}, fri::{FriUnsentCommitment, FriWitness}}, + domains::StarkDomainsImpl, table_commitment::{TableCommitmentConfig, TableCommitmentWitness, TableDecommitment}, proof_of_work::{ config::{ProofOfWorkConfig, ProofOfWorkConfigTrait}, @@ -33,10 +34,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, From d4715694bdd91890f5e3d7ce034b8634f69976ab Mon Sep 17 00:00:00 2001 From: Neo Date: Wed, 10 Jan 2024 12:06:03 +0100 Subject: [PATCH 2/2] derive Copy for StarkDomains for consistency --- src/domains.cairo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/domains.cairo b/src/domains.cairo index 26247ed40..e1db84264 100644 --- a/src/domains.cairo +++ b/src/domains.cairo @@ -5,7 +5,7 @@ use cairo_verifier::{ }; // Information about the domains that are used in the stark proof. -#[derive(Drop)] +#[derive(Drop, Copy)] struct StarkDomains { // Log2 of the evaluation domain size. log_eval_domain_size: felt252,