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 | Belongarrow-up-right

  • Report ID: #57716

  • Report Type: Smart Contract

  • Report severity: Critical

  • Target: https://github.com/immunefi-team/audit-comp-belong/blob/main/contracts/v2/periphery/Staking.sol

  • Impacts:

    • Direct theft of any user funds, whether at-rest or in-motion, other than unclaimed yield

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.

1

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.

2

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.

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

chevron-rightClick to expand the PoC test case and test outputhashtag

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

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

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)

Was this helpful?