diff --git a/crypto/multisig/compact_bit_array.go b/crypto/multisig/compact_bit_array.go index be31a5c7..94e9791c 100644 --- a/crypto/multisig/compact_bit_array.go +++ b/crypto/multisig/compact_bit_array.go @@ -71,12 +71,10 @@ func (bA *CompactBitArray) SetIndex(i int, v bool) bool { return true } -// NumOfTrueBitsBefore returns the location of the given index, among the -// values in the bit array that are set to true. -// e.g. if bA = _XX_X_X, NumOfTrueBitsBefore(4) = 2, since -// the value at index 4 of the bit array is the third -// value that is true. (And it is 0-indexed) -func (bA *CompactBitArray) NumOfTrueBitsBefore(index int) int { +// NumTrueBitsBefore returns the number of bits set to true before the +// given index. e.g. if bA = _XX__XX, NumOfTrueBitsBefore(4) = 2, since +// there are two bits set to true before index 4. +func (bA *CompactBitArray) NumTrueBitsBefore(index int) int { numTrueValues := 0 for i := 0; i < index; i++ { if bA.GetIndex(i) { diff --git a/crypto/multisig/multisignature.go b/crypto/multisig/multisignature.go index 374b5e1b..29e8a30b 100644 --- a/crypto/multisig/multisignature.go +++ b/crypto/multisig/multisignature.go @@ -33,7 +33,7 @@ func getIndex(pk crypto.PubKey, keys []crypto.PubKey) int { // AddSignature adds a signature to the multisig, at the corresponding index. // If the signature already exists, replace it. func (mSig *Multisignature) AddSignature(sig []byte, index int) { - newSigIndex := mSig.BitArray.NumOfTrueBitsBefore(index) + newSigIndex := mSig.BitArray.NumTrueBitsBefore(index) // Signature already exists, just replace the value there if mSig.BitArray.GetIndex(index) { mSig.Sigs[newSigIndex] = sig diff --git a/crypto/multisig/threshold_multisig.go b/crypto/multisig/threshold_multisig.go index 01462d6f..58a3ea0e 100644 --- a/crypto/multisig/threshold_multisig.go +++ b/crypto/multisig/threshold_multisig.go @@ -47,7 +47,7 @@ func (pk *ThresholdMultiSignaturePubKey) VerifyBytes(msg []byte, marshalledSig [ return false } // ensure at least k signatures are set - if sig.BitArray.NumOfTrueBitsBefore(size) < int(pk.K) { + if sig.BitArray.NumTrueBitsBefore(size) < int(pk.K) { return false } // index in the list of signatures which we are concerned with.