Skip to content
Business logic Audit finding Beginner

function tokenByIndex treats last index as invalid

The tokenByIndex function used a strict less-than check against the token limit, so the last token index was rejected as invalid. An attacker could not exploit this directly, but legitimate users querying the final token would receive an error instead of the token data.

Larva Labs Meebits

Originally disclosed on Code4rena

NFT indexes start from 0:

// Don't allow a zero index, start counting at 1
return value.add(1);

So if there are 30 tokens, indexes would be 1-30. However, function tokenByIndex sets such boundaries:

require(index > 0 && index < TOKEN_LIMIT);

This means that the last token (with index 30 in this case) will not be valid.

Recommend using:

require(index > 0 && index <= TOKEN_LIMIT);

dangerousfood (Meebits) commented:

Beebots is indexing by 1

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

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 an off-by-one error in the boundary check: the condition used '<' instead of '<=' for the upper limit.

Impact

The last token index is incorrectly rejected, causing a denial of service for that specific query; no theft or takeover is possible.

What the attacker needed

None

The fix

The boundary check should use '<=' instead of '<' to include the last valid index.

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.

In many NFT contracts, tokens are numbered starting from 1, not 0. The function that looks up a token by its index had an off-by-one mistake: it treated the highest valid number as out of range. This is a logic bug that breaks normal use but does not let someone steal anything.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More from Larva Labs Meebits

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.