depositCreditForMarket
is called during negative PnL adjustments of a position in order to deposit a portion of a user's margin as credit to a specific market. However when the asset is not usd or USDC it will actually increase debt, instead of reducing it. Debt will be decreased after a keeper calls convertMarketsCreditDepositsToUsdc
, however this will still create a window in which users will be able to deposit and receive significantly more index tokens.
When a position has a negative PnL, the PerpEngine will call depositCreditForMarket
. This will remove collateral from the positions margin and transfer it to the market. However when the collateral is not the USD token of the MarketMakingEngine
and is not USDC, the depositCreditForMarket
will perform the following call:
When credit is deposited, it is added to the creditDeposits
mapping.
However when we look into the getRealizedDebtUsd
function we see that these creditDeposits
are counted towards the debt:
Due to this mistake, debt will be overestimated allowing user's to deposit to vauts connected to this market using a wrong rate.
This is because getVaultAssetSwapRate
will use the following formula:
Here totalAssetsMinusVaultDebt
will be decreased because of the wrong implementation of the getRealizedDebtUsd
which will allow users to get more index tokens.
The users will instantly profit when the keeper calls convertMarketsCreditDepositsToUsdc
which will decrease the debt, resulting in the index token being more expensive.
Deposited credit is counted as debt, while it should be counted as credit.
Wrong debt calculation will allow users to get more index tokens at a cheaper price. Also this could also trigger keepers to unnecessarly execute functions such as settleVaultsDebt which will further decrease the vault's credit capacity.
Manual Review
Deposited collateral should be counted against the debt.
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.