Skip to content

Commit

Permalink
check grouped requests 2 requests at least
Browse files Browse the repository at this point in the history
  • Loading branch information
daveroga committed Jan 9, 2025
1 parent 1d49a4e commit 4a9e988
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 7 deletions.
38 changes: 32 additions & 6 deletions contracts/verifiers/Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ error UserIDNotFound(uint256 userID);
error UserIDNotLinkedToAddress(uint256 userID, address userAddress);
error UserNotAuthenticated();
error MetadataNotSupportedYet();
error GroupMustHaveAtLeastTwoRequests(uint256 groupID);

abstract contract Verifier is IVerifier, ContextUpgradeable {
/// @dev Key to retrieve the linkID from the proof storage
Expand Down Expand Up @@ -58,8 +59,6 @@ abstract contract Verifier is IVerifier, ContextUpgradeable {
// Information about multiRequests
mapping(uint256 multiRequestId => IVerifier.MultiRequest) _multiRequests;
uint256[] _multiRequestIds;
// Whitelisted validators
mapping(IRequestValidator => bool isApproved) _validatorWhitelist;
// Information about auth types and validators
string[] _authTypes;
mapping(string authType => AuthTypeData) _authMethods;
Expand Down Expand Up @@ -234,14 +233,41 @@ abstract contract Verifier is IVerifier, ContextUpgradeable {
* @dev Sets different requests
* @param requests The list of requests
*/
function setRequests(Request[] calldata requests) public {
function setRequests(IVerifier.Request[] calldata requests) public {

Check failure on line 236 in contracts/verifiers/Verifier.sol

View workflow job for this annotation

GitHub Actions / solhint

Function has cyclomatic complexity 12 but allowed no more than 8
VerifierStorage storage s = _getVerifierStorage();

// 1. Check first that groupIds don't exist
uint256 newGroupsCount = 0;
uint256[] memory newGroupsGroupID = new uint256[](requests.length);
uint256[] memory newGroupsRequestCount = new uint256[](requests.length);

// 1. Check first that groupIds don't exist and keep the number of requests per group
for (uint256 i = 0; i < requests.length; i++) {
uint256 groupID = requests[i].validator.getRequestParams(requests[i].params).groupID;
if (groupID != 0 && groupIdExists(groupID)) {
revert GroupIdAlreadyExists(groupID);

if (groupID != 0) {
if (groupIdExists(groupID)) {
revert GroupIdAlreadyExists(groupID);
}

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

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

Expand Down
36 changes: 35 additions & 1 deletion test/verifier/universal-verifier.v3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ describe("Universal Verifier V3 validator", function () {
validator: await v3Validator.getAddress(),
params: params,
},
{
requestId: requestId + 10,
metadata: "metadata",
validator: await v3Validator.getAddress(),
params: params,
},
]);

const requestStored = await verifier.getRequest(requestId);
Expand Down Expand Up @@ -238,6 +244,12 @@ describe("Universal Verifier V3 validator", function () {
validator: await v3Validator.getAddress(),
params: params,
},
{
requestId: requestId + 10,
metadata: "metadata",
validator: await v3Validator.getAddress(),
params: params,
},
]);
const { inputs, pi_a, pi_b, pi_c } = prepareInputs(proofJson);
const proof = packZKProof(inputs, pi_a, pi_b, pi_c);
Expand Down Expand Up @@ -318,6 +330,12 @@ describe("Universal Verifier V3 validator", function () {
validator: await v3Validator.getAddress(),
params: params,
},
{
requestId: requestId + 10,
metadata: "metadata",
validator: await v3Validator.getAddress(),
params: params,
},
]);

const { inputs, pi_a, pi_b, pi_c } = prepareInputs(proofJson);
Expand Down Expand Up @@ -359,6 +377,12 @@ describe("Universal Verifier V3 validator", function () {
validator: await v3Validator.getAddress(),
params: params,
},
{
requestId: requestId + 10,
metadata: "metadata",
validator: await v3Validator.getAddress(),
params: params,
},
]);

const { inputs, pi_a, pi_b, pi_c } = prepareInputs(proofJson);
Expand Down Expand Up @@ -400,6 +424,12 @@ describe("Universal Verifier V3 validator", function () {
validator: await v3Validator.getAddress(),
params: params,
},
{
requestId: requestId + 10,
metadata: "metadata",
validator: await v3Validator.getAddress(),
params: params,
},
]);

const { inputs, pi_a, pi_b, pi_c } = prepareInputs(proofJson);
Expand Down Expand Up @@ -439,7 +469,11 @@ describe("Universal Verifier V3 validator", function () {
await publishState(state, stateTransition12 as any);
await publishState(state, stateTransition13 as any);

const params = packV3ValidatorParams(query);
const query2 = {
...query,
};
query2.groupID = 0;
const params = packV3ValidatorParams(query2);
const requestId = 37;
await verifier.setRequests([
{
Expand Down

0 comments on commit 4a9e988

Please sign in to comment.