Skip to content
DoS Audit finding Advanced

Nimbus: remote DoS via large custody group count metadata update

The peer custody check calls the peer's advertised custody group count three times without caching, so a malicious peer can return a small value twice and then a huge value. That huge value is passed to a loop that tries to collect that many distinct custody groups, causing an effectively endless loop and disabling the node.

quasar Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-09-ethereum-fusaka-upgrade-judging/issues/15

Found by

quasar

Summary

The function checkPeerCustody is a part of PeerDAS protocol implementation.

During execution checkPeerCustody function calls lookupCgcFromPeer several times.

Between these calls there is a window, where faulty peer could send large CGC value in metadata update.

This creates a potential Denial of Service issue, where large CGC values will trigger almost infinite loop in handle_custody_groups function.

Root Cause

Let's look at the code:

NIM

proc checkPeerCustody(rman: RequestManager,
                      peer: Peer):
                      bool =
  # Returns true if the peer custodies atleast
  # ONE of the common custody columns, straight
  # away returns true if the peer is a supernode.
  if rman.supernode:
    # For a supernode, it is always best/optimistic
    # to filter other supernodes, rather than filter
    # too many full nodes that have a subset of the custody
    # columns
    if peer.lookupCgcFromPeer() ==
        rman.network.cfg.NUMBER_OF_CUSTODY_GROUPS.uint64:
      return true

  else:
 1)   if peer.lookupCgcFromPeer() ==
        rman.network.cfg.NUMBER_OF_CUSTODY_GROUPS.uint64:
      return true

 2)   elif peer.lookupCgcFromPeer() ==
        CUSTODY_REQUIREMENT.uint64:

      # Fetch the remote custody count
 3)     let remoteCustodyGroupCount =
        peer.lookupCgcFromPeer()

      # Extract remote peer's nodeID from peerID
      # Fetch custody columns from remote peer
      let
        remoteNodeId = fetchNodeIdFromPeerId(peer)
        remoteCustodyColumns =
          rman.network.cfg.resolve_columns_from_custody_groups(
            remoteNodeId,
            max(rman.network.cfg.SAMPLES_PER_SLOT.uint64,
                remoteCustodyGroupCount))

      for local_column in rman.custody_columns_set:
        if local_column notin remoteCustodyColumns:
          return false

      return true

    else:
      return false

As you can see, there are three consecutive calls to peer.lookupCgcFromPeer() without caching the result.

A faulty peer can exploit this by returning different custody group count values between calls. Assume

Assume the following scenario:

  1. Call on line 1 will return 4, check is false (NUMBER_OF_CUSTODY_GROUPS = 128)

  2. Call on line 2 will return 4, check is true (CUSTODY_REQUIREMENT = 4)

  3. Call on line 3 will return huge value

These large cgc value is passed to handle_custody_groups:

func handle_custody_groups(cfg: RuntimeConfig, node_id: NodeId,
                           custody_group_count: CustodyIndex):
                           HashSet[CustodyIndex] =
  # Decouples the custody group computation from
  # `get_custody_groups`, in order to later use this custody
  # group list across various types of output types

  var
    custody_groups: HashSet[CustodyIndex]
    current_id = node_id

  while custody_groups.lenu64 < custody_group_count:
    var hashed_bytes: array[8, byte]

    let
      current_id_bytes = current_id.toBytesLE()
      hashed_current_id = eth2digest(current_id_bytes)

    hashed_bytes[0..7] = hashed_current_id.data.toOpenArray(0,7)
    let custody_group = bytes_to_uint64(hashed_bytes) mod
      cfg.NUMBER_OF_CUSTODY_GROUPS

    custody_groups.incl custody_group

    inc current_id

  custody_groups

Type of CustodyIndex is uint64, so it is basically an infinite loop.

How metadata update could enable this scenario.

Function lookupCgcFromPeer function reads cgc from either cached metadata or ENR:

NIM

