# Novax: stake/withdraw price manipulation via flash loan

Novax stake contract valued tokens in USDT at stake time; attacker flash-loaned USDT, pumped token price, staked, dumped, then withdrew at inflated value.

- Payout: Real-world hack
- Severity: high
- Program: Novax
- Credited: DeFiHackLabs
- Disclosed: 2024-08-06
- Write-up quality: 6/10
- Original: https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2024-08/NovaXM2E_exp.sol
- Library page: https://bugbountylibrary.com/r/dhl%3A20240806-novaxm2e
- Tags: domain:web3 impact:funds-loss kind:incident platform:defihacklabs sev:high technique:chained vuln:flash-loan vuln:oracle-manipulation

**Target:** TokenStake contract on BSC
**Root cause:** Stake contract converts staked token amount to USDT value at stake time and uses that stored value to compute token amount on withdraw, without a TWAP or manipulation-resistant oracle.
**Steps:**
1. Flash loan 500,000 USDT from PancakeSwap pair `0x7EFaEf62fDdCCa950418312c6C91Aef321375A00` via `swap(500000e18, 0, attacker, data)`.
2. Swap USDT to NovaXM2E on PancakeSwap router, pumping NovaXM2E price.
3. Approve and call `tokenStake.stake(0, NovaXM2E.balanceOf(attacker)/2)`.
4. Swap remaining NovaXM2E back to USDT, crashing price.
5. Call `tokenStake.withdraw(tokenStake.stakeIndex())` to receive NovaXM2E valued at the inflated stake-time price.
6. Swap received NovaXM2E to USDT and repay flash loan plus fee.
**How found:** Likely identified that the stake contract stores a USDT-denominated value at stake time and uses it for withdrawal, making it vulnerable to spot price manipulation via a flash loan.
**Exploitation:** Attacker used a flash loan to buy NovaXM2E, inflating its USDT price. Staked half the tokens, then sold the rest to crash the price. Withdrew the stake, receiving NovaXM2E calculated from the inflated USDT value recorded at stake time. Sold the withdrawn tokens for USDT, repaid the loan, and kept the profit (~25K USD).
**Insight:** When a contract records a value based on a DEX spot price at deposit time and later uses that value to return tokens, a flash loan can sandwich the stake and withdraw to profit from the price difference.
