Gas Optimizations #107
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")
Title: Caching
.length
for loop can save gasProof of Concept:
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/access/RoleManager.sol#L82
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/zaps/PoolMigrationZap.sol#L39
Recommended Mitigation Steps:
Change to:
========================================================================
Title: Using != is more gas efficient
Proof of Concept:
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/BkdLocker.sol#L91
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/BkdLocker.sol#L254
Recommended Mitigation Steps:
Change to
!=
========================================================================
Title: Using delete statement to empty
curRewardTokenData.userShares
can save gasProof of Concept:
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/BkdLocker.sol#L215
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/utils/Preparable.sol#L87-L88
Recommended Mitigation Steps:
========================================================================
Title: Gas improvement on returning
totalEthRequired
valueProof of Concept:
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/Controller.sol#L121-L130
Recommended Mitigation Steps:
by set
totalEthRequired
in returns and delete L#123 can save gas========================================================================
Title: Using unchecked to calculate
Proof of Concept:
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/StakerVault.sol#L124
Recommended Mitigation Steps:
balances[msg.sender]
value was checked that it >= thanamount
so using unchecked can save gas:========================================================================
Title: Unnecessary MSTORE
timeElapsed
Proof of Concept:
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/tokenomics/AmmGauge.sol#L144-L149
Recommended Mitigation Steps:
By passing
block.timestamp - uint256(ammLastUpdated)
directly to L#148 without storing it totimeElapsed
can save gas without damaging readability of the code========================================================================
Title: Unnecessary MSTORE
Proof of Concept:
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/BkdLocker.sol#L138-L144
Recommended Mitigation Steps:
instead of caching
length
toi
. use it directly can save gasdelete L#138 and replace
i
with `length========================================================================
Title: Use
allowance_
directly to substractProof of Concept:
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/StakerVault.sol#L387
Recommended Mitigation Steps:
========================================================================
Title: Unnecessary
bool
var setProof of Concept:
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/tokenomics/InflationManager.sol#L412
Recommended Mitigation Steps:
the default value of
bool
isfalse
========================================================================
Title: Using
>
instead>=
can save gasProof of Concept:
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/tokenomics/VestedEscrow.sol#L57
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/utils/Preparable.sol#L110
Recommended Mitigation Steps:
1 second difference can be ignored to validate. using
>
operator can save gas========================================================================
Title: Use custom errors rather than revert()/require() strings to save deployment gas
Proof of Concept:
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/tokenomics/VestedEscrowRevocable.sol#L53-L54
reference: https://blog.soliditylang.org/2021/04/21/custom-errors/
========================================================================
Title: Using
+=
to increase valueProof of Concept:
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/tokenomics/VestedEscrow.sol#L145
Recommended Mitigation Steps:
Change to:
========================================================================
14
Title: Unnecessary MSTORE
Proof of Concept:
https://github.com/code-423n4/2022-05-backd/blob/main/protocol/contracts/tokenomics/VestedEscrow.sol#L155-L156
Recommended Mitigation Steps:
instead of caching to
elapsed
. calculate directly can save gasdelete L#155
========================================================================
The text was updated successfully, but these errors were encountered: