forked from UMAprotocol/protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[P1-H01] Require additional data in vote commit hash to prevent dupli…
…cation of votes (UMAprotocol#1217) Signed-off-by: Nick Pai <npai.nyc@gmail.com>
- Loading branch information
1 parent
84b6f3a
commit 50a88a3
Showing
9 changed files
with
634 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,31 @@ | ||
const web3 = require("web3"); | ||
|
||
// Web3's soliditySha3 will attempt to auto-detect the type of given input parameters, | ||
// but this won't produce expected behavior for certain types such as `bytes32` or `address`. | ||
// Therefore, these helper methods will explicitly set types. | ||
|
||
function computeTopicHash(request, roundId) { | ||
// Explicitly set the type. Otherwise `identifier` is encoded as a string. | ||
return web3.utils.soliditySha3( | ||
{ t: "bytes32", v: request.identifier }, | ||
{ t: "uint", v: request.time }, | ||
{ t: "uint", v: roundId } | ||
); | ||
} | ||
|
||
function computeVoteHash(request) { | ||
return web3.utils.soliditySha3( | ||
{ t: "int", v: request.price }, | ||
{ t: "int", v: request.salt }, | ||
{ t: "address", v: request.account }, | ||
{ t: "uint", v: request.time }, | ||
{ t: "uint", v: request.roundId }, | ||
{ t: "bytes32", v: request.identifier } | ||
); | ||
} | ||
|
||
function getKeyGenMessage(roundId) { | ||
// TODO: discuss dApp tradeoffs for changing this to a per-topic hash keypair. | ||
return `UMA Protocol one time key for round: ${roundId.toString()}`; | ||
} | ||
|
||
module.exports = { computeTopicHash, getKeyGenMessage }; | ||
module.exports = { computeTopicHash, computeVoteHash, getKeyGenMessage }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.