Skip to content

Commit

Permalink
fri verify config
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Dec 18, 2023
1 parent 1d574e5 commit 4a6194c
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/fri.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod fri_formula;
mod fri_group;
mod fri_layer;
mod fri_config;

#[cfg(test)]
mod tests;
59 changes: 59 additions & 0 deletions src/fri/fri_config.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use core::option::OptionTrait;
use core::array::SpanTrait;
use core::traits::Into;
use cairo_verifier::structs::table_commitment_config::TableCommitmentConfig;

const MAX_LAST_LAYER_LOG_DEGREE_BOUND: u32 = 15;
const MAX_FRI_LAYERS: u32 = 15;
const MAX_FRI_STEP: u32 = 4;

struct FriConfig {
// Log2 of the size of the input layer to FRI.
log_input_size: felt252,
// Number of layers in the FRI. Inner + last layer.
n_layers: felt252,
// Array of size n_layers - 1, each entry is a configuration of a table commitment for the
// corresponding inner layer.
inner_layers: Span<TableCommitmentConfig>,
// Array of size n_layers, each entry represents the FRI step size,
// i.e. the number of FRI-foldings between layer i and i+1.
fri_step_sizes: Span<felt252>,
log_last_layer_degree_bound: felt252,
}

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(), '');
assert(config.log_last_layer_degree_bound.try_into().unwrap() <= MAX_LAST_LAYER_LOG_DEGREE_BOUND, '');

assert(2_u256 <= config.n_layers.into(), '');
assert(config.n_layers.try_into().unwrap() <= MAX_FRI_LAYERS + 1, '');

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

let len: u32 = config.n_layers.try_into().unwrap();
let mut i = 0_u32;
let mut sum_of_step_sizes: felt252 = 0;
let mut log_input_size = config.log_input_size;
loop {
if i == len { break; }
let fri_step: felt252 = *(config.fri_step_sizes.at(i));
assert(1_u32 <= fri_step.try_into().unwrap(), '');
assert(fri_step.try_into().unwrap() <= MAX_FRI_STEP + 1, '');
assert((*(config.inner_layers.at(i))).columns == fri_step * fri_step, '');
i += 1;
log_input_size -= fri_step;
sum_of_step_sizes += fri_step;
// validate_vector_commitment(
// config=layers[0].vector,
// expected_height=log_input_size,
// n_verifier_friendly_commitment_layers=n_verifier_friendly_commitment_layers,
// );
};


let log_expected_input_degree = sum_of_step_sizes + config.log_last_layer_degree_bound;
assert(log_expected_input_degree + log_n_cosets == config.log_input_size, '');
log_expected_input_degree
}
12 changes: 12 additions & 0 deletions src/fri/fri_layer.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Constant parameters for computing the next FRI layer.
struct FriLayerComputationParams {
coset_size: felt252,
fri_group: Span<felt252>,
eval_point: felt252,
}

struct FriLayerQuery {
index: felt252,
y_value: felt252,
x_inv_value: felt252,
}
1 change: 0 additions & 1 deletion src/structs.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
mod fri_config;
mod proof_of_work_config;
mod stark_config;
mod stark_proof;
Expand Down
15 changes: 0 additions & 15 deletions src/structs/fri_config.cairo

This file was deleted.

2 changes: 1 addition & 1 deletion src/structs/stark_config.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cairo_verifier::structs::traces_config::TracesConfig;
use cairo_verifier::structs::table_commitment_config::TableCommitmentConfig;
use cairo_verifier::structs::fri_config::FriConfig;
use cairo_verifier::fri::fri_config::FriConfig;
use cairo_verifier::structs::proof_of_work_config::ProofOfWorkConfig;

struct StarkConfig {
Expand Down
1 change: 1 addition & 0 deletions src/structs/table_commitment_config.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cairo_verifier::structs::vector_commitment_config::VectorCommitmentConfig;

#[derive(Drop, Copy)]
struct TableCommitmentConfig {
columns: felt252,
vector: VectorCommitmentConfig
Expand Down
1 change: 1 addition & 0 deletions src/structs/vector_commitment_config.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[derive(Drop, Copy)]
struct VectorCommitmentConfig {
height: felt252,
verifier_friendly_commitment_layers: felt252,
Expand Down

0 comments on commit 4a6194c

Please sign in to comment.