Reproduced Exploit

Magic Yearn MyStaking: stake stores claimable rewards twice

Aug 2022•Other•logic•2 min read

Chain

Other

Category

logic

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: 57532-incorrect-storage-of-user-rewards-during-staking-in-mystakin. Standalone Foundry PoC and full write-up: 57532-incorrect-storage-of-user-rewards-during-staking-in-mystakin_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/logic/reward-calculation

Reproduction: faithful local reproduction of AuditVault 57532. claimableAmount already adds unclaimedAmount, and stake adds that total back onto unclaimedAmount.

Root cause#

claimableAmount returns fresh accrual plus unclaimedAmount. stake then does unclaimedAmount += claimable. The stored rewards are counted twice.

SOLIDITY
uint256 claimable = claimableAmount(msg.sender);
// @> VULN: claimable already includes unclaimedAmount, so this doubles it
u.unclaimedAmount += claimable;

Two equal stakers share a 2,000 RWD pool, 1,000 each. The attacker's second stake(0) turns a stored 1,000 into 2,000. Their claim empties the pool.

Attack path#

flowchart TD A["Two stakers deposit equal stake"] --> B["2000 RWD is added, 1000 each"] B --> C["First stake stores the true 1000"] C --> D["Second stake adds claimable again"] D --> E["unclaimedAmount becomes 2000"] E --> F["Attacker claims the whole pool"] F --> G["Victim is paid 0 and the sink receives the stolen 1000"]

Impact#

The attacker is paid 2,000 RWD. The other staker is paid 0. 1,000 RWD of that payout is the victim's share and is forwarded to the sink. The fixed stake adds only the fresh accrual, and each staker claims 1,000 RWD.

PoC#

BASH
cd 57532-incorrect-storage-of-user-rewards-during-staking-in-mystakin_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.