Skip to content
DoS Audit finding Intermediate

Suboptimal Lock Holding During Logging in decrement_transactions_in_flight

A method that decrements an in-flight transaction counter holds a write lock while it writes a log line, so the lock is held longer than needed. An attacker flooding the node with transactions could increase lock contention and slow transaction processing if logging is slow.

savi0ur Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#42940 [BC-Medium] Suboptimal Lock Holding During Logging in `decrement_transactions_in_flight`

Submitted on Mar 29th 2025 at 20:03:42 UTC by @savi0ur for Attackathon | Movement Labs

Description

Bug Description

The decrement_transactions_in_flight method acquires a write lock on self.transactions_in_flight using write().unwrap(), performs a read operation (get_count()), logs information with info!, and then modifies the state with decrement(count). The logging statement i.e., info!, could be a relatively slow operation (due to sending the logs over network or writing it in a file on disk), which is executed while holding the lock, unnecessarily extending the lock's critical section.

Here’s the relevant code block:
https://github.com/immunefi-team/attackathon-movement/blob/a2790c6ac17b7cf02a69aea172c2b38d2be8ce00/protocol-units/execution/maptos/opt-executor/src/executor/mod.rs#L43-L54

Rust
pub fn decrement_transactions_in_flight(&self, count: u64) {
    // unwrap because lock is poisoned
    let mut transactions_in_flight = self.transactions_in_flight.write().unwrap(); //@audit optimization for lock by moving info! after releasing the lock.
    let current = transactions_in_flight.get_count();
    info!(
        target: "movement_timing",
        count,
        current,
        "decrementing_transactions_in_flight",
    );
    transactions_in_flight.decrement(count);
}
  • The RwLock write guard (transactions_in_flight) is held for the entire duration of the method, including during the info! macro execution.
  • Logging operations, especially with tracing::info!, may involve I/O (e.g., writing to a file or network sink), which can be slow compared to the simple counter operations (get_count and decrement).
  • This unnecessarily prolongs the time the lock is held, increasing contention in a concurrent environment where other threads or tasks might need to access transactions_in_flight.

Impact

Holding the write lock longer than necessary prevents other threads or async tasks from reading or writing to transactions_in_flight, potentially causing delays in transaction processing or state updates.

Recommendation

Move the logging operation outside the critical section by releasing the lock before calling info!. This can be achieved by scoping the lock usage to only the operations that require it (get_count and decrement), then logging afterward. Here’s a refactored version:

Rust
pub fn decrement_transactions_in_flight(&self, count: u64) {
    let current = {
        let mut transactions_in_flight = self.transactions_in_flight.write().unwrap();
        let current = transactions_in_flight.get_count();
        transactions_in_flight.decrement(count);
        current // Return current for logging
    }; // write lock release here
    info!(
        target: "movement_timing",
        count,
        current,
        "decrementing_transactions_in_flight",
    );
}

This approach ensures the lock is held for the shortest possible time and adds robustness against poisoned locks.

Proof of Concept

Proof of Concept

The "attack" scenario demonstrates how an attacker could amplify the inefficiency to degrade system performance.

  1. Assume a blockchain node running the Executor processes a high volume of transactions, frequently calling decrement_transactions_in_flight. The system uses a logging configuration that writes to a slow sink (e.g., a file on a busy disk or a remote server).

  2. An attacker floods the system with transactions that trigger frequent calls to decrement_transactions_in_flight. For example, submit numerous small transactions that quickly enter and exit the in-flight state:

    Rust
    for _ in 0..10000 {
        executor.decrement_transactions_in_flight(1);
    }
    
  3. In the original code:

    • Each call locks transactions_in_flight, retrieves current, logs via info! (potentially taking milliseconds if the sink is slow), and then decrements.
    • With 10,000 calls and a slow log operation (e.g., 1ms each), the lock is held for ~10 seconds cumulatively.
    • Other threads or tasks needing to access transactions_in_flight (e.g., to increment or read the count) are blocked during this time.
  4. If the logging sink is very slow (e.g., a remote server with high latency or a contended disk), then:

    • Logging to a network sink with 10ms latency per write.
    • Each info! call takes 10ms, extending the lock duration to ~100 seconds for 10,000 calls.

The original report as published on Immunefi, by savi0ur. 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 write lock on the in-flight counter is held across a logging call that may perform slow I/O, extending the critical section.

Impact

Holding the write lock longer than necessary could delay transaction processing or state updates under load, though the report only describes a potential slowdown rather than a demonstrated outage.

What the attacker needed

Node logging to a slow sink; attacker can flood transactions

The fix

The lock should be scoped to only the counter read and decrement, with the log call moved after the lock is released.

How it was found

  1. Assume a node processes many transactions and logging writes to a slow sink.
  2. Flood the system with transactions that trigger frequent calls to the decrement method.
  3. Each call holds the lock while logging, so other threads are blocked.
  4. With a very slow logging sink, the lock is held for much longer per call.

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 lock is a way for one part of a program to stop others from touching shared data at the same time. Here the code keeps that lock while it writes a log message, which can be slow, so other parts of the program wait longer than necessary. The report suggests writing the log after releasing the lock.

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 savi0ur

View all

18 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.