Gas Optimizations #36
Labels
bug
Something isn't working
G (Gas Optimization)
invalid
This doesn't seem right
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Title: Use lendTicketContract, borrowTicketContract as immutable variables
Impact
For any variable that is only set once, either use a constant or immutable to save gas. The compiler does not reserve a storage slot for these variables, and every occurrence is replaced by the respective value (Source: https://docs.soliditylang.org/en/v0.6.5/contracts.html#constant-and-immutable-state-variables)
Recommended Mitigation Steps
Remove functions setLendTicketContract() and setBorrowTicketContract(), change variables lendTicketContract, borrowTicketContract as immutable and initialize them in constructor:
https://github.com/code-423n4/2022-04-backed/blob/main/contracts/NFTLoanFacilitator.sol#L275-L293
Title: Use Solidity v0.8.4 because of Solidity Custom Errors
Impact
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. Custom errors decrease both deploy and runtime gas costs. Source: https://blog.soliditylang.org/2021/04/21/custom-errors/
OpenZeppelin is also planing to use custom errors starting with next major release 5.0.
Source release v5.0: OpenZeppelin/openzeppelin-contracts#2961
Source OZ custom error issue: OpenZeppelin/openzeppelin-contracts#2839
Recommended Mitigation Steps
Refactor code and use Solidity custom errors.
The text was updated successfully, but these errors were encountered: