Skip to content

Commit

Permalink
update zkp request only owner
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-basiuk committed Nov 6, 2024
1 parent ba53eb8 commit bf871f4
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 93 deletions.
11 changes: 0 additions & 11 deletions contracts/interfaces/IZKPVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,6 @@ interface IZKPVerifier {
*/
function requestIdExists(uint64 requestId) external view returns (bool);

/**
* @dev Get the ZKP requests.
* @param startIndex Start index of the ZKP requests.
* @param length Length of the ZKP requests.
* @return Array of the ZKP requests.
*/
function getZKPRequests(
uint256 startIndex,
uint256 length
) external view returns (ZKPRequest[] memory);

/**
* @dev Get if proof is verified for the sender and ZKP request with requestId.
* @param sender Sender of the proof.
Expand Down
4 changes: 2 additions & 2 deletions contracts/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.4.5",
"version": "2.4.6",
"files": [
"**/*.sol",
"/build/contracts/*.json",
Expand Down
35 changes: 26 additions & 9 deletions 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.1";
string public constant VERSION = "1.1.2";

/// @dev Event emitted upon submitting a ZKP request
event ZKPResponseSubmitted(uint64 indexed requestId, address indexed caller);
Expand All @@ -35,6 +35,15 @@ contract UniversalVerifier is
bytes data
);

/// @dev Event emitted upon updating a ZKP request
event ZKPRequestUpdate(
uint64 indexed requestId,
address indexed requestOwner,
string metadata,
address validator,
bytes data
);

/// @dev Modifier to check if the caller is the contract Owner or ZKP Request Owner
modifier onlyOwnerOrRequestOwner(uint64 requestId) {
address sender = _msgSender();
Expand Down Expand Up @@ -65,20 +74,28 @@ contract UniversalVerifier is
) public override(RequestOwnership, ValidatorWhitelist, ZKPVerifierBase) {
super.setZKPRequest(requestId, request);

// emit ZKPRequestSet(
// requestId,
// _msgSender(),
// request.metadata,
// address(request.validator),
// request.data
// );
emit ZKPRequestSet(
requestId,
_msgSender(),
request.metadata,
address(request.validator),
request.data
);
}

function updateZKPRequest(
uint64 requestId,
IZKPVerifier.ZKPRequest calldata request
) public override onlyOwnerOrRequestOwner(requestId) {
) public override onlyOwner {
super.updateZKPRequest(requestId, request);

emit ZKPRequestUpdate(
requestId,
_msgSender(),
request.metadata,
address(request.validator),
request.data
);
}

/// @dev Submits a ZKP response and updates proof status
Expand Down
25 changes: 0 additions & 25 deletions contracts/verifiers/ZKPVerifierBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -247,31 +247,6 @@ abstract contract ZKPVerifierBase is IZKPVerifier, ContextUpgradeable {
ICircuitValidator(address(0));
}

/// @dev Gets multiple ZKP requests within a range
/// @param startIndex The starting index of the range
/// @param length The length of the range
/// @return An array of ZKP requests within the specified range
function getZKPRequests(
uint256 startIndex,
uint256 length
) public view returns (IZKPVerifier.ZKPRequest[] memory) {
ZKPVerifierStorage storage s = _getZKPVerifierStorage();
(uint256 start, uint256 end) = ArrayUtils.calculateBounds(
s._requestIds.length,
startIndex,
length,
REQUESTS_RETURN_LIMIT
);

IZKPVerifier.ZKPRequest[] memory result = new IZKPVerifier.ZKPRequest[](end - start);

for (uint256 i = start; i < end; i++) {
result[i - start] = s._requests[s._requestIds[i]];
}

return result;
}

/// @dev Checks if proof submitted for a given sender and request ID
/// @param sender The sender's address
/// @param requestId The ID of the ZKP request
Expand Down
5 changes: 4 additions & 1 deletion helpers/UniversalVerifierContractMigrationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export class UniversalVerifierContractMigrationHelper extends ContractMigrationS
const requestsObj: any[] = [];

if (countRequests > 0) {
const requests = await contract.getZKPRequests(0, countRequests);
const requests: any = [];
for (let i = 0; i < countRequests; i++) {
requests.push(await contract.getZKPRequest(i));
}
for (const request of requests) {
if (!validators.includes(request[1])) {
validators.push(request[1]);
Expand Down
5 changes: 4 additions & 1 deletion scripts/upgrade/validators/verifier-validators-upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ async function main() {
}[] = [];

if (countRequests > 0) {
const requests = await verifierContract.getZKPRequests(0, countRequests);
const requests: any = [];
for (let i = 0; i < countRequests; i++) {
requests.push(await verifierContract.getZKPRequest(i));
}
console.log("Requests found: ", requests.length);
for (const request of requests) {
if (!validators.find((v) => v.validatorContractAddress === request[1])) {
Expand Down
23 changes: 0 additions & 23 deletions test/verifier/embedded-zkp-verifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,29 +199,6 @@ describe("Embedded ZKP Verifier", function () {
expect(proofStatus.blockTimestamp).to.be.equal(txResTimestamp);
});

it("test query param pagination", async () => {
for (let i = 0; i < 30; i++) {
await verifier.setZKPRequest(i, {
metadata: "metadataN" + i,
validator: await sig.getAddress(),
data: "0x00",
});
}
let queries = await verifier.getZKPRequests(5, 10);
expect(queries.length).to.be.equal(10n);
expect(queries[0].metadata).to.be.equal("metadataN5");
expect(queries[9].metadata).to.be.equal("metadataN14");

const count = await verifier.getZKPRequestsCount();
expect(count).to.be.equal(30n);

queries = await verifier.getZKPRequests(15, 3);
expect(queries.length).to.be.equal(3n);
expect(queries[0].metadata).to.be.equal("metadataN15");
expect(queries[1].metadata).to.be.equal("metadataN16");
expect(queries[2].metadata).to.be.equal("metadataN17");
});

it("test getZKPRequest and request id exists", async () => {
const requestsCount = 3;
for (let i = 0; i < requestsCount; i++) {
Expand Down
20 changes: 0 additions & 20 deletions test/verifier/universal-verifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,26 +132,6 @@ describe("Universal Verifier MTP & SIG validators", function () {
);
});

it("Test getZKPRequests pagination", async () => {
for (let i = 0; i < 30; i++) {
await verifier.setZKPRequest(i, {
metadata: "metadataN" + i,
validator: await sig.getAddress(),
data: "0x00",
});
}
let queries = await verifier.getZKPRequests(5, 10);
expect(queries.length).to.be.equal(10);
expect(queries[0].metadata).to.be.equal("metadataN5");
expect(queries[9].metadata).to.be.equal("metadataN14");

queries = await verifier.getZKPRequests(15, 3);
expect(queries.length).to.be.equal(3);
expect(queries[0].metadata).to.be.equal("metadataN15");
expect(queries[1].metadata).to.be.equal("metadataN16");
expect(queries[2].metadata).to.be.equal("metadataN17");
});

it("Check access control", async () => {
const owner = signer;
const requestOwner = signer2;
Expand Down

0 comments on commit bf871f4

Please sign in to comment.