Skip to content

Commit

Permalink
Merge pull request #157 from privacy-scaling-explorations/fix/non-int…
Browse files Browse the repository at this point in the history
…eractive-setup

fix(setup): remove S3 usage and download from URL
  • Loading branch information
ctrlc03 authored Aug 22, 2023
2 parents 4f2b2be + 03984b5 commit 72b6713
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 33 deletions.
46 changes: 19 additions & 27 deletions packages/actions/src/helpers/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Firestore } from "firebase/firestore"
import fs, { ReadPosition } from "fs"
import fs, { ReadPosition, createWriteStream } from "fs"
import { utils as ffUtils } from "ffjavascript"
import winston, { Logger } from "winston"
import { S3Client, GetObjectCommand, HeadObjectCommand } from "@aws-sdk/client-s3"
import fetch from "@adobe/node-fetch-retry"
import {
CircuitMetadata,
Contribution,
Expand All @@ -29,7 +29,7 @@ import {
getZkeyStorageFilePath
} from "./storage"
import { blake512FromPath } from "./crypto"
import { Readable, pipeline } from "stream"
import { pipeline } from "stream"
import { promisify } from "util"

/**
Expand Down Expand Up @@ -93,37 +93,27 @@ export const parseCeremonyFile = async (path: string, cleanup: boolean = false):
// 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,
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)
// Make the call.
const responseR1CS = await fetch(artifacts.r1csStoragePath)

// Handle errors.
if (!responseR1CS.ok && responseR1CS.status !== 200)
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))
await streamPipeline(responseR1CS.body!, createWriteStream(localR1csPath))
// Write the file locally

// 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))
const responseWASM = await fetch(artifacts.wasmStoragePath)
if (!responseWASM.ok && responseWASM.status !== 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.`)
await streamPipeline(responseWASM.body!, createWriteStream(localWasmPath))

// validate that the circuit hash and template links are valid
const template = circuitData.template
Expand Down Expand Up @@ -239,8 +229,10 @@ export const parseCeremonyFile = async (path: string, cleanup: boolean = false):

circuits.push(circuit)

// remove the local r1cs download (if used for verifying the config only vs setup)
if (cleanup) fs.unlinkSync(localR1csPath)
// remove the local r1cs and wasm downloads (if used for verifying the config only vs setup)
if (cleanup)
fs.unlinkSync(localR1csPath)
fs.unlinkSync(localWasmPath)
}

const setupData: SetupCeremonyData = {
Expand Down
6 changes: 2 additions & 4 deletions packages/actions/test/data/artifacts/ceremonySetup.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,8 @@
"cfOrVm": "CF"
},
"artifacts": {
"bucket": "p0tion-test-definitely-setup",
"region": "us-east-1",
"r1csStoragePath": "circuit.r1cs",
"wasmStoragePath": "circuit.wasm"
"r1csStoragePath": "https://p0tion-test-definitely-setup.s3.amazonaws.com/circuit.r1cs",
"wasmStoragePath": "https://p0tion-test-definitely-setup.s3.amazonaws.com/circuit.wasm"
},
"name": "circuit",
"dynamicThreshold": 0,
Expand Down
2 changes: 0 additions & 2 deletions packages/phase2cli/src/commands/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { pipeline } from "node:stream"
import { promisify } from "node:util"
import fetch from "node-fetch"
import { Functions } from "firebase/functions"
import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3"
import {
CeremonyTimeoutType,
CircomCompilerData,
Expand Down Expand Up @@ -63,7 +62,6 @@ import {
getFileStats,
checkAndMakeNewDirectoryIfNonexistent
} from "../lib/files.js"
import { Readable } from "stream"

/**
* Handle whatever is needed to obtain the input data for a circuit that the coordinator would like to add to the ceremony.
Expand Down

0 comments on commit 72b6713

Please sign in to comment.