diff --git a/src/fri/fri_config.cairo b/src/fri/fri_config.cairo index 21232cb59..5ec9146aa 100644 --- a/src/fri/fri_config.cairo +++ b/src/fri/fri_config.cairo @@ -1,12 +1,12 @@ -use cairo_verifier::vector_commitment::vector_commitment::VectorCommitmentConfigTrait; use cairo_verifier::{ + common::{asserts::assert_in_range, math::{pow, Felt252PartialOrd}}, table_commitment::TableCommitmentConfig, - vector_commitment::vector_commitment::VectorCommitmentConfig, + vector_commitment::vector_commitment::{VectorCommitmentConfig, VectorCommitmentConfigTrait}, }; -const MAX_LAST_LAYER_LOG_DEGREE_BOUND: u32 = 15; -const MAX_FRI_LAYERS: u32 = 15; -const MAX_FRI_STEP: u32 = 4; +const MAX_LAST_LAYER_LOG_DEGREE_BOUND: felt252 = 15; +const MAX_FRI_LAYERS: felt252 = 15; +const MAX_FRI_STEP: felt252 = 4; #[derive(Drop, Copy)] struct FriConfig { @@ -28,44 +28,38 @@ impl FriConfigImpl of FriConfigTrait { fn validate( self: @FriConfig, log_n_cosets: felt252, n_verifier_friendly_commitment_layers: felt252 ) -> felt252 { - let n_layers: u32 = (*self.n_layers).try_into().unwrap(); - let log_last_layer_degree_bound: u32 = (*self.log_last_layer_degree_bound) - .try_into() - .unwrap(); - - assert(log_last_layer_degree_bound <= MAX_LAST_LAYER_LOG_DEGREE_BOUND, 'Value too big'); - + assert_in_range(*self.n_layers, 2, MAX_FRI_LAYERS + 1); + assert( + *self.log_last_layer_degree_bound <= MAX_LAST_LAYER_LOG_DEGREE_BOUND, 'Value too big' + ); assert(*self.fri_step_sizes[0] == 0, 'Invalid value'); - assert(n_layers >= 2, 'Value too small'); - assert(n_layers <= MAX_FRI_LAYERS + 1, 'Value too big'); - let mut i: u32 = 1; - let mut sum_of_step_sizes: felt252 = 0; + let n_layers: u32 = (*self.n_layers).try_into().unwrap(); + let mut sum_of_step_sizes = 0; let mut log_input_size = *self.log_input_size; loop { if i == n_layers { break; } - let fri_step: felt252 = *self.fri_step_sizes[i]; - let table_commitment = *self.inner_layers[i]; - - let fri_step_u32: u32 = fri_step.try_into().unwrap(); - assert(fri_step_u32 >= 1, 'Value too small'); - assert(fri_step_u32 <= MAX_FRI_STEP + 1, 'Value too big'); - assert(table_commitment.n_columns == fri_step * fri_step, 'Invalid value'); - + let fri_step = *self.fri_step_sizes[i]; + let table_commitment: TableCommitmentConfig = *self.inner_layers[i - 1]; log_input_size -= fri_step; sum_of_step_sizes += fri_step; + assert_in_range(fri_step, 1, MAX_FRI_STEP + 1); + assert(table_commitment.n_columns == pow(2, fri_step), 'Invalid value'); table_commitment.vector.validate(log_input_size, n_verifier_friendly_commitment_layers); i += 1; }; let log_expected_input_degree = sum_of_step_sizes + *self.log_last_layer_degree_bound; - assert(log_expected_input_degree + log_n_cosets == *self.log_input_size, ''); + assert( + log_expected_input_degree + log_n_cosets == *self.log_input_size, + 'Log input size mismatch' + ); log_expected_input_degree } } diff --git a/src/lib.cairo b/src/lib.cairo index 39871a834..9586bf0eb 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -11,11 +11,14 @@ mod stark; mod table_commitment; mod vector_commitment; -use cairo_verifier::{deserialization::stark::StarkProofWithSerde, stark::StarkProof,}; +use cairo_verifier::{ + deserialization::stark::StarkProofWithSerde, stark::{StarkProof, StarkProofImpl} +}; fn main(x: Array) { let mut x_span = x.span(); let stark_proof: StarkProof = Serde::::deserialize(ref x_span) .unwrap() .into(); + stark_proof.verify(); }