@@ -29,7 +29,9 @@ abstract contract EIP712 {
29
29
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
30
30
* contract upgrade].
31
31
*/
32
- constructor (string memory name ) {
32
+ constructor (
33
+ string memory name
34
+ ) {
33
35
_name = name.toShortStringWithFallback (_nameFallback);
34
36
_hashedName = keccak256 (bytes (name));
35
37
}
@@ -60,7 +62,9 @@ abstract contract EIP712 {
60
62
* address signer = ECDSA.recover(digest, signature);
61
63
* ```
62
64
*/
63
- function _hashTypedDataV4 (bytes32 structHash ) internal view virtual returns (bytes32 ) {
65
+ function _hashTypedDataV4 (
66
+ bytes32 structHash
67
+ ) internal view virtual returns (bytes32 ) {
64
68
return ECDSA.toTypedDataHash (_domainSeparatorV4 (), structHash);
65
69
}
66
70
}
@@ -73,11 +77,15 @@ contract SignerECDSA is EIP712, Test {
73
77
"Permit(address signer,address sender,uint256 nonceNamespace,uint256 nonce,uint256 deadline,uint256 value,bytes data) "
74
78
);
75
79
76
- constructor (EthereumVaultConnector _evc ) EIP712 (_evc.name ()) {
80
+ constructor (
81
+ EthereumVaultConnector _evc
82
+ ) EIP712 (_evc.name ()) {
77
83
evc = _evc;
78
84
}
79
85
80
- function setPrivateKey (uint256 _privateKey ) external {
86
+ function setPrivateKey (
87
+ uint256 _privateKey
88
+ ) external {
81
89
privateKey = _privateKey;
82
90
}
83
91
@@ -111,15 +119,19 @@ contract SignerERC1271 is EIP712, IERC1271 {
111
119
"Permit(address signer,address sender,uint256 nonceNamespace,uint256 nonce,uint256 deadline,uint256 value,bytes data) "
112
120
);
113
121
114
- constructor (EthereumVaultConnector _evc ) EIP712 (_evc.name ()) {
122
+ constructor (
123
+ EthereumVaultConnector _evc
124
+ ) EIP712 (_evc.name ()) {
115
125
evc = _evc;
116
126
}
117
127
118
128
function _buildDomainSeparator () internal view override returns (bytes32 ) {
119
129
return keccak256 (abi.encode (_TYPE_HASH, _hashedName, block .chainid , address (evc)));
120
130
}
121
131
122
- function setSignatureHash (bytes calldata signature ) external {
132
+ function setSignatureHash (
133
+ bytes calldata signature
134
+ ) external {
123
135
signatureHash = keccak256 (signature);
124
136
}
125
137
@@ -151,23 +163,31 @@ contract EthereumVaultConnectorWithFallback is EthereumVaultConnectorHarness {
151
163
bool internal shouldRevert;
152
164
bool public fallbackCalled;
153
165
154
- function setExpectedHash (bytes calldata data ) external {
166
+ function setExpectedHash (
167
+ bytes calldata data
168
+ ) external {
155
169
expectedHash = keccak256 (data);
156
170
}
157
171
158
- function setExpectedValue (uint256 value ) external {
172
+ function setExpectedValue (
173
+ uint256 value
174
+ ) external {
159
175
expectedValue = value;
160
176
}
161
177
162
- function setShouldRevert (bool sr ) external {
178
+ function setShouldRevert (
179
+ bool sr
180
+ ) external {
163
181
shouldRevert = sr;
164
182
}
165
183
166
184
function clearFallbackCalled () external {
167
185
fallbackCalled = false ;
168
186
}
169
187
170
- fallback (bytes calldata data ) external payable returns (bytes memory ) {
188
+ fallback (
189
+ bytes calldata data
190
+ ) external payable returns (bytes memory ) {
171
191
if (shouldRevert) revert ("fallback reverted " );
172
192
173
193
if (expectedHash == keccak256 (data) && expectedValue == msg .value && address (this ) == msg .sender ) {
@@ -179,6 +199,7 @@ contract EthereumVaultConnectorWithFallback is EthereumVaultConnectorHarness {
179
199
}
180
200
181
201
contract PermitTest is Test {
202
+ address internal constant COMMON_PREDEPLOYS = 0x4200000000000000000000000000000000000000 ;
182
203
EthereumVaultConnectorWithFallback internal evc;
183
204
SignerECDSA internal signerECDSA;
184
205
SignerERC1271 internal signerERC1271;
@@ -215,7 +236,10 @@ contract PermitTest is Test {
215
236
address msgSender = sender == address (0 ) ? address (uint160 (uint256 (keccak256 (abi.encode (alice))))) : sender;
216
237
data = abi.encode (keccak256 (data));
217
238
218
- vm.assume (! evc.haveCommonOwner (alice, address (0 )) && alice != address (evc));
239
+ vm.assume (
240
+ ! evc.haveCommonOwner (alice, address (0 )) && ! evc.haveCommonOwner (alice, COMMON_PREDEPLOYS)
241
+ && alice != address (evc)
242
+ );
219
243
vm.assume (msgSender != address (evc));
220
244
vm.assume (nonce > 0 && nonce < type (uint256 ).max);
221
245
@@ -264,7 +288,7 @@ contract PermitTest is Test {
264
288
data = abi.encode (keccak256 (data));
265
289
266
290
vm.assume (msgSender != address (evc));
267
- vm.assume (! evc.haveCommonOwner (alice, address (0 )));
291
+ vm.assume (! evc.haveCommonOwner (alice, address (0 )) && ! evc. haveCommonOwner (alice, COMMON_PREDEPLOYS) );
268
292
vm.assume (nonce > 0 && nonce < type (uint256 ).max);
269
293
270
294
vm.warp (deadline);
@@ -310,7 +334,10 @@ contract PermitTest is Test {
310
334
&& privateKey < 115792089237316195423570985008687907852837564279074904382605163141518161494337
311
335
);
312
336
address alice = vm.addr (privateKey);
313
- vm.assume (! evc.haveCommonOwner (alice, address (0 )) && alice != address (evc));
337
+ vm.assume (
338
+ ! evc.haveCommonOwner (alice, address (0 )) && ! evc.haveCommonOwner (alice, COMMON_PREDEPLOYS)
339
+ && alice != address (evc)
340
+ );
314
341
bytes19 addressPrefix = evc.getAddressPrefix (alice);
315
342
data2 = abi.encode (keccak256 (data2));
316
343
vm.assume (nonce > 0 && nonce < type (uint256 ).max - 1 );
@@ -351,7 +378,10 @@ contract PermitTest is Test {
351
378
&& privateKey < 115792089237316195423570985008687907852837564279074904382605163141518161494337
352
379
);
353
380
address alice = vm.addr (privateKey);
354
- vm.assume (! evc.haveCommonOwner (alice, address (0 )) && alice != address (evc));
381
+ vm.assume (
382
+ ! evc.haveCommonOwner (alice, address (0 )) && ! evc.haveCommonOwner (alice, COMMON_PREDEPLOYS)
383
+ && alice != address (evc)
384
+ );
355
385
bytes19 addressPrefix = evc.getAddressPrefix (alice);
356
386
data = abi.encode (keccak256 (data));
357
387
vm.assume (sender != address (0 ) && sender != address (this ));
@@ -369,6 +399,7 @@ contract PermitTest is Test {
369
399
}
370
400
371
401
function test_RevertIfSignerInvalid_Permit (
402
+ bool option ,
372
403
address alice ,
373
404
uint256 nonceNamespace ,
374
405
uint256 nonce ,
@@ -377,7 +408,9 @@ contract PermitTest is Test {
377
408
bytes memory data ,
378
409
bytes calldata signature
379
410
) public {
380
- alice = address (uint160 (bound (uint160 (alice), 0 , 0xFF )));
411
+ alice = option
412
+ ? address (uint160 (bound (uint160 (alice), 0 , 0xFF )))
413
+ : address (uint160 (bound (uint160 (alice), uint160 (COMMON_PREDEPLOYS), uint160 (COMMON_PREDEPLOYS) + 0xFF )));
381
414
bytes19 addressPrefix = evc.getAddressPrefix (alice);
382
415
data = abi.encode (keccak256 (data));
383
416
vm.assume (nonce > 0 && nonce < type (uint256 ).max);
@@ -404,7 +437,10 @@ contract PermitTest is Test {
404
437
) public {
405
438
bytes19 addressPrefix = evc.getAddressPrefix (alice);
406
439
data = abi.encode (keccak256 (data));
407
- vm.assume (! evc.haveCommonOwner (alice, address (0 )) && alice != address (evc));
440
+ vm.assume (
441
+ ! evc.haveCommonOwner (alice, address (0 )) && ! evc.haveCommonOwner (alice, COMMON_PREDEPLOYS)
442
+ && alice != address (evc)
443
+ );
408
444
vm.assume (nonce < type (uint256 ).max);
409
445
vm.warp (deadline);
410
446
@@ -436,7 +472,10 @@ contract PermitTest is Test {
436
472
) public {
437
473
bytes19 addressPrefix = evc.getAddressPrefix (alice);
438
474
data = abi.encode (keccak256 (data));
439
- vm.assume (! evc.haveCommonOwner (alice, address (0 )) && alice != address (evc));
475
+ vm.assume (
476
+ ! evc.haveCommonOwner (alice, address (0 )) && ! evc.haveCommonOwner (alice, COMMON_PREDEPLOYS)
477
+ && alice != address (evc)
478
+ );
440
479
vm.assume (nonce > 0 && nonce < type (uint256 ).max);
441
480
vm.assume (deadline < type (uint256 ).max);
442
481
vm.warp (deadline + 1 );
@@ -466,7 +505,10 @@ contract PermitTest is Test {
466
505
address alice = vm.addr (privateKey);
467
506
bytes19 addressPrefix = evc.getAddressPrefix (alice);
468
507
data = abi.encode (keccak256 (data));
469
- vm.assume (! evc.haveCommonOwner (alice, address (0 )) && alice != address (evc));
508
+ vm.assume (
509
+ ! evc.haveCommonOwner (alice, address (0 )) && ! evc.haveCommonOwner (alice, COMMON_PREDEPLOYS)
510
+ && alice != address (evc)
511
+ );
470
512
vm.assume (nonce > 0 && nonce < type (uint256 ).max);
471
513
vm.assume (value > 0 );
472
514
vm.warp (deadline);
@@ -499,7 +541,10 @@ contract PermitTest is Test {
499
541
bytes calldata signature
500
542
) public {
501
543
bytes19 addressPrefix = evc.getAddressPrefix (alice);
502
- vm.assume (! evc.haveCommonOwner (alice, address (0 )) && alice != address (evc));
544
+ vm.assume (
545
+ ! evc.haveCommonOwner (alice, address (0 )) && ! evc.haveCommonOwner (alice, COMMON_PREDEPLOYS)
546
+ && alice != address (evc)
547
+ );
503
548
vm.assume (nonce > 0 && nonce < type (uint256 ).max);
504
549
vm.warp (deadline);
505
550
@@ -531,7 +576,10 @@ contract PermitTest is Test {
531
576
data = abi.encode (keccak256 (data));
532
577
signerECDSA.setPrivateKey (privateKey);
533
578
534
- vm.assume (! evc.haveCommonOwner (alice, address (0 )) && alice != address (evc));
579
+ vm.assume (
580
+ ! evc.haveCommonOwner (alice, address (0 )) && ! evc.haveCommonOwner (alice, COMMON_PREDEPLOYS)
581
+ && alice != address (evc)
582
+ );
535
583
vm.assume (nonce > 0 && nonce < type (uint256 ).max);
536
584
vm.warp (deadline);
537
585
vm.deal (address (evc), value);
@@ -569,7 +617,10 @@ contract PermitTest is Test {
569
617
bytes calldata signature ,
570
618
uint16 value
571
619
) public {
572
- vm.assume (! evc.haveCommonOwner (signer, address (0 )) && signer != address (evc));
620
+ vm.assume (
621
+ ! evc.haveCommonOwner (signer, address (0 )) && ! evc.haveCommonOwner (signer, COMMON_PREDEPLOYS)
622
+ && signer != address (evc)
623
+ );
573
624
vm.assume (nonce > 0 && nonce < type (uint256 ).max);
574
625
575
626
bytes19 addressPrefix = evc.getAddressPrefix (signer);
@@ -597,7 +648,7 @@ contract PermitTest is Test {
597
648
address alice = vm.addr (privateKey);
598
649
signerECDSA.setPrivateKey (privateKey);
599
650
600
- vm.assume (! evc.haveCommonOwner (alice, address (0 )));
651
+ vm.assume (! evc.haveCommonOwner (alice, address (0 )) && ! evc. haveCommonOwner (alice, COMMON_PREDEPLOYS) );
601
652
vm.warp (deadline);
602
653
603
654
// ECDSA signature invalid due to signer.
@@ -695,7 +746,7 @@ contract PermitTest is Test {
695
746
address alice = address (new SignerERC1271 (evc));
696
747
SignerERC1271 (alice).setSignatureHash (signature);
697
748
698
- vm.assume (! evc.haveCommonOwner (alice, address (0 )));
749
+ vm.assume (! evc.haveCommonOwner (alice, address (0 )) && ! evc. haveCommonOwner (alice, COMMON_PREDEPLOYS) );
699
750
vm.warp (deadline);
700
751
701
752
// ECDSA signature is always invalid here hence we fall back to ERC-1271 signature
@@ -776,7 +827,9 @@ contract PermitTest is Test {
776
827
assertTrue (evc.fallbackCalled ());
777
828
}
778
829
779
- function test_Permit (uint256 privateKey ) public {
830
+ function test_Permit (
831
+ uint256 privateKey
832
+ ) public {
780
833
vm.assume (
781
834
privateKey > 0
782
835
&& privateKey < 115792089237316195423570985008687907852837564279074904382605163141518161494337
@@ -785,7 +838,10 @@ contract PermitTest is Test {
785
838
address bob = address (new SignerERC1271 (evc));
786
839
address target = address (new Vault (evc));
787
840
788
- vm.assume (! evc.haveCommonOwner (alice, address (0 )) && ! evc.haveCommonOwner (alice, bob));
841
+ vm.assume (
842
+ ! evc.haveCommonOwner (alice, address (0 )) && ! evc.haveCommonOwner (alice, bob)
843
+ && ! evc.haveCommonOwner (alice, COMMON_PREDEPLOYS)
844
+ );
789
845
vm.deal (address (this ), type (uint128 ).max);
790
846
signerECDSA.setPrivateKey (privateKey);
791
847
@@ -1273,7 +1329,9 @@ contract PermitTest is Test {
1273
1329
assertEq (evc.isAccountOperatorAuthorized (bob, operator), false );
1274
1330
}
1275
1331
1276
- function test_RevertIfInPermit_SetLockdownMode (uint256 privateKey ) public {
1332
+ function test_RevertIfInPermit_SetLockdownMode (
1333
+ uint256 privateKey
1334
+ ) public {
1277
1335
vm.assume (
1278
1336
privateKey > 0
1279
1337
&& privateKey < 115792089237316195423570985008687907852837564279074904382605163141518161494337
@@ -1300,7 +1358,9 @@ contract PermitTest is Test {
1300
1358
evc.permit (alice, address (this ), 0 , 1 , 1 , 0 , data, signature);
1301
1359
}
1302
1360
1303
- function test_RevertIfInPermit_SetPermitDisabledMode (uint256 privateKey ) public {
1361
+ function test_RevertIfInPermit_SetPermitDisabledMode (
1362
+ uint256 privateKey
1363
+ ) public {
1304
1364
vm.assume (
1305
1365
privateKey > 0
1306
1366
&& privateKey < 115792089237316195423570985008687907852837564279074904382605163141518161494337
0 commit comments