Skip to content

Commit

Permalink
partial changes review
Browse files Browse the repository at this point in the history
  • Loading branch information
daveroga committed Dec 30, 2024
1 parent a8c8653 commit 6336ad5
Show file tree
Hide file tree
Showing 15 changed files with 62 additions and 143 deletions.
4 changes: 2 additions & 2 deletions contracts/interfaces/IAuthValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ interface IAuthValidator {
* @dev Verify the proof with the supported method informed in the auth query data
* packed as bytes and that the proof was generated by the sender.
* @param proof Proof packed as bytes to verify.
* @param data Request query data of the credential to verify.
* @param params Request query data of the credential to verify.
* @param sender Sender of the proof.
* @param state State contract to get identities and gist states to check.
* @return Array of response fields as result.
*/
function verify(
bytes calldata proof,
bytes calldata data,
bytes calldata params,
address sender,
IState state
) external returns (ResponseField[] memory);
Expand Down
25 changes: 14 additions & 11 deletions contracts/interfaces/IRequestValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ interface IRequestValidator {
uint256 value;
}

/**
* @dev RequestParams. Information about request params from request query data.

Check failure on line 21 in contracts/interfaces/IRequestValidator.sol

View workflow job for this annotation

GitHub Actions / solhint

Delete ·
* @param groupID Group ID of the request query params
* @param verifierID Verifier ID of the request query params
*/
struct RequestParams {
uint256 groupID;
uint256 verifierID;
}

/**
* @dev Get version of the contract
*/
Expand All @@ -26,29 +36,22 @@ interface IRequestValidator {
* @dev Verify the proof with the supported method informed in the request query data
* packed as bytes and that the proof was generated by the sender.
* @param proof Proof packed as bytes to verify.
* @param data Request query data of the credential to verify.
* @param params Request query data of the credential to verify.
* @param sender Sender of the proof.
* @param state State contract to get identities and gist states to check.
* @return Array of response fields as result.
*/
function verify(
bytes calldata proof,
bytes calldata data,
bytes calldata params,
address sender,
IState state
) external returns (ResponseField[] memory);

/**
* @dev Get the group ID of the request query data.
* @dev Get the request params of the request query data.
* @param params Request query data of the credential to verify.
* @return Group ID of the request query data.
*/
function getGroupID(bytes calldata params) external view returns (uint256);

/**
* @dev Get the verifier ID of the request query data.
* @param params Request query data of the credential to verify.
* @return Verifier ID encoded in the request query data.
*/
function getVerifierId(bytes calldata params) external view returns (uint256);
function getRequestParams(bytes calldata params) external view returns (RequestParams memory);
}
3 changes: 1 addition & 2 deletions contracts/interfaces/IVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,9 @@ interface IVerifier {

/**
* @dev Sets a query
* @param queryId The ID of the query
* @param query The query data
*/
function setQuery(uint256 queryId, Query calldata query) external;
function setQuery(Query calldata query) external;

/**
* @dev Gets a specific multi query by ID
Expand Down
3 changes: 1 addition & 2 deletions contracts/lib/VerifierLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ library VerifierLib {
// TODO: discuss if we need this field
// uint256 blockNumber;
uint256 blockTimestamp;
mapping(string key => bytes) metadata;
// This empty reserved space is put in place to allow future versions
// (see https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#storage-gaps)
uint256[45] __gap;
uint256[46] __gap;
}

/**
Expand Down
8 changes: 2 additions & 6 deletions contracts/test-helpers/RequestValidatorAuthV2Stub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ contract RequestValidatorAuthV2Stub is IRequestValidator, ERC165 {
return signals;
}

function getGroupID(bytes calldata) external pure override returns (uint256) {
return 0;
}

function getVerifierId(bytes calldata) external pure override returns (uint256) {
return 0;
function getRequestParams(bytes calldata) external pure override returns (IRequestValidator.RequestParams memory) {

Check failure on line 36 in contracts/test-helpers/RequestValidatorAuthV2Stub.sol

View workflow job for this annotation

GitHub Actions / solhint

Replace bytes·calldata with ⏎········bytes·calldata⏎····
return IRequestValidator.RequestParams({ groupID: 0, verifierID: 0 });

Check failure on line 37 in contracts/test-helpers/RequestValidatorAuthV2Stub.sol

View workflow job for this annotation

GitHub Actions / solhint

Replace ·groupID:·0,·verifierID:·0· with groupID:·0,·verifierID:·0
}
}
8 changes: 2 additions & 6 deletions contracts/test-helpers/RequestValidatorV2Stub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ contract RequestValidatorV2Stub is IRequestValidator, ERC165 {
return signals;
}

function getGroupID(bytes calldata) external pure override returns (uint256) {
return 0;
}

function getVerifierId(bytes calldata) external pure override returns (uint256) {
return 0;
function getRequestParams(bytes calldata) external pure override returns (IRequestValidator.RequestParams memory) {

Check failure on line 38 in contracts/test-helpers/RequestValidatorV2Stub.sol

View workflow job for this annotation

GitHub Actions / solhint

Replace bytes·calldata with ⏎········bytes·calldata⏎····
return IRequestValidator.RequestParams({ groupID: 0, verifierID: 0 });

Check failure on line 39 in contracts/test-helpers/RequestValidatorV2Stub.sol

View workflow job for this annotation

GitHub Actions / solhint

Replace ·groupID:·0,·verifierID:·0· with groupID:·0,·verifierID:·0
}
}
14 changes: 3 additions & 11 deletions contracts/test-helpers/RequestValidatorV3Stub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,11 @@ contract RequestValidatorV3Stub is IRequestValidator, ERC165 {
return signals;
}

function getGroupID(bytes calldata params) external pure override returns (uint256) {
function getRequestParams(bytes calldata params) external pure override returns (IRequestValidator.RequestParams memory) {

Check failure on line 56 in contracts/test-helpers/RequestValidatorV3Stub.sol

View workflow job for this annotation

GitHub Actions / solhint

Line length must be no more than 120 but current length is 126
CredentialAtomicQueryV3 memory credAtomicQuery = abi.decode(
params,
(CredentialAtomicQueryV3)
);
return credAtomicQuery.groupID;
}

function getVerifierId(bytes calldata params) external pure override returns (uint256) {
CredentialAtomicQueryV3 memory credAtomicQuery = abi.decode(
params,
(CredentialAtomicQueryV3)
);
return credAtomicQuery.verifierID;
}
return IRequestValidator.RequestParams({ groupID: credAtomicQuery.groupID, verifierID: credAtomicQuery.verifierID });
}
}
12 changes: 2 additions & 10 deletions contracts/test-helpers/RequestValidatorV3_2Stub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,11 @@ contract RequestValidatorV3_2Stub is IRequestValidator, ERC165 {
return signals;
}

function getGroupID(bytes calldata params) external pure override returns (uint256) {
function getRequestParams(bytes calldata params) external pure override returns (IRequestValidator.RequestParams memory) {

Check failure on line 56 in contracts/test-helpers/RequestValidatorV3_2Stub.sol

View workflow job for this annotation

GitHub Actions / solhint

Line length must be no more than 120 but current length is 126

Check failure on line 56 in contracts/test-helpers/RequestValidatorV3_2Stub.sol

View workflow job for this annotation

GitHub Actions / solhint

Replace bytes·calldata·params with ⏎········bytes·calldata·params⏎····
CredentialAtomicQueryV3 memory credAtomicQuery = abi.decode(
params,
(CredentialAtomicQueryV3)
);
return credAtomicQuery.groupID;
}

function getVerifierId(bytes calldata params) external pure override returns (uint256) {
CredentialAtomicQueryV3 memory credAtomicQuery = abi.decode(
params,
(CredentialAtomicQueryV3)
);
return credAtomicQuery.verifierID;
return IRequestValidator.RequestParams({ groupID: credAtomicQuery.groupID, verifierID: credAtomicQuery.verifierID });

Check failure on line 61 in contracts/test-helpers/RequestValidatorV3_2Stub.sol

View workflow job for this annotation

GitHub Actions / solhint

Line length must be no more than 120 but current length is 125

Check failure on line 61 in contracts/test-helpers/RequestValidatorV3_2Stub.sol

View workflow job for this annotation

GitHub Actions / solhint

Replace ·IRequestValidator.RequestParams({·groupID:·credAtomicQuery.groupID,·verifierID:·credAtomicQuery.verifierID with ⏎············IRequestValidator.RequestParams({⏎················groupID:·credAtomicQuery.groupID,⏎················verifierID:·credAtomicQuery.verifierID⏎···········
}
}
18 changes: 2 additions & 16 deletions contracts/validators/AuthV2Validator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,8 @@ contract AuthV2Validator is CredentialAtomicQueryValidatorBase {
return pubSignals;
}

/**
* @dev Get the group ID of the request query data.
* @param params Request query data of the credential to verify.
* @return Group ID of the request query data.
*/
function getGroupID(bytes calldata params) external pure override returns (uint256) {
return 0;
}

/**
* @dev Get the verifier ID from the request query data
* @param params Request query data of the credential to verify.
* @return Verifier ID
*/
function getVerifierId(bytes calldata params) external pure override returns (uint256) {
return 0;
function getRequestParams(bytes calldata) external pure override returns (IRequestValidator.RequestParams memory) {
return IRequestValidator.RequestParams({ groupID: 0, verifierID: 0 });
}

/**
Expand Down
18 changes: 2 additions & 16 deletions contracts/validators/CredentialAtomicQueryV2ValidatorBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,8 @@ abstract contract CredentialAtomicQueryV2ValidatorBase is CredentialAtomicQueryV
return _getResponseFields(pubSignals);
}

/**
* @dev Get the group ID of the request query data.
* @param params Request query data of the credential to verify.
* @return Group ID of the request query data.
*/
function getGroupID(bytes calldata params) external pure override returns (uint256) {
return 0;
}

/**
* @dev Get the verifier ID from the request query data
* @param params Request query data of the credential to verify.
* @return Verifier ID
*/
function getVerifierId(bytes calldata params) external pure override returns (uint256) {
return 0;
function getRequestParams(bytes calldata) external pure override returns (IRequestValidator.RequestParams memory) {
return IRequestValidator.RequestParams({ groupID: 0, verifierID: 0 });
}

/**
Expand Down
24 changes: 3 additions & 21 deletions contracts/validators/CredentialAtomicQueryV3Validator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,32 +147,14 @@ contract CredentialAtomicQueryV3Validator is CredentialAtomicQueryValidatorBase
return _getResponseFields(pubSignals, hasSD);
}

/**
* @dev Get the group ID of the request query data.
* @param params Request query data of the credential to verify.
* @return Group ID of the request query data.
*/
function getGroupID(bytes calldata params) external pure override returns (uint256) {
function getRequestParams(bytes calldata params) external pure override returns (IRequestValidator.RequestParams memory) {
CredentialAtomicQueryV3 memory credAtomicQuery = abi.decode(
params,
(CredentialAtomicQueryV3)
);
return credAtomicQuery.groupID;
return IRequestValidator.RequestParams({ groupID: credAtomicQuery.groupID, verifierID: credAtomicQuery.verifierID });
}

/**
* @dev Get the verifier ID from the request query data
* @param params Request query data of the credential to verify.
* @return Verifier ID
*/
function getVerifierId(bytes calldata params) external pure override returns (uint256) {
CredentialAtomicQueryV3 memory credAtomicQuery = abi.decode(
params,
(CredentialAtomicQueryV3)
);
return credAtomicQuery.verifierID;
}


/**
* @dev Verify the groth16 proof and check the request query data
* @param inputs Public inputs of the circuit.
Expand Down
15 changes: 3 additions & 12 deletions contracts/validators/EthIdentityValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,8 @@ contract EthIdentityValidator is Ownable2StepUpgradeable, IRequestValidator, ERC
require(calcId == id, "Sender is not owner of the ethereum identity");
}

function getGroupID(bytes calldata) external pure override returns (uint256) {
// TODO: Implement group ID
return 0;
}

/**
* @dev Get the verifier ID of the request query data.
* @param params Request query data of the credential to verify.
* @return Verifier ID encoded in the request query data.
*/
function getVerifierId(bytes calldata params) external view returns (uint256) {
return 0;
function getRequestParams(bytes calldata) external pure override returns (IRequestValidator.RequestParams memory) {
return IRequestValidator.RequestParams({ groupID: 0, verifierID: 0 });
}

}
8 changes: 3 additions & 5 deletions contracts/verifiers/UniversalVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,13 @@ contract UniversalVerifier is

/**
* @dev Sets a query
* @param queryId The ID of the query
* @param query The query data
*/
function setQuery(
uint256 queryId,
Query calldata query
) public override checkQueryExistence(queryId, false) {
super.setQuery(queryId, query);
emit QuerySet(queryId, query.requestIds);
) public override checkQueryExistence(query.queryId, false) {
super.setQuery(query);
emit QuerySet(query.queryId, query.requestIds);
}

/**
Expand Down
39 changes: 19 additions & 20 deletions contracts/verifiers/Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@ abstract contract Verifier is IVerifier, ContextUpgradeable {
* @dev Modifier to check if the request exists
*/
modifier checkRequestGroupExistence(Request memory request, bool existence) {
uint256 groupId = request.validator.getGroupID(request.params);
IRequestValidator.RequestParams memory requestParams = request.validator.getRequestParams(request.params);

if (groupId != 0) {
if (requestParams.groupID != 0) {
if (existence) {
if (!groupIdExists(groupId)) {
revert GroupIdNotFound(groupId);
if (!groupIdExists(requestParams.groupID)) {
revert GroupIdNotFound(requestParams.groupID);
}
} else {
if (groupIdExists(groupId)) {
revert GroupIdAlreadyExists(groupId);
if (groupIdExists(requestParams.groupID)) {
revert GroupIdAlreadyExists(requestParams.groupID);
}
}
}
Expand Down Expand Up @@ -220,14 +220,14 @@ abstract contract Verifier is IVerifier, ContextUpgradeable {
Request calldata request
) internal checkRequestExistence(request.requestId, false) {
VerifierStorage storage s = _getVerifierStorage();
uint256 verifierId = request.validator.getVerifierId(request.params);
IRequestValidator.RequestParams memory requestParams = request.validator.getRequestParams(request.params);

s._requests[request.requestId] = IVerifier.RequestData({
metadata: request.metadata,
validator: request.validator,
params: request.params,
creator: _msgSender(),
verifierId: verifierId
verifierId: requestParams.verifierID
});
s._requestIds.push(request.requestId);
}
Expand Down Expand Up @@ -285,19 +285,17 @@ abstract contract Verifier is IVerifier, ContextUpgradeable {

/**
* @dev Sets a query
* @param queryId The ID of the query
* @param query The query data
*/
function setQuery(
uint256 queryId,
IVerifier.Query calldata query
) public virtual checkQueryExistence(queryId, false) {
) public virtual checkQueryExistence(query.queryId, false) {
VerifierStorage storage s = _getVerifierStorage();
s._queries[queryId] = query;
s._queryIds.push(queryId);
s._queries[query.queryId] = query;
s._queryIds.push(query.queryId);

// checks for all the requests in this query
_checkRequestsInQuery(queryId);
_checkRequestsInQuery(query.queryId);
}

/**
Expand All @@ -316,10 +314,11 @@ abstract contract Verifier is IVerifier, ContextUpgradeable {

// check that all the single requests doesn't have group
for (uint256 i = 0; i < requestIds.length; i++) {
IRequestValidator.RequestParams memory requestParams = s._requests[requestIds[i]].validator.getRequestParams(
s._requests[requestIds[i]].params
);
if (
s._requests[requestIds[i]].validator.getGroupID(
s._requests[requestIds[i]].params
) != 0
requestParams.groupID != 0
) {
revert RequestIsAlreadyGrouped(requestIds[i]);
}
Expand Down Expand Up @@ -420,14 +419,14 @@ abstract contract Verifier is IVerifier, ContextUpgradeable {
IVerifier.Request calldata request
) internal checkRequestExistence(request.requestId, true) {
VerifierStorage storage s = _getVerifierStorage();
uint256 verifierId = request.validator.getVerifierId(request.params);

IRequestValidator.RequestParams memory requestParams = request.validator.getRequestParams(request.params);
s._requests[request.requestId] = IVerifier.RequestData({
metadata: request.metadata,
validator: request.validator,
params: request.params,
creator: _msgSender(),
verifierId: verifierId
verifierId: requestParams.verifierID
});
}

Expand Down
Loading

0 comments on commit 6336ad5

Please sign in to comment.