aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorAmir Bandeali <abandeali1@gmail.com>2018-05-10 07:42:25 +0800
committerAmir Bandeali <abandeali1@gmail.com>2018-05-31 08:11:30 +0800
commitb587f076fe02a21274c91d35b6a18a7ba86e3b58 (patch)
treeeb5eea3b121b7626b496c5c2d925682d6e1ce84c /packages
parenta5a7217c8f24fe98275fd9927ca8c5e5f140c6f3 (diff)
downloaddexon-sol-tools-b587f076fe02a21274c91d35b6a18a7ba86e3b58.tar.gz
dexon-sol-tools-b587f076fe02a21274c91d35b6a18a7ba86e3b58.tar.zst
dexon-sol-tools-b587f076fe02a21274c91d35b6a18a7ba86e3b58.zip
Add Validator signature type
Diffstat (limited to 'packages')
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol34
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IValidator.sol35
-rw-r--r--packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSignatureValidator.sol1
-rw-r--r--packages/contracts/test/libraries/lib_bytes.ts2
4 files changed, 69 insertions, 3 deletions
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol
index f7fcd36b6..2a54da90f 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/MixinSignatureValidator.sol
@@ -20,6 +20,7 @@ pragma solidity ^0.4.24;
import "./mixins/MSignatureValidator.sol";
import "./interfaces/ISigner.sol";
+import "./interfaces/IValidator.sol";
import "./libs/LibExchangeErrors.sol";
import "../../utils/LibBytes/LibBytes.sol";
@@ -169,9 +170,38 @@ contract MixinSignatureValidator is
isValid = signer == recovered;
return isValid;
- // Signature verified by signer contract
+ // Signature verified by signer contract.
+ // If used with an order, the maker of the order is the signer contract.
} else if (signatureType == SignatureType.Contract) {
- isValid = ISigner(signer).isValidSignature(hash, signature);
+ // Pass in signature without signature type.
+ bytes memory signatureWithoutType = deepCopyBytes(
+ signature,
+ 1,
+ signature.length - 1
+ );
+ isValid = ISigner(signer).isValidSignature(hash, signatureWithoutType);
+ return isValid;
+
+ // Signature verified by validator contract.
+ // If used with an order, the maker of the order can still be an EOA.
+ // A signature using this type should be encoded as:
+ // | Offset | Length | Contents |
+ // | 0x00 | 1 | Signature type is always "\x07" |
+ // | 0x01 | 20 | Address of validator contract |
+ // | 0x15 | ** | Signature to validate |
+ } else if (signatureType == SignatureType.Validator) {
+ address validator = readAddress(signature, 1);
+ // Pass in signature without type or validator address.
+ bytes memory signatureWithoutTypeOrAddress = deepCopyBytes(
+ signature,
+ 21,
+ signature.length - 21
+ );
+ isValid = IValidator(validator).isValidSignature(
+ hash,
+ signer,
+ signatureWithoutTypeOrAddress
+ );
return isValid;
// Signer signed hash previously using the preSign function
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IValidator.sol b/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IValidator.sol
new file mode 100644
index 000000000..aed725066
--- /dev/null
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/interfaces/IValidator.sol
@@ -0,0 +1,35 @@
+/*
+
+ Copyright 2018 ZeroEx Intl.
+
+ 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.23;
+
+contract IValidator {
+
+ /// @dev Verifies that a signature is valid.
+ /// @param hash Message hash that is signed.
+ /// @param signer Address that should have signed the given hash.
+ /// @param signature Proof of signing.
+ /// @return Validity of order signature.
+ function isValidSignature(
+ bytes32 hash,
+ address signer,
+ bytes signature)
+ external
+ view
+ returns (bool isValid);
+}
diff --git a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSignatureValidator.sol b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSignatureValidator.sol
index 3658e7c6f..083fa89d7 100644
--- a/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSignatureValidator.sol
+++ b/packages/contracts/src/contracts/current/protocol/Exchange/mixins/MSignatureValidator.sol
@@ -32,6 +32,7 @@ contract MSignatureValidator is
EIP712,
Trezor,
Contract,
+ Validator,
PreSigned
}
diff --git a/packages/contracts/test/libraries/lib_bytes.ts b/packages/contracts/test/libraries/lib_bytes.ts
index 1fd30a3e0..ac654e037 100644
--- a/packages/contracts/test/libraries/lib_bytes.ts
+++ b/packages/contracts/test/libraries/lib_bytes.ts
@@ -60,7 +60,7 @@ describe('LibBytes', () => {
await blockchainLifecycle.revertAsync();
});
- describe.only('deepCopyBytes', () => {
+ describe('deepCopyBytes', () => {
const byteArrayLongerThan32BytesLen = (byteArrayLongerThan32Bytes.length - 2) / 2;
it('should throw if length of copy is 0', async () => {
const index = new BigNumber(0);