Skip to content
Business logic Audit finding Intermediate

Dishonest Stakers Can Siphon Rewards From xToken Holders Through The deposit Function In NFTXInventoryStaking

The deposit function in NFTXInventoryStaking allows a user to deposit vault tokens just before a reward distribution and withdraw immediately after, capturing a disproportionate share of rewards. An attacker can also trigger reward distribution at will because the distribute function lacks access control.

leastwood Follow

Originally disclosed on Code4rena

Submitted by leastwood

xTokens is intended to be a representation of staked vault tokens. As the protocol’s vaults accrue fees from users, these fees are intended to be distributed to users in an inconsistent fashion. NFTXInventoryStaking is one of the ways users can stake vault tokens. Deposits are timelocked for 2 seconds by default, essentially rendering flash loan attacks redundant. However, it is more than likely that the same user could withdraw their xToken deposit in the next block (assuming an average block time of just over 13 seconds).

Hence, if a well-funded attacker sees a transaction to distribute rewards to xToken holders, they could deposit a large sum of vault tokens and receive a majority share of the rewards before withdrawing their tokens in the following block. Additionally, the attacker can force distribute rewards in NFTXSimpleFeeDistributor as there is no access control on the distribute function.

This issue allows users to siphon user’s rewards from the protocol, intended to be distributed to honest vault token stakers.

Proof of Concept

Consider the following exploit scenario:

  • Currently there are 1000 shares and 1000 base tokens in the XTokenUpgradeable contract.
  • Honest actor, Alice, calls distribute in NFTXSimpleFeeDistributor which attempts to send 200 base tokens as rewards for xToken holders accrued via protocol usage.
  • Bob sees a transaction to reward xToken holders and frontruns this transaction by staking vault tokens, minting 1000 shares and 1000 base tokens.
  • Rewards are distributed such that XTokenUpgradeable has 2000 shares and 2200 base tokens.
  • Bob unstakes his tokens and exits the pool, redeeming his 1000 shares for 1100 base tokens.
  • As a result, Bob was able to siphon off 100 base tokens without having to stake their tokens for the same time period that Alice had staked her tokens for.
  • This unfair distribution can be abused again and again to essentially reward dishonest actors over honest staking participants such as Alice.

Tools Used

Manual code review. Discussions with Kiwi.

Recommended Mitigation Steps

Consider adding a delay to users token deposits into the XTokenUpgradeable such that miners cannot feasibly censor a transaction for the specified time interval and users cannot frontrun a transaction to distribute rewards. The interval should be chosen such that enough time is provided for the transaction to be included in a block, given poor network conditions.

I.e. If the chosen interval is 20 blocks. Miners must be able to censor the rewards distribution for 20 blocks. This is unlikely as there would need to be sufficient miner collusion for value to be extracted from the protocol. Additionally, an interval of 20 blocks means that stakers who attempt to enter the pool upon seeing the transaction in the mempool won’t be rewarded for such behaviour.

It is also essential that the distribute function in NFTXSimpleFeeDistributor is restricted to a given role, ensuring malicious users cannot control at what point rewards are distributed.

Alternatively, PoolTogether has a Time-Weighted-Average-Balance (TWAB) implementation which can be used as reference. This would ensure the fairest distribution of rewards to stakers, however, there are additional gas costs associated with this implementation. Hence, unless the protocol intends to be used primarily on L2 protocols, this solution should be avoided.

0xKiwi (NFTX) acknowledged, but disagreed with high severity and commented:

While this attack is possible, without available flash liquidity, this attack vector requires a lot of (possibly difficult to acquire) capital to execute. Disagreeing with severity and acknowledging.

LSDan (judge) decreased severity to medium and commented:

I agree with the sponsor that the risk of this happening is almost zero. Yes it’s technically possible but the funds lost are going to be minimal and the attacker will almost definitely pay more in slippage and gas fees than they make. That said, this is a direct attack which results in a loss of user funds so making it less than medium risk seems disingenuous.


The original report as published on Code4rena, by leastwood. 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 reward distribution is based on the current share balance without any time-weighting or deposit delay, and the distribute function is callable by anyone.

Impact

An attacker could repeatedly siphon rewards from honest stakers, though the sponsor and judge noted the attack requires significant capital and may cost more in gas and slippage than it gains.

What the attacker needed

Large amount of vault tokens; ability to frontrun reward distribution; no flash loan needed

The fix

The deposit should be delayed so that frontrunning reward distributions is not profitable, and the distribute function should be restricted to a privileged role.

How it was found

  1. Alice calls distribute in NFTXSimpleFeeDistributor to send 200 base tokens as rewards.
  2. Bob sees the reward transaction and frontruns it by staking vault tokens, minting 1000 shares and 1000 base tokens.
  3. Rewards are distributed, resulting in 2000 shares and 2200 base tokens in XTokenUpgradeable.
  4. Bob unstakes his tokens and redeems his 1000 shares for 1100 base tokens, siphoning 100 base tokens.

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 stake tokens in a pool, you get a share of rewards based on how long you have staked. Here, someone can stake just before rewards are paid out and then unstake right after, taking a large cut of rewards meant for long-term stakers. The attacker can also start the reward payout themselves because anyone can call the distribute function.

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 leastwood

View all

70 more disclosed reports, best first.

More from NFTX contest

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.