Popcorn contest - MyFDsYours's results

A multi-chain regenerative yield-optimizing protocol.

General Information

Platform: Code4rena

Start Date: 31/01/2023

Pot Size: $90,500 USDC

Total HM: 47

Participants: 169

Period: 7 days

Judge: LSDan

Total Solo HM: 9

Id: 211

League: ETH

Popcorn

Findings Distribution

Researcher Performance

Rank: 162/169

Findings: 1

Award: $14.28

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

14.2839 USDC - $14.28

Labels

bug
3 (High Risk)
satisfactory
sponsor confirmed
duplicate-243

External Links

Lines of code

https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L147 https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L293-L300

Vulnerability details

Impact

This is a well-known attack vector for contracts that utilize pricePerShare for accounting : users can loss their deposits.

Proof of Concept

https://github.com/code-423n4/2022-04-pooltogether-findings/issues/44

Vault.sol#L147

        shares = convertToShares(assets) - feeShares;

Vault.sol#L293-L300

    /**
     * @notice Amount of shares the vault would exchange for given amount of assets, in an ideal scenario.
     * @param assets Exact amount of assets
     * @return Exact amount of shares
     */
    function convertToShares(uint256 assets) public view returns (uint256) {
        uint256 supply = totalSupply(); // Saves an extra SLOAD if totalSupply is non-zero.

        return
            supply == 0
                ? assets
                : assets.mulDiv(supply, totalAssets(), Math.Rounding.Down);
    }

A malicious early user can call deposit() with 1 wei as the first depositor of the Vault.sol contract and get 1 wei of shares token.

Then the attacker can send for example (100e18 - 1) directly to the contract without using the deposit function, and inflate the price per share from 1 to an extreme value of 100e18.

if a future user will deposit (100e18-1) token or less he will not receive any shares due to rounding calculation. He will immediately lose his deposit value.

Tools Used

Reading the code

Consider requiring a minimal amount of share tokens to be minted for the first minter, and send a fixed value of the initial mints as a reserve so that the pricePerShare can be more resistant to manipulation.

#0 - c4-judge

2023-02-16T03:30:36Z

dmvt marked the issue as duplicate of #15

#1 - c4-sponsor

2023-02-18T11:54:43Z

RedVeil marked the issue as sponsor confirmed

#2 - c4-judge

2023-02-23T00:39:59Z

dmvt marked the issue as partial-50

#3 - c4-judge

2023-03-01T00:33:02Z

dmvt marked the issue as full credit

#4 - c4-judge

2023-03-01T00:44:05Z

dmvt marked the issue as satisfactory

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