Skip to content

Commit bbea0d0

Browse files
authored
Fix make proof (#129)
* 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>
1 parent adb402a commit bbea0d0

File tree

6 files changed

+31
-12
lines changed

6 files changed

+31
-12
lines changed

core/pathEnd.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
var (
15-
defaultChainPrefix = commitmenttypes.NewMerklePrefix([]byte("ibc"))
15+
DefaultChainPrefix = commitmenttypes.NewMerklePrefix([]byte("ibc"))
1616
)
1717

1818
const (
@@ -78,7 +78,7 @@ func (pe *PathEnd) ConnInit(dst *PathEnd, signer sdk.AccAddress) sdk.Msg {
7878
return conntypes.NewMsgConnectionOpenInit(
7979
pe.ClientID,
8080
dst.ClientID,
81-
defaultChainPrefix,
81+
DefaultChainPrefix,
8282
version,
8383
DefaultDelayPeriod,
8484
signer.String(),
@@ -104,7 +104,7 @@ func (pe *PathEnd) ConnTry(
104104
dst.ConnectionID,
105105
dst.ClientID,
106106
cs,
107-
defaultChainPrefix,
107+
DefaultChainPrefix,
108108
conntypes.ExportedVersionsToProto(conntypes.GetCompatibleVersions()),
109109
DefaultDelayPeriod,
110110
dstConnState.Proof,

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/cosmos/go-bip39 v1.0.0
1313
github.com/cosmos/gogoproto v1.4.10
1414
github.com/cosmos/ibc-go/v7 v7.2.0
15-
github.com/datachainlab/ibc-mock-client v0.3.2
15+
github.com/datachainlab/ibc-mock-client v0.3.3
1616
github.com/prometheus/client_golang v1.15.1
1717
github.com/spf13/cobra v1.7.0
1818
github.com/spf13/viper v1.16.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,8 @@ github.com/cucumber/common/gherkin/go/v22 v22.0.0 h1:4K8NqptbvdOrjL9DEea6HFjSpbd
369369
github.com/cucumber/common/messages/go/v17 v17.1.1 h1:RNqopvIFyLWnKv0LfATh34SWBhXeoFTJnSrgm9cT/Ts=
370370
github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0=
371371
github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0=
372-
github.com/datachainlab/ibc-mock-client v0.3.2 h1:SxBkaiuHWQ+1L085m2L35Fku3am7I6YL6B7dwurtDOM=
373-
github.com/datachainlab/ibc-mock-client v0.3.2/go.mod h1:FfqyF+VJKp8jlIG21lTNJJIp8RCaxSrx6vjhNkfwgBM=
372+
github.com/datachainlab/ibc-mock-client v0.3.3 h1:jZQvvd88g/6Jq8LULaqeYviOSQYqWhgsUMYMtUzosiA=
373+
github.com/datachainlab/ibc-mock-client v0.3.3/go.mod h1:FfqyF+VJKp8jlIG21lTNJJIp8RCaxSrx6vjhNkfwgBM=
374374
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
375375
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
376376
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

provers/mock/prover.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package mock
33
import (
44
"context"
55
"crypto/sha256"
6+
"encoding/binary"
67
fmt "fmt"
78
"time"
89

@@ -117,15 +118,33 @@ func (pr *Prover) CheckRefreshRequired(dst core.ChainInfoICS02Querier) (bool, er
117118

118119
// ProveState returns the proof of an IBC state specified by `path` and `value`
119120
func (pr *Prover) ProveState(ctx core.QueryContext, path string, value []byte) ([]byte, clienttypes.Height, error) {
120-
return makeProof(value), ctx.Height().(clienttypes.Height), nil
121+
height := ctx.Height().(clienttypes.Height)
122+
return makeProof(height, path, value), height, nil
121123
}
122124

123125
// ProveHostConsensusState returns the proof of the consensus state at `height`
124126
func (pr *Prover) ProveHostConsensusState(ctx core.QueryContext, height exported.Height, consensusState exported.ConsensusState) ([]byte, error) {
125127
return clienttypes.MarshalConsensusState(pr.chain.Codec(), consensusState)
126128
}
127129

128-
func makeProof(bz []byte) []byte {
129-
h := sha256.Sum256(bz)
130+
func makeProof(height exported.Height, path string, bz []byte) []byte {
131+
revisionNumber := height.GetRevisionNumber()
132+
revisionHeight := height.GetRevisionHeight()
133+
134+
heightBuf := make([]byte, 16)
135+
binary.BigEndian.PutUint64(heightBuf[:8], revisionNumber)
136+
binary.BigEndian.PutUint64(heightBuf[8:], revisionHeight)
137+
138+
hashPrefix := sha256.Sum256(core.DefaultChainPrefix.Bytes())
139+
hashPath := sha256.Sum256([]byte(path))
140+
hashValue := sha256.Sum256([]byte(bz))
141+
142+
var combined []byte
143+
combined = append(combined, heightBuf...)
144+
combined = append(combined, hashPrefix[:]...)
145+
combined = append(combined, hashPath[:]...)
146+
combined = append(combined, hashValue[:]...)
147+
148+
h := sha256.Sum256(combined)
130149
return h[:]
131150
}

tests/chains/tendermint/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/cometbft/cometbft-db v0.8.0
1010
github.com/cosmos/cosmos-sdk v0.47.3
1111
github.com/cosmos/ibc-go/v7 v7.2.0
12-
github.com/datachainlab/ibc-mock-client v0.3.2
12+
github.com/datachainlab/ibc-mock-client v0.3.3
1313
github.com/gorilla/mux v1.8.0
1414
github.com/rakyll/statik v0.1.7
1515
github.com/spf13/cast v1.5.1

tests/chains/tendermint/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ github.com/cucumber/common/gherkin/go/v22 v22.0.0 h1:4K8NqptbvdOrjL9DEea6HFjSpbd
351351
github.com/cucumber/common/messages/go/v17 v17.1.1 h1:RNqopvIFyLWnKv0LfATh34SWBhXeoFTJnSrgm9cT/Ts=
352352
github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0=
353353
github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0=
354-
github.com/datachainlab/ibc-mock-client v0.3.2 h1:SxBkaiuHWQ+1L085m2L35Fku3am7I6YL6B7dwurtDOM=
355-
github.com/datachainlab/ibc-mock-client v0.3.2/go.mod h1:FfqyF+VJKp8jlIG21lTNJJIp8RCaxSrx6vjhNkfwgBM=
354+
github.com/datachainlab/ibc-mock-client v0.3.3 h1:jZQvvd88g/6Jq8LULaqeYviOSQYqWhgsUMYMtUzosiA=
355+
github.com/datachainlab/ibc-mock-client v0.3.3/go.mod h1:FfqyF+VJKp8jlIG21lTNJJIp8RCaxSrx6vjhNkfwgBM=
356356
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
357357
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
358358
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

0 commit comments

Comments
 (0)