Platform: Code4rena
Start Date: 13/11/2023
Pot Size: $24,500 USDC
Total HM: 3
Participants: 120
Period: 4 days
Judge: 0xTheC0der
Id: 306
League: ETH
Rank: 104/120
Findings: 1
Award: $1.37
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: rvierdiiev
Also found by: 0x175, 0x3b, 0xMango, 0xarno, 0xpiken, Bauchibred, DarkTower, ElCid, Giorgio, HChang26, Kose, KupiaSec, Madalad, PENGUN, Pheonix, RaoulSchaffranek, SpicyMeatball, T1MOH, Tricko, Udsen, Yanchuan, aslanbek, ast3ros, bart1e, bin2chen, chaduke, d3e4, deepkin, developerjordy, glcanvas, inzinko, jasonxiale, jnforja, mahyar, max10afternoon, mojito_auditor, neocrao, nmirchev8, openwide, osmanozdemir1, peanuts, pep7siup, peritoflores, pontifex, rice_cooker, rouhsamad, t0x1c, tnquanghuy0512, turvy_fuzz, twcctop, ustas, vangrim, zhaojie, zhaojohnson
1.3743 USDC - $1.37
https://github.com/code-423n4/2023-11-canto/blob/335930cd53cf9a137504a57f1215be52c6d67cb3/1155tech-contracts/src/bonding_curve/LinearBondingCurve.sol#L14-L25 https://github.com/code-423n4/2023-11-canto/blob/335930cd53cf9a137504a57f1215be52c6d67cb3/1155tech-contracts/src/Market.sol#L150-L189
In Market users can buy/sell tokens and as more tokens get created the price will rise due to the calculation of the price in LinearBondingCurve::getPriceAndFee()
, however the problem is there is no timelock when user buys a token and s/he is able to sell the token immediately, this provide the opportunity for attacker frontrun a buy token from another user and after user's transaction got placed the price will go up and attacker can sell the bought tokens immediately with profit.
Imagine a user who wants to buy 10 tokens and the attacker notice this in the mempool and frontrun the tx by buying 10 tokens after user's transaction got placed attacker will sell his 10 tokens with profit
File: 2023-11-canto\1155tech-contracts\src\bonding_curve\LinearBondingCurve.sol 14: function getPriceAndFee(uint256 shareCount, uint256 amount) 15: external 16: view 17: override 18: returns (uint256 price, uint256 fee) 19: { 20: for (uint256 i = shareCount; i < shareCount + amount; i++) { 21: uint256 tokenPrice = priceIncrease * i; 22: price += tokenPrice; 23: fee += (getFee(i) * tokenPrice) / 1e18; 24: } 25: }
As you see the price on line 21 is multiplied by the tokenCount so since attacker bought tokens before the user he will be able to sell it with profit.
Manual review
consider adding timelock when user buys tokens this way tokens can't be sold immediately
Other
#0 - c4-pre-sort
2023-11-18T16:50:49Z
minhquanym marked the issue as duplicate of #12
#1 - c4-judge
2023-11-28T23:14:14Z
MarioPoneder changed the severity to 2 (Med Risk)
#2 - c4-judge
2023-11-28T23:38:25Z
MarioPoneder marked the issue as satisfactory