Skip to content
Business logic Audit finding Intermediate

Incorrect return value of function BaseTapiocaOmnichainEngine._payNative()

The contract's _payNative function returns only the requested native fee instead of the full msg.value, so when multiple LayerZero messages are sent in one transaction the excess native tokens become stuck in the contract. This can leave insufficient native tokens for later messages, preventing functions such as MagnetarBaseModule._lzCustomWithdraw() and TapTokenReceiver._claimTwpTapRewardsReceiver() from executing.

KIntern_NA Follow

Originally disclosed on Code4rena

Submitted by KIntern_NA

According to the function _payNative(_nativeFee) described in the LayerZero codebase, it is designed to return the native fee associated with the message. However, when a contract intends to initiate multiple LayerZero messages within a single transaction, more than just _nativeFee may be required from the sender to execute such messages.

The contract BaseTapiocaOmnichainEngine() facilitates multiple LayerZero messages within the Magnetar contract and the Tap token contract. Therefore, the function _payNativeFee() needs to be overridden to return an amount of native tokens greater than just _nativeFee. However, in the current implementation of the function BaseTapiocaOmnichainEngine._payNative(), it still returns the value of the input _nativeFee.

/**
 * @inheritdoc OAppSender
 * @dev Overwrite to check for < values.
 */
function _payNative(uint256 _nativeFee) internal override returns (uint256 nativeFee) {
    if (msg.value < _nativeFee) revert NotEnoughNative(msg.value);
    return _nativeFee;
}

Impact

As only _nativeFee will be sent along with the cross-chain message, the remaining amount msg.value - _nativeFee will become trapped in the BaseTapiocaOmnichainEngine contract. This amount can be larger than just the fee to execute the transaction since the Magnetar also supports the LzComposeOption, which defines the msg.value used to execute the compose option.

Due to the insufficient native tokens provided for the multiple LayerZero messages, certain functions cannot be executed (e.g., MagnetarBaseModule._lzCustomWithdraw(), TapTokenReceiver._claimTwpTapRewardsReceiver(), …).

Recommended Mitigation Steps

Consider modifying function BaseTapiocaOmnichainEngine._payNative() as follows:

function _payNative(uint256 _nativeFee) internal override returns (uint256 nativeFee) {
    if (msg.value < _nativeFee) revert NotEnoughNative(msg.value);
    return msg.value;
}

Assessed type

Context

LSDan (judge) decreased severity to Medium

0xWeiss (Tapioca) confirmed


The original report as published on Code4rena, by KIntern_NA. 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 override of _payNative returns the input _nativeFee instead of the full msg.value, so the contract does not account for the extra native tokens needed for multiple messages.

Impact

Excess native tokens become trapped in the contract and some functions that send multiple LayerZero messages may fail due to insufficient native tokens.

What the attacker needed

Contract sends multiple LayerZero messages; user sends more native tokens than one fee

The fix

The function should be changed to return msg.value instead of _nativeFee.

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 a contract sends several cross-chain messages in one transaction, it needs to pay a fee for each message. This contract only reports back the fee for the first message, so the extra money sent by the user is not accounted for and gets stuck in the contract. That means later messages may not have enough funds to run.

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 KIntern_NA

View all

21 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.