Skip to content

Commit

Permalink
Exit with non-zero code on verification fail
Browse files Browse the repository at this point in the history
  • Loading branch information
x-mass authored and nkaskov committed Dec 18, 2023
1 parent 610c643 commit 5bb7c4b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/reusable-verify-proofs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ on:
required: true
refs:
type: string
description: "Lines with repo names and refs (e.g. `org/repo: ref`)"
description: "Lines with repo names and refs (e.g. `org/repo: ref`). Used for SyncWith handling"
required: false

jobs:
Expand All @@ -33,7 +33,7 @@ jobs:
if: inputs.refs != ''
uses: NilFoundation/ci-cd/actions/recursive-checkout@v1.1.1
with:
paths: ${{ github.workspace }}/**
paths: ${{ github.workspace }} # There are no submodules, the only thing we could want to checkout is the current repo
refs: ${{ inputs.refs }}

- name: Setup Node.js environment
Expand All @@ -55,7 +55,13 @@ jobs:
- name: Verification of zkllvm proofs
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
35 changes: 20 additions & 15 deletions tasks/modular-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ function get_subfolders(dir) {
for (const file of files) {
if (file.isDirectory()) {
result.push(file.name);
}
}
}
return result;
}

function loadProof(proof_path){
return fs.readFileSync(path.resolve(__dirname, proof_path), 'utf8');
}


function getFileContents(filePath) {
return fs.readFileSync(filePath, 'utf8');
Expand Down Expand Up @@ -182,7 +182,7 @@ function loadPublicInput(public_input_path){
}
}
return result;
} else
} else
return [];
}

Expand All @@ -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")
Expand 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);
});

0 comments on commit 5bb7c4b

Please sign in to comment.