Unspent allowance may break addLiquidity
functionality in UniV2LiquidityAMO
#876
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
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#L189
Vulnerability details
The
addLiquidity
function within theUniV2LiquidityAMO
contract can be called either byreLPContract
or directly as per the sponsors to add liquidity to RPDX/WETH pool. The function approves the AMM Router to spend a specific amount of tokenA and tokenB on behalf of the contract using thesafeApprove
method. However, it does not reset the previous approval to 0 before setting a new approval amount.If the actual amount used by the AMM Router's addLiquidity function is less than what was approved (because of the specified minimum amounts
tokenAAmountMin
/tokenBAmountMin
), there will be leftover approval. As a result, the next call toaddLiquidity
in the contract that attempts to approve a new amount will fail unless the previous approval is manually reset to 0.Impact
Due to the way the ERC20 approval mechanism works, if you try to change an existing non-zero approval without first setting it to 0, it will result in a revert. This means that if addLiquidity function of the AMM Router does not use all of the approved tokens, subsequent calls to the
addLiquidity
function in the provided contract will fail until someone manually resets the approval. This can result in a denial-of-service (DoS) condition for the contract, preventing liquidity from being added.Proof of Concept
addLiquidity
is called withtokenAAmount
= 100 andtokenBAmount
= 50.Tools Used
Manual review
Recommended Mitigation Steps
approve()
function from the ERC20 standard. This approach directly sets the allowance and avoids the potential pitfalls of managing incremental allowances.safeApprove
is essential for some safety reasons, always reset the allowance to zero before setting a new one.Assessed type
DoS
The text was updated successfully, but these errors were encountered: