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.
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
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.
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-registrymirror.
Vulnerability classes: vuln/arithmetic/reward-calculation · vuln/defi/reward-distribution
Key info#
| Field | Value |
|---|---|
| Loss | Alice is paid 8 FLIP. She staked 10 of 100 and the contract holds 80, so the pool is in deficit |
| Vulnerable contract | Staking.earned |
| Attacker EOA | 0x1111111111111111111111111111111111111111 |
| Attack contract | Exploit at 0x15452ec016c4dc8c549e7fe6ff4b26324ea8b7a4 |
| Attack tx | Exploit.run() |
| Chain / block / date | Ethereum model · block 0 · 2025-02 |
| Compiler | solc 0.8.27, cancun, via IR |
| Bug class | earned returns the user's share of the remaining balance while balance < totalStaked |
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#
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#
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#
- AuditVault finding: https://github.com/Auditware/AuditVault/blob/main/findings/55484-h-01-stakingearned-calculates-the-rewards-wrongly-pashov-aud.md
- Pashov report: Coinflip security review, 2025-02-05
Sources & further analysis#
Reproductions & code
- Standalone PoC + full trace: 55484-h-01-stakingearned-calculates-the-rewards-wrongly-pashov-aud_exp (evm-hack-registry mirror).
- AuditVault finding: 55484-h-01-stakingearned-calculates-the-rewards-wrongly-pashov-aud.
Alerts & third-party analyses
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.