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

Open
code423n4 opened this issue May 8, 2022 · 2 comments
Open

Gas Optimizations #199

code423n4 opened this issue May 8, 2022 · 2 comments
Labels
bug Something isn't working G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

Title: Use 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

Change variables as immutable.

globalBeneficiary PermissionlessBasicPoolFactory.sol:
https://github.com/code-423n4/2022-05-factorydao/blob/main/contracts/PermissionlessBasicPoolFactory.sol#L51

gateMaster MerkleEligibility.sol:
https://github.com/code-423n4/2022-05-factorydao/blob/main/contracts/MerkleEligibility.sol#L16


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.


Title: Unused .call() return data

Impact

Removing unused return variable improves code readability and can improve gas costs

Recommended Mitigation Steps

Change:
(bool sent, bytes memory data) = gate.beneficiary.call{value: msg.value}("");
To:
(bool sent, ) = gate.beneficiary.call{value: msg.value}("");
https://github.com/code-423n4/2022-05-factorydao/blob/main/contracts/SpeedBumpPriceGate.sol#L79

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

illuzen commented May 12, 2022

All duplicates

@illuzen illuzen closed this as completed May 12, 2022
@itsmetechjay itsmetechjay reopened this May 12, 2022
@gititGoro
Copy link
Collaborator

For the customs error item, the code uses a newer version of solidity than 0.8.4. The suggestion will simply be treated as "use custom errors".

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)
Projects
None yet
Development

No branches or pull requests

4 participants