Open code423n4 opened 2 years ago
1) 9 gas 2) Would like to see proof that it actually saves gas, per the docs this won't save gas
MastChef.sol 1) -> 2.1k per variable per read -> 6.1k 2) -> 2.1k per variable per read -> 6.1k 3) Not sure if we can remove this as the sponsor may want to always use non-zero indexes 4) Saves a SLOT, let's say 2k gas (one less Cold Slot) 5) Disagree as syntactic sugar won't save gas
VoteProxy.sol 1) Would like to see proof but I agree, will give it an ISZERO, 3 gas
USDMPegRecovery.sol 1) Agree, 2.1k 2) Agree, 2.1k 3) Agree, 200 gas (STATICCALL + Hot Slot Read)
ConvexStakingWrapper.sol 1) Would save 200 gas (Hot SLOAD + Same Value SSTORE)
18812 Gas Saved by implementing these findings
General issues
Change the incremental logic from
i++
to++i
in order to save some opcodes:Use delete instead of set to default value (
false
or 0)Contracts specific
Contract contracts\MasterChef.sol
The following variables could be declared as constant:
The following variables could be declared as immutable:
There was an empty pool in lines L63-L70, pushed during the constructor that never is used.
The following struct could be optimized moving
depositFeeBP
close todepositToken
in order to save one storage slot:On line 204, the
transferSuccess
variable is init false, it is better to create the variable with the return to avoid this initialization.Contract contracts\VoteProxy.sol
== true
in order to save some opcodes.Contract contracts\USDMPegRecovery.sol
startLiquidity
is never used and can be removed or changed to immutable.step
coud be constant.usdm.balanceOf(address(this))
was called twice without any change of balance, it's cheaper to cache it.Contract contracts\ConvexStakingWrapper.sol
deposits[_pid][msg.sender].amount
inside the ifif (_amount > 0) {