Skip to content

Commit

Permalink
Add FRI layer 0 commitment
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmilson committed Nov 20, 2024
1 parent 8b65c35 commit cdce69c
Show file tree
Hide file tree
Showing 13 changed files with 636 additions and 502 deletions.
2 changes: 1 addition & 1 deletion stwo_cairo_verifier/.tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scarb nightly-2024-11-09
scarb nightly-2024-11-19
starknet-foundry 0.32.0
8 changes: 4 additions & 4 deletions stwo_cairo_verifier/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ edition = "2024_07"
[lib]
casm = true

[cairo]
# TODO(andrew): Remove once inlining bug fixed as increases step counts by about 3x.
inlining-strategy = "avoid"
# [cairo]
# # TODO(andrew): Remove once inlining bug fixed as increases step counts by about 3x.
# inlining-strategy = "avoid"

[tool.fmt]
sort-module-level-items = true

[dependencies]

[dev-dependencies]
cairo_test = "2.8.4"
cairo_test = "2.8.5"
12 changes: 3 additions & 9 deletions stwo_cairo_verifier/src/channel.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl ChannelTimeImpl of ChannelTimeTrait {

#[derive(Drop)]
pub struct Channel {
digest: felt252,
pub digest: felt252,
channel_time: ChannelTime,
}

Expand All @@ -61,14 +61,8 @@ pub impl ChannelImpl of ChannelTrait {
fn draw_base_felts(ref self: Channel) -> [BaseField; FELTS_PER_HASH] {
let mut cur = self.draw_felt252().into();
[
extract_m31(ref cur),
extract_m31(ref cur),
extract_m31(ref cur),
extract_m31(ref cur),
extract_m31(ref cur),
extract_m31(ref cur),
extract_m31(ref cur),
extract_m31(ref cur),
extract_m31(ref cur), extract_m31(ref cur), extract_m31(ref cur), extract_m31(ref cur),
extract_m31(ref cur), extract_m31(ref cur), extract_m31(ref cur), extract_m31(ref cur),
]
}

Expand Down
33 changes: 30 additions & 3 deletions stwo_cairo_verifier/src/fri.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,11 @@ pub impl FriVerifierImpl of FriVerifierTrait {
/// The order of the opening positions corresponds to the order of the column commitment.
fn column_query_positions(
ref self: FriVerifier, ref channel: Channel,
) -> (Felt252Dict<Nullable<@SparseSubCircleDomain>>, Span<u32>) {
) -> (
Felt252Dict<Nullable<Span<usize>>>,
Felt252Dict<Nullable<@SparseSubCircleDomain>>,
Span<u32>,
) {
let queries = QueriesImpl::generate(
ref channel,
*self.column_bounds[0] + self.config.log_blowup_factor,
Expand All @@ -420,10 +424,33 @@ pub impl FriVerifierImpl of FriVerifierTrait {
i = i + 1;
};

(get_opening_positions(@queries, column_log_sizes.span()), column_log_sizes.span())
(
get_query_positions_per_log_size(queries.clone(), column_log_sizes.span()),
get_opening_positions(@queries, column_log_sizes.span()),
column_log_sizes.span(),
)
}
}

fn get_query_positions_per_log_size(
mut queries: Queries, mut column_log_sizes: Span<u32>,
) -> Felt252Dict<Nullable<Span<usize>>> {
let mut query_positions_per_log_size: Felt252Dict<Nullable<Span<usize>>> = Default::default();

while let Option::Some(column_log_size) = column_log_sizes.pop_front() {
let n_folds = queries.log_domain_size - *column_log_size;

if n_folds != 0 {
queries = queries.fold(n_folds);
}

query_positions_per_log_size
.insert((*column_log_size).into(), NullableTrait::new(queries.positions.span()));
};

query_positions_per_log_size
}

/// Returns the column opening positions needed for verification.
///
/// The column log sizes must be unique and in descending order. Returned
Expand Down Expand Up @@ -565,7 +592,7 @@ mod test {
let mut verifier = FriVerifierImpl::commit(ref channel, config, proof, bounds).unwrap();

let mut channel = ChannelTrait::new(0x00);
let (_, _) = verifier.column_query_positions(ref channel);
let (_, _, _) = verifier.column_query_positions(ref channel);

verifier.decommit(decommitted_values).unwrap();
}
Expand Down
Loading

0 comments on commit cdce69c

Please sign in to comment.