Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file constants_repr.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* Copyright (c) 2020-2021 Nomadic Labs <contact@nomadic-labs.com> *)(* Copyright (c) 2021-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. *)(* *)(*****************************************************************************)letmainnet_id=Chain_id.of_b58check_exn"NetXdQprcVkpaWU"(* The fitness version number was:
- "\000" until and including proto 004
- "\001" until and including proto 010
*)letfitness_version_number="\002"letproof_of_work_nonce_size=8letnonce_length=32letmax_anon_ops_per_block=132letmax_proposals_per_delegate=20letmax_operation_data_length=32*1024(* 32kB *)letmax_micheline_node_count=50_000letmax_micheline_bytes_limit=50_000letmax_allowed_global_constant_depth=10_000(* In previous versions of the protocol, this
[michelson_maximum_type_size] limit was set to 1000 but
the contract input types (pair <parameter_type> <storage_type>)
were not checked. Both components, <parameter_type> and
<storage_type> where however checked hence it was possible to build
types as big as 2001. *)letmichelson_maximum_type_size=2001(* This constant declares the number of subcaches used by the cache
mechanism (see {Context.Cache}). *)letcache_layout_size=3(* The {!Sc_rollups.wrapped_proof_encoding} uses unbounded sub-encodings.
To avoid attacks through too large proofs and long decoding times on public
nodes, we put another layer of security by restricting the maximum_size
to [30Kb].
Even if the operation size limit is currently [32Kb] (see
{!Constants_repr.max_operation_data_length}) the node's mempool can still
be spammed with larger proofs before detecting that the operations are
indeed larger than the limit.
By design, the proofs should be created and verified for a single tick
which should limit the number of read/writes in the Merkle tree, and thefore,
limit the total size of a proof. Thus, [30Kb] can be lowered once we
have empirically observed that a valid proof can not be that large.
Note that an encoded proof that is [30Kb] might still be not included
in a valid L1 operation. The refutation operation also contains other
information such as an inbox proof. We only put here an upper bound
for the size.
*)letsc_max_wrapped_proof_binary_size=30_000(* A limit on the size of the binary encoding of sc rollup messages. This limit
depends on the assumed overhead of the proof and metadata in a manager
operation justifying the existence of some chunk of data in the rollup state.
The value of this constant reflects the global constant of 4KB in the WASM
PVM specification chosen for the limit of chunks that are embedded in proofs.
*)letsc_rollup_message_size_limit=4_096(** A limit on the number of messages per inbox level.
Benchmarks have shown that proving the inclusion of the element at
index 0 in a skip list of [1_000_000] elements is ~=6Kb large.
*)letsc_rollup_max_number_of_messages_per_level=Z.of_int1_000_000typefixed=unitletfixed_encoding=letopenData_encodinginconv(fun()->((proof_of_work_nonce_size,nonce_length,max_anon_ops_per_block,max_operation_data_length,max_proposals_per_delegate,max_micheline_node_count,max_micheline_bytes_limit,max_allowed_global_constant_depth,cache_layout_size,michelson_maximum_type_size),(sc_max_wrapped_proof_binary_size,sc_rollup_message_size_limit,sc_rollup_max_number_of_messages_per_level)))(fun((_proof_of_work_nonce_size,_nonce_length,_max_anon_ops_per_block,_max_operation_data_length,_max_proposals_per_delegate,_max_micheline_node_count,_max_micheline_bytes_limit,_max_allowed_global_constant_depth,_cache_layout_size,_michelson_maximum_type_size),(_sc_max_wrapped_proof_binary_size,_sc_rollup_message_size_limit,_sc_rollup_number_of_messages_per_level))->())(merge_objs(obj10(req"proof_of_work_nonce_size"uint8)(req"nonce_length"uint8)(req"max_anon_ops_per_block"uint8)(req"max_operation_data_length"int31)(req"max_proposals_per_delegate"uint8)(req"max_micheline_node_count"int31)(req"max_micheline_bytes_limit"int31)(req"max_allowed_global_constants_depth"int31)(req"cache_layout_size"uint8)(req"michelson_maximum_type_size"uint16))(obj3(req"smart_rollup_max_wrapped_proof_binary_size"int31)(req"smart_rollup_message_size_limit"int31)(req"smart_rollup_max_number_of_messages_per_level"n)))letfixed=()typet={fixed:fixed;parametric:Constants_parametric_repr.t}letall_of_parametricparametric={fixed;parametric}letencoding=letopenData_encodinginconv(fun{fixed;parametric}->(fixed,parametric))(fun(fixed,parametric)->{fixed;parametric})(merge_objsfixed_encodingConstants_parametric_repr.encoding)typeerror+=Invalid_protocol_constantsofstring(* `Permanent *)let()=register_error_kind`Permanent~id:"constants.invalid_protocol_constants"~title:"Invalid protocol constants"~description:"The provided protocol constants are not coherent."~pp:(funppfreason->Format.fprintfppf"Invalid protocol constants: %s"reason)Data_encoding.(obj1(req"reason"@@stringPlain))(functionInvalid_protocol_constantsreason->Somereason|_->None)(funreason->Invalid_protocol_constantsreason)letcheck_constantsconstants=letopenConstants_parametric_reprinerror_unlessPeriod_repr.(constants.minimal_block_delay>zero)(Invalid_protocol_constants"The minimal block delay must be greater than zero")>>?fun()->error_unlessPeriod_repr.(constants.delay_increment_per_round>zero)(Invalid_protocol_constants"The delay increment per round must be greater than zero")>>?fun()->error_unlessCompare.Int.(constants.consensus_committee_size>0)(Invalid_protocol_constants"The consensus committee size must be strictly greater than 0.")>>?fun()->error_unlessCompare.Int.(constants.consensus_threshold>=0&&constants.consensus_threshold<=constants.consensus_committee_size)(Invalid_protocol_constants"The consensus threshold must be greater than or equal to 0 and less \
than or equal to the consensus commitee size.")>>?fun()->error_unless(letRatio_repr.{numerator;denominator}=constants.minimal_participation_ratioinCompare.Int.(numerator>=0&&denominator>0))(Invalid_protocol_constants"The minimal participation ratio must be a non-negative valid ratio.")>>?fun()->error_unlessCompare.Int.(constants.minimal_participation_ratio.numerator<=constants.minimal_participation_ratio.denominator)(Invalid_protocol_constants"The minimal participation ratio must be less than or equal to 100%.")>>?fun()->error_unlessCompare.Int.(constants.max_slashing_period>0)(Invalid_protocol_constants"The unfreeze delay must be strictly greater than 0.")>>?fun()->(* The [frozen_deposits_percentage] should be a percentage *)error_unlessCompare.Int.(constants.frozen_deposits_percentage>0&&constants.frozen_deposits_percentage<=100)(Invalid_protocol_constants"The frozen percentage ratio must be strictly greater than 0 and less \
or equal than 100.")>>?fun()->error_unlessTez_repr.(constants.double_baking_punishment>=zero)(Invalid_protocol_constants"The double baking punishment must be non-negative.")>>?fun()->error_unless(letRatio_repr.{numerator;denominator}=constants.ratio_of_frozen_deposits_slashed_per_double_endorsementinCompare.Int.(numerator>=0&&denominator>0))(Invalid_protocol_constants"The ratio of frozen deposits ratio slashed per double endorsement must \
be a non-negative valid ratio.")>>?fun()->error_unless(letsnapshot_frequence=Int32.divconstants.blocks_per_cycleconstants.blocks_per_stake_snapshotinCompare.Int32.(snapshot_frequence>Int32.zero&&snapshot_frequence<Int32.of_int(1lsl16)))(Invalid_protocol_constants"The ratio blocks_per_cycle per blocks_per_stake_snapshot should be \
between 1 and 65535")>>?fun()->error_unlessCompare.Int32.(constants.nonce_revelation_threshold>Int32.zero&&constants.nonce_revelation_threshold<constants.blocks_per_cycle)(Invalid_protocol_constants"The nonce revelation threshold must be strictly smaller than \
blocks_per_cycle and strictly positive.")>>?fun()->error_unlessCompare.Int64.(letthreshold=Int64.of_int32constants.nonce_revelation_thresholdinletblock=Period_repr.to_secondsconstants.minimal_block_delayinletips=(* We reduce the ips for short blocks_per_commitment so that we have
low difficulty during tests *)ifCompare.Int32.(constants.blocks_per_commitment>32l)thenInt64.of_int200_000elseInt64.oneinletfactor=Int64.of_int5inletdifficulty=Int64.(mul(mulipsfactor)(multhresholdblock))inconstants.vdf_difficulty>difficulty)(Invalid_protocol_constants"The VDF difficulty must be strictly greater than the product of the \
nonce_revelation_threshold, the minimial_block_delay, a benchmark of \
modulo squaring in class groups and a security threshold.")>>?fun()->error_unlessCompare.Int.(constants.sc_rollup.origination_size>=0)(Invalid_protocol_constants"The smart rollup origination size must be non-negative.")>>?fun()->error_unlessCompare.Int.(constants.sc_rollup.challenge_window_in_blocks>=0)(Invalid_protocol_constants"The smart rollup challenge window in blocks must be non-negative.")>>?fun()->error_unlessTez_repr.(constants.sc_rollup.stake_amount>=zero)(Invalid_protocol_constants"The smart rollup max stake amount must be non-negative.")>>?fun()->error_unlessCompare.Int.(constants.sc_rollup.commitment_period_in_blocks>0)(Invalid_protocol_constants"The smart rollup commitment period in blocks must be strictly greater \
than 0.")>>?fun()->error_unless(letsc_rollup_max_lookahead_in_blocks=constants.sc_rollup.max_lookahead_in_blocksinCompare.Int32.(sc_rollup_max_lookahead_in_blocks>Int32.of_intconstants.sc_rollup.commitment_period_in_blocks&&(* Check that [smart_rollup_challenge_window_in_blocks <
smart_rollup_max_lookahead_in_blocks]. Otherwise committers would be
forced to commit at an artificially slow rate, affecting the
throughput of the rollup. *)sc_rollup_max_lookahead_in_blocks>Int32.of_intconstants.sc_rollup.challenge_window_in_blocks))(Invalid_protocol_constants"The smart rollup max lookahead in blocks must be greater than \
[smart_rollup_commitment_period_in_blocks] and \
[smart_rollup_challenge_window_in_blocks].")>>?fun()->error_unlessCompare.Int.(constants.dal.number_of_slots>0&&constants.dal.number_of_slots<=256)(Invalid_protocol_constants"The number of data availability slot must be between 1 and 256")>>?fun()->error_unlessCompare.Int.(constants.sc_rollup.max_number_of_stored_cemented_commitments>0)(Invalid_protocol_constants"The number of maximum stored cemented commitments must be strictly \
positive")>>?fun()->Result.return_unitmoduleGenerated=structtypet={consensus_threshold:int;baking_reward_fixed_portion:Tez_repr.t;baking_reward_bonus_per_slot:Tez_repr.t;endorsing_reward_per_slot:Tez_repr.t;liquidity_baking_subsidy:Tez_repr.t;}letgenerate~consensus_committee_size~blocks_per_minute=letconsensus_threshold=(consensus_committee_size*2/3)+1in(* As in previous protocols, we set the maximum total rewards per minute to
be 80 tez. *)letrewards_per_minute=Tez_repr.(mul_exnone80)inletrewards_per_block=Ratio_repr.(Tez_repr.(div_exn(mul_exnrewards_per_minuteblocks_per_minute.denominator)blocks_per_minute.numerator))inletrewards_half=Tez_repr.(div_exnrewards_per_block2)inletrewards_quarter=Tez_repr.(div_exnrewards_per_block4)inletbonus_committee_size=consensus_committee_size-consensus_thresholdin{consensus_threshold;baking_reward_fixed_portion=(ifCompare.Int.(bonus_committee_size<=0)then(* a fortiori, consensus_committee_size < 4 *)rewards_halfelserewards_quarter);baking_reward_bonus_per_slot=(ifCompare.Int.(bonus_committee_size<=0)thenTez_repr.zeroelseTez_repr.div_exnrewards_quarterbonus_committee_size);endorsing_reward_per_slot=Tez_repr.div_exnrewards_halfconsensus_committee_size;liquidity_baking_subsidy=Tez_repr.div_exnrewards_per_block16;}endletcache_layoutp=Constants_parametric_repr.[p.cache_script_size;p.cache_stake_distribution_cycles;p.cache_sampler_state_cycles;]