I write MEV bots for a living. I can tell you that the Beanstalk "hack" was evidence of extremely poor design. One of the key security aspects of designing a DAO is that you are not supposed to let the results of a vote take effect in the same transaction or even the same block. This was entirely on the designers of that protocol. It's so negligent and downright stupid that I would be quite surprised if it weren't an inside job. The fact that it took more than a day for anyone to notice this is truly shocking.
I’m not remotely in DeFi but your comment suggests there’s a world of design rules & patterns within it, which are always somewhat interesting to learn about. Where would you go to learn this stuff (other than as a practitioner eg with access to mentors)?
At this point, alot of this stuff floats around Twitter and substack. It's still a bit of a dark art. If you'd like to read some stuff about MEV, start here:
You can go pretty far down the rabbit hole on crypto twitter.
This was also a cool event, there is 7 hours of video and slides, which have more of the kind of info I think you're looking for...discussions about protocol flaws and design etc.
Would you be interested in interviewing somebody on this? I run an interview platform called Taaalk (https://taaalk.co), and I'd be happy to organise an interview with somebody relevant
Is there a list of common attacks with names? This is the first time I've heard the term "reentrancy attack", there's probably a dozen other terms I've never heard of, but would like to read about.
I don’t think it counts as one, I was thinking that needs the governance contract to either recursively call itself or call an external unrelated contract
On the ETH chain, Flashbots [1] has decimated profits, by turning MEV into a race to the bottom, where miners wind up with most of the profits that bots ("searchers") create. On other chains there is much more profit to be had. People are making large amounts of money, as you can see here [2] (check out BSC on there, most of those profits go to the actual bot owners).
It's gotten incredibly competitive, and there has been quite a bit of consolidation. You used to be able to make a bot that could just make a few thousand dollars per day. Now you're either making 6 figures per day as part of a team, or a few hundred dollars per day on your own. One of the reasons you need a team and financing is that much of it is infrastructure based - being right next to miners/validators in the same server rack, etc. It takes significant resources to have nodes exactly where you need to have them, in various parts of the world.
It's also feast or famine. Sometimes, you'll wake up with hundreds of thousands of dollars from thin air. Here [3] is a loan liquidation using a flash loan from last week that netted the person that submitted it $366K (that was the value at the time) - in a few milliseconds. The only money they had to have to do this tx was the $1.50 transaction fee. The ~$8 million necessary for the liquidation was flash borrowed from a Pancakeswap pair.
So, seeing yet another story involving flash loans, I have to ask this question: what is the actual utility of a flash loan? The first use that occurred to me was to use it to pretend you were sufficiently rich for the purposes of exploiting an insufficiently secure smart contract, and judging from the number of stories involving them, I'm not the only person to think along these lines. But I'm not seeing any other uses than some variation on that fraudulent idea of making people think you have money you don't really have.
Surely the people who came up with this financial innovation had some other use for it in mind, one that would outweigh the inherent externality of this-is-a-perfect-vehicle-for-fraud, right? ... right?
Many financial positions (in DeFi or the real world) require you to have additional funds in order to move between different positions.
An example in the real world...say you're an employee at a large tech company with a bunch of stock options. You want to exercise those options and sell them. In order to exercise those options, you need money that you do not have. Luckily, your brokerage offers a service where they'll exercise the options for you and sell them. You're essentially borrowing their money very quickly to get out of your position.
In DeFi, you could use a flash loan in order to deleverage in a position. So instead of selling a small increment of your position and paying back your loan multiple times, you can instead take a flash loan and pay everything back at once to deleverage.
> Such flash loans have beneficial uses, including help for traders trying to capitalize on price differences between cryptocurrencies on different exchanges. In that sense, they are much like the financing that an investment bank might provide to an investment fund to make bets on different stocks or currencies.
This is their predominant use as well.
If you bid up the price of something on Sushiswap, that also trades on Uniswap, a flash loan will be deployed pretty much in the same block, pull all available capital necessary, and fix that price imbalance to its maximum potential.
Just a form of arbitrage.
Projects have to do system design that accounts for this. Beanstalk did not seem to account for the idea that the liquidity pool would have more than 50% of the BEAN supply eventually. But aside from that, having proposals passable in one block of deposit is the primary vector. Teams and communities like this model though because it basically comes down to "imagine how rich we would be if an attacker actually tried to buy all the tokens, I hope state actors get involved to really test that theory" because then it wouldn't matter if one block or many blocks was used if an actual organization was determined to pass something, this mentality is just not compatible with flash loans when all the liquidity is purchaseable already.
Flash loans are useful for both arbitrage and loan liquidations. Every swap on Uniswap and its many forks on many chains is actually a "flash swap" under the hood - you can take the coins out and use them before the code checks that you have sent the tokens for the swap in to the contract. You don't even need a dedicated flash loan provider on a given chain to be able to use very large amounts of capital sitting in DEX pair contracts.
There are other case-specific uses for them, but loan liquidations and arbs are the big ones.
Somewhat strange take on it. Applying the exact same reasoning, any loan is a fraud that lets you pretend you have money that you don't have. Compared to flash loans, a mortgage is a far more serious scheme, because you could end up defaulting on it, something that is impossible with flash loans by design (the transaction would revert). Mortgages also drive up house prices for everyone.
Fyi, their intended use case is to remove arbitrage opportunities, something that improves the UX for ordinary users because you don't have to worry about buying/selling at a suboptimal price.
The main use is exploiting smart contracts. Not just in the "bug" sense, but if e.g. there's a decentralized exchange and many people unwisely set a resting stop order to sell to "reduce risk", you can clear out the order book popping everyone's stops to trigger a cascade and then buyback at firesale prices.
Another common use for cryptocurrency loans is speculating on other cryptocurrencies or borrowing a lot for a short-term pump & dump. There's smart contracts that will let you borrow at 20% interest leaving the balances of both known, and they'll margin-call you if the trade goes too far against you.
There's no use for these loans outside of cryptocurrency-land: If you buy e.g. an apartment complex, that asset cannot be used as collateral for a cryptocurrency loan and you can't get millions of dollars for cheap like you can a conventional or government loan.
If the hacker had not said the bit about donating to Ukraine, but instead just made the proposal "send me all the money" would he have committed any crime? It's not clear to me that, apart from lying, he really did anything you're not supposed to do.
If, analogously, my bank had a program where people could propose actions to the bank and vote on them by putting dollars in a "yes" or "No" jar - and I started a "give me the bank" proposal, took out a massive loan and won the vote... What have I done wrong?
Yes, it would be theft because the usage was clearly outside of the intended use of the system. This sort of thing has been tested in the courts before and likely falls under the realm of any bug exploit.
For another example, let’s say you were an employee of a retailer with the power to set a discount on certain items. You suddenly set a 100% discount on every item in the store and then buy all the inventory for $0. Try explaining to the police that you were actually fully within your legal right to do that.
> For another example, let’s say you were an employee of a retailer with the power to set a discount on certain items. You suddenly set a 100% discount on every item in the store and then buy all the inventory for $0. Try explaining to the police that you were actually fully within your legal right to do that.
But if you were the board, or the majority shareholder, it would be fine. Which is what happened here.
They borrowed money, bought a majority of the BEAN, used that BEAN to vote on their proposal to take all the money, and it passed. They kept the money, sold the BEAN, and returned the borrowed money.
Which analogous cases are you talking about specifically?
And as much as your example would likely result in some kind of conversation with the police, it also highly depends on whether you discounted items fraudulently or if you did it because you specifically were in the position to do so. Your example describes it as though you had full legitimate power to discount certain items up to 100% off. At that point, at worst you would have violated company policy and not the law. You might get fired for it but when a retailer you work for offers a discount you are eligible to participate in it.
Code is law in crypto. You can’t hate the law/regulation then call it in when you need it.
Also I don’t think your retailer comparison works, in this case the power to give the user the rights and ability to create 100% discounts was designed into the system and although the outcome is unintended, it is not a flaw because the system allowed it and everyone using the system was allowed to audit it before putting value in.
The intended usage in my opinion is up to the governance to decide. They can vote on things related to how things should work. The project can be taken any way the governance decides and if the governance decides that it wants to send all of the funds to a single person I don't see how that is outside the indented usage. The exact same action could benefit all the users in case the smart contract had a vulnerability and he wanted to save everyone else's funds from being stolen.
In regards to your example if the employee truly does have the power to do that and the intention for that power is not stated. I think it's fine for them to take actions which cause the store to lose money.
Edit: As a sibling comment mentioned it's more like if a owner of the business decided to add these discounts.
Banks, and other companies, can indeed have shareholder votes to make decisions. You can't vote with dollars directly but you can buy more shares.
So shares are similar to governance tokens in DeFi projects. And in the real world, people also borrow money to get more than 50% of the shares. This is called a leveraged buyout.
However, the difference to DeFi is that shareholders have certain rights (like the right to share in the profits and assets) that are protected by laws. That means a majority shareholder cannot take actions that amount to stealing the company's profits or assets from other shareholders, or they'll be sued. They may do things that the other shareholders don't like, like dismantling the company by selling of parts for cash, but they'll have to fairly share the proceeds.
> It lets people with savings invest those savings in companies that produce real world goods and services.
You can invest in cryptos that you think will perform some sort of electronic service, like Ether, in expectation that the value will go up if it grows in usage.
It's admittedly pretty hard to make a connection to the physical world. So staying within the virtual world, ownership is an interesting application outside of finance. NFTs are the most prominent but (as art) least interesting examples of blockchain ownership. More interesting is the intersection with gaming, like what you see with Crypto Kitties and Gods Unchained (deck building game where card ownership and scarcity is blockchain driven). Another example is ENS: decentralized domain names.
> A bank can loan money to people who want to spend now what they will earn later.
This topic is much easier. Finance is the first application of blockchain, and there are tons of traditional financial instruments which exist in cryptospace already.
CDPs[1] offer a decentralized way to borrow money.
Flash loans are actually extremely democratic and socialize the ability to conduct billions of $ worth of transactions (as long as the debt is paid for in a single block).
This is in contrast to the current stock market in which only a handful of players have the liquidity and the regulatory ability to market make.
Agree. Only fine men like George Soros and companies willing to pay enough to lawyers should be able to do so.
Also open source software should be banned, as everyone can search for security exploits. I see it the same with flash loans, etc. It forces DeFi protocols to safeguard against all attack vectors, resulting in a much more secure environment.
Well, they’re kind of limited in what they can do with it because of the requirement to make a profit in an atomic transaction.
But I think the conversation we should be having is, do we want to move towards more resilient markets, given that the additional security will carry a heavy cost in terms of productivity?
I’m sure there are arguments both ways but it seems like we don’t have the full picture yet.
I analyzed this transaction when it happened back in April
There was enough liquidity in Uniswap V2. A lot of projects incentivize community organized trading liquidity these days. Larger and larger traders are more willing to buy into projects when the liquidity is large enough to support them, but in the past (and simultaenously now in the present, for projects that bother), providing liquidity had a major challenge of both expense and regulatory issues (promising liquidity to potential buyers and actively courting exchanges has been a prong in being designated as a security, but communities expected funds to be used this way anyway, exchanges know this and extort project founders). So now with AMM technology like Uniswap, this has all been solved. Nobody ever has to deal with crypto exchanges again, and communities don't have to worry about liquidity. This has allowed rapid flourishing of some kinds of projects.
Anyway, there are 71,000,000 BEAN tokens in existence. And if you look at the Uniswap liquidity pool, it has risen to around 30,000,000 BEAN slowly over time.[0] And the day the amount got high enough, the person did a flash loan of $1,000,000,000 in stablecoins and bought everything from the liquidity pool, they got 6,000,000 additional BEAN from another source, deposited 36,000,000 BEAN into Beanstalk to get immediate majority vote of their proposal, which gave them all the funds locked up in Beanstalk to themselves (the $80,000,000 or so), withdrew the bean, sold it back into the liquidity pool (resetting the price to what it was before), returned the $1,000,000,000 and kept the $80,000,000 to themselves. ($250,000 to Ukraine Relief to fulfill the promise of their proposal, but they deposited it all into Tornado cash to never have to figure out if that was good enough like in a court) [1]
Sometimes I fantasize about become a modern day Robinhood type figure and using these flash loan scams to liberate millions in crypto and then disburse them to people stuck with crippling student loan or medical debts. Not like I’m really doing much else with my life.
https://twitter.com/bertcmiller/status/1402665992422047747?s...
and here
https://twitter.com/0xmisaka/status/1525964196181057537?s=20...
You can go pretty far down the rabbit hole on crypto twitter.
This was also a cool event, there is 7 hours of video and slides, which have more of the kind of info I think you're looking for...discussions about protocol flaws and design etc.
https://flashbots.notion.site/flashbots/mev-day-836f88806995...
I don’t think it counts as one, I was thinking that needs the governance contract to either recursively call itself or call an external unrelated contract
It's gotten incredibly competitive, and there has been quite a bit of consolidation. You used to be able to make a bot that could just make a few thousand dollars per day. Now you're either making 6 figures per day as part of a team, or a few hundred dollars per day on your own. One of the reasons you need a team and financing is that much of it is infrastructure based - being right next to miners/validators in the same server rack, etc. It takes significant resources to have nodes exactly where you need to have them, in various parts of the world.
It's also feast or famine. Sometimes, you'll wake up with hundreds of thousands of dollars from thin air. Here [3] is a loan liquidation using a flash loan from last week that netted the person that submitted it $366K (that was the value at the time) - in a few milliseconds. The only money they had to have to do this tx was the $1.50 transaction fee. The ~$8 million necessary for the liquidation was flash borrowed from a Pancakeswap pair.
[1] https://docs.flashbots.net/
[2] https://eigenphi.io/
[3] https://bscscan.com/tx/0x73d37b728ebd55088d0d7ccd3f82a485ac3...
Surely the people who came up with this financial innovation had some other use for it in mind, one that would outweigh the inherent externality of this-is-a-perfect-vehicle-for-fraud, right? ... right?
An example in the real world...say you're an employee at a large tech company with a bunch of stock options. You want to exercise those options and sell them. In order to exercise those options, you need money that you do not have. Luckily, your brokerage offers a service where they'll exercise the options for you and sell them. You're essentially borrowing their money very quickly to get out of your position.
In DeFi, you could use a flash loan in order to deleverage in a position. So instead of selling a small increment of your position and paying back your loan multiple times, you can instead take a flash loan and pay everything back at once to deleverage.
> Such flash loans have beneficial uses, including help for traders trying to capitalize on price differences between cryptocurrencies on different exchanges. In that sense, they are much like the financing that an investment bank might provide to an investment fund to make bets on different stocks or currencies.
This is their predominant use as well.
If you bid up the price of something on Sushiswap, that also trades on Uniswap, a flash loan will be deployed pretty much in the same block, pull all available capital necessary, and fix that price imbalance to its maximum potential.
Just a form of arbitrage.
Projects have to do system design that accounts for this. Beanstalk did not seem to account for the idea that the liquidity pool would have more than 50% of the BEAN supply eventually. But aside from that, having proposals passable in one block of deposit is the primary vector. Teams and communities like this model though because it basically comes down to "imagine how rich we would be if an attacker actually tried to buy all the tokens, I hope state actors get involved to really test that theory" because then it wouldn't matter if one block or many blocks was used if an actual organization was determined to pass something, this mentality is just not compatible with flash loans when all the liquidity is purchaseable already.
There are other case-specific uses for them, but loan liquidations and arbs are the big ones.
Fyi, their intended use case is to remove arbitrage opportunities, something that improves the UX for ordinary users because you don't have to worry about buying/selling at a suboptimal price.
[0] Attacking the DeFi Ecosystem with Flash Loans for Fun and Profit. https://arxiv.org/abs/2003.03810
Arbitrage is not unethical. I don’t know why you paint it that way.
Another common use for cryptocurrency loans is speculating on other cryptocurrencies or borrowing a lot for a short-term pump & dump. There's smart contracts that will let you borrow at 20% interest leaving the balances of both known, and they'll margin-call you if the trade goes too far against you.
There's no use for these loans outside of cryptocurrency-land: If you buy e.g. an apartment complex, that asset cannot be used as collateral for a cryptocurrency loan and you can't get millions of dollars for cheap like you can a conventional or government loan.
Deleted Comment
If, analogously, my bank had a program where people could propose actions to the bank and vote on them by putting dollars in a "yes" or "No" jar - and I started a "give me the bank" proposal, took out a massive loan and won the vote... What have I done wrong?
For another example, let’s say you were an employee of a retailer with the power to set a discount on certain items. You suddenly set a 100% discount on every item in the store and then buy all the inventory for $0. Try explaining to the police that you were actually fully within your legal right to do that.
But if you were the board, or the majority shareholder, it would be fine. Which is what happened here.
They borrowed money, bought a majority of the BEAN, used that BEAN to vote on their proposal to take all the money, and it passed. They kept the money, sold the BEAN, and returned the borrowed money.
And as much as your example would likely result in some kind of conversation with the police, it also highly depends on whether you discounted items fraudulently or if you did it because you specifically were in the position to do so. Your example describes it as though you had full legitimate power to discount certain items up to 100% off. At that point, at worst you would have violated company policy and not the law. You might get fired for it but when a retailer you work for offers a discount you are eligible to participate in it.
Also I don’t think your retailer comparison works, in this case the power to give the user the rights and ability to create 100% discounts was designed into the system and although the outcome is unintended, it is not a flaw because the system allowed it and everyone using the system was allowed to audit it before putting value in.
No, not the employee, but the owner. Isn't that a more accurate metaphor for this situation?
In regards to your example if the employee truly does have the power to do that and the intention for that power is not stated. I think it's fine for them to take actions which cause the store to lose money.
Edit: As a sibling comment mentioned it's more like if a owner of the business decided to add these discounts.
So shares are similar to governance tokens in DeFi projects. And in the real world, people also borrow money to get more than 50% of the shares. This is called a leveraged buyout.
However, the difference to DeFi is that shareholders have certain rights (like the right to share in the profits and assets) that are protected by laws. That means a majority shareholder cannot take actions that amount to stealing the company's profits or assets from other shareholders, or they'll be sued. They may do things that the other shareholders don't like, like dismantling the company by selling of parts for cash, but they'll have to fairly share the proceeds.
I mean, there is money moved around all the time, there are more and more clever and complex systems.
But are they connected to the real world in some way?
For example, the stock market is. It lets people with savings invest those savings in companies that produce real world goods and services.
Another example is a bank. A bank can loan money to people who want to spend now what they will earn later.
But DeFi? Is anything happening there that has value to mankind? Or is it all a zero-sum game between crypto traders?
You can invest in cryptos that you think will perform some sort of electronic service, like Ether, in expectation that the value will go up if it grows in usage.
It's admittedly pretty hard to make a connection to the physical world. So staying within the virtual world, ownership is an interesting application outside of finance. NFTs are the most prominent but (as art) least interesting examples of blockchain ownership. More interesting is the intersection with gaming, like what you see with Crypto Kitties and Gods Unchained (deck building game where card ownership and scarcity is blockchain driven). Another example is ENS: decentralized domain names.
> A bank can loan money to people who want to spend now what they will earn later.
This topic is much easier. Finance is the first application of blockchain, and there are tons of traditional financial instruments which exist in cryptospace already.
CDPs[1] offer a decentralized way to borrow money.
Compound[2] offers a way to both lend and borrow.
[1] https://coinmarketcap.com/alexandria/glossary/collateralized...
[2] https://compound.finance/
Can you give an example?
This is in contrast to the current stock market in which only a handful of players have the liquidity and the regulatory ability to market make.
Also open source software should be banned, as everyone can search for security exploits. I see it the same with flash loans, etc. It forces DeFi protocols to safeguard against all attack vectors, resulting in a much more secure environment.
But I think the conversation we should be having is, do we want to move towards more resilient markets, given that the additional security will carry a heavy cost in terms of productivity?
I’m sure there are arguments both ways but it seems like we don’t have the full picture yet.
There was enough liquidity in Uniswap V2. A lot of projects incentivize community organized trading liquidity these days. Larger and larger traders are more willing to buy into projects when the liquidity is large enough to support them, but in the past (and simultaenously now in the present, for projects that bother), providing liquidity had a major challenge of both expense and regulatory issues (promising liquidity to potential buyers and actively courting exchanges has been a prong in being designated as a security, but communities expected funds to be used this way anyway, exchanges know this and extort project founders). So now with AMM technology like Uniswap, this has all been solved. Nobody ever has to deal with crypto exchanges again, and communities don't have to worry about liquidity. This has allowed rapid flourishing of some kinds of projects.
Anyway, there are 71,000,000 BEAN tokens in existence. And if you look at the Uniswap liquidity pool, it has risen to around 30,000,000 BEAN slowly over time.[0] And the day the amount got high enough, the person did a flash loan of $1,000,000,000 in stablecoins and bought everything from the liquidity pool, they got 6,000,000 additional BEAN from another source, deposited 36,000,000 BEAN into Beanstalk to get immediate majority vote of their proposal, which gave them all the funds locked up in Beanstalk to themselves (the $80,000,000 or so), withdrew the bean, sold it back into the liquidity pool (resetting the price to what it was before), returned the $1,000,000,000 and kept the $80,000,000 to themselves. ($250,000 to Ukraine Relief to fulfill the promise of their proposal, but they deposited it all into Tornado cash to never have to figure out if that was good enough like in a court) [1]
[0] https://etherscan.io/token/0xdc59ac4fefa32293a95889dc3966828...
[1] https://etherscan.io/tx/0xcd314668aaa9bbfebaf1a0bd2b6553d01d...
If you think they do, you seriously haven’t met genuinely poor people.