123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)openPlonk_testopenHelpersletnb_proofs=12letcircuit_size=4moduleScalar=Kzg.Bls.ScalarmodulePort:sigvalmake:unit->intend=structletport=ref50000letmake()=letp=!portinport:=p+1;pendmoduletypeDP_for_tests=sigincludeDistributed_prover.SmoduleWorker_Main:Distribution.Main_protocol.Svalpp_file:stringvalget_distributed_pp:MP.prover_public_parameters->bytesendmoduleDP_PlonK(Main:Distribution.Main_protocol.S)=structincludeDistributed_prover.Make(Main)moduleWorker_Main=Mainletpp_file=Filenames.plonk_pp_fileletget_distributed_pppp_prover=Plompiler.Utils.to_bytesMP.prover_public_parameters_tpp_proverendmoduleDP_aPlonk(PI:Aplonk.Pi_parameters.S)=structincludeDistributed_prover.Super_impl(PI)moduleWorker_Main=Distributed_prover.Main_Packletpp_file=Filenames.meta_pp_fileletget_distributed_pppp_prover=let({main_pp;_}:MP.prover_public_parameters)=pp_proverinPlompiler.Utils.to_bytesDistributed_prover.Main_Pack.prover_public_parameters_tmain_ppendmoduleNo_public_input_PIs=structletget_pi_module_=(moduleAplonk.Pi_parameters.No_public_input:Aplonk.Pi_parameters.CircuitPI)endmoduleRollup_example_PIs=structletget_pi_module_=(moduleAplonk.Pi_parameters.Rollup_example:Aplonk.Pi_parameters.CircuitPI)endmoduleDP_Kzg()=DP_PlonK(Distributed_prover.Main_Kzg)moduleDP_Pack()=DP_PlonK(Distributed_prover.Main_Pack)moduleDP_Meta()=DP_aPlonk(Rollup_example_PIs)letsrs=srsmoduleCircuit_Builder=structletbasenb_proofsk=letopenCasesinlet_,circuit_map,witness,_=Big_circuit.make~nb_proofs~public_input_size:2~k|>aggregate_casesin(* FIXME Multicircuit with Meta-PlonK doesn’t work *)(* let circuit_map =
Kzg.SMap.(union_disjoint circuit_map (update_keys (fun i -> i ^ "2") circuit_map))
in *)(circuit_map,witness)letrange_checksnb_proofs_=letopenCasesinlet_,circuit_map,witness,_=List.initnb_proofs(Fun.constRange_Checks.valid)|>aggregate_casesin(circuit_map,witness)endmoduleHelpers(DP:DP_for_tests)=structmoduleMP=DP.MPmoduleRunner=Master_runner.Make(DP.D)letparse_nodess=(* Expected as ip:port;ip:port... *)letnode_strings=String.split_on_char','sinList.mapi(funins->letn=String.split_on_char':'nsinRunner.{ip=List.hdn;port=int_of_string@@List.nthn1;name="worker"^string_of_inti;})node_stringsletrun_master?nb_proofs?(circuit_size=circuit_size)~self_node~nodes()=letnb_proofs=matchnb_proofswithNone->List.lengthnodes|Somen->ninletcircuit_map,x_map=Circuit_Builder.basenb_proofscircuit_sizeinletpp_prover,pp_verifier=MP.setup~zero_knowledge:falsecircuit_map~srsinletoc=open_outDP.pp_fileinletb=DP.get_distributed_pppp_proverinoutput_bytesocb;close_outoc;letinputs=Kzg.SMap.map(List.map(funwitness->MP.{witness;input_commitments=[]}))x_mapinletverifier_inputs=MP.to_verifier_inputspp_proverinputsinlett1=Unix.gettimeofday()inletproof=Runner.run~self_node~nodesDP.(distributed_prover_main~inputspp_prover)inlett2=Unix.gettimeofday()inPrintf.printf"Prover time: %4.2f\n"(t2-.t1);assert(MP.verifypp_verifier~inputs:verifier_inputsproof)end