@@ -54,7 +54,8 @@ import {
54
54
getDocumentById ,
55
55
getFinalContribution ,
56
56
sleep ,
57
- uploadFileToBucket
57
+ uploadFileToBucket ,
58
+ uploadFileToBucketNoFile
58
59
} from "../lib/utils"
59
60
60
61
dotenv . config ( )
@@ -485,14 +486,20 @@ export const verifycontribution = functionsV2.https.onCall(
485
486
486
487
// @todo check sleep
487
488
await sleep ( 1000 )
488
-
489
+ console . log ( "COMMAND SENT DEBUG" )
490
+ let success : boolean = false
489
491
// Wait until the command completes with a success status.
490
492
const interval = setInterval ( async ( ) => {
493
+ printLog ( "I started the intrarval function" , LogLevel . DEBUG )
491
494
try {
492
495
const cmdStatus = await retrieveCommandStatus ( ssm , commandId , vmInstanceId )
493
496
printLog ( "CMD STATUS" + cmdStatus , LogLevel . DEBUG )
494
497
// 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
+ }
496
503
else if ( cmdStatus === "Failed" || cmdStatus === "AccessDenied" )
497
504
// Refactoring error.
498
505
logAndThrowError ( makeError ( "aborted" , `Invalid command execution ${ cmdStatus } ` ) )
@@ -502,13 +509,26 @@ export const verifycontribution = functionsV2.https.onCall(
502
509
}
503
510
} , 60000 )
504
511
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
+ }
512
532
513
533
// Stop the VM.
514
534
// await stopEC2Instance(ec2, vmInstanceId)
@@ -591,24 +611,22 @@ export const verifycontribution = functionsV2.https.onCall(
591
611
true
592
612
)
593
613
} 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
-
604
614
// Retrieve the contribution hash from the command output.
605
615
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 )
606
624
}
607
625
608
626
// Compute verification transcript hash.
609
627
transcriptBlake2bHash = await blake512FromPath ( verificationTranscriptTemporaryLocalPath )
610
628
611
- // Free resources by unlinking transcript temporary folder .
629
+ // Free resources by unlinking transcript temporary file .
612
630
fs . unlinkSync ( verificationTranscriptTemporaryLocalPath )
613
631
614
632
// Filter participant contributions to find the data related to the one verified.
@@ -636,7 +654,7 @@ export const verifycontribution = functionsV2.https.onCall(
636
654
transcriptStoragePath : verificationTranscriptStoragePathAndFilename ,
637
655
lastZkeyStoragePath,
638
656
transcriptBlake2bHash,
639
- lastZkeyBlake2bHash // @todo we need the hash of the last zkey
657
+ lastZkeyBlake2bHash
640
658
} ,
641
659
verificationSoftware : {
642
660
name : String ( process . env . CUSTOM_CONTRIBUTION_VERIFICATION_SOFTWARE_NAME ) ,
0 commit comments