From bd01a89971f5a3aeaf34e443555d2de70b1fa816 Mon Sep 17 00:00:00 2001 From: arnaucube Date: Thu, 4 Nov 2021 11:16:58 +0100 Subject: [PATCH] Fix c tester witness file read c tester (c/tester.js) was using a method to read the witness file called 'readBinaryFile' that was obtaining a wrong number of witness elements, and as consequence was returning a wrong array of witness. Changed that method to 'readBinWitnessFile', which makes use of wtnsUtils method from snarkjs to read the witness binary file, so now the c tester returns the correct witness. --- c/tester.js | 19 ++++++------------- package.json | 3 ++- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/c/tester.js b/c/tester.js index de68981..a9c4d53 100644 --- a/c/tester.js +++ b/c/tester.js @@ -11,6 +11,8 @@ const exec = util.promisify(require("child_process").exec); const loadR1cs = require("r1csfile").load; const ZqField = require("ffjavascript").ZqField; +const readWtns = require("snarkjs").wtns.exportJson; + module.exports = c_tester; async function c_tester(circomInput, _options) { @@ -81,7 +83,7 @@ class WasmTester { }); await exec("ls " + path.join(this.dir.path, this.baseName+"_cpp/")); await exec(runc + " " + inputFile + " " + wtnsFile); - return readBinaryFile(wtnsFile); + return await readBinWitnessFile(wtnsFile); } async loadSymbols() { @@ -208,18 +210,9 @@ async function compiler_above_version(v) { return check_versions ( compiler_version, vlist ); } -function readBinaryFile(fileName) { - const buff = fs.readFileSync(fileName); - const n32 = fromArray8ToUint(buff.slice(24,27)); - var pos = 28+n32; - const ws = fromArray8ToUint(buff.slice(pos,pos+3)); - pos += 16; - const w = []; - for (let i=0; i