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!

Synthetix Logic Error Bugfix Review- 890

Immunefi Posted 3 Years Ago
  • Synthetix is a liquidity pool protocol that allows trading in the DeFi space. Since this has an Automated Market Maker (AMM), there are plenty of algorithms to ensure everyone gets the money they deserve. What if one of these was down incorrectly?
  • Frontrunning is when an attacker views the upcoming transactions and sneaks in a transaction with a higher gas price to take advantage of this. For instance, if we had a game called guess the number but you didn't know what the number was. You could view the pool until you see an answer that you like. Once you see this answer, you could steal this answer and add a higher gas price to your transaction to steal the solution.
  • In a similar fashion to frontrunning, the exchange had a problem with the latency between the off-chain market for a coin and the pools price. This allows for slight gains of funds from outsiders, but can cost the people staking into the pool money. In order to combat this latency, the exchange implement a short waiting period for taking out coins.
  • On top of the waiting period, it checks to see if arbitrage has been performed. This is calculated between the exchange prices and those at the end of the waiting period. If the result is negative, then they are owed money for the latency - this is also called rebate. If the result is positive, then they owe the pool money. Once the context is understood, then the reasoning for this makes sense.
  • The algorithm for this is Amount * (1 - feeRate) * (srcRate/destRate - newSrcRate/newDestRate). When the user withdraws their money, there is a bug in the actual code to take this out. Instead of using the variable sourceAmountAfterSettlement, sourceAmount is being used.
  • This results in not enough tokens being burned. Additionally, the amountReceived is calculated from the full sourceAmount instead of the sourceAmountAfterSettlement. In other words, the sourceAmount is slightly inflated. This earned the author a 150K bounty.
  • This was a very subtle logic bug in the handling of money. This properly took hours upon hours of reading documentation and understanding the code base to find. This company has had several reviews of their code base in the past by Sigma Prime and iosiro.