Skip to content

Commit b7b9938

Browse files
authored
fmt, gas benchmark (#122)
* fmt, gas benchmark * fix workflow action
1 parent 18a4bce commit b7b9938

File tree

80 files changed

+441
-128
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+441
-128
lines changed

.gas-snapshot

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
CoreBenchmark:test_core_callCallbackFunction_required() (gas: 43107)
2-
CoreBenchmark:test_core_callFunction_callback_callbackFunctionRequired() (gas: 43392)
3-
CoreBenchmark:test_core_callFunction_notPermissionedDelegate() (gas: 36959)
4-
CoreBenchmark:test_core_callFunction_notPermissionedExternal() (gas: 36877)
5-
CoreBenchmark:test_deployCore() (gas: 2126555)
6-
CoreBenchmark:test_deployExtension() (gas: 322501)
7-
CoreBenchmark:test_extension_callFunction_notPermissionedDelegate() (gas: 29358)
8-
CoreBenchmark:test_extension_callFunction_notPermissionedExternal() (gas: 29378)
9-
CoreBenchmark:test_installExtension() (gas: 324348)
10-
CoreBenchmark:test_uninstallExtension() (gas: 62093)
1+
CoreBenchmark:test_core_callCallbackFunction_required() (gas: 46411)
2+
CoreBenchmark:test_core_callFunction_callback_callbackFunctionRequired() (gas: 44067)
3+
CoreBenchmark:test_core_callFunction_notPermissionedDelegate() (gas: 18029)
4+
CoreBenchmark:test_core_callFunction_notPermissionedExternal() (gas: 17985)
5+
CoreBenchmark:test_deployCore() (gas: 1920924)
6+
CoreBenchmark:test_deployExtension() (gas: 258057)
7+
CoreBenchmark:test_extension_callFunction_notPermissionedDelegate() (gas: 8294)
8+
CoreBenchmark:test_extension_callFunction_notPermissionedExternal() (gas: 8314)
9+
CoreBenchmark:test_installExtension() (gas: 330369)
10+
CoreBenchmark:test_uninstallExtension() (gas: 18385)

.github/workflows/benchmark.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
strategy:
2222
fail-fast: true
2323

24-
name: Foundry project
24+
name: Foundry
2525
runs-on: ubuntu-latest
2626
steps:
2727
- uses: actions/checkout@v4
@@ -41,5 +41,5 @@ jobs:
4141

4242
- name: Create Forge Gas Report
4343
run: |
44-
forge test --isolate --mp 'test/benchmark/*'
44+
forge snapshot --diff --isolate --mp 'test/benchmark/*'
4545
id: benchmark

.github/workflows/formatter.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
strategy:
2222
fail-fast: true
2323

24-
name: Foundry project
24+
name: Foundry
2525
runs-on: ubuntu-latest
2626
steps:
2727
- uses: actions/checkout@v4

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
strategy:
2222
fail-fast: true
2323

24-
name: Foundry project
24+
name: Foundry
2525
runs-on: ubuntu-latest
2626
steps:
2727
- uses: actions/checkout@v4

foundry.toml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[profile.default]
2-
#auto_detect_solc = false
3-
solc-version = "0.8.25"
4-
evm_version = "london"
2+
solc-version = "0.8.26"
3+
evm_version = "paris"
54
optimizer = true
65
optimizer_runs = 10000
76
cache = true
@@ -16,4 +15,15 @@ gas_reports = [
1615
]
1716
ignored_warnings_from = ["node_modules", "lib", "test"]
1817

19-
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
18+
[fmt]
19+
line_length = 120
20+
tab_width = 4
21+
sort_imports = true
22+
override_spacing = false
23+
bracket_spacing = false
24+
contract_new_lines = true
25+
single_line_statement_blocks = "multi"
26+
int_types = "long"
27+
quote_style = "double"
28+
number_underscore = "thousands"
29+
multiline_func_header = "attributes_first"

script/benchmark-ext/erc721/BenchmarkERC721.s.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// SPDX-License-Identifier: Apache-2.0
22
pragma solidity ^0.8.13;
33

4-
import "forge-std/Script.sol";
54
import {IERC721} from "./BenchmarkERC721Base.sol";
6-
import {BenchmarkERC721ThirdwebLegacy} from "./BenchmarkERC721ThirdwebLegacy.sol";
5+
76
import {BenchmarkERC721Manifold} from "./BenchmarkERC721Manifold.sol";
7+
import {BenchmarkERC721ThirdwebLegacy} from "./BenchmarkERC721ThirdwebLegacy.sol";
8+
import "forge-std/Script.sol";
89

910
contract BenchmarkERC721 is Script {
11+
1012
function benchmarkThirdwebLegacy() public {
1113
BenchmarkERC721ThirdwebLegacy benchmark = new BenchmarkERC721ThirdwebLegacy();
1214

@@ -38,4 +40,5 @@ contract BenchmarkERC721 is Script {
3840
benchmarkThirdwebLegacy();
3941
benchmarkManifold();
4042
}
43+
4144
}

script/benchmark-ext/erc721/BenchmarkERC721Base.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
pragma solidity ^0.8.24;
33

44
interface IERC721 {
5+
56
function transferFrom(address from, address to, uint256 tokenId) external;
67

78
function setApprovalForAll(address operator, bool _approved) external;
9+
810
}
911

1012
abstract contract BenchmarkERC721Base {
13+
1114
// Step 1: Deploy a contract through factory or create
1215
// Step 2: Setup the collection with token URI
1316
// Step 3: Mint an NFT
@@ -27,4 +30,5 @@ abstract contract BenchmarkERC721Base {
2730
function mintBatchTokens(address contractAddress) external virtual;
2831

2932
function transferTokenFrom(address contractAddress) external virtual;
33+
3034
}

script/benchmark-ext/erc721/BenchmarkERC721Manifold.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pragma solidity ^0.8.24;
44
import "./BenchmarkERC721Base.sol";
55

66
library StorageSlot {
7+
78
struct AddressSlot {
89
address value;
910
}
@@ -14,9 +15,11 @@ library StorageSlot {
1415
r.slot := slot
1516
}
1617
}
18+
1719
}
1820

1921
abstract contract Proxy {
22+
2023
function _delegate(address implementation) internal virtual {
2124
assembly {
2225
calldatacopy(0, 0, calldatasize())
@@ -40,9 +43,11 @@ abstract contract Proxy {
4043
fallback() external payable virtual {
4144
_fallback();
4245
}
46+
4347
}
4448

4549
contract ERC721Creator is Proxy {
50+
4651
constructor(string memory name, string memory symbol) {
4752
assert(_IMPLEMENTATION_SLOT == bytes32(uint256(keccak256("eip1967.proxy.implementation")) - 1));
4853
StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = 0x07aee92b7C5977F5EC15d20BaC713A21f72F287B;
@@ -61,19 +66,23 @@ contract ERC721Creator is Proxy {
6166
function _implementation() internal view override returns (address) {
6267
return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
6368
}
69+
6470
}
6571

6672
interface IManifoldNFT {
73+
6774
function transferFrom(address from, address to, uint256 tokenId) external;
6875

6976
function mintBase(address to, string calldata uri) external returns (uint256);
7077

7178
function mintBaseBatch(address to, uint16 count) external returns (uint256[] memory);
7279

7380
function mintBaseBatch(address to, string[] calldata uris) external returns (uint256[] memory);
81+
7482
}
7583

7684
contract BenchmarkERC721Manifold is BenchmarkERC721Base {
85+
7786
function deployContract(
7887
address deployerAddress,
7988
string memory name,
@@ -102,4 +111,5 @@ contract BenchmarkERC721Manifold is BenchmarkERC721Base {
102111
function transferTokenFrom(address contractAddress) external override {
103112
IERC721(contractAddress).transferFrom(tx.origin, address(0xdead), 1);
104113
}
114+
105115
}

script/benchmark-ext/erc721/BenchmarkERC721ThirdwebLegacy.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pragma solidity ^0.8.24;
44
import "./BenchmarkERC721Base.sol";
55

66
interface IBenchmarkERC721 {
7+
78
function deployProxyByImplementation(address _implementation, bytes calldata _data, bytes32 _salt)
89
external
910
returns (address deployedProxy);
@@ -20,13 +21,17 @@ interface IBenchmarkERC721 {
2021
uint128 _platformFeeBps,
2122
address _platformFeeRecipient
2223
) external;
24+
2325
}
2426

2527
interface IThirdwebNFT {
28+
2629
function mintTo(address _to, string calldata _uri) external returns (uint256);
30+
2731
}
2832

2933
contract BenchmarkERC721ThirdwebLegacy is BenchmarkERC721Base {
34+
3035
function deployContract(
3136
address deployerAddress,
3237
string memory name,
@@ -67,4 +72,5 @@ contract BenchmarkERC721ThirdwebLegacy is BenchmarkERC721Base {
6772
function transferTokenFrom(address contractAddress) external override {
6873
IERC721(contractAddress).transferFrom(tx.origin, address(0xdead), 0);
6974
}
75+
7076
}

src/ModularCore.sol

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
pragma solidity ^0.8.23;
33

44
// Interface
5+
6+
import {IInstallationCallback} from "./interface/IInstallationCallback.sol";
57
import {IModularCore} from "./interface/IModularCore.sol";
68
import {IModularExtension} from "./interface/IModularExtension.sol";
7-
import {IInstallationCallback} from "./interface/IInstallationCallback.sol";
89

910
// Utils
1011
import {Role} from "./Role.sol";
@@ -13,6 +14,7 @@ import {EnumerableSetLib} from "@solady/utils/EnumerableSetLib.sol";
1314
import {ReentrancyGuard} from "@solady/utils/ReentrancyGuard.sol";
1415

1516
abstract contract ModularCore is IModularCore, OwnableRoles, ReentrancyGuard {
17+
1618
using EnumerableSetLib for EnumerableSetLib.AddressSet;
1719

1820
/*//////////////////////////////////////////////////////////////
@@ -147,8 +149,12 @@ abstract contract ModularCore is IModularCore, OwnableRoles, ReentrancyGuard {
147149

148150
/// @notice Returns whether a given interface is implemented by the contract.
149151
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
150-
if (interfaceId == 0xffffffff) return false;
151-
if (supportedInterfaceRefCounter[interfaceId] > 0) return true;
152+
if (interfaceId == 0xffffffff) {
153+
return false;
154+
}
155+
if (supportedInterfaceRefCounter[interfaceId] > 0) {
156+
return true;
157+
}
152158
return false;
153159
}
154160

@@ -158,8 +164,12 @@ abstract contract ModularCore is IModularCore, OwnableRoles, ReentrancyGuard {
158164

159165
/// @notice Returns whether a given interface is implemented by the contract.
160166
function _supportsInterfaceViaExtensions(bytes4 interfaceId) internal view virtual returns (bool) {
161-
if (interfaceId == 0xffffffff) return false;
162-
if (supportedInterfaceRefCounter[interfaceId] > 0) return true;
167+
if (interfaceId == 0xffffffff) {
168+
return false;
169+
}
170+
if (supportedInterfaceRefCounter[interfaceId] > 0) {
171+
return true;
172+
}
163173
return false;
164174
}
165175

@@ -208,7 +218,9 @@ abstract contract ModularCore is IModularCore, OwnableRoles, ReentrancyGuard {
208218
break;
209219
}
210220
}
211-
if (!supported) revert CallbackFunctionNotSupported();
221+
if (!supported) {
222+
revert CallbackFunctionNotSupported();
223+
}
212224

213225
functionData_[callbackFunction.selector] =
214226
InstalledFunction({implementation: _extension, permissionBits: 0, fnType: FunctionType.CALLBACK});
@@ -388,4 +400,5 @@ abstract contract ModularCore is IModularCore, OwnableRoles, ReentrancyGuard {
388400
}
389401
}
390402
}
403+
391404
}

0 commit comments

Comments
 (0)