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

Domains #48

Merged
merged 2 commits into from
Jan 10, 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
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, Copy)]
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