Skip to content
Business logic Audit finding Intermediate

beforeTokenTransfer called with wrong parameters in LBToken._burn

The LBToken._burn function calls the _beforeTokenTransfer hook with the wrong arguments, passing address(0) as the from address and the account as the to address. This could break future extensions that rely on the hook to distinguish mints from burns, potentially causing loss of funds or a bricked system.

Lambda Follow with imare, indijanc and 11 others

Originally disclosed on Code4rena

Submitted by Lambda, also found by imare, indijanc, MiloTruck, zzzitron, chaduke, bctester, Aymen0909, The_GUILD, RustyRabbit, phaze, 0x52, ladboy233, and KingNFT

LBToken.sol#L237

In LBToken._burn, the _beforeTokenTransfer hook is called with from = address(0) and to = _account:

_beforeTokenTransfer(address(0), _account, _id, _amount);

Through a lucky coincidence, it turns out that this in the current setup does not cause a high severity issue. _burn is always called with _account = address(this), which means that LBPair._beforeTokenTransfer is a NOP. However, this wrong call is very dangerous for future extensions or protocol that built on top of the protocol / fork it.

Proof Of Concept

Let’s say the protocol is extended with some logic that needs to track mints / burns. The canonical way to do this would be:

function _beforeTokenTransfer(
        address _from,
        address _to,
        uint256 _id,
        uint256 _amount
    ) internal override(LBToken) {
	if (_from == address(0)) {
		// Mint Logic
	} else if (_to == address(0)) {
		// Burn Logic
	}
}

Such an extension would break, which could lead to loss of funds or a bricked system.

Recommended Mitigation Steps

Call the hook correctly:

_beforeTokenTransfer(_account, address(0), _id, _amount);

0x0Louis (Trader Joe) confirmed

Alex the Entreprenerd (judge) commented:

The warden has shown how, due to a typo / programming mistake, the hook for burning tokens is called with incorrect parameters.

Because of the caller being the pair, this ends up having reduced impact.


The original report as published on Code4rena, by Lambda. 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 a programming mistake where the arguments to _beforeTokenTransfer were swapped in the _burn function.

Impact

In the current setup, the impact is low because _burn is always called with _account = address(this), making the hook a no-op; however, future extensions or forks could break, leading to loss of funds or a bricked system.

What the attacker needed

None for current code; future extension relying on hook

The fix

The hook should be called with the correct arguments: _beforeTokenTransfer(_account, address(0), _id, _amount).

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 hook is a function that gets called automatically before certain actions, like transferring tokens. In this case, when tokens are burned (destroyed), the hook is supposed to be told who is losing tokens and that the recipient is nobody (address zero). But the code accidentally swaps these, telling the hook that the tokens are being created (minted) instead of burned. Right now it doesn't cause harm because the current code ignores the hook, but if someone builds on top of this contract and relies on the hook, it could malfunction.

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 Lambda

View all

64 more disclosed reports, best first.

More from Trader Joe v2 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.