From e66b5c53cd9f707216e9afd8b41dcc926a69f35c Mon Sep 17 00:00:00 2001 From: Zaki Manian Date: Thu, 26 Aug 2021 13:37:23 -0700 Subject: [PATCH] Change the datahash to use a hex encoded protobuf instead of sorted json to be more cross language friendly. --- x/allocation/keeper/msg_server.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/x/allocation/keeper/msg_server.go b/x/allocation/keeper/msg_server.go index 7b08a11d..81ddc8c5 100644 --- a/x/allocation/keeper/msg_server.go +++ b/x/allocation/keeper/msg_server.go @@ -3,7 +3,7 @@ package keeper import ( "bytes" "context" - "encoding/json" + "encoding/hex" "fmt" "strings" @@ -168,18 +168,19 @@ func (k Keeper) AllocationCommit(c context.Context, msg *types.MsgAllocationComm return nil, sdkerrors.Wrap(types.ErrNoPrecommit, val.String()) } - // parse data to json in order to compute the vote hash and sort - jsonBz, err := json.Marshal(commit.Cellar) + // marshal the protobuf message to computing the hash + databytes, err := commit.Cellar.Marshal() + if err != nil { return nil, sdkerrors.Wrap( sdkerrors.ErrJSONMarshal, "failed to marshal json pool allocations", ) } - jsonBz = sdk.MustSortJSON(jsonBz) + hexbytes := hex.EncodeToString(databytes) // calculate the vote hash on the server - commitHash := types.DataHash(commit.Salt, string(jsonBz), val) + commitHash := types.DataHash(commit.Salt, hexbytes, val) // compare to precommit hash if !bytes.Equal(commitHash, precommit.Hash) {