@@ -3,7 +3,6 @@ pragma solidity 0.8.24;
3
3
4
4
import {EntryPoint, IEntryPoint, PackedUserOperation, UserOperationLib} from "account-abstraction/core/EntryPoint.sol " ;
5
5
import {Vm} from "forge-std/Vm.sol " ;
6
- import {ECDSA} from "solady/utils/ECDSA.sol " ;
7
6
import {Ownable} from "solady/auth/Ownable.sol " ;
8
7
9
8
import {BaseTest} from "./BaseTest.t.sol " ;
@@ -15,7 +14,6 @@ import {MockUserOpPrecheck} from "./mocks/MockUserOpPrecheck.sol";
15
14
16
15
contract PaymasterTest is BaseTest , MockEndpoint {
17
16
using UserOperationLib for PackedUserOperation;
18
- using ECDSA for bytes32 ;
19
17
20
18
IEntryPoint entryPoint;
21
19
MockAccount mockAccount;
@@ -317,7 +315,7 @@ contract PaymasterTest is BaseTest, MockEndpoint {
317
315
fundAccount (signer.addr, amount)
318
316
fundPaymaster (signer.addr, amount)
319
317
{
320
- PackedUserOperation[] memory userOps = _generateUserOps (signer.privateKey, amount, address (0 ), 0 );
318
+ PackedUserOperation[] memory userOps = _generateUserOps (amount, address (0 ), 0 );
321
319
uint256 maxCost = this .calculateMaxCost (userOps[0 ]);
322
320
323
321
_deposit (amount);
@@ -332,6 +330,7 @@ contract PaymasterTest is BaseTest, MockEndpoint {
332
330
abi.encodeWithSelector (Paymaster.InsufficientMagicSpendBalance.selector , signer.addr, 0 , amount)
333
331
)
334
332
);
333
+ vm.prank (signer.addr, signer.addr);
335
334
entryPoint.handleOps (userOps, payable (BUNDLER));
336
335
}
337
336
@@ -340,7 +339,7 @@ contract PaymasterTest is BaseTest, MockEndpoint {
340
339
fundAccount (signer.addr, amount)
341
340
fundPaymaster (signer.addr, amount)
342
341
{
343
- PackedUserOperation[] memory userOps = _generateUserOps (otherSigner.privateKey, amount, address (0 ), 0 );
342
+ PackedUserOperation[] memory userOps = _generateUserOps (amount, address (0 ), 0 );
344
343
uint256 maxCost = this .calculateMaxCost (userOps[0 ]);
345
344
346
345
vm.assume (maxCost <= amount && amount <= type (uint256 ).max - maxCost);
@@ -355,22 +354,24 @@ contract PaymasterTest is BaseTest, MockEndpoint {
355
354
abi.encodeWithSelector (Paymaster.InsufficientGasBalance.selector , otherSigner.addr, 0 , maxCost)
356
355
)
357
356
);
357
+ vm.prank (otherSigner.addr, otherSigner.addr);
358
358
entryPoint.handleOps (userOps, payable (BUNDLER));
359
359
}
360
360
361
361
function test_validatePaymasterUserOp_revertsIfFulfillerHasInsufficientGasBalanceOnSecondTry (
362
362
uint256 amount ,
363
363
uint256 ethAmount
364
364
) public fundAccount (signer.addr, amount) fundPaymaster (signer.addr, amount) {
365
- PackedUserOperation[] memory userOps = _generateUserOps (signer.privateKey, ethAmount, address (0 ), 0 );
365
+ PackedUserOperation[] memory userOps = _generateUserOps (ethAmount, address (0 ), 0 );
366
366
uint256 maxCost = this .calculateMaxCost (userOps[0 ]);
367
367
368
368
vm.assume (ethAmount < type (uint256 ).max - maxCost * 2 && ethAmount + maxCost * 2 < amount);
369
369
_deposit (maxCost);
370
370
371
+ vm.prank (signer.addr, signer.addr);
371
372
entryPoint.handleOps (userOps, payable (BUNDLER));
372
373
373
- userOps = _generateUserOps (otherSigner.privateKey, ethAmount, address (0 ), 1 );
374
+ userOps = _generateUserOps (ethAmount, address (0 ), 1 );
374
375
maxCost = this .calculateMaxCost (userOps[0 ]);
375
376
_deposit (maxCost);
376
377
@@ -382,6 +383,7 @@ contract PaymasterTest is BaseTest, MockEndpoint {
382
383
abi.encodeWithSelector (Paymaster.InsufficientGasBalance.selector , otherSigner.addr, 0 , maxCost)
383
384
)
384
385
);
386
+ vm.prank (otherSigner.addr, otherSigner.addr);
385
387
entryPoint.handleOps (userOps, payable (BUNDLER));
386
388
}
387
389
@@ -391,12 +393,13 @@ contract PaymasterTest is BaseTest, MockEndpoint {
391
393
fundPaymaster (signer.addr, amount)
392
394
{
393
395
assertEq (paymaster.getGasBalance (signer.addr), address (entryPoint).balance);
394
- PackedUserOperation[] memory userOps = _generateUserOps (signer.privateKey, ethAmount, address (0 ), 0 );
396
+ PackedUserOperation[] memory userOps = _generateUserOps (ethAmount, address (0 ), 0 );
395
397
uint256 maxCost = this .calculateMaxCost (userOps[0 ]);
396
398
397
399
vm.assume (ethAmount < type (uint256 ).max - maxCost && ethAmount + maxCost < amount);
398
400
_deposit (maxCost);
399
401
402
+ vm.prank (signer.addr, signer.addr);
400
403
entryPoint.handleOps (userOps, payable (BUNDLER));
401
404
402
405
assertEq (paymaster.getGasBalance (signer.addr), address (entryPoint).balance);
@@ -409,13 +412,14 @@ contract PaymasterTest is BaseTest, MockEndpoint {
409
412
{
410
413
vm.assume (ethAmount > 0 );
411
414
412
- PackedUserOperation[] memory userOps = _generateUserOps (signer.privateKey, ethAmount, precheckAddress, 0 );
415
+ PackedUserOperation[] memory userOps = _generateUserOps (ethAmount, precheckAddress, 0 );
413
416
uint256 maxCost = this .calculateMaxCost (userOps[0 ]);
414
417
415
418
vm.assume (ethAmount < type (uint256 ).max - maxCost && ethAmount + maxCost < amount);
416
419
_deposit (maxCost);
417
420
418
421
vm.expectRevert (abi.encodeWithSelector (IEntryPoint.FailedOpWithRevert.selector , 0 , "AA33 reverted " , "" ));
422
+ vm.prank (signer.addr, signer.addr);
419
423
entryPoint.handleOps (userOps, payable (BUNDLER));
420
424
}
421
425
@@ -426,12 +430,13 @@ contract PaymasterTest is BaseTest, MockEndpoint {
426
430
{
427
431
vm.assume (ethAmount > 0 );
428
432
429
- PackedUserOperation[] memory userOps = _generateUserOps (signer.privateKey, ethAmount, address (0 ), 0 );
433
+ PackedUserOperation[] memory userOps = _generateUserOps (ethAmount, address (0 ), 0 );
430
434
uint256 maxCost = this .calculateMaxCost (userOps[0 ]);
431
435
432
436
vm.assume (ethAmount < type (uint256 ).max - maxCost && ethAmount + maxCost < amount);
433
437
_deposit (maxCost);
434
438
439
+ vm.prank (signer.addr, signer.addr);
435
440
entryPoint.handleOps (userOps, payable (BUNDLER));
436
441
437
442
assertEq (paymaster.requestHash (), entryPoint.getUserOpHash (userOps[0 ]));
@@ -444,12 +449,13 @@ contract PaymasterTest is BaseTest, MockEndpoint {
444
449
fundPaymaster (signer.addr, amount)
445
450
{
446
451
uint256 ethAmount = 0 ;
447
- PackedUserOperation[] memory userOps = _generateUserOps (signer.privateKey, ethAmount, address (0 ), 0 );
452
+ PackedUserOperation[] memory userOps = _generateUserOps (ethAmount, address (0 ), 0 );
448
453
uint256 maxCost = this .calculateMaxCost (userOps[0 ]);
449
454
450
455
vm.assume (ethAmount < type (uint256 ).max - maxCost && ethAmount + maxCost < amount);
451
456
_deposit (maxCost);
452
457
458
+ vm.prank (signer.addr, signer.addr);
453
459
entryPoint.handleOps (userOps, payable (BUNDLER));
454
460
455
461
assertEq (paymaster.requestHash (), bytes32 (0 ));
@@ -463,19 +469,20 @@ contract PaymasterTest is BaseTest, MockEndpoint {
463
469
{
464
470
vm.assume (ethAmount > 0 );
465
471
466
- PackedUserOperation[] memory userOps = _generateUserOps (signer.privateKey, ethAmount, address (0 ), 0 );
472
+ PackedUserOperation[] memory userOps = _generateUserOps (ethAmount, address (0 ), 0 );
467
473
uint256 maxCost = this .calculateMaxCost (userOps[0 ]);
468
474
469
475
vm.assume (ethAmount < type (uint256 ).max - maxCost && ethAmount + maxCost < amount);
470
476
_deposit (maxCost);
471
477
uint256 initialBalance = paymaster.getMagicSpendBalance (signer.addr);
472
478
479
+ vm.prank (signer.addr, signer.addr);
473
480
entryPoint.handleOps (userOps, payable (BUNDLER));
474
481
475
482
assertEq (paymaster.getMagicSpendBalance (signer.addr), initialBalance - ethAmount);
476
483
}
477
484
478
- function _generateUserOps (uint256 signerKey , uint256 ethAmount , address precheck , uint256 nonce )
485
+ function _generateUserOps (uint256 ethAmount , address precheck , uint256 nonce )
479
486
private
480
487
view
481
488
returns (PackedUserOperation[] memory )
@@ -489,27 +496,14 @@ contract PaymasterTest is BaseTest, MockEndpoint {
489
496
accountGasLimits: bytes32 (abi.encodePacked (uint128 (1000000 ), uint128 (1000000 ))),
490
497
preVerificationGas: 100000 ,
491
498
gasFees: bytes32 (abi.encodePacked (uint128 (1000000 ), uint128 (1000000 ))),
492
- paymasterAndData: "" ,
499
+ paymasterAndData: _encodePaymasterAndData (ethAmount, precheck) ,
493
500
signature: abi.encode (0 )
494
501
});
495
- (uint8 v , bytes32 r , bytes32 s ) = vm.sign (signerKey, _genDigest (userOps[0 ], ethAmount).toEthSignedMessageHash ());
496
- userOps[0 ].paymasterAndData = _encodePaymasterAndData (abi.encodePacked (r, s, v), ethAmount, precheck);
497
502
return userOps;
498
503
}
499
504
500
- function _encodePaymasterAndData (bytes memory signature , uint256 ethAmount , address precheck )
501
- private
502
- view
503
- returns (bytes memory )
504
- {
505
- return abi.encodePacked (
506
- address (paymaster), uint128 (1000000 ), uint128 (1000000 ), abi.encode (ethAmount, signature, precheck)
507
- );
508
- }
509
-
510
- function _genDigest (PackedUserOperation memory userOp , uint256 ethAmount ) private view returns (bytes32 ) {
511
- uint256 dstChainId = block .chainid ;
512
- return keccak256 (abi.encode (userOp.sender, userOp.nonce, userOp.callData, ethAmount, dstChainId));
505
+ function _encodePaymasterAndData (uint256 ethAmount , address precheck ) private view returns (bytes memory ) {
506
+ return abi.encodePacked (address (paymaster), uint128 (1000000 ), uint128 (1000000 ), abi.encode (ethAmount, precheck));
513
507
}
514
508
515
509
function calculateMaxCost (PackedUserOperation calldata userOp ) public view returns (uint256 ) {
0 commit comments