Open code423n4 opened 2 years ago
1. Title: Using != is more gas efficient
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L614 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L772-L774
Recommended Mitigation Steps: Change to !=
!=
require(_value != 0);
========================================================================
2. Title: unnecessary variable set. the default value of uint is 0
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/Velo.sol#L9 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L584-L585 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L622
Recommended Mitigation Steps: remove 0 value
3. Title: Using storage to declare Struct variable inside function
storage
Proof of Concept: https://github.com/code-423n4/2022-05-rubicon/blob/main/contracts/rubiconPools/BathPair.sol#L299 https://github.com/code-423n4/2022-05-rubicon/blob/main/contracts/rubiconPools/BathPair.sol#L214 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L582-L583
Recommended Mitigation Steps:
LockedBalance storage _locked = locked[_tokenId];
4. Title: Using multiple require instead && can save gas
require
&&
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L307 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L846
require(attachments[_tokenId] == 0, "attached"); require(!voted[_tokenId], "attached");
5. Title: Using delete statement can save gas
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L484-L486 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L498-L500
delete ownerToNFTokenIdList[_from][current_count];
6. Title: Using calldata to store struct data type can save gas
calldata
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L579-L580
function _checkpoint( uint _tokenId, LockedBalance calldata old_locked, LockedBalance calldata new_locked ) internal {
7. Title: Cheaper to use ++ instead + 1
++
+ 1
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L705 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L1076
uint user_epoch = ++user_point_epoch[_tokenId];
8. Title: Use supply_before that already been cache
supply_before
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L730 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L854
supply_before += _value;
9. Title: Using msg.sender directly is more effective
msg.sender
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L746
Recommended Mitigation Steps: Using msg.sender directly instead of caching it to from. delete L#746 and replace all from with msg.sender
from
10. Title: Using > is cheaper than >=
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L849
Recommended Mitigation Steps: 1 second difference can be ignored to validate. using > operator can save gas
>
require(block.timestamp >= _locked.end, "The lock didn't expire");
11. Title: Gas opt to substract
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L895 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L951 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L1081
Recommended Mitigation Steps: Change to:
_max = --_mid;
12. Title: Caching .length for loop can save gas
.length
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L1146
uint256 Length = _tokenIds.length; for (uint i = 0; i < Length; i++) {
13. Title: Using += to increase value on var
+=
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L1148
votes += _balanceOfNFT(tId, block.timestamp);
14. Title: Gas improvement on returning lower value
lower
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L1153
Recommended Mitigation Steps: by setting lower in returns and deleting L#1168 can save gas
function getPastVotesIndex(address account, uint timestamp) public view returns (uint32 lower) { //@audit-info: set here
15. Title: Using unchecked and prefix increment
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L1225 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L1249
for (uint i = 0; i < srcRepOld.length;) { uint tId = srcRepOld[i]; if (tId != _tokenId) { srcRepNew.push(tId); } } unchecked{ ++i; //@audit-info: Place here with unchecked }
16. Title: Using unchecked can save gas
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/Voter.sol#L112
unchecked{ _totalWeight += _votes; }
Duplicate of #131
Minor gas savings, storage pointer type savings must have a POC to be valid.
Should save about 100 - 500 gas
1. Title: Using != is more gas efficient
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L614 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L772-L774
Recommended Mitigation Steps: Change to
!=
========================================================================
2. Title: unnecessary variable set. the default value of uint is 0
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/Velo.sol#L9 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L584-L585 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L622
Recommended Mitigation Steps: remove 0 value
========================================================================
3. Title: Using
storage
to declare Struct variable inside functionProof of Concept: https://github.com/code-423n4/2022-05-rubicon/blob/main/contracts/rubiconPools/BathPair.sol#L299 https://github.com/code-423n4/2022-05-rubicon/blob/main/contracts/rubiconPools/BathPair.sol#L214 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L582-L583
Recommended Mitigation Steps:
========================================================================
4. Title: Using multiple
require
instead&&
can save gasProof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L307 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L846
Recommended Mitigation Steps:
========================================================================
5. Title: Using delete statement can save gas
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L484-L486 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L498-L500
Recommended Mitigation Steps:
========================================================================
6. Title: Using
calldata
to store struct data type can save gasProof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L579-L580
Recommended Mitigation Steps:
========================================================================
7. Title: Cheaper to use
++
instead+ 1
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L705 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L1076
Recommended Mitigation Steps:
========================================================================
8. Title: Use
supply_before
that already been cacheProof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L730 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L854
Recommended Mitigation Steps:
========================================================================
9. Title: Using
msg.sender
directly is more effectiveProof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L746
Recommended Mitigation Steps: Using
msg.sender
directly instead of caching it tofrom
. delete L#746 and replace allfrom
withmsg.sender
========================================================================
10. Title: Using > is cheaper than >=
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L849
Recommended Mitigation Steps: 1 second difference can be ignored to validate. using
>
operator can save gas========================================================================
11. Title: Gas opt to substract
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L895 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L951 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L1081
Recommended Mitigation Steps: Change to:
========================================================================
12. Title: Caching
.length
for loop can save gasProof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L1146
Recommended Mitigation Steps: Change to:
========================================================================
13. Title: Using
+=
to increase value on varProof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L1148
Recommended Mitigation Steps: Change to:
========================================================================
14. Title: Gas improvement on returning
lower
valueProof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L1153
Recommended Mitigation Steps: by setting
lower
in returns and deleting L#1168 can save gas========================================================================
15. Title: Using unchecked and prefix increment
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L1225 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L1249
Recommended Mitigation Steps:
========================================================================
16. Title: Using unchecked can save gas
Proof of Concept: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/Voter.sol#L112
Recommended Mitigation Steps:
========================================================================