Incorrect use of state.isDelinquent
in updateTimeDelinquentAndGetPenaltyTime
function - total misbehavior of applying delinquency fee
#18
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#L96
https://github.com/code-423n4/2024-08-wildcat/blob/main/src/market/WildcatMarketBase.sol#L406
Vulnerability details
Impact
Due to the incorrect value of
state.isDelinquent
, theupdateTimeDelinquentAndGetPenaltyTime
function malfunctions, causing significant disruptions in fee accumulation.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.This function has a critical flaw by using incorrect
state.isDelinquent
value. It's assumed that:state.isDelinquent
is up-to-updateHowever, this is WRONG because
state.isDelinquent
is the delinquency status of last updated time (indicated bystate.lastInterestAccruedTimestamp
)_writeState
function which is normally at the end of an action.So the whole deliquent penalty time is calculated wrongly, which leads to incorrect accumulation of delinquency fee.
Tools Used
Manual Review
Recommended Mitigation Steps
Though we can't completely guarantee 2nd point (
The delinqency state of market has been consistent
) because delinquency state can be changed in-between by direct transfer-in of assets (either by borrower or whoever), we can mostly assume it's true for a specific duration between market operations.We can have correct value of
state.isDelinquent
, so thatupdateTimeDelinquentAndGetPenaltyTime
function could perform correctly. It can be done by making changes to_getUpdatedState
function ofWildcatMarketBase
contract.Assessed type
Error
The text was updated successfully, but these errors were encountered: