Skip to content

Commit

Permalink
add logic from skip tests in verifier test
Browse files Browse the repository at this point in the history
  • Loading branch information
daveroga committed Jan 16, 2025
1 parent 296bb68 commit b0c8353
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
28 changes: 24 additions & 4 deletions contracts/verifiers/Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ error LinkIDNotTheSameForGroupedRequests();
error UserIDNotFound(uint256 userID);
error UserIDNotLinkedToAddress(uint256 userID, address userAddress);
error UserNotAuthenticated();
error UserIDMismatch(uint256 userIDFromAuth, uint256 userIDFromResponse);
error MetadataNotSupportedYet();
error GroupMustHaveAtLeastTwoRequests(uint256 groupID);
error NullifierSessionIDAlreadyExists(uint256 nullifierSessionID);
error VerifierIDIsNotValid(uint256 requestVerifierID, uint256 expectedVerifierID);
error RequestIdNotValid();
error RequestIdUsesReservedBytes();
error ResponseFieldAlreadyExists(string responseFieldName);

abstract contract Verifier is IVerifier, ContextUpgradeable {
/// @dev Key to retrieve the linkID from the proof storage
Expand Down Expand Up @@ -462,25 +464,25 @@ abstract contract Verifier is IVerifier, ContextUpgradeable {

// TODO: Get userID from responses that has userID informed (LinkedMultiquery doesn't have userID)

uint256 userIDFromReponse;
uint256 userIDFromAuthResponse;
AuthTypeData storage authTypeData = $._authMethods[authResponse.authType];

bytes32 expectedNonce = keccak256(abi.encode(sender, responses));

// Authenticate user
userIDFromReponse = authTypeData.validator.verify(
userIDFromAuthResponse = authTypeData.validator.verify(
authResponse.proof,
authTypeData.params,
sender,
$._state,
expectedNonce
);

if (userIDFromReponse == 0) {
if (userIDFromAuthResponse == 0) {
revert UserNotAuthenticated();
}

// 3. Verify all the responses, write proof results (under the userID key from the auth of the user),
// 3. Verify all the responses, check userID from signals and write proof results,
// emit events (existing logic)
for (uint256 i = 0; i < responses.length; i++) {
IVerifier.Response memory response = responses[i];
Expand All @@ -493,6 +495,24 @@ abstract contract Verifier is IVerifier, ContextUpgradeable {
$._state
);

// Check if userID from authResponse is the same as the one in the signals
for (uint256 j = 0; j < signals.length; j++) {
if (keccak256(abi.encodePacked(signals[j].name)) == keccak256(abi.encodePacked("userID"))) {

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

View workflow job for this annotation

GitHub Actions / solhint

Replace keccak256(abi.encodePacked(signals[j].name))·==·keccak256(abi.encodePacked("userID")) with ⏎····················keccak256(abi.encodePacked(signals[j].name))·==⏎····················keccak256(abi.encodePacked("userID"))⏎················
if (userIDFromAuthResponse != signals[j].value) {
revert UserIDMismatch(userIDFromAuthResponse, signals[j].value);
}
}
}

// Check that response fields are not repeated
for (uint256 j = 0; j < signals.length; j++) {
for (uint256 k = j + 1; k < signals.length; k++) {
if (keccak256(abi.encodePacked(signals[j].name)) == keccak256(abi.encodePacked(signals[k].name))) {

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

View workflow job for this annotation

GitHub Actions / solhint

Replace keccak256(abi.encodePacked(signals[j].name))·==·keccak256(abi.encodePacked(signals[k].name)) with ⏎························keccak256(abi.encodePacked(signals[j].name))·==⏎························keccak256(abi.encodePacked(signals[k].name))⏎····················
revert ResponseFieldAlreadyExists(signals[j].name);
}
}
}

$.writeProofResults(response.requestId, sender, signals);

if (response.metadata.length > 0) {
Expand Down
8 changes: 4 additions & 4 deletions test/verifier/verifer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ describe("Verifer tests", function () {
it("setRequests: requestId should be valid and not using reserved bytes", async function () {
await validator.stub_setRequestParams([request.params], [paramsFromValidator]);

request.requestId = BigInt(2 ** 256) - BigInt(1);
request.requestId = BigInt(2 ** 256) - BigInt(1); // requestId without valid prefix 0x0000000000000000 or 0x0000000000000001

await expect(verifier.setRequests([request])).to.be.revertedWithCustomError(
verifier,
"RequestIdNotValid",
);

request.requestId = BigInt(2 ** 248) + BigInt(2 ** 247);
request.requestId = BigInt(2 ** 247); // requestId uses reserved bytes
await expect(verifier.setRequests([request])).to.be.revertedWithCustomError(
verifier,
"RequestIdUsesReservedBytes",
Expand Down Expand Up @@ -124,7 +124,7 @@ describe("Verifer tests", function () {
expect(resonseField2).to.be.equal(2);
});

it.skip("submitResponse: should throw if repeated responseFields from validator", async function () {
it("submitResponse: should throw if repeated responseFields from validator", async function () {
await verifier.setRequests([request]);
await validator.stub_setVerifyResults([
{
Expand Down Expand Up @@ -152,7 +152,7 @@ describe("Verifer tests", function () {
.withArgs("someFieldName1");
});

it.skip("submitResponse: userID in response fields should match auth userID", async function () {
it("submitResponse: userID in response fields should match auth userID", async function () {
await verifier.setRequests([request]);

let userID = 1; // we assume that userID is hardcoded to 1 in the auth stub contract
Expand Down

0 comments on commit b0c8353

Please sign in to comment.