Skip to content
DoS Audit finding Advanced

Broken safety cap in liquidate.rs causes permanent DoS of liquidation engine during market crashes, leading to insolvency.

The protocol caps debt_per_col and exchange_rate at 1e26, but this value exceeds the safe limit for the ratioX48 conversion, causing a revert in get_tick_at_ratio when debt_per_col is between ~4.62e25 and 1e26. This blocks all liquidations and vault operations during extreme market conditions, leading to bad debt.

ranzo Follow with 0xABSattar, AcsonBarbosa and 4 others

Originally disclosed on Code4rena

Submitted by ranzo, also found by 0xABSattar, AcsonBarbosa, edoscoba, happykilling, Khan2018, and legat

  • programs/vaults/src/utils/liquidate.rs #L152-L154
  • programs/vaults/src/utils/operate.rs #L41-L42

In get_ticks_from_oracle_price() (liquidate.rs) and get_sanitized_exchange_rate() (operate.rs), the protocol caps debt_per_col / exchange_rate at 10u128.pow(26) (1e26) to prevent precision loss. After capping, the value is converted into a ratioX48 format via:

let liquidation_ratio: u128 = safe_multiply_divide(
    debt_per_col,
    TickMath::ZERO_TICK_SCALED_RATIO, // 2^48 = 281474976710656
    10u128.pow(RATE_OUTPUT_DECIMALS), // 1e15
)?;

This ratio is then multiplied by the liquidation threshold (e.g., 900/1000 = 90%) and passed to TickMath::get_tick_at_ratio(), which enforces a hard upper bound of MAX_RATIOX48 ≈ 1.30e25.

The developer’s own inline comment confirms they verified the math for debt_per_col = 4e25 (which fits safely), but then set the cap at 1e26—more than 2× the safe limit—assuming the liquidation threshold multiplier would bring the result back within bounds. This assumption is incorrect: the threshold is applied after the conversion to ratioX48, so the intermediate liquidation_ratio already overflows MAX_RATIOX48 before any scaling down occurs.

Root Cause

The cap value 1e26 was chosen based on an incorrect analysis. The developer’s comment in liquidate.rs shows the safe boundary calculation was done for raw_col_per_debt (the inverse), not for debt_per_col used in the liquidation_ratio path. The two variables are computed from debt_per_col but feed into different downstream calculations with different bounds:

  • raw_col_per_debt = 1e30 / debt_per_col → at debt_per_col = 4e25, this gives ~4e25 * 2^48 / 1e15 ≈ 1.13e25 < MAX_RATIOX48 ✓
  • liquidation_ratio = debt_per_col * 2^48 / 1e15 → at debt_per_col = 1e26, this gives ≈ 2.81e25 > MAX_RATIOX48 ✗

The cap protects one path but breaks the other.

Impact

  • Liquidation DoS: When extreme market divergence pushes debt_per_col into the range [~4.62e25, 1e26], calls to get_ticks_from_oracle_price() revert with LibraryTickRatioOutOfBounds. This blocks all liquidations for the affected vault precisely when liquidation is most critical (collateral collapse or debt spike scenarios).
  • Operate DoS: The same cap in get_sanitized_exchange_rate() (operate.rs) means check_if_position_safe() also reverts, blocking deposits, withdrawals, borrows, and paybacks—freezing the vault entirely.
  • Bad debt accumulation: Positions that should be liquidated cannot be, leading to unbounded protocol loss. The safety mechanism (cap) fails its stated purpose of keeping the math within bounds.
  • The cap was designed to enable graceful degradation under extreme prices. Instead, it creates a hard revert window between ~4.62e25 and 1e26 where the protocol is completely inoperable.

Proof of Calculation

Step | Value |

debt_per_col (at cap) | 1e26 = 100_000_000_000_000_000_000_000_000 |

ZERO_TICK_SCALED_RATIO (2^48) | 281_474_976_710_656 |

RATE_OUTPUT_DECIMALS | 15 → divisor = 1e15 |

liquidation_ratio | 1e26 × 281474976710656 / 1e15 ≈ 2.81e25 |

threshold_ratio (LT=90%) | 2.81e25 × 900 / 1000 ≈ 2.53e25 |

max_ratio (LML=95%) | 2.81e25 × 950 / 1000 ≈ 2.67e25 |

MAX_RATIOX48 | ≈ 1.30e25 |

Result | 2.53e25 > 1.30e25 → REVERT |

Reverse Calculation for the Safe Cap

MAX_RATIOX48 = 13002088133096036565414295 ≈ 1.30e25
max safe liquidation_ratio = MAX_RATIOX48
max safe debt_per_col = MAX_RATIOX48 * 1e15 / 2^48
                      ≈ 1.30e25 * 1e15 / 2.81e14
                      ≈ 4.62e25

