Starting from Solidity v0.8.4, there is a convenient and gas-efficient way to explain to users why an operation failed through the use of custom errors. Until now, you could already use strings to give more information about failures (e.g., revert("Insufficient funds.");), but they are rather expensive, especially when it comes to deploy cost, and it is difficult to use dynamic information in them.
Source: https://blog.soliditylang.org/2021/04/21/custom-errors/
Mitigation
Consider using custom errors instead if the contract uses solidity version 0.8.4 or above.
Prefix Increments Cost Less Gas Than Suffix Increments
According to the fact that EVM is a stack-based machine with 256-bits size per stack. When the value are read or written in contract storage, a full 256-bits are read or written; so, packing multiple smaller variables in one slot can save more gas from reading and writing.
Mitigation
uint32 private blockTimestampLast can be declared next to the address public immutable override asset1 pack both variable in the same storage.
Custom Errors Should Be Used For Gas-optimization
Permalinks
Description
Mitigation
Consider using custom errors instead if the contract uses solidity version 0.8.4 or above.
Prefix Increments Cost Less Gas Than Suffix Increments
Permalinks
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/libraries/FullMath.sol#L124
Description
Using a prefix increment
++i
costs less gas than a suffix incrementi++
.Mitigation
Use prefix increment rather than suffix increment.
State Variables Can Be More Packed
Permalinks
https://github.com/code-423n4/2022-04-phuture/blob/594459d0865fb6603ba388b53f3f01648f5bb6fb/contracts/UniswapV2PriceOracle.sol#L29
Description
According to the fact that EVM is a stack-based machine with 256-bits size per stack. When the value are read or written in contract storage, a full 256-bits are read or written; so, packing multiple smaller variables in one slot can save more gas from reading and writing.
Mitigation
uint32 private blockTimestampLast
can be declared next to theaddress public immutable override asset1
pack both variable in the same storage.