-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* prover sub crate created * working on fold function * merge * test working * fold test completed * next_fri_layer function * Dependencies removed * using iterator step_by * fmt * reordering fri functions * fri_decommit init * evaluate_vec in polynomial and reference in evaluate * using evaluate_vec * evaluate_vec changed to evaluate_slice * evaluate_slice changed * fri_commitment * fri continuation * comment moved * fri_decommit_layers * comments added * polynomial.rs merge confilct * adapting to the new code * conflicts solved * append in transcript * insert last_evaluation in transcript * beta from transcript.challenge() * test: generating subgroups * prover sub crate created * Save work in progress * Add first iteration of function to get composition polynomials from trace and air * Add test for get_composition_poly * Add get_coefficients function * Tidy up code * Add docs * Fix tests * Add u128_prime field and make get_composition_poly return a Polynomial data structure * Fixes from rebasing * Apply clippy suggestions * Make functions pub crate * Tidy up code * Tidy up code * Minor fixes * Use U384 instead of U128 * Tidy up code and remove unnecessary u128 field element module * generate_vec_roots * generate_vec_roots in lib * Return trace polynomial from get_composition_poly * coset_factor * Add coset evaluation and fri commitment steps * Add result to get_cp_and_tp * Change error description and module name * Add decommitment step * Start filling the stark proof struct * Small comments * Add first verifier step * Switch to hardcoded fibonacci trace * Start FRI verification step * More progress * Improve code, change field to 17 for testing purposes * Fix FRI operation * Go back to fibonacci example with test passing * Refactor functions that use fiat shamir to take in a transcript * Add TODO * Add comments * Moved field definition to lib, removed duplicated definitions * Renamed types * Simplified operations * Refactor roots of unity generator * Small refactor * Refactor roots of unity generator * Update comment * Extracted FRI * Refactor verify * Refactor clippy * Re ordered prover * cargo fmt * fix roots of unity * Remove air * Prover -> Stark * Move folders * Uncomment tests, remove unused code * Fix fri_functions tests * Remove fri_merkle_tree module, move to mod.rs * Clippy * Remove TODOs --------- Co-authored-by: Pablo Deymonnaz <deymonnaz@gmail.com> Co-authored-by: Mariano Nicolini <mariano.nicolini.91@gmail.com> Co-authored-by: Javier Chatruc <jrchatruc@gmail.com> Co-authored-by: MauroFab <maurotoscano2@gmail.com>
- Loading branch information
1 parent
5ebbd30
commit 3c681a3
Showing
20 changed files
with
819 additions
and
8 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 |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
members = [ | ||
"math", | ||
"crypto", | ||
"proving-system/stark", | ||
] |
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 +1 @@ | ||
mod transcript; | ||
pub mod transcript; |
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
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
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
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
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,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" |
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 @@ | ||
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>>; |
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,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}"); | ||
} | ||
} |
Oops, something went wrong.