diff --git a/light/verifier.go b/light/verifier.go index 165a9a641..d9c8019eb 100644 --- a/light/verifier.go +++ b/light/verifier.go @@ -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) } diff --git a/light/verifier_test.go b/light/verifier_test.go index 9e10810b2..556beee75 100644 --- a/light/verifier_test.go +++ b/light/verifier_test.go @@ -311,25 +311,26 @@ func TestValidateTrustLevel(t *testing.T) { valid bool }{ // valid - 0: {tmmath.Fraction{Numerator: 1, Denominator: 1}, true}, - 1: {tmmath.Fraction{Numerator: 1, Denominator: 3}, true}, - 2: {tmmath.Fraction{Numerator: 2, Denominator: 3}, true}, - 3: {tmmath.Fraction{Numerator: 3, Denominator: 3}, true}, - 4: {tmmath.Fraction{Numerator: 4, Denominator: 5}, true}, + 0: {tmmath.Fraction{Numerator: 1, Denominator: 3}, true}, + 1: {tmmath.Fraction{Numerator: 2, Denominator: 3}, true}, + 2: {tmmath.Fraction{Numerator: 4, Denominator: 5}, true}, + 3: {tmmath.Fraction{Numerator: 99, Denominator: 100}, true}, // invalid + 4: {tmmath.Fraction{Numerator: 3, Denominator: 3}, false}, 5: {tmmath.Fraction{Numerator: 6, Denominator: 5}, false}, - 6: {tmmath.Fraction{Numerator: 0, Denominator: 1}, false}, - 7: {tmmath.Fraction{Numerator: 0, Denominator: 0}, false}, - 8: {tmmath.Fraction{Numerator: 1, Denominator: 0}, false}, + 6: {tmmath.Fraction{Numerator: 3, Denominator: 10}, false}, + 7: {tmmath.Fraction{Numerator: 0, Denominator: 1}, false}, + 8: {tmmath.Fraction{Numerator: 0, Denominator: 0}, false}, + 9: {tmmath.Fraction{Numerator: 1, Denominator: 0}, false}, } - for _, tc := range testCases { + for idx, tc := range testCases { err := light.ValidateTrustLevel(tc.lvl) if !tc.valid { - assert.Error(t, err) + assert.Error(t, err, idx) } else { - assert.NoError(t, err) + assert.NoError(t, err, idx) } } }