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

2 stars 0 forks source link

Gas report #37

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Handle

wuwe1

Vulnerability details

Cache array length in for loops can save gas

POC

Caching the array length in the stack saves around 3 gas per iteration.

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

function claimRewards(address[] calldata _tokens) external override {
    for (uint256 i = 0; i < _tokens.length; i++) {
        uint256 getting = reward[msg.sender][_tokens[i]];
        IERC20(_tokens[i]).safeTransfer(msg.sender, getting);
        reward[msg.sender][_tokens[i]] = 0;
    }
}

Dead code

Remove dead code in

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

public to external

These function can be external.

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

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

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

state can be constant

These state variables can be constant

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

GalloDaSballo commented 2 years ago

Cache array length in for loops can save gas

3 gas

Remove dead code in

Agree but hard to quantify as it's deployment cost

public to external

Will not save any gas

state can be constant

Would have preferred the warden to do the work of showing the savings, but ultimately this finding is very valuable.

It will save 60k as that's the cost of storing the values. Additionally on each call it will save another 2100 * 2 = 4200 per call

_perMille will cost 2100 less per call

Total Savings 66303

GalloDaSballo commented 2 years ago

Am changing the math on how I calculate gas savings, will not add the 20k at deployment so the new total gas saved here is: 6303