Uni v2 AMO unspent allowance may break functionality on addLiquidity
#1335
Labels
2 (Med Risk)
Assets not at direct risk, but function/availability of the protocol could be impacted or leak value
bug
Something isn't working
duplicate-1782
sufficient quality report
This report is of sufficient quality
unsatisfactory
does not satisfy C4 submission criteria; not eligible for awards
Lines of code
https://github.com/code-423n4/2023-08-dopex/blob/main/contracts/amo/UniV2LiquidityAmo.sol#L200-L207
Vulnerability details
Impact
Uni v2 AMO unspent allowance may break functionality on
addLiquidity
Proof of Concept
The
UniV2LiquidityAmo
addLiquidity function contains severalsafeApprove
functions on tokenA and tokenB forammRouter
with amount (tokenAAmount, tokenBAmount) provided.The usage of this allowance is on
addLiquidity
function call on Uniswap v2 router, and by design it's possible that the usage of the allowance is not completely used, also theaddLiquidity
may only guarantee to use the amount based on the minimum parameter (the tokenAAmountMin and tokenBAmountMin).When there is a difference between tokenAAmount and tokenAAmountMin (also tokenBAmount and tokenBAmountMin), it means there is some allowance left for the router which is not being used. (allowance is not 0).
Then later, if there is another
addLiquidity
function call, it will be reverted. This is due to the definition ofsafeApprove
of Openzeppelinhttps://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.3/contracts/token/ERC20/utils/SafeERC20.sol#L45-L54
the above snippet shows that
safeApprove
need to make sure the existing allowance is 0. Thus, on our case, since the allowance is not 0 due to unspent allowance of previosaddLiquidity
, it will be reverted.This issue is valid medium referring to code-423n4/2023-05-xeth-findings#29
Note: Even though the deprecated usage of
safeApprove()
is mentioned in the automated findings, this report demonstrates how this function can cause a serious vulnerability that may end up bricking the contract.the custom
TransferHelper.safeApprove
doesn't effect of this issue. only the safeApprove based on OpenZeppelin.Tools Used
Manual Analysis
Recommended Mitigation Steps
Consider to use approve(), or reset the allowance to zero after any allowance usage, or use safeIncreaseAllowance().
Assessed type
DoS
The text was updated successfully, but these errors were encountered: