Submitted by 3docSec, also found by aslanbek, rvierdiiev, btk, and ether_sky
The function notifyPnL in ProfitManager is called by LendingTerms when a loan is closed to report a profit or loss.
In case there is a loss, the amount in excess of the protocols buffer is attributed to the credit token holders. This is done by slashing the creditMultiplier with the effect of depreciating the credit token relatively to the collateral.
The math for slashing the creditMultiplier is the following:
It is particularly interesting that totalSupply() is used, since in a similar high-level accounting calculation, totalBorrowedCredit(), targetTotalSupply() is used instead:
The usage of totalSupply() here can be problematic when a significant portion of the supply is in undistributed rewards. In this case, the creditMultiplier slashing will be higher than it should because totalSupply() will return a much lower value than targetTotalSupply().
creditMultiplier slashing will always be higher than it should for correct accounting, penalizing credit token holders, and finally locking value in the protocol. The negative effects will be proportional to the relative supply of credit tokens in undistributed rewards versus the interpolated supply of the credit token.
The following PoC in Foundry (full setup here) shows how an overshot creditMultiplier slashing locks collateral value in SimplePSM, with a net loss for protocol users, in a real-wold scenario:
Foundry
Consider using targetTotalSupply() instead of totalSupply() in the creditMultiplier slashing calculation:
Math
eswak (Ethereum Credit Guild) confirmed, but disagreed with severity and commented:
TrungOre (judge) decreased severity to Medium
btk (warden) commented:
Soul22 (warden) commented:
0xStalin (warden) commented:
0xStalin (warden) commented:
3docSec (warden) commented:
0xStalin (warden) commented:
btk (warden) commented:
0xStalin (warden) commented:
TrungOre (judge) commented:
