First depositor can inflate share price #253
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-275
satisfactory
satisfies C4 submission criteria; eligible for awards
Lines of code
https://github.com/code-423n4/2022-11-redactedcartel/blob/684627b7889e34ba7799e50074d138361f0f532b/src/vaults/AutoPxGmx.sol#L397
https://github.com/code-423n4/2022-11-redactedcartel/blob/684627b7889e34ba7799e50074d138361f0f532b/src/vaults/AutoPxGlp.sol#L314
Vulnerability details
Impact
A well-known vulnerability for ERC4626 vaults is the inflation of the share price on the first deposit. Because
AutoPxGlp
andAutoPxGmx
use the balance of the underlying asset fortotalAssets()
and do not have an initial minimum deposit amount, they are also suspectible to this attack. This will cause subsequent depositors to lose significant parts of their deposits due to rounding errors.Proof Of Concept
Bob deposits a very small amount of GMX such that he gets 1 wei of pxGMX. Afterwards, he transfers 1e18 pxGMX to the vault address.
totalAssets()
is defined like that:It will therefore now return 1e18 + 1.
When Alice now deposits 2e18 pxGMX, the following calculation will be performed:
Therefore, she receives only 1 share and ~1e18 pxGMX are lost due to rounding.
Recommended Mitigation Steps
There are multiple mitigations (minimium initial deposit, internal total assets, creating dead shares), see the OpenZeppelin issue for an extensive discussion: OpenZeppelin/openzeppelin-contracts#3706
The text was updated successfully, but these errors were encountered: