Skip to content

Commit e84f267

Browse files
authored
Merge pull request #9 from pimlicolabs/fix/revert-if-binary-search-fails
revert if initial run fails
2 parents 927701e + 6542a16 commit e84f267

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/v07/EntryPointSimulations.sol

+17-2
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,16 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations {
172172
targetSuccess = true;
173173
targetResult = hex"";
174174
minGas = initialMinGas;
175+
176+
(targetSuccess, targetResult) = thisContract.simulateCall(entryPoint, payload, gasleft());
177+
178+
// If the call reverts then don't binary search.
179+
if (!targetSuccess) {
180+
return TargetCallResult(0, targetSuccess, targetResult);
181+
}
175182
} else {
176183
// Find the minGas (reduces number of iterations + checks if the call reverts).
177184
uint256 remainingGas = gasleft();
178-
179185
(targetSuccess, targetResult) = thisContract.simulateCall(entryPoint, payload, gasleft());
180186
minGas = remainingGas - gasleft();
181187

@@ -255,7 +261,7 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations {
255261
* @param gasAllowance - The margin to add to the binary search to account for overhead.
256262
* @return optimalGas - The estimated gas limit for the call.
257263
*/
258-
function simulateCallData(
264+
function binarySearchCallGasLimit(
259265
SimulationArgs[] calldata queuedUserOps,
260266
SimulationArgs calldata targetUserOp,
261267
address entryPoint,
@@ -299,6 +305,15 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations {
299305
targetSuccess = true;
300306
targetResult = hex"";
301307
minGas = initialMinGas;
308+
309+
bytes memory payload =
310+
abi.encodeWithSelector(this.simulateCallAndRevert.selector, target, targetCallData, gasleft());
311+
(targetSuccess, targetResult) = thisContract.simulateCall(entryPoint, payload, gasleft());
312+
313+
// If the call reverts then don't binary search.
314+
if (!targetSuccess) {
315+
return TargetCallResult(0, targetSuccess, targetResult);
316+
}
302317
} else {
303318
// Find the minGas (reduces number of iterations + checks if the call reverts).
304319
uint256 remainingGas = gasleft();

0 commit comments

Comments
 (0)