# N00d Token: ERC777 reentrancy drains Uniswap pool

N00d ERC777 token's tokensToSend hook reentered the SushiBar enter/leave during a Uniswap V2 swap, inflating xN00d balance to drain the pool.

- Payout: Real-world hack
- Severity: high
- Program: N00d Token
- Analysis by: DeFiHackLabs
- Disclosed: 2022-10-26
- Write-up quality: 6/10
- Original: https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2022-10/N00d_exp.sol
- Library page: https://bugbountylibrary.com/r/dhl%3A20221026-n00d
- Tags: area:web3 domain:web3 impact:funds-loss kind:incident platform:defihacklabs sev:high tech:evm tech:solidity technique:chained vuln:flash-loan vuln:reentrancy

**Target:** ERC777 token + Uniswap V2 pair + SushiBar staking contract
**Root cause:** N00d is an ERC777 token whose tokensToSend hook fires on transfer to the SushiBar, allowing reentrant calls to Bar.enter before the first enter's balance accounting settles, inflating xN00d shares.
**Steps:**
1. Fork mainnet at block 15826379; register ERC1820 interface implementer for tokensToSend/tokensReceived on the attacker contract.
2. Approve Bar to spend N00d; loop 4 times calling `Pair.swap(n00dReserve - 1e18, 0, address(this), new bytes(1))` to borrow N00d via flash swap.
3. In uniswapV2Call, reset i=0, set enterAmount = balance/5, call `Bar.enter(enterAmount)` then `Bar.leave(Xn00d.balanceOf(this))`, then repay pair with `n00d.transfer(address(Pair), n00dReserve * 1000 / 997 + 1000)`.
4. tokensToSend hook fires on transfer to Bar; while i<2, increment i and call `Bar.enter(enterAmount)` again to reenter staking.
5. After 4 swap iterations, swap remaining N00d back to WETH via `Pair.swap(0, amountOut, address(this), "")` to realize profit.
**Exploitation:** Flash-borrow N00d from the Uniswap V2 pair, stake into SushiBar; the ERC777 tokensToSend hook reenters Bar.enter twice per swap, minting excess xN00d shares. Repeated 4 times to inflate share balance, then leave and swap back to WETH for profit.
**Escalation:** Repeated the swap/reenter cycle 4 times to compound the inflated xN00d balance before exiting.
**Insight:** ERC777 tokensToSend/tokensReceived hooks fire on every transfer including staking deposits; any staking or reward contract that credits shares before the transfer completes is reentrancy-prone. Check token standards of pool assets before assuming Uniswap V2 callback-only reentrancy surface.

