Skip to content
Business logic Write-up Advanced

Belt Finance Logic Error Bug Fix Review Largest Ever Bounty Payout

A logic error in Belt Finance's strategy contract caused it to undercount its holdings when tokens were sent directly to it, leading to excess shares being minted on deposit. An attacker could exploit this to withdraw more funds than deposited, potentially draining about $60 million.

immunefi.com

Published on immunefi.com

Whitehat Alexander Schlindwein, known for his critical bug reports in Armor and Fei Protocol, reported a critical bug in Belt Finance to Immunefi on August 10, 2021. The attack was a logic error in Belt Finance that caused one of their contracts to think that it had less money than it did, resulting in excess shares…

The author, on immunefi.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

The contract updated the balanceSnapshot variable even when a withdrawal could be satisfied without liquidating the yield-generating asset, effectively double-counting the withdrawal and understating total holdings.

Impact

The attacker could have withdrawn an unfair proportion of the contract's assets, with about $60 million at risk, though the bug was never exploited and has been patched.

What the attacker needed

Ability to interact with the smart contract; some initial capital to deposit and send tokens

The fix

The fix ensures balanceSnapshot is only reduced when funds are actually withdrawn from the yield-generating asset, preventing the double-count.

How it was found

  1. The attacker calls deposit, sending BNB into the strategy token, which forwards to the strategy contract and then to the bank, minting a pro-rata share.
  2. The attacker sends wBNB directly to the strategy contract, causing the check if(_wantAmt > wantLockedInHere()) to fail.
  3. The attacker calls withdraw, triggering the double-count bug so the contract thinks it has less BNB than it actually does.
  4. The attacker calls deposit again, and the strategy token mints too many shares based on the artificially low balance.
  5. The attacker calls earn, which overwrites balanceSnapshot with the correct value from the bank.
  6. The attacker calls withdraw again to claim the BNB represented by all shares, ending up with more money than they started with.

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.

Belt Finance is a yield farming protocol where users deposit tokens and receive shares representing their portion of the pool. A flaw in the smart contract's accounting allowed someone to manipulate the reported balance by sending tokens directly to the contract, causing new deposits to receive too many shares. This meant the attacker could later withdraw more than they put in, taking other users' funds.

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.

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.