Skip to content
DoS Audit finding Intermediate

The mempool garbage collector doesn't fully execute garbage collection on each iteration

The mempool garbage collector function removes only one expired transaction per invocation instead of all stale entries, causing excessive I/O and database bloat. An attacker could exploit this by flooding the mempool with many expired transactions, forcing repeated scans and disk writes.

jovi Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

#41243 [BC-Insight] The mempool garbage collector doesn't fully execute garbage collection on each iteration

Submitted on Mar 12th 2025 at 21:32:25 UTC by @jovi for Attackathon | Movement Labs

Description

Summary

A logic flaw in gc_mempool_transactions causes it to remove only one expired transaction each time it’s invoked. Although multiple invocations (or a loop) will eventually clear all stale entries, it leads to excessive I/O overhead, unnecessary looping, and potential database bloat.

Vulnerability Details

Location

  • File: protocol-units/mempool/move-rocks/src/lib.rs
  • Function: gc_mempool_transactions
  • Caller: gc() (in sequencing/memseq/sequencer/src/lib.rs)

Description

  • The gc_mempool_transactions function stops after removing the first qualifying transaction. It never continues iterating over all stale transactions within the same invocation.
  • The gc() caller function (see snippet below) implies it expects multiple transactions to be pruned in one pass—logging the total removed each cycle — yet, due to the single-item removal logic, each call to gc_mempool_transactions can only return gc_count == 1 when there are still many stale entries.

gc() Caller Snippet

Rust
async fn gc(&self) -> Result<(), anyhow::Error> {
    let gc_interval = self.building_time_ms * 2 / 1000 + 1;
    let timestamp_threshold = SystemTime::now()
        .duration_since(UNIX_EPOCH)
        .unwrap()
        .as_secs()
        .saturating_sub(gc_interval);

    // Attempt to prune transactions older than 'timestamp_threshold'
    let gc_count = self.mempool.gc_mempool_transactions(timestamp_threshold).await?;

    if gc_count != 0 {
        // The log implies multiple pruned transactions could be reported
        info!("pruned {gc_count} transactions");
    } else {
        debug!("no transactions to prune");
    }

    // Sleep until the next GC cycle
    tokio::time::sleep(Duration::from_secs(gc_interval)).await;
    Ok(())
}

Because gc_mempool_transactions removes only one transaction per call, the above function either logs 1 transaction removed or none—even though the developer apparently expected that a single call might remove many stale entries.

Impact

  1. Resource Inefficiency: Potentially thousands of extra calls (and disk writes) if the mempool has many expired transactions.
  2. Performance Degradation: Repeatedly scanning the mempool in separate passes prolongs garbage collection and can bloat disk usage.
  3. Operational Confusion: Log messages (e.g. “pruned 1 transaction” repeatedly) may not reflect the intended behavior of removing all expired transactions in one pass.

Recommended Fix

In gc_mempool_transactions, change the single if let Some(...) block to a loop:

Rust
while let Some(res) = iter.next() {
    let (key, value) = res?;
    let transaction: MempoolTransaction = bcs::from_bytes(&value)?;
    batch.delete_cf(&cf_handle, &key);
    batch.delete_cf(&lookups_cf_handle, transaction.transaction.id().to_vec());
    transaction_count += 1;
}

This ensures all transactions below the threshold are pruned in one invocation, aligning with the gc() function’s expectation that multiple transactions might be removed together.

Proof of Concept

Override the test_rocksdb_gc test at RocksdbMempool implementation in protocol-units/mempool/move-rocks/src/lib.rs:

Rust
async fn test_rocksdb_gc() -> Result<(), Error> {
    let temp_dir = tempdir()?;
    let path = temp_dir.path().to_str().unwrap();
    let mempool = RocksdbMempool::try_new(path)?;

    let transaction1 = MempoolTransaction::at_time(Transaction::new(vec![1], 0, 0), 2);
    let transaction1_id = transaction1.transaction.id();
    mempool.add_mempool_transaction(transaction1).await?;
    assert!(mempool.has_mempool_transaction(transaction1_id).await?);

    sleep(Duration::from_secs(1)).await;

    let transaction2 = MempoolTransaction::at_time(Transaction::new(vec![2], 0, 0), 3);
    let transaction2_id = transaction2.transaction.id();
    let transaction2_ts = transaction2.timestamp;
    mempool.add_mempool_transaction(transaction2).await?;

    // Wait again so transaction1 is definitely < threshold
    sleep(Duration::from_secs(1)).await;

    // GC call #1
    mempool.gc_mempool_transactions(transaction2_ts + 1).await?;
    assert!(!mempool.has_mempool_transaction(transaction1_id).await?);
    assert!(mempool.has_mempool_transaction(transaction2_id).await?);

    // GC call #2
    mempool.gc_mempool_transactions(transaction2_ts + 1).await?;
    assert!(!mempool.has_mempool_transaction(transaction2_id).await?);

    Ok(())
}

This confirms that one transaction is pruned each time—contrary to the usual expectation of removing all stale transactions in a single pass.


The original report as published on Immunefi, by jovi. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

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 function uses a single `if let Some(...)` block instead of a loop, so it stops after deleting the first matching entry.

Impact

Potentially thousands of extra calls and disk writes if the mempool has many expired transactions, prolonging garbage collection and bloating disk usage.

What the attacker needed

Ability to add transactions to the mempool

The fix

The function should be changed to loop over all entries below the threshold and delete them in one invocation.

How it was found

  1. Add a transaction to the mempool with a timestamp.
  2. Wait so the transaction becomes older than a threshold.
  3. Add a second transaction with a later timestamp.
  4. Call the garbage collector with a threshold that should remove both.
  5. Observe that only the first transaction is removed; a second call is needed to remove the second.

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 mempool is a waiting area for transactions before they are processed. The garbage collector is supposed to clean out old, expired transactions, but it only removes one per run instead of all of them. This means if many old transactions pile up, the system has to run the cleanup many times, wasting resources.

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.

More by jovi

View all

25 more disclosed reports, best first.

More from Movement Labs

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.