Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sha512 merkle tree upgrade #218

Merged
merged 4 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ require (
cosmossdk.io/api v0.2.4
cosmossdk.io/core v0.3.2
github.com/golang/mock v1.6.0
golang.org/x/crypto v0.1.0
)

require (
Expand Down Expand Up @@ -131,7 +132,6 @@ require (
github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
golang.org/x/crypto v0.1.0 // indirect
golang.org/x/net v0.1.0 // indirect
golang.org/x/sys v0.1.0 // indirect
golang.org/x/term v0.1.0 // indirect
Expand Down Expand Up @@ -165,6 +165,8 @@ replace (
github.com/tendermint/tendermint => github.com/informalsystems/tendermint v0.34.23
github.com/tendermint/tm-db => github.com/informalsystems/tm-db v0.6.7

github.com/wealdtech/go-merkletree => github.com/TheMarstonConnell/go-merkletree v0.0.0-20230124030923-93fb10e701d7

// use grpc compatible with cosmos-flavored protobufs
google.golang.org/grpc => google.golang.org/grpc v1.33.2
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/TheMarstonConnell/go-merkletree v0.0.0-20230124030923-93fb10e701d7 h1:5HSad+OSV81UBODXzvt+CVUzmxPMzC/OFoq2cIqj3LE=
github.com/TheMarstonConnell/go-merkletree v0.0.0-20230124030923-93fb10e701d7/go.mod h1:SL9h+IpE1SI3K+In4dOtjHu9KZIluuRjdQxYHJQGdUI=
github.com/VictoriaMetrics/fastcache v1.5.7/go.mod h1:ptDBkNMQI4RtmVo8VS/XwRY6RoTu1dAWCbrk+6WsEM8=
github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw=
github.com/VividCortex/gohistogram v1.0.0 h1:6+hBz+qvs0JOrrNhhmR7lFxo5sINxBCGXrdtl/UvroE=
Expand Down Expand Up @@ -947,8 +949,6 @@ github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPU
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/vmihailenco/msgpack/v5 v5.1.4/go.mod h1:C5gboKD0TJPqWDTVTtrQNfRbiBwHZGo8UTqP/9/XvLI=
github.com/vmihailenco/tagparser v0.1.2/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
github.com/wealdtech/go-merkletree v1.0.0 h1:DsF1xMzj5rK3pSQM6mPv8jlyJyHXhFxpnA2bwEjMMBY=
github.com/wealdtech/go-merkletree v1.0.0/go.mod h1:cdil512d/8ZC7Kx3bfrDvGMQXB25NTKbsm0rFrmDax4=
github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
github.com/wsddn/go-ecdh v0.0.0-20161211032359-48726bab9208/go.mod h1:IotVbo4F+mw0EzQ08zFqg7pK3FebNXpaMsRy2RT+Ees=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
Expand Down
3 changes: 2 additions & 1 deletion x/storage/keeper/msg_server_postproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
merkletree "github.com/wealdtech/go-merkletree"
"github.com/wealdtech/go-merkletree/sha3"

"github.com/jackalLabs/canine-chain/x/storage/types"
)
Expand Down Expand Up @@ -63,7 +64,7 @@ func (k msgServer) Postproof(goCtx context.Context, msg *types.MsgPostproof) (*t
ctx.Logger().Error("%v\n", err)
return nil, fmt.Errorf("could not build merkle tree")
}
verified, err := merkletree.VerifyProof(hashName, &proof, m)
verified, err := merkletree.VerifyProofUsing(hashName, false, &proof, [][]byte{m}, sha3.New512())
if err != nil {
ctx.Logger().Error("%v\n", err)

Expand Down
10 changes: 5 additions & 5 deletions x/storage/keeper/msg_server_proofs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/jackalLabs/canine-chain/x/storage/types"
"github.com/jackalLabs/canine-chain/x/storage/types/sha512"
merkletree "github.com/wealdtech/go-merkletree"
"github.com/wealdtech/go-merkletree/sha3"
)

type TestFile struct {
Expand Down Expand Up @@ -53,7 +53,7 @@ func CreateMerkleForProof(file TestFile) (string, string, error) {

data = append(data, hashName)

tree, err := merkletree.NewUsing(data, sha512.New(), []byte{})
tree, err := merkletree.NewUsing(data, sha3.New512(), false)
if err != nil {
return "", "", err
}
Expand All @@ -65,7 +65,7 @@ func CreateMerkleForProof(file TestFile) (string, string, error) {
}
ditem := h.Sum(nil)

proof, err := tree.GenerateProof(ditem)
proof, err := tree.GenerateProof(ditem, 0)
if err != nil {
return "", "", err
}
Expand All @@ -79,7 +79,7 @@ func CreateMerkleForProof(file TestFile) (string, string, error) {

k, _ := hex.DecodeString(e)

verified, err := merkletree.VerifyProof(ditem, proof, k)
verified, err := merkletree.VerifyProofUsing(ditem, false, proof, [][]byte{k}, sha3.New512())
if err != nil {
return "", "", err
}
Expand All @@ -106,7 +106,7 @@ func makeContract(file TestFile) (string, string, error) {

list = append(list, hashName)

t, err := merkletree.NewUsing(list, sha512.New(), []byte{})
t, err := merkletree.NewUsing(list, sha3.New512(), false)
if err != nil {
return "", "", err
}
Expand Down
9 changes: 5 additions & 4 deletions x/storage/simulation/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

sdksim "github.com/cosmos/cosmos-sdk/types/simulation"
merkle "github.com/wealdtech/go-merkletree"
"github.com/wealdtech/go-merkletree/sha3"
)

const (
Expand Down Expand Up @@ -47,7 +48,7 @@ func GetMerkleProof() (item, jProof string) {

data = append(data, hashName)

tree, err := merkle.New(data)
tree, err := merkle.NewUsing(data, sha3.New512(), false)
if err != nil {
panic(err)
}
Expand All @@ -59,7 +60,7 @@ func GetMerkleProof() (item, jProof string) {
}
hashedItem := h.Sum(nil)

proof, err := tree.GenerateProof(hashedItem)
proof, err := tree.GenerateProof(hashedItem, 0)
if err != nil {
panic(err)
}
Expand All @@ -79,7 +80,7 @@ func GetMerkleProof() (item, jProof string) {
panic(err)
}

validProof, err := merkle.VerifyProof(hashedItem, proof, hex)
validProof, err := merkle.VerifyProofUsing(hashedItem, false, proof, [][]byte{hex}, sha3.New512())
if err != nil {
panic(err)
}
Expand All @@ -106,7 +107,7 @@ func GetMerkleRoot() string {

data = append(data, hashName)

tree, err := merkle.New(data)
tree, err := merkle.NewUsing(data, sha3.New512(), false)
if err != nil {
panic(err)
}
Expand Down
17 changes: 0 additions & 17 deletions x/storage/types/sha512/sha512.go

This file was deleted.