Browse Source

(squash this) address Jae's comments on `NumTrueBitsBefore`

pull/2164/head
ValarDragon 6 years ago
parent
commit
6beaf6e72d
3 changed files with 6 additions and 8 deletions
  1. +4
    -6
      crypto/multisig/compact_bit_array.go
  2. +1
    -1
      crypto/multisig/multisignature.go
  3. +1
    -1
      crypto/multisig/threshold_multisig.go

+ 4
- 6
crypto/multisig/compact_bit_array.go View File

@ -71,12 +71,10 @@ func (bA *CompactBitArray) SetIndex(i int, v bool) bool {
return true 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 numTrueValues := 0
for i := 0; i < index; i++ { for i := 0; i < index; i++ {
if bA.GetIndex(i) { if bA.GetIndex(i) {


+ 1
- 1
crypto/multisig/multisignature.go View File

@ -33,7 +33,7 @@ func getIndex(pk crypto.PubKey, keys []crypto.PubKey) int {
// AddSignature adds a signature to the multisig, at the corresponding index. // AddSignature adds a signature to the multisig, at the corresponding index.
// If the signature already exists, replace it. // If the signature already exists, replace it.
func (mSig *Multisignature) AddSignature(sig []byte, index int) { 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 // Signature already exists, just replace the value there
if mSig.BitArray.GetIndex(index) { if mSig.BitArray.GetIndex(index) {
mSig.Sigs[newSigIndex] = sig mSig.Sigs[newSigIndex] = sig


+ 1
- 1
crypto/multisig/threshold_multisig.go View File

@ -47,7 +47,7 @@ func (pk *ThresholdMultiSignaturePubKey) VerifyBytes(msg []byte, marshalledSig [
return false return false
} }
// ensure at least k signatures are set // 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 return false
} }
// index in the list of signatures which we are concerned with. // index in the list of signatures which we are concerned with.


Loading…
Cancel
Save