From fb8a21949b162254d9471130f5ffca67187c83e2 Mon Sep 17 00:00:00 2001 From: Varun Thakore Date: Thu, 29 Aug 2024 00:55:18 +0530 Subject: [PATCH] fix: subtraction overflow --- commitment_scheme/src/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/commitment_scheme/src/lib.rs b/commitment_scheme/src/lib.rs index 4f45025..3fcfc5a 100644 --- a/commitment_scheme/src/lib.rs +++ b/commitment_scheme/src/lib.rs @@ -349,8 +349,12 @@ where W: Digest + Clone + 'static, { // Calculate the number of layers in the segment and the total height - let n_layers_in_segment = - n_elements_in_segment.ilog2() as usize - if n_columns == 1 { 1 } else { 0 }; + let n_layers_in_segment = if n_elements_in_segment == 1 { + 0 + } else { + n_elements_in_segment.ilog2() as usize - if n_columns == 1 { 1 } else { 0 } + }; + let segment_tree_height = n_segments.ilog2() as usize; let total_height = n_layers_in_segment + segment_tree_height; let is_verifier_friendly_layer = total_height < n_verifier_friendly_commitment_layers;