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

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

Gas Optimizations #325

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

Comments

@code423n4
Copy link
Contributor

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");
_;
}

@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 Jul 4, 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