Claiming rewards while the deduction rate is != 0 , allows for repeated withdrawal of redistributed rewards
When a pool participant claims rewards while a deduction rate is non-zero, the deducted portion is redistributed to all participants, including the claimer. This lets a user repeatedly claim and recover part of their own deduction, drawing more from the reward pool than intended.
n4nika Follow with ABAIKUNANBAEV and djxploit
Originally disclosed on Code4rena
Submitted by n4nika, also found by ABAIKUNANBAEV and djxploit
If a participant in a pool claims rewards while the deduction rate is != 0, the deducted rewards are redistributed between all the participants.
fn payout_reward_and_reaccumulate_reward(
pool_id: PoolId,
who: &T::AccountId,
reward_currency_id: CurrencyId,
payout_amount: Balance,
reaccumulate_amount: Balance,
) -> DispatchResult {
if !reaccumulate_amount.is_zero() {
<orml_rewards::Pallet<T>>::accumulate_reward(&pool_id, reward_currency_id, reaccumulate_amount)?;
}
T::Currency::transfer(reward_currency_id, &Self::account_id(), who, payout_amount)?;
Ok(())
}
Since the deduction is redistributed between all participants (since accumulate_reward distributes to all participating users) including the one claiming the reward, they can repeatedly claim rewards and receive more of the rewards pool than they probably should.
Proof of Concept
#[test]
fn repeated_claiming() {
ExtBuilder::default().build().execute_with(|| {
assert_ok!(TokensModule::deposit(BTC, &VAULT::get(), 10000));
assert_ok!(IncentivesModule::update_claim_reward_deduction_rates(
RuntimeOrigin::signed(ROOT::get()),
vec![(PoolId::Dex(BTC_AUSD_LP), Rate::saturating_from_rational(0, 100))]
));
assert_ok!(IncentivesModule::update_claim_reward_deduction_rates(
RuntimeOrigin::signed(ROOT::get()),
vec![(PoolId::Dex(BTC_AUSD_LP), Rate::saturating_from_rational(20, 100))]
));
// 40% deduction rate
assert_ok!(IncentivesModule::update_claim_reward_deduction_rates(
RuntimeOrigin::signed(ROOT::get()),
vec![(PoolId::Dex(BTC_AUSD_LP), Rate::saturating_from_rational(40, 100))]
));
// give RewardsSource tokens
TokensModule::deposit(BTC, &RewardsSource::get(), 10000);
// add 11 participants with equal shares
TokensModule::deposit(BTC_AUSD_LP, &ALICE::get(), 100);
TokensModule::deposit(BTC_AUSD_LP, &BOB::get(), 100);
// 1000 BTC as reward
IncentivesModule::update_incentive_rewards(RuntimeOrigin::signed(ROOT::get()), vec![(PoolId::Dex(BTC_AUSD_LP), vec![(BTC, 1000)])]);
// all 11 participants deposit their share
assert_ok!(IncentivesModule::deposit_dex_share(RuntimeOrigin::signed(ALICE::get()), BTC_AUSD_LP, 100));
assert_ok!(IncentivesModule::deposit_dex_share(RuntimeOrigin::signed(BOB::get()), BTC_AUSD_LP, 100));
// first accumulation of rewards
IncentivesModule::on_initialize(10);
// ALICE claims their reward and should receive ((1000 // 2) * 0.6) = 300 BTC
assert_ok!(IncentivesModule::claim_rewards(RuntimeOrigin::signed(ALICE::get()), PoolId::Dex(BTC_AUSD_LP)));
let btc_before = TokensModule::total_balance(BTC, &ALICE::get());
// here ALICE should have claimed all their rewards and not be able to claim anymore
assert_ok!(IncentivesModule::claim_rewards(RuntimeOrigin::signed(ALICE::get()), PoolId::Dex(BTC_AUSD_LP)));
let btc_after = TokensModule::total_balance(BTC, &ALICE::get());
assert_eq!(btc_before, btc_after);
});
}
Recommended Mitigation Steps
Add the claiming user to accumulate_rewards and implement reaccumulating excluding the calling user.
xlc (Acala) disputed and commented:
This is intended behaviour and non issue.
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 redistribution function credits the deducted amount to all participants without excluding the account that just claimed, so the claimer receives part of their own deduction back.
Impact
A participant could repeatedly claim to recover part of their own deduction, potentially extracting more from the reward pool than intended; the project disputed this as intended behaviour.
What the attacker needed
A pool with a non-zero deduction rate; a participant with a pool share
The fix
The reporter suggested adding the claiming user to the accumulation call and reaccumulating while excluding the caller, though the project disputed the issue.
How it was found
- Set a non-zero deduction rate on the pool.
- Fund the rewards source and add participants with equal shares.
- Trigger reward accumulation.
- Have a participant claim rewards, then claim again.
- Observe the balance changes from the repeated claims.
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 reward pool pays out tokens to people who deposit into it. A deduction rate means a slice of each payout is taken back and shared among everyone in the pool. The report says the person claiming also gets a share of their own deduction, so by claiming over and over they slowly take back more than they should.
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.