This repository was archived by the owner on Jan 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 59
Brian/validate order sig #79
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6b76e51
Adding lib bytes and removing coverage of it.
bweick a80af4e
Added fuller fillOrder function as well as signature checking and has…
bweick a51155c
Added validation logic and cleaned up tests.
bweick 0de5162
Removed LibBytes from branch.
bweick 38d7961
Added docs/comments and revert error messages
bweick e40ea29
Refactored CoreIssuanceOrder to make OrderLibnrary and associated tests.
bweick afa3be5
Added validateSignature test to CoreIssuanceOrder. Fixed erring tests…
bweick 18c1ae0
Removed .only on test.
bweick bfaef2e
Merge branch 'master' into brian/validate_order_sig
bweick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/* | ||
Copyright 2018 Set Labs Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
pragma solidity 0.4.24; | ||
|
||
|
||
/** | ||
* @title OrderLibrary | ||
* @author Set Protocol | ||
* | ||
* The Order Library contains functions for checking validation and hashing of Orders. | ||
* | ||
*/ | ||
|
||
library OrderLibrary { | ||
|
||
/* ============ Structs ============ */ | ||
|
||
struct IssuanceOrder { | ||
address setAddress; // _addresses[0] | ||
uint256 quantity; // _values[0] | ||
address makerAddress; // _addresses[1] | ||
address makerToken; // _addresses[2] | ||
uint256 makerTokenAmount; // _values[1] | ||
uint256 expiration; // _values[2] | ||
address relayerToken; // _addresses[3] | ||
uint256 relayerTokenAmount; // _values[3] | ||
uint256 salt; // _values[4] | ||
bytes32 orderHash; | ||
} | ||
|
||
/* ============ Internal Functions ============ */ | ||
|
||
/** | ||
* Create hash of order parameters | ||
* | ||
* @param _addresses [setAddress, makerAddress, makerToken, relayerToken] | ||
* @param _values [quantity, makerTokenAmount, expiration, relayerTokenAmount, salt] | ||
*/ | ||
function generateOrderHash( | ||
address[4] _addresses, | ||
uint[5] _values | ||
) | ||
internal | ||
pure | ||
returns(bytes32) | ||
{ | ||
// Hash the order parameters | ||
return keccak256( | ||
abi.encodePacked( | ||
_addresses[0], // setAddress | ||
_addresses[1], // makerAddress | ||
_addresses[2], // makerToken | ||
_addresses[3], // relayerToken | ||
_values[0], // quantity | ||
_values[1], // makerTokenAmount | ||
_values[2], // expiration | ||
_values[3], // relayerTokenAmount | ||
_values[4] // salt | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Validate order signature | ||
* | ||
* @param _orderHash Hash of issuance order | ||
* @param _signerAddress Address of Issuance Order signer | ||
* @param _v v element of ECDSA signature | ||
* @param _r r element of ECDSA signature | ||
* @param _s s element of ECDSA signature | ||
*/ | ||
function validateSignature( | ||
bytes32 _orderHash, | ||
address _signerAddress, | ||
uint8 _v, | ||
bytes32 _r, | ||
bytes32 _s | ||
) | ||
internal | ||
pure | ||
returns(bool) | ||
{ | ||
// Public address returned by ecrecover function | ||
address recAddress; | ||
|
||
// Ethereum msg prefix | ||
bytes memory msgPrefix = "\x19Ethereum Signed Message:\n32"; | ||
|
||
// Find what address signed the order | ||
recAddress = ecrecover( | ||
keccak256(abi.encodePacked(msgPrefix, _orderHash)), | ||
_v, | ||
_r, | ||
_s | ||
); | ||
|
||
return recAddress == _signerAddress; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: space |
||
} |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
pragma solidity 0.4.24; | ||
pragma experimental "ABIEncoderV2"; | ||
|
||
import { OrderLibrary } from "../../core/lib/OrderLibrary.sol"; | ||
|
||
// Mock contract implementation of OrderLibrary functions | ||
contract MockOrderLibrary { | ||
function testGenerateOrderHash( | ||
address[4] _addresses, | ||
uint[5] _values | ||
) | ||
public | ||
pure | ||
returns(bytes32) | ||
{ | ||
return OrderLibrary.generateOrderHash( | ||
_addresses, | ||
_values | ||
); | ||
} | ||
|
||
function testValidateSignature( | ||
bytes32 _orderHash, | ||
address _signerAddress, | ||
uint8 _v, | ||
bytes32 _r, | ||
bytes32 _s | ||
) | ||
public | ||
pure | ||
returns(bool) | ||
{ | ||
return OrderLibrary.validateSignature( | ||
_orderHash, | ||
_signerAddress, | ||
_v, | ||
_r, | ||
_s | ||
); | ||
} | ||
} | ||
|
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: space when you work on this next