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 29b70e7 commit 28f2d67
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions modules/light-clients/xx-mock/types/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package types
import (
"bytes"
"crypto/sha256"
"math/big"
"encoding/binary"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -119,12 +119,9 @@ func (cs ClientState) VerifyMembership(
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)

merklePath := path.(commitmenttypes.MerklePath)
mPrefix, err := merklePath.GetKey(0)
Expand All @@ -141,7 +138,7 @@ func (cs ClientState) VerifyMembership(
hashValue := sha256.Sum256([]byte(value))

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

0 comments on commit 28f2d67

Please sign in to comment.