@devtion/backend 0.0.0-5d170d3 → 0.0.0-bfc9ee4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1292,6 +1292,7 @@ const coordinate = async (participant, circuit, isSingleParticipantCoordination,
1292
1292
  printLog(`Coordinate - executing scenario A - single - participantResumingAfterTimeoutExpiration`, LogLevel.DEBUG);
1293
1293
  newParticipantStatus = "CONTRIBUTING" /* ParticipantStatus.CONTRIBUTING */;
1294
1294
  newContributionStep = "DOWNLOADING" /* ParticipantContributionStep.DOWNLOADING */;
1295
+ newCurrentContributorId = participant.id;
1295
1296
  }
1296
1297
  // Scenario (B).
1297
1298
  else if (participantIsNotCurrentContributor) {
@@ -1400,53 +1401,6 @@ const waitForVMCommandExecution = (resolve, reject, ssm, vmInstanceId, commandId
1400
1401
  }
1401
1402
  }, 60000); // 1 minute.
1402
1403
  };
1403
- /**
1404
- * Wait until the artifacts have been downloaded.
1405
- * @param {any} resolve the promise.
1406
- * @param {any} reject the promise.
1407
- * @param {string} potTempFilePath the tmp path to the locally downloaded pot file.
1408
- * @param {string} firstZkeyTempFilePath the tmp path to the locally downloaded first zkey file.
1409
- * @param {string} lastZkeyTempFilePath the tmp path to the locally downloaded last zkey file.
1410
- */
1411
- const waitForFileDownload = (resolve, reject, potTempFilePath, firstZkeyTempFilePath, lastZkeyTempFilePath, circuitId, participantId) => {
1412
- const maxWaitTime = 5 * 60 * 1000; // 5 minutes
1413
- // every second check if the file download was completed
1414
- const interval = setInterval(async () => {
1415
- printLog(`Verifying that the artifacts were downloaded for circuit ${circuitId} and participant ${participantId}`, LogLevel.DEBUG);
1416
- try {
1417
- // check if files have been downloaded
1418
- if (!fs.existsSync(potTempFilePath)) {
1419
- printLog(`Pot file not found at ${potTempFilePath}`, LogLevel.DEBUG);
1420
- }
1421
- if (!fs.existsSync(firstZkeyTempFilePath)) {
1422
- printLog(`First zkey file not found at ${firstZkeyTempFilePath}`, LogLevel.DEBUG);
1423
- }
1424
- if (!fs.existsSync(lastZkeyTempFilePath)) {
1425
- printLog(`Last zkey file not found at ${lastZkeyTempFilePath}`, LogLevel.DEBUG);
1426
- }
1427
- // if all files were downloaded
1428
- if (fs.existsSync(potTempFilePath) && fs.existsSync(firstZkeyTempFilePath) && fs.existsSync(lastZkeyTempFilePath)) {
1429
- printLog(`All required files are present on disk.`, LogLevel.INFO);
1430
- // resolve the promise
1431
- resolve();
1432
- }
1433
- }
1434
- catch (error) {
1435
- // if we have an error then we print it as a warning and reject
1436
- printLog(`Error while downloading files: ${error}`, LogLevel.WARN);
1437
- reject();
1438
- }
1439
- finally {
1440
- printLog(`Clearing the interval for file download. Circuit ${circuitId} and participant ${participantId}`, LogLevel.DEBUG);
1441
- clearInterval(interval);
1442
- }
1443
- }, 5000);
1444
- // we want to clean in 5 minutes in case
1445
- setTimeout(() => {
1446
- clearInterval(interval);
1447
- reject(new Error('Timeout exceeded while waiting for files to be downloaded.'));
1448
- }, maxWaitTime);
1449
- };
1450
1404
  /**
1451
1405
  * This method is used to coordinate the waiting queues of ceremony circuits.
1452
1406
  * @dev this cloud function is triggered whenever an update of a document related to a participant of a ceremony occurs.
@@ -1757,7 +1711,9 @@ const verifycontribution = functionsV2__namespace.https.onCall({ memory: "16GiB"
1757
1711
  const newAvgVerifyCloudFunctionTime = avgVerifyCloudFunctionTime > 0
1758
1712
  ? (avgVerifyCloudFunctionTime + verifyCloudFunctionTime) / 2
1759
1713
  : verifyCloudFunctionTime;
1760
- // Prepare tx to update circuit average contribution/verification time.
1714
+ // Prepare tx to update circuit average contribution/verification time.
1715
+ const updatedCircuitDoc = await getDocumentById(actions.getCircuitsCollectionPath(ceremonyId), circuitId);
1716
+ const { waitingQueue: updatedWaitingQueue } = updatedCircuitDoc.data();
1761
1717
  /// @dev this must happen only for valid contributions.
1762
1718
  batch.update(circuitDoc.ref, {
1763
1719
  avgTimings: {
@@ -1770,7 +1726,7 @@ const verifycontribution = functionsV2__namespace.https.onCall({ memory: "16GiB"
1770
1726
  : avgVerifyCloudFunctionTime
1771
1727
  },
1772
1728
  waitingQueue: {
1773
- ...waitingQueue,
1729
+ ...updatedWaitingQueue,
1774
1730
  completedContributions: isContributionValid
1775
1731
  ? completedContributions + 1
1776
1732
  : completedContributions,
@@ -1835,33 +1791,21 @@ const verifycontribution = functionsV2__namespace.https.onCall({ memory: "16GiB"
1835
1791
  await downloadArtifactFromS3Bucket(bucketName, potStoragePath, potTempFilePath);
1836
1792
  await downloadArtifactFromS3Bucket(bucketName, firstZkeyStoragePath, firstZkeyTempFilePath);
1837
1793
  await downloadArtifactFromS3Bucket(bucketName, lastZkeyStoragePath, lastZkeyTempFilePath);
1838
- await sleep(6000);
1839
- // wait until the files are actually downloaded
1840
- return new Promise((resolve, reject) => waitForFileDownload(resolve, reject, potTempFilePath, firstZkeyTempFilePath, lastZkeyTempFilePath, circuitId, participantDoc.id))
1841
- .then(async () => {
1842
- printLog(`Downloads from AWS S3 bucket completed - ceremony ${ceremonyId} circuit ${circuitId}`, LogLevel.DEBUG);
1843
- // Step (1.A.4).
1844
- isContributionValid = await snarkjs.zKey.verifyFromInit(firstZkeyTempFilePath, potTempFilePath, lastZkeyTempFilePath, transcriptLogger);
1845
- // Compute contribution hash.
1846
- lastZkeyBlake2bHash = await actions.blake512FromPath(lastZkeyTempFilePath);
1847
- // Free resources by unlinking temporary folders.
1848
- // Do not free-up verification transcript path here.
1849
- try {
1850
- fs.unlinkSync(potTempFilePath);
1851
- fs.unlinkSync(firstZkeyTempFilePath);
1852
- fs.unlinkSync(lastZkeyTempFilePath);
1853
- }
1854
- catch (error) {
1855
- printLog(`Error while unlinking temporary files - Error ${error}`, LogLevel.WARN);
1856
- }
1857
- await completeVerification();
1858
- })
1859
- .catch((error) => {
1860
- // Throw the new error
1861
- const commonError = COMMON_ERRORS.CM_INVALID_REQUEST;
1862
- const additionalDetails = error.toString();
1863
- logAndThrowError(makeError(commonError.code, commonError.message, additionalDetails));
1864
- });
1794
+ // Step (1.A.4).
1795
+ isContributionValid = await snarkjs.zKey.verifyFromInit(firstZkeyTempFilePath, potTempFilePath, lastZkeyTempFilePath, transcriptLogger);
1796
+ // Compute contribution hash.
1797
+ lastZkeyBlake2bHash = await actions.blake512FromPath(lastZkeyTempFilePath);
1798
+ // Free resources by unlinking temporary folders.
1799
+ // Do not free-up verification transcript path here.
1800
+ try {
1801
+ fs.unlinkSync(potTempFilePath);
1802
+ fs.unlinkSync(firstZkeyTempFilePath);
1803
+ fs.unlinkSync(lastZkeyTempFilePath);
1804
+ }
1805
+ catch (error) {
1806
+ printLog(`Error while unlinking temporary files - Error ${error}`, LogLevel.WARN);
1807
+ }
1808
+ await completeVerification();
1865
1809
  }
1866
1810
  }
1867
1811
  });
@@ -2523,7 +2467,7 @@ const checkAndRemoveBlockingContributor = functions__namespace
2523
2467
  // Prepare Firestore batch of txs.
2524
2468
  const batch = firestore.batch();
2525
2469
  // Remove current contributor from waiting queue.
2526
- contributors.shift(1);
2470
+ contributors.shift();
2527
2471
  // Check if someone else is ready to start the contribution.
2528
2472
  if (contributors.length > 0) {
2529
2473
  // Step (E.1).
@@ -19,7 +19,7 @@ import { pipeline } from 'node:stream';
19
19
  import { promisify } from 'node:util';
20
20
  import fs, { readFileSync } from 'fs';
21
21
  import mime from 'mime-types';
22
- import { setTimeout as setTimeout$1 } from 'timers/promises';
22
+ import { setTimeout } from 'timers/promises';
23
23
  import fetch from '@adobe/node-fetch-retry';
24
24
  import path from 'path';
25
25
  import os from 'os';
@@ -191,7 +191,7 @@ const getCurrentServerTimestampInMillis = () => Timestamp.now().toMillis();
191
191
  * Interrupt the current execution for a specified amount of time.
192
192
  * @param ms <number> - the amount of time expressed in milliseconds.
193
193
  */
