Skip to content
Business logic Write-up Intermediate

Beanstalk Logic Error Bug Fix Review

A logic error in Beanstalk's transferTokenFrom function allowed an attacker to steal tokens from any user who had approved the contract, because the allowance check was only performed for internal transfers. The attacker could transfer tokens directly from the victim's account to themselves.

immunefi.com

Published on immunefi.com

On Nov 15th, an anonymous whitehat submitted a critical logic error vulnerability to the Beanstalk protocol via Immunefi, demonstrating a direct theft of assets from the accounts that were approved for the Beanstalk contract. The Beanstalk Immunefi Committee estimated that the vulnerability could have resulted in a…

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 function only checked the allowance for internal transfers, not for external transfers, allowing anyone to move tokens from any user who had approved the contract.

Impact

The vulnerability could have resulted in a loss of up to $3.1 million in funds, but no user funds were lost because the issue was quickly remediated.

What the attacker needed

Victim has approved Beanstalk contract; attacker can call transferTokenFrom

The fix

The vulnerable function was removed and replaced with a new function that always uses internal transfer mode, preventing external transfers without allowance checks.

How it was found

  1. Victim approves the Beanstalk contract to spend their tokens.
  2. Attacker calls transferTokenFrom with EXTERNAL transfer mode, specifying the victim as sender and themselves as recipient.
  3. The function transfers tokens from the victim to the attacker without checking the attacker's allowance.

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.

This is a bug in a smart contract that handles token transfers. When users approve a contract to spend their tokens, they expect only the approved amount to be movable. Here, the contract had a flaw that let anyone move tokens from users who had approved it, without checking if the caller was allowed. So an attacker could take tokens from other users' accounts.

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.