Skip to content
DoS Audit finding Beginner

Underflow Revert in remove_item When Removing from an Empty Array

The remove_item subroutine in a smart contract library subtracts one from the array length without first checking whether the array is empty, so the subtraction underflows. An attacker or any caller passing an empty array causes the transaction to abort instead of receiving the promised 'not present' result.

Afriauditor Follow

Originally disclosed on Immunefi

  • Disclosed after under an hour

#49938 [SC-Low] Underflow Revert in `remove_item` When Removing from an Empty Array

Submitted on Jul 20th 2025 at 16:30:46 UTC by @Afriauditor for Audit Comp | Folks Smart Contract Library

Description

Brief/Intro

The remove_item subroutine in UInt64SetLib unconditionally computes last_idx = items.length - 1, which underflows when the array is empty and causes the transaction to revert instead of returning (false, items), leading to unexpected failures or DoS in production.

Vulnerability Details

In the first line of remove_item the code does:

last_idx = items.length - 1

Because there is no check for an empty array before this subtraction, any call to remove_item(x, []) will immediately abort the TEAL execution at that line, bypassing the intended “not present” return path. So the function violates its specification and any upstream contract logic reverts

Impact Details

Because remove_item aborts instead of returning the promised (false, items) when called on an empty array, any contract logic that depends on that return value will itself revert or misbehave breaking workflows

References

Proof of Concept

Proof of Concept

  1. Deploy the UInt64SetLibExposed application so you have an ABI method dynamicRemoveItem that calls remove_item on a box-backed array.
  2. Reset the box to an empty array by invoking its dynamicReset method (or equivalent), ensuring items.length == 0.
  3. Attempt to remove any value (e.g. 123) by calling dynamicRemoveItem({ args: [123], boxReferences: ["uint64_set"] }).
  4. Watch the transaction revert with an underflow or “invalid subtract” error at the very first line of remove_item.
  5. Confirm that no (false, items) return is ever emitted and that the fallback return path is never reached.

The original report as published on Immunefi, by Afriauditor. 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

Likely the function computes the last index as the array length minus one before checking whether the array is empty, so the subtraction underflows on an empty array.

Impact

Any contract logic relying on the promised false return when removing from an empty array will itself revert, which could break workflows or cause a denial of service.

What the attacker needed

Caller can invoke remove_item; array is empty

How it was found

  1. Deploy the exposed library application that calls remove_item on a box-backed array.
  2. Reset the box so the array is empty.
  3. Call the remove method with any value.
  4. Observe the transaction revert at the first line of remove_item.

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 library function is meant to remove a number from a list and politely report back that the number was not there if the list is empty. Instead, it does a subtraction that only works when the list has at least one item, so with an empty list the whole transaction crashes.

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 Afriauditor

View all

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