Skip to content
Smart contracts Audit finding Advanced

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.

cmichel Follow

Originally disclosed on Code4rena

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:

  1. Transfer 1000 USDC
  2. 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


The original report as published on Code4rena, by cmichel. 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

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

  1. Attacker submits two cross-chain messages: one to transfer 1000 USDC and one to call their attacker-controlled contract.
  2. A node submits the postIncomingMessages transaction, which transfers 1000 USDC and then calls the attacker's contract.
  3. 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.

More by cmichel

View all

196 more disclosed reports, best first.

More from SKALE contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.