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

The pair's token can be stolen without purchasing funds. #424

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

The pair's token can be stolen without purchasing funds. #424

code423n4 opened this issue Dec 19, 2022 · 4 comments
Labels
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 downgraded by judge Judge downgraded the risk level of this issue duplicate-243 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

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

Vulnerability details

Impact

Due to the absence of checking the inputAmount value, the pair's funds can be stolen.

Proof of Concept

require(inputAmount <= maxInputAmount, "Slippage: amount in");

There is no guarantee that the inputAmount is greater than zero. In the following situations, a problem occurs when the inputAmount becomes 0.

  1. The value of baseTokenReserves() is much smaller than the value of fractionalTokenReserves()
  2. If baseToken is not ETH

As many tokens as outputAmount exit the pair, but the token does not enter the pair because inputAmount is 0.

Recommended Mitigation Steps

In the buyQuote function, it is recommended to add code that guarantees that the inputAmount is greater than zero.

    function buyQuote(uint256 outputAmount) public view returns (uint256 inputAmount) {
        uint256 inputAmount = (outputAmount * 1000 * baseTokenReserves()) / ((fractionalTokenReserves() - outputAmount) * 997);
      	require(inputAmount > 0, "InputAmount is zero");
        return inputAmount;
    }
@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Dec 19, 2022
code423n4 added a commit that referenced this issue Dec 19, 2022
@Shungy
Copy link
Member

Shungy commented Dec 21, 2022

Seems technically valid.

Though I think it is overinflated as it would mean stealing at most 1 wei of fractionalTokenReserves.
Also I think the real issue is the rounding as stated in #436 . With rounding up minInputAmount >= 1 is guaranteed.

So I believe it is potential dup of #436, and not a unique issue.

@c4-judge
Copy link
Contributor

berndartmueller marked the issue as duplicate of #243

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

berndartmueller changed the severity to 2 (Med Risk)

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Jan 10, 2023
@c4-judge
Copy link
Contributor

berndartmueller marked the issue as satisfactory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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 downgraded by judge Judge downgraded the risk level of this issue duplicate-243 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

3 participants