Skip to content

Commit

Permalink
🐛 Fix EVM state during benchmark to prevent warm storage access
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed Jan 30, 2024
1 parent 22ee469 commit c84b75e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
18 changes: 9 additions & 9 deletions benchmarks/validator/ECDSA.json
Original file line number Diff line number Diff line change
@@ -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
}
}
28 changes: 19 additions & 9 deletions test/benchmark/BaseValidatorBenchmark.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -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);

Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c84b75e

Please sign in to comment.