From 358b48771cb406a6edc02e25ab81c87f20d129ac Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Wed, 12 Sep 2018 00:13:14 -0700 Subject: [PATCH] Merge PR #2308: Remove ripemd160 entirely * Remove ripemd160 entirely We already made this decision awhile ago, and have had tendermint switched for awhile. I was surprised to find ripemd still used within the storeinfo. This actually leads me to think the new "byter" API change in the tendermint PR RFC compliance is better, as it avoids things like this from ever happening. * Get ripemd160 removed from the gopkg imports --- Gopkg.lock | 1 - PENDING.md | 1 + examples/README.md | 2 +- store/multistoreproof.go | 2 +- store/multistoreproof_test.go | 9 +++++---- store/rootmultistore.go | 5 ++--- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index b647d20212..d5ccc65899 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -679,7 +679,6 @@ "github.com/tendermint/tmlibs/cli", "github.com/zondax/ledger-goclient", "golang.org/x/crypto/blowfish", - "golang.org/x/crypto/ripemd160", ] solver-name = "gps-cdcl" solver-version = 1 diff --git a/PENDING.md b/PENDING.md index aec65f3d56..652da599b0 100644 --- a/PENDING.md +++ b/PENDING.md @@ -43,6 +43,7 @@ BREAKING CHANGES * [simulation] Remove log and testing.TB from Operation and Invariants, in favor of using errors \#2282 * [tools] Removed gocyclo [#2211](https://github.com/cosmos/cosmos-sdk/issues/2211) * [baseapp] Remove `SetTxDecoder` in favor of requiring the decoder be set in baseapp initialization. [#1441](https://github.com/cosmos/cosmos-sdk/issues/1441) + * [store] Change storeInfo within the root multistore to use tmhash instead of ripemd160 \#2308 * Tendermint diff --git a/examples/README.md b/examples/README.md index 11aef9d280..5d872a7c93 100644 --- a/examples/README.md +++ b/examples/README.md @@ -253,7 +253,7 @@ first time. Accounts are serialized and stored in a Merkle tree under the key ``base/a/
``, where ``
`` is the address of the account. -Typically, the address of the account is the 20-byte ``RIPEMD160`` hash +Typically, the address of the account is the first 20-bytes of the ``sha256`` hash of the public key, but other formats are acceptable as well, as defined in the `Tendermint crypto library `__. The Merkle tree diff --git a/store/multistoreproof.go b/store/multistoreproof.go index e25f1cc1f2..d62bc4aca5 100644 --- a/store/multistoreproof.go +++ b/store/multistoreproof.go @@ -2,6 +2,7 @@ package store import ( "bytes" + "github.com/pkg/errors" "github.com/tendermint/iavl" cmn "github.com/tendermint/tendermint/libs/common" @@ -47,7 +48,6 @@ func VerifyMultiStoreCommitInfo(storeName string, storeInfos []storeInfo, appHas Version: height, StoreInfos: storeInfos, } - if !bytes.Equal(appHash, ci.Hash()) { return nil, cmn.NewError("the merkle root of multiStoreCommitInfo doesn't equal to appHash") } diff --git a/store/multistoreproof_test.go b/store/multistoreproof_test.go index 790588fb29..45a102cd3b 100644 --- a/store/multistoreproof_test.go +++ b/store/multistoreproof_test.go @@ -5,13 +5,14 @@ import ( "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/tendermint/iavl" cmn "github.com/tendermint/tendermint/libs/common" "github.com/tendermint/tendermint/libs/db" ) func TestVerifyMultiStoreCommitInfo(t *testing.T) { - appHash, _ := hex.DecodeString("ebf3c1fb724d3458023c8fefef7b33add2fc1e84") + appHash, _ := hex.DecodeString("69959B1B4E68E0F7BD3551A50C8F849B81801AF2") substoreRootHash, _ := hex.DecodeString("ea5d468431015c2cd6295e9a0bb1fc0e49033828") storeName := "acc" @@ -83,13 +84,13 @@ func TestVerifyMultiStoreCommitInfo(t *testing.T) { }) commitHash, err := VerifyMultiStoreCommitInfo(storeName, storeInfos, appHash) - assert.Nil(t, err) - assert.Equal(t, commitHash, substoreRootHash) + require.Nil(t, err) + require.Equal(t, commitHash, substoreRootHash) appHash, _ = hex.DecodeString("29de216bf5e2531c688de36caaf024cd3bb09ee3") _, err = VerifyMultiStoreCommitInfo(storeName, storeInfos, appHash) - assert.Error(t, err, "appHash doesn't match to the merkle root of multiStoreCommitInfo") + require.Error(t, err, "appHash doesn't match to the merkle root of multiStoreCommitInfo") } func TestVerifyRangeProof(t *testing.T) { diff --git a/store/rootmultistore.go b/store/rootmultistore.go index d9cf8a29a2..8aa2da0ba3 100644 --- a/store/rootmultistore.go +++ b/store/rootmultistore.go @@ -5,10 +5,9 @@ import ( "io" "strings" - "golang.org/x/crypto/ripemd160" - abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/merkle" + "github.com/tendermint/tendermint/crypto/tmhash" dbm "github.com/tendermint/tendermint/libs/db" sdk "github.com/cosmos/cosmos-sdk/types" @@ -424,7 +423,7 @@ func (si storeInfo) Hash() []byte { // Doesn't write Name, since merkle.SimpleHashFromMap() will // include them via the keys. bz, _ := cdc.MarshalBinary(si.Core) // Does not error - hasher := ripemd160.New() + hasher := tmhash.New() _, err := hasher.Write(bz) if err != nil { // TODO: Handle with #870