Skip to content
DoS Audit finding Beginner

Critical UInt64 underflow in set removal causes permanent denial of service

The remove_item subroutine in a smart contract library subtracts one from the set length without checking for an empty set, causing an unsigned integer underflow. An attacker can call remove_item on an empty set, which makes the transaction fail and permanently disables the function.

DSbeX Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#48998 [SC-Low] Critical UInt64 underflow in set removal causes permanent denial of service

Submitted on Jul 10th 2025 at 10:37:24 UTC by @DSbeX for Audit Comp | Folks Smart Contract Library

Description

Brief/Intro

The remove_item subroutine contains a critical vulnerability stemming from unchecked arithmetic on unsigned 64-bit integers. When invoked on an empty set, the line calculating last_idx = items.length - 1 causes an underflow, resulting in a value of 2^64 - 1. This triggers a runtime error in the AVM, permanently disabling the function whenever the set is empty. There is no recovery path once this occurs, and affected functionality cannot be restored without a full contract redeployment.

Vulnerability Details

The remove_item subroutine does not include any safeguards or checks for empty sets, nor does it document the precondition that the set must not be empty before calling this function. This omission increases the risk of accidental misuse by integrators and developers, leading to unexpected permanent denial of service. Proper documentation or built-in validation is essential to prevent this vulnerability from being triggered in practice. The following line is executed unconditionally:

JavaScript
last_idx = items.length - 1  # Unsafe when items is empty
  • When items is empty (length=0), items.length - 1 underflows
  • Algorand AVM treats integer underflows as fatal errors
  • Transaction fails completely

Impact Details

  • Permanent Lockout: Once the set is emptied, the function can no longer be used
  • Requires contract migration to resolve
  • Easy to Trigger: Any user can invoke remove_item on an empty set
  • Callers lose transaction fees for every failed attempt
  • Affects all higher-level functionality relying on dynamic set behavior While no direct loss of funds occurs, the loss of core contract functionality can break integrations.

References

Vulnerable code in the remove_item function: https://github.com/Folks-Finance/algorand-smart-contract-library/blob/7673a43fa5183af736b65f17d1a297fdea672059/contracts/library/UInt64SetLib.py#L33

Proof of Concept

Proof of Concept

  1. Attacker initiates removal call
  • Calls contract function that triggers remove_item(any_value, empty_set)
  1. Contract execution reaches vulnerable code:
JavaScript
last_idx = items.length - 1  # items.length = 0
  1. UInt64 underflow occurs:
  • 0 - 1 calculation attempts to create 2^64 - 1
  • AVM detects invalid UInt64 operation
  1. Transaction fails
  • Entire transaction is reverted
  • AVM throws ERR_OPCODE

The original report as published on Immunefi, by DSbeX. 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 remove_item subroutine lacks a check for an empty set before subtracting one from the set length, leading to an unsigned integer underflow.

Impact

The function becomes permanently unusable once the set is empty, requiring a full contract redeployment to restore functionality, and callers lose transaction fees for each failed attempt.

What the attacker needed

Ability to call the contract function; The set must be empty

The fix

The function should be fixed by adding a check that the set is not empty before performing the subtraction, or by documenting the precondition.

How it was found

  1. Attacker calls a contract function that triggers remove_item with an empty set.
  2. The contract executes the line that calculates last_idx by subtracting one from the set length.
  3. An unsigned integer underflow occurs because the length is zero.
  4. The transaction fails and is reverted with an error.

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 smart contract is a program that runs on a blockchain. This program has a function that removes an item from a list, but it does not check if the list is empty first. If you try to remove an item from an empty list, the program tries to subtract one from zero, which is not allowed for unsigned numbers, so it crashes and the function can never be used again.

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 DSbeX

View all

11 more disclosed reports, best first.

More from Folks Smart Contract Library

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.