**Appendix A. Attack Cost Calculation for Constant Product Market**

In constant product AMMs, the liquidity is defined as follows:

$$
\alpha \times y = k \tag{A1}
$$

If an attacker wants to move the spot price of an asset, they would need to swap against the pool, depending on whether they want to manipulate the price up or down. If we assume that they want to increase the price of *y*, they would need to sell some amount of *x* and receive some *y* tokens in return (adding *x* tokens from the pool, an attacker decreases its value). After the swap, the liquidity in the pool will be as follows:

$$(\mathbf{x} + \Delta \mathbf{x})(y - \Delta y) = k = \mathbf{x}y \tag{A2}$$

From here, we can express the Δ*y*—how much of token *y* attacker would receive after making a swap:

$$
\Delta y = y(\frac{\Delta x}{x + \Delta x}) \tag{A3}
$$

Because the attacker wants to increase the price *y* by adding the Δ*x* tokens and removing Δ*y* tokens, we can express how big the change of manipulated price *pj* would be:

$$p\_j = \frac{\mathbf{x} + \Delta \mathbf{x}}{y - \Delta y} = \frac{\mathbf{x} + \Delta \mathbf{x}}{y - y(\frac{\Delta \mathbf{x}}{\mathbf{x} + \Delta \mathbf{x}})} = \frac{(\mathbf{x} + \Delta \mathbf{x})^2}{\mathbf{x}y} = \frac{(\mathbf{x} + \Delta \mathbf{x})^2}{k} \tag{A4}$$

From here, we can express the Δ*x*—how many tokens *x* are needed to get the target *pj*:

$$
\Delta \mathbf{x} = \sqrt{p\_{\rangle} \times y \times \mathbf{x}} - \mathbf{x} \tag{A5}
$$

Now, when we know both how many tokens *x* will be needed to make a swap and how many tokens *y* we receive in exchange, we can easily calculate the total attack cost by subtracting Δ*x* − Δ*y*:

$$A\mathcal{C} = (\sqrt{p\_{\dot{\jmath}} \times \underline{y} \times \underline{x}} - \underline{x}) - p\_{\dot{\jmath}} \times y \frac{\sqrt{p\_{\dot{\jmath}} \times \underline{y} \times \underline{x}} - \underline{x}}{\text{tr} + (\sqrt{p\_{\dot{\jmath}} \times \underline{y} \times \underline{x}} - \underline{x})} \tag{A6}$$
