FV-SOL-8-C1 Price Manipulation

TLDR

Exploiting the price calculation mechanism to cause an unusually high slippage rate

Game

They did not thing about guarding against slippage here.

// SPDX-License-Identifier: MIT
// Open me in VSCode and really think before opening the hints!
// Add @audit tags wherever suspicious
// Go to the solidity docs to complete missing knowledge of what's happening here
// Solve by drafting a fix!
pragma solidity ^0.8.0;

interface IDEX {
    function swap(address tokenIn, address tokenOut, uint256 amountIn) external returns (uint256);
    function getPrice(address tokenIn, address tokenOut) external view returns (uint256);
}

contract PriceManipulationGame {
    IDEX public dex;
    address public tokenOut;

    constructor(address _dex, address _tokenOut) {
        dex = IDEX(_dex);
        tokenOut = _tokenOut;
    }

    // Function to execute a swap based on the DEX's current price without additional protection
    function executeSwap(address tokenIn, uint256 amountIn) public {
        uint256 currentPrice = dex.getPrice(tokenIn, tokenOut);
        uint256 amountOut = dex.swap(tokenIn, tokenOut, amountIn);
        
        // No more safeguards after this point
    }
}

Last updated