proc lookupCgcFromPeer*(peer: Peer): uint64 =
  # Fetches the custody column count from a remote peer.
  # If the peer advertises their custody column count via the `cgc` ENR field,
  # that value is returned. Otherwise, the default value `CUSTODY_REQUIREMENT`
  # is assumed.

  let metadata = peer.metadata
  if metadata.isOk:
    return metadata.get.custody_group_count

  # Try getting the custody count from ENR if metadata fetch fails.
  debug "Could not get cgc from metadata, trying from ENR",
        peer_id = peer.peerId
  let enrOpt = peer.enr
  if not enrOpt.isNone:
    let enr = enrOpt.get
    let enrFieldOpt = enr.get(enrCustodySubnetCountField, seq[byte])
    if enrFieldOpt.isOk:
      try:
        let cgc = SSZ.decode(enrFieldOpt.get, uint8)
        return cgc.uint64
      except SszError, SerializationError:
        discard  # Ignore decoding errors and fallback to default

  # Return default value if no valid custody subnet count is found.
  return CUSTODY_REQUIREMENT.uint64

The race condition may occur when metadata is updated between calls (via peerPingerHeartbeat):

NIM
proc updatePeerMetadata(node: Eth2Node, peerId: PeerId) {.async.} =
  let newMetadataRes = await node.getMetadata_vx(peer)
  peer.metadata = Opt.some(newMetadata)  

Internal Pre-conditions

None

External Pre-conditions

None

Attack Path

Simple scenario could look like this:

  1. Faulty peer connects with cgc=4 in ENR
  2. Stays in peer pool
  3. When blocks arrives with missing columns, peer gets acquired
  4. If metadata update happens during checkPeerCustody, exploit will succeed

Impact

A faulty peer could trigger infinite loop in handle_custody_groups and disable nimbus node.

PoC

Proof of concept is a simple race condition simulation.

It clearly demonstrates that large cgc value could trigger long loops in handle_custody_groups.

  1. create poc.nim
NIM

import std/[tables, sets, sequtils, times, monotimes, algorithm]

type
  NodeId = uint64
  CustodyIndex = uint64
  ColumnIndex = uint64
  Eth2Digest = array[32, byte]
  
  RuntimeConfig = object
    NUMBER_OF_CUSTODY_GROUPS: uint64
    SAMPLES_PER_SLOT: uint64
  
  Peer = ref object
    callCount: int
    custodyValues: seq[uint64]  
  
  RequestManager = object
    network: Network
    custody_columns_set: HashSet[ColumnIndex]
  
  Network = object
    cfg: RuntimeConfig

const
  CUSTODY_REQUIREMENT: uint64 = 4
  NUMBER_OF_COLUMNS: uint64 = 128

proc fetchNodeIdFromPeerId(peer: Peer): NodeId = 12345

proc bytes_to_uint64(bytes: array[8, byte]): uint64 =
  result = 0
  for i in 0..7:
    result = result or (uint64(bytes[i]) shl (i * 8))

proc eth2digest(data: openArray[byte]): Eth2Digest =
  for i in 0..<32:
    if i < data.len:
      result[i] = data[i]
    else:
      result[i] = 0

proc lookupCgcFromPeer(peer: Peer): uint64 =
  if peer.callCount < peer.custodyValues.len:
    result = peer.custodyValues[peer.callCount]
    inc peer.callCount
    echo "Call ", peer.callCount, ": returning ", result
  else:
    result = CUSTODY_REQUIREMENT

# Original code from peerdas_helpers.nim
iterator compute_columns_for_custody_group(cfg: RuntimeConfig,
                                          custody_group: CustodyIndex):
                                          ColumnIndex =
  let columns_per_group = NUMBER_OF_COLUMNS div cfg.NUMBER_OF_CUSTODY_GROUPS
  for i in 0'u64 ..< columns_per_group:
    yield ColumnIndex(cfg.NUMBER_OF_CUSTODY_GROUPS * i + custody_group)

