From 12938869312cc7cb111a36e4de5d4a298325292c Mon Sep 17 00:00:00 2001 From: x-mass <36629999+x-mass@users.noreply.github.com> Date: Thu, 14 Dec 2023 08:22:12 +0000 Subject: [PATCH] Exit with non-zero code on verification fail --- .github/workflows/reusable-verify-proofs.yml | 13 ++++++-- tasks/modular-test.ts | 35 +++++++++++--------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/.github/workflows/reusable-verify-proofs.yml b/.github/workflows/reusable-verify-proofs.yml index edaf598..a67b83e 100644 --- a/.github/workflows/reusable-verify-proofs.yml +++ b/.github/workflows/reusable-verify-proofs.yml @@ -54,8 +54,15 @@ jobs: npx hardhat deploy - name: Verification of zkllvm proofs + continue-on-error: true # next steps will be executed, workflow will still be marked as failed run: | - echo "${{ inputs.test-names }}" | awk '{$1=$1};1' | sed '/^$/d' | while read test_name + failure_met=0 + while read test_name do - npx hardhat verify-circuit-proof --test "$test_name" - done + npx hardhat verify-circuit-proof --test "$test_name" || failure_met=1 + done < <(echo "${{ inputs.test-names }}" | awk '{$1=$1};1' | sed '/^$/d') + + if [ $failure_met -eq 1 ]; then + echo "One or more verifications failed." + exit 1 + fi diff --git a/tasks/modular-test.ts b/tasks/modular-test.ts index 7e6896e..3c0cc06 100644 --- a/tasks/modular-test.ts +++ b/tasks/modular-test.ts @@ -10,7 +10,7 @@ function get_subfolders(dir) { for (const file of files) { if (file.isDirectory()) { result.push(file.name); - } + } } return result; } @@ -18,7 +18,7 @@ function get_subfolders(dir) { function loadProof(proof_path){ return fs.readFileSync(path.resolve(__dirname, proof_path), 'utf8'); } - + function getFileContents(filePath) { return fs.readFileSync(filePath, 'utf8'); @@ -182,7 +182,7 @@ function loadPublicInput(public_input_path){ } } return result; - } else + } else return []; } @@ -209,25 +209,30 @@ const verify_circuit_proof = async (modular_path: string, circuit: string) => { let receipt = await (await verifier_contract.verify(proof, public_input, {gasLimit: 30_500_000})).wait(); console.log("⛽Gas used: ", receipt.gasUsed.toNumber()); console.log("Events received:"); + const get_verification_event_result = (event): boolean | null => { + if (event.event == 'VerificationResult') { + return BigInt(event.data) != 0n; + } + return null; + }; const event_to_string = (event) => { - switch(event.event) { - case 'VerificationResult': { - if (BigInt(event.data) != 0n) { - return '✅ProofVerified'; - } else { - return '🛑ProofVerificationFailed'; - } - } - break; - default: - return '🤔'+event.event; + const verification_result = get_verification_event_result(event); + if (verification_result !== null) { + return verification_result ? '✅ProofVerified' : '🛑ProofVerificationFailed'; } + return '🤔' + event.event; }; + let verification_result = null; for(const e of receipt.events) { + const result = get_verification_event_result(e); + if (result !== null) { + verification_result = result; + } console.log(event_to_string(e)); } console.log("===================================="); + return verification_result; } task("verify-circuit-proof-all") @@ -246,5 +251,5 @@ task("verify-circuit-proof") console.log("Run modular verifier for:",test.test); let modular_path = "../contracts/zkllvm/"; let circuit = test.test; - await verify_circuit_proof(modular_path, circuit); + process.exit((await verify_circuit_proof(modular_path, circuit)) ? 0 : 1); });