Skip to content

Commit

Permalink
Improve batch blame midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert committed Mar 4, 2024
1 parent 9a0e46a commit 3e88ed8
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,20 @@ impl Proof {
let mut right = proofs.len();

while left < right {
let unscaled_average = left
.checked_add(right)
#[allow(clippy::arithmetic_side_effects)]
let average = left
.checked_add(
// This cannot underflow since `left < right`
(right - left) / 2,
)
.ok_or(ProofError::FailedBatchVerificationWithSingleBlame { index: None })?;

let mid = if unscaled_average % 2 == 0 {
unscaled_average / 2
#[allow(clippy::arithmetic_side_effects)]
// This cannot underflow since `left < right`
let mid = if (right - left) % 2 == 0 {
average
} else {
(unscaled_average / 2)
average
.checked_add(1)
.ok_or(ProofError::FailedBatchVerificationWithSingleBlame { index: None })?
};
Expand Down

0 comments on commit 3e88ed8

Please sign in to comment.