123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2021 Nomadic Labs <contact@nomadic-labs.com> *)(* Copyright (c) 2022 Trili Tech, <contact@trili.tech> *)(* *)(* 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. *)(* *)(*****************************************************************************)modulePVM=structtypeboot_sector=stringmoduletypeS=sigvalname:stringvalparse_boot_sector:string->boot_sectoroptionvalpp_boot_sector:Format.formatter->boot_sector->unitincludeSc_rollup_PVM_sig.Sendtypet=(moduleS)endmoduleKind=struct(*
Each time we add a data constructor to [t], we also need:
- to extend [Sc_rollups.all] with this new constructor ;
- to update [Sc_rollups.of_name] and [encoding] ;
- to update [Sc_rollups.wrapped_proof] and [wrapped_proof_encoding].
*)typet=Example_arith|Wasm_2_0_0letencoding=Data_encoding.string_enum[("arith_pvm_kind",Example_arith);("wasm_2_0_0_pvm_kind",Wasm_2_0_0)]letequalxy=match(x,y)with|Example_arith,Example_arith->true|Wasm_2_0_0,Wasm_2_0_0->true|_->falseletall=[Example_arith;Wasm_2_0_0]letof_name=function|"arith"->SomeExample_arith|"wasm_2_0_0"->SomeWasm_2_0_0|_->Noneletexample_arith_pvm=(moduleSc_rollup_arith.Protocol_implementation:PVM.S)letwasm_2_0_0_pvm=(moduleSc_rollup_wasm.V2_0_0.Protocol_implementation:PVM.S)letpvm_of=function|Example_arith->example_arith_pvm|Wasm_2_0_0->wasm_2_0_0_pvmletof_pvm(moduleM:PVM.S)=matchof_nameM.namewith|Somek->k|None->failwith(Format.sprintf"The module named %s is not in Sc_rollups.all."M.name)letpvm_of_name~name=Option.mappvm_of(of_namename)letall_names=List.map(funk->let(moduleM:PVM.S)=pvm_ofkinM.name)allletname_ofk=let(moduleM)=pvm_ofkinM.nameletppfmtk=Format.fprintffmt"%s"(name_ofk)endmoduletypePVM_with_proof=sigincludePVM.Svalproof:proofendtypewrapped_proof=|Unencodableof(modulePVM_with_proof)|Arith_pvm_with_proofof(modulePVM_with_proofwithtypeproof=Sc_rollup_arith.Protocol_implementation.proof)|Wasm_2_0_0_pvm_with_proofof(modulePVM_with_proofwithtypeproof=Sc_rollup_wasm.V2_0_0.Protocol_implementation.proof)letwrapped_proof_modulep=matchpwith|Unencodablep->p|Arith_pvm_with_proof(moduleP)->(moduleP)|Wasm_2_0_0_pvm_with_proof(moduleP)->(moduleP)letwrapped_proof_kind_exn:wrapped_proof->Kind.t=function|Unencodable_->raise(Invalid_argument"wrapped_proof_kind_exn: Unencodable")|Arith_pvm_with_proof_->Kind.Example_arith|Wasm_2_0_0_pvm_with_proof_->Kind.Wasm_2_0_0(* TODO: #3704
Change to an encoding that produces bytes
*)letwrapped_proof_encoding=letopenData_encodinginletencoding=union~tag_size:`Uint8[case~title:"Arithmetic PVM with proof"(Tag0)(obj2(req"kind"@@constant"arith_pvm_kind")(req"proof"Sc_rollup_arith.Protocol_implementation.proof_encoding))(function|Arith_pvm_with_proof(moduleP)->Some((),P.proof)|_->None)(fun((),proof)->Arith_pvm_with_proof(modulestructincludeSc_rollup_arith.Protocol_implementationletproof=proofend));case~title:"Wasm 2.0.0 PVM with proof"(Tag1)(obj2(req"kind"@@constant"wasm_2_0_0_pvm_kind")(req"proof"Sc_rollup_wasm.V2_0_0.Protocol_implementation.proof_encoding))(function|Wasm_2_0_0_pvm_with_proof(moduleP)->Some((),P.proof)|_->None)(fun((),proof)->Wasm_2_0_0_pvm_with_proof(modulestructincludeSc_rollup_wasm.V2_0_0.Protocol_implementationletproof=proofend));(* The later case is provided solely in order to provide error
messages in case someone tries to encode an [Unencodable]
proof. *)case~title:"Unencodable"(Tag255)empty(function|Unencodable(moduleP)->raise(Invalid_argumentFormat.(sprintf"cannot encode Unencodable (PVM %s)"P.name))|_->None)(fun()->raise(Invalid_argument"cannot decode Unencodable"));]incheck_sizeConstants_repr.sc_max_wrapped_proof_binary_sizeencodingletwrap_proofpvm_with_proof=let(moduleP:PVM_with_proof)=pvm_with_proofinmatchKind.of_nameP.namewith|None->Some(Unencodablepvm_with_proof)|SomeKind.Example_arith->Option.map(funarith_proof->letmoduleP_arith=structincludeSc_rollup_arith.Protocol_implementationletproof=arith_proofendinArith_pvm_with_proof(moduleP_arith))(Option.bind(Data_encoding.Binary.to_bytes_optP.proof_encodingP.proof)(funbytes->Data_encoding.Binary.of_bytes_optSc_rollup_arith.Protocol_implementation.proof_encodingbytes))|SomeKind.Wasm_2_0_0->Option.map(funwasm_proof->letmoduleP_wasm2_0_0=structincludeSc_rollup_wasm.V2_0_0.Protocol_implementationletproof=wasm_proofendinWasm_2_0_0_pvm_with_proof(moduleP_wasm2_0_0))(Option.bind(Data_encoding.Binary.to_bytes_optP.proof_encodingP.proof)(funbytes->Data_encoding.Binary.of_bytes_optSc_rollup_wasm.V2_0_0.Protocol_implementation.proof_encodingbytes))