Skip to content

Commit

Permalink
feat:revert unaccounted gas caching and passing in context
Browse files Browse the repository at this point in the history
  • Loading branch information
livingrockrises committed Oct 11, 2024
1 parent c3efddc commit ca4515e
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions contracts/sponsorship/BiconomySponsorshipPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ contract BiconomySponsorshipPaymaster is
override
{
unchecked {
(address paymasterId, uint32 priceMarkup, bytes32 userOpHash, uint256 prechargedAmount, uint256 unaccountedGasCatched) =
abi.decode(context, (address, uint32, bytes32, uint256, uint256));
(address paymasterId, uint32 priceMarkup, bytes32 userOpHash, uint256 prechargedAmount) =
abi.decode(context, (address, uint32, bytes32, uint256));

// Include unaccountedGas since EP doesn't include this in actualGasCost
// unaccountedGas = postOpGas + EP overhead gas + estimated penalty
actualGasCost = actualGasCost + (unaccountedGasCatched * actualUserOpFeePerGas);
actualGasCost = actualGasCost + (unaccountedGas * actualUserOpFeePerGas);
// Apply the price markup
uint256 adjustedGasCost = (actualGasCost * priceMarkup) / PRICE_DENOMINATOR;

Expand Down Expand Up @@ -314,11 +314,7 @@ contract BiconomySponsorshipPaymaster is
revert InvalidSignatureLength();
}

// Note: may not need to cache and forward in the context
uint256 unaccountedGasCatched = unaccountedGas;


if(unaccountedGasCatched >= userOp.unpackPostOpGasLimit()) {
if(unaccountedGas >= userOp.unpackPostOpGasLimit()) {
revert PostOpGasLimitTooLow();
}

Expand All @@ -335,15 +331,15 @@ contract BiconomySponsorshipPaymaster is
}

// Deduct the max gas cost.
uint256 effectiveCost = (requiredPreFund + unaccountedGasCatched * userOp.unpackMaxFeePerGas()) * priceMarkup / PRICE_DENOMINATOR;
uint256 effectiveCost = (requiredPreFund + unaccountedGas * userOp.unpackMaxFeePerGas()) * priceMarkup / PRICE_DENOMINATOR;

if (effectiveCost > paymasterIdBalances[paymasterId]) {
revert InsufficientFundsForPaymasterId();
}

paymasterIdBalances[paymasterId] -= effectiveCost;

context = abi.encode(paymasterId, priceMarkup, userOpHash, effectiveCost, unaccountedGasCatched);
context = abi.encode(paymasterId, priceMarkup, userOpHash, effectiveCost);

//no need for other on-chain validation: entire UserOp should have been checked
// by the external service prior to signing it.
Expand Down

0 comments on commit ca4515e

Please sign in to comment.