Skip to content

Commit

Permalink
perf(verifier): Remove parallelism
Browse files Browse the repository at this point in the history
The parallelism in Triton VM's verifier has more overhead than benefit.
  • Loading branch information
jan-ferdinand committed Jan 13, 2025
1 parent 2530bfc commit baf5860
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ strum = { version = "0.26", features = ["derive"] }
syn = "2.0"
test-strategy = "0.4.0"
thiserror = "2.0"
twenty-first = "0.44.1"
twenty-first = "0.45.0"
unicode-width = "0.2"
divan = "0.1.17"

Expand Down
9 changes: 4 additions & 5 deletions triton-vm/src/fri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ impl ProverRound {
}

fn merkle_tree_from_codeword(codeword: &[XFieldElement]) -> ProverResult<MerkleTree> {
let digests = codeword_as_digests(codeword);
MerkleTree::new::<CpuParallel>(&digests).map_err(FriProvingError::MerkleTreeError)
let digests: Vec<_> = codeword.par_iter().map(|&xfe| xfe.into()).collect();
MerkleTree::par_new(&digests).map_err(FriProvingError::MerkleTreeError)
}

fn split_and_fold(&self, folding_challenge: XFieldElement) -> Vec<XFieldElement> {
Expand Down Expand Up @@ -385,7 +385,6 @@ impl FriVerifier<'_> {
let folding_challenge = round.folding_challenge.unwrap();

(0..self.num_collinearity_checks)
.into_par_iter()
.map(|i| {
let point_a_x = domain.domain_value(a_indices[i] as u32).lift();
let point_b_x = domain.domain_value(b_indices[i] as u32).lift();
Expand Down Expand Up @@ -434,7 +433,7 @@ impl FriVerifier<'_> {

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

Ok(merkle_tree.root())
Expand Down Expand Up @@ -618,7 +617,7 @@ impl Fri {
}

fn codeword_as_digests(codeword: &[XFieldElement]) -> Vec<Digest> {
codeword.par_iter().map(|&xfe| xfe.into()).collect()
codeword.iter().map(|&xfe| xfe.into()).collect()
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion 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::new::<CpuParallel>(&leaf_digests).unwrap();
let merkle_tree = MerkleTree::par_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)
Expand Down
2 changes: 1 addition & 1 deletion triton-vm/src/shared_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub(crate) struct LeavedMerkleTreeTestData {
#[strategy(Just(#leaves.iter().map(|&x| x.into()).collect()))]
pub leaves_as_digests: Vec<Digest>,

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

#[strategy(Just(#revealed_indices.iter().map(|&i| #leaves[i]).collect()))]
Expand Down
5 changes: 2 additions & 3 deletions triton-vm/src/stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ impl Prover {
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::new::<CpuParallel>(&fri_domain_quotient_segment_codewords_digests)?;
let quot_merkle_tree = MerkleTree::par_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");
Expand Down Expand Up @@ -1353,7 +1352,7 @@ impl Verifier {
let interpret_xfe_as_bfes = |xfe: XFieldElement| xfe.coefficients.to_vec();
let collect_row_as_bfes = |row: &QuotientSegments| row.map(interpret_xfe_as_bfes).concat();
quotient_segment_rows
.par_iter()
.iter()
.map(collect_row_as_bfes)
.map(|row| Tip5::hash_varlen(&row))
.collect()
Expand Down
2 changes: 1 addition & 1 deletion triton-vm/src/table/master_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ where
profiler!(stop "leafs");

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

merkle_tree
Expand Down

0 comments on commit baf5860

Please sign in to comment.