123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127(*****************************************************************************)(* *)(* Open Source 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. *)(* *)(*****************************************************************************)moduleSMap=Map.Make(String)typestatic={public_parameters:Plonk.public_parameters;state_length:int;circuits_info:[`Public|`Private|`Fee]SMap.t;nb_ops:int;}typedynamic={state:Zk_rollup_state_repr.t;paid_l2_operations_storage_space:Z.t;used_l2_operations_storage_space:Z.t;}typet={static:static;dynamic:dynamic}letcircuits_info_encoding:[`Public|`Private|`Fee]SMap.tData_encoding.t=letopenData_encodinginletvariant_encoding=letpublic_tag,public_encoding=(0,obj1@@req"public"unit)inletprivate_tag,private_encoding=(1,obj1@@req"private"unit)inletfee_tag,fee_encoding=(2,obj1@@req"fee"unit)inmatching(function|`Public->matchedpublic_tagpublic_encoding()|`Private->matchedprivate_tagprivate_encoding()|`Fee->matchedfee_tagfee_encoding())[case~title:"Public"(Tagpublic_tag)public_encoding(function`Public->Some()|_->None)(fun()->`Public);case~title:"Private"(Tagprivate_tag)private_encoding(function`Private->Some()|_->None)(fun()->`Private);case~title:"Fee"(Tagfee_tag)fee_encoding(function`Fee->Some()|_->None)(fun()->`Fee);]inconv_with_guard(funm->List.of_seq@@SMap.to_seqm)(funl->letm=SMap.of_seq@@List.to_seqlinif(* Check that the list has no duplicated keys *)Compare.List_length_with.(l<>SMap.cardinalm)thenError"Zk_rollup_origination: circuits_info has duplicated keys"elseOkm)(list(tup2(stringPlain)variant_encoding))letencoding=letopenData_encodinginletstatic_encoding=conv(fun{public_parameters;state_length;circuits_info;nb_ops}->(public_parameters,state_length,circuits_info,nb_ops))(fun(public_parameters,state_length,circuits_info,nb_ops)->{public_parameters;state_length;circuits_info;nb_ops})(obj4(req"public_parameters"Plonk.public_parameters_encoding)(req"state_length"int31)(req"circuits_info"circuits_info_encoding)(req"nb_ops"int31))inletdynamic_encoding=conv(fun{state;paid_l2_operations_storage_space;used_l2_operations_storage_space;}->(state,paid_l2_operations_storage_space,used_l2_operations_storage_space))(fun(state,paid_l2_operations_storage_space,used_l2_operations_storage_space)->{state;paid_l2_operations_storage_space;used_l2_operations_storage_space;})(obj3(req"state"Zk_rollup_state_repr.encoding)(req"paid_l2_operations_storage_space"n)(req"used_l2_operations_storage_space"n))inconv(fun{static;dynamic}->(static,dynamic))(fun(static,dynamic)->{static;dynamic})(obj2(req"static"static_encoding)(req"dynamic"dynamic_encoding))