Part 2

Zaros
PerpetualsDEXFoundrySolidity
70,000 USDC
View results
Submission Details
Severity: high
Invalid

A malicious user can drain funds in the case of a depeg of the USDz token

Summary

When a user wants to perform a swap, the protocol assumes that the price of USDz is $1, which can lead to an exploit in the case of a depeg event.

Vulnerability Details

When a user wants to perform a swap, they must call initiateSwap in the StabilityBranch, and then the keeper will execute the swap by calling fulfillSwap. The amount of USDz will then be swapped for the collaterals of the vaults specified by the user.

The function getAmountOfAssetOut is called in both `initiateSwap` and `fulfillSwap` to determine the collateral amount out.

ctx.amountOutBeforeFeesX18 = getAmountOfAssetOut(ctx.vaultId, ud60x18(ctx.amountIn), ctx.priceX18);

The problem is that the function directly computes the output asset amount by assuming that the price of one USDz is $1, as seen in line 124 of the StabilityBranch:

function getAmountOfAssetOut(
uint128 vaultId,
UD60x18 usdAmountInX18,
UD60x18 indexPriceX18
) {
...
amountOutX18 = usdAmountInX18.div(indexPriceX18).mul(premiumDiscountFactorX18);
}

The function directly computes the output amount using the USD price of the collateral but does not account for the possibility that 1 USDz might not equal $1. This can lead to an exploit in the case of a depeg event.

Impact

The user can receive a higher collateral value for a lower USDz value.

Tools Used

Manual Review

Recommendations

Refactor the function and integrate an oracle for USDz to compute the output amount correctly.

Updates

Lead Judging Commences

inallhonesty Lead Judge 10 months ago
Submission Judgement Published
Invalidated
Reason: Design choice

Appeal created

0xphantom Submitter
10 months ago
inallhonesty Lead Judge
10 months ago
inallhonesty Lead Judge 9 months ago
Submission Judgement Published
Invalidated
Reason: Design choice

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!