A critical inconsistency exists in the debt tracking mechanism between the lending protocol's borrow function and the DebtToken's mint function. While DebtToken properly handles interest accrual through index scaling, the borrow function's debt tracking fails to account for accrued interest on existing debt. This mismatch creates a discrepancy between the actual user debt (tracked by DebtToken balance) and the internal accounting (scaledDebtBalance).
The vulnerability manifests when a user with existing debt borrows additional funds. The core issue lies in how the borrow function updates scaledDebtBalance without considering previously accrued interest, while the DebtToken correctly accounts for this interest in its minting process.
Consider this scenario:
User initially borrows 1000 tokens at index 1.0 RAY
scaledDebtBalance = 1000e18
DebtToken balance = 1000e18
Index increases to 1.1 RAY (10% interest accrual)
User borrows additional 500 tokens
borrow function adds: scaledAmount = 500e18/1.1e27 ≈ 454.54e18
New scaledDebtBalance = 1000e18 + 454.54e18 = 1454.54e18
DebtToken mint calculates:
Interest on existing debt: 1000e18 * (1.1 - 1.0) = 100e18
Total mint amount: 500e18 + 100e18 = 600e18
The discrepancy becomes apparent:
scaledDebtBalance in the protocol: 1454.54e18
When converting to actual debt: 1454.54e18 * 1.1e27 ≈ 1600e18
Actual DebtToken balance: 1600e18
This incorrect tracking of scaledDebtBalance causes:
Potential errors in liquidation calculations
Inaccurate interest accrual tracking
Unreliable system-wide debt accounting
Manual Review
Update the borrow function to use the mint return values for accurate debt scaling:
This ensures that scaledDebtBalance correctly reflects both the new borrowed amount and any accrued interest on existing debt.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.