missing isEpochClaimed validation
The internal reward-claiming routine does not check whether an epoch has already been claimed, and the liquidity-moving function calls it without that check. A staker could claim rewards for an epoch and then move their staked liquidity to trigger the same claim again, though the project disputed that this yields extra rewards.
Jorgect Follow with shealtielanz and ABAIKUNANBAEV
Originally disclosed on Code4rena
Submitted by Jorgect, also found by shealtielanz and ABAIKUNANBAEV
User can claim rewards even when is already claimed
Proof of Concept
The _claimRewards function is using to calculate and send the reward to the caller but this function is no validating if isEpochClaimed mapping is true due that in claimRewards function is validated, see the stament in the following lines:
file: ajna-core/src/RewardsManager.sol
function claimRewards(
uint256 tokenId_,
uint256 epochToClaim_
) external override {
StakeInfo storage stakeInfo = stakes[tokenId_];
if (msg.sender != stakeInfo.owner) revert NotOwnerOfDeposit();
if (isEpochClaimed[tokenId_][epochToClaim_]) revert AlreadyClaimed(); // checking if the epoch was claimed;
_claimRewards(
stakeInfo,
tokenId_,
epochToClaim_,
true,
stakeInfo.ajnaPool
);
}
Now the moveStakedLiquidity is calling _claimRewards too without validate isEpochClaimed mapping:
file: ajna-core/src/RewardsManager.sol
function moveStakedLiquidity(
uint256 tokenId_,
uint256[] memory fromBuckets_,
uint256[] memory toBuckets_,
uint256 expiry_
) external override nonReentrant {
StakeInfo storage stakeInfo = stakes[tokenId_];
if (msg.sender != stakeInfo.owner) revert NotOwnerOfDeposit();
uint256 fromBucketLength = fromBuckets_.length;
if (fromBucketLength != toBuckets_.length)
revert MoveStakedLiquidityInvalid();
address ajnaPool = stakeInfo.ajnaPool;
uint256 curBurnEpoch = IPool(ajnaPool).currentBurnEpoch();
// claim rewards before moving liquidity, if any
_claimRewards(stakeInfo, tokenId_, curBurnEpoch, false, ajnaPool); // no checking is isEpochClaimed is true and revert
Also we can see in the _claimRewards function there is no validation is isEpochClaimed is true, this allow a malicius user claimReward first and then move his liquidity to other bucket or the same bucket claiming the reward each time that he want.
function _claimRewards(
StakeInfo storage stakeInfo_,
uint256 tokenId_,
uint256 epochToClaim_,
bool validateEpoch_,
address ajnaPool_
) internal {
// revert if higher epoch to claim than current burn epoch
if (
validateEpoch_ &&
epochToClaim_ > IPool(ajnaPool_).currentBurnEpoch()
) revert EpochNotAvailable();
// update bucket exchange rates and claim associated rewards
uint256 rewardsEarned = _updateBucketExchangeRates(
ajnaPool_,
positionManager.getPositionIndexes(tokenId_)
);
rewardsEarned += _calculateAndClaimRewards(tokenId_, epochToClaim_);
uint256[] memory burnEpochsClaimed = _getBurnEpochsClaimed(
stakeInfo_.lastClaimedEpoch,
epochToClaim_
);
emit ClaimRewards(
msg.sender,
ajnaPool_,
tokenId_,
burnEpochsClaimed,
rewardsEarned
);
// update last interaction burn event
stakeInfo_.lastClaimedEpoch = uint96(epochToClaim_);
// transfer rewards to sender
_transferAjnaRewards(rewardsEarned);
}
Recommended Mitigation Steps
Check if the isEpochClaime is true and revert in the _claimReward function
if (isEpochClaimed[tokenId_][epochToClaim_]) revert AlreadyClaimed();
ith-harvey (Ajna) disputed and commented:
The series of calls they are suggesting are possible: stake claimRewards() -> get rewards moveStakedLiquidity() -> get rewards
They should not be able to get these rewards because
_calculateAndClaimRewards()iterates from last claimed epoch.
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 shared internal claim routine trusts its callers to perform the already-claimed check, and the liquidity-move path does not perform it.
Impact
The reporter claims a user could receive rewards for the same epoch repeatedly, but the project disputed this, saying the calculation only iterates from the last claimed epoch, so no extra payout occurs.
What the attacker needed
A staked position in the rewards contract
The fix
The text recommends checking the already-claimed mapping inside the internal claim routine and reverting if the epoch was claimed.
How it was found
- Stake into the rewards contract to obtain a position.
- Call claimRewards for the current epoch to receive rewards.
- Call moveStakedLiquidity, which internally claims rewards again without the already-claimed check.
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 staking contract pays out rewards per period (an 'epoch'). Normally it records that a period was paid so it cannot be paid twice. Here one code path that pays rewards skips that record check, so the reporter thought a user could collect the same period's reward more than once by moving their stake around.
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.