Omniscia SaucerSwap Labs Audit
UniswapV2Router02 Code Style Findings
UniswapV2Router02 Code Style Findings
UVR-01C: Confusing Terminology
Type | Severity | Location |
---|---|---|
Code Style | UniswapV2Router02.sol:L27, L28, L30 |
Description:
The terminology utilized by the UniswapV2Router02
is confusing as it has two wHBAR
variables (WHBAR
and whbar
).
Example:
25constructor(address _factory, address _WHBAR) public {26 factory = _factory;27 WHBAR = _WHBAR;28 address _whbar = IWHBAR(_WHBAR).token();29 safeAssociateToken(address(this), _whbar);30 whbar = _whbar;31}
Recommendation:
We advise the capitalized version of wHBAR
to be specified as WHBAR_OPERATOR
given that it is the operator of the actual wHBAR
token.
Alleviation (a2c5a0b913a7ddc21ff96f97fa51f2820a5da7ec):
The SaucerSwap has evaluated this exhibit but has opted to retain the current behaviour of the codebase thus acknowledging the exhibit.
UVR-02C: Redundant Disassociations of Token
Type | Severity | Location |
---|---|---|
Gas Optimization | UniswapV2Router02.sol:L200, L226 |
Description:
The referenced dissociations of native Hedera EIP-20 tokens are redundant as the HIP-367 has introduced an "unlimited" limit for token associations, further validated by the official Hedera Network documentation.
Example:
179function removeLiquidityETH(180 address token,181 uint liquidity,182 uint amountTokenMin,183 uint amountETHMin,184 address to,185 uint deadline186) public virtual override ensure(deadline) returns (uint amountToken, uint amountETH) {187 safeAssociateToken(address(this), token);188 (amountToken, amountETH) = removeLiquidity( 189 token,190 whbar, 191 liquidity,192 amountTokenMin,193 amountETHMin,194 address(this), // used to be msg.sender195 deadline196 );197 safeTransferToken(token, address(this), to, amountToken);198 safeApproveToken(whbar, WHBAR, amountETH);199 IWHBAR(WHBAR).withdraw(address(this), to, amountETH);200 safeDissociateToken(token);201}
Recommendation:
We advise the contract to not dissociate tokens after the removal of liquidity has been performed as these tokens are likely to be utilized in consequent liquidity removal calls, further optimizing the code's gas cost.
Alleviation (a2c5a0b913a7ddc21ff96f97fa51f2820a5da7ec):
The SaucerSwap has evaluated this exhibit but has opted to retain the current behaviour of the codebase thus acknowledging the exhibit.
UVR-03C: Redundant Duplicate Query of Pair
Type | Severity | Location |
---|---|---|
Gas Optimization | UniswapV2Router02.sol:L116, L118, L145-L146 |
Description:
The referenced invocations of IUniswapV2Factory::getPair
and UniswapV2Library::pairFor
are redundant as the former being non-zero guarantees that it will be equal to the latter's result.
Example:
106function addLiquidity(107 address tokenA,108 address tokenB,109 uint amountADesired,110 uint amountBDesired,111 uint amountAMin,112 uint amountBMin,113 address to,114 uint deadline115) external virtual override ensure(deadline) returns (uint amountA, uint amountB, uint liquidity) {116 require(IUniswapV2Factory(factory).getPair(tokenA, tokenB) != address(0), "UniswapV2Router: PAIR DOES NOT EXIST");117 (amountA, amountB) = _addLiquidity(tokenA, tokenB, amountADesired, amountBDesired, amountAMin, amountBMin);118 address pair = UniswapV2Library.pairFor(factory, tokenA, tokenB);119 120 safeTransferToken(121 tokenA, msg.sender, pair, amountA122 );123 safeTransferToken(124 tokenB, msg.sender, pair, amountB125 );126 liquidity = IUniswapV2Pair(pair).mint(to);127}
Recommendation:
We advise the result of the IUniswapV2Factory::getPair
call to be stored to a local variable that will consequently be used as the pair
to execute the mint operation on, optimizing each function's gas cost.
Alleviation (a2c5a0b913a7ddc21ff96f97fa51f2820a5da7ec):
Both redundant queries of a trading pair have been optimized as advised.