Skip to content
Smart contracts Write-up Intermediate

The Silent Yield Killer: How Unscaled Integer Division Trapped Farming Rewards in a Top DEX

The reward accumulator in a Sui DEX farming contract divided the pool reward by total shares without first multiplying by the precision constant, so integer truncation set the per-share reward to zero whenever the reward was smaller than the share count. This caused the contract to mark rewards as released while users received no credit, permanently trapping those tokens in the vault.

Hacker MD Follow

Published on medium.com

In Decentralized Finance (DeFi), math is quite literally money. A single misplaced decimal, a wrong rounding direction, or a missing scaling factor can silently siphon millions of dollars from users.

Hacker MD, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the accumulator calculation omitted the REWARD_PRECISION multiplier before integer division, causing truncation to zero for small per-share rewards.

Impact

Rewards could be permanently trapped in the vault, with users receiving no yield, though the team classified it as a known limitation and the report was closed as informative.

What the attacker needed

Access to the contract source; a farming pool with rewards smaller than shares

The fix

The calculation should multiply the pool reward by the precision constant before dividing by total shares, as the standard formula does.

How it was found

  1. Review the rewarder.move module and note the defined REWARD_PRECISION constant.
  2. Inspect the accumulate_pool_reward function and see that the constant is not used in the per-share calculation.
  3. Simulate a one-second state transition with realistic pool shares and reward amounts.
  4. Observe that the contract records tokens as released while the per-share accumulator increases by zero.

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 write-up has not been written yet. The Original tab links to the source.

Smart contracts cannot store decimals, so they use whole numbers and a scaling factor to represent fractions. If you divide before multiplying by that factor, small amounts get rounded down to zero. Here, the contract recorded rewards as paid out but gave users nothing, so the tokens were stuck forever.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by Hacker MD

View all

12 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.