aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemco Bloemen <remco@wicked.ventures>2018-02-07 15:13:26 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-04-21 04:56:16 +0800
commitd0f32d186502f4c8d675f3cd0000852366e942da (patch)
tree5abd016e6b1d1bbccb1b876a4fd5354856836337
parent2fe4e380d1824794b42b463c5fa589e6fdd1118a (diff)
downloaddexon-sol-tools-d0f32d186502f4c8d675f3cd0000852366e942da.tar
dexon-sol-tools-d0f32d186502f4c8d675f3cd0000852366e942da.tar.gz
dexon-sol-tools-d0f32d186502f4c8d675f3cd0000852366e942da.tar.bz2
dexon-sol-tools-d0f32d186502f4c8d675f3cd0000852366e942da.tar.lz
dexon-sol-tools-d0f32d186502f4c8d675f3cd0000852366e942da.tar.xz
dexon-sol-tools-d0f32d186502f4c8d675f3cd0000852366e942da.tar.zst
dexon-sol-tools-d0f32d186502f4c8d675f3cd0000852366e942da.zip
Add 'caller' signature type
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol52
1 files changed, 35 insertions, 17 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol
index 919dbe312..959300753 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol
@@ -26,6 +26,7 @@ contract MixinSignatureValidator is
{
enum SignatureType {
Invalid,
+ Caller,
Ecrecover
}
@@ -36,27 +37,44 @@ contract MixinSignatureValidator is
public view
returns (bool isValid)
{
- require(signature.length >= 1);
+ // TODO: Domain separation: make hash depend on role. (Taker sig should not be valid as maker sig, etc.)
- // Select signature type
+ require(signature.length >= 1);
SignatureType signatureType = SignatureType(uint8(signature[0]));
- if (signatureType != SignatureType.Ecrecover) {
- valid = false;
+
+ // Zero is always an invalid signature
+ if (signatureType == SignatureType.Invalid) {
+ require(signature.length == 1);
+ isValid = false;
return;
- }
- // Verify using ecrecover
- require(signature.length == 66);
- uint8 v = uint8(signature[1]);
- bytes32 r = get32(signature, 2);
- bytes32 s = get32(signature, 34);
- address recovered = ecrecover(
- keccak256("\x19Ethereum Signed Message:\n32", hash),
- v,
- r,
- s
- );
- isValid = signer == recovered;
+ // Implicitly signed by caller
+ } else if (signatureType == SignatureType.Caller) {
+ require(signature.length == 1);
+ isValid = signer == msg.sender;
+ return;
+
+ // Signed using web3.eth_sign
+ } else if (signatureType == SignatureType.Ecrecover) {
+ require(signature.length == 66);
+ uint8 v = uint8(signature[1]);
+ bytes32 r = get32(signature, 2);
+ bytes32 s = get32(signature, 34);
+ address recovered = ecrecover(
+ keccak256("\x19Ethereum Signed Message:\n32", hash),
+ v,
+ r,
+ s
+ );
+ isValid = signer == recovered;
+ return;
+
+ // Anything else is illegal
+ } else {
+ revert();
+
+ }
+ return false;
}
function get32(bytes b, uint256 index)