-
Notifications
You must be signed in to change notification settings - Fork 1
tives - Early Vault depositor can manipulate exchange rates to steal funds from later depositors #154
tives - Early Vault depositor can manipulate exchange rates to steal funds from later depositors #154
Comments
1 comment(s) were left on this issue during the judging contest. 141345 commented:
|
Escalate This issue is marked as won't fixed in the v1 version of the audit here: According to sherlocks rules:
According to sponsor comment:
Can you confirm @arjun-io ? |
You've created a valid escalation! To remove the escalation from consideration: Delete your comment. You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final. |
Escalate Inflation of shares is not possible. During settlement, pending deposits will be converted to shares in the following way: As we can see, shares is calculated as depositedAssets*checkpoint.shares/checkpoint.assets. checkpoint.assets is updated here, which calls this. First depositor bug would have been possible if shares was calculated as: depositedAssets*checkpoint.shares/assets.balanceOf(address(this)). The _socialize function basically does this: So if an "attacker" transfers |
You've created a valid escalation! To remove the escalation from consideration: Delete your comment. You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final. |
Result: |
Escalations have been resolved successfully! Escalation status:
|
Note for the fix review: the above fix had a slight bug which is fixed here: equilibria-xyz/perennial-v2#101 (review) |
tives
medium
Early Vault depositor can manipulate exchange rates to steal funds from later depositors
Summary
An early user can manipulate the price per share and profit from late users' deposits because of the precision loss caused by the large value of price per share.****
Vulnerability Detail
Part 1: deposit
A malicious early user can deposit
1 wei
of token as the first depositor to the Vault, and get1 wei
of shares.User shares are set in processLocal/processGlobal. These are called in _settle, which is also called in
Vault.update(... depositAssets ...)
_withSpread
sets the shares amount to 1 wei (return totalAmount.isZero() ? amount : …
)Now, the attacker has 1 share for 1 wei of tokens.
Part 2: share value inflation
Then the attacker can send
10000e18 - 1
ofasset
token to the Vault and inflate the price per share from 1.0000 to an extreme value of 1.0000e22 ( from(1 + 10000e18 - 1) / 1
) .Part 3: redeeming for inflated share price
The
_socialize
function returns the claim amount._socialize
in turn calls_collateral
, which usesasset.balanceOf()
to return the collateral amountThis means that the
claimAmount
is calculated according to asset.balanceOf(). This means that adversary has retained her initial shares but inflated the share price via sending in tokens manually.She can now receive more tokens than her shares are worth. These tokens come from the later depositors.
Impact
Initial depositor steals from late depositors due to inflated share price.
Code Snippet
https://github.com/sherlock-audit/2023-07-perennial/blob/main/perennial-v2/packages/perennial-vault/contracts/Vault.sol/#L486
Tool used
Manual Review
Recommendation
Require a bigger initial deposit or premint some shares and burn them before the first deposit. This is a well known attack vector for ERC4626 vaults. You can read more about it here
The text was updated successfully, but these errors were encountered: