solmate
solmate copied to clipboard
Gas Optimization: Custom Errors
Description
Implemented Custom Errors across all major contracts.
Fixed up tests to accomodate custom errors.
E.g.
hevm.expectRevert("NOT_MINTED"); -> hevm.expectRevert(abi.encodeWithSignature("NOT_MINTED()"));
Gas savings are ubiquitous: E.g.
Revert Strings:
[PASS] testTransfer(address,uint256) (runs: 256, μ: 58776, ~: 60487)
[PASS] testTransferFrom(address,uint256,uint256) (runs: 256, μ: 87191, ~: 92844)
Custom Errors:
[PASS] testTransfer(address,uint256) (runs: 256, μ: 58310, ~: 60487) -- Saves ~466
[PASS] testTransferFrom(address,uint256,uint256) (runs: 256, μ: 88263, ~: 92844) -- Saves ~1072
Checklist
Ensure you completed all of the steps below before submitting your pull request:
- [x] Ran
forge snapshot? - [x] Ran
npm run lint? - [x] Ran
forge test?
Pull requests with an incomplete checklist will be thrown out.
mind doing this against the v7 branch instead of master?
happy to merge this after resolving the comments above across the diff
For sure, ill review / take care of all the comments and rebase on v7
I think custom errors should include the emitter:
error SomeError(address emitter, ..., ..., ...);
emit SomeError(address(this), ..., ..., ...);
This helps end-users identify which contract was reverted with a failed transaction, which is especially useful for complex transactions involving multiple contracts. Also, custom errors should be highly informative and I would argue that the emitter is a piece of important information that belongs to any custom error.
What's with the min version in the contracts? pragma solidity >=0.8.0;
Shouldn't it be >=0.8.4 at least?
https://blog.soliditylang.org/2021/04/21/custom-errors