Output token is obtained from the first trade in SingleNativeTokenExitV2.exit #123
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
This issue or pull request already exists
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
Handle
hyh
Vulnerability details
Impact
Exit swaps in each trade are restricted to (basket_token_i, ..., WETH) sequences as the output token is read from the first trade.
This way any other correct trade structures will fail the function because of the output token amount check.
Proof of Concept
SingleNativeTokenExitV2.exit assumes that all trades will have the same output token and reads the output token from the first trade:
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/singleJoinExit/SingleNativeTokenExitV2.sol#L93
When trades are more complicated than that due to liquidity or suitability considerations,
for example, user wants to swap all the basket tokens to WETH, then WETH to USDC and withdraw it,
or when basket is (t1, t2, WBTC) user may want to swap t1 to WBTC, t2 to WETH, then WBTC to WETH, and withdraw it,
current logic fails and function will be reverted because of the final output token amount check:
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/singleJoinExit/SingleNativeTokenExitV2.sol#L100
Recommended Mitigation Steps
Fix the index to locate the last token in the swap sequence:
Now:
To be:
Also, the comment looks like it is temporary, can it be clarified?
https://github.com/code-423n4/2021-12-amun/blob/main/contracts/basket/contracts/singleJoinExit/SingleNativeTokenExitV2.sol#L96
The text was updated successfully, but these errors were encountered: