@@ -6,6 +6,7 @@ pragma experimental ABIEncoderV2;
66import "../thirdparty/BytesUtil.sol " ;
77import "./AddressUtil.sol " ;
88import "./MathUint.sol " ;
9+ import "./ERC1271.sol " ;
910
1011
1112/// @title SignatureUtil
@@ -26,16 +27,7 @@ library SignatureUtil
2627 WALLET // deprecated
2728 }
2829
29- bytes4 constant internal ERC1271_MAGICVALUE_BS = 0x20c13b0b ;
30- bytes4 constant internal ERC1271_MAGICVALUE_B32 = 0x1626ba7e ;
31-
32- bytes4 constant internal ERC1271_SELECTOR_BS = bytes4 (
33- keccak256 (bytes ("isValidSignature(bytes,bytes) " ))
34- );
35-
36- bytes4 constant internal ERC1271_SELECTOR_B32 = bytes4 (
37- keccak256 (bytes ("isValidSignature(bytes32,bytes) " ))
38- );
30+ bytes4 constant internal ERC1271_MAGICVALUE = 0x1626ba7e ;
3931
4032 function verifySignatures (
4133 bytes32 signHash ,
@@ -45,45 +37,19 @@ library SignatureUtil
4537 internal
4638 view
4739 returns (bool )
48- {
49- return verifySignatures (abi.encodePacked (signHash), signers, signatures);
50- }
51-
52- function verifySignatures (
53- bytes memory data ,
54- address [] memory signers ,
55- bytes [] memory signatures
56- )
57- internal
58- view
59- returns (bool )
6040 {
6141 require (signers.length == signatures.length , "BAD_SIGNATURE_DATA " );
6242 address lastSigner;
6343 for (uint i = 0 ; i < signers.length ; i++ ) {
6444 require (signers[i] > lastSigner, "INVALID_SIGNERS_ORDER " );
6545 lastSigner = signers[i];
66- if (! verifySignature (data , signers[i], signatures[i])) {
46+ if (! verifySignature (signHash , signers[i], signatures[i])) {
6747 return false ;
6848 }
6949 }
7050 return true ;
7151 }
7252
73- function verifySignature (
74- bytes memory data ,
75- address signer ,
76- bytes memory signature
77- )
78- internal
79- view
80- returns (bool )
81- {
82- return signer.isContract () ?
83- verifyERC1271WithBytes (data, signer, signature) :
84- verifyEOASignature (keccak256 (data), signer, signature);
85- }
86-
8753 function verifySignature (
8854 bytes32 signHash ,
8955 address signer ,
@@ -93,8 +59,12 @@ library SignatureUtil
9359 view
9460 returns (bool )
9561 {
96- return signer.isContract () ?
97- verifyERC1271WithBytes32 (signHash, signer, signature) :
62+ if (signer == address (0 )) {
63+ return false ;
64+ }
65+
66+ return signer.isContract ()?
67+ verifyERC1271Signature (signHash, signer, signature):
9868 verifyEOASignature (signHash, signer, signature);
9969 }
10070
@@ -172,30 +142,8 @@ library SignatureUtil
172142 return success;
173143 }
174144
175- function verifyERC1271WithBytes (
176- bytes memory data ,
177- address signer ,
178- bytes memory signature
179- )
180- private
181- view
182- returns (bool )
183- {
184- bytes memory callData = abi.encodeWithSelector (
185- ERC1271_SELECTOR_BS ,
186- data,
187- signature
188- );
189- (bool success , bytes memory result ) = signer.staticcall (callData);
190- return (
191- success &&
192- result.length == 32 &&
193- result.toBytes4 (0 ) == ERC1271_MAGICVALUE_BS
194- );
195- }
196-
197- function verifyERC1271WithBytes32 (
198- bytes32 hash ,
145+ function verifyERC1271Signature (
146+ bytes32 signHash ,
199147 address signer ,
200148 bytes memory signature
201149 )
@@ -204,15 +152,15 @@ library SignatureUtil
204152 returns (bool )
205153 {
206154 bytes memory callData = abi.encodeWithSelector (
207- ERC1271_SELECTOR_B32 ,
208- hash ,
155+ ERC1271 .isValidSignature. selector ,
156+ signHash ,
209157 signature
210158 );
211159 (bool success , bytes memory result ) = signer.staticcall (callData);
212160 return (
213161 success &&
214162 result.length == 32 &&
215- result.toBytes4 (0 ) == ERC1271_MAGICVALUE_B32
163+ result.toBytes4 (0 ) == ERC1271_MAGICVALUE
216164 );
217165 }
218166}
0 commit comments