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.
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.
- Import 3 operators by calling
OperatorResolver.importOperators([0xA, 0xB, 0xC], [0x1, 0x2, 0x3). - Call
NestedFactory.addOperator()3 times to push these 3 operators into theoperatorsstate variable. - Call
NestedFactory.rebuildCache()to build the cache. - Let’s say the second operator
0xBis to be removed. Taking reference from theremoveOperator.tsscript,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 setting0xB’s destination address to be the null address, it is like as if he was never an operator. - Call
NestedFactory.rebuildCache()to rebuild the cache.resolverAddressesRequired()will return[0xA, 0xB, 0xC].0xBwill be removed fromaddressCachebecauseresolver.getAddress(0xB)returns 0x000 since it has been deleted from the OperatorResolver. - Call
NestedFactory.removeOperator(0xB). Theoperatorsarray now looks like this:[0xA, 0x0, 0xC]. - When you try to call
NestedFactory.isResolverCached, it will always return false because of the nullbytes32value, whereaddressCache[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
Taking this issue apart as a non-duplicate, for finding the most severe consequence of the incorrect implementation.
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
- Import three operators via OperatorResolver.importOperators.
- Call NestedFactory.addOperator three times to add them to the operators array.
- Call NestedFactory.rebuildCache to build the cache.
- Remove the second operator by setting its destination to the null address in OperatorResolver.
- Call NestedFactory.rebuildCache again; the removed operator is excluded from the cache.
- 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.