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

2 stars 0 forks source link

Gas Optimizations #256

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago
GalloDaSballo commented 2 years ago

Repeated external call to usdm.balanceOf(address(this):

Would save 100 for the call + 100 for SLOAD = 200 - 6 = 194

Don't need to call owner() here, you can just use msg.sender:

Saves 8 gas (JUMP)

Long revert messages, e.g.:

2500 (1 message shown)

Variables that are set in the constructor and can't be changed can be marked as immutable:

7 * 2100 = 14700

Variables and events that are not used in any meaningful way can be removed or used where they were intended:

Valid but not at runtime

Would be cheapier to use local variables when emitting events, e.g.:

194 gas saved

Usually under normal conditions, the first check is not neccessary, as GRACE_PERIOD > block.timestamp should always revert:

Saves 100 for SLOAD + 3 for check 103

This could be inlined to optimize for gas usage, from:

Saves 9 gas

Repeated access of storage variables should be cached, e.g. convexBooster is accessed 3 times:

94 + 94 - 6 = 182 94 94 Total = 370

The initialization to default variables is not necessary:

200

If the same MasterChef implementation will be used, then the pid of the token can't change, so you should cache it once (in the constructor call), and do not make the external calls again and again in stake and withdraw functions of StakingRewards:

Saves 100 gas

Contract MasterChef has declared a compiler version of ^0.8.11 but it still uses the SafeMath library:

7 * 20 = 140 gas saved

Would be cheaper if you checked not the storage but the _amount paramater against 0 in the first sentence:

Valid but only for "bad path"

currentEpoch() is called twice, should cache after the first call:

91 gas saved (97 -6)

You already have the address of rewardToken() here, no need to fetch it again:

191 (100 call 97 - 6 SLOAD)

In _calcRewardIntegral I think these statements:

Only for bad path

Total Gas Saved: 18800