Malicious sequencer can DoS proposal execution by inflating the amount of proposals to be pruned
A malicious sequencer can create many proposals without limit, inflating the proposal ID counter. When a later proposal is executed, the pruning loop iterates over all previous proposals and runs out of gas, preventing any proposal execution.
HaxSecurity Follow with underdog
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2024-08-morphl2-judging/issues/186
Found by
HaxSecurity, underdog
Summary
A malicious sequencer can inflate the amount of proposals in Gov.sol in order to force the previous proposals invalidation process in _executeProposal() to run out of gas, making it impossible to execute proposals.
Root Cause
Found in Gov.sol#L257-L260.
The Gov.sol contract incorporates a “proposal pruning process”. Every time a proposal is executed, all the previous proposals since undeletedProposalStart will be pruned (even if they are executed or not). This is done in order to avoid a situation where older proposals get executed, overriding the governance values of newly executed proposals.
As shown in the following code snippet, the “pruning process” works by iterating all proposals since the latest undeletedProposalStart, and until the current proposal ID. It is also worth noting that undeletedProposalStart is only updated when executing a proposal, and is set to the ID of the proposal being executed so that next proposal executions don’t need to prune from the first proposal ID:
// Gov.sol
function _executeProposal(uint256 proposalID) internal {
...
// when a proposal is passed, the previous proposals will be invalidated and deleted
for (uint256 i = undeletedProposalStart; i < proposalID; i++) {
delete proposalData[i];
delete proposalInfos[i];
delete votes[i];
}
undeletedProposalStart = proposalID;
...
}
However, this iteration can lead to an out-of-gas error, as a malicious sequencer can inflate the amount of proposal ID’s due to the lack of limits in proposal creations:
// Gov.sol
function createProposal(ProposalData calldata proposal) external onlySequencer returns (uint256) {
require(proposal.rollupEpoch != 0, "invalid rollup epoch");
require(proposal.maxChunks > 0, "invalid max chunks");
require(
proposal.batchBlockInterval != 0 || proposal.batchMaxBytes != 0 || proposal.batchTimeout != 0,
"invalid batch params"
);
currentProposalID++;
proposalData[currentProposalID] = proposal;
proposalInfos[currentProposalID] = ProposalInfo(block.timestamp + votingDuration, false);
emit ProposalCreated(
currentProposalID,
_msgSender(),
proposal.batchBlockInterval,
proposal.batchMaxBytes,
proposal.batchTimeout,
proposal.maxChunks,
proposal.rollupEpoch
);
return (currentProposalID);
}
As shown in the snippet, any sequencer can create a proposal, and there’s no limit to proposal creation, allowing the proposal inflation scenario to occur.
Internal pre-conditions
- A staker in Morph needs to be a sequencer in the sequencer set (achieved by obtaining delegations, or by simply being added as a staker in the
L2Stakingcontract if rewards have not started) - The sequencer needs to call
createProposal()several times so the amount of proposals created is inflated, and thecurrentProposalIDtracker becomes a number big enough to DoS proposal pruning
External pre-conditions
None.
Attack Path
- A staker stakes in
L1Staking. A cross-layer message is sent from L1 to L2, and the staker is registered to theL2Stakingcontract as a staker. - If rewards have not started and the sequencer set is not filled, the staker will be directly added to the sequencer set, becoming a sequencer. Otherwise, the staker needs to have some MORPH tokens delegated so that he can become a sequencer.
- After becoming a sequencer,
createProposal()is called several times to inflate the amount of proposal ID’s. The sequencer can set unreasonable values so that voting and executing any of the proposals leads the system to behave dangerously, making it disappealing for sequencers to vote for any of the proposals and avoid the OOG issue by executing certain proposals. - Because
currentProposalIDhas been inflated, any proposal created after the inflation will try to prune all the previous fake proposals, leading to a DoS and runnning out of gas. This will effectively DoS proposal creation.
Impact
Sequencers won’t be able to execute proposals in the governance contract, making it impossible to update global network parameters used by Morph.
PoC
No response
Mitigation
Implement a cooldown period between proposal creations. This will prevent creating a huge amount of proposals, as the attacker will need to wait for the cooldown period to finish in order to create another proposal. If the owner identifies suspicious behavior, he can then remove him in the L1 staking contract, and effectively removing the attacker as sequencer in the L2.
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/morph-l2/morph/pull/603
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 proposal pruning loop iterates over all proposals since the last executed one, and proposal creation has no limit, so a sequencer can inflate the counter and cause out-of-gas.
Impact
Sequencers cannot execute proposals, so global network parameters cannot be updated.
What the attacker needed
Be a sequencer (via staking or delegation)
The fix
The protocol team fixed this issue by implementing a cooldown period between proposal creations.
How it was found
- A staker stakes in L1Staking and is registered as a staker in L2Staking.
- The staker becomes a sequencer by being added directly or by obtaining delegations.
- The sequencer calls createProposal() many times to inflate the proposal ID counter.
- Any later proposal execution tries to prune all previous proposals and runs out of gas, causing a denial of service.
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 a special node that can create governance proposals. The contract deletes old proposals one by one when a new one is executed. If a bad sequencer creates a huge number of proposals, the deletion loop becomes too long and runs out of gas, so no proposal can be executed.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.