Skip to content

Commit

Permalink
Merge pull request #7 from pimlicolabs/feat/use-all-gas-during-estima…
Browse files Browse the repository at this point in the history
…tion

use all gas during estimation
  • Loading branch information
mouseless0x authored Dec 12, 2024
2 parents 238898b + 2bdaab4 commit caf37f3
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions src/v06/EntryPointCodeOverride.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ contract EntryPointCodeOverride is IEntryPoint, StakeManager, NonceManager, Reen
// ================================================================= //
// ======= START: THIS IS CUSTOM TO THIS SIMULATION CONTRACT ======= //
// ================================================================= //
// note: revert whole tx if CallPhaseReverted is detected.

if (reason.length == 0) revert CallPhaseReverted("");

assembly {
Expand Down Expand Up @@ -266,26 +268,46 @@ contract EntryPointCodeOverride is IEntryPoint, StakeManager, NonceManager, Reen
require(msg.sender == address(this), "AA92 internal call only");
MemoryUserOp memory mUserOp = opInfo.mUserOp;

uint256 callGasLimit = mUserOp.callGasLimit;
unchecked {
// handleOps was called with gas limit too low. abort entire bundle.
if (gasleft() < callGasLimit + mUserOp.verificationGasLimit + 5000) {
assembly {
mstore(0, INNER_OUT_OF_GAS)
revert(0, 32)
}
}
}
// ================================================================= //
// ======= START: THIS IS CUSTOM TO THIS SIMULATION CONTRACT ======= //
// ================================================================= //
// note: ignoring AA95 check

//uint256 callGasLimit = mUserOp.callGasLimit;
//
//unchecked {
// // handleOps was called with gas limit too low. abort entire bundle.
// if (gasleft() < callGasLimit + mUserOp.verificationGasLimit + 5000) {
// assembly {
// mstore(0, INNER_OUT_OF_GAS)
// revert(0, 32)
// }
// }
//}

// ================================================================= //
// ======= END: THIS IS CUSTOM TO THIS SIMULATION CONTRACT ======== //
// ================================================================= //

IPaymaster.PostOpMode mode = IPaymaster.PostOpMode.opSucceeded;
if (callData.length > 0) {
bool success = Exec.call(mUserOp.sender, 0, callData, callGasLimit);
// ================================================================= //
// ======= START: THIS IS CUSTOM TO THIS SIMULATION CONTRACT ======= //
// ================================================================= //
// note: Calling exec with gasleft() to ensure that the call has sufficient gas to execute

bool success = Exec.call(mUserOp.sender, 0, callData, gasleft());

// ================================================================= //
// ======= END: THIS IS CUSTOM TO THIS SIMULATION CONTRACT ======== //
// ================================================================= //
if (!success) {
bytes memory result = Exec.getReturnData(REVERT_REASON_MAX_LEN);

// ================================================================= //
// ======= START: THIS IS CUSTOM TO THIS SIMULATION CONTRACT ======= //
// ================================================================= //
// note: Revert if the call failed (this will be caught higher up)

revert CallPhaseReverted(result);

Expand Down Expand Up @@ -658,8 +680,8 @@ contract EntryPointCodeOverride is IEntryPoint, StakeManager, NonceManager, Reen
// ================================================================= //
// ======= START: THIS IS CUSTOM TO THIS SIMULATION CONTRACT ======= //
// ================================================================= //
// note: Throws postOp revert error if one is thrown.

// Throw postOp revert error if one is thrown.
try IPaymaster(paymaster).postOp{gas: mUserOp.verificationGasLimit}(
mode, context, actualGasCost
) {} catch (bytes memory reason) {
Expand Down

0 comments on commit caf37f3

Please sign in to comment.