From e6262121889e4e95ef01685836d29e2fd3095a79 Mon Sep 17 00:00:00 2001 From: mouseless <97399882+mouseless-eth@users.noreply.github.com> Date: Fri, 4 Oct 2024 16:46:12 +0100 Subject: [PATCH] add simulateHandleOpBulk from optimise-estimation branch --- src/EntryPointSimulations.sol | 41 ++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/EntryPointSimulations.sol b/src/EntryPointSimulations.sol index f021afb..629263f 100644 --- a/src/EntryPointSimulations.sol +++ b/src/EntryPointSimulations.sol @@ -82,9 +82,9 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations { return ValidationResult(returnInfo, senderInfo, factoryInfo, paymasterInfo, aggregatorInfo); } - function simulateValidationLast(PackedUserOperation[] calldata userOps) - external - returns (ValidationResult memory) + function simulateValidationBulk(PackedUserOperation[] calldata userOps) + public + returns (ValidationResult[] memory) { ValidationResult[] memory results = new ValidationResult[](userOps.length); @@ -94,6 +94,15 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations { results[i] = result; } + return results; + } + + function simulateValidationLast(PackedUserOperation[] calldata userOps) + external + returns (ValidationResult memory) + { + ValidationResult[] memory results = simulateValidationBulk(userOps); + return results[userOps.length - 1]; } @@ -236,11 +245,33 @@ contract EntryPointSimulations is EntryPoint, IEntryPointSimulations { function simulateHandleOpBulk(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++) { - 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[resultsIndex++] = 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"); + } + } } return results;