Skip to content

Commit

Permalink
Merge PR cosmos#2308: Remove ripemd160 entirely
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ValarDragon authored and cwgoes committed Sep 12, 2018
1 parent fb0cc0b commit 358b487
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
1 change: 0 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ first time.

Accounts are serialized and stored in a Merkle tree under the key
``base/a/<address>``, where ``<address>`` 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 <https://github.com/tendermint/tendermint/tree/master/crypto>`__. The Merkle tree
Expand Down
2 changes: 1 addition & 1 deletion store/multistoreproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package store

import (
"bytes"

"github.com/pkg/errors"
"github.com/tendermint/iavl"
cmn "github.com/tendermint/tendermint/libs/common"
Expand Down Expand Up @@ -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")
}
Expand Down
9 changes: 5 additions & 4 deletions store/multistoreproof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 2 additions & 3 deletions store/rootmultistore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 358b487

Please sign in to comment.