How Does a Time-Weighted Average Price (TWAP) Help Defend against Price Feed Attacks?
A Time-Weighted Average Price (TWAP) is a method that calculates the average price of an asset over a specific period, rather than taking the price at a single moment. This mechanism effectively smooths out any sudden, short-lived price spikes or drops caused by manipulation attempts, such as those executed via flash loans.
Since a flash loan attack is instantaneous, the momentary manipulated price has minimal impact on the overall calculated average, thus protecting the smart contract.