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

Open
code423n4 opened this issue Jun 2, 2022 · 1 comment
Open

Gas Optimizations #61

code423n4 opened this issue Jun 2, 2022 · 1 comment
Labels
bug Something isn't working 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")

Comments

@code423n4
Copy link
Contributor

G-1 COMPARISONS WITH ZERO FOR UNSIGNED INTEGERS
>0 is less gas efficient than !0 only if you enable optimizer and you're in a require statement.
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/BkdLocker.sol#:~:text=require(amount%20%3E%200%2C%20Error.INVALID_AMOUNT)%3B

G-2 An length should be cached to save gas in for-loops
Some of the for-loops in other contracts already have been doing this but the one below hasn't.
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/StakerVault.sol#:~:text=for%20(uint256%20i%3B%20i%20%3C%20actions.length%3B%20i%20%3D%20i.uncheckedInc())%20%7B

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Jun 2, 2022
code423n4 added a commit that referenced this issue Jun 2, 2022
@chase-manning chase-manning added sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) labels Jun 6, 2022
@GalloDaSballo
Copy link
Collaborator

Saves 6 gas in total

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

No branches or pull requests

3 participants