_lockOnTOB function of MagnetarMintCommonModule will not work due to the missing approved asset for YieldBox before depositing
The _lockOnTOB function deposits singularity tokens into YieldBox without first approving YieldBox to spend them, so the deposit call reverts. This breaks any Magnetar function that calls _lockOnTOB, such as mintBBLendSGLLockTOLP and lockAndParticipate.
KIntern_NA Follow with carrotsmuggler
Originally disclosed on Code4rena
Submitted by KIntern_NA, also found by carrotsmuggler
In MagnetarMintCommonModule, the _lockOnTOB function is used to pull the singularity tokens from the user and lock them into the TapiocaOptionBroker contract.
function _lockOnTOB(
IOptionsLockData memory lockData,
IYieldBox yieldBox_,
uint256 fraction,
bool participate,
address user,
address singularityAddress
) internal returns (uint256 tOLPTokenId) {
tOLPTokenId = 0;
if (lockData.lock) {
if (!cluster.isWhitelisted(0, lockData.target)) {
revert Magnetar_TargetNotWhitelisted(lockData.target);
}
if (lockData.fraction > 0) fraction = lockData.fraction;
// retrieve and deposit SGLAssetId registered in tOLP
(uint256 tOLPSglAssetId,,) =
ITapiocaOptionLiquidityProvision(lockData.target).activeSingularities(singularityAddress);
if (fraction == 0) revert Magnetar_ActionParamsMismatch();
//deposit to YieldBox
_extractTokens(user, singularityAddress, fraction);
yieldBox_.depositAsset(tOLPSglAssetId, address(this), address(this), fraction, 0);
...
}
}
In the above code snippet, _extractTokens is used to pull singularity tokens from the user to this contract. Afterward, it will deposit these tokens into YieldBox to get YieldBox shares and then lock them in the TOB contract. However, it misses approving Singularity tokens before depositing them into YieldBox. YieldBox will attempt to pull tokens from this contract (from == address(this)), so it will revert as YieldBox can’t transfer tokens due to insufficient allowance during yieldBox_.depositAsset().
Impact
The functions of Magnetar which call _lockOnTOB will be broken, including the mintBBLendSGLLockTOLP function of MagnetarMintModule and the lockAndParticipate function of MagnetarMintXChainModule.
Recommended Mitigation Steps
Should approve Singularity tokens before depositing them into YieldBox:
//deposit to YieldBox
_extractTokens(user, singularityAddress, fraction);
singularityAddress.safeApprove(address(yieldBox_), fraction);
yieldBox_.depositAsset(tOLPSglAssetId, address(this), address(this), fraction, 0);
cryptotechmaker (Tapioca) confirmed and commented:
PR here.
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 code calls yieldBox_.depositAsset without first calling safeApprove on the singularity token, so YieldBox cannot transfer the tokens from the contract.
Impact
Functions that call _lockOnTOB, including mintBBLendSGLLockTOLP and lockAndParticipate, will be broken and unusable.
What the attacker needed
None
The fix
The fix is to approve the singularity token for YieldBox before calling depositAsset; the report notes a PR was submitted.
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 take tokens from it, it must first give permission, called an allowance. Here the code forgot to give that permission, so the deposit step fails and the whole function stops 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.