This level will ask you to break DexTwo, a subtlely modified Dex contract from the previous level, in a different way.
You need to drain all balances of token1 and token2 from the DexTwo contract to succeed in this level.
You will still start with 10 tokens of token1 and 10 of token2. The DEX contract still starts with 100 of each token.
How has the swap method been modified?
提示說看 swap(address from, address to, uint256 amount)
跟上一關的有什麼不一樣:
Dex2:
兩關的合約在計算價格的方式是一樣的,不一樣的只有這關少一個「條件判斷」;代表可以將不屬於這題的代幣用來交易。這樣就很簡單了,我們只要用別的代幣把 token1 跟 token2 都換出來就好了。
按照價格公式來看的話,我們只要先給關卡 1 枚我們自建的代幣,再用 1 枚就可以換出 token2 的 100 枚,因為 可以換出的 token2 數量 = 轉進去的 token1 數量 * 關卡中 token2 的數量 / 關卡中 token1 的數量,也就是:換出 100 枚 = 1 * 100 / 1
。
換完後關卡中有 2 枚,套用上面的思路,只要再給 2 枚就可以將 token1 的 100 枚也換出來,整理攻擊流程: