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

AA-430: Provide detailed gas usage breakdown in 'postOp' #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions contracts/interfaces/IRip7560Paymaster.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.23;

/**
* @title UsedGasBreakdown
* @dev The detailed breakdown of where the gas in the transaction was consumed.
* @dev This data is provided to the Paymaster contract in the 'postPaymasterTransaction' frame.
* @notice Gas used during 'postPaymasterTransaction' cannot be known ahead of time and may need to be guesstimated.
*/
struct UsedGasBreakdown {
uint256 preTransactionGasUsed;
uint256 accountDeploymentGasUsed;
uint256 accountValidationGasUsed;
uint256 paymasterValidationGasUsed;
uint256 executionGasUsed;
uint256 executionUnusedPenaltyGas;
}

/**
* @dev Calculate ETH gas cost of a transaction using the provided gas usage info plus an estimate for 'postOpGasUsed'.
* @param usedGasBreakdown - the actual gas cost of each completed frame of the transaction.
* @param postOpGasUsed - the best-effort estimation of the amount of gas consumed by the 'postPaymasterTransaction'.
* @notice 'postPaymasterTransaction' may be penalized for unused gas and this should be included in 'postOpGasUsed'.
*/
function calculateActualGasCost(
UsedGasBreakdown calldata usedGasBreakdown,
uint256 postOpGasUsed
) returns (uint256){
uint256 actualGas = postOpGasUsed +
usedGasBreakdown.preTransactionGasUsed +
usedGasBreakdown.accountDeploymentGasUsed +
usedGasBreakdown.accountValidationGasUsed +
usedGasBreakdown.paymasterValidationGasUsed +
usedGasBreakdown.executionGasUsed +
usedGasBreakdown.executionUnusedPenaltyGas;
return actualGas * tx.gasprice;
}

/**
* @title IRip7560Paymaster
* @dev Interface for the paymaster contract.
Expand All @@ -23,18 +58,18 @@ interface IRip7560Paymaster {


/**
* paymaster post transaction function.
* This method is called after the transaction has been executed - if the validation function returned a context
* @dev revert in this method will cause the account execution function to revert too
* (but the reverted transaction will still get on-chain and be paid for)
* @param success - true if the transaction was successful, false otherwise
* @param actualGasCost - the actual gas cost of the transaction
* @dev The paymaster's post-transaction callback function.
* @dev This method is called after the transaction has been executed if the validation function returned a context.
* @dev Revert in this method will cause the account execution function to revert too.
* @dev Notice that unlike an invalid transaction, the reverted transaction will still get on-chain and be paid for.
* @param success - true if the transaction execution was successful, false otherwise
* @param context - context data returned by validatePaymasterTransaction
* @param usedGasBreakdown - the actual gas cost of each completed frame of the transaction
*/
function postPaymasterTransaction(
bool success,
uint256 actualGasCost,
bytes calldata context
bytes calldata context,
UsedGasBreakdown calldata usedGasBreakdown
) external;

}
Loading