Skip to content
high DeFi Economic No SWC entry CWE-682

Same-Block Deposit/Withdraw Share Manipulation

SAFE-0223 DeFi Economic Checked automatically by the scanner
1

What goes wrong

A vault lets a user deposit and withdraw in the same transaction with share price driven by an external, flash-manipulable quantity (spot price, reserves). The attacker deposits, pumps the priced quantity, and withdraws more than they put in.

2

The vulnerable pattern

proof of concept — how it is exploited
// 1. deposit at price P
// 2. flash-manipulate the pool so share price = 2P
// 3. withdraw same shares -> 2x assets out, all in one tx.
3

How to fix it

the pattern that is safe
// snapshot price at deposit; block same-block deposit+withdraw; use TWAP
require(lastDeposit[msg.sender] != block.number, "same block");
Guard against atomic deposit+withdraw around manipulable prices.
Check your own contract for this

The SaferICO scanner runs 201 detectors over your Solidity source, SAFE-0223 among them. Paste an address or the source itself — a small per-scan fee, shown before you sign, or unlimited on any plan.

Run the scanner See how it is attacked Read the docs