Skip to content

Commit 065fe40

Browse files
committed
Add overhead for postOp gas
1 parent 6cbd97e commit 065fe40

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/LimitingPaymaster.sol

+16-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
1919
contract LimitingPaymaster is BasePaymaster {
2020
using UserOperationLib for UserOperation;
2121

22+
uint256 public constant newSenderPostOpOverhead = 23231;
23+
uint256 public constant oldSenderPostOpOverhead = 6143;
24+
2225
address public immutable verifyingSigner;
2326

2427
mapping (uint32 => uint96) public spent;
@@ -89,16 +92,22 @@ contract LimitingPaymaster is BasePaymaster {
8992

9093
// no need for other on-chain validation: entire UserOp should have been checked
9194
// by the external service prior to signing it.
92-
return (abi.encode(spentKey, allowAnyBundler), _packValidationData(false, validUntil, validAfter));
95+
return (_packContextData(userOp, spentKey, allowAnyBundler), _packValidationData(false, validUntil, validAfter));
96+
}
97+
98+
function _packContextData(UserOperation calldata userOp, uint32 spentKey, bool allowAnyBundler) internal pure returns (bytes memory) {
99+
return abi.encode(userOp.maxFeePerGas, userOp.maxPriorityFeePerGas, spentKey, allowAnyBundler);
93100
}
94101

95102
function _postOp(PostOpMode mode, bytes calldata context, uint256 actualGasCost) internal override {
96-
(uint32 spentKey, bool allowAnyBundler) = abi.decode(context, (uint32, bool));
103+
(uint256 maxFeePerGas, uint256 maxPriorityFeePerGas, uint32 spentKey, bool allowAnyBundler) = abi.decode(context, (uint256, uint256, uint32, bool));
97104
// unfortunately tx.origin is not allowed in validation, so we check here
98105
require(allowAnyBundler || bundlerAllowed[tx.origin], "Paymaster: bundler not allowed");
99106

100107
if (mode != PostOpMode.postOpReverted) {
101-
spent[spentKey] += uint96(actualGasCost);
108+
uint256 overhead = spent[spentKey] == 0 ? newSenderPostOpOverhead : oldSenderPostOpOverhead;
109+
uint256 gasPrice = min(maxFeePerGas, maxPriorityFeePerGas + block.basefee);
110+
spent[spentKey] += uint96(actualGasCost + overhead*gasPrice);
102111
}
103112
}
104113

@@ -130,6 +139,10 @@ contract LimitingPaymaster is BasePaymaster {
130139
bundlerAllowed[bundler] = false;
131140
}
132141

142+
function min(uint256 a, uint256 b) internal pure returns (uint256) {
143+
return a < b ? a : b;
144+
}
145+
133146
receive() external payable {
134147
// use address(this).balance rather than msg.value in case of force-send
135148
(bool callSuccess, ) = payable(address(entryPoint)).call{value: address(this).balance}("");

0 commit comments

Comments
 (0)