Early user can break pool via inflation attack due to no minimum liquidity check in the incentive contract
The incentive contract lacks a minimum liquidity check, allowing a user to hold as few as one share. An attacker can manipulate the share-to-reward ratio so that reward inflation rounds to zero, letting them steal rewards from other users.
carrotsmuggler Follow with zhaojie
Originally disclosed on Code4rena
Submitted by carrotsmuggler, also found by zhaojie
The incentive contract does not enforce a minimum liquidity limit. This means users can have as little as 1 share in the pool. This can lead to inflation attacks as described below.
Let’s imagine the state of the pool is as follows:
There is a single depositor, with 1000 shares deposited. Rewards have been accumulated up to 500 tokens. The user can then withdraw 998 shares, leaving 2 shares. They will also claim the rewards, and leave 1 reward tokens in the pool. This is the setup for the inflation attack. The user can then deposit 1 share.
The inflation is calculated as shown below:
U256::from(add_amount.to_owned().saturated_into::<u128>())
.saturating_mul(total_reward.to_owned().saturated_into::<u128>().into())
.checked_div(initial_total_shares.to_owned().saturated_into::<u128>().into())
.unwrap_or_default()
.as_u128()
.saturated_into()
Here total_reward=1, add_amount=1 and initial_total_shares=2. So the result is calculated to 0; so inflation is 0.
After this step, the initial_total_shares is updated to 3. Now the user can deposit 2 wei of shares without changing the inflation amount. Next iteration, they can deposit 4 shares. This way, the user can deposit 2**n shares each iteration, and inflate the initial_total_shares without affecting the reward inflation. This leads to the situation where the total_shares keeps growing according to the deposit, but the entire reward inflation mechanism is broken. This lets users steal reward tokens from other users, and is a high severity issue.
In fact, whenever the total_reward value is less than the total_shares, this issue can be triggered. This is because in those conditions, users can create deposits and have the reward_inflation evaluate to 0. 0 reward_inflation basically means later users can steal rewards of earlier users, as is outlined in the docs. However, this donation attack is more effective the lower the total_shares in the system.
Proof of Concept
The situation can be created via the following steps:
- Since there is no minimum deposit, we can create a situation where the
total_reward < total_shares, andtotal_shares=2. This also works for higher values oftotal_share, but is most potent in this stage. - User deposits 1 share, or any number of shares as long as
deposit*total_reward/total_sharesis less than 1.reward_inflationwill be0, while the user gets their shares accounted for. - Since
total_shareshas now increased, the user can deposit more shares now, and still have thereward_inflationbe0. This way, the user can keep depositing shares and increasing thetotal_shareswithout affecting the reward inflation. - Since
reward_inflationand thustotal_rewardhas not increased, but thetotal_shareshave increased, users will lose rewards, since the rewards are calculated astotal_reward * user_shares / total_shares. This means older users lose shares.
While this vector is generally applicable and can lead to small losses when there’s a lot of liquidity, this becomes more potent when there is very low liquidity in the pool. This was the method of attack for the Wise Lending hack and is a high severity issue. More details can be found in the blog post here which outlines the attack scenario with more numbers and examples.
Tools Used
Substrate
Recommended Mitigation Steps
Add a minimum liquidity limit. This will ensure the pool never reaches a liquidity amount so low that rounding errors become significant.
xlc (Acala) confirmed and commented:
It is actually almost impossible to trigger this in production because anyone can deposit into the incentives pool at any time. I.E. before rewards starts accumulates.
Fixed by this PR.
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 absence of a minimum liquidity requirement allows the share count to become so low that integer division in the reward inflation calculation truncates to zero.
Impact
Users could steal reward tokens from other users, though the project maintainer noted it is almost impossible to trigger in production because anyone can deposit into the pool at any time.
What the attacker needed
Ability to deposit into the incentive pool; pool total_shares can be reduced to a very low value
The fix
A minimum liquidity limit should be added so the pool never reaches a liquidity amount so low that rounding errors become significant; the project says it was fixed by a pull request.
How it was found
- Create a situation where total_reward is less than total_shares and total_shares equals 2.
- Deposit 1 share (or any amount such that deposit*total_reward/total_shares is less than 1), making reward_inflation zero while shares are credited.
- Because total_shares has increased, deposit more shares while reward_inflation remains zero.
- Repeat deposits to keep increasing total_shares without increasing reward_inflation, causing older users to lose 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 reward pool gives out tokens based on how many shares each person holds. If someone can make the pool very small, they can add tiny amounts of shares in a way that the reward calculation rounds down to zero, so they keep getting shares without increasing the reward pool. This lets them take rewards that should have gone to earlier users.
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.