Algo Ssstablecoinsss

AI First Flight #2
Beginner FriendlyDeFi
EXP
View results
Submission Details
Impact: medium
Likelihood: medium
Invalid

Liquidation Bonus Calculation Precision Issues

Root + Impact

Description

  • * Liquidators receive a 10% bonus on the collateral they seize when liquidating unhealthy positions. The bonus is calculated based on the token amount derived from the debt to cover.

    * The liquidation bonus is calculated using the token amount derived from USD debt value at the current price. If prices change between when the liquidator calculates the bonus and when the transaction executes, or due to rounding in the calculation, the bonus may not be exactly 10% of the debt value.

    ```vyper

    @external

    def liquidate(collateral: address, user: address, debt_to_cover: uint256):

    assert debt_to_cover > 0, "DSCEngine__NeedsMoreThanZero"

    starting_user_health_factor: uint256 = self._health_factor(user)

    assert (

    starting_user_health_factor < MIN_HEALTH_FACTOR

    ), "DSCEngine__HealthFactorOk"

    token_amount_from_debt_covered: uint256 = self._get_token_amount_from_usd(

    collateral, debt_to_cover // @> Price used here

    )

    bonus_collateral: uint256 = (

    token_amount_from_debt_covered * LIQUIDATION_BONUS // @> Bonus calculated on token amount

    ) // LIQUIDATION_PRECISION

    self._redeem_collateral(

    collateral,

    token_amount_from_debt_covered + bonus_collateral, // @> Bonus may not be exactly 10% of debt value

    user,

    msg.sender,

    )

    ```


Risk

Likelihood:

  • * Price changes between calculation and execution can affect the actual bonus percentage

    * Integer division rounding can cause the bonus to be slightly more or less than 10%

    * Large debt amounts with small price movements can result in significant bonus discrepancies

Impact:

  • * Liquidators may receive more or less than the intended 10% bonus, affecting protocol economics

    * Inconsistent bonus amounts could lead to arbitrage opportunities

    * Protocol may pay more in bonuses than intended over time

Proof of Concept

```python
# Scenario:
# 1. User has 1000 DSC debt, ETH price = $2000
# 2. token_amount_from_debt_covered = 1000 * 1e18 / (2000 * 1e8 * 1e10) = 0.5 ETH
# 3. bonus_collateral = 0.5 * 10 / 100 = 0.05 ETH
# 4. Total collateral = 0.55 ETH
# 5. Actual USD value of bonus = 0.05 * 2000 = $100
# 6. But if price changes to $2100, bonus USD value = $105 (10.5% of debt)
```

Recommended Mitigation

```diff
@external
def liquidate(collateral: address, user: address, debt_to_cover: uint256):
assert debt_to_cover > 0, "DSCEngine__NeedsMoreThanZero"
starting_user_health_factor: uint256 = self._health_factor(user)
assert (
starting_user_health_factor < MIN_HEALTH_FACTOR
), "DSCEngine__HealthFactorOk"
token_amount_from_debt_covered: uint256 = self._get_token_amount_from_usd(
collateral, debt_to_cover
)
- bonus_collateral: uint256 = (
- token_amount_from_debt_covered * LIQUIDATION_BONUS
- ) // LIQUIDATION_PRECISION
+ # Calculate bonus based on USD value to ensure exactly 10%
+ bonus_usd_value: uint256 = (debt_to_cover * LIQUIDATION_BONUS) // LIQUIDATION_PRECISION
+ bonus_collateral: uint256 = self._get_token_amount_from_usd(collateral, bonus_usd_value)
self._redeem_collateral(
collateral,
token_amount_from_debt_covered + bonus_collateral,
user,
msg.sender,
)
```
Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge 16 days ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!