Attacker can freeze chain and steal challenge deposits using fake `prevStateRoot`
A sequencer could commit a batch with a fake previous state root that passes validation only at finalisation, allowing them to win challenges against honest challengers and steal deposits, and to halt the chain because the batch cannot be finalised.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-08-morphl2-judging/issues/84
Found by
PapaPitufo
Summary
Because the prevStateRoot is not validated until a batch is finalized, a committed batch with a malicious prevStateRoot can be used to both (a) win challenges against honest challengers and (b) halt the chain since it will be approved but be unable to be finalized.
Root Cause
In Rollup.sol, if a malicious batch is proposed, the assumption is that the sequencer who proposed it will lose the challenge, get slashed, and the chain will be reset. These economic incentives prevent the chain from being regularly halted.
This is based on the assumption that a sequencer can only win challenges if the batch they proposed is valid.
However, the check that prevStateRoot is actually the postStateRoot of the previous batch only happens in finalizeBatch(). This check is sufficient to prevent batches with fake prevStateRoots from being finalized, but it does not stop these batches from being committed.
This allows a malicious sequencer to propose any batch that performs a valid state transaction on a fake prevStateRoot.
In most cases, a challenger will attack this invalid batch. However, it is possible for the sequencer to provide a valid proof of this state transition to steal the honest challenger's deposit and win the challenge.
In the case that this happens, or that no challenge is performed, the committed batch will not be able to finalized due to the following check:
require(
finalizedStateRoots[_batchIndex - 1] == BatchHeaderCodecV0.getPrevStateHash(memPtr),
"incorrect previous state root"
);
This will freeze the chain and not allow any new batches to be finalized, since batches are committed sequentially and must be finalized sequentially.
Internal Preconditions
None
External Preconditions
None
Attack Path
- Attacker proposes a batch that contains a valid state transition from a fake
prevStateRoot. - If an honest challenger challenges the batch, the attacker provides a valid proof of the state transition to win the challenge and steal the challenger's deposit.
- Whether or not the above happens, the chain is now halted, as the attacker's batch cannot be finalized, and no other batches can be finalized without it being finalized first.
- The attacker will not be slashed, due to the fact that they won the challenge.
Impact
- An honest challenge will lose their deposit when a dishonest sequencer beats them in a challenge.
- No new batches will be able to be finalized, so the chain will halt and have to be manually rolled back by the admins.
PoC
N/A
Mitigation
Check in commitBatch() that prevStateRoot is equal to the parentBatchHeader.postStateRoot.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/morph-l2/morph/pull/616
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 check that `prevStateRoot` matches the previous batch's `postStateRoot` is only performed in `finalizeBatch()`, not in `commitBatch()`, allowing invalid batches to be committed.
Impact
An honest challenger could lose their deposit, and the chain could halt and require manual rollback by admins.
What the attacker needed
Attacker is a sequencer
The fix
The issue was fixed by checking in `commitBatch()` that `prevStateRoot` equals the parent batch header's `postStateRoot`.
How it was found
- Attacker proposes a batch that contains a valid state transition from a fake `prevStateRoot`.
- If an honest challenger challenges the batch, the attacker provides a valid proof of the state transition to win the challenge and steal the challenger's deposit.
- Whether or not the above happens, the chain is now halted, as the attacker's batch cannot be finalised, and no other batches can be finalised without it being finalised first.
- The attacker will not be slashed, due to the fact that they won the challenge.
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 sequencer is the computer that puts transactions in order and proposes batches. The previous state root is like a fingerprint of the chain's state before the batch. The contract only checked this fingerprint when finalising the batch, not when accepting it, so a bad batch could be accepted and then block everything.
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.