Skip to content
Business logic Audit finding Intermediate

Attacker can DOS user from selling shares of a credId

The contract lets anyone buy shares on behalf of another curator, and each such purchase resets that curator's ten-minute share lock timer. An attacker could repeatedly buy a single share for a victim to keep delaying their sale, and the price could move against the victim during the delay.

MrPotatoMagic Follow with 0xCiphky, 0xNirix and 12 others

Originally disclosed on Code4rena

Submitted by MrPotatoMagic, also found by 0xCiphky, 0xNirix, Tigerfrake, typicalHuman, 0xc0ffEE, DigiSafe, eLSeR17, onthehunt11, rscodes, Jorgect, 20centclub, dimah7, Gosho, and Beosin

The Cred.sol contract provides a buyShareCredFor() function which anyone can use to buy shares for another curator. We also know that once a share is bought, the curator needs to serve a 10 minute share lock period before being able to sell those tokens.

Impact

The issue is that an attacker can purchase 1 share every 10 minutes on behalf of the curator to DOS them from selling. As we can see on the bonding share price curve docs here, the price to buy 1 share starts from 2.46 USD and barely increases. Each share bought = 10 minutes of delay for the victim user.

Delaying the user from selling is not the only problem though. During these delays, the price of the share can drop, which could ruin a user’s trade strategy causing to incur more loss.

Proof of Concept

Refer to the price curve here for cost of shares.

  1. Let’s assume 30 shares have been bought already by users A, B and C (we ignore the 1 share given to the creator). The shares were bought in order, i.e., 10 first by A, then B and then C. This means A bought 10 shares for 25 USD, B for 30 USD and C for 35 USD. The price of 1 share currently is 4 USD as per the price curve after all buys.
  2. Let’s say A and C hold the shares for a bit longer while B is looking to sell them as soon as possible to profit from C’s buy that increased the price.
  3. Now let’s say the attacker calls function buyShareCredFor() with user B as the curator. This would be done close to the end of the 10 minute share lock period of user B.
File: Cred.sol
186:     function buyShareCredFor(uint256 credId_, uint256 amount_, address curator_, uint256 maxPrice_) public payable {
187:         if (curator_ == address(0)) revert InvalidAddressZero();
188:         _handleTrade(credId_, amount_, true, curator_, maxPrice_);
189:     }
  1. When the attacker’s call goes through to the internal function _handleTrade(), the lastTradeTimestamp is updated for the user B. This means B has to serve the share lock period all over again for 10 minutes. Note that this would provide user B with 1 more share (which costs the attacker 4 USD).
