Skip to content

Commit

Permalink
move validation to relevant structs
Browse files Browse the repository at this point in the history
  • Loading branch information
neotheprogramist committed Jan 8, 2024
1 parent 5d4ae1a commit 8acd2c7
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 73 deletions.
1 change: 1 addition & 0 deletions src/common.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod array_extend;
mod array_split;
mod consts;
mod merge_sort;
mod asserts;

#[cfg(test)]
mod tests;
File renamed without changes.
2 changes: 1 addition & 1 deletion src/fri/fri_config.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::traits::TryInto;
use core::traits::Into;
use cairo_verifier::{
common::math::{pow, Felt252PartialOrd}, table_commitment::TableCommitmentConfig,
structs::stark_config::FriConfig as FriConfigInputStruct, validation::asserts::assert_in_range,
structs::stark_config::FriConfig as FriConfigInputStruct, common::asserts::assert_in_range,
vector_commitment::vector_commitment::{validate_vector_commitment, VectorCommitmentConfig},
};

Expand Down
2 changes: 1 addition & 1 deletion src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod table_commitment;
mod validation;
mod vector_commitment;

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


fn main(x: Array<felt252>) {
Expand Down
48 changes: 47 additions & 1 deletion src/structs/stark_config.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
use cairo_verifier::{
common::asserts::assert_in_range,
fri::fri_config::FriConfig as DeserializationUnfriendlyFriConfig,
table_commitment::TableCommitmentConfig,
vector_commitment::vector_commitment::VectorCommitmentConfig,
vector_commitment::vector_commitment::{VectorCommitmentConfig, validate_vector_commitment},
validation::proof_of_work::proof_of_work_config_validate, fri::fri_config::fri_config_validate,
};

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)]
struct StarkConfig {
traces: TracesConfig,
Expand All @@ -21,12 +27,52 @@ struct StarkConfig {
n_verifier_friendly_commitment_layers: felt252,
}

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

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);

validate_vector_commitment(
stark_config.composition.vector,
log_eval_domain_size,
stark_config.n_verifier_friendly_commitment_layers
);
fri_config_validate(
stark_config.fri.into(),
stark_config.log_n_cosets,
stark_config.n_verifier_friendly_commitment_layers
);
}

#[derive(Drop, Serde)]
struct TracesConfig {
original: TableCommitmentConfig,
interaction: TableCommitmentConfig,
}

// 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, 'Wrong number of columns');
assert(
config.interaction.n_columns == AIR_LAYOUT_N_INTERACTION_COLUMNS, 'Wrong number of 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,
);
}

#[derive(Drop, Serde)]
struct FriConfig {
// Log2 of the size of the input layer to FRI.
Expand Down
8 changes: 7 additions & 1 deletion src/structs/stark_proof.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use cairo_verifier::structs::{
stark_config::StarkConfig, public_input::PublicInput,
stark_config::{StarkConfig, stark_config_validate}, public_input::PublicInput,
stark_unsent_commitment::StarkUnsentCommitment, stark_witness::StarkWitness,
};

const SECURITY_BITS: felt252 = 9;


#[derive(Drop, Serde)]
struct StarkProof {
Expand All @@ -11,3 +13,7 @@ struct StarkProof {
unsent_commitment: StarkUnsentCommitment,
witness: StarkWitness,
}

fn verify_stark_proof(proof: StarkProof) {
stark_config_validate(proof.config, SECURITY_BITS);
}
4 changes: 0 additions & 4 deletions src/validation.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
mod asserts;
mod config;
mod proof_of_work;
mod stark_config;
mod stark;
31 changes: 0 additions & 31 deletions src/validation/config.cairo

This file was deleted.

10 changes: 0 additions & 10 deletions src/validation/stark.cairo

This file was deleted.

24 changes: 0 additions & 24 deletions src/validation/stark_config.cairo

This file was deleted.

0 comments on commit 8acd2c7

Please sign in to comment.