Skip to content

Commit f4397dc

Browse files
committed
optimise
1 parent 498ae9c commit f4397dc

7 files changed

+9
-169
lines changed

script/PimlicoEntryPointSimulations.s.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity ^0.8.13;
33

44
import "forge-std/Script.sol";
5-
import "../src/v07/PimlicoEntryPointSimulations.sol";
5+
import "../src/v08/PimlicoEntryPointSimulations.sol";
66

77
contract PimlicoEntryPointSimulationsScript is Script {
88
function setUp() public {}

src/v08/EntryPoint.sol

+3-144
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pragma solidity ^0.8.28;
55

66
import "account-abstraction-v8/interfaces/IAccount.sol";
77
import "account-abstraction-v8/interfaces/IAccountExecute.sol";
8-
import "account-abstraction-v8/interfaces/IEntryPoint.sol";
8+
import "./IEntryPoint.sol";
99
import "account-abstraction-v8/interfaces/IPaymaster.sol";
1010

1111
import "account-abstraction-v8/core/UserOperationLib.sol";
@@ -17,15 +17,14 @@ import "./Eip7702Support.sol";
1717
import "account-abstraction-v8/utils/Exec.sol";
1818

1919
import "@openzeppelin/contracts-51/utils/ReentrancyGuardTransient.sol";
20-
import "@openzeppelin/contracts-51/utils/introspection/ERC165.sol";
2120
import "@openzeppelin/contracts-51/utils/cryptography/EIP712.sol";
2221

2322
/**
2423
* Account-Abstraction (EIP-4337) singleton EntryPoint v0.8 implementation.
2524
* Only one instance required on each chain.
2625
* @custom:security-contact https://bounty.ethereum.org
2726
*/
28-
contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuardTransient, ERC165, EIP712 {
27+
contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuardTransient, EIP712 {
2928
using UserOperationLib for PackedUserOperation;
3029

3130
/**
@@ -52,110 +51,19 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuardT
5251

5352
constructor() EIP712(DOMAIN_NAME, DOMAIN_VERSION) {}
5453

55-
/// @inheritdoc IEntryPoint
56-
function handleOps(PackedUserOperation[] calldata ops, address payable beneficiary) external nonReentrant {
57-
uint256 opslen = ops.length;
58-
UserOpInfo[] memory opInfos = new UserOpInfo[](opslen);
59-
unchecked {
60-
_iterateValidationPhase(ops, opInfos, address(0), 0);
61-
62-
uint256 collected = 0;
63-
emit BeforeExecution();
64-
65-
for (uint256 i = 0; i < opslen; i++) {
66-
uint256 paymasterPostOpGasLimit;
67-
uint256 _collected;
68-
(_collected, paymasterPostOpGasLimit) = _executeUserOp(i, ops[i], opInfos[i]);
69-
collected += _collected;
70-
}
71-
72-
_compensate(beneficiary, collected);
73-
}
74-
}
75-
76-
/// @inheritdoc IEntryPoint
77-
function handleAggregatedOps(UserOpsPerAggregator[] calldata opsPerAggregator, address payable beneficiary)
78-
external
79-
nonReentrant
80-
{
81-
unchecked {
82-
uint256 opasLen = opsPerAggregator.length;
83-
uint256 totalOps = 0;
84-
for (uint256 i = 0; i < opasLen; i++) {
85-
UserOpsPerAggregator calldata opa = opsPerAggregator[i];
86-
PackedUserOperation[] calldata ops = opa.userOps;
87-
IAggregator aggregator = opa.aggregator;
88-
89-
// address(1) is special marker of "signature error"
90-
require(address(aggregator) != address(1), SignatureValidationFailed(address(aggregator)));
91-
92-
if (address(aggregator) != address(0)) {
93-
// solhint-disable-next-line no-empty-blocks
94-
try aggregator.validateSignatures(ops, opa.signature) {}
95-
catch {
96-
revert SignatureValidationFailed(address(aggregator));
97-
}
98-
}
99-
100-
totalOps += ops.length;
101-
}
102-
103-
UserOpInfo[] memory opInfos = new UserOpInfo[](totalOps);
104-
105-
uint256 opIndex = 0;
106-
for (uint256 a = 0; a < opasLen; a++) {
107-
UserOpsPerAggregator calldata opa = opsPerAggregator[a];
108-
PackedUserOperation[] calldata ops = opa.userOps;
109-
IAggregator aggregator = opa.aggregator;
110-
111-
opIndex += _iterateValidationPhase(ops, opInfos, address(aggregator), opIndex);
112-
}
113-
114-
emit BeforeExecution();
115-
116-
uint256 collected = 0;
117-
opIndex = 0;
118-
for (uint256 a = 0; a < opasLen; a++) {
119-
UserOpsPerAggregator calldata opa = opsPerAggregator[a];
120-
emit SignatureAggregatorChanged(address(opa.aggregator));
121-
PackedUserOperation[] calldata ops = opa.userOps;
122-
uint256 opslen = ops.length;
123-
124-
for (uint256 i = 0; i < opslen; i++) {
125-
uint256 paymasterPostOpGasLimit;
126-
uint256 _collected;
127-
(_collected, paymasterPostOpGasLimit) = _executeUserOp(opIndex, ops[i], opInfos[opIndex]);
128-
collected += _collected;
129-
opIndex++;
130-
}
131-
}
132-
133-
_compensate(beneficiary, collected);
134-
}
135-
}
136-
13754
/// @inheritdoc IEntryPoint
13855
function getUserOpHash(PackedUserOperation calldata userOp) public view returns (bytes32) {
13956
bytes32 overrideInitCodeHash = Eip7702Support._getEip7702InitCodeHashOverride(userOp);
14057
return MessageHashUtils.toTypedDataHash(getDomainSeparatorV4(), userOp.hash(overrideInitCodeHash));
14158
}
14259

143-
/// @inheritdoc IEntryPoint
144-
function getSenderAddress(bytes calldata initCode) external {
145-
address sender = senderCreator().createSender(initCode);
146-
revert SenderAddressResult(sender);
147-
}
148-
14960
/// @inheritdoc IEntryPoint
15061
function senderCreator() public view virtual returns (ISenderCreator) {
15162
return _senderCreator;
15263
}
15364

15465
/// @inheritdoc IEntryPoint
155-
function delegateAndRevert(address target, bytes calldata data) external {
156-
(bool success, bytes memory ret) = target.delegatecall(data);
157-
revert DelegateAndRevert(success, ret);
158-
}
66+
function delegateAndRevert(address target, bytes calldata data) external {}
15967

16068
function getPackedUserOpTypeHash() external pure returns (bytes32) {
16169
return UserOperationLib.PACKED_USEROP_TYPEHASH;
@@ -165,26 +73,6 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuardT
16573
return _domainSeparatorV4();
16674
}
16775

168-
/// @inheritdoc IERC165
169-
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
170-
// note: solidity "type(IEntryPoint).interfaceId" is without inherited methods but we want to check everything
171-
return interfaceId
172-
== (type(IEntryPoint).interfaceId ^ type(IStakeManager).interfaceId ^ type(INonceManager).interfaceId)
173-
|| interfaceId == type(IEntryPoint).interfaceId || interfaceId == type(IStakeManager).interfaceId
174-
|| interfaceId == type(INonceManager).interfaceId || super.supportsInterface(interfaceId);
175-
}
176-
177-
/**
178-
* Compensate the caller's beneficiary address with the collected fees of all UserOperations.
179-
* @param beneficiary - The address to receive the fees.
180-
* @param amount - Amount to transfer.
181-
*/
182-
function _compensate(address payable beneficiary, uint256 amount) internal virtual {
183-
require(beneficiary != address(0), "AA90 invalid beneficiary");
184-
(bool success,) = beneficiary.call{value: amount}("");
185-
require(success, "AA91 failed send to beneficiary");
186-
}
187-
18876
/**
18977
* Execute a user operation.
19078
* @param opIndex - Index into the opInfo array.
@@ -251,35 +139,6 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuardT
251139
emit UserOperationPrefundTooLow(opInfo.userOpHash, opInfo.mUserOp.sender, opInfo.mUserOp.nonce);
252140
}
253141

254-
/**
255-
* Iterate over calldata PackedUserOperation array and perform account and paymaster validation.
256-
* @notice UserOpInfo is a global array of all UserOps while PackedUserOperation is grouped per aggregator.
257-
*
258-
* @param ops - an array of UserOps to be validated
259-
* @param opInfos - an array of UserOp metadata being read and filled in during this function's execution
260-
* @param expectedAggregator - an address of the aggregator specified for a given UserOp if any, or address(0)
261-
* @param opIndexOffset - an offset for the index between 'ops' and 'opInfos' arrays, see the notice.
262-
* @return opsLen - processed UserOps (length of "ops" array)
263-
*/
264-
function _iterateValidationPhase(
265-
PackedUserOperation[] calldata ops,
266-
UserOpInfo[] memory opInfos,
267-
address expectedAggregator,
268-
uint256 opIndexOffset
269-
) internal returns (uint256 opsLen) {
270-
unchecked {
271-
opsLen = ops.length;
272-
for (uint256 i = 0; i < opsLen; i++) {
273-
UserOpInfo memory opInfo = opInfos[opIndexOffset + i];
274-
(uint256 validationData, uint256 pmValidationData,) =
275-
_validatePrepayment(opIndexOffset + i, ops[i], opInfo);
276-
_validateAccountAndPaymasterValidationData(
277-
opIndexOffset + i, validationData, pmValidationData, expectedAggregator
278-
);
279-
}
280-
}
281-
}
282-
283142
/**
284143
* A memory copy of UserOp static fields only.
285144
* Excluding: callData, initCode and signature. Replacing paymasterAndData with paymaster.

src/v08/EntryPointSimulations.sol

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pragma solidity ^0.8.28;
77
import "./EntryPoint.sol";
88
import "./IEntryPointSimulations.sol";
99
import {UserOperationLib} from "account-abstraction-v8/core/UserOperationLib.sol";
10-
import {IEntryPoint} from "account-abstraction-v8/interfaces/IEntryPoint.sol";
1110

1211
struct SimulationArgs {
1312
PackedUserOperation op;

src/v08/IEntryPoint.sol

-18
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,6 @@ interface IEntryPoint is IStakeManager, INonceManager {
129129
bytes signature;
130130
}
131131

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-
140132
/**
141133
* Generate a request Id - unique identifier for this request.
142134
* The request ID is a hash over the content of the userOp (except the signature), entrypoint address, chainId and (optionally) 7702 delegate address
@@ -161,16 +153,6 @@ interface IEntryPoint is IStakeManager, INonceManager {
161153
bytes paymasterContext;
162154
}
163155

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-
174156
error DelegateAndRevert(bool success, bytes ret);
175157

176158
/**

src/v08/IEntryPointSimulations.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pragma solidity >=0.7.5;
33

44
import "account-abstraction-v8/interfaces/PackedUserOperation.sol";
5-
import "account-abstraction-v8/interfaces/IEntryPoint.sol";
5+
import "./IEntryPoint.sol";
66

77
interface IEntryPointSimulations is IEntryPoint {
88
struct TargetCallResult {

src/v08/SenderCreator.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pragma solidity ^0.8.28;
44
/* solhint-disable no-inline-assembly */
55

66
import "account-abstraction-v8/interfaces/ISenderCreator.sol";
7-
import "account-abstraction-v8/interfaces/IEntryPoint.sol";
7+
import "./IEntryPoint.sol";
88
import "account-abstraction-v8/utils/Exec.sol";
99

1010
/**

test/Test.sol

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ contract ATest is Test {
1313

1414
function testSimulateEmptyBytes() public {
1515
vm.etch(
16-
address(0x47B65635728aBa56Fa95022bA5D0222FF1317A0C),
16+
address(0xf315FCB0F56A10001A21f1F814c0366959656Ea5),
1717
hex"6080604081815260049182361015610021575b505050361561001f575f80fd5b005b5f925f3560e01c91826319822f7c146101ab57508163408aee421461018d57816345171159146100f2578163a9cc4718146100ad578163a9e966b714610093575063c19d93fb146100725780610012565b3461008f578160031936011261008f576020906001549051908152f35b5080fd5b83903461008f57602036600319011261008f573560015580f35b905082346100ef57806003193601126100ef57506020606492519162461bcd60e51b835282015260096024820152681d195cdd0819985a5b60ba1b6044820152fd5b80fd5b918091506003193601126101895781356001600160a01b03811692908390036101895760243563ffffffff811680910361018957833b15610189575f906024845180968193621cb65b60e51b83528683015234905af1801561017f57610156578380f35b919250906001600160401b03831161016c575052005b604190634e487b7160e01b5f525260245ffd5b82513d5f823e3d90fd5b5f80fd5b8234610189575f3660031901126101895760209060015f5d515f8152f35b8390346101895760031990606036830112610189578335906001600160401b03908183116101895761012083870194843603011261018957604435906064840160146101f782886103c4565b905014610328575b5050806102bf575b5050906101046102189201906103c4565b6001600160f01b0319918291903582811691600281106102a9575b505090501661dead60f01b8114610269576020925061deaf60f01b036102605760ff6001915b5191168152f35b60ff5f91610259565b815162461bcd60e51b8152602081850152601a6024820152797465737457616c6c65743a2064656164207369676e617475726560301b6044820152606490fd5b8391925060020360031b1b161681908580610233565b5f80808093335af1503d1561031a573d908111610307576102189291610104918551906102f66020601f19601f84011601836103f6565b81525f60203d92013e5b9192610207565b604185634e487b7160e01b5f525260245ffd5b509061010461021892610300565b816024815f6103396020958b6103c4565b6001600160601b0319913582811691601481106103af575b5050631bab58f560e01b8452308e85015260601c90505af180156103a55761037a575b806101ff565b602090813d831161039e575b61039081836103f6565b810103126101895786610374565b503d610386565b86513d5f823e3d90fd5b8391925060140360031b1b1616808e80610351565b903590601e198136030182121561018957018035906001600160401b0382116101895760200191813603831361018957565b601f909101601f19168101906001600160401b0382119082101761041957604052565b634e487b7160e01b5f52604160045260245ffdfea2646970667358221220c9740d7fb0148de5efc37bbdc6af8538da4c4c2a3d4369305eef4e99174b912264736f6c63430008190033"
1818
);
1919
bytes memory data =
20-
hex"c18f52260000000000000000000000004337084d9e255ff0702461cf8895ce9e3b5ff1080000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000284fe2171cb00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000047b65635728aba56fa95022ba5d0222ff1317a0c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000f4240000000000000000000000000000493e000000000000000000000000000000000000000000000000000000000000493e0000000000000000000000000b2d05e00000000000000000000000000ee6b280000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000000387702000000000000000000000000000000000000a9e966b70000000000000000000000000000000000000000000000000000000000001e1600000000000000000000000000000000000000000000000000000000000000000000000000000004a9cc47180000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002face00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
20+
hex"c18f52260000000000000000000000004337084d9e255ff0702461cf8895ce9e3b5ff1080000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000284fe2171cb000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000f315fcb0f56a10001a21f1f814c0366959656ea5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001200000000000000000000000000000000000000000000000000000000000000180000000000000000000000000000f4240000000000000000000000000000493e000000000000000000000000000000000000000000000000000000000000493e0000000000000000000000000b2d05e00000000000000000000000000ee6b280000000000000000000000000000000000000000000000000000000000000001c000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000000387702000000000000000000000000000000000000a9e966b70000000000000000000000000000000000000000000000000000000000001e1600000000000000000000000000000000000000000000000000000000000000000000000000000004a9cc47180000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002face00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
2121

2222
// Call the simulation function with a dummy address (we won't actually use it)
2323
//(bool s, bytes memory b) = address(0x289675eC355a3Eb0660E847d6DBC01a6B61bf2DC).call(data);
24-
(bool s, bytes memory b) = address(pimlicoEntryPointSimulations).call(data);
24+
(bool s, bytes memory b) = address(0x6b11F6aF92A5d705C2788e6DDDfd8B5799d6854d).call(data);
2525

2626
console.log(s);
2727
console.logBytes(b);

0 commit comments

Comments
 (0)