Reproduced Exploit

Magic Yearn MyStaking: a non-staker can zero stakerCount

Aug 2022•Other•dos•2 min read

Chain

Other

Category

dos

Date

Aug 2022

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. No backend, no live RPC.

Loading fork state…

Source & credit. Reproduction of a public audit finding curated by AuditVault — the original finding: 57533-user-funds-lock-in-mystaking-due-to-stakercount-manipulation. Standalone Foundry PoC and full write-up: 57533-user-funds-lock-in-mystaking-due-to-stakercount-manipulation_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/dos/frozen-funds

Reproduction: faithful local reproduction of AuditVault 57533. withdraw decrements stakerCount without checking that the caller has a share.

Root cause#

stake increments stakerCount only when a user goes from zero shares to a position. withdraw always executes stakerCount -= 1. A caller with zero shares can drive the counter to zero. The real staker's later withdraw underflows and reverts.

SOLIDITY
uint256 share = shares[msg.sender];
shares[msg.sender] = 0;
// @> VULN: stakerCount decreases even when the caller has no share
stakerCount -= 1;
if (share > 0) token.transfer(msg.sender, share);

Attack path#

flowchart TD A["Victim stakes 1000 STK"] --> B["stakerCount is 1"] B --> C["Attacker with zero shares calls withdraw"] C --> D["stakerCount becomes 0"] D --> E["Victim withdraw underflows and reverts"] E --> F["1000 STK stays in MyStaking"]

Impact#

The victim's 1,000 STK cannot be withdrawn. The attacker's call moved no tokens. The fixed withdraw requires share > 0, so the zero-share call reverts and the victim exits with their 1,000 STK.

PoC#

BASH
cd 57533-user-funds-lock-in-mystaking-due-to-stakercount-manipulation_exp
forge test -vv

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.