Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/chainlight 006 Unused Gas Penalty #26

Merged
merged 5 commits into from
Oct 18, 2024

Conversation

filmakarov
Copy link
Collaborator

Fix this.

-SponsorshipPaymaster now charges maxPenalty = (mUserOp.callGasLimit + mUserOp.paymasterPostOpGasLimit) * 10 / 100 * maxFeePerGas at _validatePaymasterUserOp.

  • SponsorshipPaymaster now emits the actual gas cost (A+U) before applying it's own fee. This value can be used on the backend to calculate the refund , which is needed to be executed to paymasterId in regards of the difference b/w maxPenalty and actual penalty.
  • Refund would be calculated in a following way:

let's define the EP.actualGasCost emitted here as EPAGC.

Then EPAGC = A + P + actualPenalty, where A is actualGasCost passed to Paymaster.postOp here.
P is component brought by preGas - gasleft() from here , which you reference above as postOpCost I believe.
actualPenalty is the component added here

The amount deducted by Paymaster (leaving Paymaster premium coming from priceMarkup aside) is
PC = A + U + MaxPenalty.
Where U is (unaccountedGasCatched * actualUserOpFeePerGas) from here
And maxPenalty is as discussed above.

Assuming MaxPenalty >= actualPenalty && U >= P is true for all maxPenalty, actualPenalty, U, P

on backend we do amountToRefund = PC - EPAGC = (U - P) + (MaxPenalty - actualPenalty) which will reflect the exact amount overcharged by Paymaster.

  • We do not account for Q = priceMarkup / _PRICE_DENOMINATOR when calculating the refund.
    EP emits AGC w/o Q, Paymaster also emits it's gas cost (A+U) before applying Q.

@@ -337,9 +338,15 @@ contract BiconomySponsorshipPaymaster is
revert InvalidPriceMarkup();
}

// callGasLimit + paymasterPostOpGas
uint256 maxPenalty = (
uint128(uint256(userOp.accountGasLimits)) +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will take lower 128?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@livingrockrises
Copy link
Contributor

What does the backend service do then with this event?

@livingrockrises livingrockrises merged commit 6c81989 into develop Oct 18, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants