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 committed Dec 18, 2023
1 parent edececf commit 1293886
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
13 changes: 10 additions & 3 deletions .github/workflows/reusable-verify-proofs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 1293886

Please sign in to comment.