Skip to content

Commit

Permalink
code checked for correctness 2/2
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Dec 22, 2023
1 parent f49f8b0 commit 6057dfc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
27 changes: 13 additions & 14 deletions src/fri/fri_config.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,31 @@ struct FriConfig {
fn fri_config_validate(
config: FriConfig, log_n_cosets: felt252, n_verifier_friendly_commitment_layers: felt252
) -> felt252 {
assert(0_u256 <= config.log_last_layer_degree_bound.into(), 'Invalid value');
assert(
config.log_last_layer_degree_bound.try_into().unwrap() <= MAX_LAST_LAYER_LOG_DEGREE_BOUND,
'Invalid value'
);
let n_layers = config.n_layers.try_into().unwrap();
let log_last_layer_degree_bound = config.log_last_layer_degree_bound.try_into().unwrap();

assert(2_u256 <= config.n_layers.into(), 'Invalid value');
assert(config.n_layers.try_into().unwrap() <= MAX_FRI_LAYERS + 1, 'Invalid value');
assert(log_last_layer_degree_bound >= 0, 'Must be non negative value');
assert(log_last_layer_degree_bound <= MAX_LAST_LAYER_LOG_DEGREE_BOUND, 'Value too big');

assert(*(config.fri_step_sizes[0]) == 0, 'Invalid value');
assert(*config.fri_step_sizes.at(0) == 0, 'Invalid value');

assert(n_layers >= 2, 'Value too small');
assert(n_layers <= MAX_FRI_LAYERS + 1, 'Value too big');

let len: u32 = config.n_layers.try_into().unwrap();
let mut i: u32 = 1;
let mut sum_of_step_sizes: felt252 = 0;
let mut log_input_size = config.log_input_size;
loop {
if i == len {
if i == n_layers {
break;
}

let fri_step: felt252 = *(config.fri_step_sizes.at(i));
let table_commitment = *(config.inner_layers.at(i));
let fri_step: felt252 = *config.fri_step_sizes.at(i);
let table_commitment = *config.inner_layers.at(i);

let fri_step_u32: u32 = fri_step.try_into().unwrap();
assert(1_u32 <= fri_step_u32, 'Invalid value');
assert(fri_step_u32 <= MAX_FRI_STEP + 1, 'Invalid value');
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');

i += 1;
Expand Down
2 changes: 1 addition & 1 deletion src/fri/fri_first_layer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn gather_first_layer_queries(
}

// Translate the coset to the homogenous group to have simple FRI equations.
let shifted_x_value = *(x_values.at(i)) * FIELD_GENERATOR_INVERSE;
let shifted_x_value = (*x_values.at(i)) * FIELD_GENERATOR_INVERSE;

fri_queries
.append(
Expand Down
8 changes: 4 additions & 4 deletions src/fri/fri_formula.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn fri_formula2(f_x: felt252, f_minus_x: felt252, eval_point: felt252, x_inv: fe

// Function to fold 4 elements into one using 2 layers of FRI.
fn fri_formula4(values: Span<felt252>, eval_point: felt252, x_inv: felt252) -> felt252 {
assert(values.len() == 4, 'Values length not equal 4');
assert(values.len() == 4, 'Values length invalid');
// Applying the first layer of folding.
let g0 = fri_formula2(*values[0], *values[1], eval_point, x_inv);
let g1 = fri_formula2(*values[2], *values[3], eval_point, x_inv * OMEGA_4);
Expand All @@ -25,7 +25,7 @@ fn fri_formula4(values: Span<felt252>, eval_point: felt252, x_inv: felt252) -> f

// Function to fold 8 elements into one using 3 layers of FRI.
fn fri_formula8(values: Span<felt252>, eval_point: felt252, x_inv: felt252) -> felt252 {
assert(values.len() == 8, 'Values length not equal 8');
assert(values.len() == 8, 'Values length invalid');
// Applying the first two layers of folding.
let g0 = fri_formula4(values.slice(0, 4), eval_point, x_inv);
let g1 = fri_formula4(values.slice(4, 4), eval_point, x_inv * OMEGA_8);
Expand All @@ -42,7 +42,7 @@ fn fri_formula8(values: Span<felt252>, eval_point: felt252, x_inv: felt252) -> f

// Function to fold 16 elements into one using 4 layers of FRI.
fn fri_formula16(values: Span<felt252>, eval_point: felt252, x_inv: felt252) -> felt252 {
assert(values.len() == 16, 'Values length not equal 16');
assert(values.len() == 16, 'Values length invalid');
// Applying the first three layers of folding.
let g0 = fri_formula8(values.slice(0, 8), eval_point, x_inv);
let g1 = fri_formula8(values.slice(8, 8), eval_point, x_inv * OMEGA_16);
Expand Down Expand Up @@ -72,7 +72,7 @@ fn fri_formula(
} else if (coset_size == 16) {
return fri_formula16(values, eval_point, x_inv);
} else {
assert(values.len() == 2, 'Values length not equal 2');
assert(values.len() == 2, 'Values length invalid');
return fri_formula2(*values[0], *values[1], eval_point, x_inv);
}
}
2 changes: 1 addition & 1 deletion src/fri/fri_last_layer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn verify_last_layer(queries: Span<FriLayerQuery>, coefficients: Span<ChannelSen
let value = horner_eval::horner_eval(
coefficients, math::mul_inverse(*queries.at(i).x_inv_value)
);
assert(value == *queries.at(i).y_value, '');
assert(value == *queries.at(i).y_value, 'Invalid value');
i += 1;
}
}
4 changes: 2 additions & 2 deletions src/fri/fri_layer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn compute_next_layer(
}

let coset_index = *(queries.at(i)).index;
assert(0_u256 <= coset_index.into(), 'Invalid value');
assert(coset_index.into() >= 0_u256, 'Must be non negative value');

verify_indices.append(coset_index);

Expand All @@ -108,7 +108,7 @@ fn compute_next_layer(

// Verify that at least one query was consumed.
let coset_elements_len = coset_elements.len();
assert(0 <= coset_elements_len, 'Invalid value');
assert(coset_elements_len >= 0, 'Must be non negative value');

let coset_elements_span = coset_elements.span();

Expand Down

0 comments on commit 6057dfc

Please sign in to comment.