Skip to content

Commit

Permalink
Support mutiply by point 0 in scalarmulany
Browse files Browse the repository at this point in the history
  • Loading branch information
jbaylina committed Sep 5, 2019
1 parent ebbeaeb commit 024188b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
16 changes: 10 additions & 6 deletions circuits/escalarmulany.circom
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

include "montgomery.circom";
include "babyjub.circom";
include "comparators.circom";

template Multiplexor2() {
signal input sel;
Expand Down Expand Up @@ -138,6 +139,8 @@ template EscalarMulAny(n) {
component doublers[nsegments-1];
component m2e[nsegments-1];
component adders[nsegments-1];
component zeropoint = IsZero();
zeropoint.in <== p[0];

var s;
var i;
Expand All @@ -154,8 +157,9 @@ template EscalarMulAny(n) {
}

if (s==0) {
p[0] ==> segments[s].p[0];
p[1] ==> segments[s].p[1];
// force G8 point if input point is zero
segments[s].p[0] <== p[0] + (5299619240641551281634865583518297030282874472190772894086521144482721001553 - p[0])*zeropoint.out;
segments[s].p[1] <== p[1] + (16950150798460657717958625567821834550301663161624707787222815936182638968203 - p[1])*zeropoint.out;
} else {
doublers[s-1] = MontgomeryDouble();
m2e[s-1] = Montgomery2Edwards();
Expand Down Expand Up @@ -183,10 +187,10 @@ template EscalarMulAny(n) {
}

if (nsegments == 1) {
segments[0].out[0] ==> out[0];
segments[0].out[1] ==> out[1];
segments[0].out[0]*(1-zeropoint.out) ==> out[0];
segments[0].out[1]+(1-segments[0].out[1])*zeropoint.out ==> out[1];
} else {
adders[nsegments-2].xout ==> out[0];
adders[nsegments-2].yout ==> out[1];
adders[nsegments-2].xout*(1-zeropoint.out) ==> out[0];
adders[nsegments-2].yout+(1-adders[nsegments-2].yout)*zeropoint.out ==> out[1];
}
}
2 changes: 1 addition & 1 deletion circuits/escalarmulfix.circom
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ template EscalarMulFix(n, BASE) {
var s;
var i;
var nseg;
var nWindows
var nWindows;

for (s=0; s<nsegments; s++) {

Expand Down

0 comments on commit 024188b

Please sign in to comment.