You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
18 KiB

  1. // for the initial development is hardcoded
  2. const inputs = {
  3. Private: [3],
  4. Public: [35]
  5. };
  6. const circuit = {"NVars":8,"NPublic":1,"NSignals":8,"PrivateInputs":["s0"],"PublicInputs":["s1"],"Signals":["one","s1","s0","s2","s3","s4","s5","out"],"Witness":null,"Constraints":[{"Op":"in","V1":"","V2":"","Out":"s1","Literal":"","PrivateInputs":null,"PublicInputs":null},{"Op":"in","V1":"","V2":"","Out":"s0","Literal":"","PrivateInputs":null,"PublicInputs":null},{"Op":"*","V1":"s0","V2":"s0","Out":"s2","Literal":"s2=s0*s0","PrivateInputs":null,"PublicInputs":null},{"Op":"*","V1":"s2","V2":"s0","Out":"s3","Literal":"s3=s2*s0","PrivateInputs":null,"PublicInputs":null},{"Op":"+","V1":"s3","V2":"s0","Out":"s4","Literal":"s4=s3+s0","PrivateInputs":null,"PublicInputs":null},{"Op":"+","V1":"s4","V2":"5","Out":"s5","Literal":"s5=s4+5","PrivateInputs":null,"PublicInputs":null},{"Op":"*","V1":"s5","V2":"1","Out":"s1","Literal":"equals(s1, s5): s1==s5 * 1","PrivateInputs":null,"PublicInputs":null},{"Op":"*","V1":"s1","V2":"1","Out":"s5","Literal":"equals(s1, s5): s5==s1 * 1","PrivateInputs":null,"PublicInputs":null},{"Op":"*","V1":"1","V2":"1","Out":"out","Literal":"out=1*1","PrivateInputs":null,"PublicInputs":null}],"R1CS":{"A":[["0","0","1","0","0","0","0","0"],["0","0","0","1","0","0","0","0"],["0","0","1","0","1","0","0","0"],["5","0","0","0","0","1","0","0"],["0","0","0","0","0","0","1","0"],["0","1","0","0","0","0","0","0"],["1","0","0","0","0","0","0","0"]],"B":[["0","0","1","0","0","0","0","0"],["0","0","1","0","0","0","0","0"],["1","0","0","0","0","0","0","0"],["1","0","0","0","0","0","0","0"],["1","0","0","0","0","0","0","0"],["1","0","0","0","0","0","0","0"],["1","0","0","0","0","0","0","0"]],"C":[["0","0","0","1","0","0","0","0"],["0","0","0","0","1","0","0","0"],["0","0","0","0","0","1","0","0"],["0","0","0","0","0","0","1","0"],["0","1","0","0","0","0","0","0"],["0","0","0","0","0","0","1","0"],["0","0","0","0","0","0","0","1"]]}};
  7. const setup = {"G1T":[["1","2","1"],["9060122645382620703912131576596541626275459709528189228377806057487579608777","18552187397697551333331725893031797322982741119378938051419279530432019342188","3919832823776698517503991563314380964772509805496866335136766014655653885039"],["3431942732352420155072012305772200032351558289434666812664907450194303325062","4439599953252627470375533428625515591130196040383855535852348208030559853883","14380560303832201195398083235300299176047912901985399685682202109326154017836"],["11822380047681984103313692560743268302859438330661504781058076964635828163545","8488512494309293936137843888199752117254316665196510892680599422501820645496","207004353051063893639356651228375382867476477156537867899604336306721551467"],["13369149528075388664712802073899096107708041573561715823114105693815630697378","6525621151123618360901435612882281583875709999978828932272129288831466827866","11600385445429612519884793603235271263938097080983698348010928146803302198747"],["18825387175693767583147722806260279460154004788869566944381085627780183542321","21871358166487926120169952009258732520451507028508675117536950592602704070959","8338796029255778027872921751274765153551503228218840224193616009381870863859"],["5295089009059580756220007472162113933002275383891633808559131232316008899814","19161554621761663329748638078311007921708756009709737212648552680361792208166","5748093032442185061964190665446005439031320403353312848790332588256670922610"]],"G2T":null,"Pk":{"A":[["7174206590592787125297180086710023841226950848202094190665117479806387137883","17652025361381698291522443621361023414364698651922621167014090353827449887602","14028631817708334859212193494275677331425051891495047854336610288692893108523"],["9496211367937653129316339857607539932181489693017062849205858418506655217336","20715527976204177150125765369524021558336699683501368910122162008825354750707","18144702909222194940950017253098692203736826433930172591650227400416842046007"],["8901446074764075762317322178403715419786041734956949277497403600806655756999","1819546472752206525532345074946787072722754628056662237144167000020486136261","14011785723394611426263152521847748432413809948263682161626132238732409292156"],["3034322623472011366874310663122511445017897586814784238936130126083833342572","6000716018565206962631571744863084388195912679008915160547676552399144597222","19633356630741448377199281317268311013507848842507369122202461483618915252791"],["20400767842971485002755729001425862955157807736474954458535675697195868062157","2480339942144794994541179826591189975358952742940180047516155221987544649543","2930359521139331505426168469282155091733507964960079037721723057334380754832"],["15972800874658679764040929017147984737594922899793665982077616144811369187929","516092169688554124376657658423277195353489015172032409759529165262089173843","13393164579642250179301818522896567463002539684064419152857556777450792232485"],["7989664273119626379441761463603280444548957021816315575283452454158546653123","20521624009984172416112083757509334497384073164090293573602315991532953084126","9329559313197536002444990345118096485080888784374316889753587882609581324708"],["0","0","0"]],"B":[[["5815369437987100634609339902385421223315394731609221757034488448935919995916","8252390417041598259382486298194659712618888866174524769037422532689839477658"],["11533402706690712823766541428715411632779261603093597859161664756122531183237","18627526051178474362533706672805205430694267650356820844522468576441067526839"],["5816946121727103786752704946398277271179139419210154515139785707542532543515","8711188252952341899050651095594182425912023670301734838624741835772060675923"]],[["0","0"],["0","0"],["0","0"]],[["2401819658168185492503821857831354652027009144511160692800080431942811642954","17887968592994135563790051067012399327748486012642292105318763562719151670738"],["10194497249847711690662078608111424117717077813588311699424143534915621933145","5716972360720872183753890650316537039876875814617422375421303585710342314972"],["11191630595691625428764822244945047324117541309730980482204081246404577903244","16929614368553665442422134772689491903010833430956238740001557474030061052047"]],[["0","0"],["0","0"],["0","0"]],[["0","0"],["0","0"],["0","0"]],[["0","0"],["0","0"],["0","0"]],[["0","0"],["0","0"],["0","0"]],[["0","0"],["0","0"],["0","0"]]],"C":[["0","0","0"],["7228767935399026124377674569835023996471124047376499986588322759520287376643","15756846338035180234637287638488767247805098673677786920524329717482129350970","3171690559257254733468070394886500227122785515732964450380707782252885192427"],["0","0","0"],["502178371863112877214246669105223240671288387004954562104561474318626628358","14281071509372702160411194231620580091825555855821393182911135574049788049250","13353222991856667158413464713971759235844487491950350135168816332124546071957"],["75830204847830990594144479386955887505479373961361960992122468551082617598","3620989002593745206918814452932530954989678696591623917474446342425092995497","19666444163225247314242064702527779043250121130484727356466142911949111935438"],["9031012234534022136483008989682930453160625935900206563086229260562901425140","12167734924968472048363017594858894873922981749643702767142838456901122279618","8866186995178277587293519284886147013162202661113424681959849037110579430954"],["7043614674423437565815457189316920937598596386585351081257639723526445294622","13997282284798872174173623407608412755589971684761434109988488309457350594322","5432033042341951323916232775494378178055280220023620917623070336881935188880"],["12540326078906727737977942384837308648589691803986711969888425075942125072515","20336215384724265398926866877489490981908331512379622833283546888430087905285","404381112074483703365120720382997575432300588716855073754573083326810107046"]],"Kp":[["16397731635341061441600048298332877379485321359782651940831453466888087726793","11990389239268162965738393253423986038495575862450766744339565491500894056998","4740202064294228054891894739816778666936733392862283378796889148289715470140"],["12461454013977576960065191252419221404197669361166610130734464986277253862324","6094388489154805073749746895410983103386493705580804449661063285519872192451","8359105801841182960739325087251631077342120727282223771432006229153914968890"],["18457408708429046146629326609802671028103942264210002426725236753035516623906","18545849575159982833013987628873581232936077783444232057806007948855054399625","618749639505772405889754631206429697176812030971262513731033712304234874418"],["4557458278801119067353358785306376592356924433404696901104306174394808584856","11727755992040510811991308532742640403357849878113224062166958735310365336821","11800005947420536690266944520797644308314964571308722589856008342003550438733"],["11045237773515655252238230722838602454216253865679283403883451102008737954322","20459622981394974501639705422311715443696149891014332262191264185012934820835","16704662814308768799348611138107904053331354994353926431672416749019955129354"],["7666109966547297455059674915442404837637115579036115598101747754770977557225","18512894982168636908918309706134992141627978876560796851949223013303115195291","19823718127687878306247084559452726410731057102132140941746905033465319714386"],["8923951353178846455449386767499183969139412662946660616673044124895919749553","16080607484400595699269809548351227229290499524769502164338935861202252610358","18003572383917501082652709867467294420820997768712604413771466196940372695536"],["9493928075603028079979385952295263213757105981181830620659024601654311048961","16033649245701154034094927637666840087702550265715865953269493122798725310441","18838535899918008331143704820589722656209350313166306272877060336239646296736"]],"Ap":[["17310202984743469784106570115659758169564348235060651103821167200155783660918","2045857096388329417446474612981991173436096054584464753685233111783909278185","149258049057629035002740575667943995604773593033407664490503911393137939724"],["12308502803380963717917299028665830285655931293373977919528546972772611201893","3573390545894811605897775284829227309141780937281562397893394071295330341327","15759991386309921105345895393351664441629404398194632678619406374074747343461"],["17919191091012506920817750996376310406088010875380023766754475715290868397752","14992232101897933477049912622215992904072719270431233853990556171603707415082","16608227653666428681518809275951539253294049396546857477308378296354036796892"],["6953747325129672696717463838122915047815275353293122028433963608181201863882","6419581023792778112762192572596350211310078278044361882053378885462079944238","12832145701739198674116310242269406968876180979244356882610581968128858520762"],["9432254756736523110034404783484840768780306500787008606137624450505554520435","6238049349920776714077150877453703226567604544525725602435764552740388147061","16206787146740222307434915485322443350901391864542964549250937609221279435121"],["20621184205232877805958633205452087718190994896343873812870546221433686913613","12856359198128666430171274778842157543041689589723182023473900388392058929606","11582912053018919500379507725486489329655937241224344538021607590326180677358"],["16677528246129312709240739617646314258879663219575692781694728968325593610949","6397274661015364427230613915045582313266278499204613733814533144723997400371","8289239447135302152271538605839546417853218661014808909784337448208209839379"],["0","0","0"]],"Bp":[["20018780434939681348137993935355686411827041700269658615965970389757853610060","12214991964314039865316783931020555498866124560003656342797729842023365206713","14563493435420279349650395422592820229826346263123449820617232894977970999387"],["0","0","0"],["19274528938481114377814791526884136805658142485058201128291111188915998296357","11319134201215538741944134532084533437012392966224464057344192877082320972891","1593572666518915656000637407242705056790260319730981223924868331168260242449"],["0","0","0"],["0","0","0"],["0","0","0"],["0","0","0"],["0","0","0"]],"Cp":[["0","0","0"],["14987227002519402401359841510768304665057543070376416931019432865238411881373","4707895417838638711612830595553391676214246525936871977687639690199976052742","17404086172672623228193483870496542757414022042455907126449959180813980194773"],["0","0","0"],["16014836084107670530502498025633394447105169997401771603866344164565660540973","20235483341184415292875962913426672632727141159620557462454344181386411192357","19333921793661249086188773173741885819349336071811123445234475710091821184997"],["12490952236165464028751046327529873153947842808903658123722900467139035958314","847512381539492768958412219292953032928469010943979052909089966885101136845","4184102947332631027232961712919297966146030658948066145861361929711365988039"],["5123818148326232257245867142221882926648873724312852831604116546492362380508","19044410175328600074008795135278295722267991800599159011122500985820973438460","5015595052313212324194813708153870196673017569081232632586001237044929654040"],["15978580101259669822312864668490348182406207205048917713158641372796675169523","8364084821959862858099098975080346721532738543672583975603478487742174982833","2319477857884936519784662361436527615659625357181614654126959744602265664688"],["20682997069429442890771013480814916377706173671426676880788124657265474725432","18660989240828625870452952266849945193634768111915852064783696435779861308955","3517407932972985341499660388830421377171132598336429919477261029159940762388"]],"Z":["720","21888242871839275222246405745257275088548364400416034343698204186575808493853","1624","21888242871839275222246405745257275088548364400416034343698204186575808494882","175","21888242871839275222246405745257275088548364400416034343698204186575808495596","1"]},"Vk":{"Vka":[["20214571844042784668277636692905197466177419439964686731196189932981920590822","15276326414920997693778417011131896891285513750682271416430716961378882594519"],["16498035158192775354342900050792858826389458032456459122216986217940526372057","20991711584316395543077614973508465836613050901314901591480745784166147200174"],["6554187966347558329138786326314231043574337655348545603106486528529616191262","3329049453466022164817299141240290667596535381768743742083160916011303392614"]],"Vkb":["18601699720276287321203962347637511035834839448990340830509726610548371325938","1404033020547542514452780713672814114407357194997099157699901438205943518993","9878628437561206917036168906193330943231851856412294605073956359601611464573"],"Vkc":[["11201726330257670413254165918954792292808047052763030911614100485460506324887","934969546379598639340650175600025064266557353863820319935819231249163270767"],["13304404400663675184865999338606690656572060605272848711326915297751075541966","11378789116609243263745403165917762883252438608536455003337239566234909822227"],["17466827643606195162625697931726983774172034013958787179396969407079370356584","15000536982475601439524169813356540143374565850393853241584230104237035092676"]],"IC":[["7174206590592787125297180086710023841226950848202094190665117479806387137883","17652025361381698291522443621361023414364698651922621167014090353827449887602","14028631817708334859212193494275677331425051891495047854336610288692893108523"],["9496211367937653129316339857607539932181489693017062849205858418506655217336","20715527976204177150125765369524021558336699683501368910122162008825354750707","18144702909222194940950017253098692203736826433930172591650227400416842046007"]],"G1Kbg":["19565810405534790741082831936064612684475555528159464341421930532575157635016","9799284072503001264378302942679352604989683608693688725866622459096256374574","5439756270363982397635037014986730980256257574257202393692990560225837703460"],"G2Kbg":[["7203663164634332596159832593371068902137670685197048804721245666572399446641","9647927520523281739632004193430205551282338357864496740791607437771659434446"],["12635628955805234822373808404031007162830931332162422406930356235594909536097","4525590619102035023419475118621776377495537374130624082096973427302753356672"],["10340977129747011226703015997599340344360948786234691736499821757268703108360","10313061803116028699328887269171348446722130367355951387162443297447631257052"]],"G2Kg":[["3530878578326465145608159294456745500351881239330516635657099408154033928513","12828533343030757742027018294000229952634862390599660668826878515412669227723"],["1555565908497920970072864259284092943250038177120380161621820719610403685807","3695200516686918833737615149262571835341469128876911982248847228856612041601"],["21796564584401779739204868190265096884129092077989267871136514246491447614488","9849506192886271133535915496779663766139277044154034600311452060203107849389"]],"Vkz":[["11513088702254679699323010943896789023715231470824941455892216464429039145652","1625429026784522879605778124473104553417494250251020384149638852566558637730"],["21618500115441299970426725684976255792080430977789008509842208339530512020429","18998629536272373495983374392593854393457027995029334544640573238830053525634"],["4353032488604798586028070468593404321831373691185739435853683684699874655988","20116220156107780813383974456858322113922541314847440497024320298172369098679"]]}};
  8. const px = ["21888242871839275222246405745257275088548364400416034343698204186575808491809","10214513340191661770381656014453395041322570053527482693725828620402043982207","6250309353402993035685918085034577441952144056563245362589376084388869725846","8684363028317712437715356353558094792076827912572472885439518975877531461332","4676585224700845145864220486776033543224569523514814745192926496344784986728","15086167396042000456999692848727670503739063657925634782028102538317006907054","21632626702190133686375495752236851586646219728193583201883487889998783136513","12304536531079092564172545451934558461236042348706097084183122422939664568112","5627862446735063646553285921653823681621549943926414385940458402833120205122","19793152958064844596228144454594339151253283687552138463809498762698702751890","12878849570320523547145145010088473306441356493332753911233629701770305283468","21470238233661789063488227857761042404565669941380311465606745426068284375041","14598495318168266605115151979982065705759253455717291424254733984391562089814"];
  9. function callGenerateProof() {
  10. console.log("s", JSON.stringify(setup))
  11. let r = generateProofs(
  12. JSON.stringify(circuit),
  13. JSON.stringify(setup),
  14. JSON.stringify(px),
  15. JSON.stringify(inputs),
  16. );
  17. console.log("r", r);
  18. document.getElementById("proofResult").value = r;
  19. }
  20. function callVerifyProof() {
  21. const proof = document.getElementById("proofResult").value;
  22. let r = verifyProofs(
  23. JSON.stringify(circuit),
  24. JSON.stringify(setup),
  25. proof,
  26. JSON.stringify([35])
  27. );
  28. console.log("r", r);
  29. alert("verified: " + r);
  30. }