From 4fd6ccee715cc0d8a59f19f679530de4567290a7 Mon Sep 17 00:00:00 2001 From: Geoff Lamperd Date: Mon, 8 Jul 2024 15:06:47 +1000 Subject: [PATCH 1/9] fix: hash regex include \r --- packages/actions/src/helpers/constants.ts | 2 ++ packages/actions/src/index.ts | 3 ++- packages/actions/test/unit/ec2.test.ts | 5 ++--- packages/phase2cli/src/lib/utils.ts | 5 +++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/actions/src/helpers/constants.ts b/packages/actions/src/helpers/constants.ts index fe5e0879..134a87a1 100644 --- a/packages/actions/src/helpers/constants.ts +++ b/packages/actions/src/helpers/constants.ts @@ -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. diff --git a/packages/actions/src/index.ts b/packages/actions/src/index.ts index 608956ac..43d63310 100644 --- a/packages/actions/src/index.ts +++ b/packages/actions/src/index.ts @@ -52,7 +52,8 @@ export { ec2InstanceTag, vmConfigurationTypes, vmBootstrapScriptFilename, - powersOfTauFiles + powersOfTauFiles, + contribHashRegex } from "./helpers/constants" export { extractPrefix, diff --git a/packages/actions/test/unit/ec2.test.ts b/packages/actions/test/unit/ec2.test.ts index b443afe1..43928855 100644 --- a/packages/actions/test/unit/ec2.test.ts +++ b/packages/actions/test/unit/ec2.test.ts @@ -20,6 +20,7 @@ import { checkIfRunning, checkParticipantForCeremony, commonTerms, + contribHashRegex, createCustomLoggerForFile, createEC2Client, createEC2Instance, @@ -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) diff --git a/packages/phase2cli/src/lib/utils.ts b/packages/phase2cli/src/lib/utils.ts index eb83d6e5..84476d1d 100644 --- a/packages/phase2cli/src/lib/utils.ts +++ b/packages/phase2cli/src/lib/utils.ts @@ -18,7 +18,8 @@ import { ParticipantContributionStep, permanentlyStoreCurrentContributionTimeAndHash, progressToNextContributionStep, - verifyContribution + verifyContribution, + contribHashRegex } from "@p0tion/actions" import { Presets, SingleBar } from "cli-progress" import dotenv from "dotenv" @@ -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) From dc0f0f62775d671ccf4103b49c7c86e0de6fe3f6 Mon Sep 17 00:00:00 2001 From: Geoff Lamperd Date: Mon, 8 Jul 2024 17:42:00 +1000 Subject: [PATCH 2/9] fix: adds unit test for regex pattern --- .../actions/test/unit/helpers.utils.test.ts | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/actions/test/unit/helpers.utils.test.ts b/packages/actions/test/unit/helpers.utils.test.ts index 15160a5d..985a0274 100644 --- a/packages/actions/test/unit/helpers.utils.test.ts +++ b/packages/actions/test/unit/helpers.utils.test.ts @@ -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" @@ -71,4 +72,27 @@ 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 = "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") + expect(hashStrUnix.match(contribHashRegex)).not.to.be.null + + + }) + it("should match Windows contribution hash", () => { + const hashStrWin = hashStr + "\r\n" + //const r = new RegExp("Contribution Hash: \n\t\t.+\n.+\n.+\n.+\n") + expect(hashStrWin.match(contribHashRegex)).not.to.be.null + }) + }) }) From 309266765a261e832b39644e045a9206add3f6f2 Mon Sep 17 00:00:00 2001 From: Geoff Lamperd Date: Fri, 12 Jul 2024 13:59:03 +1000 Subject: [PATCH 3/9] adds unit test for regex --- .../actions/test/unit/helpers.utils.test.ts | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/actions/test/unit/helpers.utils.test.ts b/packages/actions/test/unit/helpers.utils.test.ts index 985a0274..1c30b4c1 100644 --- a/packages/actions/test/unit/helpers.utils.test.ts +++ b/packages/actions/test/unit/helpers.utils.test.ts @@ -74,25 +74,34 @@ 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\t847482b6 5d88b59f 0e860287 8d527446 \n" + + "\t\tf2fe25f6 ba2eb6d8 7478803e b723dd39 \n" + + "\t\tdf0fa90a 4d8b0ee8 07d70070 03308fb4 \n" + "\t\t17c8ff20 0123b155 9aa15a5c 14b5bf26" - const hash = "847482b6 5d88b59f 0e860287 8d527446 " + + 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") - expect(hashStrUnix.match(contribHashRegex)).not.to.be.null - + 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 r = new RegExp("Contribution Hash: \n\t\t.+\n.+\n.+\n.+\n") - expect(hashStrWin.match(contribHashRegex)).not.to.be.null + 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") }) }) }) From 3fb52f843fa94e6daeb70c93aa1d8b8d7e77f055 Mon Sep 17 00:00:00 2001 From: Geoff Lamperd Date: Fri, 12 Jul 2024 14:15:41 +1000 Subject: [PATCH 4/9] updates actions version --- packages/actions/package.json | 2 +- packages/phase2cli/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/actions/package.json b/packages/actions/package.json index b8764cf7..1b1f3f88 100644 --- a/packages/actions/package.json +++ b/packages/actions/package.json @@ -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": "git@github.com:privacy-scaling-explorations/p0tion.git", "homepage": "https://github.com/privacy-scaling-explorations/p0tion", diff --git a/packages/phase2cli/package.json b/packages/phase2cli/package.json index e9e09b71..75a2702e 100644 --- a/packages/phase2cli/package.json +++ b/packages/phase2cli/package.json @@ -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", From 46e4606c3408951b23ffec683e72131b43ec754e Mon Sep 17 00:00:00 2001 From: Geoff Lamperd Date: Fri, 12 Jul 2024 14:43:12 +1000 Subject: [PATCH 5/9] fix: handle username with hyphens --- packages/phase2cli/src/lib/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/phase2cli/src/lib/utils.ts b/packages/phase2cli/src/lib/utils.ts index 84476d1d..83d3763c 100644 --- a/packages/phase2cli/src/lib/utils.ts +++ b/packages/phase2cli/src/lib/utils.ts @@ -160,7 +160,7 @@ export const getUserHandleFromProviderUserId = (providerUserId: string): string return providerUserId } - return providerUserId.split("-")[0] + return providerUserId.substring(0, providerUserId.lastIndexOf("-")) } /** From 5fad82d7a096e5f8623c8e9e80f3f5b46e7c226c Mon Sep 17 00:00:00 2001 From: Geoff Lamperd Date: Fri, 12 Jul 2024 15:19:25 +1000 Subject: [PATCH 6/9] bump version --- packages/phase2cli/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/phase2cli/package.json b/packages/phase2cli/package.json index 75a2702e..4a102fe2 100644 --- a/packages/phase2cli/package.json +++ b/packages/phase2cli/package.json @@ -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": "git@github.com:privacy-scaling-explorations/p0tion.git", "homepage": "https://github.com/privacy-scaling-explorations/p0tion", From bbc217a98cbab5ea443d7eda8070800cfb458632 Mon Sep 17 00:00:00 2001 From: Geoff Lamperd Date: Mon, 15 Jul 2024 11:30:44 +1000 Subject: [PATCH 7/9] chore: update lock file --- yarn.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yarn.lock b/yarn.lock index aaaa10ab..572746b6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4718,7 +4718,7 @@ __metadata: languageName: node linkType: hard -"@p0tion/actions@^1.2.0, @p0tion/actions@workspace:packages/actions": +"@p0tion/actions@^1.2.0, @p0tion/actions@^1.2.5, @p0tion/actions@workspace:packages/actions": version: 0.0.0-use.local resolution: "@p0tion/actions@workspace:packages/actions" dependencies: @@ -4804,7 +4804,7 @@ __metadata: "@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 "@types/clear": ^0.1.2 "@types/cli-progress": ^3.11.0 From c233069a0f94029e4797aad927f1c5abfc6d851a Mon Sep 17 00:00:00 2001 From: Geoff Lamperd Date: Mon, 15 Jul 2024 11:40:45 +1000 Subject: [PATCH 8/9] chore: bump version --- lerna.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lerna.json b/lerna.json index e02f2401..5e7116f4 100644 --- a/lerna.json +++ b/lerna.json @@ -3,7 +3,7 @@ "packages/*" ], "npmClient": "yarn", - "version": "1.2.4", + "version": "1.2.5", "changelogPreset": { "name": "conventionalcommits", "issuePrefixes": [ From a7b749e0210094440134c9fea9a752669fa2a4c1 Mon Sep 17 00:00:00 2001 From: Geoff Lamperd Date: Mon, 15 Jul 2024 13:39:26 +1000 Subject: [PATCH 9/9] update backend version --- packages/backend/package.json | 2 +- yarn.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/backend/package.json b/packages/backend/package.json index 99ac2731..4e0dbaaf 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -68,7 +68,7 @@ "@aws-sdk/middleware-endpoint": "^3.329.0", "@aws-sdk/s3-request-presigner": "^3.329.0", "@bandada/api-sdk": "^1.0.0-beta.1", - "@p0tion/actions": "^1.2.0", + "@p0tion/actions": "^1.2.5", "blakejs": "^1.2.1", "dotenv": "^16.0.3", "ethers": "5.7.2", diff --git a/yarn.lock b/yarn.lock index 572746b6..e77e6c3d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4718,7 +4718,7 @@ __metadata: languageName: node linkType: hard -"@p0tion/actions@^1.2.0, @p0tion/actions@^1.2.5, @p0tion/actions@workspace:packages/actions": +"@p0tion/actions@^1.2.5, @p0tion/actions@workspace:packages/actions": version: 0.0.0-use.local resolution: "@p0tion/actions@workspace:packages/actions" dependencies: @@ -4769,7 +4769,7 @@ __metadata: "@aws-sdk/s3-request-presigner": ^3.329.0 "@bandada/api-sdk": ^1.0.0-beta.1 "@firebase/rules-unit-testing": ^2.0.7 - "@p0tion/actions": ^1.2.0 + "@p0tion/actions": ^1.2.5 "@types/rollup-plugin-auto-external": ^2.0.2 "@types/uuid": ^9.0.1 blakejs: ^1.2.1