Skip to content

Commit

Permalink
feat(circom): Add DivisionBy template
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-nikolov96 committed Jun 27, 2023
1 parent 45eaaf9 commit 1456b2a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion beacon-light-client/circom/circuits/utils/numerical.circom
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,30 @@ template DivisionVerification() {
signal input remainder;

dividend === divisor * quotient + remainder;

component lessThan = LessThan(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;

quotient * divisor + remainder === dividend;

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


template Pow(N){
Expand Down

0 comments on commit 1456b2a

Please sign in to comment.