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

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

Gas Optimizations #111

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

Comments

@code423n4
Copy link
Contributor

Gas

For small gas savings (little goes a long way)

Within the “if” and “require” statement (which necessitates a condition), for readability and to save gas, remove the explicit use of the Boolean terms.

VoterProxy.sol

https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L93-L97

https://github.com/code-423n4/2022-05-vetoken/blob/main/contracts/VoterProxy.sol#L110-L113

Booster.sol

https://github.com/code-423n4/2022-05-vetoken/blob/2d7cd1f6780a9bcc8387dea8fecfbd758462c152/contracts/Booster.sol#L352

https://github.com/code-423n4/2022-05-vetoken/blob/2d7cd1f6780a9bcc8387dea8fecfbd758462c152/contracts/Booster.sol#L498

For eg, Use if(!x) or(x) {

…..

}

and require(x) or (! x)

Use unchecked block

https://github.com/code-423n4/2022-05-vetoken/blob/2d7cd1f6780a9bcc8387dea8fecfbd758462c152/contracts/VoterProxy.sol#L131

https://github.com/code-423n4/2022-05-vetoken/blob/2d7cd1f6780a9bcc8387dea8fecfbd758462c152/contracts/VeAssetDepositor.sol#L148

https://github.com/code-423n4/2022-05-vetoken/blob/2d7cd1f6780a9bcc8387dea8fecfbd758462c152/contracts/VeTokenMinter.sol#L61

https://github.com/code-423n4/2022-05-vetoken/blob/2d7cd1f6780a9bcc8387dea8fecfbd758462c152/contracts/Booster.sol#L529

https://github.com/code-423n4/2022-05-vetoken/blob/2d7cd1f6780a9bcc8387dea8fecfbd758462c152/contracts/BaseRewardPool.sol#L332

https://github.com/code-423n4/2022-05-vetoken/blob/2d7cd1f6780a9bcc8387dea8fecfbd758462c152/contracts/VE3DRewardPool.sol#L375

Check whether a non-zero value exists before accessing the state variable

Below, totalWeight is being decremented before anything is added. This would be waste gas when an address is being added for the first time without any weight :

https://github.com/code-423n4/2022-05-vetoken/blob/2d7cd1f6780a9bcc8387dea8fecfbd758462c152/contracts/VeTokenMinter.sol#L43

Use an if statement prior to reducing the totalWeight which checks whether the specific asset has any weight.

For eg,
if (veAssetWeight[_asset] >0){

……

}

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

Effectively just a recommendation to use the unchecked block, without the math nor further details.

Would save less than 500 gas overall

Considering marking invalid against 50+ submissions

@GalloDaSballo
Copy link
Collaborator

Downgrading to 100 gas saved, but maintaing as valid

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

2 participants