Skip to content

Commit

Permalink
Bug/gen withdrawal hash (#65)
Browse files Browse the repository at this point in the history
* add splitter between variables

* splitter
  • Loading branch information
sh-cha authored May 28, 2024
1 parent aabb774 commit 89f0784
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions x/ophost/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,15 @@ func (ms MsgServer) FinalizeTokenWithdrawal(ctx context.Context, req *types.MsgF
seed := []byte{}
seed = binary.BigEndian.AppendUint64(seed, bridgeId)
seed = binary.BigEndian.AppendUint64(seed, req.Sequence)
// variable length
seed = append(seed, sender...)
seed = append(seed, types.Splitter)
// variable length
seed = append(seed, receiver...)
seed = append(seed, types.Splitter)
// variable length
seed = append(seed, []byte(denom)...)
seed = append(seed, types.Splitter)
seed = binary.BigEndian.AppendUint64(seed, amount.Uint64())

withdrawalHash = sha3.Sum256(seed)
Expand Down
4 changes: 2 additions & 2 deletions x/ophost/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ func Test_FinalizeTokenWithdrawal(t *testing.T) {
amount := sdk.NewCoin("l1denom", math.NewInt(3_000_000))
input.Faucet.Fund(ctx, types.BridgeAddress(1), amount)

outputRoot := decodeHex(t, "d87b15f515e52e234f5ddca84627128ad842fa6c741d6b85d589a13bbdad3a89")
outputRoot := decodeHex(t, "1d1ff385c7ea31c99289091fd4548072e5cd061b6bbde2b406ff62dd97e3edc3")
version := decodeHex(t, "0000000000000000000000000000000000000000000000000000000000000001")
stateRoot := decodeHex(t, "0000000000000000000000000000000000000000000000000000000000000002")
storageRoot := decodeHex(t, "326ca35f4738f837ad9f335349fc71bdecf4c4ed3485fff1763d3bab55efc88a")
storageRoot := decodeHex(t, "b88a9b5af9f2a469cefb7e2e388eb146e7154f2eea8aaad1422f232f1b62067e")
blockHash := decodeHex(t, "0000000000000000000000000000000000000000000000000000000000000003")
proofs := [][]byte{
decodeHex(t, "32e1a72a7c215563f9426bfe267b6fa22ba49b1fba7162d80094dc2f2b6c5a3a"),
Expand Down
2 changes: 2 additions & 0 deletions x/ophost/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ var (
NextOutputIndexPrefix = []byte{0x61}
ProvenWithdrawalPrefix = []byte{0x71}
BatchInfoPrefix = []byte{0x81}

Splitter = byte('|')
)

0 comments on commit 89f0784

Please sign in to comment.