diff options
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) |