Reproduced Exploit

Balmy: a direct vault-share deposit is charged a performance fee

The user transfers ERC-4626 shares straight to the strategy, then the strategy is told about the deposit. _fees_deposited reads balanceOf after that transfer, compares it with a zero lastBalance, and charges the 500 bps performance fee on the deposit itself. The user is credited 95,000. The fee rec…

Nov 2024•Ethereum•logic•3 min read

Loss

5,000 of a 100,000 share deposit is skimmed before any yield

Chain

Ethereum

Category

logic

Date

Nov 2024

Source

AuditVault

EVM Playground

Source-level debugger — step opcodes and Solidity in sync

evm-hack-analyzer

The attack is replayed in an in-browser EVM preloaded with the exact dumped fork state. The execution tree shows every call; step by Solidity line or by opcode across all depths — source, Stack, Memory, Storage, Balances (native / ERC-20 / NFT), Transient storage and Return value stay in sync. Click a tree node, opcode, or source line to jump. Query opens a search over the trace: previous and next writes, balance changes and calls, breakpoints, and a diff of everything that changed between two steps. No backend, no live RPC.

Loading fork state…

Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 46434-externalfee-contract-treats-newly-deposit-vault-share-as-yie. Standalone Foundry PoC and full write-up: 46434-externalfee-contract-treats-newly-deposit-vault-share-as-yie_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/logic/fee-calculation

Key info#

FieldValue
Loss5,000 of a 100,000 share deposit is skimmed before any yield
Vulnerable contractExternalFeeStrategy._fees_deposited
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit
Attack txExploit.run()
Chain / block / dateEthereum model · local · 2024-11
Compilersolc 0.8.27, cancun
Bug classDeposit included in the performance-fee snapshot

TL;DR#

The user transfers ERC-4626 shares straight to the strategy, then the strategy is told about the deposit. _fees_deposited reads balanceOf after that transfer, compares it with a zero lastBalance, and charges the 500 bps performance fee on the deposit itself. The user is credited 95,000. The fee recipient receives 5,000.

Background#

Cantina review of Balmy, November 2024, reported by Blockdev. The report's assumption is an empty strategy and a 500 bps performance fee. Depositing the underlying asset snapshots a zero share balance. Depositing the share token itself does not.

The vulnerable code#

SOLIDITY
uint256 currentBalance = shares.balanceOf(address(this)); // deposit already included
uint256 performanceFee = _calculateFees(currentBalance, performanceFeeBps); // @> VULN: deposit counted as yield

The fix is to snapshot before the user's transfer, or to stop sending shares directly to the strategy. Balmy described that change across PR 77 and PR 133.

Root cause#

The fee baseline is updated only inside _fees_deposited, but the tokens are already on the contract when that function reads the balance. The whole deposit looks like yield.

Preconditions#

  • Performance fee is 500 bps and the strategy share balance starts at 0.
  • The user deposits the vault share token, not the underlying asset.
  • No reward has been paid into the strategy.

Attack walkthrough#

  1. The user approves and deposits 100,000 shares.
  2. transferFrom delivers them before the fee math.
  3. currentBalance is 100,000.
  4. The fee is (100,000 - 0) * 500 / 10,000 = 5,000.
  5. Those 5,000 shares are transferred to the fee recipient.
  6. The credited amount is 95,000.

Diagrams#

flowchart TD A["User holds 100,000 vault shares"] --> B["Shares are transferred straight to the strategy"] B --> C["balanceOf is already 100,000"] C --> D["VULN fee uses that balance as yield"] D --> E["5,000 shares move to the fee recipient"] E --> F["User is credited 95,000"]

Impact#

The depositor loses 5 percent of the deposit on the same call that delivers it. The fee recipient's share balance increases by 5,000 ether units. An underlying deposit on an empty strategy, which snapshots before shares exist, credits the full 100,000 and charges 0.

Remediation#

Do not count shares that just arrived as yield. Snapshot the balance before the transfer, or pull the tokens only after the strategy has recorded the baseline.

How to reproduce#

BASH
cd 46434-externalfee-contract-treats-newly-deposit-vault-share-as-yie_exp
forge test -vv

test_exploit_share_deposit_pays_five_percent_immediately asserts a 95,000 credit and a 5,000 fee. test_control_underlying_deposit_charges_no_yield_fee asserts a full credit. Captured output is output.txt.

Sources#


Sources & further analysis#

Reproductions & code

Alerts & third-party analyses

  • Web3Sec X hacked database: search.
  • Rekt leaderboard: search.
  • Solodit incident search: search.

These dashboards index community alerts tweets, post-mortems, and independent write-ups. Reach them through the protocol name above to cross-check this reproduction against other analyses.