@devtion/actions 0.0.0-bfc9ee4 → 0.0.0-c749be4
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 +265 -280
- package/dist/index.node.js +265 -280
- package/dist/types/src/helpers/constants.d.ts +6 -0
- package/dist/types/src/helpers/constants.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 +19 -19
- package/dist/types/src/helpers/utils.d.ts.map +1 -1
- package/dist/types/src/helpers/vm.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +2 -2
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/package.json +2 -6
- package/src/helpers/constants.ts +7 -1
- 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 +262 -268
- package/src/helpers/vm.ts +11 -5
- package/src/index.ts +2 -2
- package/src/types/index.ts +11 -7
package/dist/index.node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @module @
|
|
3
|
-
* @version 1.0
|
|
2
|
+
* @module @devtion/actions
|
|
3
|
+
* @version 1.1.0
|
|
4
4
|
* @file A set of actions and helpers for CLI commands
|
|
5
5
|
* @copyright Ethereum Foundation 2022
|
|
6
6
|
* @license MIT
|
|
@@ -19,7 +19,6 @@ var crypto = require('crypto');
|
|
|
19
19
|
var blake = require('blakejs');
|
|
20
20
|
var ffjavascript = require('ffjavascript');
|
|
21
21
|
var winston = require('winston');
|
|
22
|
-
var clientS3 = require('@aws-sdk/client-s3');
|
|
23
22
|
var stream = require('stream');
|
|
24
23
|
var util = require('util');
|
|
25
24
|
var app = require('firebase/app');
|
|
@@ -246,6 +245,12 @@ const commonTerms = {
|
|
|
246
245
|
verificationStartedAt: "verificationStartedAt"
|
|
247
246
|
}
|
|
248
247
|
},
|
|
248
|
+
avatars: {
|
|
249
|
+
name: "avatars",
|
|
250
|
+
fields: {
|
|
251
|
+
avatarUrl: "avatarUrl"
|
|
252
|
+
}
|
|
253
|
+
},
|
|
249
254
|
ceremonies: {
|
|
250
255
|
name: "ceremonies",
|
|
251
256
|
fields: {
|
|
@@ -336,7 +341,7 @@ const commonTerms = {
|
|
|
336
341
|
finalizeCircuit: "finalizeCircuit",
|
|
337
342
|
finalizeCeremony: "finalizeCeremony",
|
|
338
343
|
downloadCircuitArtifacts: "downloadCircuitArtifacts",
|
|
339
|
-
transferObject: "transferObject"
|
|
344
|
+
transferObject: "transferObject"
|
|
340
345
|
}
|
|
341
346
|
};
|
|
342
347
|
|
|
@@ -687,11 +692,15 @@ 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.
|
|
@@ -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
|
};
|
|
@@ -1040,207 +1053,22 @@ const compareHashes = async (path1, path2) => {
|
|
|
1040
1053
|
};
|
|
1041
1054
|
|
|
1042
1055
|
/**
|
|
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
|
|
1056
|
+
* Return a string with double digits if the provided input is one digit only.
|
|
1057
|
+
* @param in <number> - the input number to be converted.
|
|
1058
|
+
* @returns <string> - the two digits stringified number derived from the conversion.
|
|
1048
1059
|
*/
|
|
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
|
-
let circuit = {};
|
|
1174
|
-
if (data.timeoutMechanismType === "DYNAMIC" /* CeremonyTimeoutType.DYNAMIC */) {
|
|
1175
|
-
if (circuitData.dynamicThreshold <= 0)
|
|
1176
|
-
throw new Error("The dynamic threshold should be > 0.");
|
|
1177
|
-
dynamicThreshold = circuitData.dynamicThreshold;
|
|
1178
|
-
// the Circuit data for the ceremony setup
|
|
1179
|
-
circuit = {
|
|
1180
|
-
name: circuitData.name,
|
|
1181
|
-
description: circuitData.description,
|
|
1182
|
-
prefix: circuitPrefix,
|
|
1183
|
-
sequencePosition: i + 1,
|
|
1184
|
-
metadata: metadata,
|
|
1185
|
-
files: files,
|
|
1186
|
-
template: template,
|
|
1187
|
-
compiler: compiler,
|
|
1188
|
-
verification: verification,
|
|
1189
|
-
dynamicThreshold: dynamicThreshold,
|
|
1190
|
-
avgTimings: {
|
|
1191
|
-
contributionComputation: 0,
|
|
1192
|
-
fullContribution: 0,
|
|
1193
|
-
verifyCloudFunction: 0
|
|
1194
|
-
},
|
|
1195
|
-
};
|
|
1196
|
-
}
|
|
1197
|
-
if (data.timeoutMechanismType === "FIXED" /* CeremonyTimeoutType.FIXED */) {
|
|
1198
|
-
if (circuitData.fixedTimeWindow <= 0)
|
|
1199
|
-
throw new Error("The fixed time window threshold should be > 0.");
|
|
1200
|
-
fixedTimeWindow = circuitData.fixedTimeWindow;
|
|
1201
|
-
// the Circuit data for the ceremony setup
|
|
1202
|
-
circuit = {
|
|
1203
|
-
name: circuitData.name,
|
|
1204
|
-
description: circuitData.description,
|
|
1205
|
-
prefix: circuitPrefix,
|
|
1206
|
-
sequencePosition: i + 1,
|
|
1207
|
-
metadata: metadata,
|
|
1208
|
-
files: files,
|
|
1209
|
-
template: template,
|
|
1210
|
-
compiler: compiler,
|
|
1211
|
-
verification: verification,
|
|
1212
|
-
fixedTimeWindow: fixedTimeWindow,
|
|
1213
|
-
avgTimings: {
|
|
1214
|
-
contributionComputation: 0,
|
|
1215
|
-
fullContribution: 0,
|
|
1216
|
-
verifyCloudFunction: 0
|
|
1217
|
-
},
|
|
1218
|
-
};
|
|
1219
|
-
}
|
|
1220
|
-
circuits.push(circuit);
|
|
1221
|
-
// remove the local r1cs download (if used for verifying the config only vs setup)
|
|
1222
|
-
if (cleanup)
|
|
1223
|
-
fs.unlinkSync(localR1csPath);
|
|
1224
|
-
}
|
|
1225
|
-
const setupData = {
|
|
1226
|
-
ceremonyInputData: {
|
|
1227
|
-
title: data.title,
|
|
1228
|
-
description: data.description,
|
|
1229
|
-
startDate: startDate.valueOf(),
|
|
1230
|
-
endDate: endDate.valueOf(),
|
|
1231
|
-
timeoutMechanismType: data.timeoutMechanismType,
|
|
1232
|
-
penalty: data.penalty
|
|
1233
|
-
},
|
|
1234
|
-
ceremonyPrefix: extractPrefix(data.title),
|
|
1235
|
-
circuits: circuits,
|
|
1236
|
-
circuitArtifacts: circuitArtifacts
|
|
1237
|
-
};
|
|
1238
|
-
return setupData;
|
|
1239
|
-
}
|
|
1240
|
-
catch (error) {
|
|
1241
|
-
throw new Error(`Error while parsing up the ceremony setup file. ${error.message}`);
|
|
1242
|
-
}
|
|
1243
|
-
};
|
|
1060
|
+
const convertToDoubleDigits = (amount) => (amount < 10 ? `0${amount}` : amount.toString());
|
|
1061
|
+
/**
|
|
1062
|
+
* Extract a prefix consisting of alphanumeric and underscore characters from a string with arbitrary characters.
|
|
1063
|
+
* @dev replaces all special symbols and whitespaces with an underscore char ('_'). Convert all uppercase chars to lowercase.
|
|
1064
|
+
* @notice example: str = 'Multiplier-2!2.4.zkey'; output prefix = 'multiplier_2_2_4.zkey'.
|
|
1065
|
+
* NB. Prefix extraction is a key process that conditions the name of the ceremony artifacts, download/upload from/to storage, collections paths.
|
|
1066
|
+
* @param str <string> - the arbitrary string from which to extract the prefix.
|
|
1067
|
+
* @returns <string> - the resulting prefix.
|
|
1068
|
+
*/
|
|
1069
|
+
const extractPrefix = (str) =>
|
|
1070
|
+
// eslint-disable-next-line no-useless-escape
|
|
1071
|
+
str.replace(/[`\s~!@#$%^&*()|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "-").toLowerCase();
|
|
1244
1072
|
/**
|
|
1245
1073
|
* Extract data from a R1CS metadata file generated with a custom file-based logger.
|
|
1246
1074
|
* @notice useful for extracting metadata circuits contained in the generated file using a logger
|
|
@@ -1297,17 +1125,6 @@ const formatZkeyIndex = (progress) => {
|
|
|
1297
1125
|
* @returns <number> - the amount of powers.
|
|
1298
1126
|
*/
|
|
1299
1127
|
const extractPoTFromFilename = (potCompleteFilename) => Number(potCompleteFilename.split("_").pop()?.split(".").at(0));
|
|
1300
|
-
/**
|
|
1301
|
-
* Extract a prefix consisting of alphanumeric and underscore characters from a string with arbitrary characters.
|
|
1302
|
-
* @dev replaces all special symbols and whitespaces with an underscore char ('_'). Convert all uppercase chars to lowercase.
|
|
1303
|
-
* @notice example: str = 'Multiplier-2!2.4.zkey'; output prefix = 'multiplier_2_2_4.zkey'.
|
|
1304
|
-
* NB. Prefix extraction is a key process that conditions the name of the ceremony artifacts, download/upload from/to storage, collections paths.
|
|
1305
|
-
* @param str <string> - the arbitrary string from which to extract the prefix.
|
|
1306
|
-
* @returns <string> - the resulting prefix.
|
|
1307
|
-
*/
|
|
1308
|
-
const extractPrefix = (str) =>
|
|
1309
|
-
// eslint-disable-next-line no-useless-escape
|
|
1310
|
-
str.replace(/[`\s~!@#$%^&*()|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "-").toLowerCase();
|
|
1311
1128
|
/**
|
|
1312
1129
|
* Automate the generation of an entropy for a contribution.
|
|
1313
1130
|
* @dev Took inspiration from here https://github.com/glamperd/setup-mpc-ui/blob/master/client/src/state/Compute.tsx#L112.
|
|
@@ -1374,7 +1191,9 @@ const getContributionsValidityForContributor = async (firestoreDatabase, circuit
|
|
|
1374
1191
|
* @param isFinalizing <boolean> - true when the coordinator is finalizing the ceremony, otherwise false.
|
|
1375
1192
|
* @returns <string> - the public attestation preamble.
|
|
1376
1193
|
*/
|
|
1377
|
-
const getPublicAttestationPreambleForContributor = (contributorIdentifier, ceremonyName, isFinalizing) => `Hey, I'm ${contributorIdentifier} and I have ${isFinalizing ? "finalized" : "contributed to"} the ${ceremonyName}
|
|
1194
|
+
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")
|
|
1195
|
+
? "."
|
|
1196
|
+
: " MPC Phase2 Trusted Setup ceremony."}\nThe following are my contribution signatures:`;
|
|
1378
1197
|
/**
|
|
1379
1198
|
* Check and prepare public attestation for the contributor made only of its valid contributions.
|
|
1380
1199
|
* @param firestoreDatabase <Firestore> - the Firestore service instance associated to the current Firebase application.
|
|
@@ -1577,11 +1396,193 @@ const getR1CSInfo = (localR1CSFilePath) => {
|
|
|
1577
1396
|
}
|
|
1578
1397
|
};
|
|
1579
1398
|
/**
|
|
1580
|
-
*
|
|
1581
|
-
* @
|
|
1582
|
-
* @
|
|
1399
|
+
* Parse and validate that the ceremony configuration is correct
|
|
1400
|
+
* @notice this does not upload any files to storage
|
|
1401
|
+
* @param path <string> - the path to the configuration file
|
|
1402
|
+
* @param cleanup <boolean> - whether to delete the r1cs file after parsing
|
|
1403
|
+
* @returns any - the data to pass to the cloud function for setup and the circuit artifacts
|
|
1583
1404
|
*/
|
|
1584
|
-
const
|
|
1405
|
+
const parseCeremonyFile = async (path, cleanup = false) => {
|
|
1406
|
+
// check that the path exists
|
|
1407
|
+
if (!fs.existsSync(path))
|
|
1408
|
+
throw new Error("The provided path to the configuration file does not exist. Please provide an absolute path and try again.");
|
|
1409
|
+
try {
|
|
1410
|
+
// read the data
|
|
1411
|
+
const data = JSON.parse(fs.readFileSync(path).toString());
|
|
1412
|
+
// verify that the data is correct
|
|
1413
|
+
if (data.timeoutMechanismType !== "DYNAMIC" /* CeremonyTimeoutType.DYNAMIC */ &&
|
|
1414
|
+
data.timeoutMechanismType !== "FIXED" /* CeremonyTimeoutType.FIXED */)
|
|
1415
|
+
throw new Error("Invalid timeout type. Please choose between DYNAMIC and FIXED.");
|
|
1416
|
+
// validate that we have at least 1 circuit input data
|
|
1417
|
+
if (!data.circuits || data.circuits.length === 0)
|
|
1418
|
+
throw new Error("You need to provide the data for at least 1 circuit.");
|
|
1419
|
+
// validate that the end date is in the future
|
|
1420
|
+
let endDate;
|
|
1421
|
+
let startDate;
|
|
1422
|
+
try {
|
|
1423
|
+
endDate = new Date(data.endDate);
|
|
1424
|
+
startDate = new Date(data.startDate);
|
|
1425
|
+
}
|
|
1426
|
+
catch (error) {
|
|
1427
|
+
throw new Error("The dates should follow this format: 2023-07-04T00:00:00.");
|
|
1428
|
+
}
|
|
1429
|
+
if (endDate <= startDate)
|
|
1430
|
+
throw new Error("The end date should be greater than the start date.");
|
|
1431
|
+
const currentDate = new Date();
|
|
1432
|
+
if (endDate <= currentDate || startDate <= currentDate)
|
|
1433
|
+
throw new Error("The start and end dates should be in the future.");
|
|
1434
|
+
// validate penalty
|
|
1435
|
+
if (data.penalty <= 0)
|
|
1436
|
+
throw new Error("The penalty should be greater than zero.");
|
|
1437
|
+
const circuits = [];
|
|
1438
|
+
const urlPattern = /(https?:\/\/[^\s]+)/g;
|
|
1439
|
+
const commitHashPattern = /^[a-f0-9]{40}$/i;
|
|
1440
|
+
const circuitArtifacts = [];
|
|
1441
|
+
for (let i = 0; i < data.circuits.length; i++) {
|
|
1442
|
+
const circuitData = data.circuits[i];
|
|
1443
|
+
const { artifacts } = circuitData;
|
|
1444
|
+
circuitArtifacts.push({
|
|
1445
|
+
artifacts
|
|
1446
|
+
});
|
|
1447
|
+
// where we storing the r1cs downloaded
|
|
1448
|
+
const localR1csPath = `./${circuitData.name}.r1cs`;
|
|
1449
|
+
// where we storing the wasm downloaded
|
|
1450
|
+
const localWasmPath = `./${circuitData.name}.wasm`;
|
|
1451
|
+
// download the r1cs to extract the metadata
|
|
1452
|
+
const streamPipeline = util.promisify(stream.pipeline);
|
|
1453
|
+
// Make the call.
|
|
1454
|
+
const responseR1CS = await fetch(artifacts.r1csStoragePath);
|
|
1455
|
+
// Handle errors.
|
|
1456
|
+
if (!responseR1CS.ok && responseR1CS.status !== 200)
|
|
1457
|
+
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.`);
|
|
1458
|
+
await streamPipeline(responseR1CS.body, fs.createWriteStream(localR1csPath));
|
|
1459
|
+
// Write the file locally
|
|
1460
|
+
// extract the metadata from the r1cs
|
|
1461
|
+
const metadata = getR1CSInfo(localR1csPath);
|
|
1462
|
+
// download wasm too to ensure it's available
|
|
1463
|
+
const responseWASM = await fetch(artifacts.wasmStoragePath);
|
|
1464
|
+
if (!responseWASM.ok && responseWASM.status !== 200)
|
|
1465
|
+
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.`);
|
|
1466
|
+
await streamPipeline(responseWASM.body, fs.createWriteStream(localWasmPath));
|
|
1467
|
+
// validate that the circuit hash and template links are valid
|
|
1468
|
+
const { template } = circuitData;
|
|
1469
|
+
const URLMatch = template.source.match(urlPattern);
|
|
1470
|
+
if (!URLMatch || URLMatch.length === 0 || URLMatch.length > 1)
|
|
1471
|
+
throw new Error("You should provide the URL to the circuits templates on GitHub.");
|
|
1472
|
+
const hashMatch = template.commitHash.match(commitHashPattern);
|
|
1473
|
+
if (!hashMatch || hashMatch.length === 0 || hashMatch.length > 1)
|
|
1474
|
+
throw new Error("You should provide a valid commit hash of the circuit templates.");
|
|
1475
|
+
// calculate the hash of the r1cs file
|
|
1476
|
+
const r1csBlake2bHash = await blake512FromPath(localR1csPath);
|
|
1477
|
+
const circuitPrefix = extractPrefix(circuitData.name);
|
|
1478
|
+
// filenames
|
|
1479
|
+
const doubleDigitsPowers = convertToDoubleDigits(metadata.pot);
|
|
1480
|
+
const r1csCompleteFilename = `${circuitData.name}.r1cs`;
|
|
1481
|
+
const wasmCompleteFilename = `${circuitData.name}.wasm`;
|
|
1482
|
+
const smallestPowersOfTauCompleteFilenameForCircuit = `${potFilenameTemplate}${doubleDigitsPowers}.ptau`;
|
|
1483
|
+
const firstZkeyCompleteFilename = `${circuitPrefix}_${genesisZkeyIndex}.zkey`;
|
|
1484
|
+
// storage paths
|
|
1485
|
+
const r1csStorageFilePath = getR1csStorageFilePath(circuitPrefix, r1csCompleteFilename);
|
|
1486
|
+
const wasmStorageFilePath = getWasmStorageFilePath(circuitPrefix, wasmCompleteFilename);
|
|
1487
|
+
const potStorageFilePath = getPotStorageFilePath(smallestPowersOfTauCompleteFilenameForCircuit);
|
|
1488
|
+
const zkeyStorageFilePath = getZkeyStorageFilePath(circuitPrefix, firstZkeyCompleteFilename);
|
|
1489
|
+
const files = {
|
|
1490
|
+
potFilename: smallestPowersOfTauCompleteFilenameForCircuit,
|
|
1491
|
+
r1csFilename: r1csCompleteFilename,
|
|
1492
|
+
wasmFilename: wasmCompleteFilename,
|
|
1493
|
+
initialZkeyFilename: firstZkeyCompleteFilename,
|
|
1494
|
+
potStoragePath: potStorageFilePath,
|
|
1495
|
+
r1csStoragePath: r1csStorageFilePath,
|
|
1496
|
+
wasmStoragePath: wasmStorageFilePath,
|
|
1497
|
+
initialZkeyStoragePath: zkeyStorageFilePath,
|
|
1498
|
+
r1csBlake2bHash
|
|
1499
|
+
};
|
|
1500
|
+
// validate that the compiler hash is a valid hash
|
|
1501
|
+
const { compiler } = circuitData;
|
|
1502
|
+
const compilerHashMatch = compiler.commitHash.match(commitHashPattern);
|
|
1503
|
+
if (!compilerHashMatch || compilerHashMatch.length === 0 || compilerHashMatch.length > 1)
|
|
1504
|
+
throw new Error("You should provide a valid commit hash of the circuit compiler.");
|
|
1505
|
+
// validate that the verification options are valid
|
|
1506
|
+
const { verification } = circuitData;
|
|
1507
|
+
if (verification.cfOrVm !== "CF" && verification.cfOrVm !== "VM")
|
|
1508
|
+
throw new Error("Please enter a valid verification mechanism: either CF or VM");
|
|
1509
|
+
// @todo VM parameters verification
|
|
1510
|
+
// if (verification['cfOrVM'] === "VM") {}
|
|
1511
|
+
// check that the timeout is provided for the correct configuration
|
|
1512
|
+
let dynamicThreshold;
|
|
1513
|
+
let fixedTimeWindow;
|
|
1514
|
+
let circuit = {};
|
|
1515
|
+
if (data.timeoutMechanismType === "DYNAMIC" /* CeremonyTimeoutType.DYNAMIC */) {
|
|
1516
|
+
if (circuitData.dynamicThreshold <= 0)
|
|
1517
|
+
throw new Error("The dynamic threshold should be > 0.");
|
|
1518
|
+
dynamicThreshold = circuitData.dynamicThreshold;
|
|
1519
|
+
// the Circuit data for the ceremony setup
|
|
1520
|
+
circuit = {
|
|
1521
|
+
name: circuitData.name,
|
|
1522
|
+
description: circuitData.description,
|
|
1523
|
+
prefix: circuitPrefix,
|
|
1524
|
+
sequencePosition: i + 1,
|
|
1525
|
+
metadata,
|
|
1526
|
+
files,
|
|
1527
|
+
template,
|
|
1528
|
+
compiler,
|
|
1529
|
+
verification,
|
|
1530
|
+
dynamicThreshold,
|
|
1531
|
+
avgTimings: {
|
|
1532
|
+
contributionComputation: 0,
|
|
1533
|
+
fullContribution: 0,
|
|
1534
|
+
verifyCloudFunction: 0
|
|
1535
|
+
}
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1538
|
+
if (data.timeoutMechanismType === "FIXED" /* CeremonyTimeoutType.FIXED */) {
|
|
1539
|
+
if (circuitData.fixedTimeWindow <= 0)
|
|
1540
|
+
throw new Error("The fixed time window threshold should be > 0.");
|
|
1541
|
+
fixedTimeWindow = circuitData.fixedTimeWindow;
|
|
1542
|
+
// the Circuit data for the ceremony setup
|
|
1543
|
+
circuit = {
|
|
1544
|
+
name: circuitData.name,
|
|
1545
|
+
description: circuitData.description,
|
|
1546
|
+
prefix: circuitPrefix,
|
|
1547
|
+
sequencePosition: i + 1,
|
|
1548
|
+
metadata,
|
|
1549
|
+
files,
|
|
1550
|
+
template,
|
|
1551
|
+
compiler,
|
|
1552
|
+
verification,
|
|
1553
|
+
fixedTimeWindow,
|
|
1554
|
+
avgTimings: {
|
|
1555
|
+
contributionComputation: 0,
|
|
1556
|
+
fullContribution: 0,
|
|
1557
|
+
verifyCloudFunction: 0
|
|
1558
|
+
}
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
circuits.push(circuit);
|
|
1562
|
+
// remove the local r1cs and wasm downloads (if used for verifying the config only vs setup)
|
|
1563
|
+
if (cleanup)
|
|
1564
|
+
fs.unlinkSync(localR1csPath);
|
|
1565
|
+
fs.unlinkSync(localWasmPath);
|
|
1566
|
+
}
|
|
1567
|
+
const setupData = {
|
|
1568
|
+
ceremonyInputData: {
|
|
1569
|
+
title: data.title,
|
|
1570
|
+
description: data.description,
|
|
1571
|
+
startDate: startDate.valueOf(),
|
|
1572
|
+
endDate: endDate.valueOf(),
|
|
1573
|
+
timeoutMechanismType: data.timeoutMechanismType,
|
|
1574
|
+
penalty: data.penalty
|
|
1575
|
+
},
|
|
1576
|
+
ceremonyPrefix: extractPrefix(data.title),
|
|
1577
|
+
circuits,
|
|
1578
|
+
circuitArtifacts
|
|
1579
|
+
};
|
|
1580
|
+
return setupData;
|
|
1581
|
+
}
|
|
1582
|
+
catch (error) {
|
|
1583
|
+
throw new Error(`Error while parsing up the ceremony setup file. ${error.message}`);
|
|
1584
|
+
}
|
|
1585
|
+
};
|
|
1585
1586
|
|
|
1586
1587
|
/**
|
|
1587
1588
|
* Verify that a zKey is valid
|
|
@@ -1830,7 +1831,7 @@ const getFirestoreDatabase = (app) => firestore.getFirestore(app);
|
|
|
1830
1831
|
* @param app <FirebaseApp> - the Firebase application.
|
|
1831
1832
|
* @returns <Functions> - the Cloud Functions associated to the application.
|
|
1832
1833
|
*/
|
|
1833
|
-
const getFirebaseFunctions = (app) => functions.getFunctions(app,
|
|
1834
|
+
const getFirebaseFunctions = (app) => functions.getFunctions(app, "europe-west1");
|
|
1834
1835
|
/**
|
|
1835
1836
|
* Retrieve the configuration variables for the AWS services (S3, EC2).
|
|
1836
1837
|
* @returns <AWSVariables> - the values of the AWS services configuration variables.
|
|
@@ -1839,14 +1840,14 @@ const getAWSVariables = () => {
|
|
|
1839
1840
|
if (!process.env.AWS_ACCESS_KEY_ID ||
|
|
1840
1841
|
!process.env.AWS_SECRET_ACCESS_KEY ||
|
|
1841
1842
|
!process.env.AWS_REGION ||
|
|
1842
|
-
!process.env.
|
|
1843
|
+
!process.env.AWS_INSTANCE_PROFILE_ARN ||
|
|
1843
1844
|
!process.env.AWS_AMI_ID)
|
|
1844
1845
|
throw new Error("Could not retrieve the AWS environment variables. Please, verify your environment configuration and retry");
|
|
1845
1846
|
return {
|
|
1846
1847
|
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
1847
1848
|
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
1848
1849
|
region: process.env.AWS_REGION || "us-east-1",
|
|
1849
|
-
|
|
1850
|
+
instanceProfileArn: process.env.AWS_INSTANCE_PROFILE_ARN,
|
|
1850
1851
|
amiId: process.env.AWS_AMI_ID
|
|
1851
1852
|
};
|
|
1852
1853
|
};
|
|
@@ -2081,55 +2082,28 @@ const verifyCeremony = async (functions, firestore$1, ceremonyPrefix, outputDire
|
|
|
2081
2082
|
};
|
|
2082
2083
|
|
|
2083
2084
|
/**
|
|
2084
|
-
* This function
|
|
2085
|
-
* @param user
|
|
2086
|
-
* @returns
|
|
2087
|
-
*/
|
|
2088
|
-
const getNumberOfPublicReposGitHub = async (user) => {
|
|
2089
|
-
const response = await fetch(`https://api.github.com/user/${user}/repos`, {
|
|
2090
|
-
method: "GET",
|
|
2091
|
-
headers: {
|
|
2092
|
-
Authorization: `token ${process.env.GITHUB_ACCESS_TOKEN}`
|
|
2093
|
-
}
|
|
2094
|
-
});
|
|
2095
|
-
if (response.status !== 200)
|
|
2096
|
-
throw new Error("It was not possible to retrieve the number of public repositories. Please try again.");
|
|
2097
|
-
const jsonData = await response.json();
|
|
2098
|
-
return jsonData.length;
|
|
2099
|
-
};
|
|
2100
|
-
/**
|
|
2101
|
-
* This function will return the number of followers of a user
|
|
2102
|
-
* @param user <string> The username of the user
|
|
2103
|
-
* @returns <number> The number of followers
|
|
2104
|
-
*/
|
|
2105
|
-
const getNumberOfFollowersGitHub = async (user) => {
|
|
2106
|
-
const response = await fetch(`https://api.github.com/user/${user}/followers`, {
|
|
2107
|
-
method: "GET",
|
|
2108
|
-
headers: {
|
|
2109
|
-
Authorization: `token ${process.env.GITHUB_ACCESS_TOKEN}`
|
|
2110
|
-
}
|
|
2111
|
-
});
|
|
2112
|
-
if (response.status !== 200)
|
|
2113
|
-
throw new Error("It was not possible to retrieve the number of followers. Please try again.");
|
|
2114
|
-
const jsonData = await response.json();
|
|
2115
|
-
return jsonData.length;
|
|
2116
|
-
};
|
|
2117
|
-
/**
|
|
2118
|
-
* This function will return the number of following of a user
|
|
2119
|
-
* @param user <string> The username of the user
|
|
2120
|
-
* @returns <number> The number of following users
|
|
2085
|
+
* This function queries the GitHub API to fetch users statistics
|
|
2086
|
+
* @param user {string} the user uid
|
|
2087
|
+
* @returns {any} the stats from the GitHub API
|
|
2121
2088
|
*/
|
|
2122
|
-
const
|
|
2123
|
-
const response = await fetch(`https://api.github.com/user/${user}
|
|
2089
|
+
const getGitHubStats = async (user) => {
|
|
2090
|
+
const response = await fetch(`https://api.github.com/user/${user}`, {
|
|
2124
2091
|
method: "GET",
|
|
2125
2092
|
headers: {
|
|
2126
2093
|
Authorization: `token ${process.env.GITHUB_ACCESS_TOKEN}`
|
|
2127
2094
|
}
|
|
2128
2095
|
});
|
|
2129
2096
|
if (response.status !== 200)
|
|
2130
|
-
throw new Error("It was not possible to retrieve the
|
|
2097
|
+
throw new Error("It was not possible to retrieve the user's statistic. Please try again.");
|
|
2131
2098
|
const jsonData = await response.json();
|
|
2132
|
-
|
|
2099
|
+
const data = {
|
|
2100
|
+
following: jsonData.following,
|
|
2101
|
+
followers: jsonData.followers,
|
|
2102
|
+
publicRepos: jsonData.public_repos,
|
|
2103
|
+
avatarUrl: jsonData.avatar_url,
|
|
2104
|
+
age: jsonData.created_at
|
|
2105
|
+
};
|
|
2106
|
+
return data;
|
|
2133
2107
|
};
|
|
2134
2108
|
/**
|
|
2135
2109
|
* This function will check if the user is reputable enough to be able to use the app
|
|
@@ -2137,19 +2111,24 @@ const getNumberOfFollowingGitHub = async (user) => {
|
|
|
2137
2111
|
* @param minimumAmountOfFollowing <number> The minimum amount of following the user should have
|
|
2138
2112
|
* @param minimumAmountOfFollowers <number> The minimum amount of followers the user should have
|
|
2139
2113
|
* @param minimumAmountOfPublicRepos <number> The minimum amount of public repos the user should have
|
|
2140
|
-
* @returns <
|
|
2114
|
+
* @returns <any> Return the avatar URL of the user if the user is reputable, false otherwise
|
|
2141
2115
|
*/
|
|
2142
|
-
const githubReputation = async (userLogin, minimumAmountOfFollowing, minimumAmountOfFollowers, minimumAmountOfPublicRepos) => {
|
|
2116
|
+
const githubReputation = async (userLogin, minimumAmountOfFollowing, minimumAmountOfFollowers, minimumAmountOfPublicRepos, minimumAge) => {
|
|
2143
2117
|
if (!process.env.GITHUB_ACCESS_TOKEN)
|
|
2144
2118
|
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.");
|
|
2145
|
-
const following = await
|
|
2146
|
-
const repos = await getNumberOfPublicReposGitHub(userLogin);
|
|
2147
|
-
const followers = await getNumberOfFollowersGitHub(userLogin);
|
|
2119
|
+
const { following, followers, publicRepos, avatarUrl, age } = await getGitHubStats(userLogin);
|
|
2148
2120
|
if (following < minimumAmountOfFollowing ||
|
|
2149
|
-
|
|
2150
|
-
followers < minimumAmountOfFollowers
|
|
2151
|
-
|
|
2152
|
-
|
|
2121
|
+
publicRepos < minimumAmountOfPublicRepos ||
|
|
2122
|
+
followers < minimumAmountOfFollowers ||
|
|
2123
|
+
new Date(age) > new Date(Date.now() - minimumAge))
|
|
2124
|
+
return {
|
|
2125
|
+
reputable: false,
|
|
2126
|
+
avatarUrl: ""
|
|
2127
|
+
};
|
|
2128
|
+
return {
|
|
2129
|
+
reputable: true,
|
|
2130
|
+
avatarUrl
|
|
2131
|
+
};
|
|
2153
2132
|
};
|
|
2154
2133
|
|
|
2155
2134
|
/**
|
|
@@ -2357,8 +2336,13 @@ const vmDependenciesAndCacheArtifactsCommand = (zKeyPath, potPath, snsTopic, reg
|
|
|
2357
2336
|
// eslint-disable-next-line no-template-curly-in-string
|
|
2358
2337
|
"touch ${MARKER_FILE}",
|
|
2359
2338
|
"sudo yum update -y",
|
|
2360
|
-
"curl -
|
|
2361
|
-
"
|
|
2339
|
+
"curl -O https://nodejs.org/dist/v16.13.0/node-v16.13.0-linux-x64.tar.xz",
|
|
2340
|
+
"tar -xf node-v16.13.0-linux-x64.tar.xz",
|
|
2341
|
+
"mv node-v16.13.0-linux-x64 nodejs",
|
|
2342
|
+
"sudo mv nodejs /opt/",
|
|
2343
|
+
"echo 'export NODEJS_HOME=/opt/nodejs' >> /etc/profile",
|
|
2344
|
+
"echo 'export PATH=$NODEJS_HOME/bin:$PATH' >> /etc/profile",
|
|
2345
|
+
"source /etc/profile",
|
|
2362
2346
|
"npm install -g snarkjs",
|
|
2363
2347
|
`aws s3 cp s3://${zKeyPath} /var/tmp/genesisZkey.zkey`,
|
|
2364
2348
|
`aws s3 cp s3://${potPath} /var/tmp/pot.ptau`,
|
|
@@ -2377,6 +2361,7 @@ const vmDependenciesAndCacheArtifactsCommand = (zKeyPath, potPath, snsTopic, reg
|
|
|
2377
2361
|
* @returns Array<string> - the list of commands for contribution verification.
|
|
2378
2362
|
*/
|
|
2379
2363
|
const vmContributionVerificationCommand = (bucketName, lastZkeyStoragePath, verificationTranscriptStoragePathAndFilename) => [
|
|
2364
|
+
`source /etc/profile`,
|
|
2380
2365
|
`aws s3 cp s3://${bucketName}/${lastZkeyStoragePath} /var/tmp/lastZKey.zkey > /var/tmp/log.txt`,
|
|
2381
2366
|
`snarkjs zkvi /var/tmp/genesisZkey.zkey /var/tmp/pot.ptau /var/tmp/lastZKey.zkey > /var/tmp/verification_transcript.log`,
|
|
2382
2367
|
`aws s3 cp /var/tmp/verification_transcript.log s3://${bucketName}/${verificationTranscriptStoragePathAndFilename} &>/dev/null`,
|
|
@@ -2403,7 +2388,7 @@ const computeDiskSizeForVM = (zKeySizeInBytes, pot) => Math.ceil(2 * convertByte
|
|
|
2403
2388
|
*/
|
|
2404
2389
|
const createEC2Instance = async (ec2, commands, instanceType, volumeSize, diskType) => {
|
|
2405
2390
|
// Get the AWS variables.
|
|
2406
|
-
const { amiId,
|
|
2391
|
+
const { amiId, instanceProfileArn } = getAWSVariables();
|
|
2407
2392
|
// Parametrize the VM EC2 instance.
|
|
2408
2393
|
const params = {
|
|
2409
2394
|
ImageId: amiId,
|
|
@@ -2412,7 +2397,7 @@ const createEC2Instance = async (ec2, commands, instanceType, volumeSize, diskTy
|
|
|
2412
2397
|
MinCount: 1,
|
|
2413
2398
|
// nb. to find this: iam -> roles -> role_name.
|
|
2414
2399
|
IamInstanceProfile: {
|
|
2415
|
-
Arn:
|
|
2400
|
+
Arn: instanceProfileArn
|
|
2416
2401
|
},
|
|
2417
2402
|
// nb. for running commands at the startup.
|
|
2418
2403
|
UserData: Buffer.from(commands.join("\n")).toString("base64"),
|