Gas Optimizations #75
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")
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/tokenomics/KeeperGauge.sol#L4
Recommendation:
Remove unused libraries.
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/tokenomics/InflationManager.sol#L427-L428
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/tokenomics/InflationManager.sol#L461-L462
InflationManager
callpoolCheckPoint()
, then callkill()
function, but inside ofkill()
function,poolCheckPoint()
will be executed again.Recommendation:
Remove
poolCheckPoint()
call before kill.Cache length of array and use it in the loop is a good solution to reduce gas.
Other wise, it will always trying to load length from storage in every loop.
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/tokenomics/InflationManager.sol#L116
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/access/RoleManager.sol#L82
Recommendation
Cache length of array and use it in loop.
!=0
instead of>0
for uint non zero check.In most of places, there is something like
a > 0
for non-zero check.For Uint variables, there is no negative value, so it’s enough to change to
a != 0
.Ex.
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/tokenomics/KeeperGauge.sol#L140
Recommendation:
Use non-equal operator instead of greater operator for non-zero check.
lastEvent
inMinter.sol
can be update multiple times.https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/tokenomics/Minter.sol#L222
_mint
function updatelastEvent
twice – first update in Line 222, and second update insideexecuteInflationRateUpdate()
Recommendation:
Optimize code to avoid multiple updates.
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/tokenomics/Minter.sol#L56
There is a
IBkdToken
interface, but now it is usingBkdToken
(implementation contract) for external calls.This increase contract size.
Recommendation:
Use interface for external calls.
The text was updated successfully, but these errors were encountered: