_internalRemoteTransferSendPacket() can’t send the difference back to the user
In the TapiocaOmnichainReceiver contract, when a user requests a remote transfer with an amount larger than the debited amount, the code overwrites the send amount before calculating the difference to refund, so the refund is always zero. The excess tokens remain stuck in the contract instead of being returned to the user.
Submitted by bin2chen, also found by cccz
In TapiocaOmnichainReceiver, when the user executes MSG_REMOTE_TRANSFER, if the srcChain amount request is bigger than the debited one, it overwrites the amount to credit with the amount debited and send the difference back to the user.
lzCompose() -> _remoteTransferReceiver() -> _internalRemoteTransferSendPacket().
function _internalRemoteTransferSendPacket(
address _srcChainSender,
LZSendParam memory _lzSendParam,
bytes memory _composeMsg
) internal returns (MessagingReceipt memory msgReceipt, OFTReceipt memory oftReceipt) {
...
// If the srcChain amount request is bigger than the debited one, overwrite the amount to credit with the amount debited and send the difference back to the user.
if (_lzSendParam.sendParam.amountLD > amountDebitedLD_) {
// Overwrite the amount to credit with the amount debited
@> _lzSendParam.sendParam.amountLD = amountDebitedLD_;
_lzSendParam.sendParam.minAmountLD = amountDebitedLD_;
// Send the difference back to the user
@> _transfer(address(this), _srcChainSender, _lzSendParam.sendParam.amountLD - amountDebitedLD_);
}
The above code, first modify _lzSendParam.sendParam.amountLD = amountDebitedLD_ Then call _transfer(address(this), _srcChainSender, _lzSendParam.sendParam.amountLD - amountDebitedLD_);. This way the difference is always 0.
Correctly transfer() the difference first, and then modify _lzSendParam.sendParam.amountLD.
Impact
The difference token be left in the contract.
Recommended Mitigation
function _internalRemoteTransferSendPacket(
address _srcChainSender,
LZSendParam memory _lzSendParam,
bytes memory _composeMsg
) internal returns (MessagingReceipt memory msgReceipt, OFTReceipt memory oftReceipt) {
...
// If the srcChain amount request is bigger than the debited one, overwrite the amount to credit with the amount debited and send the difference back to the user.
if (_lzSendParam.sendParam.amountLD > amountDebitedLD_) {
+ _transfer(address(this), _srcChainSender, _lzSendParam.sendParam.amountLD - amountDebitedLD_);
// Overwrite the amount to credit with the amount debited
_lzSendParam.sendParam.amountLD = amountDebitedLD_;
_lzSendParam.sendParam.minAmountLD = amountDebitedLD_;
// Send the difference back to the user
- _transfer(address(this), _srcChainSender, _lzSendParam.sendParam.amountLD - amountDebitedLD_);
}
Assessed type
Context
LSDan (judge) decreased severity to Medium
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 updates the send amount to the debited amount before computing the difference for the refund, making the difference always zero.
Impact
The difference tokens are left in the contract, meaning users do not receive their excess funds.
What the attacker needed
User initiates a remote transfer; requested amount exceeds debited amount
The fix
The transfer of the difference should be performed before overwriting the send amount, as shown in the recommended mitigation.
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 you send tokens across chains, sometimes the amount you ask for is more than what was actually taken from you. The contract tries to send the extra back, but it changes the number it uses for the calculation first, so the extra becomes zero. That means your leftover tokens stay stuck in the contract.
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.