From 6beaf6e72dd2606c74d417334f2b502da8b27421 Mon Sep 17 00:00:00 2001 From: ValarDragon Date: Mon, 13 Aug 2018 18:46:33 -0700 Subject: [PATCH] (squash this) address Jae's comments on `NumTrueBitsBefore` --- crypto/multisig/compact_bit_array.go | 10 ++++------ crypto/multisig/multisignature.go | 2 +- crypto/multisig/threshold_multisig.go | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/crypto/multisig/compact_bit_array.go b/crypto/multisig/compact_bit_array.go index be31a5c70..94e9791cd 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 374b5e1b4..29e8a30b9 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 01462d6fb..58a3ea0e3 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.