-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding 08 comparing external to public functions
- Loading branch information
Showing
4 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.28; | ||
|
||
import {IdRegUnop} from "../IdRegUnop.sol"; | ||
|
||
contract IdRegUseExtFunc is IdRegUnop { | ||
// @audit change from `external` to `public` to see if | ||
// gas costs increase (compile breaks the other way) | ||
function resetId(uint256 id) public override { | ||
idToOwner[id] = address(0); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.28; | ||
|
||
import {IdRegUnopTest} from "../IdRegUnopTest.sol"; | ||
import {IdRegUseExtFunc} from "../../src/08-use-ext-func/IdRegUseExtFunc.sol"; | ||
|
||
// Optimizer ON, 10000 runs | ||
// ======================== | ||
// Pre : 1002 gas | ||
// forge test --optimizer-runs 10000 --match-contract IdRegUnopTest --match-test test_resetId -vvv | ||
// Post : 1002 gas (no improvement) | ||
// forge test --optimizer-runs 10000 --match-contract IdRegUseExtFuncTest --match-test test_resetId -vvv | ||
// | ||
// Optimizer OFF | ||
// ============= | ||
// Pre : 1018 gas | ||
// forge test --match-contract IdRegUnopTest --match-test test_resetId -vvv | ||
// Post : 1018 gas (no improvement) | ||
// forge test --match-contract IdRegUseExtFuncTest --match-test test_resetId -vvv | ||
// | ||
// Conclusion | ||
// ========== | ||
// Setting storage to default values costs the same | ||
// as using the `delete` keyword | ||
contract IdRegUseExtFuncTest is IdRegUnopTest { | ||
function setUp() external override { | ||
idReg = new IdRegUseExtFunc(); | ||
} | ||
} |