Description: Custom errors from Solidity 0.8.4 are cheaper than revert strings (cheaper deployment cost and runtime cost when the revert condition is met)
Source: https://blog.soliditylang.org/2021/04/21/custom-errors/:
Starting from Solidity v0.8.4, there is a convenient and gas-efficient way to explain to users why an operation failed through the use of custom errors. Until now, you could already use strings to give more information about failures (e.g.,
revert("Insufficient funds.");
), but they are rather expensive, especially when it comes to deploy cost, and it is difficult to use dynamic information in them.
Custom errors are defined using the error statement, which can be used inside and outside of contracts (including interfaces and libraries).
Impact: Changing this will make your code more gas efficient.
Recommended Mitigation: Let's take an example of your code to suggest a cool (and ordered) way to create this custom errors. Let's take the onlyManager()
modifier of the LiquidationPool
contract:
We can make it more efficient. First, let's define a custom error for this particular message. To make it more specific, we'll start the name of our error with the name of the contract that this error is located in, followed by double underscore. So, we'll make something like
Then, we'll modify the condition of our modifier by using an if
statement
This is more gas efficient than using strings (and looks cool, right?)
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.