The clear() function in CreditDelegation.sol is responsible for resetting delegation-related state variables. However, it does not validate whether the market state has been fully synchronized before clearing. This could lead to a deadlock scenario, preventing new credit delegations or undelegations from being processed correctly.
The clear() function deletes multiple key delegation-related state variables, including:
The issue arises when clear() is executed before ensuring all pending market debt distributions are fully settled. Since it deletes the last distributed debt values, any ongoing or future operations that rely on these values could end up in an inconsistent state.
The system may not recognize existing credit or debt obligations after clearing, causing it to be stuck in an undefined state where new delegations cannot be processed.
Removing critical debt-related values (lastVaultDistributedRealizedDebtUsdPerShare, lastVaultDistributedUnrealizedDebtUsdPerShare) without proper reconciliation may cause miscalculations and prevent accurate tracking of outstanding debts.
If an undelegation process requires these deleted values, the function calls could fail or lead to unexpected behavior.
If clear() is only triggered after all debt obligations are settled, the risk is minimized.
However, if it can be called while outstanding debt values are still being processed, a deadlock becomes highly probable.
Since there are no built-in checks to prevent premature execution, this is an exploitable flaw in the current design.
To mitigate this risk, consider the following improvements:
Before executing clear(), ensure that all debts and credits are fully settled:
Instead of immediately deleting all values, introduce a soft reset:
This allows pending operations to complete before permanently removing data.
Emit an event before and after clearing state:
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.