RingDAO is a decentralized community focused on the latest innovations in the cross-chain field within the web3 world. Our mission is to empower existing and future applications to interact seamlessly with multiple blockchain networks.
Darwinia chain, is one of the project from RingDAO, It is a one of the earliest parachains in the Polkadot ecosystem, offering out-of-the-box cross-chain capabilities to exchange messages with other parachains and external Ethereum-compatible chains.
I have already found the similar critical bug on Darwinia project, you could read here:
So, this article will be describing Part-II of the Critical bug in RingDAOās Darwinia contract.
This write-up focuses on vulnerability in the core component of Darwinia which isĀ MsgPortās ORMPUpgradeablePort contract.
https://etherscan.io/address/0x8d22f03a675064BFd7509c87206d33730f33e324#code
TheĀ ORMPUpgradeablePortĀ contract is used to do cross-chain messaging by Dapps to theĀ ORMPĀ contract. The flow:
L1 side:
Dapp --> ORMP_Port::send() --> ORMP::send()
L2 side:
ORMP::recv() --> ORMP_Port::recv() --> Dapp.
ORMP_Port == ORMPUpgradeablePort
The bug relies on theĀ ORMPUpgradeablePort::recv()Ā where a malicious user could craft an arbitrary message and pass it toĀ ORMP::send()Ā by settingĀ ORMPĀ asĀ toDapp
The bug lies in theĀ ORMPUpgradeablePort::recv()Ā function where theĀ toDappĀ which is the destination address is not verified. The malicious user could set theĀ toDappĀ as anĀ ORMPĀ contract and pass any arbitrary message on behalf of any genuine Dapps.
function _recv(bytes32 msgId, uint256 fromChainId, address fromDapp, address toDapp, bytes memory message)
internal
{
(bool success, bytes memory returndata) =
toDapp.call{value: msg.value}(abi.encodePacked(message, msgId, fromChainId, fromDapp));
emit MessageRecv(msgId, success, returndata);
}
As I said before, theĀ
MessagePortĀ can callĀORMPĀ and misuse theĀsend()Ā function to send arbitrary messages on behalf of Dapps.But instead of callingĀ
ORMP::send(), the attacker could craft a message to callĀORMP::setAppConfig().The attacker could set his own config on behalf of Darwinia MessagePort and change the oracle and relayer addresses of MessagePort.
Hence, this issue has another impact on
Attacker ability to set or modify Darwinia Msgport default settings for another UA.If the attacker could modify UA settings, the attacker could set this own address as a relayer and oracle, potentially call any contract byĀ
ORMP:recv()Ā and steal the funds or compromise the UA or MessagePort.
PassingĀ toDappĀ asĀ ORMPĀ contract can lead to arbitrary message passing on Behalf of other dapp/user and possibly cause exploits resulting in the permanent locking, loss, or theft of user funds.
OnĀ ORMPUpgradeablePort::recv()Ā function revert ifĀ toDappĀ is anĀ ORMPĀ contract address.
function recv(address fromDapp, address toDapp, bytes calldata message) {
require(toDapp != ormp, "Not allowed");
}
Usually I write Coded POC for all class of bugs, This one I actually left a theoretical POC, because of rush to submit this report to avoid duplicate status for my report.
On the L1 side: The attacker callsĀ
MessagePort::send()Ā which contains the custom message to callĀORMP::send()Ā on the L2 side.When the custom messages reachĀ
MessagePortĀ on L2. TheĀMessagePort::recv()Ā will callĀORMP::send()Ā with a crafted arbitrary malicious message.The crafted arbitrary message will pose as a genuine message sent by L2Ā
MessagePort. The other encoded parts of this message contain to compromise the genuine Dapps.Then again, the message will reach L1 where theĀ
ORMP::recv() will callĀMessage::recv()` and pass the malicious message to genuine Dapp to compromise Dapp in favour of the attacker.
Thanks for reading my bug write-ups, hope you could learn something.

