MagnetarMintXChainModule will not work as msg type is not allowed
The MagnetarMintXChainModule's cross-chain minting flow fails because the helper contract used to build the LayerZero message only allows a fixed set of message types, and the required MSG_DEPOSIT_LEND_AND_SEND_FOR_LOCK type is not among them. As a result, users cannot mint on one chain and deposit on another as intended.
Originally disclosed on Code4rena
Submitted by rvierdiiev
Users can mint USDO on chain A, then lend this USDO to singularity on chain B and lock singularity tokens to be able to get tap options on chain C.
The first step of this flow is inside MagnetarMintXChainModule.mintBBLendXChainSGL function. This function mints USDO and then initiates LZ message to chain B to process second step using _withdrawToChain function.
When message will be received by USDO on chain B, then receiver will handle compose message and MSG_DEPOSIT_LEND_AND_SEND_FOR_LOCK msg type should be provided to process it correctly. The problem is that USDO will never receive such msg type as it is not allowed.
Let’s check how _withdrawToChain function works on chain A. In order to request compose message it should call _lzCustomWithdraw. This function then creates instance of TapiocaOmnichainEngineHelper contract, which will be used to prepare LZ message.
When TapiocaOmnichainEngineHelper will build compose message it will call _sanitizeMsgType function with msg type that is going to be sent.
function _sanitizeMsgType(uint16 _msgType) internal pure {
if (
// LZ
_msgType == MSG_SEND
// Tapioca msg types
|| _msgType == MSG_APPROVALS || _msgType == MSG_NFT_APPROVALS || _msgType == MSG_PEARLMIT_APPROVAL
|| _msgType == MSG_REMOTE_TRANSFER || _msgType == MSG_YB_APPROVE_ASSET || _msgType == MSG_YB_APPROVE_ALL
|| _msgType == MSG_MARKET_PERMIT
) {
return;
} else if (!_sanitizeMsgTypeExtended(_msgType)) {
revert InvalidMsgType(_msgType);
}
}
As you can see this function allows only some types and other should be handled by _sanitizeMsgTypeExtended function and this function is empty and returns false. It is designed to be extended by other helpers, such as UsdoHelper.
But as _lzCustomWithdraw always creates instance of TapiocaOmnichainEngineHelper it means that some messages will be not allowed and will not work. Thus, whole minting flow that I have described on the beginning won’t work.
Impact
Users can’t mint on one chain and deposit on another.
Tools Used
VsCode
Recommended Mitigation Steps
For different oft token you should use different helper. For example, if message is going to be sent to USDO, then UsdoHelper should be used; if message comes to tOft, then ToftHelper is needed.
Or you can set all approved messaged in TapiocaOmnichainEngineHelper instead, then you can leave current design of MagnetarBaseModule.
Assessed type
Error
cryptotechmaker (Tapioca) disputed and commented:
Invalid. The following extends the default behavior, see here.
rvierdiiev (warden) commented:
Sponsor said that issue is invalid, because
TapiocaOmnichainReceiverhas_toeComposeReceiverfunction to handle this. This is incorrect.
TapiocaOmnichainReceiver.solis the contract that is responsible for receiving message on another chain. But in this issue I have described the fact that initiating of request on source chain will fail, so destination chain andTapiocaOmnichainReceiverwill not even receive it, because the source chain will not allow to send such message.I ask the judge and sponsor to go through the issue one more time with the whole message flow that I have described to see, that call will not be executed.
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
Impact
Users cannot mint on one chain and deposit on another; the cross-chain flow reverts on the source chain.
What the attacker needed
User initiates cross-chain mint and deposit
The fix
The report recommends using a different helper for each OFT token (e.g., UsdoHelper for USDO) or adding all approved message types to TapiocaOmnichainEngineHelper.
How it was found
- User calls MagnetarMintXChainModule.mintBBLendXChainSGL to mint USDO on chain A.
- The function calls _withdrawToChain, which calls _lzCustomWithdraw.
- _lzCustomWithdraw creates an instance of TapiocaOmnichainEngineHelper.
- The helper builds the compose message and calls _sanitizeMsgType with the message type.
- _sanitizeMsgType rejects the message type because it is not in the allowed list and _sanitizeMsgTypeExtended returns false.
- The transaction reverts, so the cross-chain mint and deposit flow cannot proceed.
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 bug in a cross-chain system. A user tries to mint a token on one blockchain and then use it on another, but the code that prepares the message to the second chain rejects the message type needed for the second step. So the whole process stops before it even starts.
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.