Skip to content

Commit 9f8d106

Browse files
committed
Added support for QUO operation
1 parent 4321add commit 9f8d106

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

src/utils/ExpressionHelper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ class ExpressionVisitor extends ExtendedCircomVisitor<CircomValueType | null> {
288288
case CircomParser.DIV:
289289
return firstExpression / secondExpression;
290290
case CircomParser.QUO:
291-
this.addError("QUO operation is not supported", ctx);
292-
return null;
291+
// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Division
292+
return firstExpression / secondExpression;
293293
case CircomParser.MOD:
294294
return firstExpression % secondExpression;
295295
case CircomParser.ADD:

test/circom-template-inputs-visitor.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,5 +255,22 @@ describe("Circom Template Inputs Visitor", () => {
255255

256256
expect(visitor.templateInputs.out2.type).to.equal("output");
257257
expect(visitor.templateInputs.out2.dimension).to.deep.equal([16]);
258+
259+
expect(visitor.templateInputs.tmp1.type).to.equal("intermediate");
260+
expect(visitor.templateInputs.tmp1.dimension).to.deep.equal([6, 8, 2, 20]);
261+
262+
expect(visitor.templateInputs.tmp2.type).to.equal("intermediate");
263+
expect(visitor.templateInputs.tmp2.dimension).to.deep.equal([6, 2, 20]);
264+
265+
expect(visitor.templateInputs.tmp3.type).to.equal("intermediate");
266+
expect(visitor.templateInputs.tmp3.dimension).to.deep.equal([6, 2, 2, 20]);
267+
268+
expect(visitor.templateInputs.tmp4.type).to.equal("intermediate");
269+
expect(visitor.templateInputs.tmp4.dimension).to.deep.equal([5, 2, 2, 20]);
270+
271+
expect(visitor.templateInputs.powers.type).to.equal("intermediate");
272+
expect(visitor.templateInputs.powers.dimension).to.deep.equal([
273+
2, 256, 2, 6,
274+
]);
258275
});
259276
});

test/data/Math.circom

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
pragma circom 2.1.6;
22

3-
template Math(a, b) {
3+
template Math(a, b, c) {
44
var input1 = (a + b) / 2;
55
var input2 = a + b / 2;
66

7+
var PRECOMPUTE_NUMBER = 2 ** c;
8+
9+
signal tmp1 [a][PRECOMPUTE_NUMBER][2][b];
10+
11+
var STRIDE = 8;
12+
var parts = a * c \ STRIDE;
13+
14+
signal tmp2[a] [2] [b];
15+
signal tmp3[a] [2][2][b];
16+
signal tmp4[a - 1][2][2][b];
17+
18+
signal powers[parts][2 ** STRIDE][2][a];
19+
720
signal output out1[input1];
821
signal output out2[input2];
922
}
1023

11-
component main = Math(6, 20);
24+
component main = Math(6, 20, 3);

0 commit comments

Comments
 (0)