Skip to content

Commit

Permalink
Merge branch 'dev' into better-error-in-func
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoSerranoP authored Jul 24, 2024
2 parents 6f686a5 + a7b749e commit 6178e88
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packages/*"
],
"npmClient": "yarn",
"version": "1.2.4",
"version": "1.2.5",
"changelogPreset": {
"name": "conventionalcommits",
"issuePrefixes": [
Expand Down
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": "git@github.com: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")
})
})
})
2 changes: 1 addition & 1 deletion packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
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": "git@github.com: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.4",
"@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
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4718,7 +4718,7 @@ __metadata:
languageName: node
linkType: hard

"@p0tion/actions@^1.2.0, @p0tion/actions@^1.2.4, @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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.4
"@p0tion/actions": ^1.2.5
"@semaphore-protocol/identity": ^3.15.1
"@types/clear": ^0.1.2
"@types/cli-progress": ^3.11.0
Expand Down

0 comments on commit 6178e88

Please sign in to comment.