Claiming accumulated rewards while the contract is underfunded can lead to a loss of rewards
The RewardsManager contract caps claimable rewards at its current Ajna token balance, so if the contract is underfunded, a staker receives fewer rewards than earned. The remaining rewards are not tracked and cannot be claimed later, causing a permanent loss.
berndartmueller Follow with ctf_sec and oxcm
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-01-ajna-judging/issues/120
Found by
berndartmueller, ctf_sec, oxcm
Summary
The claimable rewards for an NFT staker are capped at the Ajna token balance at the time of claiming. This can lead to a loss of rewards if the RewardsManager contract is underfunded with Ajna tokens.
Vulnerability Detail
The RewardsManager contract keeps track of the rewards earned by an NFT staker. The accumulated rewards are claimed by calling the RewardsManager.claimRewards function. Internally, the RewardsManager._claimRewards function transfers the accumulated rewards to the staker.
However, the transferrable amount of Ajna token rewards are capped at the Ajna token balance at the time of claiming. If the accumulated rewards are higher than the Ajna token balance, the claimer will receive fewer rewards than expected. The remaining rewards cannot be claimed at a later time as the RewardsManager contract does not keep track of the rewards that were not transferred.
Impact
If an NFT staker claims the accumulated rewards in a bad situation (when the RewardsManager contract is underfunded with Ajna tokens), the staker will receive fewer rewards than expected and is unable to claim the rest of the rewards at a later time.
Code Snippet
contracts/src/RewardsManager.sol#L479
445: function _claimRewards(
446: uint256 tokenId_,
447: uint256 epochToClaim_
448: ) internal {
// [...]
477: uint256 ajnaBalance = IERC20(ajnaToken).balanceOf(address(this));
478:
479: if (rewardsEarned > ajnaBalance) rewardsEarned = ajnaBalance;
480:
481: // transfer rewards to sender
482: IERC20(ajnaToken).safeTransfer(msg.sender, rewardsEarned);
483: }
Tool used
Manual Review
Recommendation
Consider reverting if insufficient Ajna tokens are available as rewards.
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 claim function caps the payout at the contract's token balance without recording the shortfall, so any excess rewards are silently forfeited.
Impact
A staker who claims while the contract is underfunded receives fewer rewards than expected and cannot claim the remainder later.
What the attacker needed
Contract underfunded with Ajna tokens; staker has accumulated rewards
The fix
The contract should revert if it does not hold enough Ajna tokens to pay the full accumulated 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.
A smart contract holds reward tokens for people who stake NFTs. When someone claims, the contract pays out only as many tokens as it currently holds, even if the person earned more. The unpaid part is not recorded, so it is lost 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.