Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert if initial run fails #9

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading