Skip to content

Commit

Permalink
stark_domains_create impl
Browse files Browse the repository at this point in the history
  • Loading branch information
neotheprogramist committed Jan 8, 2024
1 parent af4bafb commit a1a4196
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 9 deletions.
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
44 changes: 44 additions & 0 deletions src/domains.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use core::traits::Div;
use cairo_verifier::{
common::{consts::{FIELD_GENERATOR, STARK_PRIME_MINUS_ONE}, math::{pow, mul_inverse}},
structs::stark_config::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,
}

fn stark_domains_create(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
@@ -1,6 +1,7 @@
mod air;
mod channel;
mod common;
mod domains;
mod fri;
mod structs;
mod oods;
Expand Down
8 changes: 4 additions & 4 deletions src/structs/stark_config.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const MAX_N_COLUMNS: felt252 = 128;
const AIR_LAYOUT_N_ORIGINAL_COLUMNS: felt252 = 12;
const AIR_LAYOUT_N_INTERACTION_COLUMNS: felt252 = 3;

#[derive(Drop, Serde)]
#[derive(Drop, Clone, Serde)]
struct StarkConfig {
traces: TracesConfig,
composition: TableCommitmentConfig,
Expand Down Expand Up @@ -45,7 +45,7 @@ fn stark_config_validate(stark_config: StarkConfig, security_bits: felt252) {
);
}

#[derive(Drop, Serde)]
#[derive(Drop, Clone, Serde)]
struct TracesConfig {
original: TableCommitmentConfig,
interaction: TableCommitmentConfig,
Expand Down Expand Up @@ -73,7 +73,7 @@ fn traces_config_validate(
);
}

#[derive(Drop, Serde)]
#[derive(Drop, Clone, Serde)]
struct FriConfig {
// Log2 of the size of the input layer to FRI.
log_input_size: felt252,
Expand Down Expand Up @@ -120,7 +120,7 @@ impl IntoDeserializationUnfriendlyFriConfig of Into<FriConfig, DeserializationUn
}
}

#[derive(Drop, Serde)]
#[derive(Drop, Clone, Serde)]
struct ProofOfWorkConfig {
// Proof of work difficulty (number of bits required to be 0).
n_bits: felt252,
Expand Down
13 changes: 9 additions & 4 deletions src/structs/stark_proof.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use cairo_verifier::structs::{
stark_config::{StarkConfig, stark_config_validate}, public_input::PublicInput,
stark_unsent_commitment::StarkUnsentCommitment, stark_witness::StarkWitness,
use core::clone::Clone;
use cairo_verifier::{
domains::stark_domains_create,
structs::{
stark_config::{StarkConfig, stark_config_validate}, public_input::PublicInput,
stark_unsent_commitment::StarkUnsentCommitment, stark_witness::StarkWitness,
}
};

const SECURITY_BITS: felt252 = 9;
Expand All @@ -15,5 +19,6 @@ struct StarkProof {
}

fn verify_stark_proof(proof: StarkProof) {
stark_config_validate(proof.config, SECURITY_BITS);
stark_config_validate(proof.config.clone(), SECURITY_BITS);
let stark_domains = stark_domains_create(proof.config.clone());
}
2 changes: 1 addition & 1 deletion src/vector_commitment/vector_commitment.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ struct VectorCommitment {
commitment_hash: felt252
}

#[derive(Drop, Copy, Serde)]
#[derive(Drop, Copy, Clone, Serde)]
struct VectorCommitmentConfig {
height: felt252,
n_verifier_friendly_commitment_layers: felt252,
Expand Down

0 comments on commit a1a4196

Please sign in to comment.