Crafted p2p spam can render nodes permanently unable to process L2 blocks
The p2p block validator uses a small LRU cache of 100 block numbers to reject previously seen blocks, but more than 100 valid L2 blocks can be produced per minute. An attacker could replay old blocks to evict the cache and cause a node to reject or discard new blocks, halting its ability to process L2 blocks.
Source: https://github.com/sherlock-audit/2023-01-optimism-judging/issues/177
Found by
usmannk
Summary
The constraints in BuildBlocksValidator are meant to prevent p2p spam from bogging down the network. However they are not sufficient for stopping spam, but are strong enough to render nodes unable to catch up.
Vulnerability Detail
The p2p.BuildBlocksValidator function has several constraints that must be met before a gossiped block is considered valid. If a block is considered valid then it is gossiped to peers and ingested into the current node.
The constraints on a gossiped block block are, in order:
blockmust be <10MBblockmust be compressed as valid snappy datablockmust be signed by the sequencerblockmust be a valid SSZ encoded blockblock.timestamp must within 60 seconds in the past and 5 seconds in the futureblock.BlockHashmust be correctly calculatedblock.BlockNumbermust not be in the set of the previous 100 unique block numbers that reached this step
These constraints are applied here:
https://github.com/sherlock-audit/2023-01-optimism/blob/main/optimism/op-node/p2p/gossip.go#L208
However, it is often the case that there are over 100 valid L2 blocks emitted per minute. For example, the 253 blocks between block 71404110 and 71404363 were emitted within 60 seconds.
In this example, an attacker would take the 200 blocks from 71404110-71404310 and replay them in order to a node for 60 seconds. Every block would be valid because they each pass all constraints and the 100 block LRU cache for marking seen blocks would be evicted twice over during the process.
After 60 seconds, block 71404310 + 1 would be invalid to this node because its timestamp would be too old. At this point, for any new L2 block the node would either:
- mark it as invalid because it is too old
- or ingest it and throw it away because it is waiting for block
71404311
As a result, the node will no longer be able to successfully process any L2 blocks from the p2p network.
Furthermore, because all 200 blocks are marked as valid several times, the node would gossip all of these blocks (potentially several times) to its peers who would suffer the same effect and impact their peers.
Impact
Attackers may halt targeted nodes.
Further knock-on potential halting of the node's peers, peers of peers, and so on.
Code Snippet
Tool used
Manual Review
Recommendation
Increase the size of the blockHeightLRU cache to more effectively catch and reject previously seen nodes. It would be reasonable to set it to 1000 instead of 100. Even at 1000 the cache should occupy less than 500kb in memory.
Discussion
rcstanciu
Comment from Optimism
Description: P2P buffer is too small
Reason: This is a valid attack, wherein the attacker replays blocks and eclipses a node from the P2P network.
Action: Increase buffer size
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
Likely the block deduplication cache is too small (100 entries) relative to the block production rate, allowing an attacker to evict it with replayed valid blocks.
Impact
Attackers may halt targeted nodes, with potential knock-on halting of their peers.
What the attacker needed
Ability to send p2p messages to a node; access to 200 recent valid L2 blocks
The fix
The size of the blockHeightLRU cache should be increased, for example to 1000, to more effectively reject previously seen blocks.
How it was found
- Collect 200 valid L2 blocks that were produced within a 60-second window.
- Replay these blocks in order to a target node over 60 seconds.
- Each block passes all validation constraints and evicts the 100-entry seen-block cache.
- After 60 seconds, new blocks are either too old or cannot be processed because the node is waiting for a missing block.
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 node is a computer that runs the blockchain software and talks to other nodes. The software tries to ignore blocks it has already seen by remembering the last 100 block numbers. If an attacker sends many old but still valid blocks quickly, the node forgets which blocks are new and gets stuck, so it can no longer keep up with the network.
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.