Unlike transfer() and transferFrom() functions were implemented (which returning the _transfer() return value directly). mint() function is returning true
RECOMMENDED MITIGATION STEP
The declaration order of state variables affects storage slot packing and gas impact from reads/writes of shared slots. By placing stable var next to any address var can save 1 slot for storage which can make more efficient for reading the storage and gas usage
GAS
1. Title: Unnecessary
_mint()
in constructor() https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/Velo.sol#L22Minting 0 amount of token is unnecessary and wasting deployment gas. I recommend to remove L22
2. Title: Unnecessary
allowed_from
MSTORE https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/Velo.sol#L61MSTORing to
allowed_from
is wasting gas since its just called once in the function RECOMMENDED MITIGATION STEP3. Title: Returning _mint() value directly https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/Velo.sol#L71 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/Velo.sol#L77
Unlike
transfer()
andtransferFrom()
functions were implemented (which returning the _transfer() return value directly).mint()
function is returning true RECOMMENDED MITIGATION STEP4. Title: Using prefix increment than postfix increment https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L137
Using prefix increment is way cheaper for gas usage than postfix increment Change to:
5. Title: Better way to do decrement and increment https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L142 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L655
Instead of using -= 1 to decrease value by 1, using --var is more optimum Change to:
6. Title: Using && operator is inefficient https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L307
Instead of using && operator. Using multiple require can save 15 execution gas per call Change to:
7. Title: Using != instead of > Occurrence: https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L369 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L591 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L595 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L785
Using != operator is way more effective than > to validate that the var value is not zero
8. Title: Using delete statement 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 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L1071
Instead of set the mapping value to 0, using delete statement is more effective and can save 4 gas each call Change to:
9. Title: Using unchecked for increase i value in for() https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L632 https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L1325
Using unchecked{++i;} can save a lot of gas
10. Title: Unnecessary msg.sender MSTORE https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/VotingEscrow.sol#L746
MLOAD are way more expensive than just call msg.sender. So, MSTORing msg.sender is wasting gas. I recommend just remove L746 and just use msg.sender
11. Title: Storage slot packing impacts gas efficiency https://github.com/code-423n4/2022-05-velodrome/blob/main/contracts/contracts/Pair.sol#L18
The declaration order of state variables affects storage slot packing and gas impact from reads/writes of shared slots. By placing
stable
var next to any address var can save 1 slot for storage which can make more efficient for reading the storage and gas usage