diff options
author | Remco Bloemen <remco@wicked.ventures> | 2018-02-07 15:13:26 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2018-04-21 04:56:16 +0800 |
commit | d0f32d186502f4c8d675f3cd0000852366e942da (patch) | |
tree | 5abd016e6b1d1bbccb1b876a4fd5354856836337 /packages/contracts | |
parent | 2fe4e380d1824794b42b463c5fa589e6fdd1118a (diff) | |
download | dexon-0x-contracts-d0f32d186502f4c8d675f3cd0000852366e942da.tar dexon-0x-contracts-d0f32d186502f4c8d675f3cd0000852366e942da.tar.gz dexon-0x-contracts-d0f32d186502f4c8d675f3cd0000852366e942da.tar.bz2 dexon-0x-contracts-d0f32d186502f4c8d675f3cd0000852366e942da.tar.lz dexon-0x-contracts-d0f32d186502f4c8d675f3cd0000852366e942da.tar.xz dexon-0x-contracts-d0f32d186502f4c8d675f3cd0000852366e942da.tar.zst dexon-0x-contracts-d0f32d186502f4c8d675f3cd0000852366e942da.zip |
Add 'caller' signature type
Diffstat (limited to 'packages/contracts')
-rw-r--r-- | packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol | 52 |
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) |