Part 2

Zaros
PerpetualsDEXFoundrySolidity
70,000 USDC
View results
Submission Details
Severity: medium
Valid

Share Minting and Redemption Attack

Summary

An attacker can take advantage of the vault’s debt dynamics to gain an unfair share allocation. When the vault has a high level of debt, the share price decreases, enabling the attacker to mint an excessive number of shares for a minimal deposit. Once the debt is repaid, the share price returns to its normal level, allowing the attacker to redeem their shares for a significantly higher value, extracting substantial profits at the expense of the vault and its honest participants.


Impact

  • Funds Drain: The attacker can drain funds from the vault, leading to significant losses for other depositors.

  • System Insolvency: The vault may become insolvent, undermining trust in the protocol and causing long-term damage to its reputation.

https://github.com/Cyfrin/2025-01-zaros-part-2/blob/35deb3e92b2a32cd304bf61d27e6071ef36e446d/src/zlp/ZlpVault.sol#L190

https://github.com/Cyfrin/2025-01-zaros-part-2/blob/35deb3e92b2a32cd304bf61d27e6071ef36e446d/src/zlp/ZlpVault.sol#L172


Attack Scenario

1. Initial Vault State (Healthy)

// Initial state
uint256 totalAssets = 1000; // Total assets in the vault
uint256 debt = 0; // Vault debt
uint256 totalAssetsMinusVaultDebt = totalAssets - debt; // 1000
uint256 totalShares = 1000; // Total shares issued
uint256 sharePrice = totalAssetsMinusVaultDebt / totalShares; // 1 asset per share

2. Debt Increase

A malicious user monitors the protocol for opportunities to increase the vault's debt or actively participates in creating debt.

uint256 debt = 999; // Artificially inflated debt
totalAssetsMinusVaultDebt = totalAssets - debt; // 1
uint256 newSharePrice = totalAssetsMinusVaultDebt / totalShares; // 0.001 assets per share

3. Attacker Deposits 1 Asset & Mints Shares

Using the share minting formula:
https://github.com/Cyfrin/2025-01-zaros-part-2/blob/35deb3e92b2a32cd304bf61d27e6071ef36e446d/src/market-making/branches/VaultRouterBranch.sol#L224

uint256 previewSharesOut = assetsIn.mulDiv(
totalShares + 10 ** decimalOffset,
totalAssetsMinusVaultDebt,
MathOpenZeppelin.Rounding.Floor
);
  • With assetsIn = 1 and totalAssetsMinusVaultDebt = 1, the attacker mints:

    uint256 mintedShares = 1 * (1000 / 1); // 1000 shares

4. Debt Decrease

After a certain period, the vault's debt decreases.

uint256 debt = 0; // Debt repaid
totalAssetsMinusVaultDebt = totalAssets - debt; // 1000

5. Attacker Redeems Shares for Assets

Using the redemption formula:
https://github.com/Cyfrin/2025-01-zaros-part-2/blob/35deb3e92b2a32cd304bf61d27e6071ef36e446d/src/market-making/branches/VaultRouterBranch.sol#L178

uint256 previewAssetsOut = sharesIn.mulDiv(
totalAssetsMinusVaultDebt,
totalShares + 10 ** decimalOffset,
MathOpenZeppelin.Rounding.Floor
);
  • Redeeming 1000 shares:

    uint256 redeemedAssets = 1000 * (1000 / 2000); // 500 assets
  • Final Profit: The attacker deposited 1 asset and redeemed 500 assets, netting a profit of 499 assets.


Root Cause

The vulnerability arises because the share minting and redemption formulas are directly influenced by totalAssetsMinusVaultDebt. When totalAssetsMinusVaultDebt is artificially reduced (due to inflated debt), the share price drops significantly, allowing attackers to mint an excessive number of shares. Once the debt is repaid, the share price increases, enabling the attacker to redeem their shares at a much higher value, resulting in substantial profits.


Recommendations

1. Follow the ERC-4626 Standard

The ERC-4626 tokenized vault standard provides a robust framework for share minting and redemption. Adhering to this standard ensures that share calculations are resistant to manipulation.

2. Exclude Debt from Share Minting Logic

Modify the share minting logic to exclude debt from the calculation. This ensures that users receive shares based on the total assets in the vault, regardless of the debt level.

It is recommended to track totalAssets virtually.

The share redeeming can still account for the debt.

Updates

Lead Judging Commences

inallhonesty Lead Judge 7 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Appeal created

oxelmiguel Submitter
7 months ago
oxelmiguel Submitter
6 months ago
inallhonesty Lead Judge
6 months ago
inallhonesty Lead Judge 6 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Vault swap rate calculations vulnerable to manipulation when credit capacity approaches zero, allowing excessive share minting and value extraction from other users

Support

FAQs

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