How Does a Constant Product Market Maker (CPMM) Work?
A CPMM, like Uniswap v2, maintains a constant product for the reserves of two assets in a liquidity pool, defined by the formula x y = k. When a user trades, the ratio of x and y changes to maintain k, which determines the new price.
The larger the trade, the more the price shifts (slippage), which is the mechanism exploited by sandwich attacks.