Skip to content

Commit

Permalink
chore(deps): Upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-ferdinand committed Aug 19, 2024
1 parent d9edddd commit d77e736
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ get-size = "0.1.4"
indexmap = "2.2.6"
itertools = "0.13"
lazy_static = "1.5"
ndarray = { version = "0.15", features = ["rayon"] }
ndarray = { version = "0.16", features = ["rayon"] }
nom = "7.1"
num-traits = "0.2"
prettyplease = "0.2"
Expand All @@ -54,7 +54,7 @@ syn = "2.0"
test-strategy = "0.4.0"
thiserror = "1.0"
trybuild = "1.0"
twenty-first = "0.42.0-alpha.8"
twenty-first = "0.42.0-alpha.9"
unicode-width = "0.1"

[workspace.lints.clippy]
Expand Down
3 changes: 1 addition & 2 deletions triton-vm/benches/initialize_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ fn set_ones(matrix: &mut Array2<XFieldElement>, indices: &[(usize, usize)]) {

fn into_shape<const NUM_ROWS: usize, const NUM_COLS: usize>() -> Array2<XFieldElement> {
Array1::zeros(NUM_ROWS * NUM_COLS)
.into_shape((NUM_COLS, NUM_ROWS))
.into_shape_with_order(((NUM_COLS, NUM_ROWS), ndarray::Order::ColumnMajor))
.unwrap()
.reversed_axes()
}

fn set_len<const NUM_ROWS: usize, const NUM_COLS: usize>() -> Array2<XFieldElement> {
Expand Down
32 changes: 15 additions & 17 deletions triton-vm/src/fri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ pub struct Fri<H: AlgebraicHasher> {
}

#[derive(Debug, Eq, PartialEq)]
struct FriProver<'stream, H: AlgebraicHasher> {
struct FriProver<'stream> {
proof_stream: &'stream mut ProofStream,
rounds: Vec<ProverRound<H>>,
rounds: Vec<ProverRound>,
first_round_domain: ArithmeticDomain,
num_rounds: usize,
num_collinearity_checks: usize,
first_round_collinearity_check_indices: Vec<usize>,
}

#[derive(Debug, Clone, Eq, PartialEq)]
struct ProverRound<H: AlgebraicHasher> {
struct ProverRound {
domain: ArithmeticDomain,
codeword: Vec<XFieldElement>,
merkle_tree: MerkleTree<H>,
merkle_tree: MerkleTree,
}

impl<'stream, H: AlgebraicHasher> FriProver<'stream, H> {
impl<'stream> FriProver<'stream> {
fn commit(&mut self, codeword: &[XFieldElement]) -> ProverResult<()> {
self.commit_to_first_round(codeword)?;
for _ in 0..self.num_rounds {
Expand All @@ -73,17 +73,17 @@ impl<'stream, H: AlgebraicHasher> FriProver<'stream, H> {
Ok(())
}

fn commit_to_round(&mut self, round: &ProverRound<H>) {
fn commit_to_round(&mut self, round: &ProverRound) {
let merkle_root = round.merkle_tree.root();
let proof_item = ProofItem::MerkleRoot(merkle_root);
self.proof_stream.enqueue(proof_item);
}

fn store_round(&mut self, round: ProverRound<H>) {
fn store_round(&mut self, round: ProverRound) {
self.rounds.push(round);
}

fn construct_next_round(&mut self) -> ProverResult<ProverRound<H>> {
fn construct_next_round(&mut self) -> ProverResult<ProverRound> {
let previous_round = self.rounds.last().unwrap();
let folding_challenge = self.proof_stream.sample_scalars(1)[0];
let codeword = previous_round.split_and_fold(folding_challenge);
Expand Down Expand Up @@ -157,7 +157,7 @@ impl<'stream, H: AlgebraicHasher> FriProver<'stream, H> {
}
}

impl<H: AlgebraicHasher> ProverRound<H> {
impl ProverRound {
fn new(domain: ArithmeticDomain, codeword: &[XFieldElement]) -> ProverResult<Self> {
debug_assert_eq!(domain.length, codeword.len());
let merkle_tree = Self::merkle_tree_from_codeword(codeword)?;
Expand All @@ -169,9 +169,9 @@ impl<H: AlgebraicHasher> ProverRound<H> {
Ok(round)
}

fn merkle_tree_from_codeword(codeword: &[XFieldElement]) -> ProverResult<MerkleTree<H>> {
fn merkle_tree_from_codeword(codeword: &[XFieldElement]) -> ProverResult<MerkleTree> {
let digests = codeword_as_digests(codeword);
CpuParallel::from_digests(&digests).map_err(FriProvingError::MerkleTreeError)
MerkleTree::new::<CpuParallel>(&digests).map_err(FriProvingError::MerkleTreeError)
}

fn split_and_fold(&self, folding_challenge: XFieldElement) -> Vec<XFieldElement> {
Expand Down Expand Up @@ -337,11 +337,10 @@ impl<'stream, H: AlgebraicHasher> FriVerifier<'stream, H> {
let leaf_indices = self.collinearity_check_a_indices_for_round(0);
let indexed_leafs = leaf_indices.into_iter().zip_eq(revealed_digests).collect();

let inclusion_proof = MerkleTreeInclusionProof::<H> {
let inclusion_proof = MerkleTreeInclusionProof {
tree_height: round.merkle_tree_height(),
indexed_leafs,
authentication_structure,
..MerkleTreeInclusionProof::default()
};
match inclusion_proof.verify(round.merkle_root) {
true => Ok(()),
Expand All @@ -361,11 +360,10 @@ impl<'stream, H: AlgebraicHasher> FriVerifier<'stream, H> {
let leaf_indices = self.collinearity_check_b_indices_for_round(round_number);
let indexed_leafs = leaf_indices.into_iter().zip_eq(revealed_digests).collect();

let inclusion_proof = MerkleTreeInclusionProof::<H> {
let inclusion_proof = MerkleTreeInclusionProof {
tree_height: round.merkle_tree_height(),
indexed_leafs,
authentication_structure,
..MerkleTreeInclusionProof::default()
};
match inclusion_proof.verify(round.merkle_root) {
true => Ok(()),
Expand Down Expand Up @@ -441,7 +439,7 @@ impl<'stream, H: AlgebraicHasher> FriVerifier<'stream, H> {

fn last_round_codeword_merkle_root(&self) -> VerifierResult<Digest> {
let codeword_digests = codeword_as_digests(&self.last_round_codeword);
let merkle_tree: MerkleTree<H> = CpuParallel::from_digests(&codeword_digests)
let merkle_tree = MerkleTree::new::<CpuParallel>(&codeword_digests)
.map_err(FriValidationError::MerkleTreeError)?;

Ok(merkle_tree.root())
Expand Down Expand Up @@ -548,7 +546,7 @@ impl<H: AlgebraicHasher> Fri<H> {
Ok(prover.first_round_collinearity_check_indices)
}

fn prover<'stream>(&'stream self, proof_stream: &'stream mut ProofStream) -> FriProver<H> {
fn prover<'stream>(&'stream self, proof_stream: &'stream mut ProofStream) -> FriProver {
FriProver {
proof_stream,
rounds: vec![],
Expand Down
5 changes: 2 additions & 3 deletions triton-vm/src/proof_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ mod tests {
let num_leaves = 1 << tree_height;
let leaf_values: Vec<XFieldElement> = random_elements(num_leaves);
let leaf_digests = leaf_values.iter().map(|&xfe| xfe.into()).collect_vec();
let merkle_tree: MerkleTree<Tip5> = CpuParallel::from_digests(&leaf_digests).unwrap();
let merkle_tree = MerkleTree::new::<CpuParallel>(&leaf_digests).unwrap();
let indices_to_check = vec![5, 173, 175, 167, 228, 140, 252, 149, 232, 182, 5, 5, 182];
let auth_structure = merkle_tree
.authentication_structure(&indices_to_check)
Expand Down Expand Up @@ -254,11 +254,10 @@ mod tests {
.zip_eq(maybe_same_leaf_digests)
.collect();

let inclusion_proof = MerkleTreeInclusionProof::<Tip5> {
let inclusion_proof = MerkleTreeInclusionProof {
tree_height,
indexed_leafs,
authentication_structure: auth_structure,
..MerkleTreeInclusionProof::default()
};
assert!(inclusion_proof.verify(merkle_tree.root()));
}
Expand Down
4 changes: 2 additions & 2 deletions triton-vm/src/shared_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ pub(crate) struct LeavedMerkleTreeTestData {
#[strategy(Just(#leaves.iter().map(|&x| x.into()).collect()))]
pub leaves_as_digests: Vec<Digest>,

#[strategy(Just(CpuParallel::from_digests(&#leaves_as_digests).unwrap()))]
pub merkle_tree: MerkleTree<Tip5>,
#[strategy(Just(MerkleTree::new::<CpuParallel>(&#leaves_as_digests).unwrap()))]
pub merkle_tree: MerkleTree,

#[strategy(Just(#revealed_indices.iter().map(|&i| #leaves[i]).collect()))]
pub revealed_leaves: Vec<XFieldElement>,
Expand Down
13 changes: 5 additions & 8 deletions triton-vm/src/stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ impl Stark {
quotient_segments_rows.map(hash_row).collect::<Vec<_>>();
profiler!(stop "hash rows of quotient segments");
profiler!(start "Merkle tree" ("hash"));
let quot_merkle_tree: MerkleTree<Tip5> =
CpuParallel::from_digests(&fri_domain_quotient_segment_codewords_digests)?;
let quot_merkle_tree =
MerkleTree::new::<CpuParallel>(&fri_domain_quotient_segment_codewords_digests)?;
let quot_merkle_tree_root = quot_merkle_tree.root();
proof_stream.enqueue(ProofItem::MerkleRoot(quot_merkle_tree_root));
profiler!(stop "Merkle tree");
Expand Down Expand Up @@ -890,11 +890,10 @@ impl Stark {
index_iter.zip_eq(leaves).collect()
};
profiler!(start "Merkle verify (base tree)" ("hash"));
let base_merkle_tree_inclusion_proof = MerkleTreeInclusionProof::<Tip5> {
let base_merkle_tree_inclusion_proof = MerkleTreeInclusionProof {
tree_height: merkle_tree_height,
indexed_leafs: index_leaves(leaf_digests_base),
authentication_structure: base_authentication_structure,
..MerkleTreeInclusionProof::default()
};
if !base_merkle_tree_inclusion_proof.verify(base_merkle_tree_root) {
return Err(VerificationError::BaseCodewordAuthenticationFailure);
Expand All @@ -916,11 +915,10 @@ impl Stark {
profiler!(stop "dequeue extension elements");

profiler!(start "Merkle verify (extension tree)" ("hash"));
let ext_merkle_tree_inclusion_proof = MerkleTreeInclusionProof::<Tip5> {
let ext_merkle_tree_inclusion_proof = MerkleTreeInclusionProof {
tree_height: merkle_tree_height,
indexed_leafs: index_leaves(leaf_digests_ext),
authentication_structure: ext_authentication_structure,
..MerkleTreeInclusionProof::default()
};
if !ext_merkle_tree_inclusion_proof.verify(extension_tree_merkle_root) {
return Err(VerificationError::ExtensionCodewordAuthenticationFailure);
Expand All @@ -938,11 +936,10 @@ impl Stark {
profiler!(stop "dequeue quotient segments' elements");

profiler!(start "Merkle verify (combined quotient)" ("hash"));
let quot_merkle_tree_inclusion_proof = MerkleTreeInclusionProof::<Tip5> {
let quot_merkle_tree_inclusion_proof = MerkleTreeInclusionProof {
tree_height: merkle_tree_height,
indexed_leafs: index_leaves(revealed_quotient_segments_digests),
authentication_structure: revealed_quotient_authentication_structure,
..MerkleTreeInclusionProof::default()
};
if !quot_merkle_tree_inclusion_proof.verify(quotient_codeword_merkle_root) {
return Err(VerificationError::QuotientCodewordAuthenticationFailure);
Expand Down
4 changes: 2 additions & 2 deletions triton-vm/src/table/master_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,13 @@ where

/// Compute a Merkle tree of the FRI domain table. Every row gives one leaf in the tree.
/// The function [`hash_row`](Self::hash_one_row) is used to hash each row.
fn merkle_tree(&self) -> MerkleTree<Tip5> {
fn merkle_tree(&self) -> MerkleTree {
profiler!(start "leafs");
let hashed_rows = self.hash_all_fri_domain_rows();
profiler!(stop "leafs");

profiler!(start "Merkle tree");
let merkle_tree = CpuParallel::from_digests(&hashed_rows).unwrap();
let merkle_tree = MerkleTree::new::<CpuParallel>(&hashed_rows).unwrap();
profiler!(stop "Merkle tree");

merkle_tree
Expand Down
3 changes: 1 addition & 2 deletions triton-vm/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1524,11 +1524,10 @@ pub(crate) mod tests {
/// - produces the correct output.
#[must_use]
pub fn is_integral(&self) -> bool {
let inclusion_proof = MerkleTreeInclusionProof::<Tip5> {
let inclusion_proof = MerkleTreeInclusionProof {
tree_height: self.leaved_merkle_tree.merkle_tree.height(),
indexed_leafs: vec![(self.revealed_leafs_index, self.new_leaf)],
authentication_structure: self.authentication_path(),
_hasher: std::marker::PhantomData,
};

let new_root = self.clone().assemble().run().unwrap();
Expand Down

0 comments on commit d77e736

Please sign in to comment.