123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140(*****************************************************************************)(* *)(* Open Source License *)(* 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. *)(* *)(*****************************************************************************)moduleS=Saturation_reprmoduleConstants=struct(* equal to Michelson_v1_gas.Cost_of.Unparsing.contract_optimized *)letcost_decoding_contract_optimized=S.safe_int70(* equal to Michelson_v1_gas.Cost_of.Unparsing.key_hash_optimized *)letcost_decoding_key_hash_optimized=S.safe_int70(* Set to the cost of encoding a pkh defined in {!Michelson_v1_gas} divided
by the number of characters of a pkh, with the result rounded up, i.e.
70/20 + 1.
To be updated when benchmarking is completed. *)letcost_encode_string_per_byte=S.safe_int4(* Cost of serializing a state hash. *)letcost_serialize_state_hash=letlen=S.safe_intState_hash.sizeinS.Syntax.(cost_encode_string_per_byte*len)(* Cost of serializing a commitment hash. *)letcost_serialize_commitment_hash=letlen=S.safe_intSc_rollup_commitment_repr.Hash.sizeinS.Syntax.(cost_encode_string_per_byte*len)(* Cost of serializing a commitment. The cost of serializing the level and
number of ticks (both int32) is negligible. *)letcost_serialize_commitment=S.Syntax.(cost_serialize_state_hash+cost_serialize_commitment_hash)(* Cost of serializing an operation hash. *)letcost_serialize_operation_hash=letlen=S.safe_intOperation_hash.sizeinS.Syntax.(cost_encode_string_per_byte*len)(* Cost of serializing a nonce. The cost of serializing the index (an int32)
is negligible. *)letcost_serialize_nonce=cost_serialize_operation_hashend(* Reusing model from {!Ticket_costs.has_tickets_of_ty_cost}. *)letis_valid_parameters_ty_cost~ty_size=letfixed_cost=S.safe_int10inletcoeff=S.safe_int6inS.addfixed_cost(S.mulcoeffty_size)letcost_serialize_internal_inbox_message(internal_inbox_message:Sc_rollup_inbox_message_repr.internal_inbox_message)=matchinternal_inbox_messagewith|Transfer{payload;sender=_;source=_;destination=_}->letlexpr=Script_repr.lazy_exprpayloadinletexpr_cost=Script_repr.force_bytes_costlexprinS.Syntax.(expr_cost+Constants.cost_decoding_contract_optimized+Constants.cost_decoding_key_hash_optimized)|Start_of_level->Saturation_repr.zero|End_of_level->Saturation_repr.zero|Info_per_level_->Saturation_repr.zero(* Derived from benchmark in
[Sc_rollup_benchmarks.Sc_rollup_deserialize_output_proof_benchmark] and model
[model_Sc_rollup_deserialize_output_proof_benchmark]. *)(* fun size -> (7086.16259141 + (6.04996016914 * size)) *)letcost_deserialize_output_proof~bytes_len=letopenS.Syntaxinletv0=S.safe_intbytes_leninS.safe_int7100+((v0lsl2)+(v0lsl1))letcost_serialize_external_inbox_message~bytes_len=letlen=S.safe_intbytes_leninS.Syntax.(Constants.cost_encode_string_per_byte*len)(* Equal to Michelson_v1_gas.Cost_of.Interpreter.blake2b. *)letcost_hash_bytes~bytes_len=letopenS.Syntaxinletv0=S.safe_intbytes_leninS.safe_int430+v0+(v0lsr3)letcost_comparea_size_in_bytesb_size_in_bytes=letopenS.Syntaxinletsize_in_bytes=Compare.Int.mina_size_in_bytesb_size_in_bytesinletv0=S.safe_intsize_in_bytesinS.safe_int35+((v0lsr6)+(v0lsr7))letcost_search_in_tick_listlentick_size=letopenS.SyntaxinS.safe_intlen*cost_comparetick_sizetick_sizeletcost_check_dissection~number_of_states~tick_size~hash_size=letopenS.Syntaxincost_search_in_tick_listnumber_of_statestick_size+(S.safe_int2*cost_comparehash_sizehash_size)letcost_add_message~current_index~msg_len=letopenS.Syntaxinlethash_cell_cost=Skip_list_costs.model_hash_cell_computed_backpointers_count~index:current_indexinlethash_content_cost=cost_hash_bytes~bytes_len:msg_leninletnext_cell_cost=Skip_list_costs.model_next~length:(Z.succcurrent_index)inhash_cell_cost+hash_content_cost+next_cell_cost(* Derived from benchmark in
[Sc_rollup_benchmarks.Sc_rollup_verify_output_proof_benchmark] and model
[model_Sc_rollup_verify_output_proof_benchmark] with estimated parameters:
[fun size -> (103413.141163 + (6.85566158429 * size))] *)letcost_verify_output_proof~bytes_len=letopenS.Syntaxinletsize=S.safe_intbytes_leninletv0=sizeinS.safe_int103450+(v0lsl2)+(v0lsl1)+v0