@devtion/actions 0.0.0-270e9e0 → 0.0.0-2e5a17d
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.
- package/README.md +1 -1
- package/dist/index.mjs +330 -280
- package/dist/index.node.js +330 -279
- package/dist/types/src/helpers/constants.d.ts +7 -0
- package/dist/types/src/helpers/constants.d.ts.map +1 -1
- package/dist/types/src/helpers/contracts.d.ts.map +1 -1
- package/dist/types/src/helpers/crypto.d.ts +1 -0
- package/dist/types/src/helpers/crypto.d.ts.map +1 -1
- package/dist/types/src/helpers/database.d.ts +8 -0
- package/dist/types/src/helpers/database.d.ts.map +1 -1
- package/dist/types/src/helpers/security.d.ts +2 -2
- package/dist/types/src/helpers/security.d.ts.map +1 -1
- package/dist/types/src/helpers/storage.d.ts +5 -2
- package/dist/types/src/helpers/storage.d.ts.map +1 -1
- package/dist/types/src/helpers/utils.d.ts +34 -20
- package/dist/types/src/helpers/utils.d.ts.map +1 -1
- package/dist/types/src/helpers/verification.d.ts +3 -2
- package/dist/types/src/helpers/verification.d.ts.map +1 -1
- package/dist/types/src/helpers/vm.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +9 -3
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/package.json +3 -8
- package/src/helpers/constants.ts +7 -0
- package/src/helpers/contracts.ts +3 -3
- package/src/helpers/database.ts +13 -0
- package/src/helpers/functions.ts +1 -1
- package/src/helpers/security.ts +33 -52
- package/src/helpers/services.ts +3 -3
- package/src/helpers/storage.ts +15 -3
- package/src/helpers/utils.ts +316 -277
- package/src/helpers/verification.ts +6 -6
- package/src/helpers/vm.ts +14 -7
- package/src/index.ts +3 -2
- package/src/types/index.ts +32 -8
package/dist/index.node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @module @
|
|
3
|
-
* @version 1.
|
|
2
|
+
* @module @devtion/actions
|
|
3
|
+
* @version 1.1.1
|
|
4
4
|
* @file A set of actions and helpers for CLI commands
|
|
5
5
|
* @copyright Ethereum Foundation 2022
|
|
6
6
|
* @license MIT
|
|
@@ -17,9 +17,7 @@ var firestore = require('firebase/firestore');
|
|
|
17
17
|
var snarkjs = require('snarkjs');
|
|
18
18
|
var crypto = require('crypto');
|
|
19
19
|
var blake = require('blakejs');
|
|
20
|
-
var ffjavascript = require('ffjavascript');
|
|
21
20
|
var winston = require('winston');
|
|
22
|
-
var clientS3 = require('@aws-sdk/client-s3');
|
|
23
21
|
var stream = require('stream');
|
|
24
22
|
var util = require('util');
|
|
25
23
|
var app = require('firebase/app');
|
|
@@ -246,6 +244,12 @@ const commonTerms = {
|
|
|
246
244
|
verificationStartedAt: "verificationStartedAt"
|
|
247
245
|
}
|
|
248
246
|
},
|
|
247
|
+
avatars: {
|
|
248
|
+
name: "avatars",
|
|
249
|
+
fields: {
|
|
250
|
+
avatarUrl: "avatarUrl"
|
|
251
|
+
}
|
|
252
|
+
},
|
|
249
253
|
ceremonies: {
|
|
250
254
|
name: "ceremonies",
|
|
251
255
|
fields: {
|
|
@@ -337,6 +341,7 @@ const commonTerms = {
|
|
|
337
341
|
finalizeCeremony: "finalizeCeremony",
|
|
338
342
|
downloadCircuitArtifacts: "downloadCircuitArtifacts",
|
|
339
343
|
transferObject: "transferObject",
|
|
344
|
+
bandadaValidateProof: "bandadaValidateProof"
|
|
340
345
|
}
|
|
341
346
|
};
|
|
342
347
|
|
|
@@ -687,19 +692,23 @@ const getChunksAndPreSignedUrls = async (cloudFunctions, bucketName, objectKey,
|
|
|
687
692
|
* @param cloudFunctions <Functions> - the Firebase Cloud Functions service instance.
|
|
688
693
|
* @param ceremonyId <string> - the unique identifier of the ceremony.
|
|
689
694
|
* @param alreadyUploadedChunks Array<ETagWithPartNumber> - the temporary information about the already uploaded chunks.
|
|
695
|
+
* @param logger <GenericBar> - an optional logger to show progress.
|
|
690
696
|
* @returns <Promise<Array<ETagWithPartNumber>>> - the completed (uploaded) chunks information.
|
|
691
697
|
*/
|
|
692
|
-
const uploadParts = async (chunksWithUrls, contentType, cloudFunctions, ceremonyId, alreadyUploadedChunks) => {
|
|
698
|
+
const uploadParts = async (chunksWithUrls, contentType, cloudFunctions, ceremonyId, alreadyUploadedChunks, logger) => {
|
|
693
699
|
// Keep track of uploaded chunks.
|
|
694
700
|
const uploadedChunks = alreadyUploadedChunks || [];
|
|
701
|
+
// if we were passed a logger, start it
|
|
702
|
+
if (logger)
|
|
703
|
+
logger.start(chunksWithUrls.length, 0);
|
|
695
704
|
// Loop through remaining chunks.
|
|
696
705
|
for (let i = alreadyUploadedChunks ? alreadyUploadedChunks.length : 0; i < chunksWithUrls.length; i += 1) {
|
|
697
706
|
// Consume the pre-signed url to upload the chunk.
|
|
698
707
|
// @ts-ignore
|
|
699
708
|
const response = await fetch(chunksWithUrls[i].preSignedUrl, {
|
|
700
709
|
retryOptions: {
|
|
701
|
-
retryInitialDelay: 500,
|
|
702
|
-
socketTimeout: 60000,
|
|
710
|
+
retryInitialDelay: 500, // 500 ms.
|
|
711
|
+
socketTimeout: 60000, // 60 seconds.
|
|
703
712
|
retryMaxDuration: 300000 // 5 minutes.
|
|
704
713
|
},
|
|
705
714
|
method: "PUT",
|
|
@@ -723,6 +732,9 @@ const uploadParts = async (chunksWithUrls, contentType, cloudFunctions, ceremony
|
|
|
723
732
|
// nb. this must be done only when contributing (not finalizing).
|
|
724
733
|
if (!!ceremonyId && !!cloudFunctions)
|
|
725
734
|
await temporaryStoreCurrentContributionUploadedChunkData(cloudFunctions, ceremonyId, chunk);
|
|
735
|
+
// increment the count on the logger
|
|
736
|
+
if (logger)
|
|
737
|
+
logger.increment();
|
|
726
738
|
}
|
|
727
739
|
return uploadedChunks;
|
|
728
740
|
};
|
|
@@ -743,8 +755,9 @@ const uploadParts = async (chunksWithUrls, contentType, cloudFunctions, ceremony
|
|
|
743
755
|
* @param configStreamChunkSize <number> - size of each chunk into which the artifact is going to be splitted (nb. will be converted in MB).
|
|
744
756
|
* @param [ceremonyId] <string> - the unique identifier of the ceremony (used as a double-edge sword - as identifier and as a check if current contributor is the coordinator finalizing the ceremony).
|
|
745
757
|
* @param [temporaryDataToResumeMultiPartUpload] <TemporaryParticipantContributionData> - the temporary information necessary to resume an already started multi-part upload.
|
|
758
|
+
* @param logger <GenericBar> - an optional logger to show progress.
|
|
746
759
|
*/
|
|
747
|
-
const multiPartUpload = async (cloudFunctions, bucketName, objectKey, localFilePath, configStreamChunkSize, ceremonyId, temporaryDataToResumeMultiPartUpload) => {
|
|
760
|
+
const multiPartUpload = async (cloudFunctions, bucketName, objectKey, localFilePath, configStreamChunkSize, ceremonyId, temporaryDataToResumeMultiPartUpload, logger) => {
|
|
748
761
|
// The unique identifier of the multi-part upload.
|
|
749
762
|
let multiPartUploadId = "";
|
|
750
763
|
// The list of already uploaded chunks.
|
|
@@ -768,7 +781,7 @@ const multiPartUpload = async (cloudFunctions, bucketName, objectKey, localFileP
|
|
|
768
781
|
const chunksWithUrlsZkey = await getChunksAndPreSignedUrls(cloudFunctions, bucketName, objectKey, localFilePath, multiPartUploadId, configStreamChunkSize, ceremonyId);
|
|
769
782
|
// Step (2).
|
|
770
783
|
const partNumbersAndETagsZkey = await uploadParts(chunksWithUrlsZkey, mime.lookup(localFilePath), // content-type.
|
|
771
|
-
cloudFunctions, ceremonyId, alreadyUploadedChunks);
|
|
784
|
+
cloudFunctions, ceremonyId, alreadyUploadedChunks, logger);
|
|
772
785
|
// Step (3).
|
|
773
786
|
await completeMultiPartUpload(cloudFunctions, bucketName, objectKey, multiPartUploadId, partNumbersAndETagsZkey, ceremonyId);
|
|
774
787
|
};
|
|
@@ -992,6 +1005,17 @@ const getClosedCeremonies = async (firestoreDatabase) => {
|
|
|
992
1005
|
]);
|
|
993
1006
|
return fromQueryToFirebaseDocumentInfo(closedCeremoniesQuerySnap.docs);
|
|
994
1007
|
};
|
|
1008
|
+
/**
|
|
1009
|
+
* Query all ceremonies
|
|
1010
|
+
* @notice get all ceremonies from the database.
|
|
1011
|
+
* @dev this is a helper for the CLI ceremony methods.
|
|
1012
|
+
* @param firestoreDatabase <Firestore> - the Firestore service instance associated to the current Firebase application.
|
|
1013
|
+
* @returns <Promise<Array<FirebaseDocumentInfo>>> - the list of all ceremonies.
|
|
1014
|
+
*/
|
|
1015
|
+
const getAllCeremonies = async (firestoreDatabase) => {
|
|
1016
|
+
const ceremoniesQuerySnap = await queryCollection(firestoreDatabase, commonTerms.collections.ceremonies.name, []);
|
|
1017
|
+
return fromQueryToFirebaseDocumentInfo(ceremoniesQuerySnap.docs);
|
|
1018
|
+
};
|
|
995
1019
|
|
|
996
1020
|
/**
|
|
997
1021
|
* @hidden
|
|
@@ -1040,189 +1064,22 @@ const compareHashes = async (path1, path2) => {
|
|
|
1040
1064
|
};
|
|
1041
1065
|
|
|
1042
1066
|
/**
|
|
1043
|
-
*
|
|
1044
|
-
* @
|
|
1045
|
-
* @
|
|
1046
|
-
* @param cleanup <boolean> - whether to delete the r1cs file after parsing
|
|
1047
|
-
* @returns any - the data to pass to the cloud function for setup and the circuit artifacts
|
|
1067
|
+
* Return a string with double digits if the provided input is one digit only.
|
|
1068
|
+
* @param in <number> - the input number to be converted.
|
|
1069
|
+
* @returns <string> - the two digits stringified number derived from the conversion.
|
|
1048
1070
|
*/
|
|
1049
|
-
const
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
throw new Error("You need to provide the data for at least 1 circuit.");
|
|
1062
|
-
// validate that the end date is in the future
|
|
1063
|
-
let endDate;
|
|
1064
|
-
let startDate;
|
|
1065
|
-
try {
|
|
1066
|
-
endDate = new Date(data.endDate);
|
|
1067
|
-
startDate = new Date(data.startDate);
|
|
1068
|
-
}
|
|
1069
|
-
catch (error) {
|
|
1070
|
-
throw new Error("The dates should follow this format: 2023-07-04T00:00:00.");
|
|
1071
|
-
}
|
|
1072
|
-
if (endDate <= startDate)
|
|
1073
|
-
throw new Error("The end date should be greater than the start date.");
|
|
1074
|
-
const currentDate = new Date();
|
|
1075
|
-
if (endDate <= currentDate || startDate <= currentDate)
|
|
1076
|
-
throw new Error("The start and end dates should be in the future.");
|
|
1077
|
-
// validate penalty
|
|
1078
|
-
if (data.penalty <= 0)
|
|
1079
|
-
throw new Error("The penalty should be greater than zero.");
|
|
1080
|
-
const circuits = [];
|
|
1081
|
-
const urlPattern = /(https?:\/\/[^\s]+)/g;
|
|
1082
|
-
const commitHashPattern = /^[a-f0-9]{40}$/i;
|
|
1083
|
-
const circuitArtifacts = [];
|
|
1084
|
-
for (let i = 0; i < data.circuits.length; i++) {
|
|
1085
|
-
const circuitData = data.circuits[i];
|
|
1086
|
-
const artifacts = circuitData.artifacts;
|
|
1087
|
-
circuitArtifacts.push({
|
|
1088
|
-
artifacts: artifacts
|
|
1089
|
-
});
|
|
1090
|
-
const r1csPath = artifacts.r1csStoragePath;
|
|
1091
|
-
const wasmPath = artifacts.wasmStoragePath;
|
|
1092
|
-
// where we storing the r1cs downloaded
|
|
1093
|
-
const localR1csPath = `./${circuitData.name}.r1cs`;
|
|
1094
|
-
// check that the artifacts exist in S3
|
|
1095
|
-
// we don't need any privileges to download this
|
|
1096
|
-
// just the correct region
|
|
1097
|
-
const s3 = new clientS3.S3Client({ region: artifacts.region });
|
|
1098
|
-
try {
|
|
1099
|
-
await s3.send(new clientS3.HeadObjectCommand({
|
|
1100
|
-
Bucket: artifacts.bucket,
|
|
1101
|
-
Key: r1csPath
|
|
1102
|
-
}));
|
|
1103
|
-
}
|
|
1104
|
-
catch (error) {
|
|
1105
|
-
throw new Error(`The r1cs file (${r1csPath}) seems to not exist. Please ensure this is correct and that the object is publicly available.`);
|
|
1106
|
-
}
|
|
1107
|
-
try {
|
|
1108
|
-
await s3.send(new clientS3.HeadObjectCommand({
|
|
1109
|
-
Bucket: artifacts.bucket,
|
|
1110
|
-
Key: wasmPath
|
|
1111
|
-
}));
|
|
1112
|
-
}
|
|
1113
|
-
catch (error) {
|
|
1114
|
-
throw new Error(`The wasm file (${wasmPath}) seems to not exist. Please ensure this is correct and that the object is publicly available.`);
|
|
1115
|
-
}
|
|
1116
|
-
// download the r1cs to extract the metadata
|
|
1117
|
-
const command = new clientS3.GetObjectCommand({ Bucket: artifacts.bucket, Key: artifacts.r1csStoragePath });
|
|
1118
|
-
const response = await s3.send(command);
|
|
1119
|
-
const streamPipeline = util.promisify(stream.pipeline);
|
|
1120
|
-
if (response.$metadata.httpStatusCode !== 200)
|
|
1121
|
-
throw new Error("There was an error while trying to download the r1cs file. Please check that the file has the correct permissions (public) set.");
|
|
1122
|
-
if (response.Body instanceof stream.Readable)
|
|
1123
|
-
await streamPipeline(response.Body, fs.createWriteStream(localR1csPath));
|
|
1124
|
-
// extract the metadata from the r1cs
|
|
1125
|
-
const metadata = getR1CSInfo(localR1csPath);
|
|
1126
|
-
// validate that the circuit hash and template links are valid
|
|
1127
|
-
const template = circuitData.template;
|
|
1128
|
-
const URLMatch = template.source.match(urlPattern);
|
|
1129
|
-
if (!URLMatch || URLMatch.length === 0 || URLMatch.length > 1)
|
|
1130
|
-
throw new Error("You should provide the URL to the circuits templates on GitHub.");
|
|
1131
|
-
const hashMatch = template.commitHash.match(commitHashPattern);
|
|
1132
|
-
if (!hashMatch || hashMatch.length === 0 || hashMatch.length > 1)
|
|
1133
|
-
throw new Error("You should provide a valid commit hash of the circuit templates.");
|
|
1134
|
-
// calculate the hash of the r1cs file
|
|
1135
|
-
const r1csBlake2bHash = await blake512FromPath(localR1csPath);
|
|
1136
|
-
const circuitPrefix = extractPrefix(circuitData.name);
|
|
1137
|
-
// filenames
|
|
1138
|
-
const doubleDigitsPowers = convertToDoubleDigits(metadata.pot);
|
|
1139
|
-
const r1csCompleteFilename = `${circuitData.name}.r1cs`;
|
|
1140
|
-
const wasmCompleteFilename = `${circuitData.name}.wasm`;
|
|
1141
|
-
const smallestPowersOfTauCompleteFilenameForCircuit = `${potFilenameTemplate}${doubleDigitsPowers}.ptau`;
|
|
1142
|
-
const firstZkeyCompleteFilename = `${circuitPrefix}_${genesisZkeyIndex}.zkey`;
|
|
1143
|
-
// storage paths
|
|
1144
|
-
const r1csStorageFilePath = getR1csStorageFilePath(circuitPrefix, r1csCompleteFilename);
|
|
1145
|
-
const wasmStorageFilePath = getWasmStorageFilePath(circuitPrefix, wasmCompleteFilename);
|
|
1146
|
-
const potStorageFilePath = getPotStorageFilePath(smallestPowersOfTauCompleteFilenameForCircuit);
|
|
1147
|
-
const zkeyStorageFilePath = getZkeyStorageFilePath(circuitPrefix, firstZkeyCompleteFilename);
|
|
1148
|
-
const files = {
|
|
1149
|
-
potFilename: smallestPowersOfTauCompleteFilenameForCircuit,
|
|
1150
|
-
r1csFilename: r1csCompleteFilename,
|
|
1151
|
-
wasmFilename: wasmCompleteFilename,
|
|
1152
|
-
initialZkeyFilename: firstZkeyCompleteFilename,
|
|
1153
|
-
potStoragePath: potStorageFilePath,
|
|
1154
|
-
r1csStoragePath: r1csStorageFilePath,
|
|
1155
|
-
wasmStoragePath: wasmStorageFilePath,
|
|
1156
|
-
initialZkeyStoragePath: zkeyStorageFilePath,
|
|
1157
|
-
r1csBlake2bHash: r1csBlake2bHash
|
|
1158
|
-
};
|
|
1159
|
-
// validate that the compiler hash is a valid hash
|
|
1160
|
-
const compiler = circuitData.compiler;
|
|
1161
|
-
const compilerHashMatch = compiler.commitHash.match(commitHashPattern);
|
|
1162
|
-
if (!compilerHashMatch || compilerHashMatch.length === 0 || compilerHashMatch.length > 1)
|
|
1163
|
-
throw new Error("You should provide a valid commit hash of the circuit compiler.");
|
|
1164
|
-
// validate that the verification options are valid
|
|
1165
|
-
const verification = circuitData.verification;
|
|
1166
|
-
if (verification.cfOrVm !== "CF" && verification.cfOrVm !== "VM")
|
|
1167
|
-
throw new Error("Please enter a valid verification mechanism: either CF or VM");
|
|
1168
|
-
// @todo VM parameters verification
|
|
1169
|
-
// if (verification['cfOrVM'] === "VM") {}
|
|
1170
|
-
// check that the timeout is provided for the correct configuration
|
|
1171
|
-
let dynamicThreshold;
|
|
1172
|
-
let fixedTimeWindow;
|
|
1173
|
-
if (data.timeoutMechanismType === "DYNAMIC" /* CeremonyTimeoutType.DYNAMIC */) {
|
|
1174
|
-
if (circuitData.dynamicThreshold <= 0)
|
|
1175
|
-
throw new Error("The dynamic threshold should be > 0.");
|
|
1176
|
-
dynamicThreshold = circuitData.dynamicThreshold;
|
|
1177
|
-
}
|
|
1178
|
-
if (data.timeoutMechanismType === "FIXED" /* CeremonyTimeoutType.FIXED */) {
|
|
1179
|
-
if (circuitData.fixedTimeWindow <= 0)
|
|
1180
|
-
throw new Error("The fixed time window threshold should be > 0.");
|
|
1181
|
-
fixedTimeWindow = circuitData.fixedTimeWindow;
|
|
1182
|
-
}
|
|
1183
|
-
// the Circuit data for the ceremony setup
|
|
1184
|
-
const circuit = {
|
|
1185
|
-
name: circuitData.name,
|
|
1186
|
-
description: circuitData.description,
|
|
1187
|
-
prefix: circuitPrefix,
|
|
1188
|
-
sequencePosition: i + 1,
|
|
1189
|
-
metadata: metadata,
|
|
1190
|
-
files: files,
|
|
1191
|
-
template: template,
|
|
1192
|
-
compiler: compiler,
|
|
1193
|
-
verification: verification,
|
|
1194
|
-
fixedTimeWindow: fixedTimeWindow,
|
|
1195
|
-
// dynamicThreshold: dynamicThreshold,
|
|
1196
|
-
avgTimings: {
|
|
1197
|
-
contributionComputation: 0,
|
|
1198
|
-
fullContribution: 0,
|
|
1199
|
-
verifyCloudFunction: 0
|
|
1200
|
-
},
|
|
1201
|
-
};
|
|
1202
|
-
circuits.push(circuit);
|
|
1203
|
-
// remove the local r1cs download (if used for verifying the config only vs setup)
|
|
1204
|
-
if (cleanup)
|
|
1205
|
-
fs.unlinkSync(localR1csPath);
|
|
1206
|
-
}
|
|
1207
|
-
const setupData = {
|
|
1208
|
-
ceremonyInputData: {
|
|
1209
|
-
title: data.title,
|
|
1210
|
-
description: data.description,
|
|
1211
|
-
startDate: startDate.valueOf(),
|
|
1212
|
-
endDate: endDate.valueOf(),
|
|
1213
|
-
timeoutMechanismType: data.timeoutMechanismType,
|
|
1214
|
-
penalty: data.penalty
|
|
1215
|
-
},
|
|
1216
|
-
ceremonyPrefix: extractPrefix(data.title),
|
|
1217
|
-
circuits: circuits,
|
|
1218
|
-
circuitArtifacts: circuitArtifacts
|
|
1219
|
-
};
|
|
1220
|
-
return setupData;
|
|
1221
|
-
}
|
|
1222
|
-
catch (error) {
|
|
1223
|
-
throw new Error(`Error while parsing up the ceremony setup file. ${error.message}`);
|
|
1224
|
-
}
|
|
1225
|
-
};
|
|
1071
|
+
const convertToDoubleDigits = (amount) => (amount < 10 ? `0${amount}` : amount.toString());
|
|
1072
|
+
/**
|
|
1073
|
+
* Extract a prefix consisting of alphanumeric and underscore characters from a string with arbitrary characters.
|
|
1074
|
+
* @dev replaces all special symbols and whitespaces with an underscore char ('_'). Convert all uppercase chars to lowercase.
|
|
1075
|
+
* @notice example: str = 'Multiplier-2!2.4.zkey'; output prefix = 'multiplier_2_2_4.zkey'.
|
|
1076
|
+
* NB. Prefix extraction is a key process that conditions the name of the ceremony artifacts, download/upload from/to storage, collections paths.
|
|
1077
|
+
* @param str <string> - the arbitrary string from which to extract the prefix.
|
|
1078
|
+
* @returns <string> - the resulting prefix.
|
|
1079
|
+
*/
|
|
1080
|
+
const extractPrefix = (str) =>
|
|
1081
|
+
// eslint-disable-next-line no-useless-escape
|
|
1082
|
+
str.replace(/[`\s~!@#$%^&*()|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "-").toLowerCase();
|
|
1226
1083
|
/**
|
|
1227
1084
|
* Extract data from a R1CS metadata file generated with a custom file-based logger.
|
|
1228
1085
|
* @notice useful for extracting metadata circuits contained in the generated file using a logger
|
|
@@ -1279,17 +1136,6 @@ const formatZkeyIndex = (progress) => {
|
|
|
1279
1136
|
* @returns <number> - the amount of powers.
|
|
1280
1137
|
*/
|
|
1281
1138
|
const extractPoTFromFilename = (potCompleteFilename) => Number(potCompleteFilename.split("_").pop()?.split(".").at(0));
|
|
1282
|
-
/**
|
|
1283
|
-
* Extract a prefix consisting of alphanumeric and underscore characters from a string with arbitrary characters.
|
|
1284
|
-
* @dev replaces all special symbols and whitespaces with an underscore char ('_'). Convert all uppercase chars to lowercase.
|
|
1285
|
-
* @notice example: str = 'Multiplier-2!2.4.zkey'; output prefix = 'multiplier_2_2_4.zkey'.
|
|
1286
|
-
* NB. Prefix extraction is a key process that conditions the name of the ceremony artifacts, download/upload from/to storage, collections paths.
|
|
1287
|
-
* @param str <string> - the arbitrary string from which to extract the prefix.
|
|
1288
|
-
* @returns <string> - the resulting prefix.
|
|
1289
|
-
*/
|
|
1290
|
-
const extractPrefix = (str) =>
|
|
1291
|
-
// eslint-disable-next-line no-useless-escape
|
|
1292
|
-
str.replace(/[`\s~!@#$%^&*()|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "-").toLowerCase();
|
|
1293
1139
|
/**
|
|
1294
1140
|
* Automate the generation of an entropy for a contribution.
|
|
1295
1141
|
* @dev Took inspiration from here https://github.com/glamperd/setup-mpc-ui/blob/master/client/src/state/Compute.tsx#L112.
|
|
@@ -1356,7 +1202,9 @@ const getContributionsValidityForContributor = async (firestoreDatabase, circuit
|
|
|
1356
1202
|
* @param isFinalizing <boolean> - true when the coordinator is finalizing the ceremony, otherwise false.
|
|
1357
1203
|
* @returns <string> - the public attestation preamble.
|
|
1358
1204
|
*/
|
|
1359
|
-
const getPublicAttestationPreambleForContributor = (contributorIdentifier, ceremonyName, isFinalizing) => `Hey, I'm ${contributorIdentifier} and I have ${isFinalizing ? "finalized" : "contributed to"} the ${ceremonyName}
|
|
1205
|
+
const getPublicAttestationPreambleForContributor = (contributorIdentifier, ceremonyName, isFinalizing) => `Hey, I'm ${contributorIdentifier} and I have ${isFinalizing ? "finalized" : "contributed to"} the ${ceremonyName}${ceremonyName.toLowerCase().includes("trusted setup") || ceremonyName.toLowerCase().includes("ceremony")
|
|
1206
|
+
? "."
|
|
1207
|
+
: " MPC Phase2 Trusted Setup ceremony."}\nThe following are my contribution signatures:`;
|
|
1360
1208
|
/**
|
|
1361
1209
|
* Check and prepare public attestation for the contributor made only of its valid contributions.
|
|
1362
1210
|
* @param firestoreDatabase <Firestore> - the Firestore service instance associated to the current Firebase application.
|
|
@@ -1427,6 +1275,41 @@ const readBytesFromFile = (localFilePath, offset, length, position) => {
|
|
|
1427
1275
|
// Return the read bytes.
|
|
1428
1276
|
return buffer;
|
|
1429
1277
|
};
|
|
1278
|
+
/**
|
|
1279
|
+
* Given a buffer in little endian format, convert it to bigint
|
|
1280
|
+
* @param buffer
|
|
1281
|
+
* @returns
|
|
1282
|
+
*/
|
|
1283
|
+
function leBufferToBigint(buffer) {
|
|
1284
|
+
return BigInt(`0x${buffer.reverse().toString("hex")}`);
|
|
1285
|
+
}
|
|
1286
|
+
/**
|
|
1287
|
+
* Given an input containing string values, convert them
|
|
1288
|
+
* to bigint
|
|
1289
|
+
* @param input - The input to convert
|
|
1290
|
+
* @returns the input with string values converted to bigint
|
|
1291
|
+
*/
|
|
1292
|
+
const unstringifyBigInts = (input) => {
|
|
1293
|
+
if (typeof input === "string" && /^[0-9]+$/.test(input)) {
|
|
1294
|
+
return BigInt(input);
|
|
1295
|
+
}
|
|
1296
|
+
if (typeof input === "string" && /^0x[0-9a-fA-F]+$/.test(input)) {
|
|
1297
|
+
return BigInt(input);
|
|
1298
|
+
}
|
|
1299
|
+
if (Array.isArray(input)) {
|
|
1300
|
+
return input.map(unstringifyBigInts);
|
|
1301
|
+
}
|
|
1302
|
+
if (input === null) {
|
|
1303
|
+
return null;
|
|
1304
|
+
}
|
|
1305
|
+
if (typeof input === "object") {
|
|
1306
|
+
return Object.entries(input).reduce((acc, [key, value]) => {
|
|
1307
|
+
acc[key] = unstringifyBigInts(value);
|
|
1308
|
+
return acc;
|
|
1309
|
+
}, {});
|
|
1310
|
+
}
|
|
1311
|
+
return input;
|
|
1312
|
+
};
|
|
1430
1313
|
/**
|
|
1431
1314
|
* Return the info about the R1CS file.ù
|
|
1432
1315
|
* @dev this method was built taking inspiration from
|
|
@@ -1487,17 +1370,17 @@ const getR1CSInfo = (localR1CSFilePath) => {
|
|
|
1487
1370
|
let constraints = 0;
|
|
1488
1371
|
try {
|
|
1489
1372
|
// Get 'number of section' (jump magic r1cs and version1 data).
|
|
1490
|
-
const numberOfSections =
|
|
1373
|
+
const numberOfSections = leBufferToBigint(readBytesFromFile(localR1CSFilePath, 0, 4, 8));
|
|
1491
1374
|
// Jump to first section.
|
|
1492
1375
|
pointer = 12;
|
|
1493
1376
|
// For each section
|
|
1494
1377
|
for (let i = 0; i < numberOfSections; i++) {
|
|
1495
1378
|
// Read section type.
|
|
1496
|
-
const sectionType =
|
|
1379
|
+
const sectionType = leBufferToBigint(readBytesFromFile(localR1CSFilePath, 0, 4, pointer));
|
|
1497
1380
|
// Jump to section size.
|
|
1498
1381
|
pointer += 4;
|
|
1499
1382
|
// Read section size
|
|
1500
|
-
const sectionSize = Number(
|
|
1383
|
+
const sectionSize = Number(leBufferToBigint(readBytesFromFile(localR1CSFilePath, 0, 8, pointer)));
|
|
1501
1384
|
// If at header section (0x00000001 : Header Section).
|
|
1502
1385
|
if (sectionType === BigInt(1)) {
|
|
1503
1386
|
// Read info from header section.
|
|
@@ -1529,22 +1412,22 @@ const getR1CSInfo = (localR1CSFilePath) => {
|
|
|
1529
1412
|
*/
|
|
1530
1413
|
pointer += sectionSize - 20;
|
|
1531
1414
|
// Read R1CS info.
|
|
1532
|
-
wires = Number(
|
|
1415
|
+
wires = Number(leBufferToBigint(readBytesFromFile(localR1CSFilePath, 0, 4, pointer)));
|
|
1533
1416
|
pointer += 4;
|
|
1534
|
-
publicOutputs = Number(
|
|
1417
|
+
publicOutputs = Number(leBufferToBigint(readBytesFromFile(localR1CSFilePath, 0, 4, pointer)));
|
|
1535
1418
|
pointer += 4;
|
|
1536
|
-
publicInputs = Number(
|
|
1419
|
+
publicInputs = Number(leBufferToBigint(readBytesFromFile(localR1CSFilePath, 0, 4, pointer)));
|
|
1537
1420
|
pointer += 4;
|
|
1538
|
-
privateInputs = Number(
|
|
1421
|
+
privateInputs = Number(leBufferToBigint(readBytesFromFile(localR1CSFilePath, 0, 4, pointer)));
|
|
1539
1422
|
pointer += 4;
|
|
1540
|
-
labels = Number(
|
|
1423
|
+
labels = Number(leBufferToBigint(readBytesFromFile(localR1CSFilePath, 0, 8, pointer)));
|
|
1541
1424
|
pointer += 8;
|
|
1542
|
-
constraints = Number(
|
|
1425
|
+
constraints = Number(leBufferToBigint(readBytesFromFile(localR1CSFilePath, 0, 4, pointer)));
|
|
1543
1426
|
}
|
|
1544
1427
|
pointer += 8 + Number(sectionSize);
|
|
1545
1428
|
}
|
|
1546
1429
|
return {
|
|
1547
|
-
curve: "bn-128",
|
|
1430
|
+
curve: "bn-128", /// @note currently default to bn-128 as we support only Groth16 proving system.
|
|
1548
1431
|
wires,
|
|
1549
1432
|
constraints,
|
|
1550
1433
|
privateInputs,
|
|
@@ -1559,11 +1442,194 @@ const getR1CSInfo = (localR1CSFilePath) => {
|
|
|
1559
1442
|
}
|
|
1560
1443
|
};
|
|
1561
1444
|
/**
|
|
1562
|
-
*
|
|
1563
|
-
* @
|
|
1564
|
-
* @
|
|
1445
|
+
* Parse and validate that the ceremony configuration is correct
|
|
1446
|
+
* @notice this does not upload any files to storage
|
|
1447
|
+
* @param path <string> - the path to the configuration file
|
|
1448
|
+
* @param cleanup <boolean> - whether to delete the r1cs file after parsing
|
|
1449
|
+
* @returns any - the data to pass to the cloud function for setup and the circuit artifacts
|
|
1565
1450
|
*/
|
|
1566
|
-
const
|
|
1451
|
+
const parseCeremonyFile = async (path, cleanup = false) => {
|
|
1452
|
+
// check that the path exists
|
|
1453
|
+
if (!fs.existsSync(path))
|
|
1454
|
+
throw new Error("The provided path to the configuration file does not exist. Please provide an absolute path and try again.");
|
|
1455
|
+
try {
|
|
1456
|
+
// read the data
|
|
1457
|
+
const data = JSON.parse(fs.readFileSync(path).toString());
|
|
1458
|
+
// verify that the data is correct
|
|
1459
|
+
if (data.timeoutMechanismType !== "DYNAMIC" /* CeremonyTimeoutType.DYNAMIC */ &&
|
|
1460
|
+
data.timeoutMechanismType !== "FIXED" /* CeremonyTimeoutType.FIXED */)
|
|
1461
|
+
throw new Error("Invalid timeout type. Please choose between DYNAMIC and FIXED.");
|
|
1462
|
+
// validate that we have at least 1 circuit input data
|
|
1463
|
+
if (!data.circuits || data.circuits.length === 0)
|
|
1464
|
+
throw new Error("You need to provide the data for at least 1 circuit.");
|
|
1465
|
+
// validate that the end date is in the future
|
|
1466
|
+
let endDate;
|
|
1467
|
+
let startDate;
|
|
1468
|
+
try {
|
|
1469
|
+
endDate = new Date(data.endDate);
|
|
1470
|
+
startDate = new Date(data.startDate);
|
|
1471
|
+
}
|
|
1472
|
+
catch (error) {
|
|
1473
|
+
throw new Error("The dates should follow this format: 2023-07-04T00:00:00.");
|
|
1474
|
+
}
|
|
1475
|
+
if (endDate <= startDate)
|
|
1476
|
+
throw new Error("The end date should be greater than the start date.");
|
|
1477
|
+
const currentDate = new Date();
|
|
1478
|
+
if (endDate <= currentDate || startDate <= currentDate)
|
|
1479
|
+
throw new Error("The start and end dates should be in the future.");
|
|
1480
|
+
// validate penalty
|
|
1481
|
+
if (data.penalty <= 0)
|
|
1482
|
+
throw new Error("The penalty should be greater than zero.");
|
|
1483
|
+
const circuits = [];
|
|
1484
|
+
const urlPattern = /(https?:\/\/[^\s]+)/g;
|
|
1485
|
+
const commitHashPattern = /^[a-f0-9]{40}$/i;
|
|
1486
|
+
const circuitArtifacts = [];
|
|
1487
|
+
for (let i = 0; i < data.circuits.length; i++) {
|
|
1488
|
+
const circuitData = data.circuits[i];
|
|
1489
|
+
const { artifacts } = circuitData;
|
|
1490
|
+
circuitArtifacts.push({
|
|
1491
|
+
artifacts
|
|
1492
|
+
});
|
|
1493
|
+
// where we storing the r1cs downloaded
|
|
1494
|
+
const localR1csPath = `./${circuitData.name}.r1cs`;
|
|
1495
|
+
// where we storing the wasm downloaded
|
|
1496
|
+
const localWasmPath = `./${circuitData.name}.wasm`;
|
|
1497
|
+
// download the r1cs to extract the metadata
|
|
1498
|
+
const streamPipeline = util.promisify(stream.pipeline);
|
|
1499
|
+
// Make the call.
|
|
1500
|
+
const responseR1CS = await fetch(artifacts.r1csStoragePath);
|
|
1501
|
+
// Handle errors.
|
|
1502
|
+
if (!responseR1CS.ok && responseR1CS.status !== 200)
|
|
1503
|
+
throw new Error(`There was an error while trying to download the r1cs file for circuit ${circuitData.name}. Please check that the file has the correct permissions (public) set.`);
|
|
1504
|
+
await streamPipeline(responseR1CS.body, fs.createWriteStream(localR1csPath));
|
|
1505
|
+
// Write the file locally
|
|
1506
|
+
// extract the metadata from the r1cs
|
|
1507
|
+
const metadata = getR1CSInfo(localR1csPath);
|
|
1508
|
+
// download wasm too to ensure it's available
|
|
1509
|
+
const responseWASM = await fetch(artifacts.wasmStoragePath);
|
|
1510
|
+
if (!responseWASM.ok && responseWASM.status !== 200)
|
|
1511
|
+
throw new Error(`There was an error while trying to download the WASM file for circuit ${circuitData.name}. Please check that the file has the correct permissions (public) set.`);
|
|
1512
|
+
await streamPipeline(responseWASM.body, fs.createWriteStream(localWasmPath));
|
|
1513
|
+
// validate that the circuit hash and template links are valid
|
|
1514
|
+
const { template } = circuitData;
|
|
1515
|
+
const URLMatch = template.source.match(urlPattern);
|
|
1516
|
+
if (!URLMatch || URLMatch.length === 0 || URLMatch.length > 1)
|
|
1517
|
+
throw new Error("You should provide the URL to the circuits templates on GitHub.");
|
|
1518
|
+
const hashMatch = template.commitHash.match(commitHashPattern);
|
|
1519
|
+
if (!hashMatch || hashMatch.length === 0 || hashMatch.length > 1)
|
|
1520
|
+
throw new Error("You should provide a valid commit hash of the circuit templates.");
|
|
1521
|
+
// calculate the hash of the r1cs file
|
|
1522
|
+
const r1csBlake2bHash = await blake512FromPath(localR1csPath);
|
|
1523
|
+
const circuitPrefix = extractPrefix(circuitData.name);
|
|
1524
|
+
// filenames
|
|
1525
|
+
const doubleDigitsPowers = convertToDoubleDigits(metadata.pot);
|
|
1526
|
+
const r1csCompleteFilename = `${circuitData.name}.r1cs`;
|
|
1527
|
+
const wasmCompleteFilename = `${circuitData.name}.wasm`;
|
|
1528
|
+
const smallestPowersOfTauCompleteFilenameForCircuit = `${potFilenameTemplate}${doubleDigitsPowers}.ptau`;
|
|
1529
|
+
const firstZkeyCompleteFilename = `${circuitPrefix}_${genesisZkeyIndex}.zkey`;
|
|
1530
|
+
// storage paths
|
|
1531
|
+
const r1csStorageFilePath = getR1csStorageFilePath(circuitPrefix, r1csCompleteFilename);
|
|
1532
|
+
const wasmStorageFilePath = getWasmStorageFilePath(circuitPrefix, wasmCompleteFilename);
|
|
1533
|
+
const potStorageFilePath = getPotStorageFilePath(smallestPowersOfTauCompleteFilenameForCircuit);
|
|
1534
|
+
const zkeyStorageFilePath = getZkeyStorageFilePath(circuitPrefix, firstZkeyCompleteFilename);
|
|
1535
|
+
const files = {
|
|
1536
|
+
potFilename: smallestPowersOfTauCompleteFilenameForCircuit,
|
|
1537
|
+
r1csFilename: r1csCompleteFilename,
|
|
1538
|
+
wasmFilename: wasmCompleteFilename,
|
|
1539
|
+
initialZkeyFilename: firstZkeyCompleteFilename,
|
|
1540
|
+
potStoragePath: potStorageFilePath,
|
|
1541
|
+
r1csStoragePath: r1csStorageFilePath,
|
|
1542
|
+
wasmStoragePath: wasmStorageFilePath,
|
|
1543
|
+
initialZkeyStoragePath: zkeyStorageFilePath,
|
|
1544
|
+
r1csBlake2bHash
|
|
1545
|
+
};
|
|
1546
|
+
// validate that the compiler hash is a valid hash
|
|
1547
|
+
const { compiler } = circuitData;
|
|
1548
|
+
const compilerHashMatch = compiler.commitHash.match(commitHashPattern);
|
|
1549
|
+
if (!compilerHashMatch || compilerHashMatch.length === 0 || compilerHashMatch.length > 1)
|
|
1550
|
+
throw new Error("You should provide a valid commit hash of the circuit compiler.");
|
|
1551
|
+
// validate that the verification options are valid
|
|
1552
|
+
const { verification } = circuitData;
|
|
1553
|
+
if (verification.cfOrVm !== "CF" && verification.cfOrVm !== "VM")
|
|
1554
|
+
throw new Error("Please enter a valid verification mechanism: either CF or VM");
|
|
1555
|
+
// @todo VM parameters verification
|
|
1556
|
+
// if (verification['cfOrVM'] === "VM") {}
|
|
1557
|
+
// check that the timeout is provided for the correct configuration
|
|
1558
|
+
let dynamicThreshold;
|
|
1559
|
+
let fixedTimeWindow;
|
|
1560
|
+
let circuit = {};
|
|
1561
|
+
if (data.timeoutMechanismType === "DYNAMIC" /* CeremonyTimeoutType.DYNAMIC */) {
|
|
1562
|
+
if (circuitData.dynamicThreshold <= 0)
|
|
1563
|
+
throw new Error("The dynamic threshold should be > 0.");
|
|
1564
|
+
dynamicThreshold = circuitData.dynamicThreshold;
|
|
1565
|
+
// the Circuit data for the ceremony setup
|
|
1566
|
+
circuit = {
|
|
1567
|
+
name: circuitData.name,
|
|
1568
|
+
description: circuitData.description,
|
|
1569
|
+
prefix: circuitPrefix,
|
|
1570
|
+
sequencePosition: i + 1,
|
|
1571
|
+
metadata,
|
|
1572
|
+
files,
|
|
1573
|
+
template,
|
|
1574
|
+
compiler,
|
|
1575
|
+
verification,
|
|
1576
|
+
dynamicThreshold,
|
|
1577
|
+
avgTimings: {
|
|
1578
|
+
contributionComputation: 0,
|
|
1579
|
+
fullContribution: 0,
|
|
1580
|
+
verifyCloudFunction: 0
|
|
1581
|
+
}
|
|
1582
|
+
};
|
|
1583
|
+
}
|
|
1584
|
+
if (data.timeoutMechanismType === "FIXED" /* CeremonyTimeoutType.FIXED */) {
|
|
1585
|
+
if (circuitData.fixedTimeWindow <= 0)
|
|
1586
|
+
throw new Error("The fixed time window threshold should be > 0.");
|
|
1587
|
+
fixedTimeWindow = circuitData.fixedTimeWindow;
|
|
1588
|
+
// the Circuit data for the ceremony setup
|
|
1589
|
+
circuit = {
|
|
1590
|
+
name: circuitData.name,
|
|
1591
|
+
description: circuitData.description,
|
|
1592
|
+
prefix: circuitPrefix,
|
|
1593
|
+
sequencePosition: i + 1,
|
|
1594
|
+
metadata,
|
|
1595
|
+
files,
|
|
1596
|
+
template,
|
|
1597
|
+
compiler,
|
|
1598
|
+
verification,
|
|
1599
|
+
fixedTimeWindow,
|
|
1600
|
+
avgTimings: {
|
|
1601
|
+
contributionComputation: 0,
|
|
1602
|
+
fullContribution: 0,
|
|
1603
|
+
verifyCloudFunction: 0
|
|
1604
|
+
}
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
circuits.push(circuit);
|
|
1608
|
+
// remove the local r1cs and wasm downloads (if used for verifying the config only vs setup)
|
|
1609
|
+
if (cleanup) {
|
|
1610
|
+
fs.unlinkSync(localR1csPath);
|
|
1611
|
+
fs.unlinkSync(localWasmPath);
|
|
1612
|
+
}
|
|
1613
|
+
}
|
|
1614
|
+
const setupData = {
|
|
1615
|
+
ceremonyInputData: {
|
|
1616
|
+
title: data.title,
|
|
1617
|
+
description: data.description,
|
|
1618
|
+
startDate: startDate.valueOf(),
|
|
1619
|
+
endDate: endDate.valueOf(),
|
|
1620
|
+
timeoutMechanismType: data.timeoutMechanismType,
|
|
1621
|
+
penalty: data.penalty
|
|
1622
|
+
},
|
|
1623
|
+
ceremonyPrefix: extractPrefix(data.title),
|
|
1624
|
+
circuits,
|
|
1625
|
+
circuitArtifacts
|
|
1626
|
+
};
|
|
1627
|
+
return setupData;
|
|
1628
|
+
}
|
|
1629
|
+
catch (error) {
|
|
1630
|
+
throw new Error(`Error while parsing up the ceremony setup file. ${error.message}`);
|
|
1631
|
+
}
|
|
1632
|
+
};
|
|
1567
1633
|
|
|
1568
1634
|
/**
|
|
1569
1635
|
* Verify that a zKey is valid
|
|
@@ -1812,7 +1878,7 @@ const getFirestoreDatabase = (app) => firestore.getFirestore(app);
|
|
|
1812
1878
|
* @param app <FirebaseApp> - the Firebase application.
|
|
1813
1879
|
* @returns <Functions> - the Cloud Functions associated to the application.
|
|
1814
1880
|
*/
|
|
1815
|
-
const getFirebaseFunctions = (app) => functions.getFunctions(app,
|
|
1881
|
+
const getFirebaseFunctions = (app) => functions.getFunctions(app, "europe-west1");
|
|
1816
1882
|
/**
|
|
1817
1883
|
* Retrieve the configuration variables for the AWS services (S3, EC2).
|
|
1818
1884
|
* @returns <AWSVariables> - the values of the AWS services configuration variables.
|
|
@@ -1821,14 +1887,14 @@ const getAWSVariables = () => {
|
|
|
1821
1887
|
if (!process.env.AWS_ACCESS_KEY_ID ||
|
|
1822
1888
|
!process.env.AWS_SECRET_ACCESS_KEY ||
|
|
1823
1889
|
!process.env.AWS_REGION ||
|
|
1824
|
-
!process.env.
|
|
1890
|
+
!process.env.AWS_INSTANCE_PROFILE_ARN ||
|
|
1825
1891
|
!process.env.AWS_AMI_ID)
|
|
1826
1892
|
throw new Error("Could not retrieve the AWS environment variables. Please, verify your environment configuration and retry");
|
|
1827
1893
|
return {
|
|
1828
1894
|
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
1829
1895
|
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
1830
1896
|
region: process.env.AWS_REGION || "us-east-1",
|
|
1831
|
-
|
|
1897
|
+
instanceProfileArn: process.env.AWS_INSTANCE_PROFILE_ARN,
|
|
1832
1898
|
amiId: process.env.AWS_AMI_ID
|
|
1833
1899
|
};
|
|
1834
1900
|
};
|
|
@@ -1909,11 +1975,11 @@ const p256 = (proofPart) => {
|
|
|
1909
1975
|
*/
|
|
1910
1976
|
const formatSolidityCalldata = (circuitInput, _proof) => {
|
|
1911
1977
|
try {
|
|
1912
|
-
const proof =
|
|
1978
|
+
const proof = unstringifyBigInts(_proof);
|
|
1913
1979
|
// format the public inputs to the circuit
|
|
1914
1980
|
const formattedCircuitInput = [];
|
|
1915
1981
|
for (const cInput of circuitInput) {
|
|
1916
|
-
formattedCircuitInput.push(p256(
|
|
1982
|
+
formattedCircuitInput.push(p256(unstringifyBigInts(cInput)));
|
|
1917
1983
|
}
|
|
1918
1984
|
// construct calldata
|
|
1919
1985
|
const calldata = {
|
|
@@ -2063,55 +2129,28 @@ const verifyCeremony = async (functions, firestore$1, ceremonyPrefix, outputDire
|
|
|
2063
2129
|
};
|
|
2064
2130
|
|
|
2065
2131
|
/**
|
|
2066
|
-
* This function
|
|
2067
|
-
* @param user
|
|
2068
|
-
* @returns
|
|
2069
|
-
*/
|
|
2070
|
-
const getNumberOfPublicReposGitHub = async (user) => {
|
|
2071
|
-
const response = await fetch(`https://api.github.com/user/${user}/repos`, {
|
|
2072
|
-
method: "GET",
|
|
2073
|
-
headers: {
|
|
2074
|
-
Authorization: `token ${process.env.GITHUB_ACCESS_TOKEN}`
|
|
2075
|
-
}
|
|
2076
|
-
});
|
|
2077
|
-
if (response.status !== 200)
|
|
2078
|
-
throw new Error("It was not possible to retrieve the number of public repositories. Please try again.");
|
|
2079
|
-
const jsonData = await response.json();
|
|
2080
|
-
return jsonData.length;
|
|
2081
|
-
};
|
|
2082
|
-
/**
|
|
2083
|
-
* This function will return the number of followers of a user
|
|
2084
|
-
* @param user <string> The username of the user
|
|
2085
|
-
* @returns <number> The number of followers
|
|
2086
|
-
*/
|
|
2087
|
-
const getNumberOfFollowersGitHub = async (user) => {
|
|
2088
|
-
const response = await fetch(`https://api.github.com/user/${user}/followers`, {
|
|
2089
|
-
method: "GET",
|
|
2090
|
-
headers: {
|
|
2091
|
-
Authorization: `token ${process.env.GITHUB_ACCESS_TOKEN}`
|
|
2092
|
-
}
|
|
2093
|
-
});
|
|
2094
|
-
if (response.status !== 200)
|
|
2095
|
-
throw new Error("It was not possible to retrieve the number of followers. Please try again.");
|
|
2096
|
-
const jsonData = await response.json();
|
|
2097
|
-
return jsonData.length;
|
|
2098
|
-
};
|
|
2099
|
-
/**
|
|
2100
|
-
* This function will return the number of following of a user
|
|
2101
|
-
* @param user <string> The username of the user
|
|
2102
|
-
* @returns <number> The number of following users
|
|
2132
|
+
* This function queries the GitHub API to fetch users statistics
|
|
2133
|
+
* @param user {string} the user uid
|
|
2134
|
+
* @returns {any} the stats from the GitHub API
|
|
2103
2135
|
*/
|
|
2104
|
-
const
|
|
2105
|
-
const response = await fetch(`https://api.github.com/user/${user}
|
|
2136
|
+
const getGitHubStats = async (user) => {
|
|
2137
|
+
const response = await fetch(`https://api.github.com/user/${user}`, {
|
|
2106
2138
|
method: "GET",
|
|
2107
2139
|
headers: {
|
|
2108
2140
|
Authorization: `token ${process.env.GITHUB_ACCESS_TOKEN}`
|
|
2109
2141
|
}
|
|
2110
2142
|
});
|
|
2111
2143
|
if (response.status !== 200)
|
|
2112
|
-
throw new Error("It was not possible to retrieve the
|
|
2144
|
+
throw new Error("It was not possible to retrieve the user's statistic. Please try again.");
|
|
2113
2145
|
const jsonData = await response.json();
|
|
2114
|
-
|
|
2146
|
+
const data = {
|
|
2147
|
+
following: jsonData.following,
|
|
2148
|
+
followers: jsonData.followers,
|
|
2149
|
+
publicRepos: jsonData.public_repos,
|
|
2150
|
+
avatarUrl: jsonData.avatar_url,
|
|
2151
|
+
age: jsonData.created_at
|
|
2152
|
+
};
|
|
2153
|
+
return data;
|
|
2115
2154
|
};
|
|
2116
2155
|
/**
|
|
2117
2156
|
* This function will check if the user is reputable enough to be able to use the app
|
|
@@ -2119,19 +2158,24 @@ const getNumberOfFollowingGitHub = async (user) => {
|
|
|
2119
2158
|
* @param minimumAmountOfFollowing <number> The minimum amount of following the user should have
|
|
2120
2159
|
* @param minimumAmountOfFollowers <number> The minimum amount of followers the user should have
|
|
2121
2160
|
* @param minimumAmountOfPublicRepos <number> The minimum amount of public repos the user should have
|
|
2122
|
-
* @returns <
|
|
2161
|
+
* @returns <any> Return the avatar URL of the user if the user is reputable, false otherwise
|
|
2123
2162
|
*/
|
|
2124
|
-
const githubReputation = async (userLogin, minimumAmountOfFollowing, minimumAmountOfFollowers, minimumAmountOfPublicRepos) => {
|
|
2163
|
+
const githubReputation = async (userLogin, minimumAmountOfFollowing, minimumAmountOfFollowers, minimumAmountOfPublicRepos, minimumAge) => {
|
|
2125
2164
|
if (!process.env.GITHUB_ACCESS_TOKEN)
|
|
2126
2165
|
throw new Error("The GitHub access token is missing. Please insert a valid token to be used for anti-sybil checks on user registation, and then try again.");
|
|
2127
|
-
const following = await
|
|
2128
|
-
const repos = await getNumberOfPublicReposGitHub(userLogin);
|
|
2129
|
-
const followers = await getNumberOfFollowersGitHub(userLogin);
|
|
2166
|
+
const { following, followers, publicRepos, avatarUrl, age } = await getGitHubStats(userLogin);
|
|
2130
2167
|
if (following < minimumAmountOfFollowing ||
|
|
2131
|
-
|
|
2132
|
-
followers < minimumAmountOfFollowers
|
|
2133
|
-
|
|
2134
|
-
|
|
2168
|
+
publicRepos < minimumAmountOfPublicRepos ||
|
|
2169
|
+
followers < minimumAmountOfFollowers ||
|
|
2170
|
+
new Date(age) > new Date(Date.now() - minimumAge))
|
|
2171
|
+
return {
|
|
2172
|
+
reputable: false,
|
|
2173
|
+
avatarUrl: ""
|
|
2174
|
+
};
|
|
2175
|
+
return {
|
|
2176
|
+
reputable: true,
|
|
2177
|
+
avatarUrl
|
|
2178
|
+
};
|
|
2135
2179
|
};
|
|
2136
2180
|
|
|
2137
2181
|
/**
|
|
@@ -2317,8 +2361,8 @@ const createSSMClient = async () => {
|
|
|
2317
2361
|
* @returns <Array<string>> - the list of startup commands to be executed.
|
|
2318
2362
|
*/
|
|
2319
2363
|
const vmBootstrapCommand = (bucketName) => [
|
|
2320
|
-
"#!/bin/bash",
|
|
2321
|
-
`aws s3 cp s3://${bucketName}/${vmBootstrapScriptFilename} ${vmBootstrapScriptFilename}`,
|
|
2364
|
+
"#!/bin/bash", // shabang.
|
|
2365
|
+
`aws s3 cp s3://${bucketName}/${vmBootstrapScriptFilename} ${vmBootstrapScriptFilename}`, // copy file from S3 bucket to VM.
|
|
2322
2366
|
`chmod +x ${vmBootstrapScriptFilename} && bash ${vmBootstrapScriptFilename}` // grant permission and execute.
|
|
2323
2367
|
];
|
|
2324
2368
|
/**
|
|
@@ -2339,8 +2383,13 @@ const vmDependenciesAndCacheArtifactsCommand = (zKeyPath, potPath, snsTopic, reg
|
|
|
2339
2383
|
// eslint-disable-next-line no-template-curly-in-string
|
|
2340
2384
|
"touch ${MARKER_FILE}",
|
|
2341
2385
|
"sudo yum update -y",
|
|
2342
|
-
"curl -
|
|
2343
|
-
"
|
|
2386
|
+
"curl -O https://nodejs.org/dist/v16.13.0/node-v16.13.0-linux-x64.tar.xz",
|
|
2387
|
+
"tar -xf node-v16.13.0-linux-x64.tar.xz",
|
|
2388
|
+
"mv node-v16.13.0-linux-x64 nodejs",
|
|
2389
|
+
"sudo mv nodejs /opt/",
|
|
2390
|
+
"echo 'export NODEJS_HOME=/opt/nodejs' >> /etc/profile",
|
|
2391
|
+
"echo 'export PATH=$NODEJS_HOME/bin:$PATH' >> /etc/profile",
|
|
2392
|
+
"source /etc/profile",
|
|
2344
2393
|
"npm install -g snarkjs",
|
|
2345
2394
|
`aws s3 cp s3://${zKeyPath} /var/tmp/genesisZkey.zkey`,
|
|
2346
2395
|
`aws s3 cp s3://${potPath} /var/tmp/pot.ptau`,
|
|
@@ -2359,6 +2408,7 @@ const vmDependenciesAndCacheArtifactsCommand = (zKeyPath, potPath, snsTopic, reg
|
|
|
2359
2408
|
* @returns Array<string> - the list of commands for contribution verification.
|
|
2360
2409
|
*/
|
|
2361
2410
|
const vmContributionVerificationCommand = (bucketName, lastZkeyStoragePath, verificationTranscriptStoragePathAndFilename) => [
|
|
2411
|
+
`source /etc/profile`,
|
|
2362
2412
|
`aws s3 cp s3://${bucketName}/${lastZkeyStoragePath} /var/tmp/lastZKey.zkey > /var/tmp/log.txt`,
|
|
2363
2413
|
`snarkjs zkvi /var/tmp/genesisZkey.zkey /var/tmp/pot.ptau /var/tmp/lastZKey.zkey > /var/tmp/verification_transcript.log`,
|
|
2364
2414
|
`aws s3 cp /var/tmp/verification_transcript.log s3://${bucketName}/${verificationTranscriptStoragePathAndFilename} &>/dev/null`,
|
|
@@ -2385,7 +2435,7 @@ const computeDiskSizeForVM = (zKeySizeInBytes, pot) => Math.ceil(2 * convertByte
|
|
|
2385
2435
|
*/
|
|
2386
2436
|
const createEC2Instance = async (ec2, commands, instanceType, volumeSize, diskType) => {
|
|
2387
2437
|
// Get the AWS variables.
|
|
2388
|
-
const { amiId,
|
|
2438
|
+
const { amiId, instanceProfileArn } = getAWSVariables();
|
|
2389
2439
|
// Parametrize the VM EC2 instance.
|
|
2390
2440
|
const params = {
|
|
2391
2441
|
ImageId: amiId,
|
|
@@ -2394,7 +2444,7 @@ const createEC2Instance = async (ec2, commands, instanceType, volumeSize, diskTy
|
|
|
2394
2444
|
MinCount: 1,
|
|
2395
2445
|
// nb. to find this: iam -> roles -> role_name.
|
|
2396
2446
|
IamInstanceProfile: {
|
|
2397
|
-
Arn:
|
|
2447
|
+
Arn: instanceProfileArn
|
|
2398
2448
|
},
|
|
2399
2449
|
// nb. for running commands at the startup.
|
|
2400
2450
|
UserData: Buffer.from(commands.join("\n")).toString("base64"),
|
|
@@ -2403,7 +2453,7 @@ const createEC2Instance = async (ec2, commands, instanceType, volumeSize, diskTy
|
|
|
2403
2453
|
DeviceName: "/dev/xvda",
|
|
2404
2454
|
Ebs: {
|
|
2405
2455
|
DeleteOnTermination: true,
|
|
2406
|
-
VolumeSize: volumeSize,
|
|
2456
|
+
VolumeSize: volumeSize, // disk size in GB.
|
|
2407
2457
|
VolumeType: diskType
|
|
2408
2458
|
}
|
|
2409
2459
|
}
|
|
@@ -2631,6 +2681,7 @@ exports.generatePreSignedUrlsParts = generatePreSignedUrlsParts;
|
|
|
2631
2681
|
exports.generateValidContributionsAttestation = generateValidContributionsAttestation;
|
|
2632
2682
|
exports.generateZkeyFromScratch = generateZkeyFromScratch;
|
|
2633
2683
|
exports.genesisZkeyIndex = genesisZkeyIndex;
|
|
2684
|
+
exports.getAllCeremonies = getAllCeremonies;
|
|
2634
2685
|
exports.getAllCollectionDocs = getAllCollectionDocs;
|
|
2635
2686
|
exports.getBucketName = getBucketName;
|
|
2636
2687
|
exports.getCeremonyCircuits = getCeremonyCircuits;
|