Updated 67 days ago

AntiSandwichHook

A hook to protect against sandwich attacks. Its main goal is to prevent attacks by analyzing transactions and charging additional fees if the transaction looks suspicious.

  • Crypto / Web3
  • DeFi

AntiSandwichHook - Protection Against Sandwich Attacks in Uniswap V4

AntiSandwichHook is a smart contract solution designed to prevent sandwich attacks in Uniswap V4 pools. A sandwich attack occurs when a malicious actor (usually an MEV bot) manipulates the price of a token by placing transactions before and after a target swap, exploiting price slippage to extract profit. This project introduces a custom Uniswap V4 hook that monitors pool state changes and dynamically adjusts fees to mitigate the effects of sandwich attacks.

How It Works

  1. Before Swap: The hook captures the current pool state (liquidity, price, and fees) and stores a checkpoint.
  2. After Swap: After the swap, the hook checks whether the balance changes indicate a sandwich attack by comparing the final pool state with the checkpoint.
  3. Dynamic Fee Adjustment: If an attack is detected, the hook can dynamically adjust commissions and redistribute funds to the pool to mitigate the effects of the attack.

Key Features

  • Dynamic Price Protection: The hook detects sandwich attacks by analyzing balance deltas before and after swaps. It applies protective measures such as dynamic fees or other restrictions to block malicious behavior.

  • Flexible Integration: The hook integrates seamlessly with Uniswap V4, leveraging its modular hook architecture to provide protection without affecting other core functionalities.

  • Comprehensive Testing: The project includes a suite of tests that simulate both successful and failed sandwich attacks, ensuring that the hook functions as expected under various scenarios.

  • Prevents MEV Bots: By reducing the profitability of sandwich attacks, this solution disincentivizes MEV (Maximal Extractable Value) bots from targeting the pool.

AntiSandwichHook provides an essential layer of defense for decentralized finance applications built on Uniswap V4, reducing the impact of sandwich attacks and protecting both users and liquidity providers from malicious front-running and back-running strategies. By incorporating this hook, DeFi protocols can maintain fair and secure trading environments.