Skip to content

Commit

Permalink
fri_decommit skaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Dec 21, 2023
1 parent c20d5d3 commit 0d2d9ec
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 38 deletions.
40 changes: 35 additions & 5 deletions src/fri/fri.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ use cairo_verifier::table_commitment::{
TableCommitment, TableCommitmentConfig, TableUnsentCommitment
};
use core::array::ArrayTrait;
use cairo_verifier::table_commitment::table_commit;
use cairo_verifier::table_commitment::{table_commit, table_decommit};
use cairo_verifier::channel::channel::Channel;
use cairo_verifier::channel::channel::{ChannelUnsentFelt, ChannelSentFelt};
use cairo_verifier::fri::fri_config::FriConfig;
use cairo_verifier::common::math;
use cairo_verifier::table_commitment::TableCommitmentWitness;
use cairo_verifier::table_commitment::{TableCommitmentWitness, TableDecommitment};
use cairo_verifier::fri::fri_first_layer::gather_first_layer_queries;
use cairo_verifier::fri::fri_group::get_fri_group;
use cairo_verifier::fri::fri_layer::FriLayerQuery;
use cairo_verifier::fri::fri_layer::{FriLayerQuery, FriLayerComputationParams, compute_next_layer};

// Commitment values for FRI. Used to generate a commitment by "reading" these values
// from the channel.
Expand Down Expand Up @@ -149,7 +149,7 @@ fn fri_decommit_layers(
layer_witness: Span<FriLayerWitness>,
eval_points: Span<felt252>,
step_sizes: Span<felt252>,
queries: Span<felt252>,
mut queries: Span<FriLayerQuery>,
) -> Array<FriLayerQuery> {
let last_queries = ArrayTrait::<FriLayerQuery>::new();
let len: u32 = n_layers.try_into().unwrap();
Expand All @@ -159,8 +159,28 @@ fn fri_decommit_layers(
if i == len {
break;
}
//

// Params.
let coset_size = math::pow(2, *(step_sizes.at(i)));
let params = FriLayerComputationParams {
coset_size: coset_size, fri_group: fri_group, eval_point: *(eval_points.at(i))
};

// Compute next layer queries.
let (next_queries, verify_indices, verify_y_values) = compute_next_layer(
queries, *(layer_witness.at(i)).leaves, params
);
queries = next_queries.span();

// Table decommitment.
table_decommit(
*commitment.at(i),
verify_indices.span(),
TableDecommitment { values: verify_y_values.span() },
*layer_witness.at(i).table_witness
);

i += 1;
};

last_queries
Expand All @@ -181,4 +201,14 @@ fn fri_decommit(
);

let fri_group = get_fri_group();

let last_queries = fri_decommit_layers(
fri_group.span(),
commitment.config.n_layers - 1,
commitment.inner_layers,
witness.layers,
commitment.eval_points.slice(1, commitment.eval_points.len() - 1),
commitment.config.fri_step_sizes.slice(1, commitment.config.fri_step_sizes.len() - 1),
fri_queries.span(),
);
}
21 changes: 6 additions & 15 deletions src/fri/fri_layer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ struct FriLayerQuery {
// query was consumed by this function.

fn compute_coset_elements(
mut n_queries: felt252,
queries: Span<FriLayerQuery>,
sibling_witness: Span<felt252>,
coset_size: felt252,
Expand All @@ -45,6 +44,7 @@ fn compute_coset_elements(
let mut coset_elements = ArrayTrait::<felt252>::new();
let mut coset_x_inv: felt252 = 0;

let len = queries.len();
let mut i: u32 = 0;
let mut j: u32 = 0;

Expand All @@ -53,10 +53,9 @@ fn compute_coset_elements(
break;
}

if n_queries != 0 && *(queries.at(i)).index == coset_start_index + offset_within_coset {
if i != len && *(queries.at(i)).index == coset_start_index + offset_within_coset {
coset_elements.append(*(queries.at(i)).y_value);
coset_x_inv = (*(queries.at(i)).x_inv_value) * (*(fri_group.at(i)));
n_queries -= 1;
i += 1;
} else {
coset_elements.append(*(sibling_witness.at(j)));
Expand All @@ -81,20 +80,18 @@ fn compute_coset_elements(
// - verify_indices: query indices of the given layer for Merkle verification.
// - verify_y_values: query y values of the given layer for Merkle verification.
fn compute_next_layer(
mut n_queries: felt252,
queries: Span<FriLayerQuery>,
sibling_witness: Span<felt252>,
params: FriLayerComputationParams,
queries: Span<FriLayerQuery>, sibling_witness: Span<felt252>, params: FriLayerComputationParams,
) -> (Array<FriLayerQuery>, Array<felt252>, Array<felt252>) {
let mut next_queries = ArrayTrait::<FriLayerQuery>::new();
let mut verify_indices = ArrayTrait::<felt252>::new();
let mut verify_y_values = ArrayTrait::<felt252>::new();

let coset_size = params.coset_size;

let len = queries.len();
let mut i: u32 = 0;
loop {
if n_queries == 0 {
if i == len {
break;
}

Expand All @@ -104,13 +101,7 @@ fn compute_next_layer(
verify_indices.append(coset_index);

let (coset_elements, coset_x_inv) = compute_coset_elements(
n_queries,
queries,
sibling_witness,
coset_size,
coset_index * coset_size,
0,
params.fri_group
queries, sibling_witness, coset_size, coset_index * coset_size, 0, params.fri_group
);

let coset_elements_len = coset_elements.len();
Expand Down
26 changes: 8 additions & 18 deletions src/table_commitment.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use cairo_verifier::vector_commitment::{VectorCommitmentConfig, VectorUnsentCommitment, VectorCommitment, VectorCommitmentWitness};
use cairo_verifier::vector_commitment::{
VectorCommitmentConfig, VectorUnsentCommitment, VectorCommitment, VectorCommitmentWitness
};
use cairo_verifier::channel::channel::ChannelSentFelt;

// Commitment values for a table commitment protocol. Used to generate a commitment by "reading"
Expand Down Expand Up @@ -26,7 +28,6 @@ struct TableCommitmentConfig {
#[derive(Drop, Copy)]
struct TableDecommitment {
// n_columns * n_queries values to decommit.
n_values: felt252,
values: Span<felt252>,
}

Expand All @@ -42,19 +43,11 @@ fn table_commit(
TableCommitment {
config: TableCommitmentConfig {
n_columns: 0,
vector: VectorCommitmentConfig {
height: 0,
n_verifier_friendly_commitment_layers: 0,
}
vector: VectorCommitmentConfig { height: 0, n_verifier_friendly_commitment_layers: 0, }
},
vector_commitment: VectorCommitment {
config: VectorCommitmentConfig {
height: 0,
n_verifier_friendly_commitment_layers: 0,
},
commitment_hash: ChannelSentFelt {
value: 0,
}
config: VectorCommitmentConfig { height: 0, n_verifier_friendly_commitment_layers: 0, },
commitment_hash: ChannelSentFelt { value: 0, }
}
}
}
Expand All @@ -69,10 +62,7 @@ fn table_commit(
// witness - the decommitment witness.
fn table_decommit(
commitment: TableCommitment,
n_queries: felt252,
queries: felt252,
queries: Span<felt252>,
decommitment: TableDecommitment,
witness: TableCommitmentWitness,
) {

}
) {}

0 comments on commit 0d2d9ec

Please sign in to comment.