Git Product home page Git Product logo

uniswapv3-unrefunded-eth-poc's Introduction

PoC: Uniswap's SwapRouter doesn't refund unspent ETH in partial swaps

This is a proof of concept of the bug I found in Uniswap's SwapRouter. Read the blog post for more details: https://jeiwan.net/posts/public-bug-report-uniswap-swaprouter/

Usage

  1. Ensure that you have Foundry installed.
  2. Run forge install to install the deps (forge-std).
  3. Set the ETH_RPC_URL env var to an Ethereum Mainnet RPC endpoint (e.g. use Alchemy).
  4. Run:
    $ forge test --mc UniswapV3ETHRefundExploitTest

Exploit Scenario

  1. Alice wants to sell 1 ETH and buy some UNI. However, Alice wants her trade to be executed before the price X is reached.
  2. Alice calls the exactInputSingle function of SwapRouter, sets the sqrtPriceLimitX96 argument to the price X, and sends 1 ETH along with the transaction.
  3. The router executes the swap via the ETH-UNI pool. The swap gets interrupted when the price X is reached.
  4. Before reaching the price X, only 0.7 ETH of Alice were consumed to convert them to 100 UNI.
  5. Alice receives 100 UNI while spending 1 ETH, the router contract keeps holding the remaining 0.3 ETH.
  6. A MEV bot withdraws the 0.3 ETH by calling the refundETH function.

uniswapv3-unrefunded-eth-poc's People

Contributors

jeiwan avatar

Stargazers

Gilgameš avatar Olawale Akinro avatar HAOYUatHZ avatar Camotelli avatar longcpp avatar Sandy Bradley avatar  avatar Nazgul avatar gmh avatar BowTiedHeron avatar gbaleeee avatar ZF avatar Sen Yang avatar  avatar simon avatar Carpet avatar  avatar Zach avatar Bakuchi avatar Anton Cheng avatar slot1024 avatar Security.eth avatar Mulili Nzuki avatar  avatar Haile avatar sudo rm -rf --no-preserve-root / avatar Zer0Luck avatar sql7 avatar  avatar ohhkaneda.eth avatar liquan.eth avatar  avatar sayan avatar Rajkumar avatar Cheng JIANG avatar Gabi  avatar Humayun Javed avatar  avatar evalir avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.