123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150(*****************************************************************************)(* *)(* MIT License *)(* Copyright (c) 2022 Nomadic Labs <contact@nomadic-labs.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)openKzg.BlsopenIdentitiesmoduleL=Plompiler.LibCircuittypepublic={public_inputs:Scalar.tarray;input_coms_size:int}letone=Scalar.oneletmone=Scalar.negateonelettwo=Scalar.addoneoneletwire_name=Plompiler.Csir.wire_nameletcom_label="com"lettmp_buffers=ref[||]typeanswers={q:Scalar.t;wires:Scalar.tarray;wires_g:Scalar.tarray}typewitness={q:Evaluations.t;wires:Evaluations.tarray}letget_buffers~nb_buffers~nb_ids=letprecomputed=!tmp_buffersinletnb_precomputed=Array.lengthprecomputedinletsize_eval=Evaluations.lengthprecomputed.(0)inletbuffers=Array.init(maxnb_buffersnb_precomputed)(funi->ifi<nb_precomputedthenprecomputed.(i)elseEvaluations.createsize_eval)intmp_buffers:=buffers;(buffers,Array.initnb_ids(fun_->Evaluations.createsize_eval))letget_answers?(gx=false)~q_label~prefix~prefix_commonanswers:answers=letdummy=Scalar.zeroinletanswer=get_answeranswersinletanswer_wirew=letw=wire_namewinletw'=prefixwinletx=answerXw'inletgx=ifgxthenanswerGXw'elsedummyin(x,gx)inletq=prefix_commonq_label|>answerXinletwires,wires_g=Array.initPlompiler.Csir.nb_wires_archanswer_wire|>Array.splitin{q;wires;wires_g}letget_evaluations~q_label~prefix~prefix_commonevaluations=letfind_wirew=Evaluations.find_evaluationevaluations(prefix@@wire_namew)in{q=Evaluations.find_evaluationevaluations(prefix_commonq_label);wires=Array.initPlompiler.Csir.nb_wires_archfind_wire;}(* Block names to merge identities within, if identities are independent, use q_label instead.
For instance, we want to have want AddLeft and Addright identities to be merged inside the Arithmetic block,
we thus use "arith" as Map key for these gates identities.
We also want to use the ECC point addition identity independently, as such we put ECCAdd gate's q_label as key. *)letarith="Arith"letqadv_label="qadv"letmap_singletonm=letmapft=letopenLinlet*x=tinret(fx)inmap(funx->[x])mmoduletypeBase_sig=sigvalq_label:stringvalidentity:string*intvalindex_com:intoptionvalnb_advs:intvalnb_buffers:intvalgx_composition:boolvalequations:q:Scalar.t->wires:Scalar.tarray->wires_g:Scalar.tarray->?precomputed_advice:Scalar.tSMap.t->unit->Scalar.tlistvalprover_identities:prefix_common:(string->string)->prefix:(string->string)->public:public->domain:Domain.t->prover_identitiesvalverifier_identities:prefix_common:(string->string)->prefix:(string->string)->public:public->generator:Scalar.t->size_domain:int->verifier_identities(* Give the size of the domain on which the identities
of the gate need to have the evaluation of each of his polynomial
divided by the size of the citcuit. *)valpolynomials_degree:intSMap.tvalcs:q:L.scalarL.repr->wires:L.scalarL.reprarray->wires_g:L.scalarL.reprarray->?precomputed_advice:L.scalarL.reprSMap.t->unit->L.scalarL.reprlistL.tend