123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)moduleAddress=structletprefix="epx1"letencoded_size=37letdecoded_prefix="\001\023\224\125"moduleH=Blake2B.Make(Base58)(structletname="Zk_rollup_hash"lettitle="A zk rollup address"letb58check_prefix=decoded_prefixletsize=Some20end)includeHlet()=Base58.check_encoded_prefixb58check_encodingprefixencoded_sizeincludePath_encoding.Make_hex(H)typeerror+=(* `Permanent *)Error_zk_rollup_address_generationlet()=letopenData_encodinginletmsg="Error while generating rollup address"inregister_error_kind`Permanent~id:"rollup.error_zk_rollup_address_generation"~title:msg~pp:(funppf()->Format.fprintfppf"%s"msg)~description:msgunit(functionError_zk_rollup_address_generation->Some()|_->None)(fun()->Error_zk_rollup_address_generation)letfrom_noncenonce=letopenResult_syntaxinData_encoding.Binary.to_bytes_optOrigination_nonce.encodingnonce|>function|None->tzfailError_zk_rollup_address_generation|Somenonce->return@@hash_bytes[nonce]letof_b58data=functionH.Datah->Someh|_->Noneendtypet=Address.tletto_scalarx=Zk_rollup_scalar.of_bits(Data_encoding.Binary.to_string_exnAddress.encodingx)typepending_list=|Emptyof{next_index:int64}|Pendingof{next_index:int64;length:int}letpending_list_encoding:pending_listData_encoding.t=letopenData_encodinginletempty_tag,pending_tag=(0,1)inletempty_encoding=obj1(req"next_index"Compact.(make~tag_size:`Uint8int64))inletpending_encoding=obj2(req"next_index"Compact.(make~tag_size:`Uint8int64))(req"length"uint16)inmatching(function|Empty{next_index}->matchedempty_tagempty_encodingnext_index|Pending{next_index;length}->matchedpending_tagpending_encoding(next_index,length))[case~title:"Empty"(Tagempty_tag)empty_encoding(functionEmpty{next_index}->Somenext_index|_->None)(funnext_index->Empty{next_index});case~title:"Pending"(Tagpending_tag)pending_encoding(function|Pending{next_index;length}->Some(next_index,length)|_->None)(fun(next_index,length)->Pending{next_index;length});]moduleIndex=structtypenonrect=tletpath_length=1letto_pathcl=letraw_key=Data_encoding.Binary.to_bytes_exnAddress.encodingcinlet(`Hexkey)=Hex.of_bytesraw_keyinkey::lletof_path=function|[key]->Option.bind(Hex.to_bytes(`Hexkey))(Data_encoding.Binary.of_bytes_optAddress.encoding)|_->Noneletrpc_arg=Address.rpc_argletencoding=Address.encodingletcompare=Address.compareendletin_memory_size(_:t)=letopenCache_memory_helpersinh1w+!string_size_genAddress.sizemoduleInternal_for_tests=structletoriginated_zk_rollupnonce=letdata=Data_encoding.Binary.to_bytes_exnOrigination_nonce.encodingnonceinAddress.hash_bytes[data]end