Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Z0NaN - Vault inflation attack in UsualX allows malicious user to steal money and innocent user to lose money #281

Open
sherlock-admin2 opened this issue Nov 13, 2024 · 0 comments

Comments

@sherlock-admin2
Copy link
Contributor

sherlock-admin2 commented Nov 13, 2024

Z0NaN

High

Vault inflation attack in UsualX allows malicious user to steal money and innocent user to lose money

Summary

The missing check: require(convertToShares(assets) != 0); in usualX::depositWithPermit(...) allows the attacker to perform and fully beneficiate from his attack at low cost as he takes advantage of a rounding issue.

Root Cause

There's a rounding issue here:
in convertToShares(...) called in the subcalls of deposit()
https://github.com/sherlock-audit/2024-10-usual-labs-v1/blob/main/pegasus/packages/solidity/src/vaults/UsualX.sol#L308

Internal pre-conditions

  1. totalAsset()==0, totalSupply()==0

External pre-conditions

No response

Attack Path

  1. A hacker back-runs the transaction of an ERC4626 pool creation.
  2. The hacker mints for themself one share: deposit(1). Thus, totalAsset()==1, totalSupply()==1.
  3. The hacker front-runs the deposit of the victim who wants to deposit 20,000 usual (20,000).
  4. The hacker inflates the denominator right in front of the victim: asset.transfer(20_000dec). Now totalAsset()==20_000dec + 1, totalSupply()==1.
  5. Next, the victim's tx takes place. The victim gets 1 * 20_000dec / (20_000dec + 1) == 0 shares. The victim gets zero shares.
  6. The hacker burns their share and gets all the money.

Impact

No response

PoC

No response

Mitigation

Add the following check: require(convertToShares(assets) != 0);or implement the 'dead shares' technique used by UniswapV2

@sherlock-admin4 sherlock-admin4 changed the title Digital Rouge Iguana - Vault inflation attack in UsualX allows malicious user to steal money and innocent user to lose money Z0NaN - Vault inflation attack in UsualX allows malicious user to steal money and innocent user to lose money Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant