Reproduced Exploit

Coinflip staking pays a reward out of a pool that is already in deficit

earned does staked 1e18 / totalStaked balance / 1e18. When the token balance is below totalStaked, the quoted function returns that share. The recommendation returns 0 until the pool is whole again.

Feb 2025•Ethereum•arithmetic•2 min read

Loss

Alice is paid 8 FLIP. She staked 10 of 100 and the contract holds 80, so the pool is in deficit

Chain

Ethereum

Category

arithmetic

Date

Feb 2025

Source

AuditVault

EVM Playground

Source-level debugger — step opcodes and Solidity in sync

evm-hack-analyzer

The attack replays in your browser. Step through it by Solidity line or by opcode.

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: 55484-h-01-stakingearned-calculates-the-rewards-wrongly-pashov-aud. Standalone Foundry PoC and full write-up: 55484-h-01-stakingearned-calculates-the-rewards-wrongly-pashov-aud_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/arithmetic/reward-calculation · vuln/defi/reward-distribution

Key info#

FieldValue
LossAlice is paid 8 FLIP. She staked 10 of 100 and the contract holds 80, so the pool is in deficit
Vulnerable contractStaking.earned
Attacker EOA0x1111111111111111111111111111111111111111
Attack contractExploit at 0x15452ec016c4dc8c549e7fe6ff4b26324ea8b7a4
Attack txExploit.run()
Chain / block / dateEthereum model · block 0 · 2025-02
Compilersolc 0.8.27, cancun, via IR
Bug classearned returns the user's share of the remaining balance while balance < totalStaked
flowchart TD A["Alice staked 10 of totalStaked 100 and the contract holds 80"] --> B["earned computes 10 * 80 / 100"] B --> C["VULN the deficit branch returns 8"] C --> D["giveReward pays Alice 8 and the pool is left with 72"] B --> E["Control returns 0 while the balance is below totalStaked"] E --> F["Alice receives 0 and the 80 stays in the pool"]

TL;DR#

earned does staked * 1e18 / totalStaked * balance / 1e18. When the token balance is below totalStaked, the quoted function returns that share. The recommendation returns 0 until the pool is whole again.

Alice's stake is 10, totalStaked is 100, and the contract holds 80. Her share of the remaining balance is 8. giveReward transfers those 8 FLIP. The fixed earned returns 0, Alice receives nothing, and the pool stays at 80.

The vulnerable code#

SOLIDITY
uint256 userShare = stakedBalances[user] * 1e18 / totalStaked * totalTokenBalance / 1e18;
if (totalTokenBalance < totalStaked) {
    return userShare; // @> VULN: a loss still pays the user their share of the remaining balance
}

Impact#

A distribution during a deficit pays depositors out of principal that is already short. Here that payment is 8 FLIP, and the pool falls from 80 to 72 against 100 staked.

How to reproduce#

BASH
cd 55484-h-01-stakingearned-calculates-the-rewards-wrongly-pashov-aud_exp
forge test -vv

test_exploit_deficit_pays_8 asserts Alice holds 8 and the pool holds 72. test_control_deficit_pays_0 asserts the fixed path pays 0 and leaves 80.

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.