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

Pause gas metering for debug trace recording and parseValidation #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion src/Simulator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
IEntryPointSimulationsV060,
UserOperation,
UserOperationDetails,
IStakeManager

Check warning on line 10 in src/Simulator.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

imported name IStakeManager is not used
} from "./lib/ERC4337.sol";
import { VmSafe } from "forge-std/Vm.sol";
import {
Expand All @@ -17,7 +17,9 @@
stopMappingRecording,
stopAndReturnDebugTraceRecording,
revertToState,
expectRevert
expectRevert,

Check warning on line 20 in src/Simulator.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

imported name expectRevert is not used
pauseGasMetering,
resumeGasMetering
} from "./lib/Vm.sol";
import { ERC4337SpecsParser } from "./SpecsParser.sol";

Expand Down Expand Up @@ -118,7 +120,7 @@
// selector (4 bytes) + length(32 bytes) + preOpGas(32 bytes)
// + prefund (32 bytes) + sigFailed (32 bytes)
uint256 pos = 4 + 32 + 32 + 32;
assembly {

Check warning on line 123 in src/Simulator.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

Avoid to use inline assembly. It is acceptable only in rare cases
sigFailed := mload(add(reason, pos))
}
}
Expand Down Expand Up @@ -146,12 +148,14 @@

// Store the snapshot id so that it can be reverted to after simulation
bytes32 snapShotSlot = keccak256(abi.encodePacked("Simulator.SnapshotId"));
assembly {

Check warning on line 151 in src/Simulator.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

Avoid to use inline assembly. It is acceptable only in rare cases
sstore(snapShotSlot, snapShotId)
}

// Start recording mapping accesses and debug trace
startMappingRecording();
// Pause gas metering to avoid OOG issues as debug trace recording consumes many gas
pauseGasMetering();
startDebugTraceRecording();
}

Expand All @@ -163,9 +167,15 @@
function _postSimulation(UserOperationDetails memory userOpDetails) internal {
// Get the recorded opcodes
VmSafe.DebugStep[] memory debugTrace = stopAndReturnDebugTraceRecording();
// Resume gas metering after debug trace recording is completed
resumeGasMetering();

// Validate the ERC-4337 rules
// Pause gas metering to avoid OOG issues as `parseValidation` consumes many gas
pauseGasMetering();
ERC4337SpecsParser.parseValidation(userOpDetails, debugTrace);
// Resume gas metering after `parseValidation` is completed
resumeGasMetering();

// Stop (and remove) recording mapping accesses
stopMappingRecording();
Expand All @@ -173,7 +183,7 @@
// Get the snapshot id
uint256 snapShotId;
bytes32 snapShotSlot = keccak256(abi.encodePacked("Simulator.SnapshotId"));
assembly {

Check warning on line 186 in src/Simulator.sol

View workflow job for this annotation

GitHub Actions / lint / forge-lint

Avoid to use inline assembly. It is acceptable only in rare cases
snapShotId := sload(snapShotSlot)
}

Expand Down
8 changes: 8 additions & 0 deletions src/lib/Vm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ function startDebugTraceRecording() {
function stopAndReturnDebugTraceRecording() returns (VmSafe.DebugStep[] memory steps) {
return Vm(VM_ADDR).stopAndReturnDebugTraceRecording();
}

function pauseGasMetering() {
Vm(VM_ADDR).pauseGasMetering();
}

function resumeGasMetering() {
Vm(VM_ADDR).resumeGasMetering();
}
Loading