From c84b75e4bb50123c75a6390ce1cdfd512c79a55a Mon Sep 17 00:00:00 2001 From: KONFeature Date: Tue, 30 Jan 2024 21:23:50 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20EVM=20state=20during=20ben?= =?UTF-8?q?chmark=20to=20prevent=20warm=20storage=20access?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- benchmarks/validator/ECDSA.json | 18 ++++++------- test/benchmark/BaseValidatorBenchmark.t.sol | 28 ++++++++++++++------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/benchmarks/validator/ECDSA.json b/benchmarks/validator/ECDSA.json index bd4570b4..5f421e15 100644 --- a/benchmarks/validator/ECDSA.json +++ b/benchmarks/validator/ECDSA.json @@ -1,18 +1,18 @@ { "global": { - "disable": 1988, - "enable": 30567, + "disable": 10488, + "enable": 32571, "fullDeployment": 14120 }, "signature": { - "ko_viaKernel": 11929, - "ko_viaValidator": 9455, - "viaKernel": 11911, - "viaValidator": 9443 + "ko_viaKernel": 18429, + "ko_viaValidator": 11456, + "viaKernel": 18412, + "viaValidator": 17943 }, "userOp": { - "viaEntryPoint": 173360, - "viaKernel": 13229, - "viaValidator": 7173 + "viaEntryPoint": 178360, + "viaKernel": 26730, + "viaValidator": 13672 } } \ No newline at end of file diff --git a/test/benchmark/BaseValidatorBenchmark.t.sol b/test/benchmark/BaseValidatorBenchmark.t.sol index 382403eb..e033fa48 100644 --- a/test/benchmark/BaseValidatorBenchmark.t.sol +++ b/test/benchmark/BaseValidatorBenchmark.t.sol @@ -49,6 +49,9 @@ abstract contract BaseValidatorBenchmark is Test { /// @dev dummy contract we will use to test user op DummyContract private _dummyContract; + /// @dev Snapshot used to reset the gas measurement + uint256 private _snapshot; + /// @dev Init the base stuff required to run the benchmark function _init() internal { _isWriteEnabled = vm.envOr("WRITE_BENCHMARK_RESULT", false); @@ -121,6 +124,7 @@ abstract contract BaseValidatorBenchmark is Test { /// @dev Run the whole benchmark function test_benchmark() public { + _snapshot = vm.snapshot(); string memory validatorName = _getValidatorName(); console.log("====================================="); console.log("Benchmarking: %s", validatorName); @@ -161,7 +165,7 @@ abstract contract BaseValidatorBenchmark is Test { /* -------------------------------------------------------------------------- */ /// @dev Benchmark the enable of the given validator - function _benchmark_fullDeployment() private { + function _benchmark_fullDeployment() private cleanState { // Don't save this in our gas measurement bytes memory initData = _getInitData(); @@ -173,7 +177,7 @@ abstract contract BaseValidatorBenchmark is Test { } /// @dev Benchmark the enable of the given validator - function _benchmark_enable() private { + function _benchmark_enable() private cleanState { // Don't save this in our gas measurement bytes memory enableData = _getEnableData(); @@ -186,7 +190,7 @@ abstract contract BaseValidatorBenchmark is Test { } /// @dev Benchmark the disable of the given validator - function _benchmark_disable() private { + function _benchmark_disable() private cleanState { // Don't save this in our gas measurement bytes memory disableData = _getDisableData(); @@ -205,7 +209,7 @@ abstract contract BaseValidatorBenchmark is Test { /* -------------------------------------------------------------------------- */ /// @dev Benchmark the user op validation process only - function _benchmark_userOp_viaEntryPoint() private { + function _benchmark_userOp_viaEntryPoint() private cleanState { // Build a dummy user op (UserOperation memory userOperation,) = _getSignedDummyUserOp(); @@ -221,7 +225,7 @@ abstract contract BaseValidatorBenchmark is Test { } /// @dev Benchmark the user op validation process only - function _benchmark_userOp_viaKernel() private { + function _benchmark_userOp_viaKernel() private cleanState { // Build a dummy user op (UserOperation memory userOperations, bytes32 userOperationHash) = _getSignedDummyUserOp(); @@ -237,7 +241,7 @@ abstract contract BaseValidatorBenchmark is Test { } /// @dev Benchmark the user op validation process only - function _benchmark_userOp_viaValidator() private { + function _benchmark_userOp_viaValidator() private cleanState { // Build a dummy user op (UserOperation memory userOperations, bytes32 userOperationHash) = _getSignedDummyUserOp(); @@ -275,7 +279,7 @@ abstract contract BaseValidatorBenchmark is Test { /* -------------------------------------------------------------------------- */ /// @dev Benchmark on a direct signature validation on the validator level - function _benchmark_signature_viaValidator() private { + function _benchmark_signature_viaValidator() private cleanState { bytes32 _hash = keccak256("0xacab"); bytes memory signature = _generateHashSignature(_hash); @@ -291,7 +295,7 @@ abstract contract BaseValidatorBenchmark is Test { } /// @dev Benchmark on a direct signature validation on the kernel level - function _benchmark_signature_viaKernel() private { + function _benchmark_signature_viaKernel() private cleanState { bytes32 _hash = keccak256("0xacab"); // Get a few data for the domain separator bytes32 domainSeparator = _kernel.getDomainSeparator(); @@ -327,7 +331,7 @@ abstract contract BaseValidatorBenchmark is Test { } /// @dev Benchmark on a direct signature validation on the kernel level - function _benchmark_signature_ko_viaKernel() private { + function _benchmark_signature_ko_viaKernel() private cleanState { bytes32 _hash = keccak256("0xacab"); // Get a few data for the domain separator bytes32 domainSeparator = _kernel.getDomainSeparator(); @@ -383,6 +387,12 @@ abstract contract BaseValidatorBenchmark is Test { // Reset the current json _currentJson = ""; } + + /// @dev Revert the state after the run of the method + modifier cleanState() { + vm.revertTo(_snapshot); + _; + } } /// @dev Dummy contract used to test the validator