Using hardcoded strings instead of custom errors will result in more gas consumption
In the below examples, we can see that hardcoded strings are used instead of custom error type definitions. Although there is nothing wrong with this approach, we can change it in a way that will result in more gas-efficient code. There are two instances where this optimization can be considered. For one of the error messages, we already declared an error in the Errors.sol
file, so we can use it instead of the "UNAUTHORIZED"
string message.
Ownable.sol
https://github.com/Cyfrin/2023-07-beedle/blob/658e046bda8b010a5b82d2d85e824f3823602d27/src/utils/Ownable.sol#L10C1-L13C6
Fees.sol
https://github.com/Cyfrin/2023-07-beedle/blob/658e046bda8b010a5b82d2d85e824f3823602d27/src/Fees.sol#L24C1-L45C2
This approach will lead to using more gas while running the code and overall more gas consumption
Manual Review
Try to avoid implementing checks with hardcoded string messages and strive to build more gas-efficient and better-performing code by using custom errors. Consider adding a new error in the Errors.sol
file and reconsidering the logic in the onlyOwner modifier by replacing the hardcoded string with error Unauthorized();
.
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.