Reentrancy in MessageProxyForSchain leads to replay attacks
The postIncomingMessages function calls an attacker-controlled contract before updating the incoming message counter, allowing re-entrancy. An attacker could replay the same cross-chain messages to receive funds multiple times.
Submitted by cmichel
The postIncomingMessages function calls _callReceiverContract(fromChainHash, messages[i], startingCounter + 1) which gives control to a contract that is potentially attacker controlled before updating the incomingMessageCounter.
for (uint256 i = 0; i < messages.length; i++) {
// @audit re-entrant, can submit same postIncomingMessages again
_callReceiverContract(fromChainHash, messages[i], startingCounter + 1);
}
connectedChains[fromChainHash].incomingMessageCounter += messages.length;
The attacker can re-enter into the postIncomingMessages function and submit the same messages again, creating a replay attack. Note that the startingCounter is the way how messages are prevented from replay attacks here, there are no further nonces.
Proof of Concept
Attacker can submit two cross-chain messages to be executed:
- Transfer 1000 USDC
- A call to their attacker-controlled contract, could be masked as a token contract that allows re-entrance on
transfer.
Some node submits the postIncomingMessages(params) transaction, transfers 1000 USDC, then calls the attackers contract, who can themself call postIncomingMessages(params) again, receive 1000 USDC a second time, and stop the recursion.
Recommended Mitigation Steps
Add a messageInProgressLocker modifier to postIncomingMessages as was done in MessageProxyForMainnet.
cstrangedk (SKALE) resolved:
Resolved via https://github.com/skalenetwork/IMA/pull/1054
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 contract updates the incoming message counter only after calling an external contract, so the external call can re-enter before the counter changes.
Impact
An attacker could replay the same cross-chain messages to receive funds multiple times.
What the attacker needed
Attacker can submit cross-chain messages; attacker controls a contract called during message…
The fix
The issue was fixed by adding a messageInProgressLocker modifier to postIncomingMessages, as was already done in MessageProxyForMainnet.
How it was found
- Attacker submits two cross-chain messages: one to transfer 1000 USDC and one to call their attacker-controlled contract.
- A node submits the postIncomingMessages transaction, which transfers 1000 USDC and then calls the attacker's contract.
- The attacker's contract calls postIncomingMessages again with the same messages, receiving another 1000 USDC, then stops the recursion.
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.
A smart contract processes messages from another blockchain. It calls a contract controlled by the attacker before it records that the message has been handled. The attacker's contract can call back into the same function and make it process the same message again, like getting paid twice for one job.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.