With a typical LT of 90%, the effective safe cap would be ~4.62e25 / 0.9 ≈ 5.13e25. The current cap of 1e26 is nearly 2× too high.

Even a conservative LT of 50% yields 4.62e25 / 0.5 = 9.24e25, still below 1e26.

Recommended Mitigation Steps

Reduce the cap to align with TickMath::MAX_RATIOX48. A safe cap should account for the highest possible LT/LML multiplier. Since liquidation_max_limit can be close to 100% (e.g., 950/1000 = 95%), the cap must satisfy:

cap * 2^48 / 1e15 * (LML / 1000) ≤ MAX_RATIOX48

For LML = 999 (near 100%, worst case):

cap ≤ MAX_RATIOX48 * 1e15 / 2^48 * 1000 / 999 ≈ 4.62e25

Apply the fix in both liquidate.rs and operate.rs:

  // liquidate.rs - get_ticks_from_oracle_price
- if debt_per_col > 10u128.pow(26) {
-     debt_per_col = 10u128.pow(26);
+ // Cap derived from MAX_RATIOX48 * 1e15 / 2^48 ≈ 4.62e25
+ // Rounded down for safety margin
+ if debt_per_col > 46_000_000_000_000_000_000_000_000 {
+     debt_per_col = 46_000_000_000_000_000_000_000_000;
  }
  // operate.rs - get_sanitized_exchange_rate
- if exchange_rate > 10u128.pow(26) {
-     exchange_rate = 10u128.pow(26);
+ if exchange_rate > 46_000_000_000_000_000_000_000_000 {
+     exchange_rate = 46_000_000_000_000_000_000_000_000;
  }

Proof of Concept

The vulnerability is a pure arithmetic overflow that can be demonstrated with a calculation trace. No on-chain PoC is needed as the revert path is deterministic.

Step-by-Step Scenario:

  1. A vault is configured with liquidation_threshold = 900 (90%) and liquidation_max_limit = 950 (95%).
  2. The collateral token’s price collapses, or the debt token’s price spikes, or vault exchange price magnifiers cause significant divergence between supply_ex_price and borrow_ex_price.
  3. debt_per_col computes to a value in the range [4.62e25, 1e26], for example 7e25.
  4. The cap at 1e26 does not activate (value is below cap).
  5. liquidation_ratio = 7e25 * 2^48 / 1e15 ≈ 1.97e25.
  6. threshold_ratio = 1.97e25 * 900 / 1000 ≈ 1.77e25.
  7. 1.77e25 > MAX_RATIOX48 (1.30e25) → get_tick_at_ratio reverts.
  8. All liquidation calls fail. Bad debt accumulates.

Note: Even without reaching the cap, debt_per_col values above ~4.62e25 can cause the revert depending on the LT/LML configuration. The cap merely fails to prevent this scenario—it should reject values above the safe threshold but currently allows values up to 2× the safe limit.

Sponsor team notes

The Jupiter Lend team commented:

This was fixed in https://github.com/Instadapp/fluid-contracts-solana/commit/d93a923acd134cd85c28f8c84af31e1b41a1a6da (PR #137)


The original report as published on Code4rena, by ranzo. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 cap of 1e26 was chosen based on a calculation for a different variable (raw_col_per_debt) and does not account for the fact that the liquidation threshold is applied after the ratioX48 conversion, so the intermediate value already exceeds MAX_RATIOX48.

Impact

All liquidations and vault operations (deposits, withdrawals, borrows, paybacks) are blocked when debt_per_col is in the range [~4.62e25, 1e26], leading to bad debt accumulation and potential insolvency.

What the attacker needed

Extreme market divergence; debt_per_col in [4.62e25, 1e26]

How it was found

  1. A vault is configured with liquidation_threshold = 900 and liquidation_max_limit = 950.
  2. Market conditions cause debt_per_col to reach a value between 4.62e25 and 1e26, for example 7e25.
  3. The cap at 1e26 does not activate because the value is below the cap.
  4. The liquidation_ratio is computed as debt_per_col * 2^48 / 1e15, which exceeds MAX_RATIOX48.
  5. The threshold_ratio is computed by multiplying by 900/1000, but it still exceeds MAX_RATIOX48.
  6. get_tick_at_ratio reverts with LibraryTickRatioOutOfBounds, causing all liquidation calls to fail.

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.

A safety cap is meant to stop numbers from getting too big, but the cap itself is set too high. When the ratio of debt to collateral gets very large, the code tries to convert it to a special format and hits a hard limit, causing the transaction to fail. This means the protocol cannot liquidate unhealthy positions or even process normal deposits and withdrawals, which can lead to financial losses.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More from Jupiter Lend

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.