Ammalgam-1 Fixes

Code Freeze: 65d8558e068f3ecf4cff03db158c8996ecbe1402

Context

Trusted Entities:

Issues Found

Severity Tag Count
Critical (C-1) 1
High (H-1) 3
Medium (M-1) 1
Low (L-1) -
Code Quality (Q-1) 1
Gas Optimization (G-1) -
Informational (I-1) 2

[C-1] Repayment of debt can be skipped in hard liquidations

Topic Liquidations
Impact critical
Likelihood high

There are 3 different types of liquidations, hard, soft and leverage, that can be specified when calling liquidate(). In the case of a hard liquidation where debt is directly paid and collateral is transferred to the liquidator at a discount to incentivize the liquidator. This functionality is handled by liquidateHard(). Instead of the protocol directly calculating the the amount of assets to transfer to the liquidator or assets to repay debt, these parameters are provided by the liquidator and verified to be correct via Liquidation.checkHardDiscounts() which calculates the max liquidator discount given the account, and compares this discount with the discount being requested based on the inputed repay and deposit asset parameters. Repayment can occur using X/Y tokens, and or repayment in the Liquidity tokens LX and LY, with each being handled differently. In the case of repayment with LX and LY, it is required and expected that both tokens are payed at once:

if (0 < repayLXInXAssets && 0 < repayLYInYAssets) {
    repayCallback(repayLXInXAssets, repayLYInYAssets);
    (uint256 actualRepaidLXInXAssets, uint256 actualRepaidLYInYAssets,) = _repayLiquidity(borrower);

    // check that at least promised amount was repaid
    verifyRepay(actualRepaidLXInXAssets, repayLXInXAssets, actualRepaidLYInYAssets, repayLYInYAssets);
}

Reference: AmmalgamPair.sol#L760-766

However, this assumes that both repayLXInXAssets and repayLYInYAssets are greater than zero, in the case where only one is greater than zero, it will skip this branch and thus skip the repayment step entirely, jumping directly to transferring assets to the liquidator. This allows anyone to drain assets from the protocol, creating bad debt and resulting in potential insolvency.

Remediations to Consider

Ensure that both repayLXInXAssets and repayLYInYAssets if one is greater than zero to ensure repayment occurs as expected.


[H-1] Mint and burn operations should affect liquidation price and saturation

Topic Protocol Design
Impact high
Likelihood high