-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGasComparison.t.sol
More file actions
77 lines (63 loc) · 3.16 KB
/
GasComparison.t.sol
File metadata and controls
77 lines (63 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.23;
import { Test } from "forge-std/Test.sol";
import { MockSingleKeccakCreate3 } from "../src/mocks/MockSingleKeccakCreate3.sol";
import { MockERC20 } from "../src/mocks/MockERC20.sol";
import { CREATE3 } from "@solady/src/utils/CREATE3.sol";
contract GasComparisonTest is Test {
uint256 mintAmt = 5;
MockERC20 public mockErc20; // has been deployed by deployer
MockSingleKeccakCreate3 public deployer;
function setUp() public {
deployer = new MockSingleKeccakCreate3();
bytes32[] memory storageSlots = new bytes32[](1);
storageSlots[0] = bytes32(uint256(5));
bytes32[] memory storageVals = new bytes32[](1);
storageVals[0] = bytes32(uint256(uint160(address(this))));
mockErc20 = MockERC20(
deployer.deployAndSetupStorage(0, address(new MockERC20(mintAmt)).code, storageVals, storageSlots, 0)
);
}
function test_soladyCreate3() public {
bytes memory creationCode = abi.encodePacked(type(MockERC20).creationCode, mintAmt);
CREATE3.deploy(0, creationCode, 0);
}
function test_singleKeccakCreate3() public {
// mutate storage args a little to force a sstore2 instance
bytes32[] memory storageSlots = new bytes32[](3);
storageSlots[0] =
bytes32(keccak256(abi.encodePacked(bytes32(uint256(uint160(address(this)))), bytes32(uint256(0)))));
storageSlots[1] = bytes32(uint256(2));
storageSlots[2] = bytes32(uint256(5));
bytes32[] memory storageVals = new bytes32[](3);
storageVals[0] = bytes32(uint256(mintAmt));
storageVals[1] = bytes32(uint256(mintAmt));
storageVals[2] = bytes32(uint256(uint160(address(this))));
// mutate the code a little to force a sstore2 instance
deployer.deployAndSetupStorage(
bytes32(uint256(1)), abi.encodePacked(address(mockErc20).code, uint256(1)), storageVals, storageSlots, 0
);
}
function test_singleKeccakCreate3_NoStorage() public {
// mutate the code a little to force a sstore2 instance
deployer.deploy(bytes32(uint256(1)), abi.encodePacked(address(mockErc20).code, uint256(1)), 0);
}
function test_singleKeccakCreate3_Repeat() public {
// mutate storage args a little to force a sstore2 instance
bytes32[] memory storageSlots = new bytes32[](3);
storageSlots[0] =
bytes32(keccak256(abi.encodePacked(bytes32(uint256(uint160(address(this)))), bytes32(uint256(0)))));
storageSlots[1] = bytes32(uint256(2));
storageSlots[2] = bytes32(uint256(5));
bytes32[] memory storageVals = new bytes32[](3);
storageVals[0] = bytes32(uint256(mintAmt));
storageVals[1] = bytes32(uint256(mintAmt));
storageVals[2] = bytes32(uint256(uint160(address(this))));
// no sstore2 instance here
deployer.deployAndSetupStorage(bytes32(uint256(1)), address(mockErc20).code, storageVals, storageSlots, 0);
}
function test_singleKeccakCreate3_NoStorage_Repeat() public {
// no sstore2 instance here
deployer.deploy(bytes32(uint256(1)), address(mockErc20).code, 0);
}
}