From 46098f0170cbb47bbe0dcd75a0b69b23a3ed3933 Mon Sep 17 00:00:00 2001 From: NIC619 Date: Mon, 16 Dec 2024 20:49:35 +0800 Subject: [PATCH] Pause gas metering for debug trace recording and `parseValidation` --- src/Simulator.sol | 12 +++++++++++- src/lib/Vm.sol | 8 ++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Simulator.sol b/src/Simulator.sol index 7bd54c3..88793da 100644 --- a/src/Simulator.sol +++ b/src/Simulator.sol @@ -17,7 +17,9 @@ import { stopMappingRecording, stopAndReturnDebugTraceRecording, revertToState, - expectRevert + expectRevert, + pauseGasMetering, + resumeGasMetering } from "./lib/Vm.sol"; import { ERC4337SpecsParser } from "./SpecsParser.sol"; @@ -152,6 +154,8 @@ library Simulator { // Start recording mapping accesses and debug trace startMappingRecording(); + // Pause gas metering to avoid OOG issues as debug trace recording consumes many gas + pauseGasMetering(); startDebugTraceRecording(); } @@ -163,9 +167,15 @@ library Simulator { 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(); diff --git a/src/lib/Vm.sol b/src/lib/Vm.sol index ded3b88..b58a83c 100644 --- a/src/lib/Vm.sol +++ b/src/lib/Vm.sol @@ -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(); +}