@@ -172,10 +172,16 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations {
172
172
targetSuccess = true ;
173
173
targetResult = hex "" ;
174
174
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
+ }
175
182
} else {
176
183
// Find the minGas (reduces number of iterations + checks if the call reverts).
177
184
uint256 remainingGas = gasleft ();
178
-
179
185
(targetSuccess, targetResult) = thisContract.simulateCall (entryPoint, payload, gasleft ());
180
186
minGas = remainingGas - gasleft ();
181
187
@@ -255,7 +261,7 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations {
255
261
* @param gasAllowance - The margin to add to the binary search to account for overhead.
256
262
* @return optimalGas - The estimated gas limit for the call.
257
263
*/
258
- function simulateCallData (
264
+ function binarySearchCallGasLimit (
259
265
SimulationArgs[] calldata queuedUserOps ,
260
266
SimulationArgs calldata targetUserOp ,
261
267
address entryPoint ,
@@ -299,6 +305,15 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations {
299
305
targetSuccess = true ;
300
306
targetResult = hex "" ;
301
307
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
+ }
302
317
} else {
303
318
// Find the minGas (reduces number of iterations + checks if the call reverts).
304
319
uint256 remainingGas = gasleft ();
0 commit comments