Attackers may skip the collateral ratio recovery duration to inflate collateralization ratios and steal funds
The collateralization ratio update mechanism can be bypassed by gifting a small amount of loan token to the pool, causing the utilization calculation to incorrectly apply a large time delta as an increase rather than a decrease. An attacker can then borrow at an inflated collateralization ratio, stealing funds from the pool.
Source: https://github.com/sherlock-audit/2023-02-surge-judging/issues/130
Found by
usmannk
Summary
Under certain market conditions, attackers can bypass the collateralization ratio update system to instantly send the collateralization ratio from zero to maximum.
The collateralization ratio in Surge defines the amount of loan token that can be borrowed per wei of collateral token. In this way it acts as both a collateralization ratio as in other lending markets but also as an exchange rate, as the ratio is taken directly between the two tokens instead of through an intermediary such as dollars.
A Surge pool linearly decreaes the collateralization ratio to zero when it is in "Surge mode", in order to reduce demand. When the pool is not in "Surge mode", it increases the collateralization ratio similarly up to the preset maximum. However, an attacker can use a quirk in the way the utilization is calculated to instantly send a pool from zero to the maximum, greatly manipulating the exchange rate.
Vulnerability Detail
https://github.com/sherlock-audit/2023-02-surge/blob/main/surge-protocol-v1/src/Pool.sol#L216-L263
The collateralization ratio is calculated as either
_lastCollateralRatioMantissa + timeDelta * _maxCollateralRatioMantissa / _collateralRatioRecoveryDuration
or
_lastCollateralRatioMantissa - timeDelta * _maxCollateralRatioMantissa / _collateralRatioFallDuration
Depending on whether the contract is not, or is, in Surge mode (respectively).
Consider a pool that has been in a state that is just under Surge mode for a long time. That is _util <= _surgeMantissa but the two values are very close together. There have not been any interactions with the pool in a while so timeDelta is large. This means that the next interaction with the pool will use a collateralization ratio of 0.
An attacker can bypass this by gifting a small amount of the loan token to the contract. This will cause the utilization (_util) to go up on the next calculation.
Now even though the contract has not been in surge mode, on the next interaction it will think that it has been and the large timeDelta will be applied to a collateralization ratio increase instead of a collateralization ratio decrease.
The attacker can take advantage of the maximum collateralization ratio to borrow funds at an inflated valuation, stealing assets from the pool because they were able to skip the _collateralRatioRecoveryDuration.
Impact
Loss of funds from pool depositors.
Code Snippet
Tool used
Manual Review
Recommendation
When calculating utilization, only use the most recently cached values of token balances instead of using live values.
Discussion
xeious
Fixed
xeious
https://github.com/Surge-fi/surge-protocol-v1/commit/95fa486d7356482e3e8b6d8c43d93a5cf482be1b
IAm0x52
Fix looks good. Loan token balance is now cached as lastLoanTokenBalance instead of using balanceOf. This value is cached at the end of all state changing functions
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 utilization calculation uses live token balances instead of cached values, allowing an attacker to manipulate utilization by transferring tokens directly to the contract.
Impact
Loss of funds from pool depositors.
What the attacker needed
Pool is just under Surge mode for a long time; Attacker can transfer loan tokens to the pool
The fix
The fix caches the loan token balance instead of using balanceOf, updating it at the end of all state-changing functions.
How it was found
- Wait until the pool has been just under Surge mode for a long time, so timeDelta is large.
- Gift a small amount of loan token to the pool contract to increase utilization.
- On the next interaction, the contract incorrectly applies the large timeDelta as an increase to the collateralization ratio.
- Borrow funds at the inflated maximum collateralization ratio, stealing assets from the pool.
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 lending pool uses a collateralization ratio to decide how much you can borrow for each unit of collateral. This ratio normally changes gradually over time, but an attacker can trick the pool into thinking it should jump straight to the maximum by sending a tiny amount of the loan token to the contract. That lets them borrow more than they should and take other people's money.
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.