sherlock-audit / 2022-10-merit-circle-judging

1 stars 0 forks source link

nalus - Some Gas and QA improvement proposals #79

Closed sherlock-admin closed 2 years ago

sherlock-admin commented 2 years ago

nalus

low

Some Gas and QA improvement proposals

QA:

  1. Line too long https://github.com/Merit-Circle/merit-liquidity-mining/blob/ce5feaae19126079d309ac8dd9a81372648437f1/contracts/base/BasePool.sol#L34

  2. Would be informative to have a condition for rewardToken not to be 0. https://github.com/Merit-Circle/merit-liquidity-mining/blob/ce5feaae19126079d309ac8dd9a81372648437f1/contracts/base/BasePool.sol#L110

  3. Remove "hardhat/console.sol" as its only ment for testing

Gas

  1. Use calldata instead of memory in function parameters to reduce gas costs. https://github.com/Merit-Circle/merit-liquidity-mining/blob/ce5feaae19126079d309ac8dd9a81372648437f1/contracts/base/BasePool.sol#L49-L50

  2. Use immutable instead of constants since its more gas efficient. https://github.com/Merit-Circle/merit-liquidity-mining/blob/ce5feaae19126079d309ac8dd9a81372648437f1/contracts/TimeLockPool.sol#L22

  3. Storing private variables is creaper than public ones, so use private wherever possible. https://github.com/Merit-Circle/merit-liquidity-mining/blob/ce5feaae19126079d309ac8dd9a81372648437f1/contracts/base/BasePool.sol#L26-L30

  4. IT COSTS MORE GAS TO INITIALIZE VARIABLES WITH THEIR DEFAULT VALUE THAN LETTING THE DEFAULT VALUE BE APPLIED Example: for (uint256 i = 0; i < numIterations; ++i) { should be replaced with for (uint256 i; i < numIterations; ++i) {

  5. i++ costs more gas than ++i Example: for (uint256 i; i < numIterations; i++) { should be replaced with for (uint256 i; i < numIterations; ++i) {

  6. AN ARRAY’S LENGTH SHOULD BE CACHED TO SAVE GAS IN FOR-LOOPS Example: for (uint256 i; i < iterations.length; ++i) { should be replaced with for (uint256 i; i < numIterations; ++i) {

  7. INCREMENTS CAN BE UNCHECKED Example: for (uint256 i; i < iterations.length; ++i) { should be replaced with for (uint256 i; i < numIterations) { unchecked {++i; }

  8. Deposit is already defined in TimeLockPool, which is imported. https://github.com/Merit-Circle/merit-liquidity-mining/blob/ce5feaae19126079d309ac8dd9a81372648437f1/contracts/View.sol#L10