From 80cce0ccbb4ec66e4cf82a678c1d59b61daa7e22 Mon Sep 17 00:00:00 2001 From: Jordi Baylina Date: Sat, 28 Mar 2020 21:26:43 +0100 Subject: [PATCH] deps --- package.json | 2 +- src/construction_phase.js | 3 +++ src/gencode.js | 17 +++++++++-------- src/lcalgebra.js | 18 +++++++++--------- src/utils.js | 2 +- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index 50a309b..b2fdb89 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "chai": "^4.2.0", "circom_runtime": "0.0.3", "ffiasm": "0.0.2", - "ffjavascript": "0.0.3", + "ffjavascript": "0.0.4", "ffwasm": "0.0.6", "fnv-plus": "^1.3.1", "r1csfile": "0.0.3", diff --git a/src/construction_phase.js b/src/construction_phase.js index 2736e86..88f7981 100644 --- a/src/construction_phase.js +++ b/src/construction_phase.js @@ -624,6 +624,9 @@ function execReturn(ctx, ast) { function execVariable(ctx, ast) { const v = ctx.refs[ast.refId]; + if (!v) { + return ctx.throwError(ast, "Variable not defined: "+ast.name); + } const sels = []; for (let i=0; i< ast.selectors.length; i++) { diff --git a/src/gencode.js b/src/gencode.js index c2e629e..b9be071 100644 --- a/src/gencode.js +++ b/src/gencode.js @@ -175,17 +175,17 @@ function gen(ctx, ast) { } else if (ast.op == ">>") { return genOp(ctx, ast, "shr", 2); } else if (ast.op == "<") { - return genOp(ctx, ast, "lt", 2); + return genOp(ctx, ast, "lt", 2, true); } else if (ast.op == ">") { - return genOp(ctx, ast, "gt", 2); + return genOp(ctx, ast, "gt", 2, true); } else if (ast.op == "<=") { - return genOp(ctx, ast, "leq", 2); + return genOp(ctx, ast, "leq", 2, true); } else if (ast.op == ">=") { - return genOp(ctx, ast, "geq", 2); + return genOp(ctx, ast, "geq", 2, true); } else if (ast.op == "==") { - return genOp(ctx, ast, "eq", 2); + return genOp(ctx, ast, "eq", 2, true); } else if (ast.op == "!=") { - return genOp(ctx, ast, "neq", 2); + return genOp(ctx, ast, "neq", 2, true); } else if (ast.op == "?") { return genTerCon(ctx, ast); } else { @@ -1121,7 +1121,7 @@ function genOpOp(ctx, ast, op, lr) { } } -function genOp(ctx, ast, op, nOps) { +function genOp(ctx, ast, op, nOps, adjustBool) { const vals = []; const valRefs = []; @@ -1159,7 +1159,8 @@ function genOp(ctx, ast, op, nOps) { for (let i=0; i { - self._genNQOp(op[0], op[1]); + self._genNQOp(op[0], op[1], op[2]); }); } - _genNQOp(op, nOps) { + _genNQOp(op, nOps, adjustBool) { const self=this; self[op] = function() { const operands = []; @@ -118,7 +118,7 @@ class LCAlgebra { } return { t: "N", - v: self.field[op](...operands) + v: adjustBool ? ( self.field[op](...operands) ? bigInt.one: bigInt.zero) : self.field[op](...operands) }; }; } diff --git a/src/utils.js b/src/utils.js index f8748da..85936cf 100644 --- a/src/utils.js +++ b/src/utils.js @@ -77,7 +77,7 @@ function fnvHash(str) { function stringifyBigInts(o) { - if ((typeof(o) == "bigint") || o.isZero !== undefined) { + if ((typeof(o) == "bigint") || o.eq !== undefined) { return o.toString(10); } else if (Array.isArray(o)) { return o.map(stringifyBigInts);