Smart contract unable to operate due to lack of token funds
Description
Brief / Intro
A logic bug in _resolveRepaymentFee causes the contract to return the full computed repayment fee, while only deducting the clamped fee from the user’s collateral. The caller (_liquidate) then transfers the returned (uncapped) fee from the protocol contract to the liquidator. If the user’s collateral is smaller than the computed fee, the protocol pays the difference out of its own balance (vault shares / MYT). Repeating this can drain protocol-held MYT shares (yield), cause insolvent accounting and break core operations.
Vulnerability Details
Root cause
A Mismatch between what the function returns and what it actually deducts from the user.
The relevant code:
How this is used in _liquidate:
Problem: _resolveRepaymentFee computes fee (the full theoretical fee), but only deducts min(fee, account.collateralBalance) from the account. It returns fee unchanged. The caller then transfers fee from the protocol (contract) to the caller, so when fee > account.collateralBalance the protocol pays fee - accountCollateral out of its own balance.
This is an economic logic bug: the protocol can be made to overpay the liquidator relative to what the user actually had.
This might be inteded but repeating this operation will lead to draining protocol-held MYT shares, causing the depositors in suffer in future actions, for example causing DoS later when another user try to withdraw his MYT.
Consider using the FeeVaults for covering such a fees.
Impact Details
Direct theft of protocol-controlled yield: The protocol’s MYT/vault-share balance is transferred to an attacker (liquidator) beyond the user’s collateral. That is direct monetary loss for the protocol.
Protocol insolvency / inability to operate: Repeated drain reduces protocol reserves required to service redemptions or other payouts. If reserves run out, core functions (redeem, liquidate, repay) may revert or break.
Potential system-wide effects: Depleted reserves could force dependence on external funds, cause transmuter/backstop failures, or permit further cascading failures.
Add the following test in src/test/AlchemistV3.t.sol file and run it using this command forge test --mt test_PoC_RepaymentFee_ExceedsUserCollateral -vv