File: Cred.sol
642:         if (isBuy) {
643:             cred.currentSupply += amount_;
644:             ...
649:             lastTradeTimestamp[credId_][curator_] = block.timestamp;
  1. User B tries to sell but isn’t able to due to the share lock period check in _handleTrade().
File: Cred.sol
629:             if (block.timestamp <= lastTradeTimestamp[credId_][curator_] + SHARE_LOCK_PERIOD) {
630:                 revert ShareLockPeriodNotPassed(
631:                     block.timestamp, lastTradeTimestamp[credId_][curator_] + SHARE_LOCK_PERIOD
632:                 );
633:             }
  1. Users C and A sell their shares of the credId during this period for 36 USD and 31 USD respectively. This brings the price per share down to 2.57 USD, which for user B would mean 25.7 USD. This means user B lost 4.3 USD approximately from the initial buy.
  2. Note that user C could also have been the attacker where the net loss of the attacker; i.e., C would result to 4 USD - (final sell amount - initial purchase amount) = 4 USD - (36 USD - 35 USD) = 3 USD.
  3. Overall in addition to grief DOSing a user from selling, other users are able to alter another user’s strategy by preventing them from selling.

Recommended Mitigation Steps

Consider removing the buyShareCredFor() function since it does more harm than good.

Assessed type

Timing

ZaK3939 (Phi) confirmed and commented:

Thank you for this submit. I like this PR.

cats (warden) commented:

This scenario works only in a sandbox environment where users A and C are aware of the trading intentions of user B. The gradual increase/decrease of signal prices is a protocol design as per the curation price spreadsheet, meaning users engaging in signal trading are aware that their signals can appreciate/depreciate with each transaction. User B’s signals depreciating in price due to A and C’s sells is an intended design, regardless if a timelock is imposed or not. One could argue that a whale signal holder could dump their signals when other curators buy from the same cred - this is still not a vulnerability, it’s rules of the game and it also relies on the prerequisite that users willingly bought signals in a cred where there is a whale holder.

The issue is entirely speculative, requires information that is inaccessible in a real world scenario and requires the attacker to just gift free tokens to his “victim”. Also, what if user B front-runs their attack with one of his own to purchase a ton of signals to make the attacker’s signal purchase costly?

This issue is QA at best.

MrPotatoMagic (warden) commented:

@cats, I believe you’re misunderstanding the issue at hand would appreciate if you understand the root cause of the issue first.

regardless if a timelock is imposed or not.

The issue isn’t talking about the intended design of a timelock being imposed. The whole point of the issue is that other users should not be able to extend someone else’s existing share lock period. Surely users have to do their due diligence while taking a trade knowing that there would be the original timelock of 10 minutes imposed by their “own trade”. But they’re not aware beforehand that after those 10 minutes, they won’t be able to sell those shares and perform their expected trade. Fundamentally, other users should not be allowed to manipulate another user’s trade.

The issue isn’t that complicated:

  1. User buys shares.
  2. Waits for 10 minutes.
  3. User tries to sell shares for profit but fails.
  4. Market dumps on the user.
  5. The user not only loses their profit but would be in net loss.

this is still not a vulnerability, it’s rules of the game and it also relies on the prerequisite that users willingly bought signals in a cred where there is a whale holder.

Users are aware of this risk like in any other market. It’s like you’re saying I won’t buy BTC cause Blackrock can dump on me. A user is looking to profit from future user buys. If someone can prevent a user from selling at any time by extending their original share lock period, that’s a bug.

kuprum (warden) commented:

@0xDjango, I would kindly ask you to take a second look at this finding.

I was considering this when I was performing the audit, and decided against submitting this, because it’s not a vulnerability. Let’s consider the implications of this “attack”, specifically of what profit someone would extract from the attack?

  • In the example, users C and A seem to be profiting by preventing B from selling their shares. But for that:

    • They would need to know that B wants to sell their shares, which is already unrealistic.
    • Even if they know B’s intentions: instead of running to sell their shares directly; i.e., extracting the profits immediately, they for some reason frontrun B by buying shares for them; i.e., they run to experience a net loss first instead of immediately extracting profit.
  • Overall, it’s just an unrealistic assumption that someone would organize a DoS via buying shares at increasing prices, for someone else, only to be able to delay them for 10 minutes from selling their shares.

  • Finally, if you disregard the unrealistic assumption above that someone knew someone else’s intention to sell their shares, what is the net effect of this “attack”?

    • The attacker spends funds to buy shares for the victim…
    • Each time investing more and more money to delay the victim for another 10 minutes (!)…
    • While at the end the victim, who now owns substantially more shares, is able to sell them at increased prices, which increased specifically due to the executed attack.

With all due respect, this is a bunch of unrealistic assumptions stitched together.

0xDjango (judge) commented:

This is a valid griefing scenario. While it does involve the attacker “gifting” a share of increasing value, it temporarily locks someone’s funds. Higher level, this verges into “market manipulation” as anyone is able to prop up the market by prohibiting sales. Also, imagine if an exploit occurs or a zero-day vulnerability is leaked. Blocking user withdrawals for even 10 minutes will have severe impact. Given that such an example is low likelihood, this will remain as Medium.

Note: For full discussion, see here.


The original report as published on Code4rena, by MrPotatoMagic. 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

Likely the buy-for-another-user function updates the same last-trade timestamp used for the seller's lock period, so a third party can reset another user's lock.

Impact

A victim could be repeatedly blocked from selling for ten minutes at a time, and the share price may fall during the delay, causing a loss; the judge rated this a valid griefing scenario at Medium severity.

What the attacker needed

Attacker pays for at least one share; attacker knows victim wants to sell; victim holds shares of the credId

The fix

The reporter suggested removing the buy-for-another-user function, though the text does not say it was fixed.

How it was found

  1. Assume several users have already bought shares of a credId and one user, B, wants to sell soon.
  2. Close to the end of B's lock period, the attacker calls the buy-for function with B as the curator.
  3. The internal trade handler updates B's last trade timestamp, restarting the ten-minute lock.
  4. B tries to sell but the lock check reverts the transaction.
  5. Other holders sell during the delay, lowering the share price and B's potential proceeds.

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.

A smart contract lets people buy and sell 'shares' tied to a curator. After any trade, that curator must wait ten minutes before selling. Because anyone can buy a share for someone else, a stranger can keep restarting that waiting clock, so the victim cannot sell when they want.

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 by MrPotatoMagic

View all

17 more disclosed reports, best first.

More from Phi

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.