Skip to content

Commit

Permalink
Merge branch 'dev' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
glamperd committed Jul 12, 2024
2 parents b23818d + 5fad82d commit 824ac5f
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/actions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@p0tion/actions",
"version": "1.2.4",
"version": "1.2.5",
"description": "A set of actions and helpers for CLI commands",
"repository": "[email protected]:privacy-scaling-explorations/p0tion.git",
"homepage": "https://github.com/privacy-scaling-explorations/p0tion",
Expand Down
2 changes: 2 additions & 0 deletions packages/actions/src/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const verifierSmartContractAcronym = "verifier"
export const ec2InstanceTag = "p0tionec2instance"
// The name of the VM startup script file.
export const vmBootstrapScriptFilename = "bootstrap.sh"
// Match hash output by snarkjs in transcript log
export const contribHashRegex = new RegExp("Contribution.+Hash.+\n\t\t.+\n\t\t.+\n.+\n\t\t.+\r?\n")

/**
* Define the supported VM configuration types.
Expand Down
3 changes: 2 additions & 1 deletion packages/actions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export {
ec2InstanceTag,
vmConfigurationTypes,
vmBootstrapScriptFilename,
powersOfTauFiles
powersOfTauFiles,
contribHashRegex
} from "./helpers/constants"
export {
extractPrefix,
Expand Down
5 changes: 2 additions & 3 deletions packages/actions/test/unit/ec2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
checkIfRunning,
checkParticipantForCeremony,
commonTerms,
contribHashRegex,
createCustomLoggerForFile,
createEC2Client,
createEC2Instance,
Expand Down Expand Up @@ -453,9 +454,7 @@ describe("VMs", () => {

// read the contribution hash
const transcriptContents = fs.readFileSync(transcriptLocalFilePath, "utf-8").toString()
const matchContributionHash = transcriptContents.match(
/Contribution.+Hash.+\n\t\t.+\n\t\t.+\n.+\n\t\t.+\n/
)
const matchContributionHash = transcriptContents.match(contribHashRegex)
const contributionHash = matchContributionHash?.at(0)?.replace("\n\t\t", "")!

await progressToNextContributionStep(userFunctions, secondCeremonyId)
Expand Down
35 changes: 34 additions & 1 deletion packages/actions/test/unit/helpers.utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
extractPrefix,
formatZkeyIndex,
getR1CSInfo,
computeSmallestPowersOfTauForCircuit
computeSmallestPowersOfTauForCircuit,
contribHashRegex
} from "../../src/index"
import { envType } from "../utils/index"
import { TestingEnvironment } from "../../src/types/enums"
Expand Down Expand Up @@ -71,4 +72,36 @@ describe("Utils", () => {
)
})
})
describe("", () => {
const hashStr = "Contribution Hash: \n" +
"\t\t847482b6 5d88b59f 0e860287 8d527446 \n" +
"\t\tf2fe25f6 ba2eb6d8 7478803e b723dd39 \n" +
"\t\tdf0fa90a 4d8b0ee8 07d70070 03308fb4 \n" +
"\t\t17c8ff20 0123b155 9aa15a5c 14b5bf26"
const hash = "Contribution Hash: 847482b6 5d88b59f 0e860287 8d527446 " +
"f2fe25f6 ba2eb6d8 7478803e b723dd39 " +
"df0fa90a 4d8b0ee8 07d70070 03308fb4 " +
"17c8ff20 0123b155 9aa15a5c 14b5bf26"

it("should match unix contribution hash", () => {
const hashStrUnix = hashStr + '\n'
//const r = new RegExp("Contribution Hash: \n\t\t.+\n.+\n.+\n.+\n")
const match = hashStrUnix.match(contribHashRegex)
expect(match).not.to.be.null

expect(match?.length).to.be.greaterThan(0)

const contributionHash = match?.at(0)?.replaceAll("\n\t\t", "")!
expect(contributionHash).to.equal(hash + "\n")
})
it("should match Windows contribution hash", () => {
const hashStrWin = hashStr + "\r\n"
const match = hashStrWin.match(contribHashRegex)
expect(match).not.to.be.null
expect(match?.length).to.be.greaterThan(0)

const contributionHash = match?.at(0)?.replaceAll("\n\t\t", "")!
expect(contributionHash).to.equal(hash + "\r\n")
})
})
})
6 changes: 5 additions & 1 deletion packages/backend/firebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
},
"functions": {
"predeploy": "yarn --cwd \"$RESOURCE_DIR\" build",
"source": "."
"source": ".",
"ignore": [
"node_modules",
"aws"
]
},
"emulators": {
"singleProjectMode": true,
Expand Down
4 changes: 2 additions & 2 deletions packages/phase2cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@p0tion/phase2cli",
"type": "module",
"version": "1.2.4",
"version": "1.2.5",
"description": "All-in-one interactive command-line for interfacing with zkSNARK Phase 2 Trusted Setup ceremonies",
"repository": "[email protected]:privacy-scaling-explorations/p0tion.git",
"homepage": "https://github.com/privacy-scaling-explorations/p0tion",
Expand Down Expand Up @@ -73,7 +73,7 @@
"@octokit/auth-oauth-app": "^5.0.5",
"@octokit/auth-oauth-device": "^4.0.4",
"@octokit/request": "^6.2.3",
"@p0tion/actions": "^1.2.0",
"@p0tion/actions": "^1.2.5",
"@semaphore-protocol/identity": "^3.15.1",
"blakejs": "^1.2.1",
"boxen": "^7.1.0",
Expand Down
7 changes: 4 additions & 3 deletions packages/phase2cli/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
ParticipantContributionStep,
permanentlyStoreCurrentContributionTimeAndHash,
progressToNextContributionStep,
verifyContribution
verifyContribution,
contribHashRegex
} from "@p0tion/actions"
import { Presets, SingleBar } from "cli-progress"
import dotenv from "dotenv"
Expand Down Expand Up @@ -159,7 +160,7 @@ export const getUserHandleFromProviderUserId = (providerUserId: string): string
return providerUserId
}

return providerUserId.split("-")[0]
return providerUserId.substring(0, providerUserId.lastIndexOf("-"))
}

/**
Expand Down Expand Up @@ -664,7 +665,7 @@ export const handleStartOrResumeContribution = async (

// Read local transcript file info to get the contribution hash.
const transcriptContents = readFile(transcriptLocalFilePath)
const matchContributionHash = transcriptContents.match(/Contribution.+Hash.+\n\t\t.+\n\t\t.+\n.+\n\t\t.+\n/)
const matchContributionHash = transcriptContents.match(contribHashRegex)

if (!matchContributionHash)
showError(COMMAND_ERRORS.COMMAND_CONTRIBUTE_FINALIZE_NO_TRANSCRIPT_CONTRIBUTION_HASH_MATCH, true)
Expand Down

0 comments on commit 824ac5f

Please sign in to comment.