194
- const sleep = async (ms) => setTimeout$1(ms);
194
+ const sleep = async (ms) => setTimeout(ms);
195
195
  /**
196
196
  * Query for ceremony circuits.
197
197
  * @notice the order by sequence position is fundamental to maintain parallelism among contributions for different circuits.
@@ -1269,6 +1269,7 @@ const coordinate = async (participant, circuit, isSingleParticipantCoordination,
1269
1269
  printLog(`Coordinate - executing scenario A - single - participantResumingAfterTimeoutExpiration`, LogLevel.DEBUG);
1270
1270
  newParticipantStatus = "CONTRIBUTING" /* ParticipantStatus.CONTRIBUTING */;
1271
1271
  newContributionStep = "DOWNLOADING" /* ParticipantContributionStep.DOWNLOADING */;
1272
+ newCurrentContributorId = participant.id;
1272
1273
  }
1273
1274
  // Scenario (B).
1274
1275
  else if (participantIsNotCurrentContributor) {
@@ -1377,53 +1378,6 @@ const waitForVMCommandExecution = (resolve, reject, ssm, vmInstanceId, commandId
1377
1378
  }
1378
1379
  }, 60000); // 1 minute.
1379
1380
  };
1380
- /**
1381
- * Wait until the artifacts have been downloaded.
1382
- * @param {any} resolve the promise.
1383
- * @param {any} reject the promise.
1384
- * @param {string} potTempFilePath the tmp path to the locally downloaded pot file.
1385
- * @param {string} firstZkeyTempFilePath the tmp path to the locally downloaded first zkey file.
1386
- * @param {string} lastZkeyTempFilePath the tmp path to the locally downloaded last zkey file.
1387
- */
1388
- const waitForFileDownload = (resolve, reject, potTempFilePath, firstZkeyTempFilePath, lastZkeyTempFilePath, circuitId, participantId) => {
1389
- const maxWaitTime = 5 * 60 * 1000; // 5 minutes
1390
- // every second check if the file download was completed
1391
- const interval = setInterval(async () => {
1392
- printLog(`Verifying that the artifacts were downloaded for circuit ${circuitId} and participant ${participantId}`, LogLevel.DEBUG);
1393
- try {
1394
- // check if files have been downloaded
1395
- if (!fs.existsSync(potTempFilePath)) {
1396
- printLog(`Pot file not found at ${potTempFilePath}`, LogLevel.DEBUG);
1397
- }
1398
- if (!fs.existsSync(firstZkeyTempFilePath)) {
1399
- printLog(`First zkey file not found at ${firstZkeyTempFilePath}`, LogLevel.DEBUG);
1400
- }
1401
- if (!fs.existsSync(lastZkeyTempFilePath)) {
1402
- printLog(`Last zkey file not found at ${lastZkeyTempFilePath}`, LogLevel.DEBUG);
1403
- }
1404
- // if all files were downloaded
1405
- if (fs.existsSync(potTempFilePath) && fs.existsSync(firstZkeyTempFilePath) && fs.existsSync(lastZkeyTempFilePath)) {
1406
- printLog(`All required files are present on disk.`, LogLevel.INFO);
1407
- // resolve the promise
1408
- resolve();
1409
- }
1410
- }
1411
- catch (error) {
1412
- // if we have an error then we print it as a warning and reject
1413
- printLog(`Error while downloading files: ${error}`, LogLevel.WARN);
1414
- reject();
1415
- }
1416
- finally {
1417
- printLog(`Clearing the interval for file download. Circuit ${circuitId} and participant ${participantId}`, LogLevel.DEBUG);
1418
- clearInterval(interval);
1419
- }
1420
- }, 5000);
1421
- // we want to clean in 5 minutes in case
1422
- setTimeout(() => {
1423
- clearInterval(interval);
1424
- reject(new Error('Timeout exceeded while waiting for files to be downloaded.'));
1425
- }, maxWaitTime);
1426
- };
1427
1381
  /**
1428
1382
  * This method is used to coordinate the waiting queues of ceremony circuits.
1429
1383
  * @dev this cloud function is triggered whenever an update of a document related to a participant of a ceremony occurs.
@@ -1734,7 +1688,9 @@ const verifycontribution = functionsV2.https.onCall({ memory: "16GiB", timeoutSe
1734
1688
  const newAvgVerifyCloudFunctionTime = avgVerifyCloudFunctionTime > 0
1735
1689
  ? (avgVerifyCloudFunctionTime + verifyCloudFunctionTime) / 2
1736
1690
  : verifyCloudFunctionTime;
1737
- // Prepare tx to update circuit average contribution/verification time.
1691
+ // Prepare tx to update circuit average contribution/verification time.
1692
+ const updatedCircuitDoc = await getDocumentById(getCircuitsCollectionPath(ceremonyId), circuitId);
1693
+ const { waitingQueue: updatedWaitingQueue } = updatedCircuitDoc.data();
1738
1694
  /// @dev this must happen only for valid contributions.
1739
1695
  batch.update(circuitDoc.ref, {
1740
1696
  avgTimings: {
@@ -1747,7 +1703,7 @@ const verifycontribution = functionsV2.https.onCall({ memory: "16GiB", timeoutSe
1747
1703
  : avgVerifyCloudFunctionTime
1748
1704
  },
1749
1705
  waitingQueue: {
1750
- ...waitingQueue,
1706
+ ...updatedWaitingQueue,
1751
1707
  completedContributions: isContributionValid
1752
1708
  ? completedContributions + 1
1753
1709
  : completedContributions,
@@ -1812,33 +1768,21 @@ const verifycontribution = functionsV2.https.onCall({ memory: "16GiB", timeoutSe
1812
1768
  await downloadArtifactFromS3Bucket(bucketName, potStoragePath, potTempFilePath);
1813
1769
  await downloadArtifactFromS3Bucket(bucketName, firstZkeyStoragePath, firstZkeyTempFilePath);
1814
1770
  await downloadArtifactFromS3Bucket(bucketName, lastZkeyStoragePath, lastZkeyTempFilePath);
1815
- await sleep(6000);
1816
- // wait until the files are actually downloaded
1817
- return new Promise((resolve, reject) => waitForFileDownload(resolve, reject, potTempFilePath, firstZkeyTempFilePath, lastZkeyTempFilePath, circuitId, participantDoc.id))
1818
- .then(async () => {
1819
- printLog(`Downloads from AWS S3 bucket completed - ceremony ${ceremonyId} circuit ${circuitId}`, LogLevel.DEBUG);
1820
- // Step (1.A.4).
1821
- isContributionValid = await zKey.verifyFromInit(firstZkeyTempFilePath, potTempFilePath, lastZkeyTempFilePath, transcriptLogger);
1822
- // Compute contribution hash.
1823
- lastZkeyBlake2bHash = await blake512FromPath(lastZkeyTempFilePath);
1824
- // Free resources by unlinking temporary folders.
1825
- // Do not free-up verification transcript path here.
1826
- try {
1827
- fs.unlinkSync(potTempFilePath);
1828
- fs.unlinkSync(firstZkeyTempFilePath);
1829
- fs.unlinkSync(lastZkeyTempFilePath);
1830
- }
1831
- catch (error) {
1832
- printLog(`Error while unlinking temporary files - Error ${error}`, LogLevel.WARN);
1833
- }
1834
- await completeVerification();
1835
- })
1836
- .catch((error) => {
1837
- // Throw the new error
1838
- const commonError = COMMON_ERRORS.CM_INVALID_REQUEST;
1839
- const additionalDetails = error.toString();
1840
- logAndThrowError(makeError(commonError.code, commonError.message, additionalDetails));
1841
- });
1771
+ // Step (1.A.4).
1772
+ isContributionValid = await zKey.verifyFromInit(firstZkeyTempFilePath, potTempFilePath, lastZkeyTempFilePath, transcriptLogger);
1773
+ // Compute contribution hash.
1774
+ lastZkeyBlake2bHash = await blake512FromPath(lastZkeyTempFilePath);
1775
+ // Free resources by unlinking temporary folders.
1776
+ // Do not free-up verification transcript path here.
1777
+ try {
1778
+ fs.unlinkSync(potTempFilePath);
1779
+ fs.unlinkSync(firstZkeyTempFilePath);
1780
+ fs.unlinkSync(lastZkeyTempFilePath);
1781
+ }
1782
+ catch (error) {
1783
+ printLog(`Error while unlinking temporary files - Error ${error}`, LogLevel.WARN);
1784
+ }
1785
+ await completeVerification();
1842
1786
  }
1843
1787
  }
1844
1788
  });
@@ -2500,7 +2444,7 @@ const checkAndRemoveBlockingContributor = functions
2500
2444
  // Prepare Firestore batch of txs.
2501
2445
  const batch = firestore.batch();
2502
2446
  // Remove current contributor from waiting queue.
2503
- contributors.shift(1);
2447
+ contributors.shift();
2504
2448
  // Check if someone else is ready to start the contribution.
2505
2449
  if (contributors.length > 0) {
2506
2450
  // Step (E.1).
@@ -1 +1 @@
1
- {"version":3,"file":"circuit.d.ts","sourceRoot":"","sources":["../../../src/functions/circuit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,uBAAuB,CAAA;AACpD,OAAO,KAAK,WAAW,MAAM,uBAAuB,CAAA;AAyCpD,OAAO,EAAuB,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAyR5E;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,6BAA6B,4FAoGpC,CAAA;AA8BN;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,kBAAkB,0EAya9B,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,+CAA+C,wEA4EtD,CAAA;AAEN;;;;GAIG;AACH,eAAO,MAAM,eAAe,uDA8EtB,CAAA"}
1
+ {"version":3,"file":"circuit.d.ts","sourceRoot":"","sources":["../../../src/functions/circuit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,uBAAuB,CAAA;AACpD,OAAO,KAAK,WAAW,MAAM,uBAAuB,CAAA;AAyCpD,OAAO,EAAuB,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AAkO5E;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,6BAA6B,4FAoGpC,CAAA;AA8BN;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,kBAAkB,0EA0Z9B,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,+CAA+C,wEA4EtD,CAAA;AAEN;;;;GAIG;AACH,eAAO,MAAM,eAAe,uDA8EtB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devtion/backend",
3
- "version": "0.0.0-5d170d3",
3
+ "version": "0.0.0-bfc9ee4",
4
4
  "description": "MPC Phase 2 backend for Firebase services management",
5
5
  "repository": "git@github.com:privacy-scaling-explorations/p0tion.git",
6
6
  "homepage": "https://github.com/privacy-scaling-explorations/p0tion",
@@ -85,5 +85,5 @@
85
85
  "publishConfig": {
86
86
  "access": "public"
87
87
  },
88
- "gitHead": "ff032e8717f4aac3f66730e0a256660c2e741505"
88
+ "gitHead": "b2a3be0c3d0ad2a94270d7a256b5b5acf3b1c47f"
89
89
  }
@@ -131,6 +131,7 @@ const coordinate = async (
131
131
 
132
132
  newParticipantStatus = ParticipantStatus.CONTRIBUTING
133
133
  newContributionStep = ParticipantContributionStep.DOWNLOADING
134
+ newCurrentContributorId = participant.id
134
135
  }
135
136
  // Scenario (B).
136
137
  else if (participantIsNotCurrentContributor) {
@@ -265,62 +266,6 @@ const waitForVMCommandExecution = (
265
266
  }, 60000) // 1 minute.
266
267
  }
267
268
 
268
- /**
269
- * Wait until the artifacts have been downloaded.
270
- * @param {any} resolve the promise.
271
- * @param {any} reject the promise.
272
- * @param {string} potTempFilePath the tmp path to the locally downloaded pot file.
273
- * @param {string} firstZkeyTempFilePath the tmp path to the locally downloaded first zkey file.
274
- * @param {string} lastZkeyTempFilePath the tmp path to the locally downloaded last zkey file.
275
- */
276
- const waitForFileDownload = (
277
- resolve: any,
278
- reject: any,
279
- potTempFilePath: string,
280
- firstZkeyTempFilePath: string,
281
- lastZkeyTempFilePath: string,
282
- circuitId: string,
283
- participantId: string
284
- ) => {
285
- const maxWaitTime = 5 * 60 * 1000 // 5 minutes
286
- // every second check if the file download was completed
287
- const interval = setInterval(async () => {
288
- printLog(`Verifying that the artifacts were downloaded for circuit ${circuitId} and participant ${participantId}`, LogLevel.DEBUG)
289
- try {
290
- // check if files have been downloaded
291
- if (!fs.existsSync(potTempFilePath)) {
292
- printLog(`Pot file not found at ${potTempFilePath}`, LogLevel.DEBUG)
293
- }
294
- if (!fs.existsSync(firstZkeyTempFilePath)) {
295
- printLog(`First zkey file not found at ${firstZkeyTempFilePath}`, LogLevel.DEBUG)
296
- }
297
- if (!fs.existsSync(lastZkeyTempFilePath)) {
298
- printLog(`Last zkey file not found at ${lastZkeyTempFilePath}`, LogLevel.DEBUG)
299
- }
300
-
301
- // if all files were downloaded
302
- if (fs.existsSync(potTempFilePath) && fs.existsSync(firstZkeyTempFilePath) && fs.existsSync(lastZkeyTempFilePath)) {
303
- printLog(`All required files are present on disk.`, LogLevel.INFO)
304
- // resolve the promise
305
- resolve()
306
- }
307
- } catch (error: any) {
308
- // if we have an error then we print it as a warning and reject
309
- printLog(`Error while downloading files: ${error}`, LogLevel.WARN)
310
- reject()
311
- } finally {
312
- printLog(`Clearing the interval for file download. Circuit ${circuitId} and participant ${participantId}`, LogLevel.DEBUG)
313
- clearInterval(interval)
314
- }
315
- }, 5000)
316
-
317
- // we want to clean in 5 minutes in case
318
- setTimeout(() => {
319
- clearInterval(interval)
320
- reject(new Error('Timeout exceeded while waiting for files to be downloaded.'))
321
- }, maxWaitTime)
322
- }
323
-
324
269
  /**
325
270
  * This method is used to coordinate the waiting queues of ceremony circuits.
326
271
  * @dev this cloud function is triggered whenever an update of a document related to a participant of a ceremony occurs.
@@ -763,7 +708,9 @@ export const verifycontribution = functionsV2.https.onCall(
763
708
  ? (avgVerifyCloudFunctionTime + verifyCloudFunctionTime) / 2
764
709
  : verifyCloudFunctionTime
765
710
 
766
- // Prepare tx to update circuit average contribution/verification time.
711
+ // Prepare tx to update circuit average contribution/verification time.
712
+ const updatedCircuitDoc = await getDocumentById(getCircuitsCollectionPath(ceremonyId), circuitId)
713
+ const { waitingQueue: updatedWaitingQueue } = updatedCircuitDoc.data()!
767
714
  /// @dev this must happen only for valid contributions.
768
715
  batch.update(circuitDoc.ref, {
769
716
  avgTimings: {
@@ -776,7 +723,7 @@ export const verifycontribution = functionsV2.https.onCall(
776
723
  : avgVerifyCloudFunctionTime
777
724
  },
778
725
  waitingQueue: {
779
- ...waitingQueue,
726
+ ...updatedWaitingQueue,
780
727
  completedContributions: isContributionValid
781
728
  ? completedContributions + 1
782
729
  : completedContributions,
@@ -879,45 +826,28 @@ export const verifycontribution = functionsV2.https.onCall(
879
826
  await downloadArtifactFromS3Bucket(bucketName, firstZkeyStoragePath, firstZkeyTempFilePath)
880
827
  await downloadArtifactFromS3Bucket(bucketName, lastZkeyStoragePath, lastZkeyTempFilePath)
881
828
 
882
- await sleep(6000)
883
-
884
- // wait until the files are actually downloaded
885
- return new Promise<void>((resolve, reject) =>
886
- waitForFileDownload(resolve, reject, potTempFilePath, firstZkeyTempFilePath, lastZkeyTempFilePath, circuitId, participantDoc.id)
829
+ // Step (1.A.4).
830
+ isContributionValid = await zKey.verifyFromInit(
831
+ firstZkeyTempFilePath,
832
+ potTempFilePath,
833
+ lastZkeyTempFilePath,
834
+ transcriptLogger
887
835
  )
888
- .then(async () => {
889
- printLog(`Downloads from AWS S3 bucket completed - ceremony ${ceremonyId} circuit ${circuitId}`, LogLevel.DEBUG)
890
-
891
- // Step (1.A.4).
892
- isContributionValid = await zKey.verifyFromInit(
893
- firstZkeyTempFilePath,
894
- potTempFilePath,
895
- lastZkeyTempFilePath,
896
- transcriptLogger
897
- )
898
-
899
- // Compute contribution hash.
900
- lastZkeyBlake2bHash = await blake512FromPath(lastZkeyTempFilePath)
901
-
902
- // Free resources by unlinking temporary folders.
903
- // Do not free-up verification transcript path here.
904
- try {
905
- fs.unlinkSync(potTempFilePath)
906
- fs.unlinkSync(firstZkeyTempFilePath)
907
- fs.unlinkSync(lastZkeyTempFilePath)
908
- } catch (error: any) {
909
- printLog(`Error while unlinking temporary files - Error ${error}`, LogLevel.WARN)
910
- }
911
-
912
- await completeVerification()
913
- })
914
- .catch((error: any) => {
915
- // Throw the new error
916
- const commonError = COMMON_ERRORS.CM_INVALID_REQUEST
917
- const additionalDetails = error.toString()
918
-
919
- logAndThrowError(makeError(commonError.code, commonError.message, additionalDetails))
920
- })
836
+
837
+ // Compute contribution hash.
838
+ lastZkeyBlake2bHash = await blake512FromPath(lastZkeyTempFilePath)
839
+
840
+ // Free resources by unlinking temporary folders.
841
+ // Do not free-up verification transcript path here.
842
+ try {
843
+ fs.unlinkSync(potTempFilePath)
844
+ fs.unlinkSync(firstZkeyTempFilePath)
845
+ fs.unlinkSync(lastZkeyTempFilePath)
846
+ } catch (error: any) {
847
+ printLog(`Error while unlinking temporary files - Error ${error}`, LogLevel.WARN)
848
+ }
849
+
850
+ await completeVerification()
921
851
  }
922
852
  }
923
853
  }
@@ -174,7 +174,7 @@ export const checkAndRemoveBlockingContributor = functions
174
174
  const batch = firestore.batch()
175
175
 
176
176
  // Remove current contributor from waiting queue.
177
- contributors.shift(1)
177
+ contributors.shift()
178
178
 
179
179
  // Check if someone else is ready to start the contribution.
180
180
  if (contributors.length > 0) {