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

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

Gas Optimizations #286

code423n4 opened this issue May 25, 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

Gas

I. pendingPenalty will be accessed unnecessarily if there's no penalty stored. To prevent continuous access of the state variable and it being updated to zero(already the default), check whether there's any penalty before resetting to zero.

AuraBalRewardPool.sol

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraBalRewardPool.sol#L197

Add the following lines to forwardPenalty() :

if (toForward>0){

 pendingPenalty = 0;
     } 

The same applies for :

AuraMerkleDrop.sol

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraMerkleDrop.sol#L151

II. epochIndex already caches the length of the epoch. Therefore, replace all reference to the state variable below with the local variable:

https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraLocker.sol#L334-L335

III.Utilise unchecked block to save gas

The calculation for penalty will always be the smallest of the two operands :

AuraMerkleDrop.sol

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraMerkleDrop.sol#L138

AuraBalRewardPool.sol

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraBalRewardPool.sol#L185

Remove AuraMath.sub() as the condition necessitates that rdata.periodFinish is the larger operand and will not underflow:

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraLocker.sol#L866

AuraVestedEscrow.sol

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraVestedEscrow.sol#L162

@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
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