code-423n4 / 2022-05-aura-findings

0 stars 1 forks source link

Gas Optimizations #325

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

2022-05-aura gas optimization

1 Delete unused import statements. The following lines can be deleted because they will be never used in the AuraToken. You can save deployment costs by deleting.

https://github.com/code-423n4/2022-05-aura/blob/main/contracts/Aura.sol#L4 https://github.com/code-423n4/2022-05-aura/blob/main/contracts/Aura.sol#L6 https://github.com/code-423n4/2022-05-aura/blob/main/contracts/Aura.sol#L7 https://github.com/code-423n4/2022-05-aura/blob/main/contracts/Aura.sol#L21 https://github.com/code-423n4/2022-05-aura/blob/main/contracts/Aura.sol#L22

Delete them.

2 use the initial value for uint256 in the following lines.

https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraBalRewardPool.sol#L35 https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraBalRewardPool.sol#L38 https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraBalRewardPool.sol#L39

3 missing validation for newOperator in updateOperator.

As the comment describes, this can be called if the operator of the voterProxy somehow changes. To avoid unnecessary state updates, you can add validation for the newOperator.

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

require(newOperator != operator, “Operator not changed”);

4 use initial value for uint256.

The initial value of uint256 is 0, so you can save gas costs without setting the default value for uint256.

https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraBalRewardPool.sol#L35 https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraBalRewardPool.sol#L38 https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraBalRewardPool.sol#L39

4 use initial value for bool.

https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraVestedEscrow.sol#L33

bool public initialised;

5 use cache for startTime in _totalVestedOf.

The startTime will be called twice in this function. You can save gas costs by using cache.

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

Uint256 _startTime = startTime;

if (_time < _startTime) {} for the line 158. uint256 elapsed = _time - _startTime; for the line 162.

6 code duplication.

The following lines have the same function and are used three times in the contract. You can save deployment costs if you use a modifier.

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

modifier onlyOwner { require(msg.sender == admin, "!auth"); _; }

7 use cache for auraLocker in _claim.

auraLocker will be used three times in the if sentence. Save gas by using a cache.

https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraVestedEscrow.sol#L185-L187

if (_lock) { IAuraLocker _auraLocker = auraLocker; require(address(_auraLocker) != address(0), "!auraLocker"); rewardToken.safeApprove(address(_auraLocker), claimable); auraLocker.lock(_recipient, claimable); } else {

8 delete unused state variable. The state variable endTime will be never used outside of the constructor, so it can be deleted.

https://github.com/code-423n4/2022-05-aura/blob/main/contracts/AuraVestedEscrow.sol#L64

Delete it.

9 use cache for voterProxy in claimFees.

voterProxy is used four times in clainFees. With cache, you can save gas costs.

https://github.com/code-423n4/2022-05-aura/blob/main/contracts/ClaimFeesHelper.sol#L47-L52

address _voterProxy = voterProxy;

uint256 bal = IERC20(_token).balanceOf(_voterProxy); feeDistro.claimToken(_voterProxy, _token); while (IERC20(_token).balanceOf(_voterProxy) <= bal) { feeDistro.claimToken(_voterProxy, _token); }

10 code duplication. The following lines are the same. You create a new modifier and can save deployment costs.

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

modifier onlyOwner { require(msg.sender == owner, "!auth"); _; }