Skip to content
Business logic Audit finding Intermediate

Protocol and referral fee would be permanently stuck in the Curves contract when selling a token

When a token is sold, the protocol fee and any referral fee are deducted from the seller's proceeds but never sent to their intended destinations, so they remain stuck in the contract. An attacker cannot steal these funds, but the protocol and referrers permanently lose the fees they are owed.

anshujalan Follow with lukejohn, zxriptor and 48 others

Originally disclosed on Code4rena

Submitted by anshujalan, also found by lukejohn, zxriptor, ether_sky, ahmedaghadi, 0x0bserver, 0x11singh99, todorc, Aymen0909, c0pp3rscr3w3r, FastChecker, ro1sharkm, tonisives, adeolu, cu5t0mpeo, whoismatthewmc1, Oxsadeeq, Silvermist, Ryonen, ktg, nonseodion, CDSecurity, MrPotatoMagic, santipu_ (1, 2), grearlake, dimulski, BowTiedOriole (1, 2), codegpt, Cosine, _eperezok, khramov, rouhsamad, para8956, Topmark, 0xPhantom, XORs33r, aslanbek, sl1, dd0x7e8, mrudenko, mahdirostami, fishgang, alexfilippov314, zhaojohnson, SovaSlava, hals, UbiquitousComputing, SpicyMeatball, KupiaSec, klau5, cats, cccz, DanielArmstrong, developerjordy, Soliditors, deepplus, Inference, nuthan2x, petro_1912, and haxatron

During the sale of a token Curves._transferFee subtracts all the fees from the selling price and transfers the remaining to the seller here.

        uint256 sellValue = price - protocolFee - subjectFee - referralFee - holderFee;
        (bool success1, ) = firstDestination.call{value: isBuy ? buyValue : sellValue}("");

However, the protocolFee taken away is not transferred to the protocolFeeDestination in the remainder of the _transferFee function here. It stays back in the contract with no other of way of retrieval.

Furthermore, referralFee is taken away without checking if a referral address actually exists. In the event that there is no referral defined, the third transfer is never executed here. This leaves the referral fee in the contract, again no retrieval mechanism.

Recommended Mitigation Steps

The buyValue (here) variable already has the logic for jointly handling the protocol and referral fee. It can be given a more generic name, and be transferred to the protocolDestination for both buying and selling transactions.

    uint256 protocolShare = referralDefined ? protocolFee : protocolFee + referralFee;
    uint256 sellValue = price - protocolFee - subjectFee - referralFee - holderFee;

    (bool success, ) = (feesEconomics.protocolFeeDestination).call{value: protocolShare}("");
    if (!success) revert CannotSendFunds();
    if(!isBuy) {
        (bool success1, ) = (msg.sender).call{value: sellValue}("");
        if(!success1) revert CannotSendFunds();
    }

alcueca (Judge) decreased severity to Medium

andresaiello (Curves) acknowledged


The original report as published on Code4rena, by anshujalan. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 fee-splitting logic deducts the protocol and referral fees from the seller's payout but only forwards the protocol fee during buys, and only forwards the referral fee when a referrer is defined, leaving the deducted amounts in the contract.

Impact

The protocol and referrers permanently lose the fees they are owed, as those funds become stuck in the contract with no way to retrieve them.

What the attacker needed

A token sale occurs; no referrer defined, or any sale

The fix

The protocol and referral fees should be combined into a single amount and sent to the protocol fee destination for both buys and sells, rather than being left in the contract.

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.

This is a smart contract that handles buying and selling of tokens. When someone sells, a small cut is meant to go to the protocol and to a referrer, but the code subtracts those cuts from the seller's payment without actually sending them anywhere. As a result, that money is trapped in the contract forever.

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.

More from Curves

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.