Storage can be bloated with low liquidity positions
The deposit_dex_share function allows users to create multiple tiny (1 wei) positions without a minimum deposit, which can bloat the blockchain's storage. An attacker could cheaply create many such positions, potentially leading to high maintenance costs and a denial of service.
ZanyBonzy Follow with Bauchibred and carrotsmuggler
Originally disclosed on Code4rena
Submitted by ZanyBonzy, also found by Bauchibred and carrotsmuggler
The deposit_dex_share function enforce no minimum amount that can be deposited into the pool allows for creating multiple pool positions. This causes that in a coordinated effort, for a pretty cheap cost, users/attackers can create multiple low liquidity positions to bloat the runtime storage. This is very important as substrate framework requires optimization of storage to prevent bloat which can lead to high maintenance costs for the chain and a potential DOS. A more in detail explanation can be found here.
Proof of Concept
The test case below shows how a user can create multiple 1 wei positions, and it can be added to test.rs.
#[test]
fn open_low_liquidity_positions() {
ExtBuilder::default().build().execute_with(|| {
assert_ok!(TokensModule::deposit(BTC_AUSD_LP, &ALICE::get(), 1000000000));
assert_eq!(TokensModule::free_balance(BTC_AUSD_LP, &ALICE::get()), 1000000000);
assert_eq!(
TokensModule::free_balance(BTC_AUSD_LP, &IncentivesModule::account_id()),
0
);
assert_eq!(RewardsModule::pool_infos(PoolId::Dex(BTC_AUSD_LP)), PoolInfo::default(),);
assert_eq!(
RewardsModule::shares_and_withdrawn_rewards(PoolId::Dex(BTC_AUSD_LP), ALICE::get()),
Default::default(),
);
assert_ok!(IncentivesModule::deposit_dex_share(
RuntimeOrigin::signed(ALICE::get()),
BTC_AUSD_LP,
1
));
assert_ok!(IncentivesModule::deposit_dex_share(
RuntimeOrigin::signed(ALICE::get()),
BTC_AUSD_LP,
1
));
assert_ok!(IncentivesModule::deposit_dex_share(
RuntimeOrigin::signed(ALICE::get()),
BTC_AUSD_LP,
1
));
assert_eq!(TokensModule::free_balance(BTC_AUSD_LP, &ALICE::get()), 999999997);
assert_eq!(
TokensModule::free_balance(BTC_AUSD_LP, &IncentivesModule::account_id()),
3
);
assert_eq!(
RewardsModule::pool_infos(PoolId::Dex(BTC_AUSD_LP)),
PoolInfo {
total_shares: 3,
..Default::default()
}
);
assert_eq!(
RewardsModule::shares_and_withdrawn_rewards(PoolId::Dex(BTC_AUSD_LP), ALICE::get()),
(3, Default::default())
);
});
}
Recommended Mitigation Steps
Introduce a minimum deposit amount.
xlc (Acala) confirmed and commented:
Fixed here.
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
The deposit_dex_share function lacks a minimum deposit amount, allowing the creation of arbitrarily many low-value positions.
Impact
An attacker could cheaply create many low-liquidity positions, bloating storage and potentially causing a denial of service due to increased maintenance costs.
What the attacker needed
Ability to call deposit_dex_share; some tokens to deposit
The fix
A minimum deposit amount was introduced to prevent the creation of tiny positions.
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 blockchain stores data in a way that costs money to maintain. If users can create many tiny records cheaply, the storage grows unnecessarily, making the chain expensive to run and possibly unusable. This report shows that a function lets users deposit extremely small amounts repeatedly, creating many such records.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.