Skip to content
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

Merged
merged 89 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
5b71de3
prover sub crate created
pablodeymo Feb 13, 2023
6c2789e
working on fold function
pablodeymo Feb 13, 2023
49bb783
merge
pablodeymo Feb 13, 2023
9e4a345
test working
pablodeymo Feb 13, 2023
bd2b05f
fold test completed
pablodeymo Feb 13, 2023
855d4b3
next_fri_layer function
pablodeymo Feb 13, 2023
0d022a8
Dependencies removed
pablodeymo Feb 13, 2023
f18b906
using iterator step_by
pablodeymo Feb 14, 2023
97c1179
fmt
pablodeymo Feb 14, 2023
b44022e
reordering fri functions
pablodeymo Feb 14, 2023
35abba4
fri_decommit init
pablodeymo Feb 14, 2023
6b8f62c
evaluate_vec in polynomial and reference in evaluate
pablodeymo Feb 14, 2023
a9bd07d
using evaluate_vec
pablodeymo Feb 14, 2023
cff637a
evaluate_vec changed to evaluate_slice
pablodeymo Feb 14, 2023
5a8e336
evaluate_slice changed
pablodeymo Feb 14, 2023
8036639
fri_commitment
pablodeymo Feb 14, 2023
57d19fc
fri continuation
pablodeymo Feb 14, 2023
a207853
comment moved
pablodeymo Feb 15, 2023
85ecd77
fri_decommit_layers
pablodeymo Feb 15, 2023
cf2a09b
comments added
pablodeymo Feb 16, 2023
688a8c9
polynomial.rs merge confilct
pablodeymo Feb 16, 2023
e151449
adapting to the new code
pablodeymo Feb 16, 2023
f15af6b
conflicts solved
pablodeymo Feb 16, 2023
9068b27
append in transcript
pablodeymo Feb 16, 2023
f667207
Merge branch 'main' into fri-operation
pablodeymo Feb 16, 2023
623e374
insert last_evaluation in transcript
pablodeymo Feb 16, 2023
d69145b
beta from transcript.challenge()
pablodeymo Feb 16, 2023
f6dbc60
test: generating subgroups
pablodeymo Feb 16, 2023
a21bc11
prover sub crate created
pablodeymo Feb 13, 2023
e635f0e
Save work in progress
entropidelic Feb 13, 2023
24ffd2a
Add first iteration of function to get composition polynomials from t…
entropidelic Feb 14, 2023
7772c38
Add test for get_composition_poly
entropidelic Feb 14, 2023
0f72803
Add get_coefficients function
entropidelic Feb 14, 2023
999b209
Tidy up code
entropidelic Feb 15, 2023
1e65005
Add docs
entropidelic Feb 15, 2023
9b3fdfb
Fix tests
entropidelic Feb 15, 2023
5ce7556
Add u128_prime field and make get_composition_poly return a Polynomia…
entropidelic Feb 15, 2023
73299e8
Fixes from rebasing
entropidelic Feb 15, 2023
faf992f
Apply clippy suggestions
entropidelic Feb 15, 2023
81f1eb4
Make functions pub crate
entropidelic Feb 15, 2023
d2aeb77
Tidy up code
entropidelic Feb 15, 2023
ee52e75
Tidy up code
entropidelic Feb 15, 2023
9b9258e
Minor fixes
entropidelic Feb 16, 2023
88ba28e
Use U384 instead of U128
entropidelic Feb 22, 2023
8c45aa3
Tidy up code and remove unnecessary u128 field element module
entropidelic Feb 22, 2023
9cd60e0
Merge branch 'arithmetization' into fri-operation
jrchatruc Feb 22, 2023
f34f61d
generate_vec_roots
pablodeymo Feb 22, 2023
b27b769
generate_vec_roots in lib
pablodeymo Feb 22, 2023
0049484
Return trace polynomial from get_composition_poly
entropidelic Feb 22, 2023
6e1e300
coset_factor
pablodeymo Feb 22, 2023
58657b2
Add coset evaluation and fri commitment steps
jrchatruc Feb 22, 2023
1bba26f
Add result to get_cp_and_tp
entropidelic Feb 22, 2023
e363b02
Change error description and module name
entropidelic Feb 22, 2023
11d1f08
Merge branch 'arithmetization' into fri-operation
jrchatruc Feb 23, 2023
082c553
Add decommitment step
jrchatruc Feb 23, 2023
f343e1a
Start filling the stark proof struct
jrchatruc Feb 23, 2023
290114e
Small comments
jrchatruc Feb 23, 2023
331df41
Add first verifier step
jrchatruc Feb 24, 2023
a387a5e
Switch to hardcoded fibonacci trace
jrchatruc Feb 24, 2023
f340b5a
Start FRI verification step
jrchatruc Feb 27, 2023
5bbfa09
More progress
jrchatruc Feb 27, 2023
86075cd
Merge branch 'main' into fri-operation
jrchatruc Feb 28, 2023
3cb371c
Improve code, change field to 17 for testing purposes
MauroToscano Feb 28, 2023
1aa01c3
Fix FRI operation
MauroToscano Feb 28, 2023
331d683
Go back to fibonacci example with test passing
jrchatruc Feb 28, 2023
ce8b1ed
Refactor functions that use fiat shamir to take in a transcript
jrchatruc Feb 28, 2023
2b2514e
Add TODO
jrchatruc Feb 28, 2023
9aa4e9d
Add comments
MauroToscano Mar 1, 2023
609da6f
Moved field definition to lib, removed duplicated definitions
MauroToscano Mar 1, 2023
72db780
Renamed types
MauroToscano Mar 1, 2023
e09904b
Simplified operations
MauroToscano Mar 1, 2023
25d5b1d
Refactor roots of unity generator
MauroToscano Mar 1, 2023
47230dd
Small refactor
MauroToscano Mar 1, 2023
0437286
Refactor roots of unity generator
MauroToscano Mar 1, 2023
635386f
Update comment
MauroToscano Mar 1, 2023
ee8e868
Extracted FRI
MauroToscano Mar 1, 2023
cd6f341
Refactor verify
MauroToscano Mar 1, 2023
9fd980c
Refactor clippy
MauroToscano Mar 1, 2023
f0d5cd3
Re ordered prover
MauroToscano Mar 1, 2023
e635195
cargo fmt
MauroToscano Mar 1, 2023
a1b4d25
fix roots of unity
MauroToscano Mar 1, 2023
d874f5e
Remove air
MauroToscano Mar 1, 2023
7e26c7e
Prover -> Stark
MauroToscano Mar 1, 2023
d2ad4a4
Move folders
MauroToscano Mar 1, 2023
c589654
Uncomment tests, remove unused code
jrchatruc Mar 1, 2023
22a691c
Fix fri_functions tests
jrchatruc Mar 1, 2023
c4b7328
Remove fri_merkle_tree module, move to mod.rs
jrchatruc Mar 1, 2023
5f4ccc2
Clippy
jrchatruc Mar 1, 2023
9c63aaa
Remove TODOs
jrchatruc Mar 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fri_commitment
  • Loading branch information
