-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from HerodotusDev/feat/fri
Implementation of Fast Reed-Solomon Interactive Proof of Proximity (FRIPoP)
- Loading branch information
Showing
31 changed files
with
2,821 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[package] | ||
name = "cairo_verifier" | ||
version = "0.1.0" | ||
version = "0.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#[generate_trait] | ||
impl ArrayExtend<T, +Copy<T>, +Drop<T>> of ArrayExtendTrait<T> { | ||
fn extend(ref self: Array<T>, span: Span<T>) { | ||
let mut i = 0; | ||
loop { | ||
if i == span.len() { | ||
break; | ||
}; | ||
self.append(*span.at(i)); | ||
i += 1; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const STARK_PRIME: u256 = | ||
3618502788666131213697322783095070105623107215331596699973092056135872020481; | ||
const STARK_PRIME_MINUS_TWO: felt252 = | ||
3618502788666131213697322783095070105623107215331596699973092056135872020479; | ||
|
||
const FIELD_GENERATOR: felt252 = 3; | ||
const FIELD_GENERATOR_INVERSE: felt252 = | ||
1206167596222043737899107594365023368541035738443865566657697352045290673494; | ||
|
||
const MONTGOMERY_R: felt252 = | ||
3618502788666127798953978732740734578953660990361066340291730267701097005025; // 2**256 % STARK_PRIME | ||
const MONTGOMERY_R_INVERSE: felt252 = | ||
113078212145816603762751633895895194930089271709401121343797004406777446400; | ||
|
||
const C_PRIME_AS_UINT256_LOW: u128 = 31; | ||
const C_PRIME_AS_UINT256_HIGH: u128 = | ||
329648542954659146201578277794459156480; // 31 * 0x8000000000000110000000000000000; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use cairo_verifier::common::consts::STARK_PRIME_MINUS_TWO; | ||
|
||
fn pow(base: felt252, exp: felt252) -> felt252 { | ||
if exp == 0 { | ||
return 1; | ||
} | ||
let mut exp: u256 = exp.into(); | ||
let mut res = 1; | ||
let mut curr_base = base; | ||
|
||
loop { | ||
if exp == 0 { | ||
break; | ||
} else { | ||
if exp % 2 == 1 { | ||
res = res * curr_base; | ||
} | ||
curr_base = curr_base * curr_base; | ||
exp = exp / 2; | ||
} | ||
}; | ||
res | ||
} | ||
|
||
fn mul_inverse(x: felt252) -> felt252 { | ||
// From Fermat's little theorem, a ^ (p - 1) = 1 when p is prime and a != 0. Since a ^ (p - 1) = a · a ^ (p - 2) we have that | ||
// a ^ (p - 2) is the multiplicative inverse of a modulo p. | ||
pow(x, STARK_PRIME_MINUS_TWO) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ mod test_flip_endianness; | |
mod test_from_span; | ||
mod test_horner_eval; | ||
mod test_array_append; | ||
mod test_math; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use cairo_verifier::common::math::{pow, mul_inverse}; | ||
|
||
#[test] | ||
#[available_gas(9999999999)] | ||
fn test_pow_1() { | ||
let base = 1934568044210770965733097210694395167600009938751278224656090409051406060084; | ||
let exp = 69439516760000993875127; | ||
assert( | ||
pow( | ||
base, exp | ||
) == 2804690217475462062143361339624939640984649667966511418446363596075299761851, | ||
'Invalid value' | ||
); | ||
} | ||
|
||
#[test] | ||
#[available_gas(9999999999)] | ||
fn test_pow_2() { | ||
let base = 193456804421077096570009938751278224656090409051406060084; | ||
let exp = 193456804421077096570009938751278224656090409051406060084; | ||
assert( | ||
pow( | ||
base, exp | ||
) == 2672162222334975109199941471365701890765112108683608796920114577809390903720, | ||
'Invalid value' | ||
); | ||
} | ||
|
||
#[test] | ||
#[available_gas(9999999999)] | ||
fn test_mul_inverse_1() { | ||
let x = 9751091999414713; | ||
let inv_x = mul_inverse(x); | ||
assert(x * inv_x == 1, 'Invalid value'); | ||
} | ||
|
||
#[test] | ||
#[available_gas(9999999999)] | ||
fn test_mul_inverse_2() { | ||
let x = 97199414713; | ||
let inv_x = mul_inverse(x); | ||
assert(x * inv_x == 1, 'Invalid value'); | ||
} | ||
|
||
#[test] | ||
#[available_gas(9999999999)] | ||
fn test_mul_inverse_3() { | ||
let x = 92011457780; | ||
let inv_x = mul_inverse(x); | ||
assert(x * inv_x == 1, 'Invalid value'); | ||
} | ||
|
||
#[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_6() { | ||
let x = 19345680409051406060084; | ||
let inv_inv_x = mul_inverse(mul_inverse(x)); | ||
assert(x == inv_inv_x, 'Invalid value'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
mod fri_formula; | ||
mod fri_group; | ||
mod fri_layer; | ||
mod fri_config; | ||
mod fri_first_layer; | ||
mod fri_last_layer; | ||
mod fri; | ||
|
||
#[cfg(test)] | ||
mod tests; |
Oops, something went wrong.