Skip to content

Commit

Permalink
fix(setup): add missing circuit artifacts local path
Browse files Browse the repository at this point in the history
allow circuit artifacts to be in a separate folder for setup so that it can be used with
definitelySetup
  • Loading branch information
ctrlc03 committed Jul 10, 2023
1 parent 865a06f commit 15b8743
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 49 deletions.
15 changes: 11 additions & 4 deletions packages/actions/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
FirebaseDocumentInfo,
SetupCeremonyData,
CeremonySetupTemplate,
CeremonySetupTemplateCircuitArtifacts
CeremonySetupTemplateCircuitArtifacts,
} from "../types/index"
import { finalContributionIndex, genesisZkeyIndex, potFilenameTemplate } from "./constants"
import {
Expand All @@ -34,7 +34,7 @@ import {
* @param path <string> - 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.")

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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}`)
}
Expand Down
39 changes: 2 additions & 37 deletions packages/actions/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -611,50 +611,15 @@ export type VMConfigurationType = {
* @property {CeremonyInputData} - the details of the ceremony
* @property {string} - the ceremony prefix
* @property {Array<CircuitDocument>} - the details of the circuits
* @property {Array<CeremonyArtifacts>} - the details of the ceremony artifacts
*/
export type SetupCeremonyData = {
ceremonyInputData: CeremonyInputData
ceremonyPrefix: string
circuits: Array<CircuitDocument>
circuitArtifacts: Array<CeremonySetupTemplateCircuitArtifacts>
}

/*
{
"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: {
Expand Down
8 changes: 4 additions & 4 deletions packages/actions/test/e2e/contribution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,18 @@ 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`
)}`
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()
Expand All @@ -209,7 +209,7 @@ describe("Contribution", () => {
new Date().valueOf(),
contributionHash
)
await sleep(2000)
await sleep(3000)

await progressToNextContributionStep(userFunctions, ceremonyId)
await sleep(1000)
Expand Down
8 changes: 4 additions & 4 deletions packages/phase2cli/src/commands/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 15b8743

Please sign in to comment.