Revert Lend - boredpukar's results

A lending protocol specifically designed for liquidity providers on Uniswap v3.

General Information

Platform: Code4rena

Start Date: 04/03/2024

Pot Size: $88,500 USDC

Total HM: 31

Participants: 105

Period: 11 days

Judge: ronnyx2017

Total Solo HM: 7

Id: 342

League: ETH

Revert

Findings Distribution

Researcher Performance

Rank: 100/105

Findings: 1

Award: $6.61

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

6.6125 USDC - $6.61

Labels

bug
2 (Med Risk)
downgraded by judge
insufficient quality report
partial-50
:robot:_73_group
duplicate-175

External Links

Lines of code

https://github.com/code-423n4/2024-03-revert-lend/blob/main/src/automators/Automator.sol#L148

Vulnerability details

Impact

The usage of slot0 is extremely easy to manipulate.

Proof of Concept

The Automator contract is using slot0 within the _validateSwap function to calculate several variables in their codebase.

    function _validateSwap(
        bool swap0For1,
        uint256 amountIn,
        IUniswapV3Pool pool,
        uint32 twapPeriod,
        uint16 maxTickDifference,
        uint64 maxPriceDifferenceX64
    ) internal view returns (uint256 amountOutMin, int24 currentTick, uint160 sqrtPriceX96, uint256 priceX96) {
        // get current price and tick
        (sqrtPriceX96, currentTick,,,,,) = pool.slot0();

        // check if current tick not too far from TWAP
        if (!_hasMaxTWAPTickDifference(pool, twapPeriod, currentTick, maxTickDifference)) {
            revert TWAPCheckFailed();
        }

        // calculate min output price price and percentage
        priceX96 = FullMath.mulDiv(sqrtPriceX96, sqrtPriceX96, Q96);
        if (swap0For1) {
            amountOutMin = FullMath.mulDiv(amountIn * (Q64 - maxPriceDifferenceX64), priceX96, Q96 * Q64);
        } else {
            amountOutMin = FullMath.mulDiv(amountIn * (Q64 - maxPriceDifferenceX64), Q96, priceX96 * Q64);
        }
    }

This Uniswap.slot0, which is the most recent data point, can be manipulated easily via MEV bots and Flashloans with sandwich attacks; which can cause the loss of funds when interacting with the Uniswap::swap function.

An attacker can simply manipulate the sqrtPriceX96 and if the Uniswap::swap function is called with the sqrtPriceX96, the token will be bought at a higher price and the attacker would run the transaction to sell; thereby earning gains but causing a loss of funds to whoever called those functions.

Tools Used

Manual Review

Use the TWAP function to get the value of sqrtPriceX96 instead of using the slot0 values.

Assessed type

Uniswap

#0 - c4-pre-sort

2024-03-22T08:03:38Z

0xEVom marked the issue as duplicate of #191

#1 - c4-pre-sort

2024-03-22T08:03:42Z

0xEVom marked the issue as insufficient quality report

#2 - c4-judge

2024-03-31T14:28:12Z

jhsagd76 marked the issue as duplicate of #175

#3 - c4-judge

2024-03-31T14:44:51Z

jhsagd76 marked the issue as partial-50

#4 - c4-judge

2024-04-01T15:43:42Z

jhsagd76 changed the severity to 2 (Med Risk)

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter