-
Notifications
You must be signed in to change notification settings - Fork 144
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
Fibonacci Stark Prover #59
Changes from all commits
5b71de3
6c2789e
49bb783
9e4a345
bd2b05f
855d4b3
0d022a8
f18b906
97c1179
b44022e
35abba4
6b8f62c
a9bd07d
cff637a
5a8e336
8036639
57d19fc
a207853
85ecd77
cf2a09b
688a8c9
e151449
f15af6b
9068b27
f667207
623e374
d69145b
f6dbc60
a21bc11
e635f0e
24ffd2a
7772c38
0f72803
999b209
1e65005
9b3fdfb
5ce7556
73299e8
faf992f
81f1eb4
d2aeb77
ee52e75
9b9258e
88ba28e
8c45aa3
9cd60e0
f34f61d
b27b769
0049484
6e1e300
58657b2
1bba26f
e363b02
11d1f08
082c553
f343e1a
290114e
331df41
a387a5e
f340b5a
5bbfa09
86075cd
3cb371c
1aa01c3
331d683
ce8b1ed
2b2514e
9aa4e9d
609da6f
72db780
e09904b
25d5b1d
47230dd
0437286
635386f
ee8e868
cd6f341
9fd980c
f0d5cd3
e635195
a1b4d25
d874f5e
7e26c7e
d2ad4a4
c589654
22a691c
c4b7328
5f4ccc2
9c63aaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
members = [ | ||
"math", | ||
"crypto", | ||
"proving-system/stark", | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
mod transcript; | ||
pub mod transcript; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,6 +105,10 @@ where | |
fn from_base_type(x: [FieldElement<Q::BaseField>; 2]) -> [FieldElement<Q::BaseField>; 2] { | ||
x | ||
} | ||
|
||
fn representative(_x: Self::BaseType) -> Self::BaseType { | ||
todo!() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same for this |
||
} | ||
} | ||
|
||
#[cfg(test)] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,6 +151,11 @@ where | |
fn from_base_type(x: Self::BaseType) -> Self::BaseType { | ||
MontgomeryAlgorithms::cios(&x, &C::R2, &C::MODULUS, &C::MU) | ||
} | ||
|
||
// TO DO: Add tests for representatives | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's make an issue to track this TODO There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could label it as "good first issue". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good, created it here #138 |
||
fn representative(x: Self::BaseType) -> Self::BaseType { | ||
MontgomeryAlgorithms::cios(&x, &U384::from_u64(1), &C::MODULUS, &C::MU) | ||
} | ||
} | ||
|
||
impl<C> ByteConversion for FieldElement<MontgomeryBackendPrimeField<C>> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "lambdaworks-stark" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
rand = "0.8.5" | ||
lambdaworks-math = { path = "../../math" } | ||
lambdaworks-crypto = { path = "../../crypto"} | ||
thiserror = "1.0.38" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
pub use super::{FriMerkleTree, Polynomial, F, FE}; | ||
|
||
pub struct FriCommitment<FE> { | ||
pub poly: Polynomial<FE>, | ||
pub domain: Vec<FE>, | ||
pub evaluation: Vec<FE>, | ||
pub merkle_tree: FriMerkleTree, | ||
} | ||
|
||
pub type FriCommitmentVec<FE> = Vec<FriCommitment<FE>>; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
use super::FE; | ||
use crate::{fri::fri_commitment::FriCommitmentVec, PrimeField}; | ||
pub use lambdaworks_crypto::fiat_shamir::transcript::Transcript; | ||
use lambdaworks_crypto::merkle_tree::DefaultHasher; | ||
|
||
use lambdaworks_crypto::merkle_tree::proof::Proof; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct FriDecommitment { | ||
pub layer_merkle_paths: Vec<( | ||
Proof<PrimeField, DefaultHasher>, | ||
Proof<PrimeField, DefaultHasher>, | ||
)>, | ||
pub last_layer_evaluation: FE, | ||
} | ||
|
||
// verifier chooses a randomness and get the index where | ||
// they want to evaluate the poly | ||
// TODO: encapsulate the return type of this function in a struct. | ||
// This returns a list of authentication paths for evaluations on points and their symmetric counterparts. | ||
pub fn fri_decommit_layers( | ||
commit: &FriCommitmentVec<FE>, | ||
index_to_verify: usize, | ||
) -> FriDecommitment { | ||
let mut index = index_to_verify; | ||
|
||
let mut layer_merkle_paths = vec![]; | ||
|
||
// with every element of the commit, we look for that one in | ||
// the merkle tree and get the corresponding element | ||
for commit_i in commit { | ||
let length_i = commit_i.domain.len(); | ||
index %= length_i; | ||
let evaluation_i = commit_i.evaluation[index].clone(); | ||
let auth_path = commit_i.merkle_tree.get_proof(&evaluation_i).unwrap(); | ||
|
||
// symmetrical element | ||
let index_sym = (index + length_i / 2) % length_i; | ||
let evaluation_i_sym = commit_i.evaluation[index_sym].clone(); | ||
let auth_path_sym = commit_i.merkle_tree.get_proof(&evaluation_i_sym).unwrap(); | ||
|
||
layer_merkle_paths.push((auth_path, auth_path_sym)); | ||
} | ||
|
||
// send the last element of the polynomial | ||
let last = commit.last().unwrap(); | ||
let last_evaluation = last.poly.coefficients[0].clone(); | ||
|
||
FriDecommitment { | ||
layer_merkle_paths, | ||
last_layer_evaluation: last_evaluation, | ||
} | ||
} | ||
|
||
// Integration test: | ||
// * get an arbitrary polynomial | ||
// * have a domain containing roots of the unity (# is power of two) | ||
// p = 65_537 | ||
// * apply FRI commitment | ||
// * apply FRI decommitment | ||
// assert: | ||
// * evaluations of the polynomials coincide with calculations from the decommitment | ||
// * show a fail example: with a monomial | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::fri::U64PrimeField; | ||
use lambdaworks_math::field::element::FieldElement; | ||
use std::collections::HashSet; | ||
const PRIME_GENERATOR: (u64, u64) = (0xFFFF_FFFF_0000_0001_u64, 2717_u64); | ||
pub type F = U64PrimeField<{ PRIME_GENERATOR.0 }>; | ||
pub type FeGoldilocks = FieldElement<F>; | ||
|
||
#[test] | ||
fn test() { | ||
let subgroup_size = 1024_u64; | ||
let generator_field = FeGoldilocks::new(PRIME_GENERATOR.1); | ||
let exp = (PRIME_GENERATOR.0 - 1) / subgroup_size; | ||
let generator_of_subgroup = generator_field.pow(exp); | ||
let mut numbers = HashSet::new(); | ||
|
||
let mut i = 0; | ||
for exp in 0..1024_u64 { | ||
i += 1; | ||
let ret = generator_of_subgroup.pow(exp); | ||
numbers.insert(*ret.value()); | ||
println!("{ret:?}"); | ||
} | ||
|
||
let count = numbers.len(); | ||
println!("count: {count}"); | ||
println!("iter: {i}"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#139