Skip to content

Commit

Permalink
feat(circom): Add DivisionBy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-nikolov96 committed Jun 27, 2023
1 parent 1456b2a commit c558e88
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 3 deletions.
4 changes: 1 addition & 3 deletions beacon-light-client/circom/circuits/utils/numerical.circom
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ template DivisionVerification() {

dividend === divisor * quotient + remainder;

component lessThan = LessThan(252);
component lessThan = LessThanBitsCheck(252);
lessThan.in[0] <== remainder;
lessThan.in[1] <== divisor;
lessThan.out === 1;
Expand All @@ -59,8 +59,6 @@ template DivisionBy() {
quotient <-- dividend \ divisor;
remainder <-- dividend % divisor;

quotient * divisor + remainder === dividend;

component divisionVerification = DivisionVerification();
divisionVerification.divisor <== divisor;
divisionVerification.dividend <== dividend;
Expand Down
5 changes: 5 additions & 0 deletions beacon-light-client/circom/test/division_by/circuit.circom
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pragma circom 2.1.5;

include "../../circuits/utils/numerical.circom";

component main = DivisionBy();
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dividend": "23",
"divisor": "10"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"quotient": "2",
"remainder": "3"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dividend": "100",
"divisor": "10"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"quotient": "10",
"remainder": "0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"dividend": "420",
"divisor": "469"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"quotient": "0",
"remainder": "420"
}

0 comments on commit c558e88

Please sign in to comment.