Skip to content

Commit

Permalink
fix error cyclomatic-complexity from solhint
Browse files Browse the repository at this point in the history
  • Loading branch information
daveroga committed Jan 9, 2025
1 parent 4a9e988 commit 81fdf83
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions contracts/verifiers/Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -249,27 +249,23 @@ abstract contract Verifier is IVerifier, ContextUpgradeable {
revert GroupIdAlreadyExists(groupID);
}

bool existingGroupID = false;
for (uint256 j = 0; j < newGroupsCount; j++) {
if (newGroupsGroupID[j] == groupID) {
newGroupsRequestCount[j]++;
existingGroupID = true;
break;
}
}
if (!existingGroupID) {
(bool exists, uint256 groupIDIndex) = _getGroupIDIndex(
groupID,
newGroupsGroupID,
newGroupsCount
);

if (!exists) {
newGroupsGroupID[newGroupsCount] = groupID;
newGroupsRequestCount[newGroupsCount]++;
newGroupsCount++;
} else {
newGroupsRequestCount[groupIDIndex]++;
}
}
}

for (uint256 i = 0; i < newGroupsCount; i++) {
if (newGroupsRequestCount[i] < 2) {
revert GroupMustHaveAtLeastTwoRequests(newGroupsGroupID[i]);
}
}
_checkGroupsRequestsCount(newGroupsGroupID, newGroupsRequestCount, newGroupsCount);

// 2. Set requests checking groups
for (uint256 i = 0; i < requests.length; i++) {
Expand All @@ -290,6 +286,32 @@ abstract contract Verifier is IVerifier, ContextUpgradeable {
}
}

function _getGroupIDIndex(
uint256 groupID,
uint256[] memory groupList,
uint256 listCount
) internal pure returns (bool, uint256) {
for (uint256 j = 0; j < listCount; j++) {
if (groupList[j] == groupID) {
return (true, j);
}
}

return (false, 0);
}

function _checkGroupsRequestsCount(
uint256[] memory groupList,
uint256[] memory groupRequestsList,
uint256 groupsCount
) internal pure {
for (uint256 i = 0; i < groupsCount; i++) {
if (groupRequestsList[i] < 2) {
revert GroupMustHaveAtLeastTwoRequests(groupList[i]);
}
}
}

/**
* @dev Gets a specific request by ID
* @param requestId The ID of the request
Expand Down

0 comments on commit 81fdf83

Please sign in to comment.