Skip to content
Business logic Audit finding Intermediate

isResolverCached() will always return false after removing operator

Removing an operator from the NestedFactory contract deletes its value in the operators array but leaves a zero entry, causing the cache to become permanently out of sync. As a result, isResolverCached() always returns false, and any function requiring a synced cache becomes uncallable.

GreyArt Follow

Originally disclosed on Code4rena

Submitted by GreyArt, also found by WatchPug

Impact

While there is no loss of funds, removing an operator will cause the cache functionality to be permanently broken. If there was a function that had a modifier which requires the cache to be synced before the function can be called, it would not be callable as well.

The underlying issue is how the bytes32 operator is removed from the array when removeOperator() is called. Its value gets deleted (set to 0x0), but isn’t taken out of the array.

Proof of Concept

For ease of reading, we use abbreviated strings like 0xA, 0xB for bytes32 and address types.

  1. Import 3 operators by calling OperatorResolver.importOperators([0xA, 0xB, 0xC], [0x1, 0x2, 0x3).
  2. Call NestedFactory.addOperator() 3 times to push these 3 operators into the operators state variable.
  3. Call NestedFactory.rebuildCache() to build the cache.
  4. Let’s say the second operator 0xB is to be removed. Taking reference from the removeOperator.ts script, OperatorResolver.importOperators([0xA, 0xB, 0xC], [0x1, 0x2, 0x3) is called first. This works because OperatorResolver uses a mapping(bytes32 ⇒ address) to represent the operators. Hence, by setting 0xB’s destination address to be the null address, it is like as if he was never an operator.
  5. Call NestedFactory.rebuildCache() to rebuild the cache. resolverAddressesRequired() will return [0xA, 0xB, 0xC]. 0xB will be removed from addressCache because resolver.getAddress(0xB) returns 0x000 since it has been deleted from the OperatorResolver.
  6. Call NestedFactory.removeOperator(0xB). The operators array now looks like this: [0xA, 0x0, 0xC].
  7. When you try to call NestedFactory.isResolverCached, it will always return false because of the null bytes32 value, where addressCache[0x0] will always return the null address.

Recommended Mitigation Steps

Instead of doing an element deletion, it should be replaced with the last element, then have the last element popped in removeOperator().

function removeOperator(bytes32 operator) external override onlyOwner {
	for (uint256 i = 0; i < operators.length; i++) {
		if (operators[i] == operator) {
			operators[i] = operators[operators.length - 1];
			operators.pop();
			break;
		}
	}
}

maximebrugel (Nested) commented:

Duplicated : #58

alcueca (judge) commented:

Taking this issue apart as a non-duplicate, for finding the most severe consequence of the incorrect implementation.

The original report as published on Code4rena, by GreyArt. 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 removeOperator function deletes the operator's value in the array (setting it to zero) instead of removing the element, leaving a zero entry that breaks cache validation.

Impact

The cache functionality is permanently broken, and any function that requires the cache to be synced becomes uncallable; there is no loss of funds.

What the attacker needed

Owner role to call removeOperator

The fix

The removeOperator function should replace the removed element with the last element and then pop the last element, instead of deleting the value.

How it was found

  1. Import three operators via OperatorResolver.importOperators.
  2. Call NestedFactory.addOperator three times to add them to the operators array.
  3. Call NestedFactory.rebuildCache to build the cache.
  4. Remove the second operator by setting its destination to the null address in OperatorResolver.
  5. Call NestedFactory.rebuildCache again; the removed operator is excluded from the cache.
  6. Call NestedFactory.removeOperator for the removed operator, leaving a zero entry in the array.

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 operators and a cache of their addresses. When one operator is removed, the code sets its slot to zero but does not shrink the list, so the cache check always fails because it looks up a zero address. This means the contract can never confirm its cache is up to date, blocking functions that depend on it.

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 GreyArt

View all

12 more disclosed reports, best first.

More from Nested Finance 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.