123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2021 Nomadic Labs <contact@nomadic-labs.com> *)(* Copyright (c) 2022 Trili Tech, <contact@trili.tech> *)(* Copyright (c) 2022 Marigold, <contact@marigold.dev> *)(* *)(* 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="sr1"letencoded_size=36letdecoded_prefix="\006\124\117"(* "sr1(36)" decoded from base 58. *)moduleH=Blake2B.Make(Base58)(structletname="Smart_rollup_hash"lettitle="A smart rollup address"letb58check_prefix=decoded_prefixletsize=Some20end)includeHlet()=Base58.check_encoded_prefixb58check_encodingprefixencoded_sizeincludePath_encoding.Make_hex(H)letof_b58data=functionH.Datah->Someh|_->NoneendmoduleInternal_for_tests=structletoriginated_sc_rollupnonce=letdata=Data_encoding.Binary.to_bytes_exnOrigination_nonce.encodingnonceinAddress.hash_bytes[data]end(* 32 *)letstate_hash_prefix="\017\165\235\240"(* srs1(54) *)moduleState_hash=structletprefix="srs1"letencoded_size=54moduleH=Blake2B.Make(Base58)(structletname="Smart_rollup_state_hash"lettitle="The hash of the VM state of a smart rollup"letb58check_prefix=state_hash_prefix(* defaults to 32 *)letsize=Noneend)includeHlet()=Base58.check_encoded_prefixb58check_encodingprefixencoded_sizeincludePath_encoding.Make_hex(H)letcontext_hash_to_state_hash=(* Both State_hash and Context_hash's hashes are supposed to have the
same size. This top-level check enforces this invariant, in which case,
no exception could be thrown by [of_bytes_exn] below *)let()=assert(Compare.Int.equalsizeContext_hash.size)infunh->of_bytes_exn@@Context_hash.to_bytesh(* Hackish way to disable hash_bytes and hash_string to force people to use
context_hash_to_state_hash (without changing content of HASH.S) *)typeunreachable=|lethash_bytes=function(_:unreachable)->.lethash_string=function(_:unreachable)->.endtypet=Address.tletdescription="A smart rollup is identified by a base58 address starting with "^Address.prefixletpp=Address.ppletencoding=letopenData_encodingindef"smart_rollup_address"~title:"A smart rollup address"~descriptionAddress.encodingletrpc_arg=RPC_arg.likeAddress.rpc_arg~descr:"A smart rollup address.""smart_rollup_address"letin_memory_size(_:t)=letopenCache_memory_helpersinh1w+!string_size_genAddress.sizemoduleStaker=Signature.Public_key_hashmoduleIndex=structtypet=Address.tletpath_length=1letto_pathcl=letraw_key=Data_encoding.Binary.to_bytes_exnencodingcinlet(`Hexkey)=Hex.of_bytesraw_keyinkey::lletof_path=function|[key]->Option.bind(Hex.to_bytes(`Hexkey))(Data_encoding.Binary.of_bytes_optencoding)|_->Noneletrpc_arg=rpc_argletencoding=encodingletcompare=Address.compareendmoduleNumber_of_ticks=structincludeBounded.Int64(structletmin_value=0Lletmax_value=Int64.max_intend)letzero=matchof_value0Lwith|Somezero->zero|None->assertfalse(* unreachable case, since [min_int = 0l] *)end