Skip to content

Commit

Permalink
Merge pull request #156 from privacy-scaling-explorations/staging
Browse files Browse the repository at this point in the history
chore(merge) - staging to main
  • Loading branch information
daodesigner authored Aug 18, 2023
2 parents f6f48a2 + 2fc617a commit 99b61a3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 47 deletions.
39 changes: 17 additions & 22 deletions packages/actions/src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,49 +87,44 @@ export const parseCeremonyFile = async (path: string, cleanup: boolean = false):
circuitArtifacts.push({
artifacts: artifacts
})
const r1csPath = artifacts.r1csStoragePath
const wasmPath = artifacts.wasmStoragePath

// where we storing the r1cs downloaded
const localR1csPath = `./${circuitData.name}.r1cs`
// where we storing the wasm downloaded
const localWasmPath = `./${circuitData.name}.wasm`

// check that the artifacts exist in S3
// we don't need any privileges to download this
// just the correct region
const s3 = new S3Client({region: artifacts.region})

try {
await s3.send(new HeadObjectCommand({
Bucket: artifacts.bucket,
Key: r1csPath
}))
} catch (error: any) {
throw new Error(`The r1cs file (${r1csPath}) seems to not exist. Please ensure this is correct and that the object is publicly available.`)
}

try {
await s3.send(new HeadObjectCommand({
Bucket: artifacts.bucket,
Key: wasmPath
}))
} catch (error: any) {
throw new Error(`The wasm file (${wasmPath}) seems to not exist. Please ensure this is correct and that the object is publicly available.`)
}
const s3 = new S3Client({
region: artifacts.region,
credentials: undefined
})

// download the r1cs to extract the metadata
const command = new GetObjectCommand({ Bucket: artifacts.bucket, Key: artifacts.r1csStoragePath })
const response = await s3.send(command)
const streamPipeline = promisify(pipeline)

if (response.$metadata.httpStatusCode !== 200)
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.")
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.`)

if (response.Body instanceof Readable)
await streamPipeline(response.Body, fs.createWriteStream(localR1csPath))

// extract the metadata from the r1cs
const metadata = getR1CSInfo(localR1csPath)

// download wasm too to ensure it's available
const wasmCommand = new GetObjectCommand({ Bucket: artifacts.bucket, Key: artifacts.wasmStoragePath })
const wasmResponse = await s3.send(wasmCommand)

if (wasmResponse.$metadata.httpStatusCode !== 200)
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.`)

if (wasmResponse.Body instanceof Readable)
await streamPipeline(wasmResponse.Body, fs.createWriteStream(localWasmPath))

// validate that the circuit hash and template links are valid
const template = circuitData.template

Expand Down
29 changes: 4 additions & 25 deletions packages/phase2cli/src/commands/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,6 @@ const setup = async (cmd: { template?: string, auth?: string}) => {
const bucketName = await handleCeremonyBucketCreation(firebaseFunctions, ceremonySetupData.ceremonyPrefix)
console.log(`\n${theme.symbols.success} Ceremony bucket name: ${theme.text.bold(bucketName)}`)

// create S3 clienbt
const s3 = new S3Client({region: 'us-east-1'})

// loop through each circuit
for await (const circuit of setupCeremonyData.circuits) {
// Local paths.
Expand All @@ -529,32 +526,14 @@ const setup = async (cmd: { template?: string, auth?: string}) => {
const zkeyLocalPathAndFileName = getZkeyLocalFilePath(circuit.files.initialZkeyFilename)

// 2. download the pot and wasm files
const streamPipeline = promisify(pipeline)
await checkAndDownloadSmallestPowersOfTau(convertToDoubleDigits(circuit.metadata?.pot!), circuit.files.potFilename)

// download the wasm to calculate the hash
const spinner = customSpinner(
`Downloading the ${theme.text.bold(
`#${circuit.name}`
)} WASM file from the project's bucket...`,
`clock`
)
spinner.start()
const command = new GetObjectCommand({ Bucket: ceremonySetupData.circuitArtifacts[index].artifacts.bucket, Key: ceremonySetupData.circuitArtifacts[index].artifacts.wasmStoragePath })

const response = await s3.send(command)

if (response.$metadata.httpStatusCode !== 200) {
throw new Error("There was an error while trying to download the wasm file. Please check that the file has the correct permissions (public) set.")
}

if (response.Body instanceof Readable)
await streamPipeline(response.Body, createWriteStream(wasmLocalPathAndFileName))

spinner.stop()
// 3. generate the zKey
const spinner = customSpinner(`Generating genesis zKey for circuit ${theme.text.bold(circuit.name)}...`, `clock`)
spinner.start()
await zKey.newZKey(r1csLocalPathAndFileName, getPotLocalFilePath(circuit.files.potFilename), zkeyLocalPathAndFileName, undefined)

spinner.succeed(`Generation of the genesis zKey for citcui ${theme.text.bold(circuit.name)} completed successfully`)

// 4. calculate the hashes
const wasmBlake2bHash = await blake512FromPath(wasmLocalPathAndFileName)
const potBlake2bHash = await blake512FromPath(getPotLocalFilePath(circuit.files.potFilename))
Expand Down

0 comments on commit 99b61a3

Please sign in to comment.