Browse Source

(squash this) squashed bug with multiple signatures at same index.

pull/2164/head
ValarDragon 6 years ago
parent
commit
4e7bf10b59
2 changed files with 15 additions and 3 deletions
  1. +1
    -1
      crypto/multisig/threshold_multisig.go
  2. +14
    -2
      crypto/multisig/threshold_multisig_test.go

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

@ -34,7 +34,7 @@ func (pk *ThresholdMultiSignaturePubKey) VerifyBytes(msg []byte, marshalledSig [
return false
}
size := sig.BitArray.Size()
if len(sig.Sigs) < int(pk.K) || len(pk.Pubkeys) != size {
if len(sig.Sigs) < int(pk.K) || len(pk.Pubkeys) != size || sig.BitArray.NumOfTrueBitsBefore(size) < int(pk.K) {
return false
}
// index in the list of signatures which we are concerned with.


+ 14
- 2
crypto/multisig/threshold_multisig_test.go View File

@ -19,9 +19,9 @@ func TestThresholdMultisig(t *testing.T) {
require.False(t, multisigKey.VerifyBytes(msg, multisignature.Marshal()))
multisignature.AddSignatureFromPubkey(sigs[0], pubkeys[0], pubkeys)
require.False(t, multisigKey.VerifyBytes(msg, multisignature.Marshal()))
// Make sure adding the same signature twice doesn't make the signature pass
// Make sure adding the same signature twice doesn't increase number of signatures
multisignature.AddSignatureFromPubkey(sigs[0], pubkeys[0], pubkeys)
require.False(t, multisigKey.VerifyBytes(msg, multisignature.Marshal()))
require.Equal(t, 1, len(multisignature.Sigs))
// Adding two signatures should make it pass, as k = 2
multisignature.AddSignatureFromPubkey(sigs[3], pubkeys[3], pubkeys)
@ -39,6 +39,18 @@ func TestThresholdMultisig(t *testing.T) {
require.False(t, multisigKey.VerifyBytes(msg, multisignature.Marshal()))
}
func TestThresholdMultisigDuplicateSignatures(t *testing.T) {
msg := []byte{1, 2, 3, 4, 5}
pubkeys, sigs := generatePubKeysAndSignatures(5, msg)
multisigKey := NewThresholdMultiSignaturePubKey(2, pubkeys)
multisignature := NewMultisig(5)
require.False(t, multisigKey.VerifyBytes(msg, multisignature.Marshal()))
multisignature.AddSignatureFromPubkey(sigs[0], pubkeys[0], pubkeys)
// Add second signature manually
multisignature.Sigs = append(multisignature.Sigs, sigs[0])
require.False(t, multisigKey.VerifyBytes(msg, multisignature.Marshal()))
}
func TestMultiSigPubkeyEquality(t *testing.T) {
msg := []byte{1, 2, 3, 4}
pubkeys, _ := generatePubKeysAndSignatures(5, msg)


Loading…
Cancel
Save