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_);
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:
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
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.