1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495(*****************************************************************************)(* *)(* 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_reprmoduleS_syntax=structletlog2x=S.safe_int(1+S.numbitsx)let(+)=S.addlet(*)=S.mulendmoduleConstants=struct(* TODO: https://gitlab.com/tezos/tezos/-/issues/2648
Fill in real benchmarked values.
Need to create benchmark and fill in values.
*)letcost_add_message_base=S.safe_int430letcost_add_message_per_byte=S.safe_int15letcost_add_inbox_per_level=S.safe_int15letcost_update_num_and_size_of_messages=S.safe_int15(* 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_int50end(* We assume that the gas cost of adding messages [[ m_1; ... ; m_n]] at level
[l] is linear in the sum of lengths of the messages, and it is logarithmic
in [l]. That is, [cost_add_serialized_messages([m_1; .. ; m_n], l)] =
`n * cost_add_message_base +
cost_add_message_per_bytes * \sum_{i=1}^n length(m_i) +
cost_add_inbox_per_level * l`.
*)letcost_add_serialized_messages~num_messages~total_messages_sizel=letopenS_syntaxinletlog_level=ifInt32.equallInt32.zerothenSaturation_repr.safe_int0elselog2@@S.safe_int(Int32.to_intl)inletlevel_cost=log_level*Constants.cost_add_inbox_per_levelin(S.safe_intnum_messages*Constants.cost_add_message_base)+level_cost+(Constants.cost_add_message_per_byte*S.safe_inttotal_messages_size)(* 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_messageSc_rollup_inbox_message_repr.{payload;sender=_;source=_}=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)(** We assume that the cost of deserializing an expression of [bytes_len] is
greater by a notch to the real cost here.
TODO: checks if the estimated cost is close to the more precise cost: To
check the real cost we could traverse the list of expression in the
deserialized output message. *)letcost_deserialize_outbox_message~bytes_len=Script_repr.deserialization_cost_estimated_from_bytesbytes_len