Gas Optimizations #286
Labels
bug
Something isn't working
duplicate
This issue or pull request already exists
G (Gas Optimization)
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){
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
The text was updated successfully, but these errors were encountered: