News for hackers. Stuff that matters.
Re:Attacking the DeFi ecosystem with flash loans for fun and... by v64 on Saturday January 16, 2021 @05:29PM (#25806137)
Flash loans are a great example of how blockchains enable new types of financial transactions that either aren't possible or are very difficult to do in a traditional financial setting.

If you identify an arbitrage opportunity in the market, you can atomically borrow a large sum of money to take advantage of the price difference. You also have the added assurance that if the arbitrage opportunity goes away before you can take advantage of it, the entire transaction fails and you only lose the Ethereum transaction fee. It's essentially risk-free arbitrage.

This paper [1] dives into detail about how these arbitrage mechanics play out on the blockchain, and how both arbitrageurs and miners manipulate transactions in order to make a profit.

[1] https://arxiv.org/abs/1904.05234

Re:Attacking the DeFi ecosystem with flash loans for fun and... by joosters on Sunday January 17, 2021 @02:26AM (#25808924)
But the only legitimate use of a flash loan is to do some arbitrage - and there’s plenty of that in existing financial systems. All the other uses are for leveraging up theft and manipulation of markets. Well done cryptocurrencies, you’ve made a new cesspool of villainy!

Anyway, it’s not clear to me why flash loan providers are still a thing, as they seem to be open to a second layer of abuse: transaction copying / sniping:

All flash loan borrowing transactions are profitable (otherwise they wouldn’t be able to pay back the loan) - but why let the originator of the transaction keep that profit? What a sensible attacker should do is: 1) watch for flash loan transactions to be submitted by someone, then 2) quickly submit a duplicate transaction with a larger fee, but change the destination wallets to your own. That way, you get all the proceeds of a theft, and not just the loan interest rate.

Given this possibility, flash loan pools could be considered as ‘bait’ or a trap for the unwary thief...

Re:Attacking the DeFi ecosystem with flash loans for fun and... by v64 on Sunday January 17, 2021 @03:04AM (#25809073)
> But the only legitimate use of a flash loan is to do some arbitrage - and there’s plenty of that in existing financial systems.

There are two main differences:

1) The atomic nature of a flash loan makes flash loan arbitrage much less risky than performing arbitrage traditionally. Doing the same type of arbitrage non-atomically may mean that you miss the arbitrage opportunity, resulting in a loss from having to pay back the loan you took out plus interest without having made any money with it.

2) Because the debt must be repaid in the same transaction, the loan is uncollateralized. As far as I know, one cannot borrow millions of dollars in the traditional financial system without putting up some kind of collateral.

> What a sensible attacker should do is: 1) watch for flash loan transactions to be submitted by someone, then 2) quickly submit a duplicate transaction with a larger fee, but change the destination wallets to your own.

This has been observed on the blockchain in practice. The paper I linked to describes the mechanics of how this plays out and what strategies competing arbitrageurs use to win these opportunities.

