Open code423n4 opened 2 years ago
3 gas
3
Disagree especially with optimizer on
6 gas
Disagree wholeheartedly as the cost of reading from storage is way higher
Valid but no POC on savings so 0
103 gas saved
2100 * 2 = 4200
Won't cost more gas
You're storing 2 bytes 32 (2500 gas), also reading from storage twice, are you sure this saves gas?
200
2100
Happy to disagree
Saves 6 gas
467 gas (h/t #245)
2100 * 3 = 6300
Changes the functionality
6 gas saved
Honestly want to commend the warden for having a different opinion, formatting can be improved and most importantly would recommend they add POC when they make "storage can save gas" statements
Total Gas Saved: 13394
GAS OPTIMIZATION
--1 -unnecessary
i
value set https://github.com/code-423n4/2022-02-concur/blob/main/contracts/ConcurRewardPool.sol#L35 unnecessary value set. the default value of uint is zero. just use:--2 -better increment https://github.com/code-423n4/2022-02-concur/blob/main/contracts/ConcurRewardPool.sol#L35 change i++ to ++i --3 -Best way to use
SafeERC20.function
for gas opt https://github.com/code-423n4/2022-02-concur/blob/main/contracts/ConcurRewardPool.sol#L10 by not declare:and use:
can safe gas usage. --4 -unnecessary variable declaration -Unnecessary (uint)
getting
variable declaration https://github.com/code-423n4/2022-02-concur/blob/main/contracts/ConcurRewardPool.sol#L36 instead of cachingreward[msg.sender][_tokens[i]]
ingetting
, better just pass it directly intosafeTransfer()
function.getting
was declared and called once per loop. It cost more gas.recommended mitigation:
ConvexStakingWrapper.sol
--5 -Using
storage
to declare Struct variable inside function https://github.com/code-423n4/2022-02-concur/blob/main/contracts/ConvexStakingWrapper.sol#L171 instead of cachingrewardType
to memory. read it directly from storage.--6 -Using
uint
insteadstruct
https://github.com/code-423n4/2022-02-concur/blob/main/contracts/ConvexStakingWrapper.sol#L24 TheReward
struct merely contain 1 property. Instead of declaring it as struct, better as a uint example: uint128 integralReward(example name); https://github.com/code-423n4/2022-02-concur/blob/main/contracts/ConvexStakingWrapper.sol#L44 then modify theuserReward
mapping output fromReward
touint
.MasterChef.sol
--7 -unnecessary
totalAllocPoint
&_pid
value set https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L51 https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L129 unnecessary value set. the default value of uint is zero. just use:--8 -use constant for gas saving https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L57 use
constant
to declare_perMille
&_concurShareMultiplier
uint --9 -Unused library https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L15 unused SafeERC20 libShelter.sol
--10 -
&&
is more expensive gas https://github.com/code-423n4/2022-02-concur/blob/main/contracts/Shelter.sol#L45 using multiplerequire()
is cheaper than use &&--11 -unnecessary value set https://github.com/code-423n4/2022-02-concur/blob/main/contracts/StakingRewards.sol#L21-L22 unnecessary value set. the default value of uint is zero for
rewardRate
&periodFinish
. uint default value is 0 --12 -step
declaration https://github.com/code-423n4/2022-02-concur/blob/main/contracts/USDMPegRecovery.sol#L22 setting thestep
value directly and useconstant
can save gas. then remove the line: https://github.com/code-423n4/2022-02-concur/blob/main/contracts/USDMPegRecovery.sol#L56 --13 -using storage to declare struct inside function https://github.com/code-423n4/2022-02-concur/blob/main/contracts/USDMPegRecovery.sol#L91 instead of cachingLiquidity
in memory. just read it directly to storageit can save gas. And same for
user
variable right below it. --14 -unnecessary math operation https://github.com/code-423n4/2022-02-concur/blob/main/contracts/ConvexStakingWrapper.sol#L116-L117 the value ofregisteredRewards[_pid][crv]
andregisteredRewards[_pid][cvx]
is fixed, Set the value(1 and 2) directly then add additional info which explain the math operation behind it:--15 -use calldata to store
signature
https://github.com/code-423n4/2022-02-concur/blob/main/contracts/EasySign.sol#L51 replace memory with calldata to save gas --16 -Usingimmutable
to declare variable which set once at constructor https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L52-L54startBlock
,endBlock
&concur
are set once in constructor. Useimmutable
--17 -userequire()
to validate insteadif()
https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L137 by using:to replace:
can save gas with the same output 18-- -Unncessary
multiplier
(uint) declaration https://github.com/code-423n4/2022-02-concur/blob/main/contracts/MasterChef.sol#L150-L151multiplier
is called once inupdatePool()
. Its gas consuming to cachegetMultiplier
return inmultiplier
. Remove line 150, and change line it to: