Skip to content

Commit

Permalink
Fix make proof
Browse files Browse the repository at this point in the history
Signed-off-by: Dongri Jin <[email protected]>
  • Loading branch information
dongrie committed Jan 31, 2024
1 parent adb402a commit 7b816ce
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 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
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[:]
}
1 change: 1 addition & 0 deletions tests/chains/tendermint/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,6 @@ require (
replace (
// https://github.com/cosmos/cosmos-sdk/blob/v0.47.3/go.mod#L171-L182
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
github.com/datachainlab/ibc-mock-client => github.com/dongrie/ibc-mock-client v0.3.3-0.20231213015729-29b70e76baf2
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
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,6 @@ 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/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 All @@ -372,6 +370,8 @@ github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WA
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/dongrie/ibc-mock-client v0.3.3-0.20231213015729-29b70e76baf2 h1:wuqyTnekH+pfNr+0Nrfq6PJgvllBbr7brabygF7oLlM=
github.com/dongrie/ibc-mock-client v0.3.3-0.20231213015729-29b70e76baf2/go.mod h1:FfqyF+VJKp8jlIG21lTNJJIp8RCaxSrx6vjhNkfwgBM=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
Expand Down
Binary file added yui-relayer
Binary file not shown.

0 comments on commit 7b816ce

Please sign in to comment.