diff --git a/crypto/keys/multisig/multisig_test.go b/crypto/keys/multisig/multisig_test.go index 433776a6e4f..1fc16893eb9 100644 --- a/crypto/keys/multisig/multisig_test.go +++ b/crypto/keys/multisig/multisig_test.go @@ -124,7 +124,7 @@ func TestVerifyMultisignature(t *testing.T) { func(require *require.Assertions) { k := 2 signingIndices := []int{0, 3, 1} - pubKeys, sigs := generatePubKeysAndSignatures(5, msg) + pubKeys, sigs := generatePubKeysAndSignatures(8, msg) pk = kmultisig.NewLegacyAminoPubKey(k, pubKeys) sig = multisig.NewMultisig(len(pubKeys)) signBytesFn := func(mode signing.SignMode) ([]byte, error) { return msg, nil } diff --git a/crypto/types/compact_bit_array.go b/crypto/types/compact_bit_array.go index 1bbd5ec07db..741509f7753 100644 --- a/crypto/types/compact_bit_array.go +++ b/crypto/types/compact_bit_array.go @@ -92,13 +92,15 @@ func (bA *CompactBitArray) NumTrueBitsBefore(index int) int { index = max } // below we iterate over the bytes then over bits (in low endian) and count bits set to 1 - for elem := 0; ; elem++ { + for elem := 0; elem < len(bA.Elems); elem++ { if elem*8+7 >= index { onesCount += bits.OnesCount8(bA.Elems[elem] >> (7 - (index % 8) + 1)) return onesCount } onesCount += bits.OnesCount8(bA.Elems[elem]) } + + return onesCount } // Copy returns a copy of the provided bit array. diff --git a/crypto/types/compact_bit_array_test.go b/crypto/types/compact_bit_array_test.go index 11984729ac2..1a76d453135 100644 --- a/crypto/types/compact_bit_array_test.go +++ b/crypto/types/compact_bit_array_test.go @@ -205,6 +205,7 @@ func TestCompactBitArrayNumOfTrueBitsBefore(t *testing.T) { {`"x"`, []int{0}, []int{0}}, {`"_x"`, []int{1}, []int{0}}, {`"x___xxxx"`, []int{0, 4, 5, 6, 7}, []int{0, 1, 2, 3, 4}}, + {`"x___xxxx"`, []int{0, 4, 5, 6, 7, 8}, []int{0, 1, 2, 3, 4, 5}}, {`"__x_xx_x__x_x___"`, []int{2, 4, 5, 7, 10, 12}, []int{0, 1, 2, 3, 4, 5}}, {`"______________xx"`, []int{14, 15}, []int{0, 1}}, }