Re:Attacking the DeFi ecosystem with flash loans for fun and... by fbrusch on Sunday January 17, 2021 @06:35AM (#25809929)
Here's a story about that (it's called "frontrunning"): https://medium.com/@danrobinson/ethereum-is-a-dark-forest-ec...
Re:Attacking the DeFi ecosystem with flash loans for fun and... by tracedddd on Sunday January 17, 2021 @11:24AM (#25812006)
Flash loans can totally be (and are) attacked like you describe. In fact much of DeFi can be frontrun. Most commonly it’s large trades to AMMs, where the original buyer ends up getting significantly more slippage than they expected.

The future is likely private smart contracts like Secret (https://scrt.network/)in which the contract’s internal state and the function calls are entirely obscured using sMPC or by leveraging SGX enclaves. This makes it impossible to frontrun in most cases.

Whether an unauditable financial system is a good thing or bad thing is still up for debate.

Re:Attacking the DeFi ecosystem with flash loans for fun and... by gge on Saturday January 30, 2021 @10:06PM (#25975413)
I'm late to this thread, but this is incorrect. Flash loans are used for many things other than arbitrage/attacks. 2 examples include the ability to swap collateral/debt and the ability to migrate assets between defi protocols (migrate from aave v1 to aave v2 etc). Many of Defisavers and Instadapps features are powered by flash loans.
Re:Attacking the DeFi ecosystem with flash loans for fun and... by the_local_host on Saturday January 16, 2021 @06:29PM (#25806538)
Wouldn't a lender charge money for what is essentially an option to borrow contingent on the arbitrage transaction going through?
Re:Attacking the DeFi ecosystem with flash loans for fun and... by ryebit on Saturday January 16, 2021 @07:45PM (#25807010)
Per other responses, they frequently do charge a special fee (I think Aave charged around 0.09% at one point but can't find good ref right now).

One interesting thing I think is still under dev/consideration is adding the ability for MakerDAO to make "flash mint loans"(https://forum.makerdao.com/t/mip25-flash-mint-module/4400/9) -- essentially a flash loan where the caller can mint an arbitrary amount of DAI without having to back it with anything, so long as they pay it back + fee at the end.

There's a similiar idea being worked out for WETH10 (https://github.com/WETH10/WETH10#flash-loans), a project trying to make a feature update of the WETH (wrapped ether) token.

I'm honestly unsure WTH the impact of something like these would be, but would definitely prevent arbitrage from going too far out of bounds, since there would always be unlimited liquidity.

Multi-party atomic financial transactions are kinda insane.

Re:Attacking the DeFi ecosystem with flash loans for fun and... by AaronFriel on Saturday January 16, 2021 @06:34PM (#25806572)
So someone else starts a lender to charge slightly less. The race to the bottom happens very quickly.
Re:Attacking the DeFi ecosystem with flash loans for fun and... by the_local_host on Saturday January 16, 2021 @06:44PM (#25806637)
I don't think it makes sense to handwave the cost of an option to borrow to 0 in a scenario where arbitrage is assumed to still exist. If anything is going to become perfectly efficient first it's the arbitrage ("free money!").
Re:Attacking the DeFi ecosystem with flash loans for fun and... by qqii on Saturday January 16, 2021 @07:04PM (#25806752)
Feeless flash loans exist: https://money-legos.studydefi.com/#/dydx

Aave is 0.09%: https://aave.com/flash-loans/

It is also an important part of uniswap: https://uniswap.org/docs/v2/core-concepts/flash-swaps/

Any fees on a flash loan will disincentive closing arbitrage positions to that fee amount.

Re:Attacking the DeFi ecosystem with flash loans for fun and... by the_local_host on Saturday January 16, 2021 @08:05PM (#25807111)
This seems to good to be true. From https://money-legos.studydefi.com/#/dydx :

    Borrow x amount of tokens. (Withdraw)
    Call a function (i.e. Logic to handle flashloaned funds). (Call)
    Deposit back x (+2 wei) amount of tokens. (Deposit)
It looks like unlimited leverage for flat fee.
Re:Attacking the DeFi ecosystem with flash loans for fun and... by v64 on Saturday January 16, 2021 @08:15PM (#25807150)
This article [1] does a deep dive into how flash loan mechanics are structured using an actual Ethereum transaction as an example. This particular flash loan used dYdX, Uniswap, Aave, and Curve.fi.

Because of the atomicity of the transaction, there's no way to default on the loan. If you can't pay it back, you're never loaned the money in the first place.

[1] https://medium.com/@kentmakishima/the-43k-defi-magic-trick-f...

Re:Attacking the DeFi ecosystem with flash loans for fun and... by theptip on Saturday January 16, 2021 @09:41PM (#25807586)
In general the fee on a loan is based on two things: risk of default, and the time-value of money. It’s possible for the former to be zero, but lenders are losing money if they set the latter to zero.

Basically if you put $1000 of capital into the pot for making flash loans, then you are foregoing the X% / year that you could earn on interest, i.e. you are losing money.

It’s entirely possible that platforms are running these flash loans as a loss leader to drive adoption, but in a mature market and at scale, you’d expect there to be a small fee.

(Or just that the success-case fee covers the loss in the failure case, but that would break if the % of failed txns increased, so might not be a stable equilibrium. )

Re:Attacking the DeFi ecosystem with flash loans for fun and... by jonreem on Sunday January 17, 2021 @12:08AM (#25808322)
The time-value still comes into play in the form of eth transaction fee. If you're flash loaning to take advantage of an open arbitrage opportunity there will be other parties trying to take advantage of it, so you will pay more to get your transaction in before theirs.

For a lot of transactions like this its actually miners who can detect and rewrite these transactions to take advantage of the arbitrage opportunities first, for this reason this cost is called "miner extractable value" or MEV.

However, note this fee doesn't accrue to the lender!

Re:Attacking the DeFi ecosystem with flash loans for fun and... by xur17 on Saturday January 16, 2021 @10:36PM (#25807852)
> Basically if you put $1000 of capital into the pot for making flash loans, then you are foregoing the X% / year that you could earn on interest, i.e. you are losing money.

The funds aren't foregoing interest in all cases though. Ex: uniswap, curve, etc all require assets to be deposited, and pay depositors trading fees. These protocols could generate additional income by providing assets for flash loans without affecting the income received for acting as an amm.

Re:Attacking the DeFi ecosystem with flash loans for fun and... by theptip on Saturday January 16, 2021 @11:20PM (#25808081)
I see, good point. If the deposits are there already then it’s no loss to put them to work like this.
Re:Attacking the DeFi ecosystem with flash loans for fun and... by monokh on Saturday January 16, 2021 @08:37PM (#25807254)
What I struggle to understand is why the capital can be used with no fee (dydx - 2 wei). Why would someone contribute to such a pool that pays no interest as opposed to staking or lending somewhere else?
Re:Attacking the DeFi ecosystem with flash loans for fun and... by EGreg on Saturday January 16, 2021 @07:40PM (#25806985)
No, blockchains are not the future, they are really the reason why one transaction can happen at a time in the whole world. Even Ethereum 2.0 will have shards which will do away with this anomaly. The only reason flash loans even work with no collateral is because you can be sure nothing else is running on the “world computer” while your transaction runs, so you can roll it back with no risk except gas fees.

Vitalik himself acknowledges this, the guy is quite honest and straightforward about its limitations: https://thenextweb.com/hardfork/2019/08/19/vitalik-buterin-e...

Vitalik Buterin: Using Ethereum is expensive, and its blockchain is ‘almost full’ He also said blockchain's 'problem' is that every computer verifies every transaction

Actually blockchains are a first-generation technology that do global consensus for every block, which literally means all transactions in the world must go through one computer in the world (the miner) although it’s a different one each time. And the situation is actually worse, since you don’t know who would mine the next block in advance, every transaction must be sent to every potential miner! Imagine if BitTorrent had every computer store and seed every movie instead of using DHT.

The ability to send or loan arbitrarily large amounts for a fixed fee is a symptom of centralization. In a fully distributed network, transaction fees would have to be proportional to transaction size!

Almost every other protocol on the Internet does not have such bottlenecks in its design. No one asks how many emails or websites can be served per second. Blockchain is trying to secure every transaction using the entire network! That is why so much electricity is wasted just to do 7 transactions per second.

The next generation of crypto will actually be able to power payments using embarrasingly parallel architecture. Until then, we have blockchain.

Ethereum is nicknamed the “world computer” for a reason. Gas fees are super high for small transactions like paying for coffee or voting in a secure election. Just one app KryptoKitties can clog up the entire network.

We built Intercoin apps on top of Ethereum (https://intercoin.org/applications) but we are not going to wait around for Ethereum 2.0 - which is blockchain also. Kik Messenger and others have long gotten off.

Re:Attacking the DeFi ecosystem with flash loans for fun and... by qqii on Saturday January 16, 2021 @08:02PM (#25807105)
Sharding is simply not ready, as far as I know no project currently with smart contracts have non a blockchain structure.

That said currently ethereum has many L2 solutions (https://ethereum.org/en/developers/docs/layer-2-scaling/) that "run in parallel" and result in low gas fees.

So far I've not seen any hint of an "embarrasingly parallel architecture" that can satisfy the safety requirements that a blockchain also does and run smart contracts. I'd be happy to read up if you can point me to any research or projects that I've missed.

Re:Attacking the DeFi ecosystem with flash loans for fun and... by pawelduda on Saturday January 16, 2021 @09:14PM (#25807435)
I wonder what are your thoughts on Avalanche (https://www.avalabs.org). They claim to offer throughout of 4500 TPS and smart contracts with EVM compatibility. Make sure to check the whitepaper for the protocol consensus, it's supposedly a novel thing and there are a some knowledgeable people behind it.
Re:Attacking the DeFi ecosystem with flash loans for fun and... by hanniabu on Sunday January 17, 2021 @12:46AM (#25808495)
In my opinion al these other projects are just getting attention because Ethereum is struggling with throughput right now. Once ETH2 is released, or even before that with L2, all these other projects will become pointless.

Ethereum has so much network effect that these other projects need to actually pay people to use them over Ethereum. Not to mention they're also more centralized.

Re:Attacking the DeFi ecosystem with flash loans for fun and... by Vinceo on Sunday January 17, 2021 @02:34AM (#25808958)
I agree to some point. Though, Ethereum doesn't have time to wait for Eth2 imo as it will take years before it's fully released. So it will have to rely on l2 scaling until then.

A lot of other platform projects are providing bridges which makes it possible to use those projects as some sort of an L2 for ethereum. If a lot of dapps starts migrating to those instead of to native L2 solutions it can get ugly.

Re:Attacking the DeFi ecosystem with flash loans for fun and... by hanniabu on Monday January 18, 2021 @01:11AM (#25818731)
L2 is already rolling out. They're currently doing progressive rollout starting with synthetix.
Re:Attacking the DeFi ecosystem with flash loans for fun and... by EGreg on Saturday January 16, 2021 @09:24PM (#25807485)
Will definitely check it out! This space is really home to many interesting projects (including our own) to have alternative architectures. The trick is how to remain compatible with EVM since most of the developers targeted it.
Re:Attacking the DeFi ecosystem with flash loans for fun and... by EGreg on Saturday January 16, 2021 @09:13PM (#25807432)
You can start here: https://forum.intercoin.org/t/overview-and-implications-of-i...

However, the actual technical research paper with rigorous mathematical proofs is still going through peer review, but if you email me I am happy to share it with you.

Re:Attacking the DeFi ecosystem with flash loans for fun and... by MacsHeadroom on Saturday January 16, 2021 @11:00PM (#25807975)
What do you think of David Chaum's xx? Each transaction only sent to end charged by a random pool of 5 nodes that reshuffles every 10 seconds. Throughput scales linearly with network size.
Re:Attacking the DeFi ecosystem with flash loans for fun and... by EGreg on Sunday January 17, 2021 @01:25AM (#25808640)
Yes, it is a good step forward.

Really, what you need is a distributed hash table (like MaidSAFE), or randomness beacons (like Algorand) to select a subset of the network. This paper shows mathematically that the probability of a double-spend goes down exponentially with the number of notaries, and having the entire network secure every transaction, no matter the size, is wayyyy overkill:

https://arxiv.org/pdf/0802.0832v1.pdf

Re:Attacking the DeFi ecosystem with flash loans for fun and... by hanniabu on Saturday January 16, 2021 @08:09PM (#25807121)
So in other words you're shitting on Ethereum as a reason to shill your own coin since there'd be no reason for your coin unless you make people believe Ethereum is garbage? Ethereum is moving to proof of stake and there's also L2 networks. There, problem solved.
Re:Attacking the DeFi ecosystem with flash loans for fun and... by EGreg on Saturday January 16, 2021 @09:03PM (#25807372)
Yeah, I am saying global blockchains are a first generation technology. Sorry it hurts your feelings. I would like to also “shill” MaidSAFE and Solana:

http://maidsafe.net/

https://solana.com/

If you don’t like ME saying it — here is VITALIK HIMSELF saying it, the guy is quite honest and straightforward about its limitations: https://thenextweb.com/hardfork/2019/08/19/vitalik-buterin-e...

Vitalik Buterin: Using Ethereum is expensive, and its blockchain is ‘almost full’

He also said blockchain's 'problem' is that every computer verifies every transaction

Actually Ethereum 2.0 should be “fast enough” for many applications. It’s still going to be doing a global consensus, but at least it will be able to handle actual real world usage - people paying for coffee, let’s say, or voting in elections.

In fact, a major reason that so many ICOs from 2017 were considered scams is that the tokens could not actually be used for their intended purpose. Teams like Kik Messenger discovered this early on and moved away:

https://medium.com/kinblog/kin-pushing-ahead-next-steps-on-t...

Re:Attacking the DeFi ecosystem with flash loans for fun and... by imtringued on Sunday January 17, 2021 @03:46AM (#25809221)
Big question. Why would I want to pay capital gains taxes on my coffee?
Re:Attacking the DeFi ecosystem with flash loans for fun and... by fidelramos on Sunday January 17, 2021 @05:19AM (#25809601)
I don't think anybody wants to pay capital gains taxes when purchasing things with cryptocurrencies. Fortunately there are countries with a sane tax policy regarding cryptocurrencies where you don't pay taxes on cryptocurrencies, such as Portugal [0]. Maybe Americans should be pressuring their government for changes to the laws so cryptocurrencies can be useful for payments like they were originally intended?

[0] https://www.forbes.com/sites/kellyphillipserb/2019/09/19/por...

Re:Attacking the DeFi ecosystem with flash loans for fun and... by CryptoPunk on Sunday January 17, 2021 @02:08AM (#25808823)
>>The only reason flash loans even work with no collateral is because you can be sure nothing else is running on the “world computer” while your transaction runs, so you can roll it back with no risk except gas fees.

The more important reason flash loans work on Ethereum is that Ethereum runs programmatic contracts that can take the output of a function call from a different contract as their input. This is something that doesn't exist outside of the world of smart/programmatic contracts.

The blockchain just provides the immutable ordering of transactions and credible neutrality of access-control needed for the state of programmatic contracts to accrue value.

Re:Attacking the DeFi ecosystem with flash loans for fun and... by seibelj on Saturday January 16, 2021 @08:45PM (#25807295)
Even if there can be parallel computation a flash loan can still occur. The concept is borrowing a huge sum of money for a split second to take instant advantage of an opportunity. This can happen outside of a single threaded VM model.
Re:Attacking the DeFi ecosystem with flash loans for fun and... by EGreg on Saturday January 16, 2021 @09:04PM (#25807381)
Well, yes but only if all the smart contracts that are being called are on the same shard. Ideally under Ethereum 2.0 these assumptions will disappear. In fact Ethereum 2.0 should be “fast enough” for most applications.
Re:Attacking the DeFi ecosystem with flash loans for fun and... by Animats on Saturday January 16, 2021 @09:23PM (#25807479)
The next generation of crypto will actually be able to power payments using embarrasingly parallel architecture.

Been hearing that for years. Anyone yet have anything running that allows a digital currency to scale without being vulnerable to the attacks Bitcoin can resist?

Re:Attacking the DeFi ecosystem with flash loans for fun and... by Geee on Sunday January 17, 2021 @09:56AM (#25811110)
Nano is the only currency that is capable of hundreds of transactions in a second without fees, and runs in a trustless and decentralized mode (https://nano.org)

For the time being, no one has found vulnerabilities in it.

Re:Attacking the DeFi ecosystem with flash loans for fun and... by EGreg on Saturday January 16, 2021 @09:27PM (#25807500)
Not that I know of. From the mainstream ones, Ripple and Stellar come the closest. MaidSAFE has been in development since 2006 and is launching soon.

What can I say, the first generation of any technology is laughably inadequate as a replacement for what came before. That is why for example hardlh anyone uses Bitcoin in everyday transactions and why we still don’t use technology to secure voting, but that will change. As an aside, I don’t think blockchain is the best technology for voting but it’s the buzzword that people understand:

https://www.coindesk.com/in-defense-of-blockchain-voting

Re:Attacking the DeFi ecosystem with flash loans for fun and... by DSingularity on Saturday January 16, 2021 @11:41PM (#25808187)
Literally nobody thinks Blockchain is good for voting.
Re:Attacking the DeFi ecosystem with flash loans for fun and... by literallycancer on Sunday January 17, 2021 @11:09AM (#25811838)
It's not good, on the other hand it can easily be better than the monstrous only-working-by-accident software some government contractors can come up with.
Re:Attacking the DeFi ecosystem with flash loans for fun and... by EGreg on Saturday January 16, 2021 @11:45PM (#25808220)
Re:Attacking the DeFi ecosystem with flash loans for fun and... by JohnJamesRambo on Saturday January 16, 2021 @09:07PM (#25807390)
I don't think you understand why we use blockchains.
Re:Attacking the DeFi ecosystem with flash loans for fun and... by EGreg on Saturday January 16, 2021 @09:11PM (#25807415)
Please explain. Perhaps I am missing something. The main reasons seem to be trustless security and immutability.
Re:Attacking the DeFi ecosystem with flash loans for fun and... by Vinceo on Sunday January 17, 2021 @02:29AM (#25808942)
Check out avax (avalanche) for your dapp. It actually scales in a decentralized manner unlike most of the other "ethereum killers".
Re:Attacking the DeFi ecosystem with flash loans for fun and... by literallycancer on Sunday January 17, 2021 @11:05AM (#25811793)
Sharding is a dead end. Zero knowledge rollups solve most of the scalability problems without compromising security.
Re:Attacking the DeFi ecosystem with flash loans for fun and... by xwdv on Saturday January 16, 2021 @07:00PM (#25806733)
Wow this sounds like a great way to make a lot of risk free money very quickly. How do you scale the identification of arbitrage opportunities?
Re:Attacking the DeFi ecosystem with flash loans for fun and... by v64 on Saturday January 16, 2021 @07:14PM (#25806801)
The Flash Boys 2.0 paper I linked to in my original comment provides some detail as to how these opportunities are identified and exploited by competing arbitrageurs.