Skip to content
Business logic Audit finding Intermediate

Magnetar’s mintBBLendSGLLockTOLP reverts when lock is set to false

The mintBBLendSGLLockTOLP function in Magnetar is meant to allow skipping the lock step, but if the user sets lock to false while still requesting participation, the function reverts because it tries to approve an NFT that is still held by the user rather than the contract. An attacker could not exploit this directly; it is a functional bug that prevents legitimate use of the modular option.

carrotsmuggler Follow with KIntern_NA

Originally disclosed on Code4rena

Submitted by carrotsmuggler, also found by KIntern_NA

The mintBBLendSGLLockTOLP function in Magnetar is designed to mint USDO tokens from bigbang, deposit them to singularity, lock the liquidity in the TOLP contract and then participate in the TOB contract.

The function is designed to be modular, so the user can choose to skip any of the steps and still have the other execute. The issue is that if the user decides not lock in the TOLP contract, the function will revert since it is pulling tokens from the wrong address.

After the market operations, the function does two operations for locking, as shown below:

uint256 tOLPTokenId = _lockOnTOB(
    data.lockData,
    yieldBox_,
    fraction,
    data.participateData.participate,
    data.user,
    data.externalContracts.singularity
);

if (data.participateData.participate) {
    _participateOnTOLP(data.participateData, data.user, data.lockData.target, tOLPTokenId);
}

In the _lockOnTOB function, there is a check which allows the user to skip this step based on their input:

if (lockData.lock) {
    //...
}

However, if this step is skipped, then the TOLP NFT position will still be with the user; thus, needs to be pulled from the user for the participate step. But in the participate step, we see that the code expects the token to be with the Magnetar contract already.

IERC721(lockDataTarget).approve(participateData.target, tOLPTokenId);
uint256 oTAPTokenId = ITapiocaOptionBroker(participateData.target).participate(tOLPTokenId);

address oTapAddress = ITapiocaOptionBroker(participateData.target).oTAP();
IERC721(oTapAddress).safeTransferFrom(address(this), user, oTAPTokenId, "0x");

This would only be true if the previous step’s lock function had run. This is because when locking the tokens, the Magnetar contract receives the NFT position if participate function is set to be run. If the lock function is skipped, the participate function will revert since the NFT position is still with the user.

Proof of Concept

During the lock function call, we see that the Magnetar contract tries to credit itself the NFT tokens.

tOLPTokenId = ITapiocaOptionLiquidityProvision(lockData.target).lock(
    participate ? address(this) : user, singularityAddress, lockData.lockDuration, lockData.amount
);

However, if the lock functionality is skipped, then the Magnetar contract will not own the tokens since this step will not be run. Users will be forced to raw send the NFT position to the magnetar contract which is unsafe since the Magnetar contract is not designed to hold tokens.

Recommended Mitigation Steps

If lockData.lock was true, the _participateOnTOLP function should pull the NFT positions from the user to the Magnetsar contract.

cryptotechmaker (Tapioca) confirmed and commented:

PR here.


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

The participation step assumes the contract already owns the TOLP NFT, which is only true when the lock step ran and transferred it to the contract.

Impact

The function reverts for users who skip locking but still want to participate, blocking a supported modular path; no direct loss of funds is claimed.

What the attacker needed

User calls mintBBLendSGLLockTOLP; lockData.lock set to false; participateData.participate set to true

The fix

The participation function should pull the NFT from the user when the lock step was skipped, rather than assuming the contract already holds it.

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.

This is a smart contract function that lets a user mint tokens, lock them, and then join a participation scheme. The code is supposed to let the user skip the locking step, but if they do, the later participation step still assumes the contract already holds the locked NFT, so it fails. The result is that a valid combination of options simply does not work.

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 carrotsmuggler

View all

42 more disclosed reports, best first.

More from Tapioca Invitational

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.