-
Notifications
You must be signed in to change notification settings - Fork 670
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
AA-217: Charge a penalty payment for unused execution gas limit of a UserOp #356
Conversation
Makes comments and formatting consistent
fix EntryPoint revert if 'postOp' reverts with short revert reason
…on into remove_second_postop_retry
contracts/core/EntryPoint.sol
Outdated
@@ -19,6 +19,8 @@ import "./UserOperationLib.sol"; | |||
import "@openzeppelin/contracts/utils/introspection/ERC165.sol" as OpenZeppelin; | |||
import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; | |||
|
|||
import "hardhat/console.sol"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think you forgot the console.log
if (context.length > 0){ | ||
executionGasLimit += mUserOp.verificationGasLimit; | ||
} | ||
uint256 executionGasUsed = actualGas - opInfo.preOpGas; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
return | ||
} | ||
const iterations = 10 | ||
const count = await counter.populateTransaction.gasWaster(iterations, '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that a good estimate to the callGasUsed is
estimateGas({from:entryPoint, to: account.address, data: op1.callData})
if (context.length > 0){ | ||
executionGasLimit += mUserOp.verificationGasLimit; | ||
} | ||
uint256 executionGasUsed = actualGas - opInfo.preOpGas; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
uint256 executionGasLimit = mUserOp.callGasLimit + mUserOp.paymasterPostOpGasLimit;
uint256 executionGasUsed = actualGas - opInfo.preOpGas;
// this check is required for the gas used within EntryPoint and not covered by explicit gas limits
if (executionGasLimit > executionGasUsed) {
uint256 unusedGas = executionGasLimit - executionGasUsed;
uint256 unusedGasPenalty = (unusedGas * PENALTY_PERCENT) / 100;
actualGas += unusedGasPenalty;
} 'Charging a penalty fee for unused execution gas limit of a UserOp' is good! but in the implemented code, it uses 10% and callGasLimit. I'm thinking whether it would be more reasonable to increase the 10% because it includes Using methods like eth_estimateGas to estimate the calldata gasLimit may not match the actual execution gasLimit. From my understanding, some ETH clients estimate gas fees in a more resource-efficient way, leading to an underestimation of the gas fee needed (especially in complex nested contracts with create/create2). This is one reason why many DApps fix a gas fee for certain operations. Here's a list of projects on GitHub that use fixed gas fees: Additionally, the issue of inaccurate gas fee estimation is not limited to ETH clients but also influenced by contract logic and the current storage state. For example, many slots in smart contracts may or may not be initialized, and the length of dynamic linked lists greatly affects gas fee estimation. For example, during the execution of a smart contract where a linked list is looped through, if the list is periodically reset, the gas fee estimated for a length of 10 might be 50k, but when a user submits the transaction, the gas needed might only be 30k due to the list being reset. Here are some related resources: Overcoming Gas Estimation Challenges MetaMask Incorrectly Estimates 100,000 Gas for ERC20 Transfer From a (I may not have organized the information very clearly, but I believe my ideas are expressed clearly.) Wating for response ^^ |
The penalty for unused gaslimit was selected as a balance between a mechanism to prevent large unused gas blocks within a bundle, and overcharging a user that added a "cushion" to compensate for possible gas usage fluctuations. |
After a call, the EntryPoint refunds the account's deposit with the excess gas cost that was pre-charged.
A penalty of
10%
(UNUSED_GAS_PENALTY_PERCENT
) is applied on the amount of gas that is refunded.This penalty is necessary to prevent the UserOps from reserving large parts of the gas space in the bundle but leaving it unused and preventing the bundler from including other UserOperations.