Users can avoid paying borrowing interest after the fyToken matures
A user can avoid paying borrowing interest after maturity by giving their vault to the Witch contract and then buying all collateral with underlying tokens, because the auction price is calculated without accounting for accrued interest. This allows the user to repay debt without the interest, and could disincentivise timely repayment.
Yield Witch v2 contest
Originally disclosed on Code4rena
According to the protocol design, users have to pay borrowing interest when repaying the debt with underlying tokens after maturity. However, a user can give his vault to Witch and then buy all his collateral using underlying tokens to avoid paying the interest. Besides, this bug could make users less incentivized to repay the debt before maturity and hold the underlying tokens until liquidation.
- A user creates a new vault and opens a borrowing position as usual.
- The maturity date passed. If the user wants to close the position using underlying tokens, he has to pay a borrowing interest (line 350 in
Ladle), which is his debt multiplied by the rate accrual (line 373). - Now, the user wants to avoid paying the borrowing interest. He gives his vault to
Witchby calling the functionbatchofLadlewith the operationGIVE. - He then calls the function
buyofWitchwith the correspondingvaultIdto buy all his collateral using underlying tokens.
In the last step, the elapsed time (line 61) is equal to the current timestamp since the vault is never grabbed by Witch before, and thus the auction time of the vault, cauldron.auctions(vaultId), is 0 (the default mapping value). Therefore, the collateral is sold at a price of balances_.art/balances_.ink (line 74). The user can buy balances_.ink amount of collateral using balances_.art but not paying for borrowing fees.
Recommend not allowing users to give vaults to Witch. And to be more careful, requiring vaultOwners[vaultId] and cauldron.auctions(vaultId) to be non-zero at the beginning of function buy.
albertocuestacanada (Yield) confirmed:
That’s a good catch. The mitigation steps are right to avoid this being exploited by malicious users, but it would be better to fix the underlying issue.
The problem is that the Witch always applies a 1:1 exchange rate between underlying and fyToken, which is not true after maturity. As long as this is not fixed, the protocol will lose money after maturity liquidations.
albertocuestacanada (Yield) commented:
More specifically,
_debtInBaseshould be a Cauldron public function, and return (debtInFYToken, debtInBase). The Ladle would save a bit in deployment gas; the Witch would use it to determine the underlying / fyToken exchange rate.
albertocuestacanada (Yield) commented:
However, since
grabwouldn’t be called on the Witch, the vault owner wouldn’t be registered. With the liquidation being a Dutch auction, the vault owner would only get a portion of his collateral back after paying all the debt. The vault with the remaining collateral would be given to address(0).There is a small protocol loss from miscalculated vault debt on vaults liquidated after maturity, but no user funds would be at risk.
I would propose a severity of 2, given there are monetary losses, however slight, to the protocol. The attack described can’t happen, but it revealed a real issue.
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
Likely the liquidation contract uses a 1:1 exchange rate between underlying and fyToken when calculating the auction price, which is incorrect after maturity when interest has accrued.
Impact
The user avoids paying borrowing interest, causing a monetary loss to the protocol; the text notes the loss may be slight and no user funds are at risk.
What the attacker needed
A vault with a borrowing position; maturity date has passed; user has underlying tokens
The fix
The underlying issue should be fixed by making the Witch use the correct exchange rate between underlying and fyToken after maturity, for example by exposing a function that returns debt in both tokens; additionally, the buy function should require non-zero vault owner and auction data.
How it was found
- Create a vault and open a borrowing position.
- Wait until the maturity date has passed.
- Give the vault to the Witch contract by calling the batch function with the GIVE operation.
- Call the buy function of Witch with the vaultId to buy all collateral using underlying tokens.
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.
In this lending protocol, borrowers normally pay interest when they repay after the loan matures. The report shows a way to skip that interest by transferring the vault to the liquidation contract and then buying back the collateral at a price that ignores the interest. This means the borrower pays less than they owe, and the protocol loses the interest.
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.