deps
Jordi Baylina jordi@baylina.cat
Sat, 28 Mar 2020 21:26:43 +0100
5 files changed,
23 insertions(+),
19 deletions(-)
M
package.json
→
package.json
@@ -33,7 +33,7 @@ "big-integer": "^1.6.32",
"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",
M
src/construction_phase.js
→
src/construction_phase.js
@@ -624,6 +624,9 @@
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++) {
M
src/gencode.js
→
src/gencode.js
@@ -175,17 +175,17 @@ return genOp(ctx, ast, "shl", 2);
} 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 @@ return resRef;
} } -function genOp(ctx, ast, op, nOps) { +function genOp(ctx, ast, op, nOps, adjustBool) { const vals = []; const valRefs = [];@@ -1159,7 +1159,8 @@ const params = [];
for (let i=0; i<nOps; i++) { params.push(vals[i].value[0]); } - rRef = newRef(ctx, "BIGINT", "_tmp", ctx.field[op](...params)); + + rRef = newRef(ctx, "BIGINT", "_tmp", adjustBool ? (ctx.field[op](...params)?bigInt.one:bigInt.zero) : ctx.field[op](...params)); } return rRef; }
M
src/lcalgebra.js
→
src/lcalgebra.js
@@ -85,12 +85,6 @@ constructor (aField) {
const self = this; this.field= aField; [ - ["lt",2], - ["leq",2], - ["eq",2], - ["neq",2], - ["geq",2], - ["gt",2], ["idiv",2], ["mod",2], ["band",2],@@ -102,12 +96,18 @@ ["lor",2],
["lnot",2], ["shl",2], ["shr",2], + ["lt",2, true], + ["leq",2, true], + ["eq",2, true], + ["neq",2, true], + ["geq",2, true], + ["gt",2, true] ].forEach( (op) => { - 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 @@ operands.push(arguments[i].v);
} return { t: "N", - v: self.field[op](...operands) + v: adjustBool ? ( self.field[op](...operands) ? bigInt.one: bigInt.zero) : self.field[op](...operands) }; }; }
M
src/utils.js
→
src/utils.js
@@ -77,7 +77,7 @@
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);