Hacker News new | ask | show | jobs
by freemint 1518 days ago
A flash loan is a risk free crypto loan. It works by releasing the money only on the condition that it is returned before the end of the block. If it is not returned by the end of a block, the block is invalid and can not be added to the blockchain (provided the majority follows the block chain rules). Any block that is added to the blockchain has an exclusive lock to the entire block chain (no two blocks can "happen" at the same "time") meaning this guarantees atomicity of what happens in a block.
2 comments

But then how are the funds used? Why is somebody able to transact with funds that they will receive in a block that hasn’t yet been added to the chain?
The transaction is basically a function call like this:

flash_loan(int amount_borrowed, func arbitrary_trades)

1. give LOANEE_ADDRESS amount_borrowed

2. call arbitrary_trades()

3. give LOANER_ADDRESS (amount_borrowed + interest)

When 2. is executed, the loanee has the money. When 3. is complete, the loaner has the money back. If the loanee doesn't have the money to give, 3rd step fails. And since its atomic, the whole transaction fails.

This but it's transactions, not blocks.