diff --git a/contracts/core/BasePaymaster.sol b/contracts/core/BasePaymaster.sol index f8aec9d3..efb8b9cb 100644 --- a/contracts/core/BasePaymaster.sol +++ b/contracts/core/BasePaymaster.sol @@ -8,7 +8,7 @@ import "@openzeppelin/contracts/utils/introspection/IERC165.sol"; import "../interfaces/IPaymaster.sol"; import "../interfaces/IEntryPoint.sol"; import "./Helpers.sol"; - +import "./UserOperationLib.sol"; /** * Helper class for creating a paymaster. * provides helper methods for staking. @@ -17,6 +17,10 @@ import "./Helpers.sol"; abstract contract BasePaymaster is IPaymaster, Ownable { IEntryPoint public immutable entryPoint; + uint256 internal constant PAYMASTER_VALIDATION_GAS_OFFSET = UserOperationLib.PAYMASTER_VALIDATION_GAS_OFFSET; + uint256 internal constant PAYMASTER_POSTOP_GAS_OFFSET = UserOperationLib.PAYMASTER_POSTOP_GAS_OFFSET; + uint256 internal constant PAYMASTER_DATA_OFFSET = UserOperationLib.PAYMASTER_DATA_OFFSET; + constructor(IEntryPoint _entryPoint) Ownable(msg.sender) { _validateEntryPointInterface(_entryPoint); entryPoint = _entryPoint; diff --git a/contracts/samples/LegacyTokenPaymaster.sol b/contracts/samples/LegacyTokenPaymaster.sol index bc962b95..d673aefc 100644 --- a/contracts/samples/LegacyTokenPaymaster.sol +++ b/contracts/samples/LegacyTokenPaymaster.sol @@ -76,7 +76,7 @@ contract LegacyTokenPaymaster is BasePaymaster, ERC20 { // verificationGasLimit is dual-purposed, as gas limit for postOp. make sure it is high enough // make sure that verificationGasLimit is high enough to handle postOp - require(uint128(bytes16(userOp.paymasterAndData[UserOperationLib.PAYMASTER_POSTOP_GAS_OFFSET:UserOperationLib.PAYMASTER_DATA_OFFSET])) > COST_OF_POST, "TokenPaymaster: gas too low for postOp"); + require(uint128(bytes16(userOp.paymasterAndData[PAYMASTER_POSTOP_GAS_OFFSET : PAYMASTER_DATA_OFFSET])) > COST_OF_POST, "TokenPaymaster: gas too low for postOp"); if (userOp.initCode.length != 0) { _validateConstructor(userOp); diff --git a/contracts/samples/TokenPaymaster.sol b/contracts/samples/TokenPaymaster.sol index 2b40c6cc..00238e1e 100644 --- a/contracts/samples/TokenPaymaster.sol +++ b/contracts/samples/TokenPaymaster.sol @@ -121,7 +121,7 @@ contract TokenPaymaster is BasePaymaster, UniswapHelper, OracleHelper { override returns (bytes memory context, uint256 validationResult) {unchecked { uint256 priceMarkup = tokenPaymasterConfig.priceMarkup; - uint256 paymasterAndDataLength = userOp.paymasterAndData.length - UserOperationLib.PAYMASTER_DATA_OFFSET; + uint256 paymasterAndDataLength = userOp.paymasterAndData.length - PAYMASTER_DATA_OFFSET; require(paymasterAndDataLength == 0 || paymasterAndDataLength == 32, "TPM: invalid data length" ); @@ -129,7 +129,7 @@ contract TokenPaymaster is BasePaymaster, UniswapHelper, OracleHelper { // note: as price is in ether-per-token and we want more tokens increasing it means dividing it by markup uint256 cachedPriceWithMarkup = cachedPrice * PRICE_DENOMINATOR / priceMarkup; if (paymasterAndDataLength == 32) { - uint256 clientSuppliedPrice = uint256(bytes32(userOp.paymasterAndData[UserOperationLib.PAYMASTER_DATA_OFFSET : UserOperationLib.PAYMASTER_DATA_OFFSET + 32])); + uint256 clientSuppliedPrice = uint256(bytes32(userOp.paymasterAndData[PAYMASTER_DATA_OFFSET : PAYMASTER_DATA_OFFSET + 32])); if (clientSuppliedPrice < cachedPriceWithMarkup) { // note: smaller number means 'more ether per token' cachedPriceWithMarkup = clientSuppliedPrice; diff --git a/contracts/samples/VerifyingPaymaster.sol b/contracts/samples/VerifyingPaymaster.sol index 8bad94c8..6fb13ccc 100644 --- a/contracts/samples/VerifyingPaymaster.sol +++ b/contracts/samples/VerifyingPaymaster.sol @@ -23,7 +23,7 @@ contract VerifyingPaymaster is BasePaymaster { address public immutable verifyingSigner; - uint256 private constant VALID_TIMESTAMP_OFFSET = UserOperationLib.PAYMASTER_DATA_OFFSET; + uint256 private constant VALID_TIMESTAMP_OFFSET = PAYMASTER_DATA_OFFSET; uint256 private constant SIGNATURE_OFFSET = VALID_TIMESTAMP_OFFSET + 64; @@ -50,7 +50,7 @@ contract VerifyingPaymaster is BasePaymaster { keccak256(userOp.initCode), keccak256(userOp.callData), userOp.accountGasLimits, - uint256(bytes32(userOp.paymasterAndData[20 : 52])), + uint256(bytes32(userOp.paymasterAndData[PAYMASTER_VALIDATION_GAS_OFFSET : PAYMASTER_DATA_OFFSET])), userOp.preVerificationGas, userOp.maxFeePerGas, userOp.maxPriorityFeePerGas, diff --git a/contracts/test/TestExpirePaymaster.sol b/contracts/test/TestExpirePaymaster.sol index de7a374e..a92e3ff2 100644 --- a/contracts/test/TestExpirePaymaster.sol +++ b/contracts/test/TestExpirePaymaster.sol @@ -16,7 +16,7 @@ contract TestExpirePaymaster is BasePaymaster { internal virtual override view returns (bytes memory context, uint256 validationData) { (userOp, userOpHash, maxCost); - (uint48 validAfter, uint48 validUntil) = abi.decode(userOp.paymasterAndData[UserOperationLib.PAYMASTER_DATA_OFFSET :], (uint48, uint48)); + (uint48 validAfter, uint48 validUntil) = abi.decode(userOp.paymasterAndData[PAYMASTER_DATA_OFFSET :], (uint48, uint48)); validationData = _packValidationData(false, validUntil, validAfter); context = ""; } diff --git a/reports/gas-checker.txt b/reports/gas-checker.txt index 2b3b6a5f..2af08a79 100644 --- a/reports/gas-checker.txt +++ b/reports/gas-checker.txt @@ -22,11 +22,11 @@ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ ║ simple paymaster │ 1 │ 89079 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple paymaster with diff │ 2 │ │ 43963 │ 14984 ║ +║ simple paymaster with diff │ 2 │ │ 43987 │ 15008 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple paymaster │ 10 │ 485071 │ │ ║ +║ simple paymaster │ 10 │ 485083 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ simple paymaster with diff │ 11 │ │ 44017 │ 15038 ║ +║ simple paymaster with diff │ 11 │ │ 44005 │ 15026 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ ║ big tx 5k │ 1 │ 183735 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ @@ -36,11 +36,11 @@ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ ║ big tx - diff from previous │ 11 │ │ 145440 │ 20216 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp │ 1 │ 90907 │ │ ║ +║ paymaster+postOp │ 1 │ 90895 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp with diff │ 2 │ │ 45814 │ 16835 ║ +║ paymaster+postOp with diff │ 2 │ │ 45850 │ 16871 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ paymaster+postOp │ 10 │ 503383 │ │ ║ +║ paymaster+postOp │ 10 │ 503503 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ ║ paymaster+postOp with diff │ 11 │ │ 45851 │ 16872 ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ @@ -50,6 +50,6 @@ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ ║ token paymaster │ 10 │ 816150 │ │ ║ ╟────────────────────────────────┼───────┼───────────────┼────────────────┼─────────────────────╢ -║ token paymaster with diff │ 11 │ │ 74094 │ 45115 ║ +║ token paymaster with diff │ 11 │ │ 74106 │ 45127 ║ ╚════════════════════════════════╧═══════╧═══════════════╧════════════════╧═════════════════════╝