Open code423n4 opened 2 years ago
Saves 20 gas per instance 3 * 20 60
5 per instance 10
Unchecked 20
Unchecked2 20
I don't believe this will save gas as when you copy in memory you are copying all fields once
Total Gas Savings 110
Formatting can be hugely improved, as well as submission format.
We think in problems not in files, so sending the same optimization in multiple files makes it more complex to deal with.
Unchecked Gas Optimisation in Minter.sol
A check is already made to make sure that
issuedNonInflationSupply
does not exceed a certain value so an arithmetic overflow is not possibleChange
issuedNonInflationSupply += amount;
tounchecked { issuedNonInflationSupply += amount;}
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/Minter.sol#L150-L154
Unchecked Gas Optimisations in AmmGauge.sol
We can make another unchecked addition because
totalStaked
will always be larger thanbalances[user]
Change
to
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/AmmGauge.sol#L112-L113
In Line 134 and 135 Change
to
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/AmmGauge.sol#L134-L135
KeeperGauge.sol
Change
epoch++
to++epoch
as talked about here https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/KeeperGauge.sol#L59 https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/KeeperGauge.sol#L98Change
to
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/tokenomics/KeeperGauge.sol#L87-L88
BkdLocker.sol
As we already make a value check we do not need to worry about arithmetic overflow Wrap
unchecked
aroundhttps://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/BkdLocker.sol#L119-L123
Again we have a similar issue
Change
to
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/BkdLocker.sol#L149-L152
curRewardTokenData.feeBalance
will always be larger than or equal tocurRewardTokenData.userShares[msg.sender]
of any user so we can change Line 216 tounchecked { curRewardTokenData.feeBalance -= claimable; }
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/BkdLocker.sol#L214-L216
Gas Savings in
_userCheckpoint()
inBkdLocker.sol
ContractVariables such as
boostFactors
andcurRewardTokenData
are read multiple times throughout the contract. This requires multiple SLOAD operations which are very expensive. It is better to load the variables into memory and use those when reading while the storage variables can be used for writing.See here for more info i.e.
can be changed to
This also applies to
boostFactors
andprevRewardTokenData
https://github.com/code-423n4/2022-05-backd/blob/2a5664d35cde5b036074edef3c1369b984d10010/protocol/contracts/BkdLocker.sol#L292-L335