123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124(*****************************************************************************)(* *)(* 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.BlsopenKzg.UtilsmoduleSMap=Kzg.SMap(** Extension of the PC signature with additional types and functions used
in by Distributed_prover *)moduletypePC_for_distribution_sig=sigmoduleBasePC:Kzg.Interfaces.Polynomial_commitmentincludemoduletypeofBasePCvalmerge_answers:answerlist->answertypeworker_msg[@@derivingrepr]typemain_prover_statetypemain_prover_msg[@@derivingrepr]typepartial_prover_auxvaldistributed_expand_transcript:Transcript.t->querylist->answerlist->Transcript.tvaldistributed_prove_main1:Public_parameters.prover->Transcript.t->querylist->answerlist->secretlist->Commitment.prover_auxlist->(* we assume the same message is sent to all workers *)worker_msg*main_prover_statevaldistributed_prove_worker:secretlist->Commitment.prover_auxlist->worker_msg->main_prover_msgvaldistributed_prove_main2:main_prover_state->main_prover_msglist->proof*Transcript.t*partial_prover_auxend(** Extension of the KZG implementation with additional types and functions
used in by Distributed_prover *)moduleKzg_impl=structmoduleBasePC=Kzg.Polynomial_commitmentincludeBasePCtypeworker_msg=Scalar.tSMap.tSMap.t[@@derivingrepr](* batched polynomials, keyed by evaluation points *)typemain_prover_msg=Poly.tSMap.t[@@derivingrepr]typemain_prover_state={srs:Public_parameters.prover;transcript:Transcript.t;query:query;batched_answer:Scalar.tSMap.t;main_msg:main_prover_msg;}typepartial_prover_aux=unitletmerge_answers:answerlist->answer=letopenSMapinList.fold_left(union(fun_km1m2->Some(union_disjointm1m2)))emptyletdistributed_prove_workerf_map_list_prover_aux_listcoeffs=letf_map=group_secretsf_map_listinbatch_polyscoeffsf_mapletdistributed_expand_transcripttranscriptquery_listanswer_list=lettranscript=Transcript.list_expandquery_tquery_listtranscriptinTranscript.list_expandanswer_tanswer_listtranscriptletdistributed_prove_main1srstranscriptquery_listanswer_listsecret_listprover_aux_list=letquery=group_queriesquery_listinletanswer=group_answersanswer_listinlety_map,transcript=sample_ystranscriptqueryinletbatched_answer,coeffs=batch_answery_mapanswerinletmain_msg=distributed_prove_workersecret_listprover_aux_listcoeffsinletstate={srs;transcript;query;batched_answer;main_msg}in(coeffs,state)letdistributed_prove_main2{srs;transcript;query;batched_answer;main_msg}batched_polys_list=letbatched_polys_list=main_msg::batched_polys_listinletbatched_polys=SMap.map_list_to_list_mapbatched_polys_list|>SMap.map(List.fold_leftPoly.addPoly.zero)inletproof=compute_Wssrsbatched_polysbatched_answerqueryin(proof,Transcript.expandproof_tprooftranscript,())end