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

rzizah - Flawed Price Calculation in invest Function Could Lead to Loss of Funds #283

Open
sherlock-admin4 opened this issue Nov 17, 2024 · 0 comments

Comments

@sherlock-admin4
Copy link

sherlock-admin4 commented Nov 17, 2024

rzizah

Medium

Flawed Price Calculation in invest Function Could Lead to Loss of Funds

Summary

preFeeStableAmountEquivalent depends on exchangeRateNumerator which is set off-chain
a user trying to invest on-chain with invest will not recieve the same price as the off-chain investors, if any lags happen between setting the exchangeRAteNumerator and the execution on-chain, leading to potential miscalculations of preFeeStableAmountEquivalent.

Root Cause

The primary issue stems from the off-chain determination of exchangeRateNumerator, which can create a discrepancy between the set value and the actual market rate at the time of transaction execution.

Internal Preconditions

  • A user triggers the invest function, providing an amount to invest.

External Preconditions

  • The off-chain exchangeRateNumerator does not match the real-time market price during the transaction.

Attack Path

  1. A user invests 100 USDC, with the exchangeRateNumerator fixed at 1.2.
  2. When the transaction is executed on-chain, the real market price of USDC has dropped to 0.996 USD (or a significantly lower value, e.g., 0.8 USD).
  3. The user benefits from this mismatch by buying USDC at the lower market rate and investing at the more favorable off-chain exchange rate.

Impact

The inconsistency between the on-chain execution and off-chain rate settings can create opportunities for exploitation, giving some users undue profit while causing financial damage to the protocol.

Mitigation

To mitigate this risk, integrate a trusted price oracle for real-time exchange rate updates. This ensures that the exchangeRateNumerator reflects accurate market conditions, eliminating reliance on static, off-chain values and aligning the investment calculations with up-to-date prices.

@sherlock-admin3 sherlock-admin3 changed the title Swift Hemp Chameleon - Flawed Price Calculation in invest Function Could Lead to Loss of Funds rzizah - Flawed Price Calculation in invest Function Could Lead to Loss of Funds Nov 23, 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