@devtion/actions 0.0.0-3df1645 → 0.0.0-477457c
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 +2 -2
- package/dist/index.mjs +353 -262
- package/dist/index.node.js +354 -261
- package/dist/types/src/helpers/authentication.d.ts.map +1 -1
- package/dist/types/src/helpers/constants.d.ts +5 -2
- 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.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/functions.d.ts +2 -1
- package/dist/types/src/helpers/functions.d.ts.map +1 -1
- package/dist/types/src/helpers/security.d.ts +1 -1
- package/dist/types/src/helpers/security.d.ts.map +1 -1
- package/dist/types/src/helpers/services.d.ts.map +1 -1
- package/dist/types/src/helpers/storage.d.ts +1 -1
- package/dist/types/src/helpers/storage.d.ts.map +1 -1
- package/dist/types/src/helpers/utils.d.ts +33 -21
- 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 +2 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +9 -4
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/test/data/generators.d.ts +32 -0
- package/dist/types/test/data/generators.d.ts.map +1 -0
- package/dist/types/test/data/samples.d.ts +40 -0
- package/dist/types/test/data/samples.d.ts.map +1 -0
- package/dist/types/test/utils/authentication.d.ts +72 -0
- package/dist/types/test/utils/authentication.d.ts.map +1 -0
- package/dist/types/test/utils/configs.d.ts +52 -0
- package/dist/types/test/utils/configs.d.ts.map +1 -0
- package/dist/types/test/utils/index.d.ts +4 -0
- package/dist/types/test/utils/index.d.ts.map +1 -0
- package/dist/types/test/utils/storage.d.ts +126 -0
- package/dist/types/test/utils/storage.d.ts.map +1 -0
- package/package.json +7 -8
- package/src/helpers/constants.ts +40 -32
- package/src/helpers/contracts.ts +3 -3
- package/src/helpers/crypto.ts +5 -1
- package/src/helpers/database.ts +13 -0
- package/src/helpers/security.ts +8 -5
- package/src/helpers/services.ts +2 -2
- package/src/helpers/storage.ts +3 -3
- package/src/helpers/utils.ts +320 -255
- package/src/helpers/verification.ts +6 -6
- package/src/helpers/vm.ts +19 -4
- package/src/index.ts +3 -1
- package/src/types/index.ts +23 -3
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @p0tion/actions
|
|
3
|
-
* @version 1.
|
|
3
|
+
* @version 1.2.8
|
|
4
4
|
* @file A set of actions and helpers for CLI commands
|
|
5
5
|
* @copyright Ethereum Foundation 2022
|
|
6
6
|
* @license MIT
|
|
@@ -15,7 +15,6 @@ import { onSnapshot, query, collection, getDocs, doc, getDoc, where, Timestamp,
|
|
|
15
15
|
import { zKey, groth16 } from 'snarkjs';
|
|
16
16
|
import crypto from 'crypto';
|
|
17
17
|
import blake from 'blakejs';
|
|
18
|
-
import { utils } from 'ffjavascript';
|
|
19
18
|
import winston from 'winston';
|
|
20
19
|
import { pipeline } from 'stream';
|
|
21
20
|
import { promisify } from 'util';
|
|
@@ -27,10 +26,10 @@ import { EC2Client, RunInstancesCommand, DescribeInstanceStatusCommand, StartIns
|
|
|
27
26
|
import { SSMClient, SendCommandCommand, GetCommandInvocationCommand } from '@aws-sdk/client-ssm';
|
|
28
27
|
import dotenv from 'dotenv';
|
|
29
28
|
|
|
30
|
-
// Main part for the
|
|
31
|
-
const potFileDownloadMainUrl = `https://
|
|
32
|
-
// Main part for the
|
|
33
|
-
const potFilenameTemplate = `
|
|
29
|
+
// Main part for the PPoT Phase 1 Trusted Setup URLs to download PoT files.
|
|
30
|
+
const potFileDownloadMainUrl = `https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/`;
|
|
31
|
+
// Main part for the PPoT Phase 1 Trusted Setup PoT files to be downloaded.
|
|
32
|
+
const potFilenameTemplate = `ppot_0080_`;
|
|
34
33
|
// The genesis zKey index.
|
|
35
34
|
const genesisZkeyIndex = `00000`;
|
|
36
35
|
// The number of exponential iterations to be executed by SnarkJS when finalizing the ceremony.
|
|
@@ -47,6 +46,8 @@ const verifierSmartContractAcronym = "verifier";
|
|
|
47
46
|
const ec2InstanceTag = "p0tionec2instance";
|
|
48
47
|
// The name of the VM startup script file.
|
|
49
48
|
const vmBootstrapScriptFilename = "bootstrap.sh";
|
|
49
|
+
// Match hash output by snarkjs in transcript log
|
|
50
|
+
const contribHashRegex = /Contribution.+Hash.+\s+.+\s+.+\s+.+\s+.+\s*/;
|
|
50
51
|
/**
|
|
51
52
|
* Define the supported VM configuration types.
|
|
52
53
|
* @dev the VM configurations can be retrieved at https://aws.amazon.com/ec2/instance-types/
|
|
@@ -104,112 +105,116 @@ const vmConfigurationTypes = {
|
|
|
104
105
|
*/
|
|
105
106
|
const powersOfTauFiles = [
|
|
106
107
|
{
|
|
107
|
-
ref: "https://
|
|
108
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_01.ptau",
|
|
108
109
|
size: 0.000084
|
|
109
110
|
},
|
|
110
111
|
{
|
|
111
|
-
ref: "https://
|
|
112
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_02.ptau",
|
|
112
113
|
size: 0.000086
|
|
113
114
|
},
|
|
114
115
|
{
|
|
115
|
-
ref: "https://
|
|
116
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_03.ptau",
|
|
116
117
|
size: 0.000091
|
|
117
118
|
},
|
|
118
119
|
{
|
|
119
|
-
ref: "https://
|
|
120
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_04.ptau",
|
|
120
121
|
size: 0.0001
|
|
121
122
|
},
|
|
122
123
|
{
|
|
123
|
-
ref: "https://
|
|
124
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_05.ptau",
|
|
124
125
|
size: 0.000117
|
|
125
126
|
},
|
|
126
127
|
{
|
|
127
|
-
ref: "https://
|
|
128
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_06.ptau",
|
|
128
129
|
size: 0.000153
|
|
129
130
|
},
|
|
130
131
|
{
|
|
131
|
-
ref: "https://
|
|
132
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_07.ptau",
|
|
132
133
|
size: 0.000225
|
|
133
134
|
},
|
|
134
135
|
{
|
|
135
|
-
ref: "https://
|
|
136
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_08.ptau",
|
|
136
137
|
size: 0.0004
|
|
137
138
|
},
|
|
138
139
|
{
|
|
139
|
-
ref: "https://
|
|
140
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_09.ptau",
|
|
140
141
|
size: 0.000658
|
|
141
142
|
},
|
|
142
143
|
{
|
|
143
|
-
ref: "https://
|
|
144
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_10.ptau",
|
|
144
145
|
size: 0.0013
|
|
145
146
|
},
|
|
146
147
|
{
|
|
147
|
-
ref: "https://
|
|
148
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_11.ptau",
|
|
148
149
|
size: 0.0023
|
|
149
150
|
},
|
|
150
151
|
{
|
|
151
|
-
ref: "https://
|
|
152
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_12.ptau",
|
|
152
153
|
size: 0.0046
|
|
153
154
|
},
|
|
154
155
|
{
|
|
155
|
-
ref: "https://
|
|
156
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_13.ptau",
|
|
156
157
|
size: 0.0091
|
|
157
158
|
},
|
|
158
159
|
{
|
|
159
|
-
ref: "https://
|
|
160
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_14.ptau",
|
|
160
161
|
size: 0.0181
|
|
161
162
|
},
|
|
162
163
|
{
|
|
163
|
-
ref: "https://
|
|
164
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_15.ptau",
|
|
164
165
|
size: 0.0361
|
|
165
166
|
},
|
|
166
167
|
{
|
|
167
|
-
ref: "https://
|
|
168
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_16.ptau",
|
|
168
169
|
size: 0.0721
|
|
169
170
|
},
|
|
170
171
|
{
|
|
171
|
-
ref: "https://
|
|
172
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_17.ptau",
|
|
172
173
|
size: 0.144
|
|
173
174
|
},
|
|
174
175
|
{
|
|
175
|
-
ref: "https://
|
|
176
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_18.ptau",
|
|
176
177
|
size: 0.288
|
|
177
178
|
},
|
|
178
179
|
{
|
|
179
|
-
ref: "https://
|
|
180
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_19.ptau",
|
|
180
181
|
size: 0.576
|
|
181
182
|
},
|
|
182
183
|
{
|
|
183
|
-
ref: "https://
|
|
184
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_20.ptau",
|
|
184
185
|
size: 1.1
|
|
185
186
|
},
|
|
186
187
|
{
|
|
187
|
-
ref: "https://
|
|
188
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_21.ptau",
|
|
188
189
|
size: 2.3
|
|
189
190
|
},
|
|
190
191
|
{
|
|
191
|
-
ref: "https://
|
|
192
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_22.ptau",
|
|
192
193
|
size: 4.5
|
|
193
194
|
},
|
|
194
195
|
{
|
|
195
|
-
ref: "https://
|
|
196
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_23.ptau",
|
|
196
197
|
size: 9.0
|
|
197
198
|
},
|
|
198
199
|
{
|
|
199
|
-
ref: "https://
|
|
200
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_24.ptau",
|
|
200
201
|
size: 18.0
|
|
201
202
|
},
|
|
202
203
|
{
|
|
203
|
-
ref: "https://
|
|
204
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_25.ptau",
|
|
204
205
|
size: 36.0
|
|
205
206
|
},
|
|
206
207
|
{
|
|
207
|
-
ref: "https://
|
|
208
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_26.ptau",
|
|
208
209
|
size: 72.0
|
|
209
210
|
},
|
|
210
211
|
{
|
|
211
|
-
ref: "https://
|
|
212
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_27.ptau",
|
|
212
213
|
size: 144.0
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
ref: "https://pse-trusted-setup-ppot.s3.eu-central-1.amazonaws.com/pot28_0080/ppot_0080_final.ptau",
|
|
217
|
+
size: 288.0
|
|
213
218
|
}
|
|
214
219
|
];
|
|
215
220
|
/**
|
|
@@ -339,7 +344,9 @@ const commonTerms = {
|
|
|
339
344
|
finalizeCircuit: "finalizeCircuit",
|
|
340
345
|
finalizeCeremony: "finalizeCeremony",
|
|
341
346
|
downloadCircuitArtifacts: "downloadCircuitArtifacts",
|
|
342
|
-
transferObject: "transferObject"
|
|
347
|
+
transferObject: "transferObject",
|
|
348
|
+
bandadaValidateProof: "bandadaValidateProof",
|
|
349
|
+
checkNonceOfSIWEAddress: "checkNonceOfSIWEAddress"
|
|
343
350
|
}
|
|
344
351
|
};
|
|
345
352
|
|
|
@@ -705,8 +712,8 @@ const uploadParts = async (chunksWithUrls, contentType, cloudFunctions, ceremony
|
|
|
705
712
|
// @ts-ignore
|
|
706
713
|
const response = await fetch(chunksWithUrls[i].preSignedUrl, {
|
|
707
714
|
retryOptions: {
|
|
708
|
-
retryInitialDelay: 500,
|
|
709
|
-
socketTimeout: 60000,
|
|
715
|
+
retryInitialDelay: 500, // 500 ms.
|
|
716
|
+
socketTimeout: 60000, // 60 seconds.
|
|
710
717
|
retryMaxDuration: 300000 // 5 minutes.
|
|
711
718
|
},
|
|
712
719
|
method: "PUT",
|
|
@@ -1003,6 +1010,17 @@ const getClosedCeremonies = async (firestoreDatabase) => {
|
|
|
1003
1010
|
]);
|
|
1004
1011
|
return fromQueryToFirebaseDocumentInfo(closedCeremoniesQuerySnap.docs);
|
|
1005
1012
|
};
|
|
1013
|
+
/**
|
|
1014
|
+
* Query all ceremonies
|
|
1015
|
+
* @notice get all ceremonies from the database.
|
|
1016
|
+
* @dev this is a helper for the CLI ceremony methods.
|
|
1017
|
+
* @param firestoreDatabase <Firestore> - the Firestore service instance associated to the current Firebase application.
|
|
1018
|
+
* @returns <Promise<Array<FirebaseDocumentInfo>>> - the list of all ceremonies.
|
|
1019
|
+
*/
|
|
1020
|
+
const getAllCeremonies = async (firestoreDatabase) => {
|
|
1021
|
+
const ceremoniesQuerySnap = await queryCollection(firestoreDatabase, commonTerms.collections.ceremonies.name, []);
|
|
1022
|
+
return fromQueryToFirebaseDocumentInfo(ceremoniesQuerySnap.docs);
|
|
1023
|
+
};
|
|
1006
1024
|
|
|
1007
1025
|
/**
|
|
1008
1026
|
* @hidden
|
|
@@ -1024,6 +1042,9 @@ const blake512FromPath = async (path) => {
|
|
|
1024
1042
|
const hash = await new Promise((resolve) => {
|
|
1025
1043
|
fs.createReadStream(path)
|
|
1026
1044
|
.on("data", (chunk) => {
|
|
1045
|
+
if (typeof chunk === "string") {
|
|
1046
|
+
chunk = Buffer.from(chunk);
|
|
1047
|
+
}
|
|
1027
1048
|
blake.blake2bUpdate(context, chunk);
|
|
1028
1049
|
})
|
|
1029
1050
|
.on("end", () => {
|
|
@@ -1051,193 +1072,22 @@ const compareHashes = async (path1, path2) => {
|
|
|
1051
1072
|
};
|
|
1052
1073
|
|
|
1053
1074
|
/**
|
|
1054
|
-
*
|
|
1055
|
-
* @
|
|
1056
|
-
* @
|
|
1057
|
-
* @param cleanup <boolean> - whether to delete the r1cs file after parsing
|
|
1058
|
-
* @returns any - the data to pass to the cloud function for setup and the circuit artifacts
|
|
1075
|
+
* Return a string with double digits if the provided input is one digit only.
|
|
1076
|
+
* @param in <number> - the input number to be converted.
|
|
1077
|
+
* @returns <string> - the two digits stringified number derived from the conversion.
|
|
1059
1078
|
*/
|
|
1060
|
-
const
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
if (!data.circuits || data.circuits.length === 0)
|
|
1073
|
-
throw new Error("You need to provide the data for at least 1 circuit.");
|
|
1074
|
-
// validate that the end date is in the future
|
|
1075
|
-
let endDate;
|
|
1076
|
-
let startDate;
|
|
1077
|
-
try {
|
|
1078
|
-
endDate = new Date(data.endDate);
|
|
1079
|
-
startDate = new Date(data.startDate);
|
|
1080
|
-
}
|
|
1081
|
-
catch (error) {
|
|
1082
|
-
throw new Error("The dates should follow this format: 2023-07-04T00:00:00.");
|
|
1083
|
-
}
|
|
1084
|
-
if (endDate <= startDate)
|
|
1085
|
-
throw new Error("The end date should be greater than the start date.");
|
|
1086
|
-
const currentDate = new Date();
|
|
1087
|
-
if (endDate <= currentDate || startDate <= currentDate)
|
|
1088
|
-
throw new Error("The start and end dates should be in the future.");
|
|
1089
|
-
// validate penalty
|
|
1090
|
-
if (data.penalty <= 0)
|
|
1091
|
-
throw new Error("The penalty should be greater than zero.");
|
|
1092
|
-
const circuits = [];
|
|
1093
|
-
const urlPattern = /(https?:\/\/[^\s]+)/g;
|
|
1094
|
-
const commitHashPattern = /^[a-f0-9]{40}$/i;
|
|
1095
|
-
const circuitArtifacts = [];
|
|
1096
|
-
for (let i = 0; i < data.circuits.length; i++) {
|
|
1097
|
-
const circuitData = data.circuits[i];
|
|
1098
|
-
const artifacts = circuitData.artifacts;
|
|
1099
|
-
circuitArtifacts.push({
|
|
1100
|
-
artifacts: artifacts
|
|
1101
|
-
});
|
|
1102
|
-
// where we storing the r1cs downloaded
|
|
1103
|
-
const localR1csPath = `./${circuitData.name}.r1cs`;
|
|
1104
|
-
// where we storing the wasm downloaded
|
|
1105
|
-
const localWasmPath = `./${circuitData.name}.wasm`;
|
|
1106
|
-
// download the r1cs to extract the metadata
|
|
1107
|
-
const streamPipeline = promisify(pipeline);
|
|
1108
|
-
// Make the call.
|
|
1109
|
-
const responseR1CS = await fetch(artifacts.r1csStoragePath);
|
|
1110
|
-
// Handle errors.
|
|
1111
|
-
if (!responseR1CS.ok && responseR1CS.status !== 200)
|
|
1112
|
-
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.`);
|
|
1113
|
-
await streamPipeline(responseR1CS.body, createWriteStream(localR1csPath));
|
|
1114
|
-
// Write the file locally
|
|
1115
|
-
// extract the metadata from the r1cs
|
|
1116
|
-
const metadata = getR1CSInfo(localR1csPath);
|
|
1117
|
-
// download wasm too to ensure it's available
|
|
1118
|
-
const responseWASM = await fetch(artifacts.wasmStoragePath);
|
|
1119
|
-
if (!responseWASM.ok && responseWASM.status !== 200)
|
|
1120
|
-
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.`);
|
|
1121
|
-
await streamPipeline(responseWASM.body, createWriteStream(localWasmPath));
|
|
1122
|
-
// validate that the circuit hash and template links are valid
|
|
1123
|
-
const template = circuitData.template;
|
|
1124
|
-
const URLMatch = template.source.match(urlPattern);
|
|
1125
|
-
if (!URLMatch || URLMatch.length === 0 || URLMatch.length > 1)
|
|
1126
|
-
throw new Error("You should provide the URL to the circuits templates on GitHub.");
|
|
1127
|
-
const hashMatch = template.commitHash.match(commitHashPattern);
|
|
1128
|
-
if (!hashMatch || hashMatch.length === 0 || hashMatch.length > 1)
|
|
1129
|
-
throw new Error("You should provide a valid commit hash of the circuit templates.");
|
|
1130
|
-
// calculate the hash of the r1cs file
|
|
1131
|
-
const r1csBlake2bHash = await blake512FromPath(localR1csPath);
|
|
1132
|
-
const circuitPrefix = extractPrefix(circuitData.name);
|
|
1133
|
-
// filenames
|
|
1134
|
-
const doubleDigitsPowers = convertToDoubleDigits(metadata.pot);
|
|
1135
|
-
const r1csCompleteFilename = `${circuitData.name}.r1cs`;
|
|
1136
|
-
const wasmCompleteFilename = `${circuitData.name}.wasm`;
|
|
1137
|
-
const smallestPowersOfTauCompleteFilenameForCircuit = `${potFilenameTemplate}${doubleDigitsPowers}.ptau`;
|
|
1138
|
-
const firstZkeyCompleteFilename = `${circuitPrefix}_${genesisZkeyIndex}.zkey`;
|
|
1139
|
-
// storage paths
|
|
1140
|
-
const r1csStorageFilePath = getR1csStorageFilePath(circuitPrefix, r1csCompleteFilename);
|
|
1141
|
-
const wasmStorageFilePath = getWasmStorageFilePath(circuitPrefix, wasmCompleteFilename);
|
|
1142
|
-
const potStorageFilePath = getPotStorageFilePath(smallestPowersOfTauCompleteFilenameForCircuit);
|
|
1143
|
-
const zkeyStorageFilePath = getZkeyStorageFilePath(circuitPrefix, firstZkeyCompleteFilename);
|
|
1144
|
-
const files = {
|
|
1145
|
-
potFilename: smallestPowersOfTauCompleteFilenameForCircuit,
|
|
1146
|
-
r1csFilename: r1csCompleteFilename,
|
|
1147
|
-
wasmFilename: wasmCompleteFilename,
|
|
1148
|
-
initialZkeyFilename: firstZkeyCompleteFilename,
|
|
1149
|
-
potStoragePath: potStorageFilePath,
|
|
1150
|
-
r1csStoragePath: r1csStorageFilePath,
|
|
1151
|
-
wasmStoragePath: wasmStorageFilePath,
|
|
1152
|
-
initialZkeyStoragePath: zkeyStorageFilePath,
|
|
1153
|
-
r1csBlake2bHash: r1csBlake2bHash
|
|
1154
|
-
};
|
|
1155
|
-
// validate that the compiler hash is a valid hash
|
|
1156
|
-
const compiler = circuitData.compiler;
|
|
1157
|
-
const compilerHashMatch = compiler.commitHash.match(commitHashPattern);
|
|
1158
|
-
if (!compilerHashMatch || compilerHashMatch.length === 0 || compilerHashMatch.length > 1)
|
|
1159
|
-
throw new Error("You should provide a valid commit hash of the circuit compiler.");
|
|
1160
|
-
// validate that the verification options are valid
|
|
1161
|
-
const verification = circuitData.verification;
|
|
1162
|
-
if (verification.cfOrVm !== "CF" && verification.cfOrVm !== "VM")
|
|
1163
|
-
throw new Error("Please enter a valid verification mechanism: either CF or VM");
|
|
1164
|
-
// @todo VM parameters verification
|
|
1165
|
-
// if (verification['cfOrVM'] === "VM") {}
|
|
1166
|
-
// check that the timeout is provided for the correct configuration
|
|
1167
|
-
let dynamicThreshold;
|
|
1168
|
-
let fixedTimeWindow;
|
|
1169
|
-
let circuit = {};
|
|
1170
|
-
if (data.timeoutMechanismType === "DYNAMIC" /* CeremonyTimeoutType.DYNAMIC */) {
|
|
1171
|
-
if (circuitData.dynamicThreshold <= 0)
|
|
1172
|
-
throw new Error("The dynamic threshold should be > 0.");
|
|
1173
|
-
dynamicThreshold = circuitData.dynamicThreshold;
|
|
1174
|
-
// the Circuit data for the ceremony setup
|
|
1175
|
-
circuit = {
|
|
1176
|
-
name: circuitData.name,
|
|
1177
|
-
description: circuitData.description,
|
|
1178
|
-
prefix: circuitPrefix,
|
|
1179
|
-
sequencePosition: i + 1,
|
|
1180
|
-
metadata: metadata,
|
|
1181
|
-
files: files,
|
|
1182
|
-
template: template,
|
|
1183
|
-
compiler: compiler,
|
|
1184
|
-
verification: verification,
|
|
1185
|
-
dynamicThreshold: dynamicThreshold,
|
|
1186
|
-
avgTimings: {
|
|
1187
|
-
contributionComputation: 0,
|
|
1188
|
-
fullContribution: 0,
|
|
1189
|
-
verifyCloudFunction: 0
|
|
1190
|
-
}
|
|
1191
|
-
};
|
|
1192
|
-
}
|
|
1193
|
-
if (data.timeoutMechanismType === "FIXED" /* CeremonyTimeoutType.FIXED */) {
|
|
1194
|
-
if (circuitData.fixedTimeWindow <= 0)
|
|
1195
|
-
throw new Error("The fixed time window threshold should be > 0.");
|
|
1196
|
-
fixedTimeWindow = circuitData.fixedTimeWindow;
|
|
1197
|
-
// the Circuit data for the ceremony setup
|
|
1198
|
-
circuit = {
|
|
1199
|
-
name: circuitData.name,
|
|
1200
|
-
description: circuitData.description,
|
|
1201
|
-
prefix: circuitPrefix,
|
|
1202
|
-
sequencePosition: i + 1,
|
|
1203
|
-
metadata: metadata,
|
|
1204
|
-
files: files,
|
|
1205
|
-
template: template,
|
|
1206
|
-
compiler: compiler,
|
|
1207
|
-
verification: verification,
|
|
1208
|
-
fixedTimeWindow: fixedTimeWindow,
|
|
1209
|
-
avgTimings: {
|
|
1210
|
-
contributionComputation: 0,
|
|
1211
|
-
fullContribution: 0,
|
|
1212
|
-
verifyCloudFunction: 0
|
|
1213
|
-
}
|
|
1214
|
-
};
|
|
1215
|
-
}
|
|
1216
|
-
circuits.push(circuit);
|
|
1217
|
-
// remove the local r1cs and wasm downloads (if used for verifying the config only vs setup)
|
|
1218
|
-
if (cleanup)
|
|
1219
|
-
fs.unlinkSync(localR1csPath);
|
|
1220
|
-
fs.unlinkSync(localWasmPath);
|
|
1221
|
-
}
|
|
1222
|
-
const setupData = {
|
|
1223
|
-
ceremonyInputData: {
|
|
1224
|
-
title: data.title,
|
|
1225
|
-
description: data.description,
|
|
1226
|
-
startDate: startDate.valueOf(),
|
|
1227
|
-
endDate: endDate.valueOf(),
|
|
1228
|
-
timeoutMechanismType: data.timeoutMechanismType,
|
|
1229
|
-
penalty: data.penalty
|
|
1230
|
-
},
|
|
1231
|
-
ceremonyPrefix: extractPrefix(data.title),
|
|
1232
|
-
circuits: circuits,
|
|
1233
|
-
circuitArtifacts: circuitArtifacts
|
|
1234
|
-
};
|
|
1235
|
-
return setupData;
|
|
1236
|
-
}
|
|
1237
|
-
catch (error) {
|
|
1238
|
-
throw new Error(`Error while parsing up the ceremony setup file. ${error.message}`);
|
|
1239
|
-
}
|
|
1240
|
-
};
|
|
1079
|
+
const convertToDoubleDigits = (amount) => (amount < 10 ? `0${amount}` : amount.toString());
|
|
1080
|
+
/**
|
|
1081
|
+
* Extract a prefix consisting of alphanumeric and underscore characters from a string with arbitrary characters.
|
|
1082
|
+
* @dev replaces all special symbols and whitespaces with an underscore char ('_'). Convert all uppercase chars to lowercase.
|
|
1083
|
+
* @notice example: str = 'Multiplier-2!2.4.zkey'; output prefix = 'multiplier_2_2_4.zkey'.
|
|
1084
|
+
* NB. Prefix extraction is a key process that conditions the name of the ceremony artifacts, download/upload from/to storage, collections paths.
|
|
1085
|
+
* @param str <string> - the arbitrary string from which to extract the prefix.
|
|
1086
|
+
* @returns <string> - the resulting prefix.
|
|
1087
|
+
*/
|
|
1088
|
+
const extractPrefix = (str) =>
|
|
1089
|
+
// eslint-disable-next-line no-useless-escape
|
|
1090
|
+
str.replace(/[`\s~!@#$%^&*()|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "-").toLowerCase();
|
|
1241
1091
|
/**
|
|
1242
1092
|
* Extract data from a R1CS metadata file generated with a custom file-based logger.
|
|
1243
1093
|
* @notice useful for extracting metadata circuits contained in the generated file using a logger
|
|
@@ -1294,17 +1144,6 @@ const formatZkeyIndex = (progress) => {
|
|
|
1294
1144
|
* @returns <number> - the amount of powers.
|
|
1295
1145
|
*/
|
|
1296
1146
|
const extractPoTFromFilename = (potCompleteFilename) => Number(potCompleteFilename.split("_").pop()?.split(".").at(0));
|
|
1297
|
-
/**
|
|
1298
|
-
* Extract a prefix consisting of alphanumeric and underscore characters from a string with arbitrary characters.
|
|
1299
|
-
* @dev replaces all special symbols and whitespaces with an underscore char ('_'). Convert all uppercase chars to lowercase.
|
|
1300
|
-
* @notice example: str = 'Multiplier-2!2.4.zkey'; output prefix = 'multiplier_2_2_4.zkey'.
|
|
1301
|
-
* NB. Prefix extraction is a key process that conditions the name of the ceremony artifacts, download/upload from/to storage, collections paths.
|
|
1302
|
-
* @param str <string> - the arbitrary string from which to extract the prefix.
|
|
1303
|
-
* @returns <string> - the resulting prefix.
|
|
1304
|
-
*/
|
|
1305
|
-
const extractPrefix = (str) =>
|
|
1306
|
-
// eslint-disable-next-line no-useless-escape
|
|
1307
|
-
str.replace(/[`\s~!@#$%^&*()|+\-=?;:'",.<>\{\}\[\]\\\/]/gi, "-").toLowerCase();
|
|
1308
1147
|
/**
|
|
1309
1148
|
* Automate the generation of an entropy for a contribution.
|
|
1310
1149
|
* @dev Took inspiration from here https://github.com/glamperd/setup-mpc-ui/blob/master/client/src/state/Compute.tsx#L112.
|
|
@@ -1444,6 +1283,41 @@ const readBytesFromFile = (localFilePath, offset, length, position) => {
|
|
|
1444
1283
|
// Return the read bytes.
|
|
1445
1284
|
return buffer;
|
|
1446
1285
|
};
|
|
1286
|
+
/**
|
|
1287
|
+
* Given a buffer in little endian format, convert it to bigint
|
|
1288
|
+
* @param buffer
|
|
1289
|
+
* @returns
|
|
1290
|
+
*/
|
|
1291
|
+
function leBufferToBigint(buffer) {
|
|
1292
|
+
return BigInt(`0x${buffer.reverse().toString("hex")}`);
|
|
1293
|
+
}
|
|
1294
|
+
/**
|
|
1295
|
+
* Given an input containing string values, convert them
|
|
1296
|
+
* to bigint
|
|
1297
|
+
* @param input - The input to convert
|
|
1298
|
+
* @returns the input with string values converted to bigint
|
|
1299
|
+
*/
|
|
1300
|
+
const unstringifyBigInts = (input) => {
|
|
1301
|
+
if (typeof input === "string" && /^[0-9]+$/.test(input)) {
|
|
1302
|
+
return BigInt(input);
|
|
1303
|
+
}
|
|
1304
|
+
if (typeof input === "string" && /^0x[0-9a-fA-F]+$/.test(input)) {
|
|
1305
|
+
return BigInt(input);
|
|
1306
|
+
}
|
|
1307
|
+
if (Array.isArray(input)) {
|
|
1308
|
+
return input.map(unstringifyBigInts);
|
|
1309
|
+
}
|
|
1310
|
+
if (input === null) {
|
|
1311
|
+
return null;
|
|
1312
|
+
}
|
|
1313
|
+
if (typeof input === "object") {
|
|
1314
|
+
return Object.entries(input).reduce((acc, [key, value]) => {
|
|
1315
|
+
acc[key] = unstringifyBigInts(value);
|
|
1316
|
+
return acc;
|
|
1317
|
+
}, {});
|
|
1318
|
+
}
|
|
1319
|
+
return input;
|
|
1320
|
+
};
|
|
1447
1321
|
/**
|
|
1448
1322
|
* Return the info about the R1CS file.ù
|
|
1449
1323
|
* @dev this method was built taking inspiration from
|
|
@@ -1504,17 +1378,17 @@ const getR1CSInfo = (localR1CSFilePath) => {
|
|
|
1504
1378
|
let constraints = 0;
|
|
1505
1379
|
try {
|
|
1506
1380
|
// Get 'number of section' (jump magic r1cs and version1 data).
|
|
1507
|
-
const numberOfSections =
|
|
1381
|
+
const numberOfSections = leBufferToBigint(readBytesFromFile(localR1CSFilePath, 0, 4, 8));
|
|
1508
1382
|
// Jump to first section.
|
|
1509
1383
|
pointer = 12;
|
|
1510
1384
|
// For each section
|
|
1511
1385
|
for (let i = 0; i < numberOfSections; i++) {
|
|
1512
1386
|
// Read section type.
|
|
1513
|
-
const sectionType =
|
|
1387
|
+
const sectionType = leBufferToBigint(readBytesFromFile(localR1CSFilePath, 0, 4, pointer));
|
|
1514
1388
|
// Jump to section size.
|
|
1515
1389
|
pointer += 4;
|
|
1516
1390
|
// Read section size
|
|
1517
|
-
const sectionSize = Number(
|
|
1391
|
+
const sectionSize = Number(leBufferToBigint(readBytesFromFile(localR1CSFilePath, 0, 8, pointer)));
|
|
1518
1392
|
// If at header section (0x00000001 : Header Section).
|
|
1519
1393
|
if (sectionType === BigInt(1)) {
|
|
1520
1394
|
// Read info from header section.
|
|
@@ -1546,22 +1420,22 @@ const getR1CSInfo = (localR1CSFilePath) => {
|
|
|
1546
1420
|
*/
|
|
1547
1421
|
pointer += sectionSize - 20;
|
|
1548
1422
|
// Read R1CS info.
|
|
1549
|
-
wires = Number(
|
|
1423
|
+
wires = Number(leBufferToBigint(readBytesFromFile(localR1CSFilePath, 0, 4, pointer)));
|
|
1550
1424
|
pointer += 4;
|
|
1551
|
-
publicOutputs = Number(
|
|
1425
|
+
publicOutputs = Number(leBufferToBigint(readBytesFromFile(localR1CSFilePath, 0, 4, pointer)));
|
|
1552
1426
|
pointer += 4;
|
|
1553
|
-
publicInputs = Number(
|
|
1427
|
+
publicInputs = Number(leBufferToBigint(readBytesFromFile(localR1CSFilePath, 0, 4, pointer)));
|
|
1554
1428
|
pointer += 4;
|
|
1555
|
-
privateInputs = Number(
|
|
1429
|
+
privateInputs = Number(leBufferToBigint(readBytesFromFile(localR1CSFilePath, 0, 4, pointer)));
|
|
1556
1430
|
pointer += 4;
|
|
1557
|
-
labels = Number(
|
|
1431
|
+
labels = Number(leBufferToBigint(readBytesFromFile(localR1CSFilePath, 0, 8, pointer)));
|
|
1558
1432
|
pointer += 8;
|
|
1559
|
-
constraints = Number(
|
|
1433
|
+
constraints = Number(leBufferToBigint(readBytesFromFile(localR1CSFilePath, 0, 4, pointer)));
|
|
1560
1434
|
}
|
|
1561
1435
|
pointer += 8 + Number(sectionSize);
|
|
1562
1436
|
}
|
|
1563
1437
|
return {
|
|
1564
|
-
curve: "bn-128",
|
|
1438
|
+
curve: "bn-128", /// @note currently default to bn-128 as we support only Groth16 proving system.
|
|
1565
1439
|
wires,
|
|
1566
1440
|
constraints,
|
|
1567
1441
|
privateInputs,
|
|
@@ -1576,11 +1450,212 @@ const getR1CSInfo = (localR1CSFilePath) => {
|
|
|
1576
1450
|
}
|
|
1577
1451
|
};
|
|
1578
1452
|
/**
|
|
1579
|
-
*
|
|
1580
|
-
* @
|
|
1581
|
-
* @
|
|
1453
|
+
* Parse and validate that the ceremony configuration is correct
|
|
1454
|
+
* @notice this does not upload any files to storage
|
|
1455
|
+
* @param path <string> - the path to the configuration file
|
|
1456
|
+
* @param cleanup <boolean> - whether to delete the r1cs file after parsing
|
|
1457
|
+
* @returns any - the data to pass to the cloud function for setup and the circuit artifacts
|
|
1582
1458
|
*/
|
|
1583
|
-
const
|
|
1459
|
+
const parseCeremonyFile = async (path, cleanup = false) => {
|
|
1460
|
+
// check that the path exists
|
|
1461
|
+
if (!fs.existsSync(path))
|
|
1462
|
+
throw new Error("The provided path to the configuration file does not exist. Please provide an absolute path and try again.");
|
|
1463
|
+
try {
|
|
1464
|
+
// read the data
|
|
1465
|
+
const data = JSON.parse(fs.readFileSync(path).toString());
|
|
1466
|
+
// verify that the data is correct
|
|
1467
|
+
if (data.timeoutMechanismType !== "DYNAMIC" /* CeremonyTimeoutType.DYNAMIC */ &&
|
|
1468
|
+
data.timeoutMechanismType !== "FIXED" /* CeremonyTimeoutType.FIXED */)
|
|
1469
|
+
throw new Error("Invalid timeout type. Please choose between DYNAMIC and FIXED.");
|
|
1470
|
+
// validate that we have at least 1 circuit input data
|
|
1471
|
+
if (!data.circuits || data.circuits.length === 0)
|
|
1472
|
+
throw new Error("You need to provide the data for at least 1 circuit.");
|
|
1473
|
+
// validate that the end date is in the future
|
|
1474
|
+
let endDate;
|
|
1475
|
+
let startDate;
|
|
1476
|
+
try {
|
|
1477
|
+
endDate = new Date(data.endDate);
|
|
1478
|
+
startDate = new Date(data.startDate);
|
|
1479
|
+
}
|
|
1480
|
+
catch (error) {
|
|
1481
|
+
throw new Error("The dates should follow this format: 2023-07-04T00:00:00.");
|
|
1482
|
+
}
|
|
1483
|
+
if (endDate <= startDate)
|
|
1484
|
+
throw new Error("The end date should be greater than the start date.");
|
|
1485
|
+
const currentDate = new Date();
|
|
1486
|
+
if (endDate <= currentDate || startDate <= currentDate)
|
|
1487
|
+
throw new Error("The start and end dates should be in the future.");
|
|
1488
|
+
// validate penalty
|
|
1489
|
+
if (data.penalty <= 0)
|
|
1490
|
+
throw new Error("The penalty should be greater than zero.");
|
|
1491
|
+
const circuits = [];
|
|
1492
|
+
const urlPattern = /(https?:\/\/[^\s]+)/g;
|
|
1493
|
+
const commitHashPattern = /^[a-f0-9]{40}$/i;
|
|
1494
|
+
const circuitArtifacts = [];
|
|
1495
|
+
for (let i = 0; i < data.circuits.length; i++) {
|
|
1496
|
+
const circuitData = data.circuits[i];
|
|
1497
|
+
const { artifacts } = circuitData;
|
|
1498
|
+
circuitArtifacts.push({
|
|
1499
|
+
artifacts
|
|
1500
|
+
});
|
|
1501
|
+
// where we storing the r1cs downloaded
|
|
1502
|
+
const localR1csPath = `./${circuitData.name}.r1cs`;
|
|
1503
|
+
// where we storing the wasm downloaded
|
|
1504
|
+
const localWasmPath = `./${circuitData.name}.wasm`;
|
|
1505
|
+
// download the r1cs to extract the metadata
|
|
1506
|
+
const streamPipeline = promisify(pipeline);
|
|
1507
|
+
// Check if r1cs file already exists
|
|
1508
|
+
let r1csExists = false;
|
|
1509
|
+
if (fs.existsSync(localR1csPath)) {
|
|
1510
|
+
console.log(`Found existing r1cs file for circuit ${circuitData.name}. Skipping download.`);
|
|
1511
|
+
r1csExists = true;
|
|
1512
|
+
}
|
|
1513
|
+
if (!r1csExists) {
|
|
1514
|
+
// Make the call to download r1cs.
|
|
1515
|
+
const responseR1CS = await fetch(artifacts.r1csStoragePath);
|
|
1516
|
+
// Handle errors.
|
|
1517
|
+
if (!responseR1CS.ok && responseR1CS.status !== 200)
|
|
1518
|
+
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.`);
|
|
1519
|
+
// Write the file locally
|
|
1520
|
+
await streamPipeline(responseR1CS.body, createWriteStream(localR1csPath));
|
|
1521
|
+
console.log(`Downloaded r1cs file for circuit ${circuitData.name}.`);
|
|
1522
|
+
}
|
|
1523
|
+
// extract the metadata from the r1cs
|
|
1524
|
+
const metadata = getR1CSInfo(localR1csPath);
|
|
1525
|
+
// Check if wasm file already exists
|
|
1526
|
+
let wasmExists = false;
|
|
1527
|
+
if (fs.existsSync(localWasmPath)) {
|
|
1528
|
+
console.log(`Found existing wasm file for circuit ${circuitData.name}. Skipping download.`);
|
|
1529
|
+
wasmExists = true;
|
|
1530
|
+
}
|
|
1531
|
+
if (!wasmExists) {
|
|
1532
|
+
// download wasm if it's not available
|
|
1533
|
+
const responseWASM = await fetch(artifacts.wasmStoragePath);
|
|
1534
|
+
if (!responseWASM.ok && responseWASM.status !== 200)
|
|
1535
|
+
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.`);
|
|
1536
|
+
await streamPipeline(responseWASM.body, createWriteStream(localWasmPath));
|
|
1537
|
+
console.log(`Downloaded wasm file for circuit ${circuitData.name}.`);
|
|
1538
|
+
}
|
|
1539
|
+
// validate that the circuit hash and template links are valid
|
|
1540
|
+
const { template } = circuitData;
|
|
1541
|
+
const URLMatch = template.source.match(urlPattern);
|
|
1542
|
+
if (!URLMatch || URLMatch.length === 0 || URLMatch.length > 1)
|
|
1543
|
+
throw new Error("You should provide the URL to the circuits templates on GitHub.");
|
|
1544
|
+
const hashMatch = template.commitHash.match(commitHashPattern);
|
|
1545
|
+
if (!hashMatch || hashMatch.length === 0 || hashMatch.length > 1)
|
|
1546
|
+
throw new Error("You should provide a valid commit hash of the circuit templates.");
|
|
1547
|
+
// calculate the hash of the r1cs file
|
|
1548
|
+
const r1csBlake2bHash = await blake512FromPath(localR1csPath);
|
|
1549
|
+
const circuitPrefix = extractPrefix(circuitData.name);
|
|
1550
|
+
// filenames
|
|
1551
|
+
const doubleDigitsPowers = convertToDoubleDigits(metadata.pot);
|
|
1552
|
+
const r1csCompleteFilename = `${circuitData.name}.r1cs`;
|
|
1553
|
+
const wasmCompleteFilename = `${circuitData.name}.wasm`;
|
|
1554
|
+
const smallestPowersOfTauCompleteFilenameForCircuit = `${potFilenameTemplate}${doubleDigitsPowers}.ptau`;
|
|
1555
|
+
const firstZkeyCompleteFilename = `${circuitPrefix}_${genesisZkeyIndex}.zkey`;
|
|
1556
|
+
// storage paths
|
|
1557
|
+
const r1csStorageFilePath = getR1csStorageFilePath(circuitPrefix, r1csCompleteFilename);
|
|
1558
|
+
const wasmStorageFilePath = getWasmStorageFilePath(circuitPrefix, wasmCompleteFilename);
|
|
1559
|
+
const potStorageFilePath = getPotStorageFilePath(smallestPowersOfTauCompleteFilenameForCircuit);
|
|
1560
|
+
const zkeyStorageFilePath = getZkeyStorageFilePath(circuitPrefix, firstZkeyCompleteFilename);
|
|
1561
|
+
const files = {
|
|
1562
|
+
potFilename: smallestPowersOfTauCompleteFilenameForCircuit,
|
|
1563
|
+
r1csFilename: r1csCompleteFilename,
|
|
1564
|
+
wasmFilename: wasmCompleteFilename,
|
|
1565
|
+
initialZkeyFilename: firstZkeyCompleteFilename,
|
|
1566
|
+
potStoragePath: potStorageFilePath,
|
|
1567
|
+
r1csStoragePath: r1csStorageFilePath,
|
|
1568
|
+
wasmStoragePath: wasmStorageFilePath,
|
|
1569
|
+
initialZkeyStoragePath: zkeyStorageFilePath,
|
|
1570
|
+
r1csBlake2bHash
|
|
1571
|
+
};
|
|
1572
|
+
// validate that the compiler hash is a valid hash
|
|
1573
|
+
const { compiler } = circuitData;
|
|
1574
|
+
const compilerHashMatch = compiler.commitHash.match(commitHashPattern);
|
|
1575
|
+
if (!compilerHashMatch || compilerHashMatch.length === 0 || compilerHashMatch.length > 1)
|
|
1576
|
+
throw new Error("You should provide a valid commit hash of the circuit compiler.");
|
|
1577
|
+
// validate that the verification options are valid
|
|
1578
|
+
const { verification } = circuitData;
|
|
1579
|
+
if (verification.cfOrVm !== "CF" && verification.cfOrVm !== "VM")
|
|
1580
|
+
throw new Error("Please enter a valid verification mechanism: either CF or VM");
|
|
1581
|
+
// @todo VM parameters verification
|
|
1582
|
+
// if (verification['cfOrVM'] === "VM") {}
|
|
1583
|
+
// check that the timeout is provided for the correct configuration
|
|
1584
|
+
let dynamicThreshold;
|
|
1585
|
+
let fixedTimeWindow;
|
|
1586
|
+
let circuit = {};
|
|
1587
|
+
if (data.timeoutMechanismType === "DYNAMIC" /* CeremonyTimeoutType.DYNAMIC */) {
|
|
1588
|
+
if (circuitData.dynamicThreshold <= 0)
|
|
1589
|
+
throw new Error("The dynamic threshold should be > 0.");
|
|
1590
|
+
dynamicThreshold = circuitData.dynamicThreshold;
|
|
1591
|
+
// the Circuit data for the ceremony setup
|
|
1592
|
+
circuit = {
|
|
1593
|
+
name: circuitData.name,
|
|
1594
|
+
description: circuitData.description,
|
|
1595
|
+
prefix: circuitPrefix,
|
|
1596
|
+
sequencePosition: i + 1,
|
|
1597
|
+
metadata,
|
|
1598
|
+
files,
|
|
1599
|
+
template,
|
|
1600
|
+
compiler,
|
|
1601
|
+
verification,
|
|
1602
|
+
dynamicThreshold,
|
|
1603
|
+
avgTimings: {
|
|
1604
|
+
contributionComputation: 0,
|
|
1605
|
+
fullContribution: 0,
|
|
1606
|
+
verifyCloudFunction: 0
|
|
1607
|
+
}
|
|
1608
|
+
};
|
|
1609
|
+
}
|
|
1610
|
+
if (data.timeoutMechanismType === "FIXED" /* CeremonyTimeoutType.FIXED */) {
|
|
1611
|
+
if (circuitData.fixedTimeWindow <= 0)
|
|
1612
|
+
throw new Error("The fixed time window threshold should be > 0.");
|
|
1613
|
+
fixedTimeWindow = circuitData.fixedTimeWindow;
|
|
1614
|
+
// the Circuit data for the ceremony setup
|
|
1615
|
+
circuit = {
|
|
1616
|
+
name: circuitData.name,
|
|
1617
|
+
description: circuitData.description,
|
|
1618
|
+
prefix: circuitPrefix,
|
|
1619
|
+
sequencePosition: i + 1,
|
|
1620
|
+
metadata,
|
|
1621
|
+
files,
|
|
1622
|
+
template,
|
|
1623
|
+
compiler,
|
|
1624
|
+
verification,
|
|
1625
|
+
fixedTimeWindow,
|
|
1626
|
+
avgTimings: {
|
|
1627
|
+
contributionComputation: 0,
|
|
1628
|
+
fullContribution: 0,
|
|
1629
|
+
verifyCloudFunction: 0
|
|
1630
|
+
}
|
|
1631
|
+
};
|
|
1632
|
+
}
|
|
1633
|
+
circuits.push(circuit);
|
|
1634
|
+
// remove the local r1cs and wasm downloads (if used for verifying the config only vs setup)
|
|
1635
|
+
if (cleanup) {
|
|
1636
|
+
fs.unlinkSync(localR1csPath);
|
|
1637
|
+
fs.unlinkSync(localWasmPath);
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
const setupData = {
|
|
1641
|
+
ceremonyInputData: {
|
|
1642
|
+
title: data.title,
|
|
1643
|
+
description: data.description,
|
|
1644
|
+
startDate: startDate.valueOf(),
|
|
1645
|
+
endDate: endDate.valueOf(),
|
|
1646
|
+
timeoutMechanismType: data.timeoutMechanismType,
|
|
1647
|
+
penalty: data.penalty
|
|
1648
|
+
},
|
|
1649
|
+
ceremonyPrefix: extractPrefix(data.title),
|
|
1650
|
+
circuits,
|
|
1651
|
+
circuitArtifacts
|
|
1652
|
+
};
|
|
1653
|
+
return setupData;
|
|
1654
|
+
}
|
|
1655
|
+
catch (error) {
|
|
1656
|
+
throw new Error(`Error while parsing up the ceremony setup file. ${error.message}`);
|
|
1657
|
+
}
|
|
1658
|
+
};
|
|
1584
1659
|
|
|
1585
1660
|
/**
|
|
1586
1661
|
* Verify that a zKey is valid
|
|
@@ -1838,14 +1913,14 @@ const getAWSVariables = () => {
|
|
|
1838
1913
|
if (!process.env.AWS_ACCESS_KEY_ID ||
|
|
1839
1914
|
!process.env.AWS_SECRET_ACCESS_KEY ||
|
|
1840
1915
|
!process.env.AWS_REGION ||
|
|
1841
|
-
!process.env.
|
|
1916
|
+
!process.env.AWS_INSTANCE_PROFILE_ARN ||
|
|
1842
1917
|
!process.env.AWS_AMI_ID)
|
|
1843
1918
|
throw new Error("Could not retrieve the AWS environment variables. Please, verify your environment configuration and retry");
|
|
1844
1919
|
return {
|
|
1845
1920
|
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
1846
1921
|
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
1847
1922
|
region: process.env.AWS_REGION || "us-east-1",
|
|
1848
|
-
|
|
1923
|
+
instanceProfileArn: process.env.AWS_INSTANCE_PROFILE_ARN,
|
|
1849
1924
|
amiId: process.env.AWS_AMI_ID
|
|
1850
1925
|
};
|
|
1851
1926
|
};
|
|
@@ -1926,11 +2001,11 @@ const p256 = (proofPart) => {
|
|
|
1926
2001
|
*/
|
|
1927
2002
|
const formatSolidityCalldata = (circuitInput, _proof) => {
|
|
1928
2003
|
try {
|
|
1929
|
-
const proof =
|
|
2004
|
+
const proof = unstringifyBigInts(_proof);
|
|
1930
2005
|
// format the public inputs to the circuit
|
|
1931
2006
|
const formattedCircuitInput = [];
|
|
1932
2007
|
for (const cInput of circuitInput) {
|
|
1933
|
-
formattedCircuitInput.push(p256(
|
|
2008
|
+
formattedCircuitInput.push(p256(unstringifyBigInts(cInput)));
|
|
1934
2009
|
}
|
|
1935
2010
|
// construct calldata
|
|
1936
2011
|
const calldata = {
|
|
@@ -2098,7 +2173,8 @@ const getGitHubStats = async (user) => {
|
|
|
2098
2173
|
following: jsonData.following,
|
|
2099
2174
|
followers: jsonData.followers,
|
|
2100
2175
|
publicRepos: jsonData.public_repos,
|
|
2101
|
-
avatarUrl: jsonData.avatar_url
|
|
2176
|
+
avatarUrl: jsonData.avatar_url,
|
|
2177
|
+
age: jsonData.created_at
|
|
2102
2178
|
};
|
|
2103
2179
|
return data;
|
|
2104
2180
|
};
|
|
@@ -2110,20 +2186,21 @@ const getGitHubStats = async (user) => {
|
|
|
2110
2186
|
* @param minimumAmountOfPublicRepos <number> The minimum amount of public repos the user should have
|
|
2111
2187
|
* @returns <any> Return the avatar URL of the user if the user is reputable, false otherwise
|
|
2112
2188
|
*/
|
|
2113
|
-
const githubReputation = async (userLogin, minimumAmountOfFollowing, minimumAmountOfFollowers, minimumAmountOfPublicRepos) => {
|
|
2189
|
+
const githubReputation = async (userLogin, minimumAmountOfFollowing, minimumAmountOfFollowers, minimumAmountOfPublicRepos, minimumAge) => {
|
|
2114
2190
|
if (!process.env.GITHUB_ACCESS_TOKEN)
|
|
2115
2191
|
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.");
|
|
2116
|
-
const { following, followers, publicRepos, avatarUrl } = await getGitHubStats(userLogin);
|
|
2192
|
+
const { following, followers, publicRepos, avatarUrl, age } = await getGitHubStats(userLogin);
|
|
2117
2193
|
if (following < minimumAmountOfFollowing ||
|
|
2118
2194
|
publicRepos < minimumAmountOfPublicRepos ||
|
|
2119
|
-
followers < minimumAmountOfFollowers
|
|
2195
|
+
followers < minimumAmountOfFollowers ||
|
|
2196
|
+
new Date(age) > new Date(Date.now() - minimumAge))
|
|
2120
2197
|
return {
|
|
2121
2198
|
reputable: false,
|
|
2122
2199
|
avatarUrl: ""
|
|
2123
2200
|
};
|
|
2124
2201
|
return {
|
|
2125
2202
|
reputable: true,
|
|
2126
|
-
avatarUrl
|
|
2203
|
+
avatarUrl
|
|
2127
2204
|
};
|
|
2128
2205
|
};
|
|
2129
2206
|
|
|
@@ -2310,8 +2387,8 @@ const createSSMClient = async () => {
|
|
|
2310
2387
|
* @returns <Array<string>> - the list of startup commands to be executed.
|
|
2311
2388
|
*/
|
|
2312
2389
|
const vmBootstrapCommand = (bucketName) => [
|
|
2313
|
-
"#!/bin/bash",
|
|
2314
|
-
`aws s3 cp s3://${bucketName}/${vmBootstrapScriptFilename} ${vmBootstrapScriptFilename}`,
|
|
2390
|
+
"#!/bin/bash", // shabang.
|
|
2391
|
+
`aws s3 cp s3://${bucketName}/${vmBootstrapScriptFilename} ${vmBootstrapScriptFilename}`, // copy file from S3 bucket to VM.
|
|
2315
2392
|
`chmod +x ${vmBootstrapScriptFilename} && bash ${vmBootstrapScriptFilename}` // grant permission and execute.
|
|
2316
2393
|
];
|
|
2317
2394
|
/**
|
|
@@ -2384,8 +2461,9 @@ const computeDiskSizeForVM = (zKeySizeInBytes, pot) => Math.ceil(2 * convertByte
|
|
|
2384
2461
|
*/
|
|
2385
2462
|
const createEC2Instance = async (ec2, commands, instanceType, volumeSize, diskType) => {
|
|
2386
2463
|
// Get the AWS variables.
|
|
2387
|
-
const { amiId,
|
|
2464
|
+
const { amiId, instanceProfileArn } = getAWSVariables();
|
|
2388
2465
|
// Parametrize the VM EC2 instance.
|
|
2466
|
+
console.log("\nLAUNCHING AWS EC2 INSTANCE\n");
|
|
2389
2467
|
const params = {
|
|
2390
2468
|
ImageId: amiId,
|
|
2391
2469
|
InstanceType: instanceType,
|
|
@@ -2393,7 +2471,7 @@ const createEC2Instance = async (ec2, commands, instanceType, volumeSize, diskTy
|
|
|
2393
2471
|
MinCount: 1,
|
|
2394
2472
|
// nb. to find this: iam -> roles -> role_name.
|
|
2395
2473
|
IamInstanceProfile: {
|
|
2396
|
-
Arn:
|
|
2474
|
+
Arn: instanceProfileArn
|
|
2397
2475
|
},
|
|
2398
2476
|
// nb. for running commands at the startup.
|
|
2399
2477
|
UserData: Buffer.from(commands.join("\n")).toString("base64"),
|
|
@@ -2402,7 +2480,7 @@ const createEC2Instance = async (ec2, commands, instanceType, volumeSize, diskTy
|
|
|
2402
2480
|
DeviceName: "/dev/xvda",
|
|
2403
2481
|
Ebs: {
|
|
2404
2482
|
DeleteOnTermination: true,
|
|
2405
|
-
VolumeSize: volumeSize,
|
|
2483
|
+
VolumeSize: volumeSize, // disk size in GB.
|
|
2406
2484
|
VolumeType: diskType
|
|
2407
2485
|
}
|
|
2408
2486
|
}
|
|
@@ -2419,6 +2497,19 @@ const createEC2Instance = async (ec2, commands, instanceType, volumeSize, diskTy
|
|
|
2419
2497
|
{
|
|
2420
2498
|
Key: "Initialized",
|
|
2421
2499
|
Value: "false"
|
|
2500
|
+
},
|
|
2501
|
+
{
|
|
2502
|
+
Key: "Project",
|
|
2503
|
+
Value: "trusted-setup"
|
|
2504
|
+
}
|
|
2505
|
+
]
|
|
2506
|
+
},
|
|
2507
|
+
{
|
|
2508
|
+
ResourceType: "volume",
|
|
2509
|
+
Tags: [
|
|
2510
|
+
{
|
|
2511
|
+
Key: "Project",
|
|
2512
|
+
Value: "trusted-setup"
|
|
2422
2513
|
}
|
|
2423
2514
|
]
|
|
2424
2515
|
}
|
|
@@ -2588,4 +2679,4 @@ const retrieveCommandStatus = async (ssm, instanceId, commandId) => {
|
|
|
2588
2679
|
}
|
|
2589
2680
|
};
|
|
2590
2681
|
|
|
2591
|
-
export { CeremonyState, CeremonyTimeoutType, CeremonyType, CircuitContributionVerificationMechanism, DiskTypeForVM, ParticipantContributionStep, ParticipantStatus, RequestType, TestingEnvironment, TimeoutType, autoGenerateEntropy, blake512FromPath, checkAndPrepareCoordinatorForFinalization, checkIfObjectExist, checkIfRunning, checkParticipantForCeremony, commonTerms, compareCeremonyArtifacts, compareHashes, compileContract, completeMultiPartUpload, computeDiskSizeForVM, computeSHA256ToHex, computeSmallestPowersOfTauForCircuit, convertBytesOrKbToGb, convertToDoubleDigits, createCustomLoggerForFile, createEC2Client, createEC2Instance, createS3Bucket, createSSMClient, downloadAllCeremonyArtifacts, downloadCeremonyArtifact, ec2InstanceTag, exportVerifierAndVKey, exportVerifierContract, exportVkey, extractPoTFromFilename, extractPrefix, extractR1CSInfoValueForGivenKey, finalContributionIndex, finalizeCeremony, finalizeCircuit, formatSolidityCalldata, formatZkeyIndex, fromQueryToFirebaseDocumentInfo, generateGROTH16Proof, generateGetObjectPreSignedUrl, generatePreSignedUrlsParts, generateValidContributionsAttestation, generateZkeyFromScratch, genesisZkeyIndex, getAllCollectionDocs, getBucketName, getCeremonyCircuits, getCircuitBySequencePosition, getCircuitContributionsFromContributor, getCircuitsCollectionPath, getClosedCeremonies, getContributionsCollectionPath, getContributionsValidityForContributor, getCurrentActiveParticipantTimeout, getCurrentFirebaseAuthUser, getDocumentById, getOpenedCeremonies, getParticipantsCollectionPath, getPotStorageFilePath, getPublicAttestationPreambleForContributor, getR1CSInfo, getR1csStorageFilePath, getTimeoutsCollectionPath, getTranscriptStorageFilePath, getVerificationKeyStorageFilePath, getVerifierContractStorageFilePath, getWasmStorageFilePath, getZkeyStorageFilePath, githubReputation, initializeFirebaseCoreServices, isCoordinator, multiPartUpload, numExpIterations, p256, parseCeremonyFile, permanentlyStoreCurrentContributionTimeAndHash, potFileDownloadMainUrl, potFilenameTemplate, powersOfTauFiles, progressToNextCircuitForContribution, progressToNextContributionStep, queryCollection, resumeContributionAfterTimeoutExpiration, retrieveCommandOutput, retrieveCommandStatus, runCommandUsingSSM, setupCeremony, signInToFirebaseWithCredentials, solidityVersion, startEC2Instance, stopEC2Instance, temporaryStoreCurrentContributionMultiPartUploadId, temporaryStoreCurrentContributionUploadedChunkData, terminateEC2Instance, toHex, verificationKeyAcronym, verifierSmartContractAcronym, verifyCeremony, verifyContribution, verifyGROTH16Proof, verifyGROTH16ProofOnChain, verifyZKey, vmBootstrapCommand, vmBootstrapScriptFilename, vmConfigurationTypes, vmContributionVerificationCommand, vmDependenciesAndCacheArtifactsCommand };
|
|
2682
|
+
export { CeremonyState, CeremonyTimeoutType, CeremonyType, CircuitContributionVerificationMechanism, DiskTypeForVM, ParticipantContributionStep, ParticipantStatus, RequestType, TestingEnvironment, TimeoutType, autoGenerateEntropy, blake512FromPath, checkAndPrepareCoordinatorForFinalization, checkIfObjectExist, checkIfRunning, checkParticipantForCeremony, commonTerms, compareCeremonyArtifacts, compareHashes, compileContract, completeMultiPartUpload, computeDiskSizeForVM, computeSHA256ToHex, computeSmallestPowersOfTauForCircuit, contribHashRegex, convertBytesOrKbToGb, convertToDoubleDigits, createCustomLoggerForFile, createEC2Client, createEC2Instance, createS3Bucket, createSSMClient, downloadAllCeremonyArtifacts, downloadCeremonyArtifact, ec2InstanceTag, exportVerifierAndVKey, exportVerifierContract, exportVkey, extractPoTFromFilename, extractPrefix, extractR1CSInfoValueForGivenKey, finalContributionIndex, finalizeCeremony, finalizeCircuit, formatSolidityCalldata, formatZkeyIndex, fromQueryToFirebaseDocumentInfo, generateGROTH16Proof, generateGetObjectPreSignedUrl, generatePreSignedUrlsParts, generateValidContributionsAttestation, generateZkeyFromScratch, genesisZkeyIndex, getAllCeremonies, getAllCollectionDocs, getBucketName, getCeremonyCircuits, getCircuitBySequencePosition, getCircuitContributionsFromContributor, getCircuitsCollectionPath, getClosedCeremonies, getContributionsCollectionPath, getContributionsValidityForContributor, getCurrentActiveParticipantTimeout, getCurrentFirebaseAuthUser, getDocumentById, getOpenedCeremonies, getParticipantsCollectionPath, getPotStorageFilePath, getPublicAttestationPreambleForContributor, getR1CSInfo, getR1csStorageFilePath, getTimeoutsCollectionPath, getTranscriptStorageFilePath, getVerificationKeyStorageFilePath, getVerifierContractStorageFilePath, getWasmStorageFilePath, getZkeyStorageFilePath, githubReputation, initializeFirebaseCoreServices, isCoordinator, multiPartUpload, numExpIterations, p256, parseCeremonyFile, permanentlyStoreCurrentContributionTimeAndHash, potFileDownloadMainUrl, potFilenameTemplate, powersOfTauFiles, progressToNextCircuitForContribution, progressToNextContributionStep, queryCollection, resumeContributionAfterTimeoutExpiration, retrieveCommandOutput, retrieveCommandStatus, runCommandUsingSSM, setupCeremony, signInToFirebaseWithCredentials, solidityVersion, startEC2Instance, stopEC2Instance, temporaryStoreCurrentContributionMultiPartUploadId, temporaryStoreCurrentContributionUploadedChunkData, terminateEC2Instance, toHex, verificationKeyAcronym, verifierSmartContractAcronym, verifyCeremony, verifyContribution, verifyGROTH16Proof, verifyGROTH16ProofOnChain, verifyZKey, vmBootstrapCommand, vmBootstrapScriptFilename, vmConfigurationTypes, vmContributionVerificationCommand, vmDependenciesAndCacheArtifactsCommand };
|