pablodeymo committed Feb 16, 2023
commit 8036639e0d23d1de48122ba65685df884d55be02
2 changes: 1 addition & 1 deletion crypto/src/fiat_shamir/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mod transcript;
pub mod transcript;
6 changes: 3 additions & 3 deletions crypto/src/fiat_shamir/transcript.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use sha3::{Digest, Sha3_256};

struct Transcript {
pub struct Transcript {
hasher: Sha3_256,
}

Expand All @@ -13,12 +13,12 @@ impl Transcript {
}

#[allow(unused)]
fn append(&mut self, new_data: &[u8]) {
pub fn append(&mut self, new_data: &[u8]) {
self.hasher.update(&mut new_data.to_owned());
}

#[allow(unused)]
fn challenge(&mut self) -> [u8; 32] {
pub fn challenge(&mut self) -> [u8; 32] {
let mut result_hash = [0_u8; 32];
result_hash.copy_from_slice(&self.hasher.finalize_reset());
self.hasher.update(result_hash);
Expand Down
8 changes: 4 additions & 4 deletions crypto/src/merkle_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{cell::RefCell, rc::Rc};

pub struct MerkleTree<F: IsField, H: IsCryptoHash<F>> {
leafs: Vec<TreeNode<F>>,
root: TreeNode<F>,
pub root: TreeNode<F>,
hasher: H,
}

Expand Down Expand Up @@ -165,7 +165,7 @@ pub struct Proof<F: IsField, H: IsCryptoHash<F>> {
hasher: H,
}

type TreeNode<F> = Rc<RefCell<Node<F>>>;
pub type TreeNode<F> = Rc<RefCell<Node<F>>>;

fn build_tree_node<F: IsField>(hash: FieldElement<F>) -> TreeNode<F> {
Rc::new(RefCell::new(Node {
Expand All @@ -176,8 +176,8 @@ fn build_tree_node<F: IsField>(hash: FieldElement<F>) -> TreeNode<F> {
}

#[derive(Clone, Debug, PartialEq)]
struct Node<F: IsField> {
hash: FieldElement<F>,
pub struct Node<F: IsField> {
pub hash: FieldElement<F>,
parent: Option<TreeNode<F>>,
sibiling: Option<TreeNode<F>>,
}
Expand Down
23 changes: 5 additions & 18 deletions prover/src/fri/fri_commitment.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
pub use super::{Polynomial, F, FE};
use lambdaworks_crypto::{hash::traits::IsCryptoHash, merkle_tree};
use lambdaworks_crypto::{hash::traits::IsCryptoHash, merkle_tree::MerkleTree};
use lambdaworks_math::field::traits::IsField;

pub struct FriCommitment {
pub struct FriCommitment<F: IsField, H: IsCryptoHash<F>> {
pub poly: Polynomial<FE>,
pub domain: Vec<FE>,
pub evaluation: Vec<FE>,
pub merkle_tree: String, // TODO!
pub merkle_tree: MerkleTree<F, H>, // TODO!
}

pub type FriCommitmentVec = Vec<FriCommitment>;

// TODO!!!!
#[derive(Clone)]
struct TestHasher;

impl IsCryptoHash<F> for TestHasher {
fn hash_one(&self, input: FE) -> FE {
input + input
}

fn hash_two(&self, left: FE, right: FE) -> FE {
left + right
}
}
pub type FriCommitmentVec<F, H> = Vec<FriCommitment<F, H>>;
31 changes: 31 additions & 0 deletions prover/src/fri/fri_merkle_tree.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
pub use super::{Polynomial, F, FE};
use lambdaworks_crypto::hash::traits::IsCryptoHash;

// TODO!!!!
#[derive(Clone)]
pub struct FriTestHasher;

impl IsCryptoHash<F> for FriTestHasher {
fn hash_one(&self, input: FE) -> FE {
input + input
}

fn hash_two(&self, left: FE, right: FE) -> FE {
left + right
}
}

#[cfg(test)]
mod tests {
use super::{FriTestHasher, FE};
use lambdaworks_crypto::merkle_tree::MerkleTree;

#[test]
fn build_merkle_tree_from_an_even_set_of_leafs() {
let merkle_tree = MerkleTree::build(
&[FE::new(1), FE::new(2), FE::new(3), FE::new(4)],
FriTestHasher,
);
assert_eq!(merkle_tree.root.borrow().hash, FE::new(20));
}
}
29 changes: 17 additions & 12 deletions prover/src/fri/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
mod fri_commitment;
mod fri_decommit;
mod fri_functions;
mod fri_merkle_tree;

use fri_commitment::{FriCommitment, FriCommitmentVec};
use crate::fri::fri_merkle_tree::FriTestHasher;
use fri_commitment::FriCommitment; //, FriCommitmentVec};
pub use lambdaworks_crypto::fiat_shamir::transcript::Transcript;
use lambdaworks_crypto::merkle_tree::MerkleTree;
use lambdaworks_math::field::{element::FieldElement, fields::u64_prime_field::U64PrimeField};
pub use lambdaworks_math::polynomial::Polynomial;

Expand All @@ -19,23 +23,24 @@ pub fn fri_commitment(
p_i: &Polynomial<FieldElement<F>>,
domain_i: &[FE],
evaluation_i: &[FE],
// merkle_tree0: ...
// transcript
) -> FriCommitment {
transcript: &mut Transcript,
) -> FriCommitment<F, FriTestHasher> {
// Merkle tree:
// - ret_evaluation
// - root
// - hasher
// Create a new merkle tree with ret_evaluation
// Create a new merkle tree with evaluation_i
let merkle_tree = MerkleTree::build(&evaluation_i, FriTestHasher);
let root = merkle_tree.root.borrow().hash;
// TODO @@@ let bytes = root.as_bytes();
//transcript.append(bytes);

//let tree: merkle_tree::MerkleTree<FE, TestHasher>;
let ret = FriCommitment {
FriCommitment {
poly: p_i.clone(),
domain: Vec::new(),
evaluation: Vec::new(),
merkle_tree: String::new(), // TODO!
};
ret
domain: domain_i.to_vec(),
evaluation: evaluation_i.to_vec(),
merkle_tree,
}
}

/*
Expand Down