Skip to content

Commit

Permalink
Merge pull request #9 from pimlicolabs/fix/revert-if-binary-search-fails
Browse files Browse the repository at this point in the history
revert if initial run fails
  • Loading branch information
mouseless0x authored Jan 9, 2025
2 parents 927701e + 6542a16 commit e84f267
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/v07/EntryPointSimulations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -255,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,
Expand Down Expand Up @@ -299,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();
Expand Down

0 comments on commit e84f267

Please sign in to comment.