Add Validator signature type

This commit is contained in:
Amir Bandeali 2018-05-09 16:42:25 -07:00
parent a5a7217c8f
commit b587f076fe
4 changed files with 69 additions and 3 deletions

View File

@ -20,6 +20,7 @@ pragma solidity ^0.4.24;
import "./mixins/MSignatureValidator.sol"; import "./mixins/MSignatureValidator.sol";
import "./interfaces/ISigner.sol"; import "./interfaces/ISigner.sol";
import "./interfaces/IValidator.sol";
import "./libs/LibExchangeErrors.sol"; import "./libs/LibExchangeErrors.sol";
import "../../utils/LibBytes/LibBytes.sol"; import "../../utils/LibBytes/LibBytes.sol";
@ -169,9 +170,38 @@ contract MixinSignatureValidator is
isValid = signer == recovered; isValid = signer == recovered;
return isValid; 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) { } 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; return isValid;
// Signer signed hash previously using the preSign function // Signer signed hash previously using the preSign function

View File

@ -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);
}

View File

@ -32,6 +32,7 @@ contract MSignatureValidator is
EIP712, EIP712,
Trezor, Trezor,
Contract, Contract,
Validator,
PreSigned PreSigned
} }

View File

@ -60,7 +60,7 @@ describe('LibBytes', () => {
await blockchainLifecycle.revertAsync(); await blockchainLifecycle.revertAsync();
}); });
describe.only('deepCopyBytes', () => { describe('deepCopyBytes', () => {
const byteArrayLongerThan32BytesLen = (byteArrayLongerThan32Bytes.length - 2) / 2; const byteArrayLongerThan32BytesLen = (byteArrayLongerThan32Bytes.length - 2) / 2;
it('should throw if length of copy is 0', async () => { it('should throw if length of copy is 0', async () => {
const index = new BigNumber(0); const index = new BigNumber(0);