Omniscia Teahouse Finance Audit
UniswapV3PathRecommender Code Style Findings
UniswapV3PathRecommender Code Style Findings
UVP-01C: Generic Typographic Mistake
| Type | Severity | Location |
|---|---|---|
| Code Style | ![]() | UniswapV3PathRecommender.sol:L15 |
Description:
The referenced line contains a typographical mistake (i.e. private variable without an underscore prefix) or generic documentational error (i.e. copy-paste) that should be corrected.
Example:
15mapping(address => mapping(address => bytes[2])) private swapPath;Recommendation:
We advise this to be done so to enhance the legibility of the codebase.
Alleviation (302b96f324a88038a0872015466cd43783c14543):
The underscore prefix has been properly introduced to the swapPath contract-level variable, addressing this exhibit.
UVP-02C: Ineffectual Usage of Safe Arithmetics
| Type | Severity | Location |
|---|---|---|
| Language Specific | ![]() | UniswapV3PathRecommender.sol:L39, L40 |
Description:
The linked mathematical operation is guaranteed to be performed safely by surrounding conditionals evaluated in either require checks or if-else constructs.
Example:
38for (uint256 i; i < feesLength; i = i + 1) {39 pathExactInput = bytes.concat(pathExactInput, abi.encodePacked(_fees[i], _tokens[i + 1]));40 pathExactOutput = bytes.concat(pathExactOutput, abi.encodePacked(_fees[feesLength - i - 1], _tokens[feesLength - i - 1]));41}Recommendation:
Given that safe arithmetics are toggled on by default in pragma versions of 0.8.X, we advise the linked statement to be wrapped in an unchecked code block thereby optimizing its execution cost.
Alleviation (302b96f324a88038a0872015466cd43783c14543):
The referenced arithmetic operations have been wrapped in an unchecked code block, optimizing the code's gas cost.
UVP-03C: Inefficient Emissions of Contextual Variable
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | ![]() | UniswapV3PathRecommender.sol:L43, L53 |
Description:
The SwapPathSet and SwapPathDeleted events will emit the current block.timestamp redundantly as it is already attached to the transaction that each event is emitted in.
Example:
44emit SwapPathSet(block.timestamp, srcToken, dstToken, pathExactInput, pathExactOutput);Recommendation:
We advise such contextual information to not be emitted as part of the event, optimizing their gas cost while minimizing their data redundancy.
Alleviation (302b96f324a88038a0872015466cd43783c14543):
The block.timestamp variable has been removed from the SwapPathSet and SwapPathDeleted events, optimizing their emission gas cost.
UVP-04C: Loop Iterator Optimization
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | ![]() | UniswapV3PathRecommender.sol:L38 |
Description:
The linked for loop increments / decrements the iterator "safely" due to Solidity's built-in safe arithmetics (post-0.8.X).
Example:
38for (uint256 i; i < feesLength; i = i + 1) {Recommendation:
We advise the increment / decrement operation to be performed in an unchecked code block as the last statement within the for loop to optimize its execution cost.
Alleviation (302b96f324a88038a0872015466cd43783c14543):
The for loop itself has been wrapped in an unchecked code block as part of the UVP-02C remediations, addressing this exhibit.
UVP-05C: Potential Usability Enhancement
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | ![]() | UniswapV3PathRecommender.sol:L48 |
Description:
The UniswapV3PathRecommender::getRecommendedPath function will utilize an _isExactInput boolean input and convert it to either a 0 or 1 index depending on whether it is true or false respectively.
Example:
47function getRecommendedPath(bool _isExactInput, address _srcToken, address _dstToken) external view returns (bytes memory path) {48 return _isExactInput ? swapPath[_srcToken][_dstToken][0] : swapPath[_srcToken][_dstToken][1];49}Recommendation:
We advise an enum to be utilized instead, optimizing the function's gas cost as well as style.
Alleviation (302b96f324):
An enum is now utilized, however, it is not defined as an input argument to the UniswapV3PathRecommender::getRecommendedPath function. We advise this to be performed, rendering the ternary operator redundant.
Alleviation (1dc136da87):
The code was instead updated to utilize bool values as the key to the _swapPath mapping, permitting the input bool values of the referenced functions to be utilized directly and thus addressing this exhibit as the code is now optimal.
UVP-06C: Redundant Recalculation of Value
| Type | Severity | Location |
|---|---|---|
| Gas Optimization | ![]() | UniswapV3PathRecommender.sol:L40 |
Description:
The feesLength - 1 calculation is carried out twice on each iteration of the for loop inefficiently.
Example:
38for (uint256 i; i < feesLength; i = i + 1) {39 pathExactInput = bytes.concat(pathExactInput, abi.encodePacked(_fees[i], _tokens[i + 1]));40 pathExactOutput = bytes.concat(pathExactOutput, abi.encodePacked(_fees[feesLength - i - 1], _tokens[feesLength - i - 1]));41}Recommendation:
We advise it to be cached to a local variable outside the for loop, significantly optimizing each for loop's execution.
Alleviation (302b96f324a88038a0872015466cd43783c14543):
The feesLength - 1 calculation is now cached outside the for loop to a feeLengthMinus1 variable, optimizing the code's gas cost.
