From 7c1a8263763733e47ccf0376063294bdae903748 Mon Sep 17 00:00:00 2001 From: TAKAMI Torao Date: Thu, 3 Sep 2020 17:52:12 +0900 Subject: [PATCH 1/4] added signature aggregation and verify to block --- CHANGELOG_PENDING.md | 1 + blockchain/v1/reactor_test.go | 5 +- config/config.go | 1 + consensus/byzantine_test.go | 1 + consensus/common_test.go | 1 + consensus/invalid_test.go | 5 +- consensus/state.go | 2 + consensus/types/height_vote_set_test.go | 1 + crypto/bls/bls.go | 72 ++++- crypto/bls/bls_test.go | 245 ++++++++++++++++++ crypto/composite/composite.go | 3 +- crypto/composite/composite_test.go | 116 +++++++++ crypto/ed25519/ed25519.go | 1 + lite/helpers.go | 1 + lite2/helpers_test.go | 1 + privval/file_test.go | 1 + privval/signer_client_test.go | 51 ++-- proto/types/types.pb.go | 193 +++++++------- proto/types/types.proto | 4 + rpc/client/rpc_test.go | 10 +- state/validation_test.go | 1 + .../internal/test_harness.go | 1 + types/block.go | 101 +++++++- types/block_test.go | 128 ++++++++- types/evidence_test.go | 1 + types/test_util.go | 2 + types/validator_set_test.go | 14 +- types/vote.go | 6 +- types/vote_set.go | 35 ++- types/vote_set_test.go | 83 ++++++ types/vote_test.go | 21 +- types/voter_set.go | 62 ++--- types/voter_set_test.go | 4 +- 33 files changed, 989 insertions(+), 185 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index d259ec2bd..788f8b313 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -16,6 +16,7 @@ - Blockchain Protocol - [consensus] [\#101](https://github.com/line/tendermint/pull/101) Introduce composite key to delegate features to each function key +- [consensus] [\#117](https://github.com/line/tendermint/pull/117) BLS Signature Aggregation and Verification ### FEATURES: - [init command] [\#125](https://github.com/line/tendermint/pull/125) Add an option selecting private key type to init, testnet commands diff --git a/blockchain/v1/reactor_test.go b/blockchain/v1/reactor_test.go index 041409a03..38325eff0 100644 --- a/blockchain/v1/reactor_test.go +++ b/blockchain/v1/reactor_test.go @@ -67,6 +67,7 @@ func makeVote( Timestamp: tmtime.Now(), Type: types.PrecommitType, BlockID: blockID, + Signature: []byte{}, } _ = privVal.SignVote(header.ChainID, vote) @@ -229,9 +230,9 @@ func TestFastSyncNoBlockResponse(t *testing.T) { for _, tt := range tests { block := reactorPairs[1].bcR.store.LoadBlock(tt.height) if tt.existent { - assert.True(t, block != nil) + assert.True(t, block != nil, "height=%d, existent=%t", tt.height, tt.existent) } else { - assert.True(t, block == nil) + assert.True(t, block == nil, "height=%d, existent=%t", tt.height, tt.existent) } } } diff --git a/config/config.go b/config/config.go index 933127aa1..693b61f2b 100644 --- a/config/config.go +++ b/config/config.go @@ -8,6 +8,7 @@ import ( "time" "github.com/pkg/errors" + "github.com/tendermint/tendermint/privval" ) diff --git a/consensus/byzantine_test.go b/consensus/byzantine_test.go index c9fca5bf4..bcf9fe6b0 100644 --- a/consensus/byzantine_test.go +++ b/consensus/byzantine_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/stretchr/testify/require" + config2 "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/service" diff --git a/consensus/common_test.go b/consensus/common_test.go index c6080245c..6a61cc764 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -101,6 +101,7 @@ func (vs *validatorStub) signVote( Timestamp: tmtime.Now(), Type: voteType, BlockID: types.BlockID{Hash: hash, PartsHeader: header}, + Signature: []byte{}, } err = vs.PrivValidator.SignVote(config.ChainID(), vote) diff --git a/consensus/invalid_test.go b/consensus/invalid_test.go index 1ae0a69ec..64a4774f7 100644 --- a/consensus/invalid_test.go +++ b/consensus/invalid_test.go @@ -80,8 +80,11 @@ func invalidDoPrevoteFunc(t *testing.T, height int64, round int, cs *State, sw * BlockID: types.BlockID{ Hash: blockHash, PartsHeader: types.PartSetHeader{Total: 1, Hash: tmrand.Bytes(32)}}, + Signature: []byte{}, + } + if err = cs.privValidator.SignVote(cs.state.ChainID, precommit); err != nil { + panic(err) } - cs.privValidator.SignVote(cs.state.ChainID, precommit) cs.privValidator = nil // disable priv val so we don't do normal votes cs.mtx.Unlock() diff --git a/consensus/state.go b/consensus/state.go index f7ac2c6c0..54abe79a8 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -9,6 +9,7 @@ import ( "time" "github.com/pkg/errors" + "github.com/tendermint/tendermint/libs/fail" "github.com/tendermint/tendermint/libs/log" tmos "github.com/tendermint/tendermint/libs/os" @@ -2046,6 +2047,7 @@ func (cs *State) signVote( Timestamp: cs.voteTime(), Type: msgType, BlockID: types.BlockID{Hash: hash, PartsHeader: header}, + Signature: []byte{}, } err = cs.privValidator.SignVote(cs.state.ChainID, vote) diff --git a/consensus/types/height_vote_set_test.go b/consensus/types/height_vote_set_test.go index 373e28cca..3953d0bf4 100644 --- a/consensus/types/height_vote_set_test.go +++ b/consensus/types/height_vote_set_test.go @@ -67,6 +67,7 @@ func makeVoteHR(t *testing.T, height int64, round int, privVals []types.PrivVali Timestamp: tmtime.Now(), Type: types.PrecommitType, BlockID: types.BlockID{Hash: []byte("fakehash"), PartsHeader: types.PartSetHeader{}}, + Signature: []byte{}, } chainID := config.ChainID() err = privVal.SignVote(chainID, vote) diff --git a/crypto/bls/bls.go b/crypto/bls/bls.go index 4744ef947..c3a788d0f 100644 --- a/crypto/bls/bls.go +++ b/crypto/bls/bls.go @@ -2,6 +2,7 @@ package bls import ( "bytes" + "crypto/sha512" "crypto/subtle" "fmt" @@ -46,6 +47,71 @@ func init() { // PrivKeyBLS12 implements crypto.PrivKey. type PrivKeyBLS12 [PrivKeyBLS12Size]byte +// AddSignature adds a BLS signature to the init. When the init is nil, then a new aggregate signature is built +// from specified signature. +func AddSignature(init []byte, signature []byte) (aggrSign []byte, err error) { + if init == nil { + blsSign := bls.Sign{} + init = blsSign.Serialize() + } else if len(init) != SignatureSize { + err = fmt.Errorf("invalid BLS signature: aggregated signature size %d is not valid size %d", + len(init), SignatureSize) + return + } + if len(signature) != SignatureSize { + err = fmt.Errorf("invalid BLS signature: signature size %d is not valid size %d", + len(signature), SignatureSize) + return + } + blsSign := bls.Sign{} + err = blsSign.Deserialize(signature) + if err != nil { + return + } + aggrBLSSign := bls.Sign{} + err = aggrBLSSign.Deserialize(init) + if err != nil { + return + } + aggrBLSSign.Add(&blsSign) + aggrSign = aggrBLSSign.Serialize() + return +} + +func VerifyAggregatedSignature(aggregatedSignature []byte, pubKeys []PubKeyBLS12, msgs [][]byte) error { + if len(pubKeys) != len(msgs) { + return fmt.Errorf("the number of public keys %d doesn't match the one of messages %d", + len(pubKeys), len(msgs)) + } + if aggregatedSignature == nil { + if len(pubKeys) == 0 { + return nil + } + return fmt.Errorf( + "the aggregate signature was omitted, even though %d public keys were specified", len(pubKeys)) + } + aggrSign := bls.Sign{} + err := aggrSign.Deserialize(aggregatedSignature) + if err != nil { + return err + } + blsPubKeys := make([]bls.PublicKey, len(pubKeys)) + hashes := make([][]byte, len(msgs)) + for i := 0; i < len(pubKeys); i++ { + blsPubKeys[i] = bls.PublicKey{} + err = blsPubKeys[i].Deserialize(pubKeys[i][:]) + if err != nil { + return err + } + hash := sha512.Sum512_256(msgs[i]) + hashes[i] = hash[:] + } + if !aggrSign.VerifyAggregateHashes(blsPubKeys, hashes) { + return fmt.Errorf("failed to verify the aggregated hashes by %d public keys", len(blsPubKeys)) + } + return nil +} + // GenPrivKey generates a new BLS12-381 private key. func GenPrivKey() PrivKeyBLS12 { sigKey := bls.SecretKey{} @@ -74,7 +140,8 @@ func (privKey PrivKeyBLS12) Sign(msg []byte) ([]byte, error) { if err != nil { panic(fmt.Sprintf("Failed to copy the private key: %s", err)) } - sign := blsKey.SignByte(msg) + hash := sha512.Sum512_256(msg) + sign := blsKey.SignHash(hash[:]) return sign.Serialize(), nil } @@ -143,7 +210,8 @@ func (pubKey PubKeyBLS12) VerifyBytes(msg []byte, sig []byte) bool { if err != nil { return false } - return blsSign.VerifyByte(&blsPubKey, msg) + hash := sha512.Sum512_256(msg) + return blsSign.VerifyHash(&blsPubKey, hash[:]) } // VRFVerify is not supported in BLS12. diff --git a/crypto/bls/bls_test.go b/crypto/bls/bls_test.go index f00df1da6..4058d2521 100644 --- a/crypto/bls/bls_test.go +++ b/crypto/bls/bls_test.go @@ -2,8 +2,12 @@ package bls_test import ( "bytes" + "crypto/sha256" "fmt" + "math/rand" + "reflect" "testing" + "time" b "github.com/herumi/bls-eth-go-binary/bls" "github.com/stretchr/testify/assert" @@ -234,6 +238,247 @@ func TestBasicSignatureFunctions(t *testing.T) { } } +func TestSignatureAggregationAndVerify(t *testing.T) { + privKeys := make([]b.SecretKey, 25) + pubKeys := make([]b.PublicKey, len(privKeys)) + msgs := make([][]byte, len(privKeys)) + hash32s := make([][32]byte, len(privKeys)) + signatures := make([]b.Sign, len(privKeys)) + for i, privKey := range privKeys { + privKey.SetByCSPRNG() + pubKeys[i] = *privKey.GetPublicKey() + msgs[i] = []byte(fmt.Sprintf("hello, world #%d", i)) + hash32s[i] = sha256.Sum256(msgs[i]) + signatures[i] = *privKey.SignHash(hash32s[i][:]) + + // normal single-hash case + if !signatures[i].VerifyHash(&pubKeys[i], hash32s[i][:]) { + t.Fail() + } + + // in case where 1-bit of hash was garbled + garbledHash := make([]byte, len(msgs[i])) + copy(garbledHash, msgs[i]) + garbledHash[0] ^= 1 << 0 + if garbledHash[0] == msgs[i][0] || signatures[i].VerifyByte(&pubKeys[i], garbledHash) { + t.Fail() + } + + // Verification using an invalid public key + } + + // aggregation + multiSig := b.Sign{} + multiSig.Aggregate(signatures) + + // normal case + hashes := make([][]byte, len(privKeys)) + for i := 0; i < len(hashes); i++ { + hashes[i] = hash32s[i][:] + } + if !multiSig.VerifyAggregateHashes(pubKeys, hashes) { + t.Fatalf("failed to validate the aggregate signature of the hashed message") + } + + // in case where 1-bit of signature was garbled + multiSigBytes := multiSig.Serialize() + for i := range multiSigBytes { + for j := 0; j < 8; j++ { + garbledMultiSigBytes := make([]byte, len(multiSigBytes)) + copy(garbledMultiSigBytes, multiSigBytes) + garbledMultiSigBytes[i] ^= 1 << j + if garbledMultiSigBytes[i] == multiSigBytes[i] { + t.Fail() + } + garbledMultiSig := b.Sign{} + err := garbledMultiSig.Deserialize(garbledMultiSigBytes) + if err == nil { + // Note that in some cases Deserialize() fails + if garbledMultiSig.VerifyAggregateHashes(pubKeys, hashes) { + t.Errorf("successfully verified the redacted signature") + } + } + } + } + + // in case a public key used for verification is replaced + invalidPrivKey := b.SecretKey{} + invalidPrivKey.SetByCSPRNG() + invalidPubKeys := make([]b.PublicKey, len(pubKeys)) + copy(invalidPubKeys, pubKeys) + invalidPubKeys[len(invalidPubKeys)-1] = *invalidPrivKey.GetPublicKey() + if multiSig.VerifyAggregateHashes(invalidPubKeys, hashes) { + t.Fatalf("successfully verified that it contains a public key that was not involved in the signing") + } + + // in case a hash used for verification is replaced + invalidHashes := make([][]byte, len(hashes)) + copy(invalidHashes, hashes) + invalidHash := sha256.Sum256([]byte("hello, world #99")) + invalidHashes[len(invalidHashes)-1] = invalidHash[:] + if multiSig.VerifyAggregateHashes(pubKeys, invalidHashes) { + t.Fatalf("successfully verified that it contains a hash that was not involved in the signing") + } +} + +func generatePubKeysAndSigns(t *testing.T, size int) ([]bls.PubKeyBLS12, [][]byte, [][]byte) { + pubKeys := make([]bls.PubKeyBLS12, size) + msgs := make([][]byte, len(pubKeys)) + sigs := make([][]byte, len(pubKeys)) + for i := 0; i < len(pubKeys); i++ { + var err error + privKey := bls.GenPrivKey() + pubKeys[i] = blsPublicKey(t, privKey.PubKey()) + msgs[i] = []byte(fmt.Sprintf("hello, workd #%d", i)) + sigs[i], err = privKey.Sign(msgs[i]) + if err != nil { + t.Fatal(fmt.Sprintf("fail to sign: %s", err)) + } + if !pubKeys[i].VerifyBytes(msgs[i], sigs[i]) { + t.Fatal("fail to verify signature") + } + } + return pubKeys, msgs, sigs +} + +func blsPublicKey(t *testing.T, pubKey crypto.PubKey) bls.PubKeyBLS12 { + blsPubKey, ok := pubKey.(bls.PubKeyBLS12) + if !ok { + var keyType string + if t := reflect.TypeOf(pubKey); t.Kind() == reflect.Ptr { + keyType = "*" + t.Elem().Name() + } else { + keyType = t.Name() + } + t.Fatal(fmt.Sprintf("specified public key is not for BLS: %s", keyType)) + } + return blsPubKey +} + +func aggregateSignatures(init []byte, signatures [][]byte) (aggrSig []byte, err error) { + aggrSig = init + for _, sign := range signatures { + aggrSig, err = bls.AddSignature(aggrSig, sign) + if err != nil { + return + } + } + return +} + +func TestAggregatedSignature(t *testing.T) { + + // generate BLS signatures and public keys + pubKeys, msgs, sigs := generatePubKeysAndSigns(t, 25) + + // aggregate signatures + aggrSig, err := aggregateSignatures(nil, sigs) + if err != nil { + t.Error(fmt.Sprintf("fail to aggregate BLS signatures: %s", err)) + } + if len(aggrSig) != bls.SignatureSize { + t.Error(fmt.Sprintf("inconpatible signature size: %d != %d", len(aggrSig), bls.SignatureSize)) + } + + // validate the aggregated signature + if err := bls.VerifyAggregatedSignature(aggrSig, pubKeys, msgs); err != nil { + t.Errorf("fail to verify aggregated signature: %s", err) + } + + // validate with the public keys and messages pair in random order + t.Run("Doesn't Depend on the Order of PublicKey-Message Pairs", func(t *testing.T) { + shuffledPubKeys := make([]bls.PubKeyBLS12, len(pubKeys)) + shuffledMsgs := make([][]byte, len(msgs)) + copy(shuffledPubKeys, pubKeys) + copy(shuffledMsgs, msgs) + rand.Seed(time.Now().UnixNano()) + rand.Shuffle(len(shuffledPubKeys), func(i, j int) { + shuffledPubKeys[i], shuffledPubKeys[j] = shuffledPubKeys[j], shuffledPubKeys[i] + shuffledMsgs[i], shuffledMsgs[j] = shuffledMsgs[j], shuffledMsgs[i] + }) + if err := bls.VerifyAggregatedSignature(aggrSig, shuffledPubKeys, shuffledMsgs); err != nil { + t.Errorf("fail to verify the aggregated signature with random order: %s", err) + } + }) + + // validate with the public keys in random order + t.Run("Incorrect Public Key Order", func(t *testing.T) { + shuffledPubKeys := make([]bls.PubKeyBLS12, len(pubKeys)) + copy(shuffledPubKeys, pubKeys) + rand.Seed(time.Now().UnixNano()) + rand.Shuffle(len(shuffledPubKeys), func(i, j int) { + shuffledPubKeys[i], shuffledPubKeys[j] = shuffledPubKeys[j], shuffledPubKeys[i] + }) + if err := bls.VerifyAggregatedSignature(aggrSig, shuffledPubKeys, msgs); err == nil { + t.Error("successfully validated with public keys of different order") + } + }) + + // validate with the messages in random order + t.Run("Incorrect Message Order", func(t *testing.T) { + shuffledMsgs := make([][]byte, len(msgs)) + copy(shuffledMsgs, msgs) + rand.Seed(time.Now().UnixNano()) + rand.Shuffle(len(shuffledMsgs), func(i, j int) { + shuffledMsgs[i], shuffledMsgs[j] = shuffledMsgs[j], shuffledMsgs[i] + }) + if err := bls.VerifyAggregatedSignature(aggrSig, pubKeys, shuffledMsgs); err == nil { + t.Error("successfully validated with messages of different order") + } + }) + + // replace one public key with another and detect + t.Run("Replace One Public Key", func(t *testing.T) { + pubKey, _ := bls.GenPrivKey().PubKey().(bls.PubKeyBLS12) + replacedPubKeys := make([]bls.PubKeyBLS12, len(pubKeys)) + copy(replacedPubKeys, pubKeys) + replacedPubKeys[0] = pubKey + if err := bls.VerifyAggregatedSignature(aggrSig, replacedPubKeys, msgs); err == nil { + t.Error("verification with an invalid key was successful") + } + }) + + // replace one message with another and detect + t.Run("Replace One Message", func(t *testing.T) { + msg := []byte(fmt.Sprintf("hello, world #%d replaced", len(msgs))) + replacedMsgs := make([][]byte, len(msgs)) + copy(replacedMsgs, msgs) + replacedMsgs[0] = msg + if err := bls.VerifyAggregatedSignature(aggrSig, pubKeys, replacedMsgs); err == nil { + t.Error("verification with an invalid message was successful") + } + }) + + // add new signature to existing aggregated signature and verify + t.Run("Incremental Update", func(t *testing.T) { + msg := []byte(fmt.Sprintf("hello, world #%d", len(msgs))) + privKey := bls.GenPrivKey() + pubKey := privKey.PubKey() + sig, err := privKey.Sign(msg) + assert.Nilf(t, err, "%s", err) + newAggrSig, _ := aggregateSignatures(aggrSig, [][]byte{sig}) + newPubKeys := make([]bls.PubKeyBLS12, len(pubKeys)) + copy(newPubKeys, pubKeys) + newPubKeys = append(newPubKeys, blsPublicKey(t, pubKey)) + newMsgs := make([][]byte, len(msgs)) + copy(newMsgs, msgs) + newMsgs = append(newMsgs, msg) + if err := bls.VerifyAggregatedSignature(newAggrSig, newPubKeys, newMsgs); err != nil { + t.Errorf("fail to verify the aggregate signature with the new signature: %s", err) + } + }) + + // nil is returned for nil and empty signature + nilSig, _ := aggregateSignatures(nil, [][]byte{}) + assert.Nil(t, nilSig) + + // a non-BLS signature contained + func() { + _, err = aggregateSignatures(nil, [][]byte{make([]byte, 0)}) + assert.NotNil(t, err) + }() +} + func TestSignatureAggregation(t *testing.T) { publicKeys := make([]b.PublicKey, 25) aggregatedSignature := b.Sign{} diff --git a/crypto/composite/composite.go b/crypto/composite/composite.go index fbc792cbf..4115b61c7 100644 --- a/crypto/composite/composite.go +++ b/crypto/composite/composite.go @@ -3,11 +3,10 @@ package composite import ( "bytes" + "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/bls" "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/tmhash" - - "github.com/tendermint/tendermint/crypto" ) // PubKeyComposite and PrivKeyComposite are intended to allow public key algorithms to be selected for each function. diff --git a/crypto/composite/composite_test.go b/crypto/composite/composite_test.go index c85327b03..29ca85b35 100644 --- a/crypto/composite/composite_test.go +++ b/crypto/composite/composite_test.go @@ -2,8 +2,14 @@ package composite_test import ( "bytes" + "encoding/base64" + "encoding/hex" + "fmt" "testing" + "github.com/tendermint/go-amino" + + "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/bls" "github.com/tendermint/tendermint/crypto/composite" "github.com/tendermint/tendermint/crypto/ed25519" @@ -170,3 +176,113 @@ func TestPubKeyComposite_VRFVerify(t *testing.T) { t.Errorf("Output is different from the VRF key.") } } + +func TestEnvironmentalCompatibility(t *testing.T) { + var cdc = amino.NewCodec() + cdc.RegisterInterface((*crypto.PrivKey)(nil), nil) + cdc.RegisterInterface((*crypto.PubKey)(nil), nil) + cdc.RegisterConcrete(bls.PubKeyBLS12{}, bls.PubKeyAminoName, nil) + cdc.RegisterConcrete(bls.PrivKeyBLS12{}, bls.PrivKeyAminoName, nil) + cdc.RegisterConcrete(ed25519.PubKeyEd25519{}, ed25519.PubKeyAminoName, nil) + cdc.RegisterConcrete(ed25519.PrivKeyEd25519{}, ed25519.PrivKeyAminoName, nil) + cdc.RegisterConcrete(composite.PubKeyComposite{}, composite.PubKeyCompositeAminoName, nil) + cdc.RegisterConcrete(composite.PrivKeyComposite{}, composite.PrivKeyCompositeAminoName, nil) + + t.Run("MarshalCompositeKey", func(t *testing.T) { + privKey := composite.GenPrivKey() + privKeyBytes, err := cdc.MarshalBinaryBare(privKey) + if err != nil { + t.Fatal(err) + } + fmt.Printf("PrivKeyComposite: %s\n", hex.EncodeToString(privKeyBytes)) + }) + + t.Run("The same signature is generated from the same key binary for any runtime env", func(t *testing.T) { + privKeyBytes, err := hex.DecodeString("9f3ee8f00a25eaecf03f203761de9e836bed524dd0b2737c56b69f69672c2b3e40" + + "31b74817474c62b204221245a328891040c69e39ac62519a09895babbb84d6a3a8ea4b69a61760e0c0b04052e252c272ef478fb" + + "da7337ad81ed4202d2bb3ad8240e17248aae2dc169b2e12b45b366d09be") + if err != nil { + t.Fatal(err) + } + compositePrivKey := composite.PrivKeyComposite{} + if err := cdc.UnmarshalBinaryBare(privKeyBytes, &compositePrivKey); err != nil { + t.Fatal(err) + } + msg := []byte("hello, world") + actual, err := compositePrivKey.Sign(msg) + if err != nil { + t.Fatal(err) + } + expected, err := hex.DecodeString("b6bf1dbc3a0d67f19a64d8be04bac7b6bb0963698e1711b3955593f23bf325902298a4" + + "9132ce4ebf452302f21af95da307186574106a5cbdc630a43d3269db99e5ecbf99d4798d8dc681dac1d60f6e43868860ae247e9" + + "e66287774df12e79569") + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(expected, actual) { + t.Logf("Expected Signature: %s (%d bytes)", hex.EncodeToString(expected), len(expected)) + t.Logf("Actual Signature: %s (%d bytes)", hex.EncodeToString(actual), len(actual)) + t.Errorf("Signatures generated from the same key and message are different than expected") + } + }) + + // https://github.com/line/tendermint/issues/121 + t.Run("A reproduction test of issue #121", func(t *testing.T) { + + // restore BLS private key from base64 string in priv_validator_key.json + blsPrivKey := bls.PrivKeyBLS12{} + blsPrivKeyBytes, err := base64.StdEncoding.DecodeString("BpqODFajV6NnQhBfT8ERyvwyqPoZS664e1v35sfr76g=") + if err != nil { + t.Fatal(err) + } else if len(blsPrivKeyBytes) != bls.PrivKeyBLS12Size { + t.Fatalf("fixed private key size: %d != %d", bls.PrivKeyBLS12Size, len(blsPrivKeyBytes)) + } + copy(blsPrivKey[:], blsPrivKeyBytes) + + // restore Ed25519 private key from base64 string in priv_validator_key.json + ed25519PrivKey := ed25519.PrivKeyEd25519{} + ed25519PrivKeyBytes, err := base64.StdEncoding.DecodeString("TGb5K4TbD1XdNd0HGEt7I6quhTJ2aSckgPLLBKs8hDUC" + + "4Wh8kfEmnRUeMYtR8V0UfNwQyTYqGupZeyIhJcV1TA==") + if err != nil { + t.Fatal(err) + } else if len(ed25519PrivKeyBytes) != len(ed25519PrivKey) { + t.Fatalf("fixed private key size: %d != %d", len(ed25519PrivKey), len(ed25519PrivKeyBytes)) + } + copy(ed25519PrivKey[:], ed25519PrivKeyBytes) + + // compare addresses to assumed value + compositePrivKey := composite.NewPrivKeyComposite(blsPrivKey, ed25519PrivKey) + compositePubKey := compositePrivKey.PubKey() + address, err := hex.DecodeString("7A68265205CB115AE35A13515C423F1721E87BB4") + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(address, compositePubKey.Address()) { + t.Fatalf("addresses didn't match: %s", hex.EncodeToString(compositePubKey.Address())) + } + + // compare generated signature to assumed value + message, err := hex.DecodeString("44080111010000000000000022300A147A68265205CB115AE35A13515C423F1721E87BB" + + "412180A147A68265205CB115AE35A13515C423F1721E87BB410013205636861696E") + if err != nil { + t.Fatal(err) + } + signature, err := compositePrivKey.Sign(message) + if err != nil { + t.Fatal(err) + } + expectedSig, err := hex.DecodeString("a00a8a8143fff615e3df98e9b4a493b0ffc5cf1cee14c55d4c667c34651392331c4d" + + "5a1bf0a15d018262d61f74a59cc80775217b81363796e50aac7ce7542424a2eb84fbaf787f7a1c00229682ac4bb0a45f67cdf43f" + + "b21b091f25a0a8bd51ae") + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(expectedSig, signature) { + t.Logf("Address: %s", hex.EncodeToString(address)) + t.Logf("Message: %s (%d bytes)", hex.EncodeToString(message), len(message)) + t.Logf("Expected Signature: %s (%d bytes)", hex.EncodeToString(expectedSig), len(expectedSig)) + t.Logf("Actual Signature: %s (%d bytes)", hex.EncodeToString(signature), len(signature)) + t.Errorf("Different signatures are made for the same message with the same private key.") + } + }) +} diff --git a/crypto/ed25519/ed25519.go b/crypto/ed25519/ed25519.go index 8b54d08e0..2d1ac6914 100644 --- a/crypto/ed25519/ed25519.go +++ b/crypto/ed25519/ed25519.go @@ -10,6 +10,7 @@ import ( amino "github.com/tendermint/go-amino" "golang.org/x/crypto/ed25519" + "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/tmhash" ) diff --git a/lite/helpers.go b/lite/helpers.go index f56071ed0..cb4254878 100644 --- a/lite/helpers.go +++ b/lite/helpers.go @@ -104,6 +104,7 @@ func makeVote(header *types.Header, voterSet *types.VoterSet, key crypto.PrivKey Timestamp: tmtime.Now(), Type: types.PrecommitType, BlockID: blockID, + Signature: []byte{}, } // Sign it signBytes := vote.SignBytes(header.ChainID) diff --git a/lite2/helpers_test.go b/lite2/helpers_test.go index 291b417a4..db167f981 100644 --- a/lite2/helpers_test.go +++ b/lite2/helpers_test.go @@ -146,6 +146,7 @@ func makeVote(header *types.Header, voterIdx int, key crypto.PrivKey, blockID ty Timestamp: tmtime.Now(), Type: types.PrecommitType, BlockID: blockID, + Signature: []byte{}, } // Sign it signBytes := vote.SignBytes(header.ChainID) diff --git a/privval/file_test.go b/privval/file_test.go index bb5c1e1a7..954d50b8f 100644 --- a/privval/file_test.go +++ b/privval/file_test.go @@ -341,6 +341,7 @@ func newVote(addr types.Address, idx int, height int64, round int, typ byte, blo Type: types.SignedMsgType(typ), Timestamp: tmtime.Now(), BlockID: blockID, + Signature: []byte{}, } } diff --git a/privval/signer_client_test.go b/privval/signer_client_test.go index 74c9d43a3..83143b861 100644 --- a/privval/signer_client_test.go +++ b/privval/signer_client_test.go @@ -20,7 +20,7 @@ type signerTestCase struct { signerServer *SignerServer } -func getSignerTestCases(t *testing.T) []signerTestCase { +func getSignerTestCases(t *testing.T, start bool) []signerTestCase { testCases := make([]signerTestCase, 0) // Get test cases for each possible dialer (DialTCP / DialUnix / etc) @@ -35,8 +35,10 @@ func getSignerTestCases(t *testing.T) []signerTestCase { require.NoError(t, err) ss := NewSignerServer(sd, chainID, mockPV) - err = ss.Start() - require.NoError(t, err) + if start { + err = ss.Start() + require.NoError(t, err) + } tc := signerTestCase{ chainID: chainID, @@ -52,7 +54,7 @@ func getSignerTestCases(t *testing.T) []signerTestCase { } func TestSignerClose(t *testing.T) { - for _, tc := range getSignerTestCases(t) { + for _, tc := range getSignerTestCases(t, true) { err := tc.signerClient.Close() assert.NoError(t, err) @@ -62,7 +64,7 @@ func TestSignerClose(t *testing.T) { } func TestSignerPing(t *testing.T) { - for _, tc := range getSignerTestCases(t) { + for _, tc := range getSignerTestCases(t, true) { defer tc.signerServer.Stop() defer tc.signerClient.Close() @@ -72,7 +74,7 @@ func TestSignerPing(t *testing.T) { } func TestSignerGetPubKey(t *testing.T) { - for _, tc := range getSignerTestCases(t) { + for _, tc := range getSignerTestCases(t, true) { defer tc.signerServer.Stop() defer tc.signerClient.Close() @@ -94,7 +96,7 @@ func TestSignerGetPubKey(t *testing.T) { } func TestSignerProposal(t *testing.T) { - for _, tc := range getSignerTestCases(t) { + for _, tc := range getSignerTestCases(t, true) { ts := time.Now() want := &types.Proposal{Timestamp: ts} have := &types.Proposal{Timestamp: ts} @@ -111,7 +113,7 @@ func TestSignerProposal(t *testing.T) { func TestSignerGenerateVRFProof(t *testing.T) { message := []byte("hello, world") - for _, tc := range getSignerTestCases(t) { + for _, tc := range getSignerTestCases(t, true) { defer tc.signerServer.Stop() defer tc.signerClient.Close() @@ -125,10 +127,10 @@ func TestSignerGenerateVRFProof(t *testing.T) { } func TestSignerVote(t *testing.T) { - for _, tc := range getSignerTestCases(t) { + for _, tc := range getSignerTestCases(t, true) { ts := time.Now() - want := &types.Vote{Timestamp: ts, Type: types.PrecommitType} - have := &types.Vote{Timestamp: ts, Type: types.PrecommitType} + want := &types.Vote{Timestamp: ts, Type: types.PrecommitType, Signature: []byte{}} + have := &types.Vote{Timestamp: ts, Type: types.PrecommitType, Signature: []byte{}} defer tc.signerServer.Stop() defer tc.signerClient.Close() @@ -141,10 +143,10 @@ func TestSignerVote(t *testing.T) { } func TestSignerVoteResetDeadline(t *testing.T) { - for _, tc := range getSignerTestCases(t) { + for _, tc := range getSignerTestCases(t, true) { ts := time.Now() - want := &types.Vote{Timestamp: ts, Type: types.PrecommitType} - have := &types.Vote{Timestamp: ts, Type: types.PrecommitType} + want := &types.Vote{Timestamp: ts, Type: types.PrecommitType, Signature: []byte{}} + have := &types.Vote{Timestamp: ts, Type: types.PrecommitType, Signature: []byte{}} defer tc.signerServer.Stop() defer tc.signerClient.Close() @@ -167,10 +169,10 @@ func TestSignerVoteResetDeadline(t *testing.T) { } func TestSignerVoteKeepAlive(t *testing.T) { - for _, tc := range getSignerTestCases(t) { + for _, tc := range getSignerTestCases(t, true) { ts := time.Now() - want := &types.Vote{Timestamp: ts, Type: types.PrecommitType} - have := &types.Vote{Timestamp: ts, Type: types.PrecommitType} + want := &types.Vote{Timestamp: ts, Type: types.PrecommitType, Signature: []byte{}} + have := &types.Vote{Timestamp: ts, Type: types.PrecommitType, Signature: []byte{}} defer tc.signerServer.Stop() defer tc.signerClient.Close() @@ -192,7 +194,7 @@ func TestSignerVoteKeepAlive(t *testing.T) { } func TestSignerSignProposalErrors(t *testing.T) { - for _, tc := range getSignerTestCases(t) { + for _, tc := range getSignerTestCases(t, true) { // Replace service with a mock that always fails tc.signerServer.privVal = types.NewErroringMockPV() tc.mockPV = types.NewErroringMockPV() @@ -214,9 +216,9 @@ func TestSignerSignProposalErrors(t *testing.T) { } func TestSignerSignVoteErrors(t *testing.T) { - for _, tc := range getSignerTestCases(t) { + for _, tc := range getSignerTestCases(t, true) { ts := time.Now() - vote := &types.Vote{Timestamp: ts, Type: types.PrecommitType} + vote := &types.Vote{Timestamp: ts, Type: types.PrecommitType, Signature: []byte{}} // Replace signer service privval with one that always fails tc.signerServer.privVal = types.NewErroringMockPV() @@ -261,14 +263,19 @@ func brokenHandler(privVal types.PrivValidator, request SignerMessage, chainID s } func TestSignerUnexpectedResponse(t *testing.T) { - for _, tc := range getSignerTestCases(t) { + for _, tc := range getSignerTestCases(t, false) { + // this should be executed before SignerServer starts to avoid race condition + tc.signerServer.privVal = types.NewMockPV() + tc.mockPV = types.NewMockPV() + tc.signerServer.SetRequestHandler(brokenHandler) + tc.signerServer.Start() defer tc.signerServer.Stop() defer tc.signerClient.Close() ts := time.Now() - want := &types.Vote{Timestamp: ts, Type: types.PrecommitType} + want := &types.Vote{Timestamp: ts, Type: types.PrecommitType, Signature: []byte{}} e := tc.signerClient.SignVote(tc.chainID, want) assert.EqualError(t, e, "received unexpected response") diff --git a/proto/types/types.pb.go b/proto/types/types.pb.go index cbc58d4ad..9c7a2cba5 100644 --- a/proto/types/types.pb.go +++ b/proto/types/types.pb.go @@ -536,15 +536,18 @@ func (m *Vote) GetSignature() []byte { // Commit contains the evidence that a block was committed by a set of validators. type Commit struct { - Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` - Round int32 `protobuf:"varint,2,opt,name=round,proto3" json:"round,omitempty"` - BlockID BlockID `protobuf:"bytes,3,opt,name=block_id,json=blockId,proto3" json:"block_id"` - Signatures []CommitSig `protobuf:"bytes,4,rep,name=signatures,proto3" json:"signatures"` - Hash []byte `protobuf:"bytes,5,opt,name=hash,proto3" json:"hash,omitempty"` - BitArray *bits.BitArray `protobuf:"bytes,6,opt,name=bit_array,json=bitArray,proto3" json:"bit_array,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Height int64 `protobuf:"varint,1,opt,name=height,proto3" json:"height,omitempty"` + Round int32 `protobuf:"varint,2,opt,name=round,proto3" json:"round,omitempty"` + BlockID BlockID `protobuf:"bytes,3,opt,name=block_id,json=blockId,proto3" json:"block_id"` + Signatures []CommitSig `protobuf:"bytes,4,rep,name=signatures,proto3" json:"signatures"` + Hash []byte `protobuf:"bytes,5,opt,name=hash,proto3" json:"hash,omitempty"` + BitArray *bits.BitArray `protobuf:"bytes,6,opt,name=bit_array,json=bitArray,proto3" json:"bit_array,omitempty"` + // Additional field that LINE Blockchain uses for aggregated signature. For protobuf, the tags in the 1 to 15 is + // packed into a single byte, so we use 15 to account for differential expansions imported from Tendermint. + AggregatedSignature []byte `protobuf:"bytes,15,opt,name=aggregated_signature,json=aggregatedSignature,proto3" json:"aggregated_signature,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` } func (m *Commit) Reset() { *m = Commit{} } @@ -613,6 +616,13 @@ func (m *Commit) GetBitArray() *bits.BitArray { return nil } +func (m *Commit) GetAggregatedSignature() []byte { + if m != nil { + return m.AggregatedSignature + } + return nil +} + // CommitSig is a part of the Vote included in a Commit. type CommitSig struct { BlockIdFlag BlockIDFlag `protobuf:"varint,1,opt,name=block_id_flag,json=blockIdFlag,proto3,enum=tendermint.proto.types.BlockIDFlag" json:"block_id_flag,omitempty"` @@ -889,86 +899,87 @@ func init() { func init() { proto.RegisterFile("proto/types/types.proto", fileDescriptor_ff06f8095857fb18) } var fileDescriptor_ff06f8095857fb18 = []byte{ - // 1286 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0xcd, 0x6e, 0xdb, 0xc6, - 0x13, 0x37, 0x25, 0xca, 0x92, 0x86, 0x92, 0x2d, 0xf3, 0xef, 0x7f, 0xa2, 0xca, 0xad, 0xa5, 0xc8, - 0x4d, 0xea, 0x7c, 0x80, 0x2a, 0x5c, 0xa0, 0x68, 0x80, 0x5e, 0x24, 0xdb, 0x71, 0x84, 0xd8, 0xb2, - 0x40, 0xa9, 0xe9, 0xc7, 0x85, 0x58, 0x89, 0x1b, 0x8a, 0x08, 0x45, 0x12, 0xdc, 0x95, 0x61, 0xa7, - 0x40, 0xcf, 0x85, 0x4f, 0x7d, 0x01, 0x5f, 0x9a, 0x16, 0xe8, 0x5b, 0xb4, 0xc7, 0x9e, 0xfa, 0x08, - 0x29, 0x90, 0xbe, 0x42, 0x1f, 0xa0, 0xd8, 0x0f, 0x52, 0x52, 0x64, 0xb7, 0x41, 0x93, 0x5e, 0x12, - 0xee, 0xcc, 0x6f, 0x66, 0x77, 0x7e, 0xf3, 0x9b, 0x5d, 0x19, 0xae, 0x87, 0x51, 0x40, 0x83, 0x06, - 0x3d, 0x0b, 0x31, 0x11, 0xff, 0x1a, 0xdc, 0xa2, 0x5f, 0xa3, 0xd8, 0xb7, 0x71, 0x34, 0x76, 0x7d, - 0x2a, 0x2c, 0x06, 0xf7, 0x56, 0x6e, 0xd1, 0x91, 0x1b, 0xd9, 0x56, 0x88, 0x22, 0x7a, 0xd6, 0x10, - 0xc1, 0x4e, 0xe0, 0x04, 0xd3, 0x2f, 0x81, 0xae, 0x54, 0x9d, 0x20, 0x70, 0x3c, 0x2c, 0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 0x9e, 0xe3, 0xd2, 0xd1, 0x64, 0x60, 0x0c, 0x83, 0x71, 0x63, 0xda, 0xbd, 0xd9, 0xcf, - 0x99, 0x3f, 0x39, 0x06, 0xcb, 0x7c, 0xf1, 0xd1, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x9f, 0x10, - 0x1c, 0xa4, 0x88, 0x0c, 0x00, 0x00, + // 1307 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0xcb, 0x6e, 0xdb, 0x46, + 0x17, 0x36, 0x25, 0xca, 0x92, 0x0e, 0x25, 0x5b, 0x66, 0xfc, 0x27, 0xfa, 0xe5, 0xd6, 0x52, 0xe4, + 0x26, 0x75, 0x2e, 0xa0, 0x5a, 0x17, 0x28, 0x1a, 0xa0, 0x1b, 0xc9, 0x76, 0x1c, 0x21, 0xb6, 0x2c, + 0x50, 0x6a, 0x7a, 0xd9, 0x10, 0x23, 0x71, 0x42, 0x11, 0xa1, 0x48, 0x82, 0x33, 0x32, 0xec, 0x14, + 0xe8, 0xba, 0xf0, 0xaa, 0x2f, 0xe0, 0x4d, 0x2f, 0x40, 0xdf, 0xa2, 0x5d, 0x76, 0xd5, 0x65, 0x97, + 0x29, 0x90, 0xbe, 0x42, 0x1f, 0xa0, 0x98, 0x0b, 0x29, 0x29, 0xb6, 0x5b, 0xa3, 0x49, 0x37, 0xf6, + 0xcc, 0x39, 0xdf, 0x39, 0x73, 0xe6, 0x9b, 0xef, 0xcc, 0x50, 0x70, 0x23, 0x8c, 0x02, 0x1a, 0x34, + 0xe8, 0x49, 0x88, 0x89, 0xf8, 0x6b, 0x70, 0x8b, 0x7e, 0x9d, 0x62, 0xdf, 0xc6, 0xd1, 0xd8, 0xf5, + 0xa9, 0xb0, 0x18, 0xdc, 0x5b, 0xb9, 0x4d, 0x47, 0x6e, 0x64, 0x5b, 0x21, 0x8a, 0xe8, 0x49, 0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 0x59, 0x83, 0xbc, 0x8d, + 0x28, 0x12, 0x90, 0x2c, 0x87, 0xe4, 0x98, 0x81, 0x3b, 0xab, 0xa0, 0x1d, 0x05, 0x14, 0x47, 0x44, + 0xb8, 0x73, 0xdc, 0x0d, 0xc2, 0xc4, 0x01, 0xef, 0xc2, 0xf2, 0x11, 0xf2, 0x5c, 0x1b, 0xd1, 0x20, + 0x06, 0xe5, 0xc5, 0x32, 0x53, 0x33, 0x07, 0xbe, 0x07, 0xab, 0x3e, 0x3e, 0xa6, 0xd6, 0xab, 0x68, + 0xe0, 0x68, 0x9d, 0xf9, 0x9e, 0xcc, 0x47, 0xdc, 0x82, 0xa5, 0x61, 0x7c, 0x64, 0x02, 0xab, 0x71, + 0x6c, 0x31, 0xb1, 0x72, 0xd8, 0xff, 0x21, 0x87, 0xc2, 0x50, 0x00, 0x0a, 0x1c, 0x90, 0x45, 0x61, + 0xc8, 0x5d, 0x77, 0x61, 0x85, 0x93, 0x10, 0x61, 0x32, 0xf1, 0xa8, 0x4c, 0x52, 0xe4, 0x98, 0x65, + 0xe6, 0x30, 0x85, 0x9d, 0x63, 0x37, 0xa0, 0x88, 0x8f, 0x5c, 0x1b, 0xfb, 0x43, 0x2c, 0x70, 0x4b, + 0x1c, 0x57, 0x88, 0x8d, 0x1c, 0x74, 0x07, 0x4a, 0x61, 0x14, 0x84, 0x01, 0xc1, 0x91, 0x85, 0x6c, + 0x3b, 0xc2, 0x84, 0x94, 0x97, 0x45, 0xbe, 0xd8, 0xde, 0x14, 0xe6, 0xfa, 0x7d, 0x50, 0x77, 0x10, + 0x45, 0x7a, 0x09, 0xd2, 0xf4, 0x98, 0x94, 0x95, 0x5a, 0x7a, 0xb3, 0x60, 0xb2, 0xe1, 0x85, 0xed, + 0xfb, 0x67, 0x0a, 0xd4, 0x27, 0x01, 0xc5, 0xfa, 0x03, 0x50, 0xd9, 0x51, 0x73, 0x35, 0x2f, 0x5d, + 0xde, 0x23, 0x3d, 0xd7, 0xf1, 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xb1, 0x1b, 0x61, 0x21, 0x04, 0x0e, 0xdb, 0x80, 0x62, 0xd7, + 0x3c, 0xec, 0x1e, 0xf6, 0x9a, 0xfb, 0x02, 0x95, 0xae, 0x94, 0x4e, 0xcf, 0x6a, 0x85, 0xb8, 0xc5, + 0x19, 0x68, 0x5a, 0x67, 0xcb, 0xf8, 0xe2, 0xbe, 0xe3, 0xd2, 0xd1, 0x64, 0x60, 0x0c, 0x83, 0x71, + 0x63, 0x7a, 0x7a, 0xb3, 0xc3, 0x99, 0x5f, 0x29, 0x83, 0x45, 0x3e, 0xf9, 0xe0, 0xaf, 0x00, 0x00, + 0x00, 0xff, 0xff, 0x42, 0x13, 0xc4, 0x21, 0xbb, 0x0c, 0x00, 0x00, } diff --git a/proto/types/types.proto b/proto/types/types.proto index e4578e5c6..bf365ccff 100644 --- a/proto/types/types.proto +++ b/proto/types/types.proto @@ -110,6 +110,10 @@ message Commit { repeated CommitSig signatures = 4 [(gogoproto.nullable) = false]; bytes hash = 5; tendermint.proto.libs.bits.BitArray bit_array = 6; + + // Additional field that LINE Blockchain uses for aggregated signature. For protobuf, the tags in the 1 to 15 is + // packed into a single byte, so we use 15 to account for differential expansions imported from Tendermint. + bytes aggregated_signature = 15; } // CommitSig is a part of the Vote included in a Commit. diff --git a/rpc/client/rpc_test.go b/rpc/client/rpc_test.go index 0d67fcd4a..eb75bebae 100644 --- a/rpc/client/rpc_test.go +++ b/rpc/client/rpc_test.go @@ -564,11 +564,16 @@ func deepcpVote(vote *types.Vote) (res *types.Vote) { Hash: make([]byte, len(vote.BlockID.Hash)), PartsHeader: vote.BlockID.PartsHeader, }, - Signature: make([]byte, len(vote.Signature)), + Signature: []byte{}, } copy(res.ValidatorAddress, vote.ValidatorAddress) copy(res.BlockID.Hash, vote.BlockID.Hash) - copy(res.Signature, vote.Signature) + if vote.Signature == nil { + res.Signature = nil + } else if len(vote.Signature) > 0 { + res.Signature = make([]byte, len(vote.Signature)) + copy(res.Signature, vote.Signature) + } return } @@ -606,6 +611,7 @@ func makeEvidences( Hash: tmhash.Sum([]byte("partset")), }, }, + Signature: []byte{}, } var err error diff --git a/state/validation_test.go b/state/validation_test.go index c70abc4c3..7fe12f733 100644 --- a/state/validation_test.go +++ b/state/validation_test.go @@ -188,6 +188,7 @@ func TestValidateBlockCommit(t *testing.T) { Timestamp: tmtime.Now(), Type: types.PrecommitType, BlockID: blockID, + Signature: []byte{}, } err = badPrivVal.SignVote(chainID, goodVote) require.NoError(t, err, "height %d", height) diff --git a/tools/tm-signer-harness/internal/test_harness.go b/tools/tm-signer-harness/internal/test_harness.go index f9d48fdcb..bfef830d4 100644 --- a/tools/tm-signer-harness/internal/test_harness.go +++ b/tools/tm-signer-harness/internal/test_harness.go @@ -273,6 +273,7 @@ func (th *TestHarness) TestSignVote() error { ValidatorIndex: 0, ValidatorAddress: tmhash.SumTruncated([]byte("addr")), Timestamp: time.Now(), + Signature: []byte{}, } voteBytes := vote.SignBytes(th.chainID) // sign the vote diff --git a/types/block.go b/types/block.go index 96274dd10..1b3bb7812 100644 --- a/types/block.go +++ b/types/block.go @@ -10,6 +10,8 @@ import ( "github.com/pkg/errors" "github.com/tendermint/tendermint/crypto" + "github.com/tendermint/tendermint/crypto/bls" + "github.com/tendermint/tendermint/crypto/composite" "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/crypto/tmhash" "github.com/tendermint/tendermint/libs/bits" @@ -551,7 +553,9 @@ type CommitSig struct { BlockIDFlag BlockIDFlag `json:"block_id_flag"` ValidatorAddress Address `json:"validator_address"` Timestamp time.Time `json:"timestamp"` - Signature []byte `json:"signature"` + + // This can take a nil in case when the signature is being aggregated. + Signature []byte `json:"signature"` } // NewCommitSigForBlock returns new CommitSig with BlockIDFlagCommit. @@ -636,10 +640,8 @@ func (cs CommitSig) ValidateBasic() error { ) } // NOTE: Timestamp validation is subtle and handled elsewhere. - if len(cs.Signature) == 0 { - return errors.New("signature is missing") - } - if len(cs.Signature) > MaxSignatureSize { + // NOTE: Signature may be nil if it is aggregated and is handled elsewhere. + if cs.Signature != nil && len(cs.Signature) > MaxSignatureSize { return fmt.Errorf("signature is too big %d (max: %d)", len(cs.Signature), MaxSignatureSize) } } @@ -698,11 +700,18 @@ type Commit struct { // NewCommit returns a new Commit. func NewCommit(height int64, round int, blockID BlockID, commitSigs []CommitSig) *Commit { + return NewCommitWithAggregatedSignature(height, round, blockID, commitSigs, nil) +} + +// NewCommitWithAggregatedSignature returns a new Commit with . +func NewCommitWithAggregatedSignature( + height int64, round int, blockID BlockID, commitSigs []CommitSig, aggrSig []byte) *Commit { return &Commit{ - Height: height, - Round: round, - BlockID: blockID, - Signatures: commitSigs, + Height: height, + Round: round, + BlockID: blockID, + Signatures: commitSigs, + AggregatedSignature: aggrSig, } } @@ -720,6 +729,7 @@ func CommitToVoteSet(chainID string, commit *Commit, voters *VoterSet) *VoteSet panic(fmt.Sprintf("Failed to reconstruct LastCommit: %v", err)) } } + voteSet.aggregatedSignature = commit.AggregatedSignature return voteSet } @@ -819,10 +829,27 @@ func (commit *Commit) ValidateBasic() error { if len(commit.Signatures) == 0 { return errors.New("no signatures in commit") } + omittedSignatures := 0 for i, commitSig := range commit.Signatures { if err := commitSig.ValidateBasic(); err != nil { return fmt.Errorf("wrong CommitSig #%d: %v", i, err) } + if !commitSig.Absent() && commitSig.Signature == nil { + omittedSignatures++ + } + } + switch { + case commit.AggregatedSignature == nil: + if omittedSignatures > 0 { + return fmt.Errorf("%d erased signatures are present, but no aggregate signature exist in commit", + omittedSignatures) + } + case omittedSignatures == 0: + return fmt.Errorf("erased signatures are not present, but aggregated signature exist in commit: %x", + commit.AggregatedSignature) + case len(commit.AggregatedSignature) > MaxSignatureSize: + return fmt.Errorf("signature is too big %d (max: %d)", + len(commit.AggregatedSignature), MaxSignatureSize) } } @@ -835,10 +862,11 @@ func (commit *Commit) Hash() tmbytes.HexBytes { return nil } if commit.hash == nil { - bs := make([][]byte, len(commit.Signatures)) + bs := make([][]byte, len(commit.Signatures)+1) for i, commitSig := range commit.Signatures { bs[i] = cdcEncode(commitSig) } + bs[len(bs)-1] = commit.AggregatedSignature commit.hash = merkle.SimpleHashFromByteSlices(bs) } return commit.hash @@ -857,12 +885,14 @@ func (commit *Commit) StringIndented(indent string) string { %s Height: %d %s Round: %d %s BlockID: %v +%s AggregatedSignature: %X %s Signatures: %s %v %s}#%v`, indent, commit.Height, indent, commit.Round, indent, commit.BlockID, + indent, tmbytes.Fingerprint(commit.AggregatedSignature), indent, indent, strings.Join(commitSigStrings, "\n"+indent+" "), indent, commit.hash) @@ -884,6 +914,7 @@ func (commit *Commit) ToProto() *tmproto.Commit { c.Height = commit.Height c.Round = int32(commit.Round) c.BlockID = commit.BlockID.ToProto() + c.AggregatedSignature = commit.AggregatedSignature if commit.hash != nil { c.Hash = commit.hash } @@ -891,6 +922,39 @@ func (commit *Commit) ToProto() *tmproto.Commit { return c } +// VerifySignatures validates the signatures in this commit. +func (commit *Commit) VerifySignatures(chainID string, vals []*Validator) error { + blsPubKeys := make([]bls.PubKeyBLS12, 0, len(commit.Signatures)) + messages := make([][]byte, 0, len(commit.Signatures)) + for idx, commitSig := range commit.Signatures { + if commitSig.Absent() { + continue // OK, some signatures can be absent. + } + + // Validate signature. + if val := vals[idx]; val != nil { + voteSignBytes := commit.VoteSignBytes(chainID, idx) + if commitSig.Signature != nil { + if !val.PubKey.VerifyBytes(voteSignBytes, commitSig.Signature) { + return fmt.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature) + } + } else { + blsPubKey := GetSignatureKey(val.PubKey) + if blsPubKey == nil { + return fmt.Errorf("signature %d has been omitted, even though it is not a BLS key", idx) + } + blsPubKeys = append(blsPubKeys, *blsPubKey) + messages = append(messages, voteSignBytes) + } + } + } + + if err := bls.VerifyAggregatedSignature(commit.AggregatedSignature, blsPubKeys, messages); err != nil { + return fmt.Errorf("wrong aggregated signature: %X; %s", commit.AggregatedSignature, err) + } + return nil +} + // FromProto sets a protobuf Commit to the given pointer. // It returns an error if the commit is invalid. func CommitFromProto(cp *tmproto.Commit) (*Commit, error) { @@ -921,6 +985,7 @@ func CommitFromProto(cp *tmproto.Commit) (*Commit, error) { commit.Height = cp.Height commit.Round = int(cp.Round) commit.BlockID = *bi + commit.AggregatedSignature = cp.AggregatedSignature commit.hash = cp.Hash commit.bitArray = bitArray @@ -1196,3 +1261,19 @@ func BlockIDFromProto(bID *tmproto.BlockID) (*BlockID, error) { return blockID, blockID.ValidateBasic() } + +// GetSignatureKey is a utility function for referencing a specified public key as a BLS key for signature. +// If the key is not BLS, return nil +func GetSignatureKey(pubKey crypto.PubKey) *bls.PubKeyBLS12 { + for { + if compPubKey, ok := pubKey.(composite.PubKeyComposite); ok { + pubKey = compPubKey.SignKey + } else { + break + } + } + if blsPubKey, ok := pubKey.(bls.PubKeyBLS12); ok { + return &blsPubKey + } + return nil +} diff --git a/types/block_test.go b/types/block_test.go index 58d409bf7..ab62fe981 100644 --- a/types/block_test.go +++ b/types/block_test.go @@ -5,12 +5,17 @@ import ( // number generator here and we can run the tests a bit faster "crypto/rand" "encoding/hex" + "fmt" "math" "os" "reflect" "testing" "time" + "github.com/tendermint/tendermint/crypto/bls" + "github.com/tendermint/tendermint/crypto/composite" + "github.com/tendermint/tendermint/crypto/ed25519" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -211,6 +216,63 @@ func TestNilDataHashDoesntCrash(t *testing.T) { assert.Equal(t, []byte(new(Data).Hash()), nilBytes) } +func TestNewCommit(t *testing.T) { + blockID := BlockID{ + Hash: []byte{}, + PartsHeader: PartSetHeader{ + Total: 0, + Hash: []byte{}, + }, + } + privKeys := [...]crypto.PrivKey{ + bls.GenPrivKey(), + composite.GenPrivKey(), + ed25519.GenPrivKey(), + bls.GenPrivKey(), + } + msgs := make([][]byte, len(privKeys)) + signs := make([][]byte, len(privKeys)) + pubKeys := make([]crypto.PubKey, len(privKeys)) + commitSigs := make([]CommitSig, len(privKeys)) + for i := 0; i < len(privKeys); i++ { + msgs[i] = []byte(fmt.Sprintf("hello, world %d", i)) + signs[i], _ = privKeys[i].Sign(msgs[i]) + pubKeys[i] = privKeys[i].PubKey() + commitSigs[i] = NewCommitSigForBlock(signs[i], pubKeys[i].Address(), time.Now()) + assert.Equal(t, signs[i], commitSigs[i].Signature) + } + commit := NewCommit(0, 1, blockID, commitSigs) + + assert.Equal(t, int64(0), commit.Height) + assert.Equal(t, 1, commit.Round) + assert.Equal(t, blockID, commit.BlockID) + assert.Equal(t, len(commitSigs), len(commit.Signatures)) + assert.Nil(t, commit.AggregatedSignature) + assert.NotNil(t, commit.Signatures[0].Signature) + assert.NotNil(t, commit.Signatures[1].Signature) + assert.NotNil(t, commit.Signatures[2].Signature) + assert.NotNil(t, commit.Signatures[3].Signature) + assert.True(t, pubKeys[2].VerifyBytes(msgs[2], commit.Signatures[2].Signature)) + + blsPubKeys := []bls.PubKeyBLS12{ + *GetSignatureKey(pubKeys[0]), + *GetSignatureKey(pubKeys[1]), + *GetSignatureKey(pubKeys[3]), + } + blsSigMsgs := [][]byte{msgs[0], msgs[1], msgs[3]} + func() { + aggrSig, err := bls.AddSignature(nil, signs[0]) + assert.Nil(t, err) + aggrSig, err = bls.AddSignature(aggrSig, signs[1]) + assert.Nil(t, err) + aggrSig, err = bls.AddSignature(aggrSig, signs[3]) + assert.Nil(t, err) + err = bls.VerifyAggregatedSignature(aggrSig, blsPubKeys, blsSigMsgs) + assert.Nil(t, err) + assert.Nil(t, commit.AggregatedSignature) + }() +} + func TestCommit(t *testing.T) { lastID := makeBlockIDRandom() h := int64(3) @@ -228,7 +290,16 @@ func TestCommit(t *testing.T) { require.NotNil(t, commit.BitArray()) assert.Equal(t, bits.NewBitArray(10).Size(), commit.BitArray().Size()) - assert.Equal(t, voteSet.GetByIndex(0), commit.GetByIndex(0)) + vote1, vote2 := voteSet.GetByIndex(0), commit.GetByIndex(0) + assert.Equal(t, vote1.BlockID, vote2.BlockID) + assert.Equal(t, vote1.Height, vote2.Height) + assert.Equal(t, vote1.Round, vote2.Round) + assert.Equal(t, vote1.Timestamp, vote2.Timestamp) + assert.Equal(t, vote1.Type, vote2.Type) + assert.Equal(t, vote1.ValidatorAddress, vote2.ValidatorAddress) + assert.Equal(t, vote1.ValidatorIndex, vote2.ValidatorIndex) + assert.NotNil(t, vote1.Signature) + assert.Nil(t, vote2.Signature) assert.True(t, commit.IsCommit()) } @@ -253,6 +324,49 @@ func TestCommitValidateBasic(t *testing.T) { } } +func TestCommitHash(t *testing.T) { + t.Run("receiver is nil", func(t *testing.T) { + var commit *Commit = nil + assert.Nil(t, commit.Hash()) + }) + + t.Run("without any signatures", func(t *testing.T) { + commit := &Commit{ + hash: nil, + Signatures: nil, + AggregatedSignature: nil, + } + expected, _ := hex.DecodeString("6E340B9CFFB37A989CA544E6BB780A2C78901D3FB33738768511A30617AFA01D") + assert.Equal(t, expected, commit.Hash().Bytes()) + }) + + t.Run("with out without aggregated signature", func(t *testing.T) { + signature := []byte{0, 0, 0, 0} + address := []byte{0, 0, 0, 0} + tm := time.Unix(0, 0) + commit := &Commit{ + hash: nil, + Signatures: []CommitSig{ + NewCommitSigAbsent(), + NewCommitSigForBlock(signature, address, tm), + }, + AggregatedSignature: nil, + } + expected, _ := hex.DecodeString("82ac742aeeb4266d4e1f659985987c181c494ac17494750cda4dce61e38b0514") + assert.Equal(t, expected, commit.Hash().Bytes()) + + commit.hash = nil + commit.AggregatedSignature = []byte{0, 0, 0, 0} + expected, _ = hex.DecodeString("0b3875dd994c60a8781851e5533886f3000203fa2f9587b5c256666dc5fa89ef") + assert.Equal(t, expected, commit.Hash().Bytes()) + + commit.hash = nil + commit.AggregatedSignature = []byte{0, 1, 2, 3} + expected, _ = hex.DecodeString("f7d7318af02be9015b6440496844d06ec68684251c2378c41a2c2b4e2f5d76cb") + assert.Equal(t, expected, commit.Hash().Bytes()) + }) +} + func TestHeaderHash(t *testing.T) { testCases := []struct { desc string @@ -447,16 +561,17 @@ func TestCommitToVoteSet(t *testing.T) { chainID := voteSet.ChainID() voteSet2 := CommitToVoteSet(chainID, commit, valSet) + assert.Nil(t, voteSet.aggregatedSignature) + assert.NotNil(t, commit.AggregatedSignature) + assert.Equal(t, commit.AggregatedSignature, voteSet2.aggregatedSignature) + for i := 0; i < len(vals); i++ { - vote1 := voteSet.GetByIndex(i) - vote2 := voteSet2.GetByIndex(i) - vote3 := commit.GetVote(i) + vote1 := voteSet2.GetByIndex(i) + vote2 := commit.GetVote(i) vote1bz := cdc.MustMarshalBinaryBare(vote1) vote2bz := cdc.MustMarshalBinaryBare(vote2) - vote3bz := cdc.MustMarshalBinaryBare(vote3) assert.Equal(t, vote1bz, vote2bz) - assert.Equal(t, vote1bz, vote3bz) } } @@ -495,6 +610,7 @@ func TestCommitToVoteSetWithVotesForNilBlock(t *testing.T) { Type: PrecommitType, BlockID: tc.blockIDs[n], Timestamp: tmtime.Now(), + Signature: []byte{}, } added, err := signAddVote(vals[vi], vote, voteSet) diff --git a/types/evidence_test.go b/types/evidence_test.go index 64d7178b1..e1ddfec9a 100644 --- a/types/evidence_test.go +++ b/types/evidence_test.go @@ -30,6 +30,7 @@ func makeVote( Round: round, Type: SignedMsgType(step), BlockID: blockID, + Signature: []byte{}, } err = val.SignVote(chainID, v) if err != nil { diff --git a/types/test_util.go b/types/test_util.go index 377c965a8..115d0575b 100644 --- a/types/test_util.go +++ b/types/test_util.go @@ -23,6 +23,7 @@ func MakeCommit(blockID BlockID, height int64, round int, Type: PrecommitType, BlockID: blockID, Timestamp: now, + Signature: []byte{}, } _, err = signAddVote(validators[i], vote, voteSet) @@ -64,6 +65,7 @@ func MakeVote( Timestamp: now, Type: PrecommitType, BlockID: blockID, + Signature: []byte{}, } if err := privVal.SignVote(chainID, vote); err != nil { return nil, err diff --git a/types/validator_set_test.go b/types/validator_set_test.go index df8a288e1..bdaa3d600 100644 --- a/types/validator_set_test.go +++ b/types/validator_set_test.go @@ -717,8 +717,13 @@ func TestValidatorSet_VerifyCommitLight_ReturnsAsSoonAsMajorityOfVotingPowerSign require.NoError(t, err) commit.Signatures[3] = vote.CommitSig() + // NOTE: Before BLS signature aggregation, in case that three of the four signatures are valid, the Commit itself + // is considered valid even if one of the remaining signatures has been tampered with or replaced, but after + // BLS signature aggregation, the verification fails unless all four signatures are valid, since all four + // signatures are verified at once. err = vset.VerifyCommitLight(chainID, blockID, h, commit) - assert.NoError(t, err) + assert.Error(t, err) + assert.Contains(t, err.Error(), "wrong signature (#3)") } func TestValidatorSet_VerifyCommitLightTrusting_ReturnsAsSoonAsTrustLevelOfVotingPowerSigned(t *testing.T) { @@ -738,8 +743,13 @@ func TestValidatorSet_VerifyCommitLightTrusting_ReturnsAsSoonAsTrustLevelOfVotin require.NoError(t, err) commit.Signatures[2] = vote.CommitSig() + // NOTE: Before BLS signature aggregation, in case that three of the four signatures are valid, the Commit itself + // is considered valid even if one of the remaining signatures has been tampered with or replaced, but after + // BLS signature aggregation, the verification fails unless all four signatures are valid, since all four + // signatures are verified at once. err = vset.VerifyCommitLightTrusting(chainID, blockID, h, commit, tmmath.Fraction{Numerator: 1, Denominator: 3}) - assert.NoError(t, err) + assert.Error(t, err) + assert.Contains(t, err.Error(), "wrong signature (#2)") } func TestEmptySet(t *testing.T) { diff --git a/types/vote.go b/types/vote.go index 0cd9b4151..5f0cf9782 100644 --- a/types/vote.go +++ b/types/vote.go @@ -127,7 +127,7 @@ func (vote *Vote) Verify(chainID string, pubKey crypto.PubKey) error { return ErrVoteInvalidValidatorAddress } - if !pubKey.VerifyBytes(vote.SignBytes(chainID), vote.Signature) { + if vote.Signature != nil && !pubKey.VerifyBytes(vote.SignBytes(chainID), vote.Signature) { return ErrVoteInvalidSignature } return nil @@ -164,10 +164,10 @@ func (vote *Vote) ValidateBasic() error { if vote.ValidatorIndex < 0 { return errors.New("negative ValidatorIndex") } - if len(vote.Signature) == 0 { + if vote.Signature != nil && len(vote.Signature) == 0 { return errors.New("signature is missing") } - if len(vote.Signature) > MaxSignatureSize { + if vote.Signature != nil && len(vote.Signature) > MaxSignatureSize { return fmt.Errorf("signature is too big %d (max: %d)", len(vote.Signature), MaxSignatureSize) } return nil diff --git a/types/vote_set.go b/types/vote_set.go index 5bcb885f5..eb213b894 100644 --- a/types/vote_set.go +++ b/types/vote_set.go @@ -8,6 +8,7 @@ import ( "github.com/pkg/errors" + "github.com/tendermint/tendermint/crypto/bls" "github.com/tendermint/tendermint/libs/bits" ) @@ -64,6 +65,8 @@ type VoteSet struct { maj23 *BlockID // First 2/3 majority seen votesByBlock map[string]*blockVotes // string(blockHash|blockParts) -> blockVotes peerMaj23s map[P2PID]BlockID // Maj23 for each peer + + aggregatedSignature []byte } // Constructs a new VoteSet struct used to accumulate votes for given height/round. @@ -83,6 +86,8 @@ func NewVoteSet(chainID string, height int64, round int, signedMsgType SignedMsg maj23: nil, votesByBlock: make(map[string]*blockVotes, voterSet.Size()), peerMaj23s: make(map[P2PID]BlockID), + + aggregatedSignature: nil, } } @@ -193,6 +198,9 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) { // If we already know of this vote, return false. if existing, ok := voteSet.getVote(valIndex, blockKey); ok { + if existing.Signature == nil { + return false, nil // probably aggregated + } if bytes.Equal(existing.Signature, vote.Signature) { return false, nil // duplicate } @@ -204,6 +212,12 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) { return false, errors.Wrapf(err, "Failed to verify vote with ChainID %s and PubKey %s", voteSet.chainID, voter.PubKey) } + // To make state deterministic, it prohibits to add a new Vote to the VoteSet that is restored from an existing + // Commit. + if voteSet.aggregatedSignature != nil { + return false, errors.Errorf("This VoteSet is already done Commit and no new Vote can be added.") + } + // Add vote and get conflicting vote if any. added, conflicting := voteSet.addVerifiedVote(vote, blockKey, voter.VotingPower) if conflicting != nil { @@ -212,6 +226,7 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) { if !added { panic("Expected to add non-conflicting vote") } + return added, nil } @@ -567,6 +582,7 @@ func (voteSet *VoteSet) MakeCommit() *Commit { } // For every validator, get the precommit + aggregatedSignature := voteSet.aggregatedSignature commitSigs := make([]CommitSig, len(voteSet.votes)) for i, v := range voteSet.votes { commitSig := v.CommitSig() @@ -575,9 +591,26 @@ func (voteSet *VoteSet) MakeCommit() *Commit { commitSig = NewCommitSigAbsent() } commitSigs[i] = commitSig + + if !commitSigs[i].Absent() && len(commitSigs[i].Signature) == bls.SignatureSize { + if aggregatedSignature == nil { + aggregatedSignature = commitSigs[i].Signature + commitSigs[i].Signature = nil + } else { + aggrSig, err := bls.AddSignature(aggregatedSignature, commitSigs[i].Signature) + if err == nil { + aggregatedSignature = aggrSig + commitSigs[i].Signature = nil + } else { + // The BLS signature that fail to aggregate is remained intact. + fmt.Printf("*** ERROR: fail to aggregate signature: %s\n", err) + } + } + } } - return NewCommit(voteSet.GetHeight(), voteSet.GetRound(), *voteSet.maj23, commitSigs) + return NewCommitWithAggregatedSignature( + voteSet.GetHeight(), voteSet.GetRound(), *voteSet.maj23, commitSigs, aggregatedSignature) } //-------------------------------------------------------------------------------- diff --git a/types/vote_set_test.go b/types/vote_set_test.go index 0153f38d1..e509bd03a 100644 --- a/types/vote_set_test.go +++ b/types/vote_set_test.go @@ -2,8 +2,14 @@ package types import ( "bytes" + "fmt" + "sort" "testing" + "github.com/tendermint/tendermint/crypto/bls" + "github.com/tendermint/tendermint/crypto/composite" + "github.com/tendermint/tendermint/crypto/ed25519" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -24,6 +30,31 @@ func randVoteSet( return NewVoteSet("test_chain_id", height, round, signedMsgType, voterSet), valSet, voterSet, privValidators } +func randVoteSetForPrivKeys( + height int64, + round int, + signedMsgType SignedMsgType, + privKeys []crypto.PrivKey, + votingPower int64, +) (*VoteSet, *ValidatorSet, *VoterSet, []PrivValidator) { + valz := make([]*Validator, len(privKeys)) + privValidators := make([]PrivValidator, len(privKeys)) + for i := 0; i < len(privKeys); i++ { + privVal := MockPV{privKeys[i], false, false} + pubKey, err := privVal.GetPubKey() + if err != nil { + panic(fmt.Errorf("could not retrieve pubkey %w", err)) + } + val := NewValidator(pubKey, votingPower) + valz[i] = val + privValidators[i] = privVal + } + vals := NewValidatorSet(valz) + sort.Sort(PrivValidatorsByAddress(privValidators)) + voterSet := SelectVoter(vals, []byte{}, DefaultVoterParams()) + return NewVoteSet("test_chain_id", height, round, signedMsgType, voterSet), vals, voterSet, privValidators +} + // Convenience: Return new vote with different validator address/index func withValidator(vote *Vote, addr []byte, idx int) *Vote { vote = vote.Copy() @@ -97,6 +128,7 @@ func TestAddVote(t *testing.T) { Type: PrevoteType, Timestamp: tmtime.Now(), BlockID: BlockID{nil, PartSetHeader{}}, + Signature: []byte{}, } _, err = signAddVote(val0, vote, voteSet) if err != nil { @@ -127,6 +159,7 @@ func Test2_3Majority(t *testing.T) { Type: PrevoteType, Timestamp: tmtime.Now(), BlockID: BlockID{nil, PartSetHeader{}}, + Signature: []byte{}, } // 6 out of 10 voted for nil. for i := 0; i < 6; i++ { @@ -193,6 +226,7 @@ func Test2_3MajorityRedux(t *testing.T) { Timestamp: tmtime.Now(), Type: PrevoteType, BlockID: BlockID{blockHash, blockPartsHeader}, + Signature: []byte{}, } // 66 out of 100 voted for nil. @@ -306,6 +340,7 @@ func TestBadVotes(t *testing.T) { Timestamp: tmtime.Now(), Type: PrevoteType, BlockID: BlockID{nil, PartSetHeader{}}, + Signature: []byte{}, } // val0 votes for nil. @@ -383,6 +418,7 @@ func TestConflicts(t *testing.T) { Timestamp: tmtime.Now(), Type: PrevoteType, BlockID: BlockID{nil, PartSetHeader{}}, + Signature: []byte{}, } val0, err := privValidators[0].GetPubKey() @@ -525,6 +561,7 @@ func TestMakeCommit(t *testing.T) { Timestamp: tmtime.Now(), Type: PrecommitType, BlockID: BlockID{blockHash, blockPartsHeader}, + Signature: []byte{}, } // 6 out of 10 voted for some block. @@ -594,4 +631,50 @@ func TestMakeCommit(t *testing.T) { if err := commit.ValidateBasic(); err != nil { t.Errorf("error in Commit.ValidateBasic(): %v", err) } + + // Signature aggregation + t.Run("SignatureAggregation", func(t *testing.T) { + privKeys := [...]crypto.PrivKey{ + bls.GenPrivKey(), + composite.GenPrivKey(), + ed25519.GenPrivKey(), + bls.GenPrivKey(), + } + voteSet, _, _, privValidators := randVoteSetForPrivKeys(height, round, PrecommitType, privKeys[:], 1) + for i := range privKeys { + pubKey, err := privValidators[i].GetPubKey() + if err != nil { + t.Fatal(err) + } + addr := pubKey.Address() + vote := withValidator(voteProto, addr, i) + fmt.Printf("*** %v - %v\n", vote.ValidatorAddress, addr) + if _, err := signAddVote(privValidators[i], vote, voteSet); err != nil { + t.Error(err) + } + } + + commit := voteSet.MakeCommit() + + assert.Equal(t, height, commit.Height) + assert.Equal(t, round, commit.Round) + assert.NotNil(t, commit.AggregatedSignature) + // The order of commit.Signatures is sorted by address. + for i := range commit.Signatures { + idx := 0 + for { + if bytes.Equal(privKeys[idx].PubKey().Address(), commit.Signatures[i].ValidatorAddress) { + break + } + idx++ + } + if _, ok := privKeys[idx].(ed25519.PrivKeyEd25519); ok { + assert.NotNil(t, commit.Signatures[i].Signature) + } else if _, ok := privKeys[idx].(bls.PrivKeyBLS12); ok { + assert.Nil(t, commit.Signatures[i].Signature) + } else if _, ok := privKeys[idx].(composite.PrivKeyComposite); ok { + assert.Nil(t, commit.Signatures[i].Signature) + } + } + }) } diff --git a/types/vote_test.go b/types/vote_test.go index c3bd7a16f..c8a30df9e 100644 --- a/types/vote_test.go +++ b/types/vote_test.go @@ -41,6 +41,7 @@ func exampleVote(t byte) *Vote { }, ValidatorAddress: crypto.AddressHash([]byte("validator_address")), ValidatorIndex: 56789, + Signature: []byte{}, } } @@ -62,13 +63,13 @@ func TestVoteSignBytesTestVectors(t *testing.T) { want []byte }{ 0: { - "", &Vote{}, + "", &Vote{Signature: []byte{}}, // NOTE: Height and Round are skipped here. This case needs to be considered while parsing. []byte{0xd, 0x2a, 0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1}, }, // with proper (fixed size) height and round (PreCommit): 1: { - "", &Vote{Height: 1, Round: 1, Type: PrecommitType}, + "", &Vote{Height: 1, Round: 1, Type: PrecommitType, Signature: []byte{}}, []byte{ 0x21, // length 0x8, // (field_number << 3) | wire_type @@ -83,7 +84,7 @@ func TestVoteSignBytesTestVectors(t *testing.T) { }, // with proper (fixed size) height and round (PreVote): 2: { - "", &Vote{Height: 1, Round: 1, Type: PrevoteType}, + "", &Vote{Height: 1, Round: 1, Type: PrevoteType, Signature: []byte{}}, []byte{ 0x21, // length 0x8, // (field_number << 3) | wire_type @@ -97,7 +98,7 @@ func TestVoteSignBytesTestVectors(t *testing.T) { 0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1}, }, 3: { - "", &Vote{Height: 1, Round: 1}, + "", &Vote{Height: 1, Round: 1, Signature: []byte{}}, []byte{ 0x1f, // length 0x11, // (field_number << 3) | wire_type @@ -110,7 +111,7 @@ func TestVoteSignBytesTestVectors(t *testing.T) { }, // containing non-empty chain_id: 4: { - "test_chain_id", &Vote{Height: 1, Round: 1}, + "test_chain_id", &Vote{Height: 1, Round: 1, Signature: []byte{}}, []byte{ 0x2e, // length 0x11, // (field_number << 3) | wire_type @@ -132,8 +133,8 @@ func TestVoteSignBytesTestVectors(t *testing.T) { } func TestVoteProposalNotEq(t *testing.T) { - cv := CanonicalizeVote("", &Vote{Height: 1, Round: 1}) - p := CanonicalizeProposal("", &Proposal{Height: 1, Round: 1}) + cv := CanonicalizeVote("", &Vote{Height: 1, Round: 1, Signature: []byte{}}) + p := CanonicalizeProposal("", &Proposal{Height: 1, Round: 1, Signature: []byte{}}) vb, err := cdc.MarshalBinaryLengthPrefixed(cv) require.NoError(t, err) pb, err := cdc.MarshalBinaryLengthPrefixed(p) @@ -199,6 +200,7 @@ func TestVoteVerify(t *testing.T) { vote := examplePrevote() vote.ValidatorAddress = pubkey.Address() + vote.Signature = []byte{} err = vote.Verify("test_chain_id", ed25519.GenPrivKey().PubKey()) if assert.Error(t, err) { @@ -230,6 +232,7 @@ func TestMaxVoteBytes(t *testing.T) { Hash: tmhash.Sum([]byte("blockID_part_set_header_hash")), }, }, + Signature: []byte{}, } privVal := NewMockPV() @@ -272,7 +275,7 @@ func TestVoteValidateBasic(t *testing.T) { }, true}, {"Invalid Address", func(v *Vote) { v.ValidatorAddress = make([]byte, 1) }, true}, {"Invalid ValidatorIndex", func(v *Vote) { v.ValidatorIndex = -1 }, true}, - {"Invalid Signature", func(v *Vote) { v.Signature = nil }, true}, + {"Invalid Signature", func(v *Vote) { v.Signature = []byte{} }, true}, {"Too big Signature", func(v *Vote) { v.Signature = make([]byte, MaxSignatureSize+1) }, true}, } for _, tc := range testCases { @@ -299,7 +302,7 @@ func TestVoteProtobuf(t *testing.T) { expPass bool }{ {"success", vote, true}, - {"fail vote validate basic", &Vote{}, false}, + {"fail vote validate basic", &Vote{Signature: []byte{}}, false}, {"failure nil", nil, false}, } for _, tc := range testCases { diff --git a/types/voter_set.go b/types/voter_set.go index da8f7d1fc..fa4d85659 100644 --- a/types/voter_set.go +++ b/types/voter_set.go @@ -155,11 +155,6 @@ func (voters *VoterSet) VerifyCommit(chainID string, blockID BlockID, // This means we don't need the validator address or to do any lookup. val := voters.Voters[idx] - // Validate signature. - voteSignBytes := commit.VoteSignBytes(chainID, idx) - if !val.PubKey.VerifyBytes(voteSignBytes, commitSig.Signature) { - return fmt.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature) - } // Good! if blockID.Equals(commitSig.BlockID(commit.BlockID)) { talliedVotingPower += val.VotingPower @@ -170,6 +165,11 @@ func (voters *VoterSet) VerifyCommit(chainID string, blockID BlockID, // } } + // Validate signature. + if err := commit.VerifySignatures(chainID, voters.Voters); err != nil { + return err + } + if got, needed := talliedVotingPower, votingPowerNeeded; got <= needed { return ErrNotEnoughVotingPowerSigned{Got: got, Needed: needed} } @@ -213,16 +213,14 @@ func (voters *VoterSet) VerifyCommitLight(chainID string, blockID BlockID, // This means we don't need the validator address or to do any lookup. val := voters.Voters[idx] - // Validate signature. - voteSignBytes := commit.VoteSignBytes(chainID, idx) - if !val.PubKey.VerifyBytes(voteSignBytes, commitSig.Signature) { - return fmt.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature) - } - talliedVotingPower += val.VotingPower // return as soon as +2/3 of the signatures are verified if talliedVotingPower > votingPowerNeeded { + // Validate signature. + if err := commit.VerifySignatures(chainID, voters.Voters); err != nil { + return err + } return nil } } @@ -273,23 +271,20 @@ func (voters *VoterSet) VerifyFutureCommit(newSet *VoterSet, chainID string, oldVotingPower := int64(0) seen := map[int]bool{} - for idx, commitSig := range commit.Signatures { + vals := make([]*Validator, 0, len(commit.Signatures)) + for _, commitSig := range commit.Signatures { if commitSig.Absent() { continue // OK, some signatures can be absent. } // See if this validator is in oldVals. oldIdx, val := oldVoters.GetByAddress(commitSig.ValidatorAddress) + vals = append(vals, val) if val == nil || seen[oldIdx] { continue // missing or double vote... } seen[oldIdx] = true - // Validate signature. - voteSignBytes := commit.VoteSignBytes(chainID, idx) - if !val.PubKey.VerifyBytes(voteSignBytes, commitSig.Signature) { - return errors.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature) - } // Good! if blockID.Equals(commitSig.BlockID(commit.BlockID)) { oldVotingPower += val.VotingPower @@ -300,6 +295,11 @@ func (voters *VoterSet) VerifyFutureCommit(newSet *VoterSet, chainID string, // } } + // Validate signature. + if err := commit.VerifySignatures(chainID, vals); err != nil { + return err + } + if got, needed := oldVotingPower, oldVoters.TotalVotingPower()*2/3; got <= needed { return ErrNotEnoughVotingPowerSigned{Got: got, Needed: needed} } @@ -333,6 +333,7 @@ func (voters *VoterSet) VerifyCommitTrusting(chainID string, blockID BlockID, } votingPowerNeeded := totalVotingPowerMulByNumerator / trustLevel.Denominator + vals := make([]*Validator, 0, len(commit.Signatures)) for idx, commitSig := range commit.Signatures { if commitSig.Absent() { continue // OK, some signatures can be absent. @@ -341,6 +342,7 @@ func (voters *VoterSet) VerifyCommitTrusting(chainID string, blockID BlockID, // We don't know the validators that committed this block, so we have to // check for each vote if its validator is already known. valIdx, val := voters.GetByAddress(commitSig.ValidatorAddress) + vals = append(vals, val) if firstIndex, ok := seenVals[valIdx]; ok { // double vote secondIndex := idx @@ -350,12 +352,6 @@ func (voters *VoterSet) VerifyCommitTrusting(chainID string, blockID BlockID, if val != nil { seenVals[valIdx] = idx - // Validate signature. - voteSignBytes := commit.VoteSignBytes(chainID, idx) - if !val.PubKey.VerifyBytes(voteSignBytes, commitSig.Signature) { - return errors.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature) - } - // Good! if blockID.Equals(commitSig.BlockID(commit.BlockID)) { talliedVotingPower += val.VotingPower @@ -371,6 +367,11 @@ func (voters *VoterSet) VerifyCommitTrusting(chainID string, blockID BlockID, } } + // Validate signature. + if err := commit.VerifySignatures(chainID, vals); err != nil { + return err + } + return ErrNotEnoughVotingPowerSigned{Got: talliedVotingPower, Needed: votingPowerNeeded} } @@ -427,15 +428,18 @@ func (voters *VoterSet) VerifyCommitLightTrusting(chainID string, blockID BlockI } seenVals[valIdx] = idx - // Validate signature. - voteSignBytes := commit.VoteSignBytes(chainID, idx) - if !val.PubKey.VerifyBytes(voteSignBytes, commitSig.Signature) { - return errors.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature) - } - talliedVotingPower += val.VotingPower if talliedVotingPower > votingPowerNeeded { + // Validate signature. + vals := make([]*Validator, 0, len(commit.Signatures)) + for _, cs := range commit.Signatures { + _, val := voters.GetByAddress(cs.ValidatorAddress) + vals = append(vals, val) + } + if err := commit.VerifySignatures(chainID, vals); err != nil { + return err + } return nil } } diff --git a/types/voter_set_test.go b/types/voter_set_test.go index d46d76857..71bcaca4d 100644 --- a/types/voter_set_test.go +++ b/types/voter_set_test.go @@ -4,15 +4,13 @@ import ( "bytes" "math" "math/big" + s "sort" "strconv" "strings" "testing" "time" - s "sort" - "github.com/tendermint/tendermint/crypto" - "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/libs/rand" tmtime "github.com/tendermint/tendermint/types/time" From 5db1c15a7c431b751dd32d793d1c8fa46df56336 Mon Sep 17 00:00:00 2001 From: TAKAMI Torao Date: Thu, 3 Sep 2020 17:52:12 +0900 Subject: [PATCH 2/4] fixed to restore aggregate signature when restoring Commit to VoteSet --- blockchain/v1/reactor_test.go | 1 - consensus/common_test.go | 1 - consensus/invalid_test.go | 1 - consensus/reactor.go | 6 ++- consensus/state.go | 2 +- consensus/types/height_vote_set_test.go | 1 - lite/helpers.go | 1 - lite2/helpers_test.go | 1 - privval/file_test.go | 1 - privval/signer_client_test.go | 16 ++++---- rpc/client/rpc_test.go | 9 +---- state/validation_test.go | 1 - .../internal/test_harness.go | 1 - types/block.go | 40 +++++++++++++------ types/block_test.go | 17 +------- types/evidence_test.go | 1 - types/test_util.go | 2 - types/vote_set.go | 32 +-------------- types/vote_set_test.go | 7 +--- types/vote_test.go | 18 ++++----- types/voter_set.go | 3 +- types/voter_set_test.go | 7 ++-- 22 files changed, 59 insertions(+), 110 deletions(-) diff --git a/blockchain/v1/reactor_test.go b/blockchain/v1/reactor_test.go index 38325eff0..6b7837f9d 100644 --- a/blockchain/v1/reactor_test.go +++ b/blockchain/v1/reactor_test.go @@ -67,7 +67,6 @@ func makeVote( Timestamp: tmtime.Now(), Type: types.PrecommitType, BlockID: blockID, - Signature: []byte{}, } _ = privVal.SignVote(header.ChainID, vote) diff --git a/consensus/common_test.go b/consensus/common_test.go index 6a61cc764..c6080245c 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -101,7 +101,6 @@ func (vs *validatorStub) signVote( Timestamp: tmtime.Now(), Type: voteType, BlockID: types.BlockID{Hash: hash, PartsHeader: header}, - Signature: []byte{}, } err = vs.PrivValidator.SignVote(config.ChainID(), vote) diff --git a/consensus/invalid_test.go b/consensus/invalid_test.go index 64a4774f7..7bfe710db 100644 --- a/consensus/invalid_test.go +++ b/consensus/invalid_test.go @@ -80,7 +80,6 @@ func invalidDoPrevoteFunc(t *testing.T, height int64, round int, cs *State, sw * BlockID: types.BlockID{ Hash: blockHash, PartsHeader: types.PartSetHeader{Total: 1, Hash: tmrand.Bytes(32)}}, - Signature: []byte{}, } if err = cs.privValidator.SignVote(cs.state.ChainID, precommit); err != nil { panic(err) diff --git a/consensus/reactor.go b/consensus/reactor.go index 9a6131427..05e7025e2 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -652,9 +652,11 @@ OUTER_LOOP: // Catchup logic // If peer is lagging by more than 1, send Commit. if prs.Height != 0 && rs.Height >= prs.Height+2 { - // Load the block commit for prs.Height, + // Load the seen commit for prs.Height, // which contains precommit signatures for prs.Height. - commit := conR.conS.blockStore.LoadBlockCommit(prs.Height) + // Originally the block commit was used, but with the addition of the BLS signature-aggregation, + // we use seen commit instead of the block commit because block commit has no no individual signature. + commit := conR.conS.blockStore.LoadSeenCommit(prs.Height) if ps.PickSendVote(commit) { logger.Debug("Picked Catchup commit to send", "height", prs.Height) continue OUTER_LOOP diff --git a/consensus/state.go b/consensus/state.go index 54abe79a8..23103c6b2 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -1087,6 +1087,7 @@ func (cs *State) createProposalBlock(round int) (block *types.Block, blockParts case cs.LastCommit.HasTwoThirdsMajority(): // Make the commit from LastCommit commit = cs.LastCommit.MakeCommit() + commit.AggregateSignatures() default: // This shouldn't happen. cs.Logger.Error("enterPropose: Cannot propose anything: No commit for the previous block") return @@ -2047,7 +2048,6 @@ func (cs *State) signVote( Timestamp: cs.voteTime(), Type: msgType, BlockID: types.BlockID{Hash: hash, PartsHeader: header}, - Signature: []byte{}, } err = cs.privValidator.SignVote(cs.state.ChainID, vote) diff --git a/consensus/types/height_vote_set_test.go b/consensus/types/height_vote_set_test.go index 3953d0bf4..373e28cca 100644 --- a/consensus/types/height_vote_set_test.go +++ b/consensus/types/height_vote_set_test.go @@ -67,7 +67,6 @@ func makeVoteHR(t *testing.T, height int64, round int, privVals []types.PrivVali Timestamp: tmtime.Now(), Type: types.PrecommitType, BlockID: types.BlockID{Hash: []byte("fakehash"), PartsHeader: types.PartSetHeader{}}, - Signature: []byte{}, } chainID := config.ChainID() err = privVal.SignVote(chainID, vote) diff --git a/lite/helpers.go b/lite/helpers.go index cb4254878..f56071ed0 100644 --- a/lite/helpers.go +++ b/lite/helpers.go @@ -104,7 +104,6 @@ func makeVote(header *types.Header, voterSet *types.VoterSet, key crypto.PrivKey Timestamp: tmtime.Now(), Type: types.PrecommitType, BlockID: blockID, - Signature: []byte{}, } // Sign it signBytes := vote.SignBytes(header.ChainID) diff --git a/lite2/helpers_test.go b/lite2/helpers_test.go index db167f981..291b417a4 100644 --- a/lite2/helpers_test.go +++ b/lite2/helpers_test.go @@ -146,7 +146,6 @@ func makeVote(header *types.Header, voterIdx int, key crypto.PrivKey, blockID ty Timestamp: tmtime.Now(), Type: types.PrecommitType, BlockID: blockID, - Signature: []byte{}, } // Sign it signBytes := vote.SignBytes(header.ChainID) diff --git a/privval/file_test.go b/privval/file_test.go index 954d50b8f..bb5c1e1a7 100644 --- a/privval/file_test.go +++ b/privval/file_test.go @@ -341,7 +341,6 @@ func newVote(addr types.Address, idx int, height int64, round int, typ byte, blo Type: types.SignedMsgType(typ), Timestamp: tmtime.Now(), BlockID: blockID, - Signature: []byte{}, } } diff --git a/privval/signer_client_test.go b/privval/signer_client_test.go index 83143b861..b8db3e681 100644 --- a/privval/signer_client_test.go +++ b/privval/signer_client_test.go @@ -129,8 +129,8 @@ func TestSignerGenerateVRFProof(t *testing.T) { func TestSignerVote(t *testing.T) { for _, tc := range getSignerTestCases(t, true) { ts := time.Now() - want := &types.Vote{Timestamp: ts, Type: types.PrecommitType, Signature: []byte{}} - have := &types.Vote{Timestamp: ts, Type: types.PrecommitType, Signature: []byte{}} + want := &types.Vote{Timestamp: ts, Type: types.PrecommitType} + have := &types.Vote{Timestamp: ts, Type: types.PrecommitType} defer tc.signerServer.Stop() defer tc.signerClient.Close() @@ -145,8 +145,8 @@ func TestSignerVote(t *testing.T) { func TestSignerVoteResetDeadline(t *testing.T) { for _, tc := range getSignerTestCases(t, true) { ts := time.Now() - want := &types.Vote{Timestamp: ts, Type: types.PrecommitType, Signature: []byte{}} - have := &types.Vote{Timestamp: ts, Type: types.PrecommitType, Signature: []byte{}} + want := &types.Vote{Timestamp: ts, Type: types.PrecommitType} + have := &types.Vote{Timestamp: ts, Type: types.PrecommitType} defer tc.signerServer.Stop() defer tc.signerClient.Close() @@ -171,8 +171,8 @@ func TestSignerVoteResetDeadline(t *testing.T) { func TestSignerVoteKeepAlive(t *testing.T) { for _, tc := range getSignerTestCases(t, true) { ts := time.Now() - want := &types.Vote{Timestamp: ts, Type: types.PrecommitType, Signature: []byte{}} - have := &types.Vote{Timestamp: ts, Type: types.PrecommitType, Signature: []byte{}} + want := &types.Vote{Timestamp: ts, Type: types.PrecommitType} + have := &types.Vote{Timestamp: ts, Type: types.PrecommitType} defer tc.signerServer.Stop() defer tc.signerClient.Close() @@ -218,7 +218,7 @@ func TestSignerSignProposalErrors(t *testing.T) { func TestSignerSignVoteErrors(t *testing.T) { for _, tc := range getSignerTestCases(t, true) { ts := time.Now() - vote := &types.Vote{Timestamp: ts, Type: types.PrecommitType, Signature: []byte{}} + vote := &types.Vote{Timestamp: ts, Type: types.PrecommitType} // Replace signer service privval with one that always fails tc.signerServer.privVal = types.NewErroringMockPV() @@ -275,7 +275,7 @@ func TestSignerUnexpectedResponse(t *testing.T) { defer tc.signerClient.Close() ts := time.Now() - want := &types.Vote{Timestamp: ts, Type: types.PrecommitType, Signature: []byte{}} + want := &types.Vote{Timestamp: ts, Type: types.PrecommitType} e := tc.signerClient.SignVote(tc.chainID, want) assert.EqualError(t, e, "received unexpected response") diff --git a/rpc/client/rpc_test.go b/rpc/client/rpc_test.go index eb75bebae..ecf2a5ca9 100644 --- a/rpc/client/rpc_test.go +++ b/rpc/client/rpc_test.go @@ -564,16 +564,10 @@ func deepcpVote(vote *types.Vote) (res *types.Vote) { Hash: make([]byte, len(vote.BlockID.Hash)), PartsHeader: vote.BlockID.PartsHeader, }, - Signature: []byte{}, } copy(res.ValidatorAddress, vote.ValidatorAddress) copy(res.BlockID.Hash, vote.BlockID.Hash) - if vote.Signature == nil { - res.Signature = nil - } else if len(vote.Signature) > 0 { - res.Signature = make([]byte, len(vote.Signature)) - copy(res.Signature, vote.Signature) - } + copy(res.Signature, vote.Signature) return } @@ -611,7 +605,6 @@ func makeEvidences( Hash: tmhash.Sum([]byte("partset")), }, }, - Signature: []byte{}, } var err error diff --git a/state/validation_test.go b/state/validation_test.go index 7fe12f733..c70abc4c3 100644 --- a/state/validation_test.go +++ b/state/validation_test.go @@ -188,7 +188,6 @@ func TestValidateBlockCommit(t *testing.T) { Timestamp: tmtime.Now(), Type: types.PrecommitType, BlockID: blockID, - Signature: []byte{}, } err = badPrivVal.SignVote(chainID, goodVote) require.NoError(t, err, "height %d", height) diff --git a/tools/tm-signer-harness/internal/test_harness.go b/tools/tm-signer-harness/internal/test_harness.go index bfef830d4..f9d48fdcb 100644 --- a/tools/tm-signer-harness/internal/test_harness.go +++ b/tools/tm-signer-harness/internal/test_harness.go @@ -273,7 +273,6 @@ func (th *TestHarness) TestSignVote() error { ValidatorIndex: 0, ValidatorAddress: tmhash.SumTruncated([]byte("addr")), Timestamp: time.Now(), - Signature: []byte{}, } voteBytes := vote.SignBytes(th.chainID) // sign the vote diff --git a/types/block.go b/types/block.go index 1b3bb7812..4d49c3cfa 100644 --- a/types/block.go +++ b/types/block.go @@ -700,18 +700,11 @@ type Commit struct { // NewCommit returns a new Commit. func NewCommit(height int64, round int, blockID BlockID, commitSigs []CommitSig) *Commit { - return NewCommitWithAggregatedSignature(height, round, blockID, commitSigs, nil) -} - -// NewCommitWithAggregatedSignature returns a new Commit with . -func NewCommitWithAggregatedSignature( - height int64, round int, blockID BlockID, commitSigs []CommitSig, aggrSig []byte) *Commit { return &Commit{ - Height: height, - Round: round, - BlockID: blockID, - Signatures: commitSigs, - AggregatedSignature: aggrSig, + Height: height, + Round: round, + BlockID: blockID, + Signatures: commitSigs, } } @@ -719,6 +712,9 @@ func NewCommitWithAggregatedSignature( // Panics if signatures from the commit can't be added to the voteset. // Inverse of VoteSet.MakeCommit(). func CommitToVoteSet(chainID string, commit *Commit, voters *VoterSet) *VoteSet { + if commit.AggregatedSignature != nil { + panic("Aggregated commit cannot make a VoteSet") + } voteSet := NewVoteSet(chainID, commit.Height, commit.Round, PrecommitType, voters) for idx, commitSig := range commit.Signatures { if commitSig.Absent() { @@ -729,10 +725,30 @@ func CommitToVoteSet(chainID string, commit *Commit, voters *VoterSet) *VoteSet panic(fmt.Sprintf("Failed to reconstruct LastCommit: %v", err)) } } - voteSet.aggregatedSignature = commit.AggregatedSignature return voteSet } +func (commit *Commit) AggregateSignatures() { + if commit.AggregatedSignature != nil { + panic("The commit is already aggregated") + } + var err error + for i := 0; i < len(commit.Signatures); i++ { + if !commit.Signatures[i].Absent() && len(commit.Signatures[i].Signature) == bls.SignatureSize { + if commit.AggregatedSignature == nil { + commit.AggregatedSignature = commit.Signatures[i].Signature + } else { + commit.AggregatedSignature, err = bls.AddSignature(commit.AggregatedSignature, + commit.Signatures[i].Signature) + if err != nil { + panic(fmt.Sprintf("fail to aggregate signature: %s\n", err)) + } + } + commit.Signatures[i].Signature = nil + } + } +} + // GetVote converts the CommitSig for the given valIdx to a Vote. // Returns nil if the precommit at valIdx is nil. // Panics if valIdx >= commit.Size(). diff --git a/types/block_test.go b/types/block_test.go index ab62fe981..cd5ea6557 100644 --- a/types/block_test.go +++ b/types/block_test.go @@ -290,17 +290,7 @@ func TestCommit(t *testing.T) { require.NotNil(t, commit.BitArray()) assert.Equal(t, bits.NewBitArray(10).Size(), commit.BitArray().Size()) - vote1, vote2 := voteSet.GetByIndex(0), commit.GetByIndex(0) - assert.Equal(t, vote1.BlockID, vote2.BlockID) - assert.Equal(t, vote1.Height, vote2.Height) - assert.Equal(t, vote1.Round, vote2.Round) - assert.Equal(t, vote1.Timestamp, vote2.Timestamp) - assert.Equal(t, vote1.Type, vote2.Type) - assert.Equal(t, vote1.ValidatorAddress, vote2.ValidatorAddress) - assert.Equal(t, vote1.ValidatorIndex, vote2.ValidatorIndex) - assert.NotNil(t, vote1.Signature) - assert.Nil(t, vote2.Signature) - assert.True(t, commit.IsCommit()) + assert.Equal(t, voteSet.GetByIndex(0), commit.GetByIndex(0)) } func TestCommitValidateBasic(t *testing.T) { @@ -561,10 +551,6 @@ func TestCommitToVoteSet(t *testing.T) { chainID := voteSet.ChainID() voteSet2 := CommitToVoteSet(chainID, commit, valSet) - assert.Nil(t, voteSet.aggregatedSignature) - assert.NotNil(t, commit.AggregatedSignature) - assert.Equal(t, commit.AggregatedSignature, voteSet2.aggregatedSignature) - for i := 0; i < len(vals); i++ { vote1 := voteSet2.GetByIndex(i) vote2 := commit.GetVote(i) @@ -610,7 +596,6 @@ func TestCommitToVoteSetWithVotesForNilBlock(t *testing.T) { Type: PrecommitType, BlockID: tc.blockIDs[n], Timestamp: tmtime.Now(), - Signature: []byte{}, } added, err := signAddVote(vals[vi], vote, voteSet) diff --git a/types/evidence_test.go b/types/evidence_test.go index e1ddfec9a..64d7178b1 100644 --- a/types/evidence_test.go +++ b/types/evidence_test.go @@ -30,7 +30,6 @@ func makeVote( Round: round, Type: SignedMsgType(step), BlockID: blockID, - Signature: []byte{}, } err = val.SignVote(chainID, v) if err != nil { diff --git a/types/test_util.go b/types/test_util.go index 115d0575b..377c965a8 100644 --- a/types/test_util.go +++ b/types/test_util.go @@ -23,7 +23,6 @@ func MakeCommit(blockID BlockID, height int64, round int, Type: PrecommitType, BlockID: blockID, Timestamp: now, - Signature: []byte{}, } _, err = signAddVote(validators[i], vote, voteSet) @@ -65,7 +64,6 @@ func MakeVote( Timestamp: now, Type: PrecommitType, BlockID: blockID, - Signature: []byte{}, } if err := privVal.SignVote(chainID, vote); err != nil { return nil, err diff --git a/types/vote_set.go b/types/vote_set.go index eb213b894..998d5a92f 100644 --- a/types/vote_set.go +++ b/types/vote_set.go @@ -8,7 +8,6 @@ import ( "github.com/pkg/errors" - "github.com/tendermint/tendermint/crypto/bls" "github.com/tendermint/tendermint/libs/bits" ) @@ -65,8 +64,6 @@ type VoteSet struct { maj23 *BlockID // First 2/3 majority seen votesByBlock map[string]*blockVotes // string(blockHash|blockParts) -> blockVotes peerMaj23s map[P2PID]BlockID // Maj23 for each peer - - aggregatedSignature []byte } // Constructs a new VoteSet struct used to accumulate votes for given height/round. @@ -86,8 +83,6 @@ func NewVoteSet(chainID string, height int64, round int, signedMsgType SignedMsg maj23: nil, votesByBlock: make(map[string]*blockVotes, voterSet.Size()), peerMaj23s: make(map[P2PID]BlockID), - - aggregatedSignature: nil, } } @@ -212,12 +207,6 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) { return false, errors.Wrapf(err, "Failed to verify vote with ChainID %s and PubKey %s", voteSet.chainID, voter.PubKey) } - // To make state deterministic, it prohibits to add a new Vote to the VoteSet that is restored from an existing - // Commit. - if voteSet.aggregatedSignature != nil { - return false, errors.Errorf("This VoteSet is already done Commit and no new Vote can be added.") - } - // Add vote and get conflicting vote if any. added, conflicting := voteSet.addVerifiedVote(vote, blockKey, voter.VotingPower) if conflicting != nil { @@ -582,7 +571,6 @@ func (voteSet *VoteSet) MakeCommit() *Commit { } // For every validator, get the precommit - aggregatedSignature := voteSet.aggregatedSignature commitSigs := make([]CommitSig, len(voteSet.votes)) for i, v := range voteSet.votes { commitSig := v.CommitSig() @@ -591,26 +579,10 @@ func (voteSet *VoteSet) MakeCommit() *Commit { commitSig = NewCommitSigAbsent() } commitSigs[i] = commitSig - - if !commitSigs[i].Absent() && len(commitSigs[i].Signature) == bls.SignatureSize { - if aggregatedSignature == nil { - aggregatedSignature = commitSigs[i].Signature - commitSigs[i].Signature = nil - } else { - aggrSig, err := bls.AddSignature(aggregatedSignature, commitSigs[i].Signature) - if err == nil { - aggregatedSignature = aggrSig - commitSigs[i].Signature = nil - } else { - // The BLS signature that fail to aggregate is remained intact. - fmt.Printf("*** ERROR: fail to aggregate signature: %s\n", err) - } - } - } } - return NewCommitWithAggregatedSignature( - voteSet.GetHeight(), voteSet.GetRound(), *voteSet.maj23, commitSigs, aggregatedSignature) + return NewCommit( + voteSet.GetHeight(), voteSet.GetRound(), *voteSet.maj23, commitSigs) } //-------------------------------------------------------------------------------- diff --git a/types/vote_set_test.go b/types/vote_set_test.go index e509bd03a..0f25dcdc3 100644 --- a/types/vote_set_test.go +++ b/types/vote_set_test.go @@ -128,7 +128,6 @@ func TestAddVote(t *testing.T) { Type: PrevoteType, Timestamp: tmtime.Now(), BlockID: BlockID{nil, PartSetHeader{}}, - Signature: []byte{}, } _, err = signAddVote(val0, vote, voteSet) if err != nil { @@ -159,7 +158,6 @@ func Test2_3Majority(t *testing.T) { Type: PrevoteType, Timestamp: tmtime.Now(), BlockID: BlockID{nil, PartSetHeader{}}, - Signature: []byte{}, } // 6 out of 10 voted for nil. for i := 0; i < 6; i++ { @@ -226,7 +224,6 @@ func Test2_3MajorityRedux(t *testing.T) { Timestamp: tmtime.Now(), Type: PrevoteType, BlockID: BlockID{blockHash, blockPartsHeader}, - Signature: []byte{}, } // 66 out of 100 voted for nil. @@ -340,7 +337,6 @@ func TestBadVotes(t *testing.T) { Timestamp: tmtime.Now(), Type: PrevoteType, BlockID: BlockID{nil, PartSetHeader{}}, - Signature: []byte{}, } // val0 votes for nil. @@ -418,7 +414,6 @@ func TestConflicts(t *testing.T) { Timestamp: tmtime.Now(), Type: PrevoteType, BlockID: BlockID{nil, PartSetHeader{}}, - Signature: []byte{}, } val0, err := privValidators[0].GetPubKey() @@ -561,7 +556,6 @@ func TestMakeCommit(t *testing.T) { Timestamp: tmtime.Now(), Type: PrecommitType, BlockID: BlockID{blockHash, blockPartsHeader}, - Signature: []byte{}, } // 6 out of 10 voted for some block. @@ -655,6 +649,7 @@ func TestMakeCommit(t *testing.T) { } commit := voteSet.MakeCommit() + commit.AggregateSignatures() assert.Equal(t, height, commit.Height) assert.Equal(t, round, commit.Round) diff --git a/types/vote_test.go b/types/vote_test.go index c8a30df9e..81bacb379 100644 --- a/types/vote_test.go +++ b/types/vote_test.go @@ -41,7 +41,6 @@ func exampleVote(t byte) *Vote { }, ValidatorAddress: crypto.AddressHash([]byte("validator_address")), ValidatorIndex: 56789, - Signature: []byte{}, } } @@ -63,13 +62,13 @@ func TestVoteSignBytesTestVectors(t *testing.T) { want []byte }{ 0: { - "", &Vote{Signature: []byte{}}, + "", &Vote{}, // NOTE: Height and Round are skipped here. This case needs to be considered while parsing. []byte{0xd, 0x2a, 0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1}, }, // with proper (fixed size) height and round (PreCommit): 1: { - "", &Vote{Height: 1, Round: 1, Type: PrecommitType, Signature: []byte{}}, + "", &Vote{Height: 1, Round: 1, Type: PrecommitType}, []byte{ 0x21, // length 0x8, // (field_number << 3) | wire_type @@ -84,7 +83,7 @@ func TestVoteSignBytesTestVectors(t *testing.T) { }, // with proper (fixed size) height and round (PreVote): 2: { - "", &Vote{Height: 1, Round: 1, Type: PrevoteType, Signature: []byte{}}, + "", &Vote{Height: 1, Round: 1, Type: PrevoteType}, []byte{ 0x21, // length 0x8, // (field_number << 3) | wire_type @@ -98,7 +97,7 @@ func TestVoteSignBytesTestVectors(t *testing.T) { 0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1}, }, 3: { - "", &Vote{Height: 1, Round: 1, Signature: []byte{}}, + "", &Vote{Height: 1, Round: 1}, []byte{ 0x1f, // length 0x11, // (field_number << 3) | wire_type @@ -111,7 +110,7 @@ func TestVoteSignBytesTestVectors(t *testing.T) { }, // containing non-empty chain_id: 4: { - "test_chain_id", &Vote{Height: 1, Round: 1, Signature: []byte{}}, + "test_chain_id", &Vote{Height: 1, Round: 1}, []byte{ 0x2e, // length 0x11, // (field_number << 3) | wire_type @@ -133,8 +132,8 @@ func TestVoteSignBytesTestVectors(t *testing.T) { } func TestVoteProposalNotEq(t *testing.T) { - cv := CanonicalizeVote("", &Vote{Height: 1, Round: 1, Signature: []byte{}}) - p := CanonicalizeProposal("", &Proposal{Height: 1, Round: 1, Signature: []byte{}}) + cv := CanonicalizeVote("", &Vote{Height: 1, Round: 1}) + p := CanonicalizeProposal("", &Proposal{Height: 1, Round: 1}) vb, err := cdc.MarshalBinaryLengthPrefixed(cv) require.NoError(t, err) pb, err := cdc.MarshalBinaryLengthPrefixed(p) @@ -232,7 +231,6 @@ func TestMaxVoteBytes(t *testing.T) { Hash: tmhash.Sum([]byte("blockID_part_set_header_hash")), }, }, - Signature: []byte{}, } privVal := NewMockPV() @@ -302,7 +300,7 @@ func TestVoteProtobuf(t *testing.T) { expPass bool }{ {"success", vote, true}, - {"fail vote validate basic", &Vote{Signature: []byte{}}, false}, + {"fail vote validate basic", &Vote{}, false}, {"failure nil", nil, false}, } for _, tc := range testCases { diff --git a/types/voter_set.go b/types/voter_set.go index fa4d85659..3672e30c8 100644 --- a/types/voter_set.go +++ b/types/voter_set.go @@ -8,14 +8,13 @@ import ( "sort" "strings" - tmproto "github.com/tendermint/tendermint/proto/types" - "github.com/pkg/errors" "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/crypto/tmhash" tmmath "github.com/tendermint/tendermint/libs/math" tmrand "github.com/tendermint/tendermint/libs/rand" + tmproto "github.com/tendermint/tendermint/proto/types" ) // VoterSet represent a set of *Validator at a given height. diff --git a/types/voter_set_test.go b/types/voter_set_test.go index 71bcaca4d..dad9a3698 100644 --- a/types/voter_set_test.go +++ b/types/voter_set_test.go @@ -355,9 +355,10 @@ func TestElectVotersNonDupByzantineTolerable(t *testing.T) { rand.Seed(seed) t.Logf("used seed=%d", seed) validatorSet := newValidatorSet(100, func(i int) int64 { return int64(rand.Uint32()%10000 + 100) }) - tolerableByzantinePercentage := int(rand.Uint() % 33) - tolerableByzantinePower := getTolerableByzantinePower(validatorSet.TotalStakingPower(), - tolerableByzantinePercentage) + // this test has no mean if all validators are elected as voters. + // So limit the maximum to 15% not to elect all validators as voters + tolerableByzantinePercentage := int(rand.Uint() % 15) + tolerableByzantinePower := getTolerableByzantinePower(validatorSet.TotalStakingPower(), tolerableByzantinePercentage) voters := electVotersNonDup(validatorSet.Validators, rand.Uint64(), tolerableByzantinePercentage, int(rand.Uint()%100)) totalVoting := int64(0) for _, v := range voters { From a7be6d3052ce460efb129c0f1663dde399934df9 Mon Sep 17 00:00:00 2001 From: egonspace Date: Wed, 2 Dec 2020 15:48:39 +0900 Subject: [PATCH 3/4] fix: rollback needless modification --- types/block_test.go | 7 +++++-- types/vote.go | 6 +++--- types/vote_set.go | 7 +------ types/vote_test.go | 3 +-- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/types/block_test.go b/types/block_test.go index e43dfb965..adbb72184 100644 --- a/types/block_test.go +++ b/types/block_test.go @@ -808,12 +808,15 @@ func TestCommitToVoteSet(t *testing.T) { voteSet2 := CommitToVoteSet(chainID, commit, valSet) for i := 0; i < len(vals); i++ { - vote1 := voteSet2.GetByIndex(i) - vote2 := commit.GetVote(i) + vote1 := voteSet.GetByIndex(i) + vote2 := voteSet2.GetByIndex(i) + vote3 := commit.GetVote(i) vote1bz := cdc.MustMarshalBinaryBare(vote1) vote2bz := cdc.MustMarshalBinaryBare(vote2) + vote3bz := cdc.MustMarshalBinaryBare(vote3) assert.Equal(t, vote1bz, vote2bz) + assert.Equal(t, vote1bz, vote3bz) } } diff --git a/types/vote.go b/types/vote.go index 5682f9d6a..c016c12b6 100644 --- a/types/vote.go +++ b/types/vote.go @@ -125,7 +125,7 @@ func (vote *Vote) Verify(chainID string, pubKey crypto.PubKey) error { return ErrVoteInvalidValidatorAddress } - if vote.Signature != nil && !pubKey.VerifyBytes(vote.SignBytes(chainID), vote.Signature) { + if !pubKey.VerifyBytes(vote.SignBytes(chainID), vote.Signature) { return ErrVoteInvalidSignature } return nil @@ -162,10 +162,10 @@ func (vote *Vote) ValidateBasic() error { if vote.ValidatorIndex < 0 { return errors.New("negative ValidatorIndex") } - if vote.Signature != nil && len(vote.Signature) == 0 { + if len(vote.Signature) == 0 { return errors.New("signature is missing") } - if vote.Signature != nil && len(vote.Signature) > MaxSignatureSize { + if len(vote.Signature) > MaxSignatureSize { return fmt.Errorf("signature is too big %d (max: %d)", len(vote.Signature), MaxSignatureSize) } return nil diff --git a/types/vote_set.go b/types/vote_set.go index 998d5a92f..5bcb885f5 100644 --- a/types/vote_set.go +++ b/types/vote_set.go @@ -193,9 +193,6 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) { // If we already know of this vote, return false. if existing, ok := voteSet.getVote(valIndex, blockKey); ok { - if existing.Signature == nil { - return false, nil // probably aggregated - } if bytes.Equal(existing.Signature, vote.Signature) { return false, nil // duplicate } @@ -215,7 +212,6 @@ func (voteSet *VoteSet) addVote(vote *Vote) (added bool, err error) { if !added { panic("Expected to add non-conflicting vote") } - return added, nil } @@ -581,8 +577,7 @@ func (voteSet *VoteSet) MakeCommit() *Commit { commitSigs[i] = commitSig } - return NewCommit( - voteSet.GetHeight(), voteSet.GetRound(), *voteSet.maj23, commitSigs) + return NewCommit(voteSet.GetHeight(), voteSet.GetRound(), *voteSet.maj23, commitSigs) } //-------------------------------------------------------------------------------- diff --git a/types/vote_test.go b/types/vote_test.go index a6c24ab29..9a19eb79a 100644 --- a/types/vote_test.go +++ b/types/vote_test.go @@ -202,7 +202,6 @@ func TestVoteVerify(t *testing.T) { vote := examplePrevote() vote.ValidatorAddress = pubkey.Address() - vote.Signature = []byte{} err = vote.Verify("test_chain_id", ed25519.GenPrivKey().PubKey()) if assert.Error(t, err) { @@ -280,7 +279,7 @@ func TestVoteValidateBasic(t *testing.T) { }, true}, {"Invalid Address", func(v *Vote) { v.ValidatorAddress = make([]byte, 1) }, true}, {"Invalid ValidatorIndex", func(v *Vote) { v.ValidatorIndex = -1 }, true}, - {"Invalid Signature", func(v *Vote) { v.Signature = []byte{} }, true}, + {"Invalid Signature", func(v *Vote) { v.Signature = nil }, true}, {"Too big Signature", func(v *Vote) { v.Signature = make([]byte, MaxSignatureSize+1) }, true}, } for _, tc := range testCases { From bcd91a1e43a2421e8eae1a0d7f15cb614a654033 Mon Sep 17 00:00:00 2001 From: TAKAMI Torao Date: Thu, 3 Dec 2020 16:42:52 +0900 Subject: [PATCH 4/4] fixed a trivial typo --- consensus/reactor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consensus/reactor.go b/consensus/reactor.go index 05e7025e2..f6f85f50f 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -655,7 +655,7 @@ OUTER_LOOP: // Load the seen commit for prs.Height, // which contains precommit signatures for prs.Height. // Originally the block commit was used, but with the addition of the BLS signature-aggregation, - // we use seen commit instead of the block commit because block commit has no no individual signature. + // we use seen commit instead of the block commit because block commit has no individual signature. commit := conR.conS.blockStore.LoadSeenCommit(prs.Height) if ps.PickSendVote(commit) { logger.Debug("Picked Catchup commit to send", "height", prs.Height)