diff --git a/packages/actions/src/helpers/utils.ts b/packages/actions/src/helpers/utils.ts index 2b92ffc9..d11e2466 100644 --- a/packages/actions/src/helpers/utils.ts +++ b/packages/actions/src/helpers/utils.ts @@ -11,7 +11,7 @@ import { FirebaseDocumentInfo, SetupCeremonyData, CeremonySetupTemplate, - CeremonySetupTemplateCircuitArtifacts + CeremonySetupTemplateCircuitArtifacts, } from "../types/index" import { finalContributionIndex, genesisZkeyIndex, potFilenameTemplate } from "./constants" import { @@ -34,7 +34,7 @@ import { * @param path - the path to the configuration file * @returns any - the data to pass to the cloud function for setup and the circuit artifacts */ -export const parseCeremonyFile = (path: string): { setupCeremonyData: SetupCeremonyData, circuitArtifacts: CeremonySetupTemplateCircuitArtifacts } => { +export const parseCeremonyFile = (path: string): SetupCeremonyData => { // check that the path exists if (!fs.existsSync(path)) throw new Error("Error while setting up the ceremony. The provided path to the configuration file does not exist. Please provide an absolute path and try again.") @@ -74,9 +74,14 @@ export const parseCeremonyFile = (path: string): { setupCeremonyData: SetupCerem const urlPattern = /(https?:\/\/[^\s]+)/g const commitHashPattern = /^[a-f0-9]{40}$/i + const circuitArtifacts: CeremonySetupTemplateCircuitArtifacts[] = [] + for (let i = 0; i < data.circuits.length; i++) { const circuitData = data.circuits[i] const artifacts = circuitData.artifacts + circuitArtifacts.push({ + artifacts: artifacts + }) const r1csPath = artifacts.r1csLocalFilePath const wasmPath = artifacts.wasmLocalFilePath @@ -184,10 +189,12 @@ export const parseCeremonyFile = (path: string): { setupCeremonyData: SetupCerem penalty: data.penalty }, ceremonyPrefix: extractPrefix(data.title), - circuits: circuits + circuits: circuits, + circuitArtifacts: circuitArtifacts } - return setupData + return setupData + } catch (error: any) { throw new Error(`Error while setting up the ceremony. ${error.message}`) } diff --git a/packages/actions/src/types/index.ts b/packages/actions/src/types/index.ts index b3fcf840..28172266 100644 --- a/packages/actions/src/types/index.ts +++ b/packages/actions/src/types/index.ts @@ -611,50 +611,15 @@ export type VMConfigurationType = { * @property {CeremonyInputData} - the details of the ceremony * @property {string} - the ceremony prefix * @property {Array} - the details of the circuits + * @property {Array} - the details of the ceremony artifacts */ export type SetupCeremonyData = { ceremonyInputData: CeremonyInputData ceremonyPrefix: string circuits: Array + circuitArtifacts: Array } -/* -{ - "title": "Example Ceremony", - "description": "This is an example ceremony", - "startDate": "2023-07-07T00:00:00", - "endDate": "2023-07-10T00:00:00", - "timeoutMechanismType": "FIXED", - "penalty": 10, - "timeoutThreshold": 3600, - "threshold": 10, - "circuits": [ - { - "description": "description", - "compiler": { - "version": "1.0", - "commitHash": "b7ad01b11f9b4195e38ecc772291251260ab2c67" - }, - "template": { - "source": "https://github.com/circuit.circom", - "commitHash": "b7ad01b11f9b4195e38ecc772291251260ab2c67", - "paramConfiguration": [6,8,3,2] - }, - "verification": { - "cfOrVM": "CF" - }, - "artifacts": { - "r1csLocalFilePath": "./circuit.r1cs", - "wasmLocalFilePath": "./circuit.wasm" - }, - "name": "circuit", - "dynamicThreshold": 0, - "fixedTimeWindow": 3600, - "sequencePosition": 1 - } - ] - } -*/ export type CeremonySetupTemplateCircuitArtifacts = { artifacts: { diff --git a/packages/actions/test/e2e/contribution.test.ts b/packages/actions/test/e2e/contribution.test.ts index 2002c1d5..7174beb2 100644 --- a/packages/actions/test/e2e/contribution.test.ts +++ b/packages/actions/test/e2e/contribution.test.ts @@ -183,10 +183,10 @@ describe("Contribution", () => { await sleep(500) // Write the file to disk. fs.writeFileSync(lastZkeyLocalFilePath, await getResponse.buffer()) - await sleep(500) + await sleep(1000) // 9. progress to next step await progressToNextCircuitForContribution(userFunctions, ceremonyId) - await sleep(1000) + await sleep(2000) transcriptLocalFilePath = `${outputDirectory}/${getTranscriptLocalFilePath( `${circuit.data.prefix}_${nextZkeyIndex}.log` @@ -194,7 +194,7 @@ describe("Contribution", () => { const transcriptLogger = createCustomLoggerForFile(transcriptLocalFilePath) // 10. do contribution await zKey.contribute(lastZkeyLocalFilePath, nextZkeyLocalFilePath, users[2].uid, entropy, transcriptLogger) - await sleep(1000) + await sleep(2000) // read the contribution hash const transcriptContents = fs.readFileSync(transcriptLocalFilePath, "utf-8").toString() @@ -209,7 +209,7 @@ describe("Contribution", () => { new Date().valueOf(), contributionHash ) - await sleep(2000) + await sleep(3000) await progressToNextContributionStep(userFunctions, ceremonyId) await sleep(1000) diff --git a/packages/phase2cli/src/commands/setup.ts b/packages/phase2cli/src/commands/setup.ts index 6598a794..745c39e8 100644 --- a/packages/phase2cli/src/commands/setup.ts +++ b/packages/phase2cli/src/commands/setup.ts @@ -502,7 +502,7 @@ const setup = async (cmd: { template?: string, auth?: string}) => { if (cmd.template) { // 1. parse the file // tmp data - const { setupCeremonyData, circuitArtifacts} = parseCeremonyFile(cmd.template!) + const setupCeremonyData = parseCeremonyFile(cmd.template!) // final setup data const ceremonySetupData = setupCeremonyData @@ -513,8 +513,9 @@ const setup = async (cmd: { template?: string, auth?: string}) => { // loop through each circuit for (const circuit of setupCeremonyData.circuits) { // Local paths. - const r1csLocalPathAndFileName = circuitArtifacts.artifacts.r1csLocalFilePath - const wasmLocalPathAndFileName = circuitArtifacts.artifacts.wasmLocalFilePath + const index = ceremonySetupData.circuits.indexOf(circuit) + const r1csLocalPathAndFileName = setupCeremonyData.circuitArtifacts[index].artifacts.r1csLocalFilePath + const wasmLocalPathAndFileName = setupCeremonyData.circuitArtifacts[index].artifacts.wasmLocalFilePath const potLocalPathAndFileName = getPotLocalFilePath(circuit.files.potFilename) const zkeyLocalPathAndFileName = getZkeyLocalFilePath(circuit.files.initialZkeyFilename) @@ -575,7 +576,6 @@ const setup = async (cmd: { template?: string, auth?: string}) => { ) // 6 update the setup data object - const index = ceremonySetupData.circuits.indexOf(circuit) ceremonySetupData.circuits[index].files = { ...circuit.files, potBlake2bHash: potBlake2bHash,