Interest accrued could be zero for small decimal tokens
The interest calculation in PooledCreditLine.sol can round down to zero for tokens with few decimals when the principal is small and the time elapsed is short. An attacker could repeatedly borrow and repay tiny amounts to avoid paying any interest.
Submitted by hickuphh3
PooledCreditLine.sol#L1215-L1221
Interest is calculated as
(_principal.mul(_borrowRate).mul(_timeElapsed).div(YEAR_IN_SECONDS).div(SCALING_FACTOR));
It is possible for the calculated interest to be zero for principal tokens with small decimals, such as EURS (2 decimals). Accumulated interest can therefore be zero by borrowing / repaying tiny amounts frequently.
Proof of Concept
Assuming a borrow interest rate of 5% (5e17) and principal borrow amount of 10_000 EURS (10_000 * 1e2 = 1_000_000), the interest rate calculated would be 0 if principal updates are made every minute (around 63s).
// in this example, maximum duration for interest to be 0 is 63s
1_000_000 * 5e17 * 63 / (86400 * 365) / 1e18 = 0.99885 // = 0
While plausible, this method of interest evasion isn’t as economical for tokens of larger decimals like USDC and USDT (6 decimals).
Recommended Mitigation Steps
Take caution when allowing an asset to be borrowed. Alternatively, scale the principal amount to precision (1e18) amounts.
ritik99 (Sublime) disagreed with High severity and commented:
Tokens are whitelisted to ensure precision issues would not occur. Hence the issue is improbable and doesn’t occur for widely used tokens as the decimals are generally higher.
Since there is no direct attack path (the steps required for this to occur would be: the token would first have to be whitelisted -> a loan request created using it -> lenders supply sufficient liquidity for this request to go active) and is, in essence, a value leak, we would suggest reducing the severity of the issue to (1) Low / (2) Medium.
HardlyDifficult (judge) decreased severity to Medium
KushGoyal (Sublime) commented:
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 integer division truncation in the interest formula when the principal amount and elapsed time are small relative to the scaling factor.
Impact
Interest accrued could be zero, allowing borrowers to avoid interest payments, but only for whitelisted small-decimal tokens and with no direct attack path.
What the attacker needed
Token with small decimals is whitelisted; loan request created using that token; lenders supply sufficient liquidity
The fix
The project should take caution when allowing an asset to be borrowed, or scale the principal amount to 1e18 precision.
How it was found
- Assume a borrow interest rate of 5% and a principal of 10,000 EURS (2 decimals).
- Update the principal every minute (around 63 seconds).
- The calculated interest rounds down to zero each time.
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.
When a smart contract calculates interest, it does maths with whole numbers. If the result is a fraction smaller than one, it gets rounded down to zero. For tokens that have few decimal places, the numbers used in the calculation are small, so the interest can easily round down to zero, letting a borrower pay nothing.