diff --git a/zokrates_circom/src/r1cs.rs b/zokrates_circom/src/r1cs.rs index 0a96f8f1..8bdab0ac 100644 --- a/zokrates_circom/src/r1cs.rs +++ b/zokrates_circom/src/r1cs.rs @@ -1,5 +1,5 @@ use byteorder::{LittleEndian, WriteBytesExt}; -use std::collections::HashMap; +use std::collections::{BTreeSet, HashMap}; use std::io::Result; use std::{io::Write, ops::Add}; use zokrates_ast::flat::Variable; @@ -65,6 +65,9 @@ pub fn r1cs_program(prog: Prog) -> (Vec, usize, Vec Some((quad, lin)), @@ -72,16 +75,21 @@ pub fn r1cs_program(prog: Prog) -> (Vec, usize, Vec None, }) { for (k, _) in &quad.left.0 { - provide_variable_idx(&mut variables, k); + ordered_variables_set.insert(k); } for (k, _) in &quad.right.0 { - provide_variable_idx(&mut variables, k); + ordered_variables_set.insert(k); } for (k, _) in &lin.0 { - provide_variable_idx(&mut variables, k); + ordered_variables_set.insert(k); } } + // create indices for the variables *in increasing order* + for variable in ordered_variables_set { + provide_variable_idx(&mut variables, variable); + } + let mut constraints = vec![]; // second pass to convert program to raw sparse vectors diff --git a/zokrates_js/package.json b/zokrates_js/package.json index 5b3563ff..1edff92b 100644 --- a/zokrates_js/package.json +++ b/zokrates_js/package.json @@ -46,7 +46,7 @@ "dree": "^2.6.1", "mocha": "^9.2.0", "rimraf": "^3.0.2", - "snarkjs": "^0.4.19", + "snarkjs": "^0.4.24", "wasm-pack": "^0.10.2" } } \ No newline at end of file diff --git a/zokrates_js/tests/tests.js b/zokrates_js/tests/tests.js index 38ae18b8..9ed6cf6e 100644 --- a/zokrates_js/tests/tests.js +++ b/zokrates_js/tests/tests.js @@ -18,12 +18,15 @@ describe("tests", () => { .mkdtemp(path.join(os.tmpdir(), path.sep)) .then((folder) => { tmpFolder = folder; + return; }); }); }); after(() => { - if (globalThis.curve_bn128) globalThis.curve_bn128.terminate(); + if (globalThis.curve_bn128) { + return globalThis.curve_bn128.terminate() + }; }); describe("metadata", () => { @@ -165,7 +168,11 @@ describe("tests", () => { it("compile", () => { assert.doesNotThrow(() => { const code = - "def main(private field a, field b) -> bool { return a * a == b; }"; + `def main(private field a, field b) { + bool check = if (a == 0){ true} else {a * a == b}; + assert(check); + return true; + }`; artifacts = provider.compile(code, { snarkjs: true }); }); }); @@ -199,7 +206,6 @@ describe("tests", () => { .then(() => { return snarkjs.zKey .newZKey(r1csPath, "./tests/powersOfTau5_0000.ptau", zkeyPath) - .then(() => {}); }); }); } @@ -234,6 +240,11 @@ describe("tests", () => { .writeFile(witnessPath, computationResult.snarkjs.witness) .then(() => { return snarkjs.groth16.prove(zkeyPath, witnessPath); + }).then(r => { + return snarkjs.zKey.exportVerificationKey(zkeyPath).then((vk) => { + assert(snarkjs.groth16.verify(vk, r.publicSignals, r.proof) === true); + return + }) }); }); }