Skip to content
Business logic Audit finding Intermediate

Incorrect approval mechanism breaks all Magnetar functionality

The Magnetar contract grants standard ERC20 or YieldBox approvals to target contracts, but those contracts now expect permitC approvals. As a result, token transfers initiated by Magnetar fail, breaking most of its functionality.

carrotsmuggler Follow with KIntern_NA

Originally disclosed on Code4rena

Submitted by carrotsmuggler, also found by KIntern_NA

The Magnetar contract hands out approvals to various contracts so that the target contracts can use any tokens held currently by the Magnetar contract.

The issue is that at some point of time, all the target contracts were refactored to use permitC to handle token transfers. However, this change wasn’t reflected in the Magnetar contracts. Thus, instead of handing out permitC approvals, Magnetar hands out normal ERC20 approvals or yieldbox approvals. This essentially breaks the whole system.

There are numerous instances of this in the codebase. Essentially, almost every approval in the Magnetar contract is incorrect. Below are some examples, however the entire codebase needs to be checked for approvals and corrected.

The _depositYBLendSGL function in MagnetarAssetCommonModule.sol contract gives approval to the singularity contract via yieldbox. However, if we check the _addTokens function in the singularity contract below, we see the token transfers actually take place via pearlmit/permitC.

_setApprovalForYieldBox(singularityAddress, yieldBox_);

https://github.com/Tapioca-DAO/Tapioca-bar/blob/9d76b2fc7e2752ca8a816af2d748a0259af5ea42/contracts/markets/singularity/SGLCommon.sol#L165-L177

Since the Magnetar contract does not give permitC approval to the singularity contract, and instead only gives yieldbox approval, the singularity contract is unable to transfer tokens from the Magnetar contract.

Similarly, in the _wrapSglReceipt function, the Magnetar gives approval to the TOFT contract vie ERC20 approval:

IERC20(sgl).approve(tReceiptAddress, fraction);

But if we check the TOFT contract, we see the tokens are transferred via permitC and not with the raw tokens:

https://github.com/Tapioca-DAO/TapiocaZ/blob/57750b7e997e5a1654651af9b413bbd5ea508f59/contracts/tOFT/BaseTOFT.sol#L73

Since the Magnetar contract does not hand out the permitC approvals, most of the token transfers via Magnetar will fail.

Proof of Concept

The issue arises due to the target contracts using permitC, while Magnetar only giving approvals of the token itself or yieldbox. This can be verified by checking the Magnetar contract and the target contracts, as shown above.

Recommended Mitigation Steps

Refactor Magnetar to give approvals via permitC throughout.

cryptotechmaker (Tapioca) confirmed


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

Likely the target contracts were refactored to use permitC for token transfers, but Magnetar was not updated to grant permitC approvals.

Impact

Most token transfers via Magnetar will fail, breaking the whole system.

What the attacker needed

None

The fix

Magnetar should be refactored to give approvals via permitC throughout.

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.

When one contract wants another contract to move its tokens, it must first give an approval. This report says Magnetar gives the wrong kind of approval, so the other contracts cannot move the tokens and many actions stop working.

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.