ZoraModuleManager.sol Gas Optimization #178
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description & Motivation and Context
Most of the Zora-V3 contracts are using
require
statements for reverting errors. Which is not a very gas-efficient way to revert errors. Therequire
statements storesStrings
which costs a lot of Gas (deploying + function Calling & Reverting).And as the protocol aims to be Gas Efficient, Then it would be much better to not use
require
statements to revert the errors.Instead, use
Custom Errors
. Which is a new solidity feature (introduced in 0.8.*)Custom errors do the same thing but cost much less gas than the
require
statements.For more info read this
How has this been tested?
Firstly to show that, the
Custom Errors
lowers the deploying Costs I tested before & after deploying gas cost tests on Remix IDE. It's saving 199117 GasBefore:
After:
And after that, to get an estimate of how much function Calling Gasis saving I did before & after tests on VS Code using Foundry.
Before:
After:
Even tho, 2 foundry tests are failing but we can see that
custom errors
are saving functions calling Gas As well.And the 2 functions that are failing are just because they were not expecting those lines of errors.
Even tho, I changed the tests' revert text as well (similar to the expected error) but it's still failing don't know why, so please anyone from the Zora team pls guide me on what more changes I need to make.
Checklist:
My changes do not require any of the followings:
1 contract fixed of issue #177 :)
Thanks,
AB Dee.