light: ensure trust level is strictly less than 1 (#6447)

This commit is contained in:
Callum Waters
2021-05-11 15:13:52 +02:00
committed by GitHub
parent d1c9463bef
commit 811dbe439f
2 changed files with 14 additions and 13 deletions

View File

@@ -167,10 +167,10 @@ func Verify(
// ValidateTrustLevel checks that trustLevel is within the allowed range [1/3,
// 1]. If not, it returns an error. 1/3 is the minimum amount of trust needed
// which does not break the security model.
// which does not break the security model. Must be strictly less than 1.
func ValidateTrustLevel(lvl tmmath.Fraction) error {
if lvl.Numerator*3 < lvl.Denominator || // < 1/3
lvl.Numerator > lvl.Denominator || // > 1
lvl.Numerator >= lvl.Denominator || // >= 1
lvl.Denominator == 0 {
return fmt.Errorf("trustLevel must be within [1/3, 1], given %v", lvl)
}