> For the complete documentation index, see [llms.txt](https://funarchy.gitbook.io/funarchy/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://funarchy.gitbook.io/funarchy/security-for-prediction-market/trading-mechanism/amm-risks/slippage-and-sandwich-attacks.md).

# Slippage & Sandwich Attacks

#### Description

In AMM-based prediction markets, the buy and sell functions must receive parameters such as the minimum amount received (`minAmountOut`) or maximum price allowed (`maxPriceLimit`) from users to limit slippage.

AMMs have the advantage of enabling trading without liquidity gaps, but if slippage verification is not properly performed, users may receive tokens at a rate significantly less favorable than expected, and attackers may profit from the difference.

#### Attack Scenario

**Scenario - Absence of Slippage parameters**

```javascript
// Scenario - Slippage Parameter nonexist code

function vulScenario(address recipent) external payable {
    ...
    // No Slippage Check!!
}
```

{% stepper %}
{% step %}
The attacker captures the victim's transactions from the mempool.
{% endstep %}

{% step %}
The attacker submits a transaction with a higher gas fee than the victim.
{% endstep %}

{% step %}
The victim receives much less tokens (or at a much higher price) than expected.
{% endstep %}

{% step %}
The attacker immediately enters into an opposite position to lock in the profit.
{% endstep %}
{% endstepper %}

#### Mitigation

* **Slippage parameter required**
  * When calling the `buy()` or `sell()` function, it must be designed to include slippage-related parameters such as the minimum amount received (`minAmountOut`) and the maximum allowed price (`maxPriceLimit`).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://funarchy.gitbook.io/funarchy/security-for-prediction-market/trading-mechanism/amm-risks/slippage-and-sandwich-attacks.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
