Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table commitment #61

Merged
merged 10 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/air/traces.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use cairo_verifier::channel::channel::ChannelTrait;
use cairo_verifier::table_commitment::{
TableUnsentCommitment, TableCommitment, TableDecommitment, TableCommitmentWitness, table_commit,
table_decommit,
use cairo_verifier::table_commitment::table_commitment::{
TableCommitment, TableDecommitment, TableCommitmentWitness, table_commit, table_decommit,
};
use cairo_verifier::air::{public_input::PublicInput, traces_config::TracesConfig};
use cairo_verifier::channel::channel::Channel;
Expand All @@ -18,8 +17,8 @@ use cairo_verifier::channel::channel::Channel;
// values from the channel.
#[derive(Drop, Copy)]
struct TracesUnsentCommitment {
original: TableUnsentCommitment,
interaction: TableUnsentCommitment,
original: felt252,
interaction: felt252,
}

// Commitment for the Traces component.
Expand Down Expand Up @@ -62,11 +61,15 @@ fn traces_commit(
config: TracesConfig
) -> TracesCommitment {
// Read original commitment.
let original_commitment = table_commit(unsent_commitment.original, config.original);
let original_commitment = table_commit(
ref channel, unsent_commitment.original, config.original
);
// Generate interaction elements for the first interaction.
let interaction_elements = channel.random_felts_to_prover(n_interaction_elements);
// Read interaction commitment.
let interaction_commitment = table_commit(unsent_commitment.interaction, config.interaction);
let interaction_commitment = table_commit(
ref channel, unsent_commitment.interaction, config.interaction
);

TracesCommitment {
public_input: public_input,
Expand Down
4 changes: 3 additions & 1 deletion src/air/traces_config.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use cairo_verifier::vector_commitment::vector_commitment::VectorCommitmentConfigTrait;
use cairo_verifier::{common::asserts::assert_in_range, table_commitment::TableCommitmentConfig};
use cairo_verifier::{
common::asserts::assert_in_range, table_commitment::table_commitment::TableCommitmentConfig
};

const MAX_N_COLUMNS: felt252 = 128;
const AIR_LAYOUT_N_ORIGINAL_COLUMNS: felt252 = 12;
Expand Down
23 changes: 23 additions & 0 deletions src/common/array_append.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,29 @@ impl ArrayU32AppendFelt of ArrayAppendTrait<u32, felt252> {
}
}

impl ArrayU32AppendFeltsSpan of ArrayAppendTrait<u32, Span<felt252>> {
fn append_little_endian(ref self: Array<u32>, element: Span<felt252>) {
let mut i = 0;
loop {
if i == element.len() {
break;
}
self.append_little_endian(*element[i]);
i += 1;
};
}
fn append_big_endian(ref self: Array<u32>, element: Span<felt252>) {
let mut i = 0;
loop {
if i == element.len() {
break;
}
self.append_big_endian(*element[i]);
i += 1;
};
}
}

impl ArrayU32AppendU128 of ArrayAppendTrait<u32, u128> {
fn append_little_endian(ref self: Array<u32>, mut element: u128) {
let mut i = 4;
Expand Down
6 changes: 3 additions & 3 deletions src/deserialization/fri.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cairo_verifier::{
fri::{fri_config::FriConfig, fri::{FriUnsentCommitment, FriWitness, FriLayerWitness}},
table_commitment::{TableCommitmentConfig, TableCommitmentWitness, TableUnsentCommitment},
table_commitment::table_commitment::{TableCommitmentConfig, TableCommitmentWitness},
vector_commitment::vector_commitment::{VectorCommitmentConfig, VectorCommitmentWitness},
};

Expand Down Expand Up @@ -56,13 +56,13 @@ struct FriUnsentCommitmentWithSerde {
}
impl IntoFriUnsentCommitment of Into<FriUnsentCommitmentWithSerde, FriUnsentCommitment> {
fn into(self: FriUnsentCommitmentWithSerde) -> FriUnsentCommitment {
let mut inner_layers = ArrayTrait::<TableUnsentCommitment>::new();
let mut inner_layers = ArrayTrait::<felt252>::new();
let mut i = 0;
loop {
if i == self.inner_layers.len() {
break;
}
inner_layers.append(TableUnsentCommitment { vector: *self.inner_layers[i] });
inner_layers.append(*self.inner_layers[i]);
i += 1;
};
FriUnsentCommitment {
Expand Down
9 changes: 3 additions & 6 deletions src/deserialization/traces.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use cairo_verifier::{
VectorCommitmentWitnessWithSerde
}
},
table_commitment::{
TableCommitmentConfig, TableCommitmentWitness, TableDecommitment, TableUnsentCommitment
table_commitment::table_commitment::{
TableCommitmentConfig, TableCommitmentWitness, TableDecommitment
},
};

Expand Down Expand Up @@ -54,10 +54,7 @@ struct TracesUnsentCommitmentWithSerde {
}
impl IntoTracesUnsentCommitment of Into<TracesUnsentCommitmentWithSerde, TracesUnsentCommitment> {
fn into(self: TracesUnsentCommitmentWithSerde) -> TracesUnsentCommitment {
TracesUnsentCommitment {
original: TableUnsentCommitment { vector: self.original },
interaction: TableUnsentCommitment { vector: self.original },
}
TracesUnsentCommitment { original: self.original, interaction: self.original, }
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/fri/fri.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use cairo_verifier::{
fri_layer::{FriLayerQuery, FriLayerComputationParams, compute_next_layer},
fri_last_layer::verify_last_layer,
},
table_commitment::{
table_commitment::table_commitment::{
TableCommitmentWitness, TableDecommitment, TableCommitment, TableCommitmentConfig,
TableUnsentCommitment, table_commit, table_decommit
table_commit, table_decommit
}
};

Expand All @@ -17,7 +17,7 @@ use cairo_verifier::{
#[derive(Drop, Copy)]
struct FriUnsentCommitment {
// Array of size n_layers - 1 containing unsent table commitments for each inner layer.
inner_layers: Span<TableUnsentCommitment>,
inner_layers: Span<felt252>,
// Array of size 2**log_last_layer_degree_bound containing coefficients for the last layer
// polynomial.
last_layer_coefficients: Span<felt252>,
Expand Down Expand Up @@ -86,7 +86,7 @@ fn fri_commit_rounds(
ref channel: Channel,
n_layers: felt252,
configs: Span<TableCommitmentConfig>,
unsent_commitments: Span<TableUnsentCommitment>,
unsent_commitments: Span<felt252>,
step_sizes: Span<felt252>,
) -> (Array<TableCommitment>, Array<felt252>) {
let mut commitments = ArrayTrait::<TableCommitment>::new();
Expand All @@ -99,7 +99,7 @@ fn fri_commit_rounds(
break;
}
// Read commitments.
commitments.append(table_commit(*unsent_commitments.at(i), *configs.at(i)));
commitments.append(table_commit(ref channel, *unsent_commitments.at(i), *configs.at(i)));
// Send the next eval_points.
eval_points.append(channel.random_felt_to_prover());

Expand Down
2 changes: 1 addition & 1 deletion src/fri/fri_config.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cairo_verifier::{
common::{asserts::assert_in_range, math::{pow, Felt252PartialOrd}},
table_commitment::TableCommitmentConfig,
table_commitment::table_commitment::TableCommitmentConfig,
vector_commitment::vector_commitment::{VectorCommitmentConfig, VectorCommitmentConfigTrait},
};

Expand Down
2 changes: 1 addition & 1 deletion src/oods.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cairo_verifier::air::composition::{eval_composition_polynomial, eval_oods_po
use cairo_verifier::air::global_values::InteractionElements;
use cairo_verifier::air::public_input::PublicInput;
use cairo_verifier::air::traces::TracesDecommitment;
use cairo_verifier::table_commitment::TableDecommitment;
use cairo_verifier::table_commitment::table_commitment::TableDecommitment;
use cairo_verifier::air::constants::CONSTRAINT_DEGREE;

#[derive(Drop)]
Expand Down
4 changes: 3 additions & 1 deletion src/stark.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use cairo_verifier::{
},
fri::{fri_config::{FriConfig, FriConfigTrait}, fri::{FriUnsentCommitment, FriWitness}},
domains::StarkDomainsImpl,
table_commitment::{TableCommitmentConfig, TableCommitmentWitness, TableDecommitment},
table_commitment::table_commitment::{
TableCommitmentConfig, TableCommitmentWitness, TableDecommitment
},
proof_of_work::{
config::{ProofOfWorkConfig, ProofOfWorkConfigTrait},
proof_of_work::ProofOfWorkUnsentCommitment
Expand Down
69 changes: 3 additions & 66 deletions src/table_commitment.cairo
Original file line number Diff line number Diff line change
@@ -1,67 +1,4 @@
use cairo_verifier::vector_commitment::vector_commitment::{
VectorCommitmentConfig, VectorCommitment, VectorCommitmentWitness
};
mod table_commitment;

// Commitment values for a table commitment protocol. Used to generate a commitment by "reading"
// these values from the channel.
#[derive(Drop, Copy)]
struct TableUnsentCommitment {
vector: felt252,
}

// Commitment for a table (n_rows x n_columns) of field elements in montgomery form.
#[derive(Drop, Copy)]
struct TableCommitment {
config: TableCommitmentConfig,
vector_commitment: VectorCommitment,
}

#[derive(Drop, Copy)]
struct TableCommitmentConfig {
n_columns: felt252,
vector: VectorCommitmentConfig,
}

// Responses for queries to the table commitment.
// Each query corresponds to a full row of the table.
#[derive(Drop, Copy)]
struct TableDecommitment {
// n_columns * n_queries values to decommit.
values: Span<felt252>,
}

// Witness for a decommitment over queries.
#[derive(Drop, Copy)]
struct TableCommitmentWitness {
vector: VectorCommitmentWitness,
}

fn table_commit(
unsent_commitment: TableUnsentCommitment, config: TableCommitmentConfig
) -> TableCommitment {
TableCommitment {
config: TableCommitmentConfig {
n_columns: 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: 0
}
}
}

// Decommits a TableCommitment at multiple indices.
// rows must be sorted and unique.
// Args:
// commitment - the table commitment.
// n_queries - number of queries to decommit.
// queries - the claimed indices.
// decommitment - the claimed values at those indices.
// witness - the decommitment witness.
fn table_decommit(
commitment: TableCommitment,
queries: Span<felt252>,
decommitment: TableDecommitment,
witness: TableCommitmentWitness,
) {}
#[cfg(test)]
mod tests;
Loading