Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(circom): DivisionBy #171

Merged
merged 3 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion beacon-light-client/circom/circuits/utils/numerical.circom
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,31 @@ template DivisionVerification() {
signal input quotient;
signal input remainder;

//TODO: Needs additional corebase nstraint
dividend === divisor * quotient + remainder;

component lessThan = LessThanBitsCheck(252);
lessThan.in[0] <== remainder;
lessThan.in[1] <== divisor;
lessThan.out === 1;
}

template DivisionBy() {
signal input divisor;
signal input dividend;
signal output quotient;
signal output remainder;

quotient <-- dividend \ divisor;
remainder <-- dividend % divisor;

component divisionVerification = DivisionVerification();
divisionVerification.divisor <== divisor;
divisionVerification.dividend <== dividend;
divisionVerification.quotient <== quotient;
divisionVerification.remainder <== remainder;
}


template Pow(N){
signal input base;
signal input power;
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"
}