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

Open
code423n4 opened this issue May 24, 2022 · 0 comments
Open

Gas Optimizations #227

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

Comments

@code423n4
Copy link
Contributor

Save gas in for loops by unchecked arithmetic

The for loop has no overflow risk of i. Use an unchecked block to save gas.

Proof of Concept

AuraVestedEscrow.sol
100:        for (uint256 i = 0; i < _recipient.length; i++) {

ExtraRewardsDistributor.sol
233:        for (uint256 i = epochIndex; i < tokenEpochs; i++) {

AuraLocker.sol
174:            for (uint256 i = 0; i < rewardTokensLength; i++) {
306:        for (uint256 i; i < rewardTokensLength; i++) {
410:            for (uint256 i = nextUnlockIndex; i < length; i++) {
664:        for (uint256 i = locksLength; i > 0; i--) {
696:        for (uint256 i = nextUnlockIndex; i < locks.length; i++) {
726:        for (uint256 i = epochIndex + 1; i > 0; i--) {
773:        for (uint256 i = 0; i < userRewardsLength; i++) {

AuraClaimZap.sol
143:        for (uint256 i = 0; i < rewardContracts.length; i++) {
147:        for (uint256 i = 0; i < extraRewardContracts.length; i++) {
151:        for (uint256 i = 0; i < tokenRewardContracts.length; i++) {

Recommendation

Use unchecked blocks to avoid overflow checks, or use ++i rather than i++ if you don't use unchecked blocks.

for (uint256 i = 0; i < length; ) {
    ...
    unchecked {
        ++i;
    }
}
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels May 24, 2022
code423n4 added a commit that referenced this issue May 24, 2022
@0xMaharishi 0xMaharishi added the duplicate This issue or pull request already exists label May 27, 2022
@dmvt dmvt removed the duplicate This issue or pull request already exists label Jun 25, 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)
Projects
None yet
Development

No branches or pull requests

3 participants