From d77e7360d33de7b67d436e0d7926536c79d7dc94 Mon Sep 17 00:00:00 2001 From: Jan Ferdinand Sauer Date: Mon, 19 Aug 2024 13:48:16 +0200 Subject: [PATCH] chore(deps): Upgrade dependencies --- Cargo.toml | 4 ++-- triton-vm/benches/initialize_array.rs | 3 +-- triton-vm/src/fri.rs | 32 +++++++++++++-------------- triton-vm/src/proof_stream.rs | 5 ++--- triton-vm/src/shared_tests.rs | 4 ++-- triton-vm/src/stark.rs | 13 +++++------ triton-vm/src/table/master_table.rs | 4 ++-- triton-vm/src/vm.rs | 3 +-- 8 files changed, 30 insertions(+), 38 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c9e262778..96fc5648c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" @@ -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] diff --git a/triton-vm/benches/initialize_array.rs b/triton-vm/benches/initialize_array.rs index 92d1de536..40859e796 100644 --- a/triton-vm/benches/initialize_array.rs +++ b/triton-vm/benches/initialize_array.rs @@ -78,9 +78,8 @@ fn set_ones(matrix: &mut Array2, indices: &[(usize, usize)]) { fn into_shape() -> Array2 { 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() -> Array2 { diff --git a/triton-vm/src/fri.rs b/triton-vm/src/fri.rs index e773c3b09..672fbe296 100644 --- a/triton-vm/src/fri.rs +++ b/triton-vm/src/fri.rs @@ -32,9 +32,9 @@ pub struct Fri { } #[derive(Debug, Eq, PartialEq)] -struct FriProver<'stream, H: AlgebraicHasher> { +struct FriProver<'stream> { proof_stream: &'stream mut ProofStream, - rounds: Vec>, + rounds: Vec, first_round_domain: ArithmeticDomain, num_rounds: usize, num_collinearity_checks: usize, @@ -42,13 +42,13 @@ struct FriProver<'stream, H: AlgebraicHasher> { } #[derive(Debug, Clone, Eq, PartialEq)] -struct ProverRound { +struct ProverRound { domain: ArithmeticDomain, codeword: Vec, - merkle_tree: MerkleTree, + 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 { @@ -73,17 +73,17 @@ impl<'stream, H: AlgebraicHasher> FriProver<'stream, H> { Ok(()) } - fn commit_to_round(&mut self, round: &ProverRound) { + 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) { + fn store_round(&mut self, round: ProverRound) { self.rounds.push(round); } - fn construct_next_round(&mut self) -> ProverResult> { + fn construct_next_round(&mut self) -> ProverResult { 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); @@ -157,7 +157,7 @@ impl<'stream, H: AlgebraicHasher> FriProver<'stream, H> { } } -impl ProverRound { +impl ProverRound { fn new(domain: ArithmeticDomain, codeword: &[XFieldElement]) -> ProverResult { debug_assert_eq!(domain.length, codeword.len()); let merkle_tree = Self::merkle_tree_from_codeword(codeword)?; @@ -169,9 +169,9 @@ impl ProverRound { Ok(round) } - fn merkle_tree_from_codeword(codeword: &[XFieldElement]) -> ProverResult> { + fn merkle_tree_from_codeword(codeword: &[XFieldElement]) -> ProverResult { let digests = codeword_as_digests(codeword); - CpuParallel::from_digests(&digests).map_err(FriProvingError::MerkleTreeError) + MerkleTree::new::(&digests).map_err(FriProvingError::MerkleTreeError) } fn split_and_fold(&self, folding_challenge: XFieldElement) -> Vec { @@ -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:: { + 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(()), @@ -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:: { + 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(()), @@ -441,7 +439,7 @@ impl<'stream, H: AlgebraicHasher> FriVerifier<'stream, H> { fn last_round_codeword_merkle_root(&self) -> VerifierResult { let codeword_digests = codeword_as_digests(&self.last_round_codeword); - let merkle_tree: MerkleTree = CpuParallel::from_digests(&codeword_digests) + let merkle_tree = MerkleTree::new::(&codeword_digests) .map_err(FriValidationError::MerkleTreeError)?; Ok(merkle_tree.root()) @@ -548,7 +546,7 @@ impl Fri { Ok(prover.first_round_collinearity_check_indices) } - fn prover<'stream>(&'stream self, proof_stream: &'stream mut ProofStream) -> FriProver { + fn prover<'stream>(&'stream self, proof_stream: &'stream mut ProofStream) -> FriProver { FriProver { proof_stream, rounds: vec![], diff --git a/triton-vm/src/proof_stream.rs b/triton-vm/src/proof_stream.rs index 699e0ed79..f0c90e28f 100644 --- a/triton-vm/src/proof_stream.rs +++ b/triton-vm/src/proof_stream.rs @@ -223,7 +223,7 @@ mod tests { let num_leaves = 1 << tree_height; let leaf_values: Vec = random_elements(num_leaves); let leaf_digests = leaf_values.iter().map(|&xfe| xfe.into()).collect_vec(); - let merkle_tree: MerkleTree = CpuParallel::from_digests(&leaf_digests).unwrap(); + let merkle_tree = MerkleTree::new::(&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) @@ -254,11 +254,10 @@ mod tests { .zip_eq(maybe_same_leaf_digests) .collect(); - let inclusion_proof = MerkleTreeInclusionProof:: { + let inclusion_proof = MerkleTreeInclusionProof { tree_height, indexed_leafs, authentication_structure: auth_structure, - ..MerkleTreeInclusionProof::default() }; assert!(inclusion_proof.verify(merkle_tree.root())); } diff --git a/triton-vm/src/shared_tests.rs b/triton-vm/src/shared_tests.rs index 78fdd4ada..c1fe25686 100644 --- a/triton-vm/src/shared_tests.rs +++ b/triton-vm/src/shared_tests.rs @@ -65,8 +65,8 @@ pub(crate) struct LeavedMerkleTreeTestData { #[strategy(Just(#leaves.iter().map(|&x| x.into()).collect()))] pub leaves_as_digests: Vec, - #[strategy(Just(CpuParallel::from_digests(&#leaves_as_digests).unwrap()))] - pub merkle_tree: MerkleTree, + #[strategy(Just(MerkleTree::new::(&#leaves_as_digests).unwrap()))] + pub merkle_tree: MerkleTree, #[strategy(Just(#revealed_indices.iter().map(|&i| #leaves[i]).collect()))] pub revealed_leaves: Vec, diff --git a/triton-vm/src/stark.rs b/triton-vm/src/stark.rs index 0d939a84d..363677845 100644 --- a/triton-vm/src/stark.rs +++ b/triton-vm/src/stark.rs @@ -196,8 +196,8 @@ impl Stark { quotient_segments_rows.map(hash_row).collect::>(); profiler!(stop "hash rows of quotient segments"); profiler!(start "Merkle tree" ("hash")); - let quot_merkle_tree: MerkleTree = - CpuParallel::from_digests(&fri_domain_quotient_segment_codewords_digests)?; + let quot_merkle_tree = + MerkleTree::new::(&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"); @@ -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:: { + 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); @@ -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:: { + 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); @@ -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:: { + 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); diff --git a/triton-vm/src/table/master_table.rs b/triton-vm/src/table/master_table.rs index 692ff9c38..0315692e1 100644 --- a/triton-vm/src/table/master_table.rs +++ b/triton-vm/src/table/master_table.rs @@ -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 { + 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::(&hashed_rows).unwrap(); profiler!(stop "Merkle tree"); merkle_tree diff --git a/triton-vm/src/vm.rs b/triton-vm/src/vm.rs index 46c4fcebc..b7c43bc16 100644 --- a/triton-vm/src/vm.rs +++ b/triton-vm/src/vm.rs @@ -1524,11 +1524,10 @@ pub(crate) mod tests { /// - produces the correct output. #[must_use] pub fn is_integral(&self) -> bool { - let inclusion_proof = MerkleTreeInclusionProof:: { + 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();