Skip to content

Commit

Permalink
domains impl
Browse files Browse the repository at this point in the history
  • Loading branch information
neotheprogramist committed Jan 10, 2024
1 parent e174bc3 commit 3343630
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/common/consts.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const STARK_PRIME: u256 =
3618502788666131213697322783095070105623107215331596699973092056135872020481;
const STARK_PRIME_MINUS_ONE: felt252 =
3618502788666131213697322783095070105623107215331596699973092056135872020480;
const STARK_PRIME_MINUS_TWO: felt252 =
3618502788666131213697322783095070105623107215331596699973092056135872020479;

Expand Down
47 changes: 47 additions & 0 deletions src/domains.cairo
Original file line number Diff line number Diff line change
@@ -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,
}
}
}
1 change: 1 addition & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod air;
mod channel;
mod common;
mod deserialization;
mod domains;
mod fri;
mod oods;
mod proof_of_work;
Expand Down
3 changes: 2 additions & 1 deletion src/stark.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 3343630

Please sign in to comment.