During SettlementBranch._fillOrder
, profit adjustment is applied to positive PnL twice. This will lead market to loss funds gradually.
In SettlementBranch._fillOrder
, there is a usdToken deposit logic if user's PnL is positive
User's pnl is adjusted considering the market's ADL, like the following logic:
autoDeleverageFactor
is lower than one if market's debt ratio is between autoDeleverageStartThreshold
and autoDeleverageEndThreshold
.
So back to the codebase, ctx.marginToAddX18 = ctx.pnlUsdX18 * autoDeleverageFactor
And this amount is deposited to user's trading account.
We expect to withdraw the same amount marginToAddX18
from the market making engine.
However, profit adjustment is done again in marketMakingEngine.withdrawUsdTokenFromMarket
:
Thus, final usdToken minted amount is ctx.marginToAddX18 * autoDeleverageFactor
, which is lower than amount deposited to trading account (ctx.marginToAddX18
).
Users will receive less USDz than expected
TradingAccount's deposit amount will be greater than user's USDz balance, which will lead to protocol insolvency and unexpected behavior
Manual Review
Should be fixed like the following:
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.