code-423n4 / 2022-02-concur-findings

2 stars 0 forks source link

Gas Optimizations #169

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Gas Optimization

ConvexStakingWrapper.sol

1 check _amount earlier in deposit

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/ConvexStakingWrapper.sol#L228-L250

require(_amount > 0, “amount is 0”); at the beginning of code and delete if sentence.

2 check _amount earlier in withdraw

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/ConvexStakingWrapper.sol#L256-L274

require(_amount > 0, “amount is 0”); at the beginning of code and delete if sentence.

3 uint256 has a default value of 0, so you don’t need to set 0 to save a little bit of gas in for loop

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/ConvexStakingWrapper.sol#L121 https://github.com/code-423n4/2022-02-concur/blob/main/contracts/ConvexStakingWrapper.sol#L219

For (uint256 i; i < count; i++) {}

4 Use whenNotPaused() from Ownable.sol in _checkpoint

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/ConvexStakingWrapper.sol#L209-L211

function _checkpoint(uint256 _pid, address _account) internal whenNotPaused {}

And delete whenNotPaused from deposit().

MasterChef.sol

5 No need SafeMath import. Since Solidity 0.8, the overflow/underflow check is implemented on the language level

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L10

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L14

Delete them and can change the following lines

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L89

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L109

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L120-L121

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L151-L152

6 uint256 has a default value of 0, so you don’t need to set 0 to save a little bit of gas in for loop

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L129

For (uint256 i; i < count; i++) {}

7 Unused Event. EmergencyWithdraw is not used? If not, you can delete it.

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L19

8 Unchangrable variables can be set as constant to save gas.

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L50

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L56

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L57

9 No need to set 0 because the variable has a default value.

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L51

10 Input must be checked earlier to save gas

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L90

use this require after the first require.

USDMPegRecovery.sol

11 Unchangeable variables can be immutable. There are no functions to update uint256 step and uint256 startLiquidity, That’s why they can be immutable variables and they can save gas.

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/USDMPegRecovery.sol#L22

https://github.com/code-423n4/2022-02-concur/blob/main/contracts/USDMPegRecovery.sol#L24

GalloDaSballo commented 2 years ago

1 check _amount earlier in deposit and 2 Valid but saves gas only on "Bad path"

3 uint256 has a default value of 0, so you don’t need to set 0 to save a little bit of gas in for loop 3 gas * 2 = 6

4 Use whenNotPaused() from Ownable.sol in _checkpoint Don't think this will save gas

5 No need SafeMath import. Since Solidity 0.8, the overflow/underflow check is implemented on the language level Valid but no explanation so no points

6 uint256 has a default value of 0, so you don’t need to set 0 to save a little bit of gas in for loop 3 gas saved

7 Unused Event. Valid but saves only deployment cost

8 Unchangrable variables can be set as constant to save gas. Because no POC will give 2100 per variable = 6300

9 No need to set 0 because the variable has a default value. 100 gas saved

10 Input must be checked earlier to save gas Same as 1 and 2

11 Unchangeable variables can be immutable. There are no functions to update uint256 step and uint256 startLiquidity, That’s why they can be immutable variables and they can save gas. Same as 8, 4200

Total Gas saved: 10509

Formatting of titles could have been better, but overall fine report