From 8b41b058c286ee9cd3c24f70c763166993640ac5 Mon Sep 17 00:00:00 2001 From: Garvit Khatri Date: Sat, 21 Sep 2024 16:39:14 +0100 Subject: [PATCH 1/2] don't revert the estimation if earlier in the queue reverts --- src/EntryPointSimulations.sol | 39 ++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/src/EntryPointSimulations.sol b/src/EntryPointSimulations.sol index 75655b3..5748f8f 100644 --- a/src/EntryPointSimulations.sol +++ b/src/EntryPointSimulations.sol @@ -62,8 +62,8 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations { _simulationOnlyValidations(userOp); ( uint256 validationData, - uint256 paymasterValidationData, - // uint256 paymasterVerificationGasLimit + uint256 paymasterValidationData, // uint256 paymasterVerificationGasLimit + ) = _validatePrepayment(0, userOp, outOpInfo); _validateAccountAndPaymasterValidationData( @@ -118,7 +118,9 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations { function simulateValidationBulk( PackedUserOperation[] calldata userOps ) public returns (ValidationResult[] memory) { - ValidationResult[] memory results = new ValidationResult[](userOps.length); + ValidationResult[] memory results = new ValidationResult[]( + userOps.length + ); for (uint256 i = 0; i < userOps.length; i++) { ValidationResult memory result = simulateValidation(userOps[i]); @@ -227,9 +229,36 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations { ExecutionResult[] memory results = new ExecutionResult[](ops.length); for (uint256 i = 0; i < ops.length; i++) { - ExecutionResult memory result = simulateHandleOp(ops[i]); + (bool success, bytes memory returnData) = address(this).call( + abi.encodeWithSignature( + "simulateHandleOp((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,address,address,bytes))", + ops[i] + ) + ); - results[i] = result; + if (success) { + ExecutionResult memory execResult = abi.decode( + returnData, + (ExecutionResult) + ); + results.push(execResult); + } + + // revert only at last as we are estimating only the last call + if (i == ops.length - 1) { + if (returnData.length > 0) { + assembly { + // Revert using the original error data, propagating the exact revert reason + revert(add(returnData, 0x20), mload(returnData)) + } + } else { + // If there's no revert reason, we can use a generic message + revert("simulateHandleOp failed without a revert reason"); + } + } + + // ExecutionResult memory result = simulateHandleOp(ops[i]); + // results[i] = result; } return results; From 5afe47953cf907bfd3c12c8f65d6c745b98a6f0a Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Fri, 4 Oct 2024 16:36:45 +0100 Subject: [PATCH 2/2] replace results.push with index --- src/EntryPointSimulations.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/EntryPointSimulations.sol b/src/EntryPointSimulations.sol index 5748f8f..5e8e403 100644 --- a/src/EntryPointSimulations.sol +++ b/src/EntryPointSimulations.sol @@ -227,6 +227,7 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations { PackedUserOperation[] calldata ops ) public returns (ExecutionResult[] memory) { ExecutionResult[] memory results = new ExecutionResult[](ops.length); + uint256 resultsIndex = 0; for (uint256 i = 0; i < ops.length; i++) { (bool success, bytes memory returnData) = address(this).call( @@ -241,7 +242,7 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations { returnData, (ExecutionResult) ); - results.push(execResult); + results[resultsIndex++] = execResult; } // revert only at last as we are estimating only the last call