Rewards can be stolen
The NFTXInventoryStaking contract distributes rewards in a single lump when the owner calls receiveRewards, so an attacker can front-run that transaction with a deposit and receive a share of the rewards. After a short lock period, the attacker withdraws the deposit and rewards for a profit.
Submitted by cmichel
The NFTXInventoryStaking contract distributes new rewards to all previous stakers when the owner calls the receiveRewards function. This allows an attacker to frontrun this receiveRewards transaction when they see it in the mem pool with a deposit function. The attacker will receive the rewards pro-rata to their deposits. The deposit will be locked for 2 seconds only (DEFAULT_LOCKTIME) after which the depositor can withdraw their initial deposit & the rewards again for a profit.
The rewards can be gamed this way and one does not actually have to stake, only be in the staking contract at the time of reward distribution for 2 seconds. The rest of the time they can be used for other purposes.
Recommended Mitigation Steps
Distribute the rewards equally over time to the stakers instead of in a single chunk on each receiveRewards call. This is more of a “streaming rewards” approach.
0xKiwi (NFTX) confirmed and commented:
Thanks for the report.
This is unfortunately unavoidable but streaming isn’t a bad idea. Will consider. Thank you.
Confirming.
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 rewards are distributed in a single lump sum at the moment receiveRewards is called, so anyone who deposits just before that call receives a share proportional to their deposit.
Impact
An attacker could steal a share of the rewards without staking for a meaningful period, and the rewards can be gamed this way.
What the attacker needed
Attacker can see pending transactions; attacker has funds to deposit; owner calls receiveRewards
The fix
The rewards should be distributed equally over time to the stakers instead of in a single chunk on each receiveRewards call.
How it was found
- Attacker sees the receiveRewards transaction in the mem pool.
- Attacker front-runs it by calling deposit.
- Attacker waits for the lock period to end.
- Attacker withdraws the initial deposit and the rewards.
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 the owner adds rewards to a staking contract, the rewards are split among everyone who is staking at that moment. An attacker can watch for the owner's transaction and quickly add their own stake just before it, so they get a share of the rewards without staking for long. After a short wait, they take their money and the rewards out.
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.