diff --git a/.gas-snapshot b/.gas-snapshot index b8e332a8..43d76860 100644 --- a/.gas-snapshot +++ b/.gas-snapshot @@ -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) @@ -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) diff --git a/src/utils/CREATE3.sol b/src/utils/CREATE3.sol index 0d5b341e..7751f30c 100644 --- a/src/utils/CREATE3.sol +++ b/src/utils/CREATE3.sol @@ -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; //--------------------------------------------------------------------------------// @@ -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) { diff --git a/src/utils/SSTORE2.sol b/src/utils/SSTORE2.sol index 23d69803..811ee8e5 100644 --- a/src/utils/SSTORE2.sol +++ b/src/utils/SSTORE2.sol @@ -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 @@ -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(); } /*////////////////////////////////////////////////////////////// @@ -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); }