Caviar contest - 0xDave's results

A fully on-chain NFT AMM that allows you to trade every NFT in a collection.

General Information

Platform: Code4rena

Start Date: 12/12/2022

Pot Size: $36,500 USDC

Total HM: 8

Participants: 103

Period: 7 days

Judge: berndartmueller

Id: 193

League: ETH

Caviar

Findings Distribution

Researcher Performance

Rank: 64/103

Findings: 1

Award: $45.94

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

Awards

45.9386 USDC - $45.94

Labels

bug
2 (Med Risk)
downgraded by judge
satisfactory
duplicate-243

External Links

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.

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; }

#0 - Shungy

2022-12-21T07:30:59Z

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.

#1 - c4-judge

2022-12-23T13:51:11Z

berndartmueller marked the issue as duplicate of #243

#2 - c4-judge

2023-01-10T09:43:50Z

berndartmueller changed the severity to 2 (Med Risk)

#3 - c4-judge

2023-01-10T09:44:08Z

berndartmueller marked the issue as satisfactory

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax © 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter