Resources

People often ask me "How did you learn how to hack?" The answer: by reading. This page is a collection of the blog posts and other articles that I have accumulated over the years of my journey. Enjoy!

Leet Swap- 1218

BlockSecPosted 2 Years Ago
  • LeetSwap is a decentralized token exchange. It's a fork of Solidly.
  • In Solidity, private and internal functions are started with an _ (underscore) by convention. In practice, the visibility is the important part. In the case of this protocol, the function _transferFeesSupportingTaxToken() was set to public, even though it had an underscore at the beginning.
  • Although the name says taxTokens, the functionality takes in a token address and amount then sends it to the fees contract owner. So, what's the big deal? The attacker does not get sent the money.
  • How do we exploit this? Since this is an automated market maker (AMM), the prices are dedicated by the amount of the assets in the protocol. Since we can arbitrarily move assets out of the protocol, we can manipulate the trading rates. Here's a step by step for hitting a single pool if we were attacking a WETH-SOMETOKEN pool:
    1. Swap WETH for SOMETOKEN at the market rate.
    2. Call _transferFeesSupportingTokenTax() to transfer out the SOMETOKEN from the protocol. This will make the exchange rate for trading SOMETOKEN to WETH favorable.
    3. Call the sync() function to fix the pool amounts used for calculations.
    4. Swap back SOMETOKEN for WETH at the favorable rate to drain the protocol of most of its WETH.
  • Get audits people! Security is hard. A junior auditor would have trivial caught this bug.