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 #385

Open
code423n4 opened this issue Aug 6, 2022 · 0 comments
Open

Gas Optimizations #385

code423n4 opened this issue Aug 6, 2022 · 0 comments

Comments

@code423n4
Copy link
Contributor

Make ProjectFactory.homeFi immutable

Code: https://github.com/code-423n4/2022-08-rigor/blob/5ab7ea84a1516cb726421ef690af5bc41029f88f/contracts/Project.sol#L52

  • Project.homeFi can't be changed after init of the clone
  • Since ProjectFactory.homeFi can't be changed currently, that means it's also isn't changed across clones (i.e. all clones have the same value).
  • homeFi is used every tx at the Project contract, since every tx calls isTrustedForwarder()
  • The cost of reading homeFi from storage is 2.1K

Therefore consider making Project.homeFi immutable. If in the future you decide to make it modifiable, just change ProjectFactory.underlying contract and make it a storage var (or create the contract with a different value and keep it immutable).

Cache storage variable at ProjectFactory.createProject()

Code: https://github.com/code-423n4/2022-08-rigor/blob/5ab7ea84a1516cb726421ef690af5bc41029f88f/contracts/ProjectFactory.sol#L78-L93

Instead of reading homeFi from storage twice, cache it to memory. This will save ~100 gas units.

         returns (address _clone)
     {
+        address _homeFi = homeFi;
         // Revert if sender is not HomeFi
-        require(_msgSender() == homeFi, "PF::!HomeFiContract");
+        require(_msgSender() == _homeFi, "PF::!HomeFiContract");
 
         // Create clone of Project implementation
         _clone = ClonesUpgradeable.clone(underlying);
 
         // Initialize project
-        Project(_clone).initialize(_currency, _sender, homeFi);
+        Project(_clone).initialize(_currency, _sender, _homeFi);
     }
@code423n4 code423n4 added bug Something isn't working QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax labels Aug 6, 2022
code423n4 added a commit that referenced this issue Aug 6, 2022
@code423n4 code423n4 added G (Gas Optimization) and removed QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax labels Aug 6, 2022
@code423n4 code423n4 changed the title QA Report Gas Optimizations Aug 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants