Skip to content

Commit

Permalink
Use encoding/binary
Browse files Browse the repository at this point in the history
Signed-off-by: Dongri Jin <[email protected]>
  • Loading branch information
dongrie committed Dec 21, 2023
1 parent 9a144e3 commit 309fad3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
13 changes: 5 additions & 8 deletions provers/mock/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package mock
import (
"context"
"crypto/sha256"
"encoding/binary"
fmt "fmt"
"math/big"
"time"

"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -126,19 +126,16 @@ func makeProof(height exported.Height, path string, bz []byte) []byte {
revisionNumber := height.GetRevisionNumber()
revisionHeight := height.GetRevisionHeight()

heightBig := new(big.Int)
revisionNumberBig := new(big.Int).SetUint64(revisionNumber)
revisionNumberBig = revisionNumberBig.Lsh(revisionNumberBig, 64)
revisionHeightBig := new(big.Int).SetUint64(revisionHeight)
heightBig.Or(revisionNumberBig, revisionHeightBig)
hashHeight := sha256.Sum256(heightBig.Bytes())
heightBuf := make([]byte, 16)
binary.LittleEndian.PutUint64(heightBuf[:8], revisionHeight)
binary.LittleEndian.PutUint64(heightBuf[8:], revisionNumber)

hashPrefix := sha256.Sum256(core.DefaultChainPrefix.Bytes())
hashPath := sha256.Sum256([]byte(path))
hashValue := sha256.Sum256([]byte(bz))

var combined []byte
combined = append(combined, hashHeight[:]...)
combined = append(combined, heightBuf...)
combined = append(combined, hashPrefix[:]...)
combined = append(combined, hashPath[:]...)
combined = append(combined, hashValue[:]...)
Expand Down
2 changes: 1 addition & 1 deletion tests/chains/tendermint/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +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/datachainlab/ibc-mock-client => github.com/dongrie/ibc-mock-client v0.3.3-0.20231221102347-9000a7df65b4
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 @@ -370,8 +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/dongrie/ibc-mock-client v0.3.3-0.20231221102347-9000a7df65b4 h1:6Ons8oPPMxqjPpcIRan7duWpyjVBnOR6S2u0iiTIBWk=
github.com/dongrie/ibc-mock-client v0.3.3-0.20231221102347-9000a7df65b4/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

0 comments on commit 309fad3

Please sign in to comment.