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
Rank: 39/103
Findings: 3
Award: $93.19
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: Jeiwan
Also found by: 0xxm, 9svR6w, BAHOZ, Bobface, CRYP70, Chom, HE1M, Junnon, RaymondFam, UNCHAIN, __141345__, bytehat, carlitox477, caventa, cccz, chaduke, hansfriese, hihen, koxuan, mauricio1802, minhquanym, minhtrng, nicobevi, obront, shung, unforgiven, wait
40.2564 USDC - $40.26
When calculating how many LP tokens to mint to the user for their deposit, the code uses the min of their ratio of the total baseToken and their ratio of the total fractionalToken. However, the code doesn't refund the user for the excess of the token that didn't contribute to the minimum of these ratios (in other words, if these ratios are not the same for both tokens, then the user will be transferring in more tokens than they needed to for one of the two). This flaw allows a frontrunner to manipulate the token reserve amounts to lead to a user receiving much less value than they wanted, even if they receive their full minLpTokenAmount
.
In UniswapV2, the router handles this logic correctly by only transferring the exact amount of tokens that are needed. Sending any more will be a loss for the user, which can be abused as described below.
minLpTokenAmount
to x
.xy = k
invariant since he starts from scratch.minLpTokenAmount
requirement of x
, which forcing her to severely overpay.Manual.
Do something similar to the router in UniswapV2 where the tokens taken from the user are exactly the amount needed to both have the same ratio in the addQuote
calculations.
#0 - c4-judge
2022-12-28T12:35:09Z
berndartmueller marked the issue as duplicate of #376
#1 - c4-judge
2023-01-10T09:01:40Z
berndartmueller marked the issue as satisfactory
🌟 Selected for report: minhquanym
Also found by: 0x52, 0xDecorativePineapple, Apocalypto, BAHOZ, ElKu, Franfran, HE1M, Jeiwan, KingNFT, Koolex, SamGMK, Tointer, Tricko, UNCHAIN, __141345__, ak1, aviggiano, bytehat, carrotsmuggler, cccz, chaduke, cozzetti, dipp, eyexploit, fs0c, haku, hansfriese, hihen, immeas, izhelyazkov, koxuan, ladboy233, lumoswiz, rajatbeladiya, rjs, rvierdiiev, seyni, supernova, unforgiven, yixxas
6.9881 USDC - $6.99
In some protocols, a common vulnerability exists where the first depositor can be frontrun to have their entire initial deposit stolen (e.g. see https://github.com/code-423n4/2022-01-sherlock-findings/issues/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.
x
baseToken and y
fractionalToken, and sets their min minLpTokenAmount
too low.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.minLpTokenAmount
high enough, then this would be an issue.Manual.
Consider minting some of the initial shares minted to the zero address, so that an attacker can't do this attack.
#0 - c4-judge
2022-12-28T14:56:25Z
berndartmueller marked the issue as duplicate of #442
#1 - c4-judge
2023-01-10T09:18:00Z
berndartmueller changed the severity to 3 (High Risk)
#2 - c4-judge
2023-01-10T09:18:10Z
berndartmueller marked the issue as satisfactory
🌟 Selected for report: Zarf
Also found by: 0xDave, Apocalypto, CRYP70, Franfran, Jeiwan, UNCHAIN, adriro, bytehat, chaduke, hansfriese, hihen, kiki_dev, koxuan, minhtrng, rajatbeladiya, unforgiven, wait, yixxas
45.9386 USDC - $45.94
The buyQuote
function calculates the "amount of base tokens required to buy a given amount of fractional tokens". This value is rounded down, which differs from the similar function in UniswapV2. Since the value is rounded down instead of up, the user will pay less than they need to, which can be abused to make a profit.
buyQuote
calculations would have a relatively small amount of outputAmount
token round down to zero, so that the user pays nothing to get a non-zero amount of output, which would be worth a non-trivial amount of money in the case of WBTC.Manual.
Add one to the final answer in buyQuote
, similar to how getAmountIn
works in UniswapV2.
#0 - c4-judge
2022-12-28T12:24:05Z
berndartmueller marked the issue as duplicate of #243
#1 - c4-judge
2023-01-10T09:44:45Z
berndartmueller changed the severity to 2 (Med Risk)
#2 - c4-judge
2023-01-10T09:44:52Z
berndartmueller marked the issue as satisfactory