Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(crypto): Multisig verification doesn't work for multisig sizes of multiples of 8 #11142

Merged
merged 6 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crypto/keys/multisig/multisig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
4 changes: 3 additions & 1 deletion crypto/types/compact_bit_array.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions crypto/types/compact_bit_array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}},
}
Expand Down