Deep Dive into High-Profile Crypto Exploits — Part I: Beanstalk Farms

Background

  • Flash loan — a flash loan is a powerful DeFi tool that allows you to borrow funds (in the current attack, 1B$ were borrowed) from platforms like Aave & Compound. It is mainly used to amplify arbitrage gains. The catch is that all borrowed funds must be returned in the same transaction that they were borrowed.
  • Governance — a governance is a system for managing and implementing changes to a protocol. Users can submit proposals for changing parts of the system, such as moving funds from treasury, changing fees and more. Token holders can vote on whether or not to implement the change. This allows for a decentralized mechanism to reach an agreement on the future and growth of a protocol.
    Proposals are usually proposed by creating a smart contract that contains the proposal’s logic, and sending its address to the governance protocol.

The attack — A High-Level overview (For Dummies)

  1. On April 16th the attacker proposed 2 malicious proposals to the Beanstalk governance protocol — The first one is meant to drain the liquidity and funds from Beanstalk, and the second one was made public and is meant to donate 250k$ to Ukraine.
    This second proposal’s code was made public and was specifically named with the ID of the first proposal, to mislead the community and hide the first, malicious, proposal.
    It is interesting to note that the attacker hid the malicious proposal’s logic until the block of the attack (more info on that can be found in the Deeper Dive section below).
  2. Almost exactly 24 hours later, on April 17th, the attacker borrowed 1 Billion USD using flash loans from Aave protocol, and purchased a large number of special BEAN protocol tokens called BEAN3CRV-f and BEANLUSD-f. These tokens can be used to vote on Governance proposals, and this is exactly what the attacker did.
  3. The attacker used the voting tokens mentioned above to call the emergencyCommit() function of the Beanstalk governance protocol to immediately approve both of his proposals.
    This was possible because using the 1B$ from the flash loan to purchase more than 70% of the voting tokens.
  4. The attacker paid the loan back with the profits from the drained liquidity, and was ultimately left with more than 23,000 ETH and more than 60,000,000 BEAN tokens
  5. Like most of the attacks, the attacker quickly moved all funds to Tornado.cash.

The attack — A Deeper Dive

  1. The first step of the attack was deploying the contract of the public proposal to donate 250,000$ to Ukraine (which will be proposed in step 3 below)

The Attacker’s Tricks

  1. The malicious contract’s proposal was never live, until the block of the attack — The attacker calculated the address the contract will have using the create2 opcode, and used it in the proposal on April 16th, even though the malicious contract was deployed only on April 17th
  2. The attacker deployed the malicious contract and executed the attack on the same block, so no one had the chance to review the code of the proposal
  3. The attacker precalculated the ID of the malicious proposal and deployed a seemingly innocent second proposal to donate to Ukraine, and named it with an incorrect ID to mislead investors and make them believe the malicious proposal was in fact the donation to Ukraine.

Mitigation

Summary

About Solid Group

  • audited token generator ( Generate your own token with NO CODING KNOWLEDGE)
  • sniper bot protection tool
  • Smart contract auditing service

--

--

--

We are a group 3 software developers with combined experience of over 15years in various fields such as Software design, Operating systems, and solidity.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Lenny Zeltser is teaching us how malware operates

Cybercriminals: Not Just Guys in the Basement Anymore

The Future of FinTech AppSec Is Brighter Than You Think

Four cybersecurity trends 2021 that enterprises must watch

XRUN does not Stop at One M2E Game

{UPDATE} Trickster - das Spiel Hack Free Resources Generator

Modifications to the Intellectual Property Legislation in Mexico

{UPDATE} Racing Motorbike Hack Free Resources Generator

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Solidgroup

Solidgroup

We are a group 3 software developers with combined experience of over 15years in various fields such as Software design, Operating systems, and solidity.

More from Medium

Let’s talk about our treasury.

Wallet Safety: An overview

What is Defi and Cefi | Decentralized finance vs. Centralized finance

Liquidity pools