Asymmetry contest - wen's results

A protocol to help diversify and decentralize liquid staking derivatives.

General Information

Platform: Code4rena

Start Date: 24/03/2023

Pot Size: $49,200 USDC

Total HM: 20

Participants: 246

Period: 6 days

Judge: Picodes

Total Solo HM: 1

Id: 226

League: ETH

Asymmetry Finance

Findings Distribution

Researcher Performance

Rank: 125/246

Findings: 3

Award: $24.06

QA:
grade-b
Gas:
grade-b

🌟 Selected for report: 0

πŸš€ Solo Findings: 0

Lines of code

https://github.com/NaryaAI/2023-03-c4-asymmetry/blob/main/contracts/SafEth/derivatives/Reth.sol#L240

Vulnerability details

Impact

The price of Reth in ETH can be manipulated by flashloan. An attacker can exploit this fact to steal funds from other stakers.

Proof of Concept

https://github.com/NaryaAI/2023-03-c4-asymmetry/blob/main/contracts/SafEth/derivatives/Reth.sol#L240

/** @notice - Price of derivative in liquidity pool */ function poolPrice() private view returns (uint256) { address rocketTokenRETHAddress = RocketStorageInterface( ROCKET_STORAGE_ADDRESS ).getAddress( keccak256( abi.encodePacked("contract.address", "rocketTokenRETH") ) ); IUniswapV3Factory factory = IUniswapV3Factory(UNI_V3_FACTORY); IUniswapV3Pool pool = IUniswapV3Pool( factory.getPool(rocketTokenRETHAddress, W_ETH_ADDRESS, 500) ); (uint160 sqrtPriceX96, , , , , , ) = pool.slot0(); // (1) return (sqrtPriceX96 * (uint(sqrtPriceX96)) * (1e18)) >> (96 * 2); }

At (1), the function fetches the slot0.sqrtPriceX96 of the pool which shows the current price without any historical price information.

This value can be manipulated by an attacker through flashloan. For example, an attacker can (1) Use flashloan to get a large amount of WETH from any pool. (2) Add liquidity to the rETH-WTH pool at a large tick range (e.g., 29000 ~ 29010) (3) Swap all the WETH through the rETH-WTH pool Then the current price of rETH in the pool will be dramatically increased, which will affect the stake() function (if totalSupply is 0, the attacker can gain many more safETH than being supposed to).

Tools Used

Use TWAP instead of the current price (see https://docs.uniswap.org/contracts/v3/reference/core/libraries/Oracle).

#0 - c4-pre-sort

2023-04-04T11:19:28Z

0xSorryNotSorry marked the issue as duplicate of #601

#1 - c4-judge

2023-04-21T16:14:56Z

Picodes marked the issue as satisfactory

#2 - c4-judge

2023-04-21T16:15:31Z

Picodes marked the issue as duplicate of #1125

#3 - c4-judge

2023-04-21T16:15:31Z

Picodes marked the issue as duplicate of #1125

1. Unnecessary loop in addDerivative()

https://github.com/code-423n4/2023-03-asymmetry/blob/main/contracts/SafEth/SafEth.sol#L182

addDerivative() function doesn’t need to have a for loop for updating totalWeight. totalWeight could just be increased by _weight.

2. Unnecessary loop in rebalanceToWeights()

https://github.com/code-423n4/2023-03-asymmetry/blob/main/contracts/SafEth/SafEth.sol#L138

In the rebalanceToWeights() function, the second loop checks ethAmountToRebalance == 0 every time. If ethAmountToRebalance is 0, no need to have the second loop. So this check could be moved to before the second loop.

#0 - c4-pre-sort

2023-03-31T12:12:47Z

0xSorryNotSorry marked the issue as low quality report

#1 - c4-sponsor

2023-04-10T18:49:12Z

toshiSat marked the issue as sponsor acknowledged

#2 - c4-judge

2023-04-24T17:46:10Z

Picodes marked the issue as grade-b

#0 - c4-sponsor

2023-04-10T19:02:04Z

toshiSat marked the issue as sponsor acknowledged

#1 - c4-judge

2023-04-23T18:56:07Z

Picodes marked the issue as grade-b

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