Skip to content

Commit

Permalink
Optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmilson committed Oct 23, 2024
1 parent 07a8ae3 commit 1ea6c21
Show file tree
Hide file tree
Showing 5 changed files with 268 additions and 45 deletions.
1 change: 1 addition & 0 deletions stwo_cairo_verifier/src/circle.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub trait CirclePointTrait<

impl CirclePointAdd<F, +Add<F>, +Sub<F>, +Mul<F>, +Drop<F>, +Copy<F>> of Add<CirclePoint<F>> {
/// Performs the operation of the circle as a group with additive notation.
#[inline]
fn add(lhs: CirclePoint<F>, rhs: CirclePoint<F>) -> CirclePoint<F> {
CirclePoint { x: lhs.x * rhs.x - lhs.y * rhs.y, y: lhs.x * rhs.y + lhs.y * rhs.x }
}
Expand Down
11 changes: 7 additions & 4 deletions stwo_cairo_verifier/src/fri.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ pub impl FriVerifierImpl of FriVerifierTrait {
self: @FriVerifier, queries: @Queries, decommitted_values: Array<SparseCircleEvaluation>
) -> Result<(), FriVerificationError> {
assert!(queries.log_domain_size == self.expected_query_log_domain_size);

let (last_layer_queries, last_layer_query_evals) = self
.decommit_inner_layers(queries, @decommitted_values)?;
self.decommit_last_layer(last_layer_queries, last_layer_query_evals)
Expand Down Expand Up @@ -397,17 +396,21 @@ pub impl FriVerifierImpl of FriVerifierTrait {
) -> Result<(), FriVerificationError> {
let FriVerifier { last_layer_domain, last_layer_poly, .. } = self;

let domain_log_size = last_layer_domain.log_size();
// TODO(andrew): Note doing FFT on the last layer poly vs pointwize evaluation is less
// efficient for large blowup factors but more efficient for small blowup factors.
let last_layer_evals = last_layer_poly.evaluate(*last_layer_domain).values;

let mut i = 0;
loop {
if i == queries.positions.len() {
break Result::Ok(());
}

let query = *queries.positions[i];
let query_eval = *query_evals[i];
let x = last_layer_domain.at(bit_reverse_index(query, last_layer_domain.log_size()));
let last_layer_eval_i = bit_reverse_index(query, domain_log_size);

if query_eval != last_layer_poly.eval_at_point(x.into()) {
if query_evals[i] != last_layer_evals[last_layer_eval_i] {
break Result::Err(FriVerificationError::LastLayerEvaluationsInvalid);
}

Expand Down
Loading

0 comments on commit 1ea6c21

Please sign in to comment.