Skip to content
Business logic Audit finding Intermediate

wrong out of range check

The bounds check on a Merkle tree index allowed index zero even though trees are numbered from one. An attacker could only reach the following code with index zero, which the developer says reverts unless a keccak pre-image of zero bytes is known.

danb Follow

Originally disclosed on Code4rena

Submitted by danb

https://github.com/code-423n4/2022-05-factorydao/blob/main/contracts/MerkleIdentity.sol#L124

https://github.com/code-423n4/2022-05-factorydao/blob/main/contracts/MerkleIdentity.sol#L98

Vulnerability details

require(merkleIndex <= numTrees, 'merkleIndex out of range');

This line checks that the index is valid. However, the trees start at index 1, therefore index 0 should fail this check, but it doesn’t.

Recommended Mitigation Steps

change to:

require(merkleIndex <= numTrees && merkleIndex > 0, 'merkleIndex out of range');

illuzen (FactoryDAO) acknowledged, disagreed with severity and commented:

Technically valid, but the next line will revert, unless you think someone has the keccak pre-image of zero bytes and this pre-image is a set of valid arguments to this function…

illuzen (FactoryDAO) resolved:

https://github.com/code-423n4/2022-05-factorydao/pull/4


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

The range check used only an upper bound and omitted a lower bound, so index zero passed validation.

Impact

The flaw is technically valid but likely unexploitable, because the next line reverts unless someone knows the keccak pre-image of zero bytes and it forms valid arguments.

What the attacker needed

Calling the contract function directly

The fix

The check was fixed by also requiring the index to be greater than zero.

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 keeps a list of Merkle trees, which are data structures used to prove membership. The code that checks which tree you are asking about was meant to reject position zero, because counting starts at one, but it let zero through. The developer argued the very next line would stop anyone from doing anything useful with that.

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 by danb

View all

12 more disclosed reports, best first.

More from FactoryDAO contest

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.