Skip to content

Commit 9aec4e7

Browse files
committed
fix(vms): fixed wrong path in blake3 bin command and various fixes on the verification CF
1 parent b5a17bd commit 9aec4e7

File tree

2 files changed

+42
-29
lines changed

2 files changed

+42
-29
lines changed

packages/actions/src/helpers/vm.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const vmContributionVerificationCommand = (
102102
`aws s3 cp s3://${bucketName}/${lastZkeyStoragePath} /var/tmp/lastZKey.zkey &>/dev/null`,
103103
`snarkjs zkvi /var/tmp/genesisZkey.zkey /var/tmp/pot.ptau /var/tmp/lastZKey.zkey > /var/tmp/verification_transcript.log`,
104104
`aws s3 cp /var/tmp/verification_transcript.log s3://${bucketName}/${verificationTranscriptStoragePathAndFilename} &>/dev/null`,
105-
`./var/tmp/blake3.bin /var/tmp/verification_transcript.log | awk '{print $1}'`,
105+
`/var/tmp/blake3.bin /var/tmp/verification_transcript.log | awk '{print $1}'`,
106106
`rm /var/tmp/lastZKey.zkey /var/tmp/verification_transcript.log &>/dev/null`
107107
]
108108

@@ -332,6 +332,7 @@ export const retrieveCommandOutput = async (ssm: SSMClient, instanceId: string,
332332
try {
333333
// Run the command.
334334
const response = await ssm.send(command)
335+
console.log("DEBUG", response)
335336

336337
if (response.$metadata.httpStatusCode !== 200)
337338
throw new Error(
@@ -363,12 +364,6 @@ export const retrieveCommandStatus = async (ssm: SSMClient, instanceId: string,
363364
try {
364365
// Run the command.
365366
const response = await ssm.send(command)
366-
367-
if (response.$metadata.httpStatusCode !== 200)
368-
throw new Error(
369-
`Something went wrong when trying to retrieve the command ${commandId} status on the EC2 instance (${instanceId}). More details ${response}`
370-
)
371-
372367
return response.Status!
373368
} catch (error: any) {
374369
throw new Error(

packages/backend/src/functions/circuit.ts

+40-22
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ import {
5454
getDocumentById,
5555
getFinalContribution,
5656
sleep,
57-
uploadFileToBucket
57+
uploadFileToBucket,
58+
uploadFileToBucketNoFile
5859
} from "../lib/utils"
5960

6061
dotenv.config()
@@ -485,14 +486,20 @@ export const verifycontribution = functionsV2.https.onCall(
485486

486487
// @todo check sleep
487488
await sleep(1000)
488-
489+
console.log("COMMAND SENT DEBUG")
490+
let success: boolean = false
489491
// Wait until the command completes with a success status.
490492
const interval = setInterval(async () => {
493+
printLog("I started the intrarval function", LogLevel.DEBUG)
491494
try {
492495
const cmdStatus = await retrieveCommandStatus(ssm, commandId, vmInstanceId)
493496
printLog("CMD STATUS" + cmdStatus, LogLevel.DEBUG)
494497
// TODO: make an enum.
495-
if (cmdStatus === "Success") clearInterval(interval)
498+
if (cmdStatus === "Success") {
499+
printLog("DEBUG SUCCESS command", LogLevel.DEBUG)
500+
success = true
501+
clearInterval(interval)
502+
}
496503
else if (cmdStatus === "Failed" || cmdStatus === "AccessDenied")
497504
// Refactoring error.
498505
logAndThrowError(makeError("aborted", `Invalid command execution ${cmdStatus}`))
@@ -502,13 +509,26 @@ export const verifycontribution = functionsV2.https.onCall(
502509
}
503510
}, 60000)
504511

505-
// TODO To be deleted
506-
// // Retrieve the command output.
507-
// const commandOutput = await retrieveCommandOutput(ssm, commandId, vmInstanceId)
508-
509-
// // Check contribution validity.
510-
// if (commandOutput.includes("ZKey Ok!")) isContributionValid = true
511-
// else isContributionValid = false
512+
printLog("EXITED INTERVAL", LogLevel.DEBUG)
513+
printLog("Success " + success, LogLevel.DEBUG)
514+
// if the command was successful we need to check whether the zKey is valid or not
515+
if (success) {
516+
// download verification transcript which would have been uploaded to S3 by the VM
517+
verificationTranscriptTemporaryLocalPath = createTemporaryLocalPath(verificationTranscriptCompleteFilename)
518+
printLog("DOWNLOADING ARTIFACT", LogLevel.DEBUG)
519+
await downloadArtifactFromS3Bucket(bucketName, verificationTranscriptStoragePathAndFilename, verificationTranscriptCompleteFilename)
520+
// read the transcript and check if it contains the string "ZKey Ok!"
521+
const content = fs.readFileSync(verificationTranscriptTemporaryLocalPath, "utf-8")
522+
if (content.includes("ZKey Ok!")) isContributionValid = true
523+
printLog("is valid " + isContributionValid, LogLevel.DEBUG)
524+
525+
// if the contribution is valid then format the transcript and upload save it again to disk
526+
if (isContributionValid) {
527+
const updated = content.replace(/\x1b\[[0-9;]*m/g, "");
528+
fs.writeFileSync(verificationTranscriptTemporaryLocalPath, updated)
529+
}
530+
531+
}
512532

513533
// Stop the VM.
514534
// await stopEC2Instance(ec2, vmInstanceId)
@@ -591,24 +611,22 @@ export const verifycontribution = functionsV2.https.onCall(
591611
true
592612
)
593613
} else {
594-
// Download verification transcript file from S3.
595-
verificationTranscriptTemporaryLocalPath = createTemporaryLocalPath(
596-
verificationTranscriptCompleteFilename
597-
)
598-
await downloadArtifactFromS3Bucket(
599-
bucketName,
600-
verificationTranscriptStoragePathAndFilename,
601-
verificationTranscriptTemporaryLocalPath
602-
)
603-
604614
// Retrieve the contribution hash from the command output.
605615
lastZkeyBlake2bHash = await retrieveCommandOutput(await createSSMClient(), commandId, vmInstanceId)
616+
// re upload the formatted verification transcript
617+
await uploadFileToBucket(
618+
bucketName,
619+
verificationTranscriptStoragePathAndFilename,
620+
verificationTranscriptTemporaryLocalPath,
621+
true
622+
)
623+
fs.unlinkSync(verificationTranscriptTemporaryLocalPath)
606624
}
607625

608626
// Compute verification transcript hash.
609627
transcriptBlake2bHash = await blake512FromPath(verificationTranscriptTemporaryLocalPath)
610628

611-
// Free resources by unlinking transcript temporary folder.
629+
// Free resources by unlinking transcript temporary file.
612630
fs.unlinkSync(verificationTranscriptTemporaryLocalPath)
613631

614632
// Filter participant contributions to find the data related to the one verified.
@@ -636,7 +654,7 @@ export const verifycontribution = functionsV2.https.onCall(
636654
transcriptStoragePath: verificationTranscriptStoragePathAndFilename,
637655
lastZkeyStoragePath,
638656
transcriptBlake2bHash,
639-
lastZkeyBlake2bHash // @todo we need the hash of the last zkey
657+
lastZkeyBlake2bHash
640658
},
641659
verificationSoftware: {
642660
name: String(process.env.CUSTOM_CONTRIBUTION_VERIFICATION_SOFTWARE_NAME),

0 commit comments

Comments
 (0)