Skip to content

Commit

Permalink
gather_first_layer_queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Dec 20, 2023
1 parent c483e4c commit 008ebd5
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion calc.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
DEFAULT_PRIME = 2**251 + 17 * 2**192 + 1

print((pow(193456804421077096570009938751278224656090409051406060084, 193456804421077096570009938751278224656090409051406060084, DEFAULT_PRIME)))
print((pow(3, DEFAULT_PRIME-2, DEFAULT_PRIME)))
13 changes: 11 additions & 2 deletions src/common/tests/test_math.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,24 @@ fn test_mul_inverse_3() {
#[test]
#[available_gas(9999999999)]
fn test_mul_inverse_4() {
let x = 3;
let inv_x = mul_inverse(x);
assert(inv_x == 1206167596222043737899107594365023368541035738443865566657697352045290673494, 'Invalid value');
assert(x * inv_x == 1, 'Invalid value');
}

#[test]
#[available_gas(9999999999)]
fn test_mul_inverse_5() {
let x = 193456804421077096570009938751278224656090409051406060084;
let inv_inv_x = mul_inverse(mul_inverse(x));
assert(x == inv_inv_x, 'Invalid value');
}

#[test]
#[available_gas(9999999999)]
fn test_mul_inverse_5() {
fn test_mul_inverse_6() {
let x = 19345680409051406060084;
let inv_inv_x = mul_inverse(mul_inverse(x));
assert(x == inv_inv_x, 'Invalid value');
}
}
1 change: 1 addition & 0 deletions src/fri.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mod fri_formula;
mod fri_group;
mod fri_layer;
mod fri_config;
mod fri_first_layer;
mod fri_last_layer;
mod fri;

Expand Down
34 changes: 34 additions & 0 deletions src/fri/fri_first_layer.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use core::array::SpanTrait;
use core::option::OptionTrait;
use core::array::ArrayTrait;
use core::traits::TryInto;

use cairo_verifier::common::math;
use cairo_verifier::fri::fri_layer::FriLayerQuery;
use cairo_verifier::FIELD_GENERATOR_INV;

fn gather_first_layer_queries(
n_queries: felt252, queries: Span<felt252>, evaluations: Span<felt252>, x_values: Span<felt252>
) {
let mut fri_queries = ArrayTrait::<FriLayerQuery>::new();

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

// Translate the coset to the homogenous group to have simple FRI equations.
let shifted_x_value = *(x_values.at(i)) * FIELD_GENERATOR_INV;

fri_queries
.append(
FriLayerQuery {
index: *(queries.at(i)),
y_value: *(evaluations.at(i)),
x_inv_value: math::mul_inverse(shifted_x_value),
}
)
}
}
3 changes: 3 additions & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const FIELD_GENERATOR: felt252 = 3;
const FIELD_GENERATOR_INV: felt252 = 1206167596222043737899107594365023368541035738443865566657697352045290673494;

mod channel;
mod common;
mod structs;
Expand Down

0 comments on commit 008ebd5

Please sign in to comment.