Skip to content

Commit

Permalink
Fix make proof (#129)
Browse files Browse the repository at this point in the history
* Fix make proof

Signed-off-by: Dongri Jin <dongri.jin@speee.jp>

* Use encoding/binary

Signed-off-by: Dongri Jin <dongri.jin@speee.jp>

* Ibc-mock-client version up

Signed-off-by: Dongri Jin <dongri.jin@speee.jp>

* Ibc-mock-client version up

Signed-off-by: Dongri Jin <dongri.jin@speee.jp>

* Remove Yui-relayer binary

Signed-off-by: Dongri Jin <dongri.jin@speee.jp>

---------

Signed-off-by: Dongri Jin <dongri.jin@speee.jp>
  • Loading branch information
dongrie committed Jan 31, 2024
1 parent adb402a commit bbea0d0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
6 changes: 3 additions & 3 deletions core/pathEnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

var (
defaultChainPrefix = commitmenttypes.NewMerklePrefix([]byte("ibc"))
DefaultChainPrefix = commitmenttypes.NewMerklePrefix([]byte("ibc"))
)

const (
Expand Down Expand Up @@ -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(),
Expand All @@ -104,7 +104,7 @@ func (pe *PathEnd) ConnTry(
dst.ConnectionID,
dst.ClientID,
cs,
defaultChainPrefix,
DefaultChainPrefix,
conntypes.ExportedVersionsToProto(conntypes.GetCompatibleVersions()),
DefaultDelayPeriod,
dstConnState.Proof,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
25 changes: 22 additions & 3 deletions provers/mock/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package mock
import (
"context"
"crypto/sha256"
"encoding/binary"
fmt "fmt"
"time"

Expand Down Expand Up @@ -117,15 +118,33 @@ 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`
func (pr *Prover) ProveHostConsensusState(ctx core.QueryContext, height exported.Height, consensusState exported.ConsensusState) ([]byte, error) {
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[:]
}
2 changes: 1 addition & 1 deletion tests/chains/tendermint/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/chains/tendermint/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit bbea0d0

Please sign in to comment.