The getRealizedDebtUsd() function is designed to compute the realized debt of a market by adding the latest credit deposits value to the net USD token issuance. To optimize gas costs, it uses a cached credit deposit value (creditDepositsValueCacheUsd
), which is only updated when the cache is deemed outdated based on lastCreditDepositsValueRehydration
:
However, this cache invalidation logic is flawed because:
It only checks block.timestamp
, not actual changes in credit deposits. If deposits or withdrawals occur within the same block, the function may return outdated values, leading to incorrect debt calculations.
getCreditDepositsValueUsd() iterates over all credit deposits, but the function is only called if block.timestamp
is greater than lastCreditDepositsValueRehydration
, meaning it does not trigger when credit deposits change within the same block.
If the protocol allows flash loans or instant credit deposits and withdrawals, the cached value may not represent the true deposits, leading to incorrect realized debt calculations, potentially allowing vaults to manipulate their debt exposure.
The market can underestimate or overestimate realized debt due to stale credit deposit values, leading to incorrect debt distributions to vaults. This could allow malicious actors to deposit and withdraw credit within the same block, manipulating their debt obligations and gaming the system.
Instead of relying solely on block.timestamp
, invalidate the cache whenever a credit deposit is modified by updating lastCreditDepositsValueRehydration
inside deposit and withdrawal functions:
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.