Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gas Optimizations #36

Closed
code423n4 opened this issue Apr 6, 2022 · 1 comment
Closed

Gas Optimizations #36

code423n4 opened this issue Apr 6, 2022 · 1 comment
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

Comments

@code423n4
Copy link
Contributor

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.

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Apr 6, 2022
code423n4 added a commit that referenced this issue Apr 6, 2022
@wilsoncusack
Copy link
Collaborator

this is not possible because we pass in LoanFacilitator address to the borrow and lend tickets on creation, so we do not have them when loan facilitator is created. Chicken and egg

@wilsoncusack wilsoncusack added the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label Apr 6, 2022
@gzeoneth gzeoneth added the invalid This doesn't seem right label Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

3 participants