Curves::_buyCurvesToken() , Excess of Eth received is not refunded back to the user.
The buyCurvesToken function only checks that the sent ETH is at least the price plus fees, but never refunds any excess. An attacker could deliberately overpay and the extra ETH would be trapped in the contract, causing a loss to the user.
ravikiranweb3 Follow with btk, pkqs90 and 48 others
Originally disclosed on Code4rena
Submitted by ravikiranweb3, also found by btk, ether_sky (1, 2), 0xprinc (1, 2), pkqs90, cats, cartlex_, nuthan2x, pep7siup (1, 2), Prathik3, MrPotatoMagic (1, 2), Kose, peanuts, 0xmystery (1, 2), Ephraim, m4ttm, spark, 0xStriker, emrekocak, SanketKogekar, Bjorn_bug, LeoGold, 0xlamide (1, 2), c3phas, imare, PetarTolev, anshujalan, M3azad, spaghetticode_sentinel, Nikki, Timeless, Varun_05, negin, ro1sharkm, Night, tonisives, hihen, Zach_166, kodyvim, cu5t0mpeo, FastChecker, yixxas, Ryonen, nonseodion, ubermensch, Tychai0s, Silvermist, codegpt, grearlake, rouhsamad (1, 2), Cosine, HChang26, _eperezok, 0xblackskull, para8956, 13u9, Kong, dd0x7e8, iamandreiski, ubl4nk (1, 2), pipidu83, mahdirostami, merlinboii, dopeflamingo, oreztker, osmanozdemir1, sl1, DarkTower, Kaysoft, UbiquitousComputing, zhaojohnson, 0xSwahili, eeshenggoh, dimulski, SovaSlava, BowTiedOriole, developerjordy, zaevlad, Lef, KmanOfficial, latt1ce, KupiaSec, jasonxiale, hals (1, 2), Mwendwa, aslanbek, ke1caM, ZanyBonzy, EV_om, cccz, bronze_pickaxe, Oxsadeeq, ktg, twcctop, deepplus, Inference, Soliditors, lil_eth (1, 2), Mylifechangefast_eth, AlexCzm, haxatron, and alexbabits
In the buyCurvesToken(), the logic check for the msg.value to be greater than price + fees. This is fine, since if the price moves after the estimates was provided to the user, the above validation checks if the funds received are sufficient to proceed with the transaction.
But, at the same time, it is equally important to refund any excess eth received which is not being done.
Proof of Concept
Refer to the below code where the validation ensures that msg.value is not less than price + total fee.
if (msg.value < price + totalFee) revert InsufficientPayment();
But, incase any additional funds were received, the same should be returned back to the caller.
Recommended Mitigation Steps
uint256 excess = msg.value - (price + totalFee); if excess > 0, refund the amount back to the caller.
andresaiello (Curves) confirmed, but disagreed with severity and commented:
Valid but not high severity. Friend tech does not refund in fact.
alcueca (Judge) decreased severity to Medium
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The contract checks that the payment is sufficient but does not calculate or refund any surplus.
Impact
Any user who sends more ETH than required loses the excess, which remains stuck in the contract; the project acknowledged this but noted a similar platform does not refund either.
What the attacker needed
User sends more ETH than needed
The fix
The contract should calculate the excess as msg.value minus (price + totalFee) and refund it to the caller when greater than zero.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When you buy something with a cryptocurrency like ETH, you might send more than the exact price to make sure the transaction goes through. A safe contract should give you back the extra. Here, the contract keeps the extra ETH instead of returning it, so you lose money.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.