Asymmetry contest - qpzm'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: 27/246

Findings: 2

Award: $249.62

QA:
grade-b

馃専 Selected for report: 0

馃殌 Solo Findings: 0

Findings Information

馃専 Selected for report: lukris02

Also found by: Bauer, HollaDieWaldfee, RedTiger, T1MOH, dec3ntraliz3d, joestakey, koxuan, qpzm, rbserver, reassor

Labels

bug
3 (High Risk)
satisfactory
duplicate-641

Awards

236.4864 USDC - $236.49

External Links

Lines of code

https://github.com/code-423n4/2023-03-asymmetry/blob/44b5cd94ebedc187a08884a7f685e950e987261c/contracts/SafEth/derivatives/SfrxEth.sol#L115-L116

Vulnerability details

Impact

ethPerDerivative must get the price of derivative in terms of ETH. However, it returns frxETHAmount / frxETHPriceInETH .

Proof of Concept

The crv pool address is as below. 2023-03-asymmetry/SfrxEth.sol at 44b5cd94ebedc187a08884a7f685e950e987261c 路 code-423n4/2023-03-asymmetry 路 GitHub

address public constant FRX_ETH_CRV_POOL_ADDRESS =
        0xa1F8A6807c402E4A15ef4EBa36528A3FED24E577;

self.balances array is as below. Vyper_contract | Address 0xa1F8A6807c402E4A15ef4EBa36528A3FED24E577 | Etherscan

self.balances = [0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE, 0x5E8422345238F34275888049021821E8E08CAa1f];

function price_oracle() of the crv pool contract returns the 1st token price denominated in the 0th token.

@external
@view
@nonreentrant('lock')
def price_oracle() -> uint256:
    amp: uint256 = self._A()
    xp: uint256[N_COINS] = self.balances
    D: uint256 = self._get_D(xp, amp)
    return self._ma_price(xp, amp, D)

Tools used

Manual analysis.

function ethPerDerivative(uint256 _amount) public view returns (uint256) {
    uint256 frxAmount = IsFrxEth(SFRX_ETH_ADDRESS).convertToAssets(
        10 ** 18
    );
    // This line should be fixed: / -> *
    return ((10 ** 18 * frxAmount) * IFrxEthEthPool(FRX_ETH_CRV_POOL_ADDRESS).price_oracle());
}

#0 - c4-pre-sort

2023-04-04T17:03:46Z

0xSorryNotSorry marked the issue as duplicate of #698

#1 - c4-judge

2023-04-21T15:59:56Z

Picodes marked the issue as not a duplicate

#2 - c4-judge

2023-04-21T16:00:07Z

Picodes marked the issue as duplicate of #641

#3 - c4-judge

2023-04-21T16:00:13Z

Picodes marked the issue as satisfactory

I submitted the gas issue by mistake, so re-submit in QA report馃檹.

Cache the storage variable in for loop.

Reduce the number of sload.

// cache storage variable in stack.
uint256 _derivativeCount = derivativeCount;
for (uint256 i = 0; i < _derivativeCount; i++) {
// ...
}

adjustWeight: Remove the for loop as below.

https://github.com/code-423n4/2023-03-asymmetry/blob/44b5cd94ebedc187a08884a7f685e950e987261c/contracts/SafEth/SafEth.sol#L169

function adjustWeight(
        uint256 _derivativeIndex,
        uint256 _weight
    ) external onlyOwner {
        uint256 beforeWeight = weights[_derivativeIndex];
        weights[_derivativeIndex] = _weight;
        totalWeight = totalWeight - beforeWeight + _weight;
        emit WeightChange(_derivativeIndex, _weight);
    }

addDerivative: Remove the for loop as below.

https://github.com/code-423n4/2023-03-asymmetry/blob/44b5cd94ebedc187a08884a7f685e950e987261c/contracts/SafEth/SafEth.sol#L190-L193

function addDerivative(
        address _contractAddress,
        uint256 _weight
    ) external onlyOwner {
        derivatives[derivativeCount] = IDerivative(_contractAddress);
        weights[derivativeCount] = _weight;
        derivativeCount++;
        totalWeight += _weight;
        emit DerivativeAdded(_contractAddress, _weight, derivativeCount);
    }

#0 - c4-sponsor

2023-04-10T18:22:37Z

toshiSat marked the issue as sponsor acknowledged

#1 - c4-judge

2023-04-24T17:47:37Z

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