Skip to content
Business logic Audit finding Advanced

Dividend reward can be gamed

The dividend reward mechanism in the Router contract can be manipulated by an attacker who makes small trades to reset the average fee to zero, then generates a fee to claim half of the daily allocation repeatedly, draining the reserve.

cmichel Follow

Originally disclosed on Code4rena

Submitted by cmichel

The Router.addDividend function tells the reserve to send dividends to the pool depending on the fees.

  • The attacker provides LP to a curated pool. Ideally, they become a large LP holder to capture most of the profit, they should choose the smallest liquidity pool as the dividends are pool-independent.
  • The normalAverageFee variable that determines the pool dividends can be set to zero by the attacker by trading a single wei in the pool arrayFeeSize (20) times (use buyTo). The fees of the single wei trades will be zero and thus the normalAverageFee will also be zero as, see addTradeFee.
  • The attacker then does a trade that generates some non-zero fees, setting the normalAverageFee to this trade’s fee. The feeDividend is then computed as _fees * dailyAllocation / (_fees + normalAverageFee) = _fees * dailyAllocation / (2 * _fees) = dailyAllocation / 2. Half of the dailyAllocation is sent to the pool.
  • The attacker repeats the above steps until the reserve is almost empty. Each time the dailyAllocation gets smaller but it’s still possible to withdraw almost all of it.
  • They redeem their LP tokens and gain a share of the profits

The reserve can be emptied by the attacker.

Counting only the last 20 trades as a baseline for the dividends does not work. It should probably average over a timespan but even that can be gamed if it is too short. I think a better idea is to compute the dividends based on volume traded over a timespan instead of looking at individual trades.

verifyfirst (Spartan) acknowledged:

Only very deep pools will be curated for dividends. Variables can be changed reactively to alter the dividends. Whilst we were aware of this and feel the attack is limited its sparked some discussion for some new ideas to solve this.

ghoul-sol (judge) commented:

Keeping high risk as the report is valid

The original report as published on Code4rena, by cmichel. 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

Likely the dividend calculation uses a manipulable average fee based on only the last 20 trades, which an attacker can reset to zero with zero-fee trades and then set to a chosen value, causing the dividend to be half of the daily allocation regardless of actual fees.

Impact

The reserve can be emptied by the attacker, though the program acknowledged the attack is limited because only very deep pools will be curated for dividends.

What the attacker needed

Attacker provides liquidity to a curated pool; pool has small liquidity; attacker can make many small trades

The fix

The dividends should be computed based on volume traded over a timespan instead of looking at individual trades.

How it was found

  1. The attacker provides liquidity to a curated pool, preferably a small one to capture most of the profit.
  2. The attacker makes 20 tiny trades of one wei each to set the normalAverageFee to zero.
  3. The attacker makes a trade that generates non-zero fees, setting normalAverageFee to that fee.
  4. The attacker receives half of the dailyAllocation as dividend.
  5. The attacker repeats the above steps until the reserve is almost empty.
  6. The attacker redeems their LP tokens and gains a share of the profits.

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 smart contract pays out dividends to liquidity providers based on recent trading fees. An attacker can trick the contract into paying out much more than intended by making tiny trades that reset the fee average, then making one trade that sets the average to a known value, allowing them to claim half of the daily reward repeatedly. This drains the reserve that holds the rewards.

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 cmichel

View all

196 more disclosed reports, best first.

More from Spartan Protocol Contest

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.