@@ -10,7 +10,7 @@ import { TWProxy } from "contracts/infra/TWProxy.sol";
10
10
11
11
// Target
12
12
import { IAccountPermissions } from "contracts/extension/interface/IAccountPermissions.sol " ;
13
- import { AccountFactory, Account } from "contracts/prebuilts/account/non-upgradeable/AccountFactory.sol " ;
13
+ import { AccountFactory, Account as SimpleAccount } from "contracts/prebuilts/account/non-upgradeable/AccountFactory.sol " ;
14
14
15
15
library GPv2EIP1271 {
16
16
bytes4 internal constant MAGICVALUE = 0x1626ba7e ;
@@ -253,6 +253,8 @@ contract SimpleAccountVulnPOCTest is BaseTest {
253
253
/*//////////////////////////////////////////////////////////
254
254
Setup
255
255
//////////////////////////////////////////////////////////////*/
256
+ address account = accountFactory.getAddress (accountAdmin, bytes ("" ));
257
+
256
258
address [] memory approvedTargets = new address [](1 );
257
259
approvedTargets[0 ] = address (0x123 ); // allowing accountSigner permissions for some random contract, consider it as 0 address here
258
260
@@ -270,7 +272,6 @@ contract SimpleAccountVulnPOCTest is BaseTest {
270
272
271
273
vm.prank (accountAdmin);
272
274
bytes memory sig = _signSignerPermissionRequest (permissionsReq);
273
- address account = accountFactory.getAddress (accountAdmin, bytes ("" ));
274
275
IAccountPermissions (payable (account)).setPermissionsForSigner (permissionsReq, sig);
275
276
276
277
// As expected, Account Signer is not be able to call setNum on numberContract since it doesnt have numberContract as approved target
@@ -292,14 +293,40 @@ contract SimpleAccountVulnPOCTest is BaseTest {
292
293
Attack
293
294
//////////////////////////////////////////////////////////////*/
294
295
295
- //However they can bypass this by using signature verification on number contract instead
296
+ // However they can bypass this by using signature verification on number contract instead
296
297
vm.prank (accountSigner);
297
298
bytes32 digest = keccak256 (abi.encode (42 ));
298
- (uint8 v , bytes32 r , bytes32 s ) = vm.sign (accountSignerPKey, digest);
299
+ bytes32 toSign = SimpleAccount (payable (account)).getMessageHash (abi.encode (digest));
300
+ (uint8 v , bytes32 r , bytes32 s ) = vm.sign (accountSignerPKey, toSign);
299
301
bytes memory signature = abi.encodePacked (r, s, v);
300
302
301
303
vm.expectRevert ("Account: caller not approved target. " );
302
304
numberContract.setNumBySignature (account, 42 , signature);
303
305
assertEq (numberContract.num (), 0 );
306
+
307
+ // Signer can perform transaction if target is approved.
308
+ address [] memory newApprovedTargets = new address [](2 );
309
+ newApprovedTargets[0 ] = address (0x123 ); // allowing accountSigner permissions for some random contract, consider it as 0 address here
310
+ newApprovedTargets[1 ] = address (numberContract);
311
+
312
+ IAccountPermissions.SignerPermissionRequest memory updatedPermissionsReq = IAccountPermissions
313
+ .SignerPermissionRequest (
314
+ accountSigner,
315
+ 0 ,
316
+ newApprovedTargets,
317
+ 1 ether,
318
+ 0 ,
319
+ type (uint128 ).max,
320
+ 0 ,
321
+ type (uint128 ).max,
322
+ bytes32 ("another UID " )
323
+ );
324
+
325
+ vm.prank (accountAdmin);
326
+ bytes memory sig2 = _signSignerPermissionRequest (updatedPermissionsReq);
327
+ IAccountPermissions (payable (account)).setPermissionsForSigner (updatedPermissionsReq, sig2);
328
+
329
+ numberContract.setNumBySignature (account, 42 , signature);
330
+ assertEq (numberContract.num (), 42 );
304
331
}
305
332
}
0 commit comments