From f1c779f5745c73d92e33f3dabb2688f6460204f8 Mon Sep 17 00:00:00 2001 From: zkronos73 Date: Mon, 14 Nov 2022 08:17:25 +0000 Subject: [PATCH] fix recursive --- package.json | 6 ++-- recursive/recursive2.circom.ejs | 16 +++++----- recursive/recursivef.circom.ejs | 56 +++++++++++++++------------------ 3 files changed, 37 insertions(+), 41 deletions(-) diff --git a/package.json b/package.json index 279c76f4..28e1afd7 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/recursive/recursive2.circom.ejs b/recursive/recursive2.circom.ejs index 9f0c1d24..acff3c60 100644 --- a/recursive/recursive2.circom.ejs +++ b/recursive/recursive2.circom.ejs @@ -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]; @@ -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(); @@ -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++) { diff --git a/recursive/recursivef.circom.ejs b/recursive/recursivef.circom.ejs index 35eeac38..34378ad2 100644 --- a/recursive/recursivef.circom.ejs +++ b/recursive/recursivef.circom.ejs @@ -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]; @@ -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; @@ -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; @@ -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(); \ No newline at end of file