|
| 1 | +/** |
| 2 | + * Account-Abstraction (EIP-4337) singleton EntryPoint implementation. |
| 3 | + * Only one instance required on each chain. |
| 4 | + * |
| 5 | + */ |
| 6 | +// SPDX-License-Identifier: MIT |
| 7 | +pragma solidity ^0.8.28; |
| 8 | + |
| 9 | +/* solhint-disable avoid-low-level-calls */ |
| 10 | +/* solhint-disable no-inline-assembly */ |
| 11 | +/* solhint-disable reason-string */ |
| 12 | + |
| 13 | +import "account-abstraction-v8/interfaces/PackedUserOperation.sol"; |
| 14 | +import "account-abstraction-v8/interfaces/IStakeManager.sol"; |
| 15 | +import "account-abstraction-v8/interfaces/IAggregator.sol"; |
| 16 | +import "account-abstraction-v8/interfaces/INonceManager.sol"; |
| 17 | +import "account-abstraction-v8/interfaces/ISenderCreator.sol"; |
| 18 | + |
| 19 | +interface IEntryPoint is IStakeManager, INonceManager { |
| 20 | + /** |
| 21 | + * |
| 22 | + * An event emitted after each successful request. |
| 23 | + * @param userOpHash - Unique identifier for the request (hash its entire content, except signature). |
| 24 | + * @param sender - The account that generates this request. |
| 25 | + * @param paymaster - If non-null, the paymaster that pays for this request. |
| 26 | + * @param nonce - The nonce value from the request. |
| 27 | + * @param success - True if the sender transaction succeeded, false if reverted. |
| 28 | + * @param actualGasCost - Actual amount paid (by account or paymaster) for this UserOperation. |
| 29 | + * @param actualGasUsed - Total gas used by this UserOperation (including preVerification, creation, |
| 30 | + * validation and execution). |
| 31 | + */ |
| 32 | + event UserOperationEvent( |
| 33 | + bytes32 indexed userOpHash, |
| 34 | + address indexed sender, |
| 35 | + address indexed paymaster, |
| 36 | + uint256 nonce, |
| 37 | + bool success, |
| 38 | + uint256 actualGasCost, |
| 39 | + uint256 actualGasUsed |
| 40 | + ); |
| 41 | + |
| 42 | + /** |
| 43 | + * Account "sender" was deployed. |
| 44 | + * @param userOpHash - The userOp that deployed this account. UserOperationEvent will follow. |
| 45 | + * @param sender - The account that is deployed |
| 46 | + * @param factory - The factory used to deploy this account (in the initCode) |
| 47 | + * @param paymaster - The paymaster used by this UserOp |
| 48 | + */ |
| 49 | + event AccountDeployed(bytes32 indexed userOpHash, address indexed sender, address factory, address paymaster); |
| 50 | + |
| 51 | + /** |
| 52 | + * An event emitted if the UserOperation "callData" reverted with non-zero length. |
| 53 | + * @param userOpHash - The request unique identifier. |
| 54 | + * @param sender - The sender of this request. |
| 55 | + * @param nonce - The nonce used in the request. |
| 56 | + * @param revertReason - The return bytes from the reverted "callData" call. |
| 57 | + */ |
| 58 | + event UserOperationRevertReason( |
| 59 | + bytes32 indexed userOpHash, address indexed sender, uint256 nonce, bytes revertReason |
| 60 | + ); |
| 61 | + |
| 62 | + /** |
| 63 | + * An event emitted if the UserOperation Paymaster's "postOp" call reverted with non-zero length. |
| 64 | + * @param userOpHash - The request unique identifier. |
| 65 | + * @param sender - The sender of this request. |
| 66 | + * @param nonce - The nonce used in the request. |
| 67 | + * @param revertReason - The return bytes from the reverted call to "postOp". |
| 68 | + */ |
| 69 | + event PostOpRevertReason(bytes32 indexed userOpHash, address indexed sender, uint256 nonce, bytes revertReason); |
| 70 | + |
| 71 | + /** |
| 72 | + * UserOp consumed more than prefund. The UserOperation is reverted, and no refund is made. |
| 73 | + * @param userOpHash - The request unique identifier. |
| 74 | + * @param sender - The sender of this request. |
| 75 | + * @param nonce - The nonce used in the request. |
| 76 | + */ |
| 77 | + event UserOperationPrefundTooLow(bytes32 indexed userOpHash, address indexed sender, uint256 nonce); |
| 78 | + |
| 79 | + /** |
| 80 | + * An event emitted by handleOps() and handleAggregatedOps(), before starting the execution loop. |
| 81 | + * Any event emitted before this event, is part of the validation. |
| 82 | + */ |
| 83 | + event BeforeExecution(); |
| 84 | + |
| 85 | + /** |
| 86 | + * Signature aggregator used by the following UserOperationEvents within this bundle. |
| 87 | + * @param aggregator - The aggregator used for the following UserOperationEvents. |
| 88 | + */ |
| 89 | + event SignatureAggregatorChanged(address indexed aggregator); |
| 90 | + |
| 91 | + /** |
| 92 | + * A custom revert error of handleOps andhandleAggregatedOps, to identify the offending op. |
| 93 | + * Should be caught in off-chain handleOps/handleAggregatedOps simulation and not happen on-chain. |
| 94 | + * Useful for mitigating DoS attempts against batchers or for troubleshooting of factory/account/paymaster reverts. |
| 95 | + * NOTE: If simulateValidation passes successfully, there should be no reason for handleOps to fail on it. |
| 96 | + * @param opIndex - Index into the array of ops to the failed one (in simulateValidation, this is always zero). |
| 97 | + * @param reason - Revert reason. The string starts with a unique code "AAmn", |
| 98 | + * where "m" is "1" for factory, "2" for account and "3" for paymaster issues, |
| 99 | + * so a failure can be attributed to the correct entity. |
| 100 | + */ |
| 101 | + error FailedOp(uint256 opIndex, string reason); |
| 102 | + |
| 103 | + /** |
| 104 | + * A custom revert error of handleOps and handleAggregatedOps, to report a revert by account or paymaster. |
| 105 | + * @param opIndex - Index into the array of ops to the failed one (in simulateValidation, this is always zero). |
| 106 | + * @param reason - Revert reason. see FailedOp(uint256,string), above |
| 107 | + * @param inner - data from inner cought revert reason |
| 108 | + * @dev note that inner is truncated to 2048 bytes |
| 109 | + */ |
| 110 | + error FailedOpWithRevert(uint256 opIndex, string reason, bytes inner); |
| 111 | + |
| 112 | + error PostOpReverted(bytes returnData); |
| 113 | + |
| 114 | + /** |
| 115 | + * Error case when a signature aggregator fails to verify the aggregated signature it had created. |
| 116 | + * @param aggregator The aggregator that failed to verify the signature |
| 117 | + */ |
| 118 | + error SignatureValidationFailed(address aggregator); |
| 119 | + |
| 120 | + // Return value of getSenderAddress. |
| 121 | + error SenderAddressResult(address sender); |
| 122 | + |
| 123 | + // UserOps handled, per aggregator. |
| 124 | + struct UserOpsPerAggregator { |
| 125 | + PackedUserOperation[] userOps; |
| 126 | + // Aggregator address |
| 127 | + IAggregator aggregator; |
| 128 | + // Aggregated signature |
| 129 | + bytes signature; |
| 130 | + } |
| 131 | + |
| 132 | + /** |
| 133 | + * Execute a batch of UserOperation with Aggregators |
| 134 | + * @param opsPerAggregator - The operations to execute, grouped by aggregator (or address(0) for no-aggregator accounts). |
| 135 | + * @param beneficiary - The address to receive the fees. |
| 136 | + */ |
| 137 | + function handleAggregatedOps(UserOpsPerAggregator[] calldata opsPerAggregator, address payable beneficiary) |
| 138 | + external; |
| 139 | + |
| 140 | + /** |
| 141 | + * Generate a request Id - unique identifier for this request. |
| 142 | + * The request ID is a hash over the content of the userOp (except the signature), entrypoint address, chainId and (optionally) 7702 delegate address |
| 143 | + * @param userOp - The user operation to generate the request ID for. |
| 144 | + * @return hash the hash of this UserOperation |
| 145 | + */ |
| 146 | + function getUserOpHash(PackedUserOperation calldata userOp) external view returns (bytes32); |
| 147 | + |
| 148 | + /** |
| 149 | + * Gas and return values during simulation. |
| 150 | + * @param preOpGas - The gas used for validation (including preValidationGas) |
| 151 | + * @param prefund - The required prefund for this operation |
| 152 | + * @param accountValidationData - returned validationData from account. |
| 153 | + * @param paymasterValidationData - return validationData from paymaster. |
| 154 | + * @param paymasterContext - Returned by validatePaymasterUserOp (to be passed into postOp) |
| 155 | + */ |
| 156 | + struct ReturnInfo { |
| 157 | + uint256 preOpGas; |
| 158 | + uint256 prefund; |
| 159 | + uint256 accountValidationData; |
| 160 | + uint256 paymasterValidationData; |
| 161 | + bytes paymasterContext; |
| 162 | + } |
| 163 | + |
| 164 | + /** |
| 165 | + * Get counterfactual sender address. |
| 166 | + * Calculate the sender contract address that will be generated by the initCode and salt in the UserOperation. |
| 167 | + * This method always revert, and returns the address in SenderAddressResult error. |
| 168 | + * @notice this method cannot be used for EIP-7702 derived contracts. |
| 169 | + * |
| 170 | + * @param initCode - The constructor code to be passed into the UserOperation. |
| 171 | + */ |
| 172 | + function getSenderAddress(bytes memory initCode) external; |
| 173 | + |
| 174 | + error DelegateAndRevert(bool success, bytes ret); |
| 175 | + |
| 176 | + /** |
| 177 | + * Helper method for dry-run testing. |
| 178 | + * @dev calling this method, the EntryPoint will make a delegatecall to the given data, and report (via revert) the result. |
| 179 | + * The method always revert, so is only useful off-chain for dry run calls, in cases where state-override to replace |
| 180 | + * actual EntryPoint code is less convenient. |
| 181 | + * @param target a target contract to make a delegatecall from entrypoint |
| 182 | + * @param data data to pass to target in a delegatecall |
| 183 | + */ |
| 184 | + function delegateAndRevert(address target, bytes calldata data) external; |
| 185 | + |
| 186 | + /** |
| 187 | + * @notice Retrieves the immutable SenderCreator contract which is responsible for deployment of sender contracts. |
| 188 | + */ |
| 189 | + function senderCreator() external view returns (ISenderCreator); |
| 190 | +} |
0 commit comments