Skip to content

Commit

Permalink
chore: refactor Solidity Transcript and improve error handling in sol…
Browse files Browse the repository at this point in the history
…_honk flow (#11158)

A cleanup PR in preparation for the ZK contract
* create a RelationParameters struct so functions in `RelationsLib`
don't need to take the Transcript as function argument ( this will be
useful to reuse this library for both the zk and non-zk contract)
* make `loadProof` less manual and more robust by creating some utility
functions
* ensure the `sol_honk` flow actually displays contract compilation
errors and clear errors (if possible) when deploying to aid debugging
  • Loading branch information
maramihali authored Jan 13, 2025
1 parent d41e9ab commit 58fdf87
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 319 deletions.
22 changes: 19 additions & 3 deletions barretenberg/acir_tests/sol-test/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import solc from "solc";
const NUMBER_OF_FIELDS_IN_PLONK_PROOF = 93;
const NUMBER_OF_FIELDS_IN_HONK_PROOF = 443;

const WRONG_PUBLIC_INPUTS_LENGTH = "0xfa066593";
const SUMCHECK_FAILED = "0x9fc3a218";
const SHPLEMINI_FAILED = "0xa5d82e8a";

// We use the solcjs compiler version in this test, although it is slower than foundry, to run the test end to end
// it simplifies of parallelising the test suite

Expand Down Expand Up @@ -94,7 +98,7 @@ if (!testingHonk) {
}

var output = JSON.parse(solc.compile(JSON.stringify(compilationInput)));
if (output.errors.some((e) => e.type == "Error")) {
if (output.errors.some((e) => e.severity == "error")) {
throw new Error(JSON.stringify(output.errors, null, 2));
}
const contract = output.contracts["Test.sol"]["Test"];
Expand Down Expand Up @@ -236,8 +240,20 @@ try {
const result = await contract.test(proofStr, publicInputs);
if (!result) throw new Error("Test failed");
} catch (e) {
console.error(testName, " failed");
console.log(e);
console.error(testName, "failed");
if (testingHonk) {
var errorType = e.data;
switch (errorType) {
case WRONG_PUBLIC_INPUTS_LENGTH:
throw new Error("Number of inputs in the proof is wrong");
case SUMCHECK_FAILED:
throw new Error("Sumcheck round failed");
case SHPLEMINI_FAILED:
throw new Error("PCS round failed");
default:
throw e;
}
}
throw e;
} finally {
// Kill anvil at the end of running
Expand Down
Loading

0 comments on commit 58fdf87

Please sign in to comment.