Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡️ chore: convert require to custom errors #338

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ AuthTest:testTransferOwnershipWithPermissiveAuthority(address,address) (runs: 25
Bytes32AddressLibTest:testFillLast12Bytes() (gas: 223)
Bytes32AddressLibTest:testFromLast20Bytes() (gas: 191)
CREATE3Test:testDeployERC20() (gas: 853111)
CREATE3Test:testDeployERC20(bytes32,string,string,uint8) (runs: 256, μ: 922796, ~: 921961)
CREATE3Test:testFailDoubleDeployDifferentBytecode() (gas: 9079256848778914174)
CREATE3Test:testFailDoubleDeployDifferentBytecode(bytes32,bytes,bytes) (runs: 256, μ: 5062195514745832485, ~: 8937393460516727435)
CREATE3Test:testFailDoubleDeploySameBytecode() (gas: 9079256848778906218)
CREATE3Test:testFailDoubleDeploySameBytecode(bytes32,bytes) (runs: 256, μ: 5027837975401088878, ~: 8937393460516728677)
CREATE3Test:testDeployERC20(bytes32,string,string,uint8) (runs: 256, μ: 923485, ~: 921961)
CREATE3Test:testFailDoubleDeployDifferentBytecode() (gas: 9079256848778914128)
CREATE3Test:testFailDoubleDeployDifferentBytecode(bytes32,bytes,bytes) (runs: 256, μ: 5062195514745832424, ~: 8937393460516727378)
CREATE3Test:testFailDoubleDeploySameBytecode() (gas: 9079256848778906162)
CREATE3Test:testFailDoubleDeploySameBytecode(bytes32,bytes) (runs: 256, μ: 5062749668606232028, ~: 8937393460516728632)
DSTestPlusTest:testBound() (gas: 14214)
DSTestPlusTest:testBound(uint256,uint256,uint256) (runs: 256, μ: 2787, ~: 2793)
DSTestPlusTest:testBrutalizeMemory() (gas: 823)
Expand Down Expand Up @@ -325,20 +325,20 @@ RolesAuthorityTest:testSetRoleCapabilities(uint8,address,bytes4) (runs: 256, μ:
RolesAuthorityTest:testSetRoles() (gas: 29005)
RolesAuthorityTest:testSetRoles(address,uint8) (runs: 256, μ: 29122, ~: 29108)
SSTORE2Test:testFailReadInvalidPointer() (gas: 2927)
SSTORE2Test:testFailReadInvalidPointer(address,bytes) (runs: 256, μ: 3889, ~: 3892)
SSTORE2Test:testFailReadInvalidPointerCustomBounds() (gas: 3099)
SSTORE2Test:testFailReadInvalidPointerCustomBounds(address,uint256,uint256,bytes) (runs: 256, μ: 4107, ~: 4130)
SSTORE2Test:testFailReadInvalidPointer(address,bytes) (runs: 256, μ: 3879, ~: 3892)
SSTORE2Test:testFailReadInvalidPointerCustomBounds() (gas: 3033)
SSTORE2Test:testFailReadInvalidPointerCustomBounds(address,uint256,uint256,bytes) (runs: 256, μ: 4050, ~: 4067)
SSTORE2Test:testFailReadInvalidPointerCustomStartBound() (gas: 3004)
SSTORE2Test:testFailReadInvalidPointerCustomStartBound(address,uint256,bytes) (runs: 256, μ: 3980, ~: 3988)
SSTORE2Test:testFailWriteReadCustomBoundsOutOfRange(bytes,uint256,uint256,bytes) (runs: 256, μ: 46236, ~: 43603)
SSTORE2Test:testFailReadInvalidPointerCustomStartBound(address,uint256,bytes) (runs: 256, μ: 3979, ~: 3988)
SSTORE2Test:testFailWriteReadCustomBoundsOutOfRange(bytes,uint256,uint256,bytes) (runs: 256, μ: 46175, ~: 43540)
SSTORE2Test:testFailWriteReadCustomStartBoundOutOfRange(bytes,uint256,bytes) (runs: 256, μ: 46017, ~: 43452)
SSTORE2Test:testFailWriteReadEmptyOutOfBounds() (gas: 34470)
SSTORE2Test:testFailWriteReadOutOfBounds() (gas: 34426)
SSTORE2Test:testFailWriteReadEmptyOutOfBounds() (gas: 34407)
SSTORE2Test:testFailWriteReadOutOfBounds() (gas: 34363)
SSTORE2Test:testFailWriteReadOutOfStartBound() (gas: 34362)
SSTORE2Test:testWriteRead() (gas: 53497)
SSTORE2Test:testWriteRead(bytes,bytes) (runs: 256, μ: 44019, ~: 41555)
SSTORE2Test:testWriteReadCustomBounds() (gas: 34869)
SSTORE2Test:testWriteReadCustomBounds(bytes,uint256,uint256,bytes) (runs: 256, μ: 29324, ~: 44495)
SSTORE2Test:testWriteReadCustomBounds(bytes,uint256,uint256,bytes) (runs: 256, μ: 28531, ~: 41976)
SSTORE2Test:testWriteReadCustomStartBound() (gas: 34740)
SSTORE2Test:testWriteReadCustomStartBound(bytes,uint256,bytes) (runs: 256, μ: 46484, ~: 44053)
SSTORE2Test:testWriteReadEmptyBound() (gas: 34677)
Expand Down
7 changes: 5 additions & 2 deletions src/utils/CREATE3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import {Bytes32AddressLib} from "./Bytes32AddressLib.sol";
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/CREATE3.sol)
/// @author Modified from 0xSequence (https://github.com/0xSequence/create3/blob/master/contracts/Create3.sol)
library CREATE3 {
error DeploymentFailed();
error InitializationFailed();

using Bytes32AddressLib for bytes32;

//--------------------------------------------------------------------------------//
Expand Down Expand Up @@ -48,11 +51,11 @@ library CREATE3 {
// We start 32 bytes into the code to avoid copying the byte length.
proxy := create2(0, add(proxyChildBytecode, 32), mload(proxyChildBytecode), salt)
}
require(proxy != address(0), "DEPLOYMENT_FAILED");
if (proxy == address(0)) revert DeploymentFailed();

deployed = getDeployed(salt);
(bool success, ) = proxy.call{value: value}(creationCode);
require(success && deployed.code.length != 0, "INITIALIZATION_FAILED");
if (success && deployed.code.length == 0) revert InitializationFailed();
}

function getDeployed(bytes32 salt) internal view returns (address) {
Expand Down
6 changes: 4 additions & 2 deletions src/utils/SSTORE2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pragma solidity >=0.8.0;
/// @author Modified from 0xSequence (https://github.com/0xSequence/sstore2/blob/master/contracts/SSTORE2.sol)
library SSTORE2 {
uint256 internal constant DATA_OFFSET = 1; // We skip the first byte as it's a STOP opcode to ensure the contract can't be called.
error DeploymentFail();
error OutOfBounds();

/*//////////////////////////////////////////////////////////////
WRITE LOGIC
Expand Down Expand Up @@ -41,7 +43,7 @@ library SSTORE2 {
pointer := create(0, add(creationCode, 32), mload(creationCode))
}

require(pointer != address(0), "DEPLOYMENT_FAILED");
if (pointer == address(0)) revert DeploymentFail();
}

/*//////////////////////////////////////////////////////////////
Expand All @@ -66,7 +68,7 @@ library SSTORE2 {
start += DATA_OFFSET;
end += DATA_OFFSET;

require(pointer.code.length >= end, "OUT_OF_BOUNDS");
if (pointer.code.length < end) revert OutOfBounds();

return readBytecode(pointer, start, end - start);
}
Expand Down