Gas Optimizations #103
Labels
bug
Something isn't working
duplicate
This issue or pull request already exists
G (Gas Optimization)
resolved
Finding has been patched by sponsor (sponsor pls link to PR containing fix)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Gas optimization report
Keep revert strings below 32 bytes
Strings are stored in slots of 32 bytes, and hence the length of the revert string should be at max 32 bytes to fit inside 1 slot. If the string is just 33 bytes it will occupy 2 slots (64 bytes). Keeping the string size at 32 bytes or below will save gas on both deployment and when the revert condition is met.
Since the used version of Solidity is
>=0.8.4
it would also be worth considering using Custom Errors which is both more gas efficient and allows thorough error descriptions using NatSpec.The relevant code:
Cache loanAmount
In the following code the variable
loanInfo[loanId].loanAmount
is read from storage 3 times (see audit-info comments), and hence should be cached so it is only read from storage once.Change this into
The change is passing the provided test suite, and the
.gas-snapshot
reflected the change by reducing the gas costs from:The text was updated successfully, but these errors were encountered: