Skip to content

Commit 138fbf9

Browse files
authored
Merge pull request #15 from leonace924/fix/int-overflow
fix: integer overflow in calculation
2 parents 0cd0460 + 534c7f9 commit 138fbf9

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

crates/consensus/src/stake_weighted_pbft.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ impl StakeWeightedRoundState {
118118
}
119119
let approve_stake = self.approve_stake();
120120
// Require strictly more than 50% to prevent ties
121-
approve_stake * 2 > total_stake
121+
// Use division instead of multiplication to avoid overflow with large stake values
122+
approve_stake > total_stake / 2
122123
}
123124

124125
/// Check if rejection is certain (>50% reject stake)
@@ -127,7 +128,8 @@ impl StakeWeightedRoundState {
127128
return false;
128129
}
129130
let reject_stake = self.reject_stake();
130-
reject_stake * 2 > total_stake
131+
// Use division instead of multiplication to avoid overflow with large stake values
132+
reject_stake > total_stake / 2
131133
}
132134

133135
/// Get vote count (for logging)

0 commit comments

Comments
 (0)