Skip to content

Commit

Permalink
Add setZKPRequests for multiple set of zkp requests (#325)
Browse files Browse the repository at this point in the history
* add setZKPRequests for multiple set of zkp requests
  • Loading branch information
daveroga authored Dec 19, 2024
1 parent a430e00 commit 9d4e443
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 3 deletions.
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@iden3/contracts",
"description": "Smart Contract library for Solidity",
"version": "2.5.5",
"version": "2.5.6",
"files": [
"**/*.sol",
"/build/contracts/*.json",
Expand Down
12 changes: 12 additions & 0 deletions contracts/verifiers/EmbeddedZKPVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ abstract contract EmbeddedZKPVerifier is Ownable2StepUpgradeable, ZKPVerifierBas
super.setZKPRequest(requestId, request);
}

/**
* @dev Set the list of ZKP requests for the list of requestIds in the same order.
* @param requestIds Request ids of the ZKP requests.
* @param requests ZKP requests to set.
*/
function setZKPRequests(
uint64[] calldata requestIds,
ZKPRequest[] calldata requests
) public virtual override onlyOwner {
super.setZKPRequests(requestIds, requests);
}

/// @dev Submits a ZKP response and updates proof status
/// @param requestId The ID of the ZKP request
/// @param inputs The input data for the proof
Expand Down
14 changes: 14 additions & 0 deletions contracts/verifiers/RequestOwnership.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ abstract contract RequestOwnership is ZKPVerifierBase {
_setRequestOwner(requestId, _msgSender());
}

/**
* @dev Set the list of ZKP requests for the list of requestIds in the same order.
* @param requestIds Request ids of the ZKP requests.
* @param requests ZKP requests to set.
*/
function setZKPRequests(
uint64[] calldata requestIds,
ZKPRequest[] calldata requests
) public virtual override {
for (uint256 i = 0; i < requestIds.length; i++) {
setZKPRequest(requestIds[i], requests[i]);
}
}

/// @dev Get a ZKP Request Owner address
/// @param requestId The ID of a ZKP Request
/// @return The ZKP Request Owner address
Expand Down
16 changes: 15 additions & 1 deletion contracts/verifiers/UniversalVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract UniversalVerifier is
/**
* @dev Version of contract
*/
string public constant VERSION = "1.1.4";
string public constant VERSION = "1.1.5";

/// @dev Event emitted upon submitting a ZKP request
event ZKPResponseSubmitted(uint64 indexed requestId, address indexed caller);
Expand Down Expand Up @@ -83,6 +83,20 @@ contract UniversalVerifier is
);
}

/**
* @dev Set the list of ZKP requests for the list of requestIds in the same order.
* @param requestIds Request ids of the ZKP requests.
* @param requests ZKP requests to set.
*/
function setZKPRequests(
uint64[] calldata requestIds,
ZKPRequest[] calldata requests
) public override(RequestOwnership, ValidatorWhitelist, ZKPVerifierBase) {
for (uint256 i = 0; i < requestIds.length; i++) {
setZKPRequest(requestIds[i], requests[i]);
}
}

/// @dev Update a ZKP request
/// @param requestId The ID of the ZKP request
/// @param request The ZKP request data
Expand Down
14 changes: 14 additions & 0 deletions contracts/verifiers/ValidatorWhitelist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ contract ValidatorWhitelist is ZKPVerifierBase {
super.setZKPRequest(requestId, request);
}

/**
* @dev Set the list of ZKP requests for the list of requestIds in the same order.
* @param requestIds Request ids of the ZKP requests.
* @param requests ZKP requests to set.
*/
function setZKPRequests(
uint64[] calldata requestIds,
ZKPRequest[] calldata requests
) public virtual override {
for (uint256 i = 0; i < requestIds.length; i++) {
setZKPRequest(requestIds[i], requests[i]);
}
}

/// @dev Verifies a ZKP response without updating any proof status
/// @param requestId The ID of the ZKP request
/// @param inputs The public inputs for the proof
Expand Down
16 changes: 16 additions & 0 deletions contracts/verifiers/ZKPVerifierBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ abstract contract ZKPVerifierBase is IZKPVerifier, ContextUpgradeable {
s._requestIds.push(requestId);
}

/**
* @dev Set the ZKP request for the requestId.
* @param requestIds Request ids of the ZKP requests.
* @param requests ZKP requests to set.
*/
function setZKPRequests(
uint64[] calldata requestIds,
ZKPRequest[] calldata requests
) public virtual {
require(requestIds.length == requests.length, "Request IDs and requests length mismatch");

for (uint256 i = 0; i < requestIds.length; i++) {
setZKPRequest(requestIds[i], requests[i]);
}
}

/// @notice Submits a ZKP response and updates proof status
/// @param requestId The ID of the ZKP request
/// @param inputs The input data for the proof
Expand Down
2 changes: 1 addition & 1 deletion helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export const contractsInfo = Object.freeze({
},
UNIVERSAL_VERIFIER: {
name: "UniversalVerifier",
version: "1.1.4",
version: "1.1.5",
unifiedAddress: "0xfcc86A79fCb057A8e55C6B853dff9479C3cf607c",
create2Calldata: ethers.hexlify(ethers.toUtf8Bytes("iden3.create2.UniversalVerifier")),
verificationOpts: {
Expand Down
33 changes: 33 additions & 0 deletions test/verifier/universal-verifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,39 @@ describe("Universal Verifier MTP & SIG validators", function () {
expect(count).to.be.equal(requestsCount);
});

it("Test add, get ZKPRequest, requestIdExists, getZKPRequestsCount with multiple set", async () => {
const requestsCount = 3;
const validatorAddr = await validator.getAddress();

const requestIds: number[] = [];
const requests: any[] = [];
for (let i = 0; i < requestsCount; i++) {
requestIds.push(i);
requests.push({
metadata: "metadataN" + i,
validator: validatorAddr,
data: "0x0" + i,
});
}

await expect(verifier.setZKPRequests(requestIds, requests))
.to.emit(verifier, "ZKPRequestSet")
.withArgs(0, signerAddress, "metadataN" + 0, validatorAddr, "0x0" + 0);

for (let i = 1; i < requestsCount; i++) {
const request = await verifier.getZKPRequest(i);
expect(request.metadata).to.be.equal("metadataN" + i);
expect(request.validator).to.be.equal(validatorAddr);
expect(request.data).to.be.equal("0x0" + i);

const requestIdExists = await verifier.requestIdExists(i);
expect(requestIdExists).to.be.true;
}

const count = await verifier.getZKPRequestsCount();
expect(count).to.be.equal(requestsCount);
});

it("Test submit response", async () => {
const requestId = 0;
const nonExistingRequestId = 1;
Expand Down

0 comments on commit 9d4e443

Please sign in to comment.