diff --git a/core/pathEnd.go b/core/pathEnd.go index c9e4f984..81074313 100644 --- a/core/pathEnd.go +++ b/core/pathEnd.go @@ -12,7 +12,7 @@ import ( ) var ( - defaultChainPrefix = commitmenttypes.NewMerklePrefix([]byte("ibc")) + DefaultChainPrefix = commitmenttypes.NewMerklePrefix([]byte("ibc")) ) const ( @@ -78,7 +78,7 @@ func (pe *PathEnd) ConnInit(dst *PathEnd, signer sdk.AccAddress) sdk.Msg { return conntypes.NewMsgConnectionOpenInit( pe.ClientID, dst.ClientID, - defaultChainPrefix, + DefaultChainPrefix, version, DefaultDelayPeriod, signer.String(), @@ -104,7 +104,7 @@ func (pe *PathEnd) ConnTry( dst.ConnectionID, dst.ClientID, cs, - defaultChainPrefix, + DefaultChainPrefix, conntypes.ExportedVersionsToProto(conntypes.GetCompatibleVersions()), DefaultDelayPeriod, dstConnState.Proof, diff --git a/go.mod b/go.mod index e57abbc8..e2638f5e 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/cosmos/go-bip39 v1.0.0 github.com/cosmos/gogoproto v1.4.10 github.com/cosmos/ibc-go/v7 v7.2.0 - github.com/datachainlab/ibc-mock-client v0.3.2 + github.com/datachainlab/ibc-mock-client v0.3.3 github.com/prometheus/client_golang v1.15.1 github.com/spf13/cobra v1.7.0 github.com/spf13/viper v1.16.0 diff --git a/go.sum b/go.sum index 82491ecb..b65fcbbe 100644 --- a/go.sum +++ b/go.sum @@ -369,8 +369,8 @@ github.com/cucumber/common/gherkin/go/v22 v22.0.0 h1:4K8NqptbvdOrjL9DEea6HFjSpbd github.com/cucumber/common/messages/go/v17 v17.1.1 h1:RNqopvIFyLWnKv0LfATh34SWBhXeoFTJnSrgm9cT/Ts= github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0= github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0= -github.com/datachainlab/ibc-mock-client v0.3.2 h1:SxBkaiuHWQ+1L085m2L35Fku3am7I6YL6B7dwurtDOM= -github.com/datachainlab/ibc-mock-client v0.3.2/go.mod h1:FfqyF+VJKp8jlIG21lTNJJIp8RCaxSrx6vjhNkfwgBM= +github.com/datachainlab/ibc-mock-client v0.3.3 h1:jZQvvd88g/6Jq8LULaqeYviOSQYqWhgsUMYMtUzosiA= +github.com/datachainlab/ibc-mock-client v0.3.3/go.mod h1:FfqyF+VJKp8jlIG21lTNJJIp8RCaxSrx6vjhNkfwgBM= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/provers/mock/prover.go b/provers/mock/prover.go index 6ce35b7f..00926af9 100644 --- a/provers/mock/prover.go +++ b/provers/mock/prover.go @@ -3,6 +3,7 @@ package mock import ( "context" "crypto/sha256" + "encoding/binary" fmt "fmt" "time" @@ -117,7 +118,8 @@ func (pr *Prover) CheckRefreshRequired(dst core.ChainInfoICS02Querier) (bool, er // ProveState returns the proof of an IBC state specified by `path` and `value` func (pr *Prover) ProveState(ctx core.QueryContext, path string, value []byte) ([]byte, clienttypes.Height, error) { - return makeProof(value), ctx.Height().(clienttypes.Height), nil + height := ctx.Height().(clienttypes.Height) + return makeProof(height, path, value), height, nil } // ProveHostConsensusState returns the proof of the consensus state at `height` @@ -125,7 +127,24 @@ func (pr *Prover) ProveHostConsensusState(ctx core.QueryContext, height exported return clienttypes.MarshalConsensusState(pr.chain.Codec(), consensusState) } -func makeProof(bz []byte) []byte { - h := sha256.Sum256(bz) +func makeProof(height exported.Height, path string, bz []byte) []byte { + revisionNumber := height.GetRevisionNumber() + revisionHeight := height.GetRevisionHeight() + + heightBuf := make([]byte, 16) + binary.BigEndian.PutUint64(heightBuf[:8], revisionNumber) + binary.BigEndian.PutUint64(heightBuf[8:], revisionHeight) + + hashPrefix := sha256.Sum256(core.DefaultChainPrefix.Bytes()) + hashPath := sha256.Sum256([]byte(path)) + hashValue := sha256.Sum256([]byte(bz)) + + var combined []byte + combined = append(combined, heightBuf...) + combined = append(combined, hashPrefix[:]...) + combined = append(combined, hashPath[:]...) + combined = append(combined, hashValue[:]...) + + h := sha256.Sum256(combined) return h[:] } diff --git a/tests/chains/tendermint/go.mod b/tests/chains/tendermint/go.mod index caa0c5e8..e114f5c7 100644 --- a/tests/chains/tendermint/go.mod +++ b/tests/chains/tendermint/go.mod @@ -9,7 +9,7 @@ require ( github.com/cometbft/cometbft-db v0.8.0 github.com/cosmos/cosmos-sdk v0.47.3 github.com/cosmos/ibc-go/v7 v7.2.0 - github.com/datachainlab/ibc-mock-client v0.3.2 + github.com/datachainlab/ibc-mock-client v0.3.3 github.com/gorilla/mux v1.8.0 github.com/rakyll/statik v0.1.7 github.com/spf13/cast v1.5.1 diff --git a/tests/chains/tendermint/go.sum b/tests/chains/tendermint/go.sum index de842cfd..42c8ba1e 100644 --- a/tests/chains/tendermint/go.sum +++ b/tests/chains/tendermint/go.sum @@ -351,8 +351,8 @@ github.com/cucumber/common/gherkin/go/v22 v22.0.0 h1:4K8NqptbvdOrjL9DEea6HFjSpbd github.com/cucumber/common/messages/go/v17 v17.1.1 h1:RNqopvIFyLWnKv0LfATh34SWBhXeoFTJnSrgm9cT/Ts= github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0= github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0= -github.com/datachainlab/ibc-mock-client v0.3.2 h1:SxBkaiuHWQ+1L085m2L35Fku3am7I6YL6B7dwurtDOM= -github.com/datachainlab/ibc-mock-client v0.3.2/go.mod h1:FfqyF+VJKp8jlIG21lTNJJIp8RCaxSrx6vjhNkfwgBM= +github.com/datachainlab/ibc-mock-client v0.3.3 h1:jZQvvd88g/6Jq8LULaqeYviOSQYqWhgsUMYMtUzosiA= +github.com/datachainlab/ibc-mock-client v0.3.3/go.mod h1:FfqyF+VJKp8jlIG21lTNJJIp8RCaxSrx6vjhNkfwgBM= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=