proc handle_custody_groups(cfg: RuntimeConfig, node_id: NodeId,
                          custody_group_count: CustodyIndex):
                          HashSet[CustodyIndex] =
  var
    custody_groups: HashSet[CustodyIndex]
    current_id = node_id
    iterations = 0

  echo "Starting handle_custody_groups with count: ", custody_group_count
  
  while custody_groups.len.uint64 < custody_group_count:
    var hashed_bytes: array[8, byte]
    
    let
      current_id_bytes = cast[array[8, byte]](current_id)
      hashed_current_id = eth2digest(current_id_bytes)
    
    hashed_bytes[0..7] = hashed_current_id[0..7]
    let custody_group = bytes_to_uint64(hashed_bytes) mod
      cfg.NUMBER_OF_CUSTODY_GROUPS
    
    custody_groups.incl custody_group
    inc current_id
    inc iterations
    
    # Safety check to demonstrate the issue
    if iterations > 10000:
      echo "ERROR: Too many iterations, stop ", iterations
      break
  
  custody_groups

proc get_custody_groups(cfg: RuntimeConfig, node_id: NodeId,
                        custody_group_count: CustodyIndex):
                        seq[CustodyIndex] =
  let custody_groups = handle_custody_groups(cfg, node_id, custody_group_count)
  var groups = custody_groups.toSeq()
  groups.sort()  
  groups

proc resolve_columns_from_custody_groups(cfg: RuntimeConfig, node_id: NodeId,
                                        custody_group_count: CustodyIndex):
                                        HashSet[ColumnIndex] =
  let custody_groups = cfg.get_custody_groups(node_id, custody_group_count)
  var columns: HashSet[ColumnIndex]
  for group in custody_groups:
    for index in compute_columns_for_custody_group(cfg, group):
      columns.incl index
  columns

proc checkPeerCustody(rman: RequestManager, peer: Peer): bool =
  if peer.lookupCgcFromPeer() == rman.network.cfg.NUMBER_OF_CUSTODY_GROUPS:
    return true
  
  elif peer.lookupCgcFromPeer() == CUSTODY_REQUIREMENT.uint64:
    let remoteCustodyGroupCount = peer.lookupCgcFromPeer()
    
    let remoteNodeId = fetchNodeIdFromPeerId(peer)
    let remoteCustodyColumns =
      rman.network.cfg.resolve_columns_from_custody_groups(
        remoteNodeId,
        max(rman.network.cfg.SAMPLES_PER_SLOT.uint64,
            remoteCustodyGroupCount))  
    
    for local_column in rman.custody_columns_set:
      if local_column notin remoteCustodyColumns:
        return false
    
    return true
  else:
    return false

proc runTest() =
  let cfg = RuntimeConfig(
    NUMBER_OF_CUSTODY_GROUPS: 128,
    SAMPLES_PER_SLOT: 8
  )
  
  var rman = RequestManager(
    network: Network(cfg: cfg),
    custody_columns_set: [1.ColumnIndex, 2, 3].toHashSet
  )
  
  echo "\nStarting test"
  var extremePeer = Peer(
    callCount: 0,
    custodyValues: @[4'u64, 4'u64, 25005'u64]
  )
  
  discard checkPeerCustody(rman, extremePeer)
  
when isMainModule:
  runTest()


  1. run it:
$ nim c -r poc.nim
Starting test
Call 1: returning 4
Call 2: returning 4
Call 3: returning 25005
Starting handle_custody_groups with count: 25005
ERROR: Too many iterations, stop 10001

Mitigation

No response

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

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 custody group count is fetched from the peer three separate times without caching, so a peer can change its answer between calls and inject an arbitrarily large count into a loop that iterates until it has collected that many distinct groups.

Impact

A faulty peer could trigger an effectively infinite loop in handle_custody_groups and disable the Nimbus node.

What the attacker needed

Attacker runs a peer node; peer advertises small cgc in ENR; metadata update races the custody check

How it was found

  1. A faulty peer connects advertising a small custody group count in its ENR.
  2. The peer stays in the peer pool until blocks arrive with missing columns and the peer is acquired.
  3. During checkPeerCustody the peer's metadata is updated so the first two lookups return the small value and the third returns a huge value.
  4. The huge value is passed to handle_custody_groups, which loops almost forever trying to collect that many distinct groups.

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 asks a connected peer how many data pieces it stores, and it asks several times in a row instead of remembering the first answer. A malicious peer can answer 'a few' the first two times and then 'a huge number' the last time. The node then tries to build a list of that huge number of pieces, which takes so long it effectively freezes.

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 quasar

View all

3 more disclosed reports, best first.

More from Ethereum Fusaka Upgrade

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.