First depositor can manipulate share price of MainVault
Summary
The first depositors can mint 1 share and send in a large amount of Token into MainVault. The price of 1 share will be inflated. The next depositor who deposits will lose out due to a rounding error.
Vulnerability Detail
The adversary will call deposit with the amount of 1 to mint 1 share. He then transfers a large amount of Tokens over 1000 to the address of Mainvault. The price of 1 share is now 1001. The next depositor deposits 2000 and receives 1 share due to a rounding error. The pool has 3001 assets with 2 shares. The adversary can withdraw his 1 share and receive 1500 assets, gaining 500 assets.
Recommend requiring minimum amount of shares for first depositor and burning some shares of first depositor so that price of share will be more resistant.
SPYBOY
high
First depositor can manipulate share price of MainVault
Summary
The first depositors can mint 1 share and send in a large amount of Token into MainVault. The price of 1 share will be inflated. The next depositor who deposits will lose out due to a rounding error.
Vulnerability Detail
The adversary will call
deposit
with the amount of 1 to mint 1 share. He then transfers a large amount of Tokens over 1000 to the address of Mainvault. The price of 1 share is now 1001. The next depositor deposits 2000 and receives 1 share due to a rounding error. The pool has 3001 assets with 2 shares. The adversary can withdraw his 1 share and receive 1500 assets, gaining 500 assets.Impact
The first depositors can manipulate share prices to gain from future depositors.
Code Snippet
deposit() : https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/MainVault.sol#L106-L124 withdraw() : https://github.com/sherlock-audit/2023-01-derby/blob/main/derby-yield-optimiser/contracts/MainVault.sol#L131-L144
Tool used
Manual Review
Recommendation
Recommend requiring minimum amount of shares for first depositor and burning some shares of first depositor so that price of share will be more resistant.
Duplicate of #258