Wrong calculation of delinquent penalty time in updateTimeDelinquentAndGetPenaltyTime
function
#19
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
primary issue
Highest quality submission among a set of duplicates
🤖_primary
AI based primary recommendation
🤖_17_group
AI based duplicate group recommendation
sponsor disputed
Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue
sufficient quality report
This report is of sufficient quality
unsatisfactory
does not satisfy C4 submission criteria; not eligible for awards
Lines of code
https://github.com/code-423n4/2024-08-wildcat/blob/main/src/libraries/FeeMath.sol#L118
Vulnerability details
Impact
Because of the incorrect calculation of delinquent penalty time, a borrower gets charged much lower delinquency fee than intended.
Proof of Concept
Over time, as market operations occur, borrowers accumulate fees. This process is managed by the
FeeMath.updateScaleFactorAndFees
function. While this function updates the scaleFactor and applies the protocolFee, it also implements the delinquency fee based on the market's delinquency status. The calculation is performed by theupdateDelinquency
function, which then utilizes theupdateTimeDelinquentAndGetPenaltyTime
function to determine the duration for which thedelinquencyFeeBips
should be applied.When
state.isDelinquent
is false, indicating that the current market is healthy, the return value is calculated as follows:In here,
secondsRemainingWithPenalty
is wrong because delinquent state remains active untilpreviousTimeDelinquent
drops down to zero.It's also mentioned in wildcat doc: https://docs.wildcat.finance/using-wildcat/delinquency#how-delinquency-triggers
Here's an example:
IF
previousTimeDelinquent = 3 days
anddelinquencyGracePeriod = 5 days
, then it should be:secondsRemainingWithPenalty = 3 days
, but above code generates0
.(IMPORTANT NOTE: The
updateTimeDelinquentAndGetPenaltyTime
function has another critical flaw; it assumes thatstate.isDelinquent
is up-to-date and has remained unchanged from the last update to the present. This assumption is incorrect and will be addressed as a separate issue submission.)Tools Used
Manual Review
Recommended Mitigation Steps
Update the calculation as follows:
Assessed type
Error
The text was updated successfully, but these errors were encountered: