Gas Optimizations #128
Labels
bug
Something isn't working
G (Gas Optimization)
resolved
Finding has been patched by sponsor (sponsor pls link to PR containing fix)
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
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 herehttps://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#L98
Change
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
The text was updated successfully, but these errors were encountered: