Reproduced Exploit

Origin extend discards 50 OGV of rewards

Alice and Bob each stake 100 points. 100 OGV of rewards accrue. Alice's collectRewards updates accRewardPerShare and pays her 50, which leaves Bob owed 50. extend writes rewardDebt = balance * acc / 1e12 and does not call _collectRewards, so Bob's claim becomes 0. A later collect pays him nothing.…

Jul 2022•Other•logic•3 min read

Chain

Other

Category

logic

Date

Jul 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: 10564-extending-the-staking-duration-discards-rewards-openzeppelin. Standalone Foundry PoC and full write-up: 10564-extending-the-staking-duration-discards-rewards-openzeppelin_exp in the evm-hack-registry mirror.


Vulnerability classes: vuln/logic/reward-calculation

Key info#

ProtocolOrigin OGV staking
FindingOpenZeppelin, AuditVault 10564
Vulnerable codeOgvStaking.extend
HarmBob loses 50 OGV; the 50 stays in the staking contract
Chainlocal synthetic

TL;DR#

Alice and Bob each stake 100 points. 100 OGV of rewards accrue. Alice's collectRewards updates accRewardPerShare and pays her 50, which leaves Bob owed 50. extend writes rewardDebt = balance * acc / 1e12 and does not call _collectRewards, so Bob's claim becomes 0. A later collect pays him nothing. The 50 remains in the staking contract. Collecting before extend pays the 50.

The vulnerable code#

SOLIDITY
_mint(msg.sender, newPoints - oldPoints);
// @> VULN: rewardDebt is updated here with no prior _collectRewards, so the outstanding rewards are discarded
rewardDebt[msg.sender] = (balanceOf(msg.sender) * accRewardPerShare) / 1e12;

Root cause#

rewardDebt is an absolute debt. It is only meaningful if _collectRewards has just paid balance * acc / 1e12 - rewardDebt. extend updates the debt as if that payment happened. It did not, so the outstanding rewards are zeroed.

Preconditions#

Another staker has already collected, so accRewardPerShare reflects rewards Bob has not been paid. Bob then calls extend. Both stakes are 100 points and the reward pot is 100 OGV.

Attack walkthrough#

  1. 100 OGV is funded and Alice collects. She receives 50. accRewardPerShare becomes 5e11.
  2. previewRewards(Bob) is 50 OGV.
  3. Bob calls extend(0, 14 days).
  4. rewardDebt snaps to 50 OGV. Preview drops to 0.
  5. Bob's collect transfers 0. The staking contract's OGV balance is 50 higher than before the rewards arrived, and that 50 is unclaimable by Bob.

Diagrams#

flowchart TD A["Alice and Bob each stake 100"] --> B["100 OGV of rewards is funded"] B --> C["Alice collects and is paid 50"] C --> D["Bob is owed 50"] D --> E["VULN: extend snaps rewardDebt"] E --> F["Bob collects 0 and 50 OGV is stranded"]

Impact#

Bob loses 50 OGV of rewards he had already earned. The tokens sit in the staking contract. The control calls collectRewards before extend and Bob's balance is 50 OGV.

Remediation#

Call _collectRewards before updating rewardDebt in extend, or store debt per share so a balance change cannot erase unpaid rewards.

How to reproduce#

BASH
cd 10564-extending-the-staking-duration-discards-rewards-openzeppelin_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.