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

Initial user setting minLpTokenAmount too low will lose funds #317

Closed
code423n4 opened this issue Dec 19, 2022 · 3 comments
Closed

Initial user setting minLpTokenAmount too low will lose funds #317

code423n4 opened this issue Dec 19, 2022 · 3 comments
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-442 satisfactory satisfies C4 submission criteria; eligible for awards upgraded by judge Original issue severity upgraded from QA/Gas by judge

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-12-caviar/blob/0212f9dc3b6a418803dbfacda0e340e059b8aae2/src/Pair.sol#L426

Vulnerability details

Impact

In some protocols, a common vulnerability exists where the first depositor can be frontrun to have their entire initial deposit stolen (e.g. see code-423n4/2022-01-sherlock-findings#39). If the first user does not properly set the minLpTokenAmount in add function, they will be susceptible to this attack. For extra safety, you could consider minting some of the initial Math.sqrt(x * y) tokens from the first deposit to the zero address.

Proof of Concept

  • The first depositor deposits x baseToken and y fractionalToken, and sets their min minLpTokenAmount too low.
  • An attacker sees this tx in the mempool and deposits 1 wei of x and 1 wei of y. This makes the LP total supply 1. The attack also manually transfers x+1 and y+1 baseToken and fractionalToken directly to the pool contract.
  • The first depositor tx will happen, which will round the number of LP tokens they receive down to zero (or perhaps some other low number depending on the attacker's manual transfer). If they didn't set minLpTokenAmount high enough, then this would be an issue.

Tools Used

Manual.

Recommended Mitigation Steps

Consider minting some of the initial shares minted to the zero address, so that an attacker can't do this attack.

@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Dec 19, 2022
code423n4 added a commit that referenced this issue Dec 19, 2022
@c4-judge
Copy link
Contributor

berndartmueller marked the issue as duplicate of #442

C4-Staff added a commit that referenced this issue Jan 6, 2023
@c4-judge c4-judge added 3 (High Risk) Assets can be stolen/lost/compromised directly upgraded by judge Original issue severity upgraded from QA/Gas by judge and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Jan 10, 2023
@c4-judge
Copy link
Contributor

berndartmueller changed the severity to 3 (High Risk)

@c4-judge
Copy link
Contributor

berndartmueller marked the issue as satisfactory

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate-442 satisfactory satisfies C4 submission criteria; eligible for awards upgraded by judge Original issue severity upgraded from QA/Gas by judge
Projects
None yet
Development

No branches or pull requests

2 participants