Guglielmo Anfossisincronik.itBook a call

The Magic of Flash Loans (Part 1): Capital Was Never the Constraint

Constraints, episode 10

The Magic of Flash Loans (Part 1): Capital Was Never the Constraint

Flash loans look like free money. They are something stranger: a primitive that removes the constraint everyone assumed was fundamental, and in removing it, shows which constraint was doing the real work.

The first time I heard the term flash loan, I assumed someone was joking.

A loan with no collateral, no credit check and no paperwork, where a wallet holding nothing at all can borrow millions for the length of a single transaction. Outside a blockchain that is not a financial product, it is a contradiction.

Inside one it is one of the more elegant primitives anyone has built, and not for the reason people usually give. It does not conjure money out of thin air.

It quietly changes what a loan is.

Picture someone handing you a hundred million dollars. You can do whatever you like with it: trade it, liquidate positions, buy assets, sell them, move liquidity across protocols.

There is one condition.

Before the transaction ends, every cent has to come back, along with a small fee. If it does not, the transaction reverts and every step inside it is rolled back together. Not unwound partially, not settled at a loss. The failed attempt still costs you the gas you spent making it, and that is the only trace it leaves.

That condition is the entire trick, and it rests on something the traditional financial system does not have.

A blockchain executes a transaction atomically.

From the lender’s side the risk is close to zero. The funds return inside the same transaction, or they never left the vault. Repayment is not a promise you are trusted to keep.

It is a precondition for the money existing in your hands at all.

There is a detail worth making explicit, because it changes who the borrower even is. You do not take a flash loan by pressing a button from an ordinary address.

The lender sends the funds and then calls back into the borrower to run the rest of the sequence, which means the borrower has to be code: a contract holding the whole thing, borrow, act, repay, as one programmed instruction the chain executes in one breath. Since the Pectra upgrade an ordinary account can temporarily point at such code and act as that borrower itself, so deploying a separate contract is no longer strictly required.

Either way the account can be empty of funds.

What it cannot be empty of is logic.

That idea held my attention longer than I expected. For a while I spent most of my evenings on EigenPhi, watching liquidations, arbitrage, just-in-time liquidity, and every other mechanism people were inventing on top of borrowed capital.

At one point I built a small liquidation scraper of my own. Instead of monitoring every position across a lending protocol, I narrowed the search to wallets deployed through a specific contract that let users run recursive leverage loops, borrowing against their own collateral again and again to amplify their exposure to one product’s incentives.

Leverage of that shape does not simply enlarge a position, it shortens the distance to the liquidation threshold: the ratio between what is owed and what is posted moves faster than the price of the asset underneath it, so a fall that an ordinary borrower would absorb pushes a looped one over the line.

When the underlying dropped, those wallets went first, and they unwound into liquidations far larger than average.

I could not out-execute the professionals, who were colocated, tuned, and wired into private orderflow. So I tried to compete on the search space instead: fewer opportunities, each worth much more. I set it aside eventually, not because it could not work, but because I had more important things to build.

What it left behind was a suspicion about where the real limits in finance actually sit.

Flash loans quietly loosen one of the oldest of them, which is capital. If an operation is guaranteed by construction to end with more than it started, and by enough to cover the loan fee and the gas, you no longer need to own the money to run it. You borrow it for the span of a single transaction and hand it straight back.

The barrier does not disappear so much as move, and where it moves to is worth watching: who sees the opportunity first, who can get their transaction into the block on the right terms, who can act without broadcasting their intention into a public mempool, who sits closer to the network, who has built the better machine.

The contest shifts away from wealth and toward engineering.

Most people meet flash loans through stories of exploits, which is a shame, because many of their uses are ordinary and useful.

Arbitrage is the clearest. Suppose ETH trades at three thousand dollars on one venue and three thousand and ten on another, and both of them are on-chain, because that is the condition that matters here: a transaction can only be atomic across things the chain itself settles.

You can borrow fifty million through a flash loan, buy on the cheaper venue, sell on the dearer one, repay the loan with its fee, and keep what is left, having never owned fifty million at any point. Whether anything is left is a separate question, since the fee, the gas, and the price impact of pushing fifty million through a pool all eat into that ten dollar spread first.

What you needed was not the capital. It was the ability to run every step as one indivisible act.

Liquidations are the other honest case. Lending protocols let people borrow against collateral, and when the collateral falls too far, someone has to repay part of the debt and take the collateral at a discount. Without flash loans that job is rationed by access to deployable capital: it belongs to whoever happens to be sitting on enough of it at the right moment.

With them, anyone who can write the transaction can borrow the repayment amount, close the unhealthy position, sell the collateral, return the loan, and keep the bonus.

The protocol stays solvent, the bad debt is cleared, the liquidator is paid. It is a mechanism where the incentives happen to point the right way.

Like any primitive with this much reach, it is neutral about how it is used, and the same atomicity that makes arbitrage clean makes certain attacks cheap.

One is liquidity manipulation. Many protocols quietly assume that prices or pool depth stay roughly stable across a transaction. A flash loan can flood a pool with capital, distort its state for the length of a few instructions, exploit a second protocol that trusts that distorted state, and drain the capital back out before the transaction closes.

Nothing was broken at the protocol level. A protocol had taken a number that was cheap to move and treated it as a reading of something expensive to move.

The assumption was simply false, and the loan was large enough to prove it.

Then there is the sandwich.

Imagine you are standing in line to buy a hamburger at the posted price. The person behind you sees your order before it is filled. They step in front of you, buy the last hamburger at that price, which pushes the price up, and then turn around and sell it to you at the higher number, keeping the difference.

You still walk away with your hamburger. You just paid more for it than you would have a moment earlier, and the extra went to someone who did nothing but stand between you and the counter.

On-chain the counter is a decentralized exchange, the queue is the public mempool, and your purchase is the filling: the attacker buys just before you and sells just after, wrapping your transaction on both sides. A flash loan can pay for that position, so the attacker does not have to own the capital that moves the price.

But capital was never what made this hard.

This is why modern MEV is not mainly a story about money. Capital still matters, and some strategies are made of little else. But once temporary liquidity is available to anyone who can write the transaction, it stops being the thing that separates the people who capture value from the people who watch it go past.

What separates them is information, position, and execution: who sees the opportunity first, who can get their bundle into the block that actually gets built, who avoids leaking their intent into the open, who has built the machine that does all three a little better than everyone else.

And getting there is not a footrace to the validator. It is an auction, run through searchers and builders and relays, where the bid is not only in gas.

Capital stopped being the moat.

The moat is now upstream, in the engineering.

Which brings the whole thing back to where this newsletter usually starts. The magic of flash loans was never that they abolished collateral. It was that they exposed a mistaken assumption about which constraint was load-bearing.

We treated capital as the wall, the thing you had to own before you could act, when capital was only ever a proxy for the constraint that actually bound: time, and the trust that has to fill it.

Borrowing, trading, settlement and repayment were separate acts with gaps between them, and traditional finance has spent a century building machinery to survive those gaps. Credit lines, prime brokers, collateral agreements, netting, intraday facilities: all of it is a way of paying someone to carry the risk the gap creates.

Atomicity does not manage the gap. It removes it, and with it the need to be trusted across it.

Once that became possible, the wall we had been building against turned out not to be there.

It made some markets dramatically more efficient and it handed some people a cheaper way to steal. All it did was remove one constraint. What fills the space that opens up is not decided by the primitive.

It is decided by us.

That raises a different question: where does the constraint reappear once capital is no longer the gate?

Next: Episode #11: The Magic of Flash Loans (Part 2): The Next Octave

Also published on LinkedIn.