fix: curveThreshold function to handle zero length divisor case (#11953)

This commit is contained in:
Arjun Porwal 2025-10-29 20:15:44 +05:30 committed by GitHub
parent 338431fe2a
commit 104826b0d5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -67,6 +67,11 @@ export function curveThreshold (curve: PalletReferendaCurve, input: BN, div: BN)
if (curve.isLinearDecreasing) {
const { ceil, floor, length } = curve.asLinearDecreasing;
// if divisor is zero, we return the max
if (length.isZero()) {
return BN_BILLION;
}
// *ceil - (x.min(*length).saturating_div(*length, Down) * (*ceil - *floor))
// NOTE: We first multiply, then divide (since we work with fractions)
return ceil.sub(