SMART CONTRACTS, DEFI & WEB3 SECURITY - Chapter 4, Exercise 3 Solution ========================================================== Why Flash Loan Lenders Take on Essentially Zero Counterparty Risk PROBLEM ------- Explain, using this chapter's own flash loan flow and Chapter 2's own transaction-atomicity/revert behavior, why a flash loan lender takes on essentially zero counterparty risk — even when lending an enormous, completely uncollateralized sum to a stranger. SOLUTION -------- Normally, lending money to someone with no collateral and no credit check would be an extremely risky proposition - the lender is simply trusting the borrower will actually pay it back later, with no real mechanism forcing that to happen. This chapter's own flow shows flash loans avoid this entirely, but not by trusting the borrower any more than usual - by removing the need for trust altogether. The key is that a single Ethereum transaction is atomic, per Chapter 2's own out-of-gas/revert behavior: if execution fails to complete, every attempted state change is undone, as if none of it had ever been attempted. This chapter's own flow forces the entire loan - borrowing, using the funds, and repaying them - into that one, single atomic transaction. This means there are really only two possible outcomes, and no middle ground: 1. The borrower successfully repays the loan plus the fee before the transaction finishes. In this case, from the chain's own perspective, the whole sequence completed successfully, and the lender's own funds are back, safe, plus a fee. 2. The borrower fails to repay in time, for any reason. Because the transaction is atomic, the EVM reverts EVERYTHING that happened in it - including the original loan itself. From the chain's own perspective, it's exactly as though the loan was never made at all. The lender's funds were never actually, permanently handed over in any state the chain will ever record as final. There is no real scenario where the borrower successfully "walks away" with the borrowed funds without repaying, because the atomicity guarantee makes that specific outcome structurally impossible rather than merely discouraged or penalized after the fact. The lender doesn't need to trust the borrower's honesty, reputation, or ability to be tracked down later - the transaction's own atomic nature does all the real enforcement work, with nothing left to a legal system, a credit check, or good faith. ANSWER: A flash loan lender takes on essentially zero counterparty risk because the loan and its repayment are forced into one single atomic transaction - either the borrower repays in full and the whole transaction succeeds, or the entire transaction (including the original loan) is reverted as if it never happened. There's no possible outcome where the borrower keeps the funds without repaying, since atomicity makes that specific failure mode structurally impossible rather than something the lender simply has to trust won't happen. ---- WHY THIS WORKS AS AN ANSWER This explicitly connects the chapter's own four-step flash loan flow to Chapter 2's own atomicity/revert behavior, correctly identifying that trust is removed structurally (by the transaction's own all-or-nothing nature) rather than reduced through some weaker mechanism like reputation or partial guarantees.