Closed code423n4 closed 1 year ago
https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L298-L300 https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L134-L158
The first deposit with a totalSupply of zero shares will mint shares equal to the deposited amount.
totalSupply
File: src/vault/Vault.sol 298: supply == 0 299: ? assets 300: : assets.mulDiv(supply, totalAssets(), Math.Rounding.Down);
Link to Code
File: src/vault/Vault.sol function deposit(uint256 assets, address receiver) public nonReentrant whenNotPaused syncFeeCheckpoint returns (uint256 shares) { if (receiver == address(0)) revert InvalidReceiver(); uint256 feeShares = convertToShares( assets.mulDiv(uint256(fees.deposit), 1e18, Math.Rounding.Down) ); shares = convertToShares(assets) - feeShares; if (feeShares > 0) _mint(feeRecipient, feeShares); _mint(receiver, shares); asset.safeTransferFrom(msg.sender, address(this), assets); adapter.deposit(assets, address(this)); emit Deposit(msg.sender, receiver, assets, shares); }
For calculation Simplicity let's take fees to be zero as of now.
Problems with the code:
It can lead to some part of Fund getting stolen from First Depositor.
Consider the following situation:
Have a look at this table to understand the complete PoC:
Manual Review
dmvt marked the issue as duplicate of #15
RedVeil marked the issue as sponsor confirmed
dmvt marked the issue as satisfactory
Lines of code
https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L298-L300 https://github.com/code-423n4/2023-01-popcorn/blob/main/src/vault/Vault.sol#L134-L158
Vulnerability details
Description
The first deposit with a
totalSupply
of zero shares will mint shares equal to the deposited amount.Link to Code
Link to Code
For calculation Simplicity let's take fees to be zero as of now.
Problems with the code:
Impact
It can lead to some part of Fund getting stolen from First Depositor.
Proof of Concept
Consider the following situation:
Have a look at this table to understand the complete PoC:
Tools Used
Manual Review
Recommended Mitigation Steps