Open code423n4 opened 2 years ago
3 per instance 6
Saves 3 gas, only for require, solidity < 0.8.13, when using optimizer 3
Disagree, delete is the same as setting to default value
I don't believe it will save gas, it's just syntactic sugar, in lack of math I can only give it 0 gas saved
Agree, this will save 20 gas 20
Saves 6 gas but does make the code more complex to scan
I guess, saves 6 gas, notice that the sponsor forgot to use the cached length
inside the loop, that would be a more rational refactoring
Avoiding the =- saves a SLOAD which saves 100 gas
Saves 3 gas
I assume this will save the extra eq, hence saves 3 gas
In lack of POC i can't give it points
Doesn't save gas
Saves 6 gas and makes the code pretty ugly
Total Gas Saved 153
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:
========================================================================
2. 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
!=
========================================================================
3. 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:
========================================================================
4. 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========================================================================
5. 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:========================================================================
6. 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========================================================================
7. 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 gas delete L#138 and replacei
with `length========================================================================
8. 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:
========================================================================
9. 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
========================================================================
10. 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========================================================================
11. 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/
========================================================================
13. 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 gas delete L#155========================================================================