Skip to content

Commit

Permalink
fix(finalization): fix various bugs and add non interactive auth
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlc03 committed Aug 23, 2023
1 parent 8b5a17f commit a4931f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/phase2cli/src/commands/finalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ import {
sleep,
terminate
} from "../lib/utils.js"
import { bootstrapCommandExecutionAndServices, checkAuth } from "../lib/services.js"
import { authWithToken, bootstrapCommandExecutionAndServices, checkAuth } from "../lib/services.js"
import {
getAttestationLocalFilePath,
getFinalAttestationLocalFilePath,
getFinalZkeyLocalFilePath,
getVerificationKeyLocalFilePath,
getVerifierContractLocalFilePath,
Expand Down Expand Up @@ -112,7 +112,7 @@ export const handleVerifierSmartContract = async (
? `${dirname(
fileURLToPath(import.meta.url)
)}/../../../../node_modules/snarkjs/templates/verifier_groth16.sol.ejs`
: `${dirname(fileURLToPath(import.meta.url))}/../../../node_modules/snarkjs/templates/verifier_groth16.sol.ejs`
: `${dirname(fileURLToPath(import.meta.url))}/../node_modules/snarkjs/templates/verifier_groth16.sol.ejs`

// Export the Solidity verifier smart contract.
const verifierCode = await exportVerifierContract(finalZkeyLocalFilePath, verifierPath)
Expand Down Expand Up @@ -241,11 +241,12 @@ export const handleCircuitFinalization = async (
* @dev For proper execution, the command requires the coordinator to be authenticated with a GitHub account (run auth command first) in order to
* handle sybil-resistance and connect to GitHub APIs to publish the gist containing the final public attestation.
*/
const finalize = async () => {
const finalize = async (opt: any) => {
const { firebaseApp, firebaseFunctions, firestoreDatabase } = await bootstrapCommandExecutionAndServices()

// Check for authentication.
const { user, providerUserId, token: coordinatorAccessToken } = await checkAuth(firebaseApp)
const auth = opt.auth
const { user, providerUserId, token: coordinatorAccessToken } = auth ? await authWithToken(firebaseApp, auth) : await checkAuth(firebaseApp)

// Preserve command execution only for coordinators.
if (!(await isCoordinator(user))) showError(COMMAND_ERRORS.COMMAND_NOT_COORDINATOR, true)
Expand Down Expand Up @@ -344,7 +345,7 @@ const finalize = async () => {

// Write public attestation locally.
writeFile(
getAttestationLocalFilePath(
getFinalAttestationLocalFilePath(
`${prefix}_${finalContributionIndex}_${commonTerms.foldersAndPathsTerms.attestation}.log`
),
Buffer.from(publicAttestation)
Expand Down
1 change: 1 addition & 0 deletions packages/phase2cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ ceremony
.description(
"finalize a Phase2 Trusted Setup ceremony by applying a beacon, exporting verification key and verifier contract"
)
.option("-a, --auth <string>", "the Github OAuth 2.0 token", "")
.action(finalize)

program.parseAsync(process.argv)

0 comments on commit a4931f4

Please sign in to comment.