-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Usage of safeApprove
will cause DoS in UniV2LiquidityAMO::addLiquidity
and UniV2LiquidityAMO::swap
#928
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
Comments
code423n4
added
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
labels
Sep 3, 2023
Finding is OOS, found by bot. |
bytes032 marked the issue as primary issue |
c4-pre-sort
added
the
primary issue
Highest quality submission among a set of duplicates
label
Sep 8, 2023
bytes032 marked the issue as low quality report |
This was referenced Sep 8, 2023
Closed
Closed
This was referenced Sep 8, 2023
Closed
Note: It might be more severe than L from the bot race, because of the impact. |
bytes032 marked the issue as duplicate of #1782 |
c4-pre-sort
added
duplicate-1782
sufficient quality report
This report is of sufficient quality
and removed
primary issue
Highest quality submission among a set of duplicates
low quality report
This report is of especially low quality
labels
Sep 11, 2023
bytes032 marked the issue as sufficient quality report |
c4-judge
added
the
unsatisfactory
does not satisfy C4 submission criteria; not eligible for awards
label
Oct 12, 2023
GalloDaSballo marked the issue as unsatisfactory: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/amo/UniV2LiquidityAmo.sol#L200-L207
https://github.com/code-423n4/2023-08-dopex/blob/eb4d4a201b3a75dd4bddc74a34e9c42c71d0d12f/contracts/amo/UniV2LiquidityAmo.sol#L328
Vulnerability details
OpenZeppelin's
SafeERC20::safeApprove
function contains the following code:So, as can be seen, it will revert if
value
is not0
andtoken.allowance
is not0
.This function is used in
UniV2LiquidityAMO::addLiquidity
and inUniV2LiquidityAMO::swap
:It's important to notice that
UniswapV2Router::addLiquidity
(called byUniV2LiquidityAMO::addLiquidity
does not guarantee that it will spend entiretokenAAmount
andtokenBAmount
- in fact it will almost always not spend full amounts - full amounts will only be spent iftokenAAmount / tokenBAmount
precisely equals the token ratio in the pool (even10 Wei
difference in provided amounts will cause a situation where less thantokenAAmount
ortokenBAmount
was spent.If that (almost certain) scenario happens, then the allowance for Uniswap will be nonzero for
tokenA
ortokenB
- assume that it is the case fortokenA
(which isrdpx
). It means thatsafeApprove
will fail for that token unless it is zeroed out. However, it is impossible to zero out that allowance:approveContractToSpend
, since there isrequire(_amount > 0)
there, so_amount
passed cannot be0
addLiquidity
withtokenAAmount == 0
sinceUniswapV2Library
will revert on thequote
function (https://github.com/Uniswap/v2-periphery/blob/0335e8f7e1bd1e8d8329fd300aea2ef2f36dd19f/contracts/libraries/UniswapV2Library.sol#L37; see PoC)swap
withtoken1Amount == 0
, sinceUniswapV2Library
will revert from thegetAmountOut
function (https://github.com/Uniswap/v2-periphery/blob/0335e8f7e1bd1e8d8329fd300aea2ef2f36dd19f/contracts/libraries/UniswapV2Library.sol#L44; see PoC)approve
orsafeApprove
onrdpx
, hence zeroing outrdpx
allowance for Uniswap is impossibleSo, both
UniV2LiquidityAMO::addLiquidity
andUniV2LiquidityAMO::swap
will always fail, so theUniV2LiquidityAMO
contract will become virtually useless.Impact
UniV2LiquidityAMO
contract will become virtually useless even after the very first call toaddLiquidity
- it won't be possible to calladdLiquidity
orswap
anymore.It will happen either after second liquidity provision (assuming that no liquidity was added by anyone earlier on to
WETH-RDPX
pair on Uniswap) or even after the first one (if there is already some liquidity onWETH-RDPX
pair - anyone can add it before using anyWETH / RDPX
ratio, so it is even possible to frontrun the first call toUniV2LiquidityAMO::addLiquidity
to make sure that it will not spend entirerdpx
allowance).It should be noted, that although
UniV2LiquidityAMO
will be impossible to use, allERC20
tokens (including LP tokens) can still be recovered by callingemergencyWithdraw
, so that is why I'm submitting this issue as Medium.Proof of Concept
Please execute the following test (in
Periphery.t.sol
):Tools Used
VS Code
Recommended Mitigation Steps
Substitute all calls to
safeApprove
with calls toapprove
to avoid reverting when the current allowance is non-zero.Assessed type
DoS
The text was updated successfully, but these errors were encountered: