Skip to content

Commit

Permalink
fix recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
zkronos73 committed Nov 14, 2022
1 parent 88da65a commit f1c779f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 41 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"recursive1_buildconstanttree": ". ./pre.sh && $BCTREE -c $BDIR/recursive1.const -p $BDIR/recursive1.pil -s $BDIR/recursive.starkstruct.json -t $BDIR/recursive1.consttree -v $BDIR/recursive1.verkey.json",
"recursive1_verifier_gencircom": ". ./pre.sh && $PILSTARK/main_pil2circom.js --skipMain --verkeyInput -p $BDIR/recursive1.pil -s $BDIR/recursive.starkstruct.json -v $BDIR/recursive1.verkey.json -o $BDIR/recursive1.verifier.circom",
"recursive2_gencircom": ". ./pre.sh && node $NODE src/main_genrecursive.js -v $BDIR/recursive1.verkey.json -o $BDIR/recursive2.circom",
"recursive2_compile": ". ./pre.sh && circom --r1cs --sym --wasm --c --verbose --O1 --prime goldilocks $BDIR/recursive2.circom -o $BDIR -l node_modules/pil-stark/circuits.gl",
"recursive2_compile": ". ./pre.sh && circom --inspect --r1cs --sym --wasm --c --verbose --O1 --prime goldilocks $BDIR/recursive2.circom -o $BDIR -l node_modules/pil-stark/circuits.gl",
"recursive2_setup": ". ./pre.sh && $PILSTARK/compressor12/main_compressor12_setup.js -r $BDIR/recursive2.r1cs -p $BDIR/recursive2.pil -c $BDIR/recursive2.const -e $BDIR/recursive2.exec",
"recursive2_buildstarkinfo": ". ./pre.sh && $PILSTARK/main_genstarkinfo.js -p $BDIR/recursive2.pil -s $BDIR/recursive.starkstruct.json -i $BDIR/recursive2.starkinfo.json",
"recursive2_buildchelpers": ". ./pre.sh && $PILSTARK/main_buildchelpers.js -m -p $BDIR/recursive2.pil -s $BDIR/recursive.starkstruct.json -c $BDIR/recursive2.chelpers/recursive2.chelpers.cpp -C StarkRecursive2",
Expand All @@ -80,8 +80,8 @@
"final_gencircom": ". ./pre.sh && cp recursive/final.circom $BDIR",
"final_compile": ". ./pre.sh && circom --r1cs --sym --wasm --c --verbose $BDIR/final.circom -o $BDIR -l node_modules/pil-stark/circuits.bn128 -l node_modules/circomlib/circuits",
"downloadptaw": "wget -P build https://hermez.s3-eu-west-1.amazonaws.com/powersOfTau28_hez_final.ptau",
"g16setup": ". ./pre.sh && $SNARKJS g16s $BDIR/final.r1cs build/powersOfTau28_hez_final.ptau $BDIR/final.g16.0000.zkey",
"g16contribute": ". ./pre.sh && $SNARKJS zkc $BDIR/final.g16.0000.zkey $BDIR/final.g16.0001.zkey -e=\"$(dd if=/dev/random bs=64 count=1 | base64 -w0)\"",
"g16setup": ". ./pre.sh && $SNARKJS g16s $BDIR/final.r1cs build/powersOfTau28_hez_final.ptau $BDIR/final.g16.0000.zkey --verbose",
"g16contribute": ". ./pre.sh && $SNARKJS zkc $BDIR/final.g16.0000.zkey $BDIR/final.g16.0001.zkey --verbose -e=\"$(dd if=/dev/random bs=64 count=1 | base64 -w0)\"",
"g16evk": ". ./pre.sh && $SNARKJS zkev $BDIR/final.g16.0001.zkey $BDIR/final.g16.verkey.json",
"g16solidity": ". ./pre.sh && $SNARKJS zkesv $BDIR/final.g16.0001.zkey $BDIR/final.g16.verifier.sol",
"preg16setup": ". ./pre.sh && [ -f build/powersOfTau28_hez_final.ptau ] || npm run downloadptaw",
Expand Down
16 changes: 9 additions & 7 deletions recursive/recursive2.circom.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ template Main() {
signal input a_root2[4];
signal input a_root3[4];
signal input a_root4[4];

signal input a_evals[82][3];

signal input a_s0_vals1[64][12];
Expand Down Expand Up @@ -119,14 +120,14 @@ template Main() {
component isOneBatchA = IsZero();
isOneBatchA.in <== a_publics[42] - a_publics[16] - 1;
component a_muxRootC = MultiMux1(4);
a_muxRootC.c[0] <== rootCSingle;
a_muxRootC.c[1] <== rootC;
a_muxRootC.c[0] <== rootC;
a_muxRootC.c[1] <== rootCSingle;
a_muxRootC.s <== isOneBatchA.out;

for (var i=0; i<4; i++) {
vA.publics[43+i] <== a_muxRootC.out[i];
vA.publics[43+i] <== rootC[i];
}

vA.rootC <== a_muxRootC.out;

component vB = StarkVerifier();

Expand Down Expand Up @@ -164,13 +165,14 @@ template Main() {
component isOneBatchB = IsZero();
isOneBatchB.in <== b_publics[42] - b_publics[16] - 1;
component b_muxRootC = MultiMux1(4);
b_muxRootC.c[0] <== rootCSingle;
b_muxRootC.c[1] <== rootC;
b_muxRootC.c[0] <== rootC;
b_muxRootC.c[1] <== rootCSingle;
b_muxRootC.s <== isOneBatchB.out;

for (var i=0; i<4; i++) {
vB.publics[43+i] <== b_muxRootC.out[i];
vB.publics[43+i] <== rootC[i];
}
vB.rootC <== b_muxRootC.out;

// oldStateRoot
for (var i=0; i<8; i++) {
Expand Down
56 changes: 25 additions & 31 deletions recursive/recursivef.circom.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ include "iszero.circom";

template Main() {
signal input publics[43];

signal input root1[4];
signal input root2[4];
signal input root3[4];
Expand Down Expand Up @@ -44,39 +45,11 @@ template Main() {
for (var i=0; i<43; i++) {
sv.publics[i] <== publics[i];
}

component isOne = IsZero();
isOne.in <== publics[42] -publics[16] -1;

component muxKey = MultiMux1(4);
muxKey.s <== isOne.out;
muxKey.c[0][0] <== <%- constRoot1[0] %>;
muxKey.c[0][1] <== <%- constRoot1[1] %>;
muxKey.c[0][2] <== <%- constRoot1[2] %>;
muxKey.c[0][3] <== <%- constRoot1[3] %>;
muxKey.c[1][0] <== <%- constRoot2[0] %>;
muxKey.c[1][1] <== <%- constRoot2[1] %>;
muxKey.c[1][2] <== <%- constRoot2[2] %>;
muxKey.c[1][3] <== <%- constRoot2[3] %>;

sv.publics[43] <== <%- constRoot2[0] %>;
sv.publics[44] <== <%- constRoot2[1] %>;
sv.publics[45] <== <%- constRoot2[2] %>;
sv.publics[46] <== <%- constRoot2[3] %>;

sv.root1 <== root1;
sv.root2 <== root2;
sv.root3 <== root3;
sv.root4 <== root4;

sv.rootC[0] <== muxKey.out[0];
sv.rootC[1] <== muxKey.out[1];
sv.rootC[2] <== muxKey.out[2];
sv.rootC[3] <== muxKey.out[3];


sv.evals <== evals;

sv.s0_vals1 <== s0_vals1;
sv.s0_vals3 <== s0_vals3;
sv.s0_vals4 <== s0_vals4;
Expand All @@ -85,12 +58,10 @@ template Main() {
sv.s0_siblings3 <== s0_siblings3;
sv.s0_siblings4 <== s0_siblings4;
sv.s0_siblingsC <== s0_siblingsC;

sv.s1_root <== s1_root;
sv.s2_root <== s2_root;
sv.s3_root <== s3_root;
sv.s4_root <== s4_root;

sv.s1_vals <== s1_vals;
sv.s1_siblings <== s1_siblings;
sv.s2_vals <== s2_vals;
Expand All @@ -99,8 +70,31 @@ template Main() {
sv.s3_siblings <== s3_siblings;
sv.s4_vals <== s4_vals;
sv.s4_siblings <== s4_siblings;

sv.finalPol <== finalPol;

component isOne = IsZero();
isOne.in <== publics[42] -publics[16] -1;
component muxKey = MultiMux1(4);
muxKey.s <== isOne.out;
muxKey.c[0][0] <== <%- constRoot2[0] %>;
muxKey.c[0][1] <== <%- constRoot2[1] %>;
muxKey.c[0][2] <== <%- constRoot2[2] %>;
muxKey.c[0][3] <== <%- constRoot2[3] %>;
muxKey.c[1][0] <== <%- constRoot1[0] %>;
muxKey.c[1][1] <== <%- constRoot1[1] %>;
muxKey.c[1][2] <== <%- constRoot1[2] %>;
muxKey.c[1][3] <== <%- constRoot1[3] %>;

sv.publics[43] <== <%- constRoot2[0] %>;
sv.publics[44] <== <%- constRoot2[1] %>;
sv.publics[45] <== <%- constRoot2[2] %>;
sv.publics[46] <== <%- constRoot2[3] %>;

sv.rootC[0] <== muxKey.out[0];
sv.rootC[1] <== muxKey.out[1];
sv.rootC[2] <== muxKey.out[2];
sv.rootC[3] <== muxKey.out[3];

}

component main {public [publics]}= Main();

0 comments on commit f1c779f

Please sign in to comment.