Skip to content

Commit

Permalink
Merge pull request #63 from PeggyJV/zaki/update-data-hash
Browse files Browse the repository at this point in the history
  • Loading branch information
zmanian authored Sep 17, 2021
2 parents 8cc97f0 + e66b5c5 commit 6df8023
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions x/allocation/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package keeper
import (
"bytes"
"context"
"encoding/json"
"encoding/hex"
"fmt"
"strings"

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6df8023

Please sign in to comment.