Skip to content
Smart contracts Audit finding Beginner

No items length check in remove_item leads to a revert with an underflow

The remove_item function in a smart contract library does not check whether the items array is empty before subtracting one from its length. Calling it with an empty array causes an underflow panic and reverts the transaction.

j3x Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#48885 [SC-Low] No items length check in remove_item leads to a revert with an underflow

Submitted on Jul 8th 2025 at 18:32:15 UTC by @j3x for Audit Comp | Folks Smart Contract Library

Description

Brief/Intro

No items length check in remove_item leads to a revert with an underflow.

Vulnerability Details

In UInt64SetLib::remove_item(), the items array length is not verified to be a non-zero value, and the function will directly proceed to subtract from it:

Python
def remove_item(to_remove: UInt64, items: DynamicArray[ARC4UInt64]) -> Tuple[Bool, DynamicArray[ARC4UInt64]]:
    last_idx = items.length - 1
...

If the items array is empty, this will lead to a subtration from a 0 uint64, which causes a panic.

Impact Details

Contradicts with the system's best design, as it proceeds to directly subtracts from a length of 0, causing a revert with an underflow.

References

https://github.com/Folks-Finance/algorand-smart-contract-library/blob/main/contracts/library/UInt64SetLib.py#L32C1-L33C32

Proof of Concept

Proof of Concept

  • The function remove_item() is called with an empty items array.
  • This will lead to an underflow, causing a panic, which reverts the transaction

Mitigation

add the following lines before subtracting:

Python
    if items.length == 0:
        return Bool(False), items.copy()

This will return peacefully in case on an empty set.

The original report as published on Immunefi, by j3x. 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 subtracts one from the array length without first checking that the array is non-empty.

Impact

The transaction reverts with an underflow, which contradicts the system's best design; the text does not claim any loss of funds or other damage.

What the attacker needed

None

The fix

The function should check whether the array length is zero and return early before subtracting.

How it was found

  1. Call remove_item with an empty items array.
  2. The function subtracts one from the zero length, causing an underflow panic that reverts the transaction.

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 function tries to remove an item from a list. It first calculates the last position by subtracting one from the list's length. If the list is empty, that subtraction goes below zero, which the system cannot handle, so the whole transaction fails and is undone.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by j3x

View all

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

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.