← All Posts | findings | February 24, 2024

Tapioca – Unverified _srcChainSender parameter allows to impersonate the sender

Paweł Kuryłowicz

Paweł Kuryłowicz

Managing Partner & Smart Contract Security Auditor

The function executes modules depending on the _msgType parameter and some of them do not accept the _srcChainSender parameter.

Vulnerability Details

The _toeComposeReceiver function is called by the LayerZero endpoint (indirectly) when there is a compose message to be executed. It gets three parameters.

The first parameter (_msgType) represents the type of message that should be executed on the destination chain. The second (_srcChainSender) is the sender of the message on the source chain and last one (_toeComposeMsg) contains the parameters for the executed operation.

In case of MSG_TAP_EXERCISE the _srcChainSender parameter is forwarded to the UsdoOptionReceiver module.

In case of other types (MSG_MARKET_REMOVE_ASSETMSG_YB_SEND_SGL_LEND_OR_REPAY and MSG_DEPOSIT_LEND_AND_SEND_FOR_LOCK) the _srcChainSender parameter is not forwarder and the attacker fully control the contents of _toeComposeMsg.

Let’s take the MSG_MARKET_REMOVE_ASSET message as an example.

  1. The removeAssetReceiver function from UsdoMarketReceiverModule is executed with _toeComposeMsg parameter.
  2. The _toeComposeMsg bytes (called _data in this function) are decoded and some values are extracted. The most important are:
  • msg_.externalData.magnetar on which the burst function is later called with specific magnetar calls (it is legitimate and whitelisted magnetar),
  • msg_.user on whose behalf the further operation is called,
  • msg_.externalData which is forwarder to further call,
  • msg_.removeAndRepayData which is forwarder to further call.

Those parameters are used to prepare a call to exitPositionAndRemoveCollateral function from OptionModule module (defined in action’s id param).

  1. Next, the burst function from magnetar contract is called and it executes the specific module depending on the _action.id:
  1. The modules validates the sender passing the user address as the parameter.
  1. The _checkSender function does not revert if the user is the sender or the sender is whitelisted.
  1. In this case the sender is USDO contract which is whitelisted. This allows to continue operations from exitPositionAndRemoveCollateral function on behalf of the user (who is the victim).

Note: This is only one of possible attack scenarios that exploits lack of _srcChainSender parameter validation.

Impact

HIGH – The attacker can execute functions from UsdoMarketReceiverModule module on behalf of any user.

Recommendation

Validate whether the user whose assets are being managed is the same address as the _srcChainSender parameter.

References

Join the newsletter now

Please wait...

Thank you for sign up!