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

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

Gas Optimizations #335

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

Comments

@code423n4
Copy link
Contributor

  1. better use contatnt error intsead stinrg erro in solidy 0.8.4 higher

custom error from solidity 0.8.4 are cheaper than revert strings, custom error are defined using the error statement can use insideand outside the contract.

Custom errors are defined using the error statement, which can be used inside and outside of contracts

source https://blog.soliditylang.org/2021/04/21/custom-errors/

i suggestreplacing revert error strings with custom error.

POC :

https://github.com/code-423n4/2022-05-aura/blob/main/contracts/Aura.sol#L66
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/Aura.sol#L67
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/Aura.sol#L68
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/Aura.sol#L69
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/Aura.sol#L92
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/Aura.sol#L129
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraBalRewardPool.sol#L77
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraBalRewardPool.sol#L121
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraBalRewardPool.sol#L139
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraBalRewardPool.sol#L157
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraBalRewardPool.sol#L206
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraBalRewardPool.sol#L210
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraClaimZap.sol#L96
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraClaimZap.sol#L137
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMath.sol#L40
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMath.sol#L45
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMath.sol#L50
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMath.sol#L55
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMath.sol#L60
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L196
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L197
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L210
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L232
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L233
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L259
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L260
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L353
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L359
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L431
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L471
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L472
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L475
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L476
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L598
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L616
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L655
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L719
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L821
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L822
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L849
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L850
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L851
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMerkleDrop.sol#L69
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMerkleDrop.sol#L78
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMerkleDrop.sol#L84
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMerkleDrop.sol#L85
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMerkleDrop.sol#L91
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMerkleDrop.sol#L97
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMerkleDrop.sol#L98
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMerkleDrop.sol#L105
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMerkleDrop.sol#L119
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMerkleDrop.sol#L120
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMerkleDrop.sol#L121
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMerkleDrop.sol#L122
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMerkleDrop.sol#L123
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMerkleDrop.sol#L126
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMerkleDrop.sol#L152
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraMinter.sol#L32
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraPenaltyForwarder.sol#L48
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraStakingProxy.sol#L89
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraStakingProxy.sol#L90
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraStakingProxy.sol#L100
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraStakingProxy.sol#L108
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraStakingProxy.sol#L116
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraStakingProxy.sol#L117
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraStakingProxy.sol#L128
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraStakingProxy.sol#L129
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraStakingProxy.sol#L138
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraStakingProxy.sol#L158
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraStakingProxy.sol#L159
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraStakingProxy.sol#L172
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraStakingProxy.sol#L203
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraVestedEscrow.sol#L56
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraVestedEscrow.sol#L57
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraVestedEscrow.sol#L66
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraVestedEscrow.sol#L78
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraVestedEscrow.sol#L87
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraVestedEscrow.sol#L97
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraVestedEscrow.sol#L117
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraVestedEscrow.sol#L118
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraVestedEscrow.sol#L185
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/BalLiquidityProvider.sol#L47
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/BalLiquidityProvider.sol#L48
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/BalLiquidityProvider.sol#L49
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/BalLiquidityProvider.sol#L53
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/BalLiquidityProvider.sol#L57
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/BalLiquidityProvider.sol#L65
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/BalLiquidityProvider.sol#L70
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/BalLiquidityProvider.sol#L79
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/BalLiquidityProvider.sol#L89
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/ClaimFeesHelper.sol#L45
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/CrvDepositorWrapper.sol#L42
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/CrvDepositorWrapper.sol#L119
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/ExtraRewardsDistributor.sol#L68
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/ExtraRewardsDistributor.sol#L74
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/ExtraRewardsDistributor.sol#L171
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/ExtraRewardsDistributor.sol#L172

  1. Consider making some constants as non-public to save gas

Reducing from public to private or internal can save gas when a constant isn’t used outside of its contract. I suggest changing the visibility from public to internal or private
POC :

https://github.com/code-423n4/2022-05-aura/blob/main/contracts/Aura.sol#L28
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/Aura.sol#L29

  1. > 0 is less efficient then !=0 for unsignet interger

While it may seem that > 0 is cheaper than !=, this is only true without the optimizer enabled and outside a require statement. If you
enable the optimizer at 10k AND you’re in a require statement, this will save gas.

https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L259
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L822
https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L851

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