Call to swapExactTokensForETH in liquidateDai() will always fail
The liquidateDai() function calls Uniswap's swapExactTokensForETH without first approving the UniswapV2 router to spend the Dai tokens. As a result, the swap always fails and the function reverts, preventing the intended liquidation and updateCostShareRequest() from completing.
FairSide contest
Originally disclosed on Code4rena
liquidateDai() calls Uniswap’s swapExactTokensForETH to swap Dai to ETH. This will work if msg.sender (i.e., the FSD contract) has already given the router an allowance amount that is at least as much as the input token Dai.
Given that there is no prior approval, the call to UniswapV2 router for swapping will fail. This is because msg.sender has not approved UniswapV2 with an allowance for the tokens that are attempting to be swapped.
The impact is that, while working with the Dai stablecoin, updateCostShareRequest() will fail and revert.
Recommend adding FSD approval to UniswapV2 with an allowance for the tokens that are attempting to be swapped.
fairside-core (FairSide) confirmed:
Fixed in PR#19.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The contract calls the Uniswap router to swap Dai without first calling approve() to grant the router an allowance for those Dai tokens.
Impact
The Dai liquidation path always reverts, so updateCostShareRequest() cannot complete when Dai is involved.
What the attacker needed
None
The fix
The contract was fixed by adding an approval to UniswapV2 for the tokens being swapped.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a smart contract wants to swap tokens on a decentralised exchange, it must first give the exchange permission to take those tokens. This is called an allowance. Here, the contract tried to swap without giving that permission, so the exchange refused and the whole operation failed.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.