From a77c834819000160262b10e85116d494b1a81f73 Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Thu, 9 Jan 2025 14:04:27 +0000 Subject: [PATCH 1/2] revert if initial run fails --- src/v07/EntryPointSimulations.sol | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/v07/EntryPointSimulations.sol b/src/v07/EntryPointSimulations.sol index 8bfc008..2104b4e 100644 --- a/src/v07/EntryPointSimulations.sol +++ b/src/v07/EntryPointSimulations.sol @@ -172,10 +172,16 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations { targetSuccess = true; targetResult = hex""; minGas = initialMinGas; + + (targetSuccess, targetResult) = thisContract.simulateCall(entryPoint, payload, gasleft()); + + // If the call reverts then don't binary search. + if (!targetSuccess) { + return TargetCallResult(0, targetSuccess, targetResult); + } } else { // Find the minGas (reduces number of iterations + checks if the call reverts). uint256 remainingGas = gasleft(); - (targetSuccess, targetResult) = thisContract.simulateCall(entryPoint, payload, gasleft()); minGas = remainingGas - gasleft(); From 6542a16f75acf77985b6cd1497766da9cbe15b19 Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Thu, 9 Jan 2025 14:19:32 +0000 Subject: [PATCH 2/2] rename to binarySearchCallGasLimit --- src/v07/EntryPointSimulations.sol | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/v07/EntryPointSimulations.sol b/src/v07/EntryPointSimulations.sol index 2104b4e..f607b71 100644 --- a/src/v07/EntryPointSimulations.sol +++ b/src/v07/EntryPointSimulations.sol @@ -261,7 +261,7 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations { * @param gasAllowance - The margin to add to the binary search to account for overhead. * @return optimalGas - The estimated gas limit for the call. */ - function simulateCallData( + function binarySearchCallGasLimit( SimulationArgs[] calldata queuedUserOps, SimulationArgs calldata targetUserOp, address entryPoint, @@ -305,6 +305,15 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations { targetSuccess = true; targetResult = hex""; minGas = initialMinGas; + + bytes memory payload = + abi.encodeWithSelector(this.simulateCallAndRevert.selector, target, targetCallData, gasleft()); + (targetSuccess, targetResult) = thisContract.simulateCall(entryPoint, payload, gasleft()); + + // If the call reverts then don't binary search. + if (!targetSuccess) { + return TargetCallResult(0, targetSuccess, targetResult); + } } else { // Find the minGas (reduces number of iterations + checks if the call reverts). uint256 remainingGas = gasleft();