Incentive accumulation can be sandwiched with additional shares to gain advantage over long-term depositors
0xTheC0der Follow with zhaojie, djxploit and 1 other
Originally disclosed on Code4rena
Submitted by 0xTheC0der, also found by zhaojie, djxploit, and carrotsmuggler
Incentives are accumulated periodically in intervals of T::AccumulatePeriod blocks. Thereby, a fixed incentive reward amount, which is set via update_incentive_rewards(…), is accumulated among all deposited shares of a respective pool. This means if only 1 share is deposited, it is entitled for the all the rewards of this period, if N shares are deposited, the rewards are split among them, etc. (see PoC).
Furthermore, to be eligible for rewards, it is sufficient to deposit (DEX) shares before accumulate_incentives(…) is called via the on_initialize hook. This is also demonstrated in the transfer_reward_and_update_rewards_storage_atomically_when_accumulate_incentives_work() test case.
Afterward, rewards can be immediately claimed and (DEX) shares can be withdrawn without any unbonding period or other block/time related restrictions.
This leads to the following consequences:
- Users are not incentivized to keep (DEX) shares deposited, but rather to sandwich the incentive accumulation via deposit, claim & withdraw.
- Since (DEX) shares are only required for a short period of time (
>1 block) to perform the above action, an adversary can borrow vast amounts of (DEX) shares (or the underlying assets to get them) to crowd out honest users during the incentive accumulation and therefore obtain an unfairly high share of the fixed rewards.
For reference, see also the earnings module, where an unbonding period is explicitly enforced.
Proof of Concept
The diff below modifies the existing test case transfer_reward_and_update_rewards_storage_atomically_when_accumulate_incentives_work() to demonstrate that the same total reward amount is accumulated even if twice as many total shares are deposited. Therefore, it’s possible to crowd out honest users with great short-term share deposits.
diff --git a/src/modules/incentives/src/tests.rs b/src/modules/incentives/src/tests.rs
index 1370d5b..fa16a08 100644
--- a/src/modules/incentives/src/tests.rs
+++ b/src/modules/incentives/src/tests.rs
@@ -1171,10 +1171,11 @@ fn transfer_reward_and_update_rewards_storage_atomically_when_accumulate_incenti
assert_eq!(TokensModule::free_balance(AUSD, &VAULT::get()), 0);
RewardsModule::add_share(&ALICE::get(), &PoolId::Loans(LDOT), 1);
+ RewardsModule::add_share(&BOB::get(), &PoolId::Loans(LDOT), 1);
assert_eq!(
RewardsModule::pool_infos(PoolId::Loans(LDOT)),
PoolInfo {
- total_shares: 1,
+ total_shares: 2,
..Default::default()
}
);
@@ -1188,7 +1189,7 @@ fn transfer_reward_and_update_rewards_storage_atomically_when_accumulate_incenti
assert_eq!(
RewardsModule::pool_infos(PoolId::Loans(LDOT)),
PoolInfo {
- total_shares: 1,
+ total_shares: 2,
rewards: vec![(ACA, (30, 0)), (AUSD, (90, 0))].into_iter().collect()
}
);
@@ -1202,7 +1203,7 @@ fn transfer_reward_and_update_rewards_storage_atomically_when_accumulate_incenti
assert_eq!(
RewardsModule::pool_infos(PoolId::Loans(LDOT)),
PoolInfo {
- total_shares: 1,
+ total_shares: 2,
rewards: vec![(ACA, (60, 0)), (AUSD, (90, 0))].into_iter().collect()
}
);
Recommended Mitigation Steps
The present issue scales with the size of T::AccumulatePeriod in terms of blocks. Therefore, it’s recommended (for fairness) to also track deposited shares in between the accumulation intervals and scale the incentive rewards according to the actual deposit duration.
Assessed type
MEV
xlc (Acala) disputed and commented:
Furthermore, to be eligible for rewards, it is sufficient to deposit (DEX) shares before accumulate_incentives(…) is called via the on_initialize hook
It is not possible to do perform user triggered action before
on_initialize. To exploit this, attacker will need to acquire a large number of dex share somehow, deposit it, what for a block, withdraw it, ????, and repeat the same thing on next minute.Firstly, it is not possible to borrow such amount of share without some payments, because the lender have the full incentives to deposit the shares and getting the rewards. It is also not a lost free action to mint such amount of dex share and redeem them due to potential price exposure and sandwich risk.
Therefore, it is economically impossible to exploit this behavior and make a profit.
The described scenario has some stated assumptions with external requirements (availability of liquidity, possibility to front- and back-run the transactions risk free, etc…) that may not always hold in practice. But these are not very unreasonable assumptions and under these assumptions, a value leak is possible. This, therefore, fulfills the criteria of a valid medium according to the severity categorization.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
What is known
A medium-severity business logic bug in Acala. Code4rena made it public on 2 May 2024. Found in the 2024-03-acala audit contest (finding M-02), also found by 3 other wardens.
About Business logic
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
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.