Skip to content

Commit

Permalink
stark config validate in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
neotheprogramist committed Jan 4, 2024
1 parent bc1ba04 commit ed01aa9
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 16 deletions.
10 changes: 3 additions & 7 deletions src/input_structs/stark_config.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use cairo_verifier::vector_commitment::VectorCommitmentConfig;

#[derive(Drop, Serde)]
struct StarkConfig {
traces: TracesConfig,
Expand All @@ -23,16 +25,10 @@ struct TracesConfig {

#[derive(Drop, Serde)]
struct TableCommitmentConfig {
columns: felt252,
n_columns: felt252,
vector: VectorCommitmentConfig
}

#[derive(Drop, Serde)]
struct VectorCommitmentConfig {
height: felt252,
verifier_friendly_commitment_layers: felt252,
}

#[derive(Drop, Serde)]
struct FriConfig {
// Log2 of the size of the input layer to FRI.
Expand Down
3 changes: 2 additions & 1 deletion src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ mod validation;
mod vector_commitment;
mod queries;

use cairo_verifier::input_structs::stark_proof::StarkProof;
use cairo_verifier::{input_structs::stark_proof::StarkProof, validation::stark::verify_stark_proof};

fn main(x: Array<felt252>) {
let mut x_span = x.span();
let stark_proof: StarkProof = Serde::deserialize(ref x_span).unwrap();
verify_stark_proof(stark_proof)
}
4 changes: 4 additions & 0 deletions src/validation.cairo
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
mod asserts;
mod config;
mod proof_of_work;
mod stark_config_validate;
mod stark;
6 changes: 6 additions & 0 deletions src/validation/asserts.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use cairo_verifier::common::math::Felt252PartialOrd;

fn assert_in_range(x: felt252, min: felt252, max: felt252) {
assert(min <= x, 'Value too small');
assert(x < max, 'Value too large');
}
29 changes: 29 additions & 0 deletions src/validation/config.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use cairo_verifier::{
input_structs::stark_config::TracesConfig, validation::asserts::assert_in_range,
vector_commitment::validate_vector_commitment,
fri::fri_config::fri_config_validate,
};

const MAX_N_COLUMNS: felt252 = 128;
const AIR_LAYOUT_N_ORIGINAL_COLUMNS: felt252 = 8;
const AIR_LAYOUT_N_INTERACTION_COLUMNS: felt252 = 8;

// Validates the configuration of the traces.
// log_eval_domain_size - Log2 of the evaluation domain size.
fn traces_config_validate(
config: TracesConfig,
log_eval_domain_size: felt252,
n_verifier_friendly_commitment_layers: felt252,
) {
assert_in_range(config.original.n_columns, 1, MAX_N_COLUMNS + 1);
assert_in_range(config.interaction.n_columns, 1, MAX_N_COLUMNS + 1);
assert(config.original.n_columns == AIR_LAYOUT_N_ORIGINAL_COLUMNS, '');
assert(config.interaction.n_columns == AIR_LAYOUT_N_INTERACTION_COLUMNS, '');

validate_vector_commitment(
config.original.vector, log_eval_domain_size, n_verifier_friendly_commitment_layers,
);
validate_vector_commitment(
config.interaction.vector, log_eval_domain_size, n_verifier_friendly_commitment_layers,
);
}
10 changes: 10 additions & 0 deletions src/validation/proof_of_work.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use cairo_verifier::input_structs::stark_config::ProofOfWorkConfig;
use cairo_verifier::common::math::Felt252PartialOrd;

const MIN_PROOF_OF_WORK_BITS: felt252 = 30;
const MAX_PROOF_OF_WORK_BITS: felt252 = 50;

fn proof_of_work_config_validate(config: ProofOfWorkConfig) {
assert(MIN_PROOF_OF_WORK_BITS < config.n_bits, '');
assert(config.n_bits <= MAX_PROOF_OF_WORK_BITS, '');
}
11 changes: 11 additions & 0 deletions src/validation/stark.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use cairo_verifier::{
input_structs::stark_proof::StarkProof,
validation::stark_config_validate::stark_config_validate
};

const SECURITY_BITS: felt252 = 96;


fn verify_stark_proof(proof: StarkProof) {
stark_config_validate(proof.config, SECURITY_BITS);
}
27 changes: 20 additions & 7 deletions src/validation/stark_config_validate.cairo
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
use cairo_verifier::input_structs::stark_config::StarkConfig;
use cairo_verifier::{
input_structs::stark_config::StarkConfig,
validation::{proof_of_work::proof_of_work_config_validate, config::traces_config_validate},
vector_commitment::validate_vector_commitment, fri::fri_config::fri_config_validate,
};

fn stark_config_validate(stark_config: StarkConfig) {}
fn stark_config_validate(stark_config: StarkConfig, security_bits: felt252) {
proof_of_work_config_validate(stark_config.proof_of_work);

fn proof_of_work_config_validate() {}
let log_eval_domain_size = stark_config.log_trace_domain_size + stark_config.log_n_cosets;
traces_config_validate(stark_config.traces, log_eval_domain_size, security_bits);

fn traces_config_validate() {}
validate_vector_commitment(
stark_config.composition.vector,
log_eval_domain_size,
stark_config.n_verifier_friendly_commitment_layers
);

fn validate_vector_commitment() {}

fn fri_config_validate() {}
// fri_config_validate(
// stark_config.fri,
// stark_config.log_n_cosets,
// stark_config.n_verifier_friendly_commitment_layers
// );
}
2 changes: 1 addition & 1 deletion src/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)]
#[derive(Drop, Copy, Serde)]
struct VectorCommitmentConfig {
height: felt252,
n_verifier_friendly_commitment_layers: felt252,
Expand Down

0 comments on commit ed01aa9

Please sign in to comment.