In this challenge the user is provided with a contract called Dex.sol
. The goal of this challenge is to drain token0.
-
The problem in this contract is the way the contract quotes token prices. Initially the user is given
10 token0
&10 token1
. The dex already has100 token0
&100 token1
. The initial price is1 token0
=1 token1
. -
Swapping
10 token0
fortoken1
gives us20 token1
&0 token0
. But the dex now has110 token0
&90 token1
. The next quote price if we swap20 token1
fortoken0
it gives us24 token0
which is better than before. -
Swapping tokens back & forth a few more times gives us better & better price & we drain all of the funds in the dex.
-
Run Exploit!
forge test -vv -m test_challenge_21