Skip to content

Commit

Permalink
Added support for QUO operation
Browse files Browse the repository at this point in the history
  • Loading branch information
KyrylR committed Dec 25, 2024
1 parent 4321add commit 9f8d106
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/utils/ExpressionHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ class ExpressionVisitor extends ExtendedCircomVisitor<CircomValueType | null> {
case CircomParser.DIV:
return firstExpression / secondExpression;
case CircomParser.QUO:
this.addError("QUO operation is not supported", ctx);
return null;
// See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Division
return firstExpression / secondExpression;
case CircomParser.MOD:
return firstExpression % secondExpression;
case CircomParser.ADD:
Expand Down
17 changes: 17 additions & 0 deletions test/circom-template-inputs-visitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,5 +255,22 @@ describe("Circom Template Inputs Visitor", () => {

expect(visitor.templateInputs.out2.type).to.equal("output");
expect(visitor.templateInputs.out2.dimension).to.deep.equal([16]);

expect(visitor.templateInputs.tmp1.type).to.equal("intermediate");
expect(visitor.templateInputs.tmp1.dimension).to.deep.equal([6, 8, 2, 20]);

expect(visitor.templateInputs.tmp2.type).to.equal("intermediate");
expect(visitor.templateInputs.tmp2.dimension).to.deep.equal([6, 2, 20]);

expect(visitor.templateInputs.tmp3.type).to.equal("intermediate");
expect(visitor.templateInputs.tmp3.dimension).to.deep.equal([6, 2, 2, 20]);

expect(visitor.templateInputs.tmp4.type).to.equal("intermediate");
expect(visitor.templateInputs.tmp4.dimension).to.deep.equal([5, 2, 2, 20]);

expect(visitor.templateInputs.powers.type).to.equal("intermediate");
expect(visitor.templateInputs.powers.dimension).to.deep.equal([
2, 256, 2, 6,
]);
});
});
17 changes: 15 additions & 2 deletions test/data/Math.circom
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
pragma circom 2.1.6;

template Math(a, b) {
template Math(a, b, c) {
var input1 = (a + b) / 2;
var input2 = a + b / 2;

var PRECOMPUTE_NUMBER = 2 ** c;

signal tmp1 [a][PRECOMPUTE_NUMBER][2][b];

var STRIDE = 8;
var parts = a * c \ STRIDE;

signal tmp2[a] [2] [b];
signal tmp3[a] [2][2][b];
signal tmp4[a - 1][2][2][b];

signal powers[parts][2 ** STRIDE][2][a];

signal output out1[input1];
signal output out2[input2];
}

component main = Math(6, 20);
component main = Math(6, 20, 3);

0 comments on commit 9f8d106

Please sign in to comment.