Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NestedFactory.removeOperator code doesn't correspond to it's logic #220

Open
code423n4 opened this issue Nov 17, 2021 · 2 comments
Open
Assignees
Labels
1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working

Comments

@code423n4
Copy link
Contributor

Handle

hyh

Vulnerability details

Impact

Current implementation throws if first operator is to be deleted, i.e. operators[0] == operator, and doesn't throw when operator is not found, i.e. there is no i such that operators[i] == operator. This way an expected logic of throwing whenever operator isn't found in current list and deleting the one found otherwise doesn't take place.

This way

  1. operators[0] cannot be deleted
  2. if there is no requested operator in the operators list, an array bounds check violation will happen

Proof of Concept

NestedFactory.removeOperator code:
https://github.com/code-423n4/2021-11-nested/blob/main/contracts/NestedFactory.sol#L79

Recommended Mitigation Steps

Function code needs to be updated, for example:

Now:

uint256 i = 0;
while (operators[i] != operator) {
		i++;
}
require(i > 0, "NestedFactory::removeOperator: Cant remove non-existent operator");
delete operators[i];

To be:

for (uint256 i = 0; i < operators.length; i++) {
	if (operators[i] == operator) {
		break;
	}
}
require(i < operators.length, "NestedFactory::removeOperator: Can't remove non-existent operator");
delete operators[i];
@code423n4 code423n4 added 1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working labels Nov 17, 2021
code423n4 added a commit that referenced this issue Nov 17, 2021
@maximebrugel maximebrugel added the duplicate This issue or pull request already exists label Nov 18, 2021
@maximebrugel
Copy link
Collaborator

Duplicated : #58

@alcueca
Copy link
Collaborator

alcueca commented Dec 3, 2021

Taking this as the main for the whole lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants