# Bitpaidio staking: zero-amount lock enables flash-loan withdrawal drain

Bitpaidio staking contract let an attacker lock a zero-amount plan, then withdraw a flash-loaned deposit repeatedly, netting ~$30K.

- Payout: Real-world hack
- Severity: high
- Program: Bitpaidio
- Analysis by: DeFiHackLabs
- Disclosed: 2023-05-13
- Write-up quality: 6/10
- Original: https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2023-05/Bitpaidio_exp.sol
- Library page: https://bugbountylibrary.com/r/dhl%3A20230513-bitpaidio
- Tags: area:web3 domain:web3 impact:funds-loss kind:incident platform:defihacklabs sev:high tech:evm technique:source-review vuln:business-logic vuln:flash-loan

**Target:** BSC staking contract (Lock_Token/withdraw)
**Root cause:** Staking plan accounting did not validate the initial lock amount or track per-plan balances correctly, so a zero-amount Lock_Token(1,0) opened a plan that could later be credited with a flash-loaned deposit and immediately withdrawn.
**Steps:**
1. Call `Staking.Lock_Token(1, 0)` to open plan 1 with zero amount.
2. Wait past the 6-month lock period (warp).
3. Flash-borrow 219,349 BTP from the PancakeSwap pair via `Pair.swap(flashAmount, 0, ...)`.
4. In the callback, `BTP.approve(Staking, max)` then `Staking.Lock_Token(1, BTP.balanceOf(this))` to credit the plan.
5. Call `Staking.withdraw(1)` to pull the credited balance out.
6. Repay the flash loan (`flashAmount * 10000 / 9975 + 1000`) and keep the remainder.
**Exploitation:** Attacker pre-opened a staking plan with zero tokens, waited out the lock, then flash-loaned BTP, deposited it into the already-matured plan, and withdrew it plus the contract's payout, repaying the loan and keeping profit.
**Insight:** Staking contracts that let you open a plan with zero amount and later top it up can be abused: the maturity timer starts at the zero lock, so a flash-loaned top-up becomes instantly withdrawable.

