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

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

Gas Optimizations #141

code423n4 opened this issue May 21, 2022 · 0 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

!=0 cost less gas compared to >0

mitigation: use != instead of >
details/POC: >0 can be replaced with !=0 because all unsigned integers that are not equal to zero are all positive values which means it is always greater than zero.
reference: [https://github.com/code-423n4/2021-12-maple-findings/issues/75]
affected codes:
/contracts/AuraBalRewardPool.sol#L121
/contracts/AuraBalRewardPool.sol#L139
/contracts/AuraBalRewardPool.sol#L157
/contracts/AuraBalRewardPool.sol#L210
/contracts/AuraClaimZap.sol#L196
/contracts/AuraClaimZap.sol#L200
/contracts/AuraClaimZap.sol#L218
/contracts/AuraClaimZap.sol#L221
/contracts/AuraLocker.sol#L210
/contracts/AuraLocker.sol#L259
/contracts/AuraLocker.sol#L309
/contracts/AuraLocker.sol#L359
/contracts/AuraLocker.sol#L385
/contracts/AuraLocker.sol#L400
/contracts/AuraLocker.sol#L443
/contracts/AuraLocker.sol#L471
/contracts/AuraLocker.sol#L496
/contracts/AuraLocker.sol#L520
/contracts/AuraLocker.sol#L664
/contracts/AuraLocker.sol#L726
/contracts/AuraLocker.sol#L822
/contracts/AuraLocker.sol#L851
/contracts/AuraMerkleDrop.sol#L122
/contracts/AuraPenaltyForwarder.sol#L52
/contracts/AuraStakingProxy.sol#L177
/contracts/AuraStakingProxy.sol#L185
/contracts/AuraStakingProxy.sol#L207
/contracts/AuraVestedEscrow.sol#L118
/contracts/BalLiquidityProvider.sol#L57
/contracts/BalLiquidityProvider.sol#L70
/contracts/ExtraRewardsDistributor.sol#L149
/contracts/ExtraRewardsDistributor.sol#L171
/contracts/Aura.sol#L68

--i cost less gas compared to i--

mitigation: Use --i instead of i-- to decrement the value of uint variable
affected codes:
/contracts/AuraLocker.sol#L497
/contracts/AuraLocker.sol#L726
/contracts/AuraLocker.sol#L664

++i cost less gas compared to i++

mitigation: Use ++i instead of i++ to increment the value of uint variable
reference: code-423n4/2021-12-nftx-findings#195
affected codes:
/contracts/AuraVestedEscrow.sol#L100
/contracts/BalLiquidityProvider.sol#L51
/contracts/ExtraRewardsDistributor.sol#L233
/contracts/AuraLocker.sol#L174
/contracts/AuraLocker.sol#L306
/contracts/AuraLocker.sol#L410
/contracts/AuraLocker.sol#L696
/contracts/AuraLocker.sol#L773

No need to name the returns

details: Using both named returns and a return statement isn't necessary
mitigation: change returns (uint256 amount) to returns (uint256)
affected code:
/contracts/AuraLocker.sol#L648
same issue:
/contracts/AuraLocker.sol#L712

No need to explicitly initialize variables with their default values

details: When variables are not set, it is assumed to have it's default value(0 for uint, false for bool, address(0) for address...).
mitigation: change uint public pendingPenalty = 0 to uint public pendingPenalty
affected code:
/contracts/AuraBalRewardPool.sol#L35
same issue:
/contracts/AuraBalRewardPool.sol#L38
/contracts/AuraBalRewardPool.sol#L39
/contracts/AuraLocker.sol#L72
/contracts/AuraLocker.sol#L114
/contracts/AuraLocker.sol#L174
/contracts/AuraLocker.sol#L485
/contracts/AuraLocker.sol#L630
/contracts/AuraLocker.sol#L773
/contracts/AuraMerkleDrop.sol#29
/contracts/AuraVestedEscrow.sol#L33
/contracts/AuraVestedEscrow.sol#L99
/contracts/AuraVestedEscrow.sol#L100
/contracts/ExtraRewardsDistributor.sol#L231

.length in a loop can be extracted into a variable and used where necessary to reduce the number of storage reads
solution:
uint locksLength = locks.length;
for (uint256 i = nextUnlockIndex; i < locksLength; i++) { if (locks[i].unlockTime > block.timestamp) { if (idx == 0) { lockData = new LockedBalance[](locksLength - i);
affected code:
/contracts/AuraLocker.sol#L696-699
reference: code-423n4/2021-10-union-findings#92

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels May 21, 2022
code423n4 added a commit that referenced this issue May 21, 2022
@0xMaharishi 0xMaharishi added the duplicate This issue or pull request already exists label May 26, 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 duplicate This issue or pull request already exists G (Gas Optimization)
Projects
None yet
Development

No branches or pull requests

2 participants