From 728d2ed266880958c8493a6208dc3f9c1ec9efd6 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Tue, 14 Aug 2018 16:13:25 -0700 Subject: [PATCH] crypto: Remove unnecessary prefixes from amino route variable names (#2205) * crypto: Remove unnecessary ed25519 and secp256k1 prefixes from amino routes. * (squash this) add changelog * (squash this) multisig amino fixes * (squash this) fix build error --- CHANGELOG_PENDING.md | 1 + consensus/types/round_state_test.go | 2 +- crypto/ed25519/ed25519.go | 14 +++++++------- crypto/multisig/compact_bit_array_test.go | 3 ++- crypto/multisig/wire.go | 6 +++--- crypto/secp256k1/secp256k1.go | 8 ++++---- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 5728e5582..12de00342 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -10,6 +10,7 @@ BREAKING CHANGES: - [abci] Added address of the original proposer of the block to Header. - [abci] Change ABCI Header to match Tendermint exactly - [libs] Remove cmn.Fmt, in favor of fmt.Sprintf +- [crypto] Rename AminoRoute variables to no longer be prefixed by signature type. - [config] Replace MaxNumPeers with MaxNumInboundPeers and MaxNumOutboundPeers FEATURES: diff --git a/consensus/types/round_state_test.go b/consensus/types/round_state_test.go index 0257ea2ff..4d128b180 100644 --- a/consensus/types/round_state_test.go +++ b/consensus/types/round_state_test.go @@ -23,7 +23,7 @@ func BenchmarkRoundStateDeepCopy(b *testing.B) { Hash: cmn.RandBytes(20), }, } - sig := make([]byte, ed25519.SignatureEd25519Size) + sig := make([]byte, ed25519.SignatureSize) for i := 0; i < nval; i++ { precommits[i] = &types.Vote{ ValidatorAddress: types.Address(cmn.RandBytes(20)), diff --git a/crypto/ed25519/ed25519.go b/crypto/ed25519/ed25519.go index fa7526f3f..c55b3588f 100644 --- a/crypto/ed25519/ed25519.go +++ b/crypto/ed25519/ed25519.go @@ -18,11 +18,11 @@ import ( var _ crypto.PrivKey = PrivKeyEd25519{} const ( - Ed25519PrivKeyAminoRoute = "tendermint/PrivKeyEd25519" - Ed25519PubKeyAminoRoute = "tendermint/PubKeyEd25519" + PrivKeyAminoRoute = "tendermint/PrivKeyEd25519" + PubKeyAminoRoute = "tendermint/PubKeyEd25519" // Size of an Edwards25519 signature. Namely the size of a compressed // Edwards25519 point, and a field element. Both of which are 32 bytes. - SignatureEd25519Size = 64 + SignatureSize = 64 ) var cdc = amino.NewCodec() @@ -30,11 +30,11 @@ var cdc = amino.NewCodec() func init() { cdc.RegisterInterface((*crypto.PubKey)(nil), nil) cdc.RegisterConcrete(PubKeyEd25519{}, - Ed25519PubKeyAminoRoute, nil) + PubKeyAminoRoute, nil) cdc.RegisterInterface((*crypto.PrivKey)(nil), nil) cdc.RegisterConcrete(PrivKeyEd25519{}, - Ed25519PrivKeyAminoRoute, nil) + PrivKeyAminoRoute, nil) } // PrivKeyEd25519 implements crypto.PrivKey. @@ -158,10 +158,10 @@ func (pubKey PubKeyEd25519) Bytes() []byte { func (pubKey PubKeyEd25519) VerifyBytes(msg []byte, sig_ []byte) bool { // make sure we use the same algorithm to sign - if len(sig_) != SignatureEd25519Size { + if len(sig_) != SignatureSize { return false } - sig := new([SignatureEd25519Size]byte) + sig := new([SignatureSize]byte) copy(sig[:], sig_) pubKeyBytes := [PubKeyEd25519Size]byte(pubKey) return ed25519.Verify(&pubKeyBytes, msg, sig) diff --git a/crypto/multisig/compact_bit_array_test.go b/crypto/multisig/compact_bit_array_test.go index 8b342b7ad..4684ba23f 100644 --- a/crypto/multisig/compact_bit_array_test.go +++ b/crypto/multisig/compact_bit_array_test.go @@ -30,7 +30,8 @@ func randCompactBitArray(bits int) (*CompactBitArray, []byte) { func TestNewBitArrayNeverCrashesOnNegatives(t *testing.T) { bitList := []int{-127, -128, -1 << 31} for _, bits := range bitList { - _ = NewCompactBitArray(bits) + bA := NewCompactBitArray(bits) + require.Nil(t, bA) } } diff --git a/crypto/multisig/wire.go b/crypto/multisig/wire.go index a6cda34a9..4c48c6649 100644 --- a/crypto/multisig/wire.go +++ b/crypto/multisig/wire.go @@ -10,7 +10,7 @@ import ( // TODO: Figure out API for others to either add their own pubkey types, or // to make verify / marshal accept a cdc. const ( - ThresholdPubkeyAminoRoute = "tendermint/PubkeyThresholdMultisig" + ThresholdPubkeyAminoRoute = "tendermint/PubkeyMultisigThreshold" ) var cdc = amino.NewCodec() @@ -20,7 +20,7 @@ func init() { cdc.RegisterConcrete(ThresholdMultiSignaturePubKey{}, ThresholdPubkeyAminoRoute, nil) cdc.RegisterConcrete(ed25519.PubKeyEd25519{}, - ed25519.Ed25519PubKeyAminoRoute, nil) + ed25519.PubKeyAminoRoute, nil) cdc.RegisterConcrete(secp256k1.PubKeySecp256k1{}, - secp256k1.Secp256k1PubKeyAminoRoute, nil) + secp256k1.PubKeyAminoRoute, nil) } diff --git a/crypto/secp256k1/secp256k1.go b/crypto/secp256k1/secp256k1.go index aee5dafe7..0e9ed8539 100644 --- a/crypto/secp256k1/secp256k1.go +++ b/crypto/secp256k1/secp256k1.go @@ -15,8 +15,8 @@ import ( //------------------------------------- const ( - Secp256k1PrivKeyAminoRoute = "tendermint/PrivKeySecp256k1" - Secp256k1PubKeyAminoRoute = "tendermint/PubKeySecp256k1" + PrivKeyAminoRoute = "tendermint/PrivKeySecp256k1" + PubKeyAminoRoute = "tendermint/PubKeySecp256k1" ) var cdc = amino.NewCodec() @@ -24,11 +24,11 @@ var cdc = amino.NewCodec() func init() { cdc.RegisterInterface((*crypto.PubKey)(nil), nil) cdc.RegisterConcrete(PubKeySecp256k1{}, - Secp256k1PubKeyAminoRoute, nil) + PubKeyAminoRoute, nil) cdc.RegisterInterface((*crypto.PrivKey)(nil), nil) cdc.RegisterConcrete(PrivKeySecp256k1{}, - Secp256k1PrivKeyAminoRoute, nil) + PrivKeyAminoRoute, nil) } //-------------------------------------