iota_protocol_config/
lib.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use std::{
6    cell::RefCell,
7    cmp::min,
8    sync::atomic::{AtomicBool, Ordering},
9};
10
11use clap::*;
12use iota_protocol_config_macros::{
13    ProtocolConfigAccessors, ProtocolConfigFeatureFlagsGetters, ProtocolConfigOverride,
14};
15use move_vm_config::verifier::VerifierConfig;
16use serde::{Deserialize, Serialize};
17use serde_with::skip_serializing_none;
18use tracing::{info, warn};
19
20/// The minimum and maximum protocol versions supported by this build.
21const MIN_PROTOCOL_VERSION: u64 = 1;
22pub const MAX_PROTOCOL_VERSION: u64 = 15;
23
24// Record history of protocol version allocations here:
25//
26// Version 1:  Original version.
27// Version 2:  Don't redistribute slashed staking rewards, fix computation of
28//             SystemEpochInfoEventV1.
29// Version 3:  Set the `relocate_event_module` to be true so that the module
30//             that is associated as the "sending module" for an event is
31//             relocated by linkage.
32//             Add `Clock` based unlock to `Timelock` objects.
33// Version 4:  Introduce the `max_type_to_layout_nodes` config that sets the
34//             maximal nodes which are allowed when converting to a type layout.
35// Version 5:  Introduce fixed protocol-defined base fee, IotaSystemStateV2 and
36//             SystemEpochInfoEventV2.
37//             Disallow adding new modules in `deps-only` packages.
38//             Improve gas/wall time efficiency of some Move stdlib vector
39//             functions.
40//             Add new gas model version to update charging of functions.
41//             Enable proper conversion of certain type argument errors in the
42//             execution layer.
43// Version 6:  Bound size of values created in the adapter.
44// Version 7:  Improve handling of stake withdrawal from candidate validators.
45// Version 8:  Variants as type nodes.
46//             Enable smart ancestor selection for testnet.
47//             Enable probing for accepted rounds in round prober for testnet.
48//             Switch to distributed vote scoring in consensus in testnet.
49//             Enable zstd compression for consensus tonic network in testnet.
50//             Enable consensus garbage collection for testnet
51//             Enable the new consensus commit rule for testnet.
52//             Enable min_free_execution_slot for the shared object congestion
53//             tracker in devnet.
54// Version 9:  Disable smart ancestor selection for the testnet.
55//             Enable zstd compression for consensus tonic network in mainnet.
56//             Enable passkey auth in multisig for devnet.
57//             Remove the iota-bridge from the framework.
58// Version 10: Enable min_free_execution_slot for the shared object congestion
59//             tracker in all networks.
60//             Increase the committee size to 80 on all networks.
61//             Enable round prober in consensus for mainnet.
62//             Enable probing for accepted rounds in round prober for mainnet.
63//             Switch to distributed vote scoring in consensus for mainnet.
64//             Enable the new consensus commit rule for mainnet.
65//             Enable consensus garbage collection for mainnet with GC depth set
66//             to 60 rounds.
67//             Enable batching in synchronizer for testnet
68//             Enable the gas price feedback mechanism in devnet.
69//             Enable Identifier input validation.
70//             Removes unnecessary child object mutations
71//             Add additional signature checks
72//             Add additional linkage checks
73// Version 11: Framework fix regarding candidate validator commission rate.
74// Version 12: Enable the gas price feedback mechanism in all networks.
75//             Enable the normalization of PTB arguments.
76// Version 13: Introduce logic to allow the committee to be selected from a set
77//             of eligible active validators.
78//             Enable processing and tracking AuthorityCapabilitiesV1 from
79//             non-committee validators in the devnet.
80// Version 14: Switches the consensus protocol to Starfish in devnet.
81//             Enable median-based commit timestamp calculation in consensus,
82//             and enforce checkpoint timestamp monotonicity for testnet.
83//             Enable batched block sync for mainnet.
84//             Enable selecting committee only from active validators that
85//             support the next epoch's version and issued valid
86//             AuthorityCapabilities notification in testnet.
87// Version 15: Enable shared object transaction bursts of 10 times average load
88//             on devnet.
89#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
90pub struct ProtocolVersion(u64);
91
92impl ProtocolVersion {
93    // The minimum and maximum protocol version supported by this binary.
94    // Counterintuitively, this constant may change over time as support for old
95    // protocol versions is removed from the source. This ensures that when a
96    // new network (such as a testnet) is created, its genesis committee will
97    // use a protocol version that is actually supported by the binary.
98    pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
99
100    pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
101
102    #[cfg(not(msim))]
103    const MAX_ALLOWED: Self = Self::MAX;
104
105    // We create one additional "fake" version in simulator builds so that we can
106    // test upgrades.
107    #[cfg(msim)]
108    pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
109
110    pub fn new(v: u64) -> Self {
111        Self(v)
112    }
113
114    pub const fn as_u64(&self) -> u64 {
115        self.0
116    }
117
118    // For serde deserialization - we don't define a Default impl because there
119    // isn't a single universally appropriate default value.
120    pub fn max() -> Self {
121        Self::MAX
122    }
123}
124
125impl From<u64> for ProtocolVersion {
126    fn from(v: u64) -> Self {
127        Self::new(v)
128    }
129}
130
131impl std::ops::Sub<u64> for ProtocolVersion {
132    type Output = Self;
133    fn sub(self, rhs: u64) -> Self::Output {
134        Self::new(self.0 - rhs)
135    }
136}
137
138impl std::ops::Add<u64> for ProtocolVersion {
139    type Output = Self;
140    fn add(self, rhs: u64) -> Self::Output {
141        Self::new(self.0 + rhs)
142    }
143}
144
145#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum)]
146pub enum Chain {
147    Mainnet,
148    Testnet,
149    Unknown,
150}
151
152impl Default for Chain {
153    fn default() -> Self {
154        Self::Unknown
155    }
156}
157
158impl Chain {
159    pub fn as_str(self) -> &'static str {
160        match self {
161            Chain::Mainnet => "mainnet",
162            Chain::Testnet => "testnet",
163            Chain::Unknown => "unknown",
164        }
165    }
166}
167
168pub struct Error(pub String);
169
170// TODO: There are quite a few non boolean values in the feature flags. We
171// should move them out.
172/// Records on/off feature flags that may vary at each protocol version.
173#[derive(Default, Clone, Serialize, Deserialize, Debug, ProtocolConfigFeatureFlagsGetters)]
174struct FeatureFlags {
175    // Add feature flags here, e.g.:
176    // new_protocol_feature: bool,
177
178    // Disables unnecessary invariant check in the Move VM when swapping the value out of a local
179    // This flag is used to provide the correct MoveVM configuration for clients.
180    #[serde(skip_serializing_if = "is_true")]
181    disable_invariant_violation_check_in_swap_loc: bool,
182
183    // If true, checks no extra bytes in a compiled module
184    // This flag is used to provide the correct MoveVM configuration for clients.
185    #[serde(skip_serializing_if = "is_true")]
186    no_extraneous_module_bytes: bool,
187
188    // Enable zklogin auth
189    #[serde(skip_serializing_if = "is_false")]
190    zklogin_auth: bool,
191
192    // How we order transactions coming out of consensus before sending to execution.
193    #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
194    consensus_transaction_ordering: ConsensusTransactionOrdering,
195
196    #[serde(skip_serializing_if = "is_false")]
197    enable_jwk_consensus_updates: bool,
198
199    // If true, multisig containing zkLogin sig is accepted.
200    #[serde(skip_serializing_if = "is_false")]
201    accept_zklogin_in_multisig: bool,
202
203    // If true, use the hardened OTW check
204    // This flag is used to provide the correct MoveVM configuration for clients.
205    #[serde(skip_serializing_if = "is_true")]
206    hardened_otw_check: bool,
207
208    // Enable the poseidon hash function
209    #[serde(skip_serializing_if = "is_false")]
210    enable_poseidon: bool,
211
212    // Enable native function for msm.
213    #[serde(skip_serializing_if = "is_false")]
214    enable_group_ops_native_function_msm: bool,
215
216    // Controls the behavior of per object congestion control in consensus handler.
217    #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
218    per_object_congestion_control_mode: PerObjectCongestionControlMode,
219
220    // The consensus protocol to be used for the epoch.
221    #[serde(skip_serializing_if = "ConsensusChoice::is_mysticeti")]
222    consensus_choice: ConsensusChoice,
223
224    // Consensus network to use.
225    #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
226    consensus_network: ConsensusNetwork,
227
228    // Set the upper bound allowed for max_epoch in zklogin signature.
229    #[serde(skip_serializing_if = "Option::is_none")]
230    zklogin_max_epoch_upper_bound_delta: Option<u64>,
231
232    // Enable VDF
233    #[serde(skip_serializing_if = "is_false")]
234    enable_vdf: bool,
235
236    // Enable passkey auth (SIP-9)
237    #[serde(skip_serializing_if = "is_false")]
238    passkey_auth: bool,
239
240    // Rethrow type layout errors during serialization instead of trying to convert them.
241    // This flag is used to provide the correct MoveVM configuration for clients.
242    #[serde(skip_serializing_if = "is_true")]
243    rethrow_serialization_type_layout_errors: bool,
244
245    // Makes the event's sending module version-aware.
246    #[serde(skip_serializing_if = "is_false")]
247    relocate_event_module: bool,
248
249    // Enable a protocol-defined base gas price for all transactions.
250    #[serde(skip_serializing_if = "is_false")]
251    protocol_defined_base_fee: bool,
252
253    // Enable uncompressed group elements in BLS123-81 G1
254    #[serde(skip_serializing_if = "is_false")]
255    uncompressed_g1_group_elements: bool,
256
257    // Disallow adding new modules in `deps-only` packages.
258    #[serde(skip_serializing_if = "is_false")]
259    disallow_new_modules_in_deps_only_packages: bool,
260
261    // Enable v2 native charging for natives.
262    #[serde(skip_serializing_if = "is_false")]
263    native_charging_v2: bool,
264
265    // Properly convert certain type argument errors in the execution layer.
266    #[serde(skip_serializing_if = "is_false")]
267    convert_type_argument_error: bool,
268
269    // Probe rounds received by peers from every authority.
270    #[serde(skip_serializing_if = "is_false")]
271    consensus_round_prober: bool,
272
273    // Use distributed vote leader scoring strategy in consensus.
274    #[serde(skip_serializing_if = "is_false")]
275    consensus_distributed_vote_scoring_strategy: bool,
276
277    // Enables the new logic for collecting the subdag in the consensus linearizer. The new logic
278    // does not stop the recursion at the highest committed round for each authority, but
279    // allows to commit uncommitted blocks up to gc round (excluded) for that authority.
280    #[serde(skip_serializing_if = "is_false")]
281    consensus_linearize_subdag_v2: bool,
282
283    // Variants count as nodes
284    #[serde(skip_serializing_if = "is_false")]
285    variant_nodes: bool,
286
287    // Use smart ancestor selection in consensus.
288    #[serde(skip_serializing_if = "is_false")]
289    consensus_smart_ancestor_selection: bool,
290
291    // Probe accepted rounds in round prober.
292    #[serde(skip_serializing_if = "is_false")]
293    consensus_round_prober_probe_accepted_rounds: bool,
294
295    // If true, enable zstd compression for consensus tonic network.
296    #[serde(skip_serializing_if = "is_false")]
297    consensus_zstd_compression: bool,
298
299    // Use the minimum free execution slot to schedule execution of a transaction in the shared
300    // object congestion tracker.
301    #[serde(skip_serializing_if = "is_false")]
302    congestion_control_min_free_execution_slot: bool,
303
304    // If true, multisig containing passkey sig is accepted.
305    #[serde(skip_serializing_if = "is_false")]
306    accept_passkey_in_multisig: bool,
307
308    // If true, enabled batched block sync in consensus.
309    #[serde(skip_serializing_if = "is_false")]
310    consensus_batched_block_sync: bool,
311
312    // To enable/disable the gas price feedback mechanism used for transactions
313    // cancelled due to shared object congestion
314    #[serde(skip_serializing_if = "is_false")]
315    congestion_control_gas_price_feedback_mechanism: bool,
316
317    // Validate identifier inputs separately
318    #[serde(skip_serializing_if = "is_false")]
319    validate_identifier_inputs: bool,
320
321    // If true, enables the optimizations for child object mutations, removing unnecessary
322    // mutations
323    #[serde(skip_serializing_if = "is_false")]
324    minimize_child_object_mutations: bool,
325
326    // If true enable additional linkage checks.
327    #[serde(skip_serializing_if = "is_false")]
328    dependency_linkage_error: bool,
329
330    // If true enable additional multisig checks.
331    #[serde(skip_serializing_if = "is_false")]
332    additional_multisig_checks: bool,
333
334    // If true, enables the normalization of PTB arguments but does not yet enable splatting
335    // `Result`s of length not equal to 1
336    #[serde(skip_serializing_if = "is_false")]
337    normalize_ptb_arguments: bool,
338
339    // If true, use ChangeEpochV3 for epoch change to pass an additional eligible_active_validators
340    // parameter to IotaSystem's advance_epoch call. This should only be enabled when on-chain
341    // IotaSystem objects are updated as well.
342    #[serde(skip_serializing_if = "is_false")]
343    select_committee_from_eligible_validators: bool,
344
345    // If true, non-committee active validators will sign and send AuthorityCapabilitiesV1 to the
346    // committee. Once the committee reaches consensus over the AuthorityCapabilitiesV1, it is
347    // recorded and possible to use in the committee selection if
348    // select_validators_supporting_next_epoch_version is enabled. This flag does not change the
349    // way that eligible_validators vector is created - still all active validators are used for
350    // selecting the committee.
351    #[serde(skip_serializing_if = "is_false")]
352    track_non_committee_eligible_validators: bool,
353
354    // The committee be selected from active_validators who support the next protocol version AND
355    // have issued a correct AuthorityCapabilities notification. This flag should only be enabled
356    // if both select_committee_from_eligible_validators and
357    // track_non_committee_eligible_validators are enabled. If this is disabled, then all
358    // active validators are used for selecting the committee (default behavior).
359    #[serde(skip_serializing_if = "is_false")]
360    select_committee_supporting_next_epoch_version: bool,
361
362    // If true, then it (1) will not enforce monotonicity checks for a block's ancestors, (2)
363    // calculates the commit's timestamp based on the weighted by stake median timestamp of the
364    // leader's ancestors, and (3) enforces checkpoint timestamps are non-decreasing.
365    #[serde(skip_serializing_if = "is_false")]
366    consensus_median_timestamp_with_checkpoint_enforcement: bool,
367}
368
369fn is_true(b: &bool) -> bool {
370    *b
371}
372
373fn is_false(b: &bool) -> bool {
374    !b
375}
376
377/// Ordering mechanism for transactions in one consensus output.
378#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
379pub enum ConsensusTransactionOrdering {
380    /// No ordering. Transactions are processed in the order they appear in the
381    /// consensus output.
382    #[default]
383    None,
384    /// Order transactions by gas price, highest first.
385    ByGasPrice,
386}
387
388impl ConsensusTransactionOrdering {
389    pub fn is_none(&self) -> bool {
390        matches!(self, ConsensusTransactionOrdering::None)
391    }
392}
393
394// The config for per object congestion control in consensus handler.
395#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
396pub enum PerObjectCongestionControlMode {
397    #[default]
398    None, // No congestion control.
399    TotalGasBudget, // Use txn gas budget as execution cost.
400    TotalTxCount,   // Use total txn count as execution cost.
401}
402
403impl PerObjectCongestionControlMode {
404    pub fn is_none(&self) -> bool {
405        matches!(self, PerObjectCongestionControlMode::None)
406    }
407}
408
409// Configuration options for consensus algorithm.
410#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
411pub enum ConsensusChoice {
412    #[default]
413    Mysticeti,
414    Starfish,
415}
416
417impl ConsensusChoice {
418    pub fn is_mysticeti(&self) -> bool {
419        matches!(self, ConsensusChoice::Mysticeti)
420    }
421    pub fn is_starfish(&self) -> bool {
422        matches!(self, ConsensusChoice::Starfish)
423    }
424}
425
426// Configuration options for consensus network.
427#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
428pub enum ConsensusNetwork {
429    #[default]
430    Tonic,
431}
432
433impl ConsensusNetwork {
434    pub fn is_tonic(&self) -> bool {
435        matches!(self, ConsensusNetwork::Tonic)
436    }
437}
438
439/// Constants that change the behavior of the protocol.
440///
441/// The value of each constant here must be fixed for a given protocol version.
442/// To change the value of a constant, advance the protocol version, and add
443/// support for it in `get_for_version` under the new version number.
444/// (below).
445///
446/// To add a new field to this struct, use the following procedure:
447/// - Advance the protocol version.
448/// - Add the field as a private `Option<T>` to the struct.
449/// - Initialize the field to `None` in prior protocol versions.
450/// - Initialize the field to `Some(val)` for your new protocol version.
451/// - Add a public getter that simply unwraps the field.
452/// - Two public getters of the form `field(&self) -> field_type` and
453///   `field_as_option(&self) -> Option<field_type>` will be automatically
454///   generated for you.
455/// Example for a field: `new_constant: Option<u64>`
456/// ```rust,ignore
457///      pub fn new_constant(&self) -> u64 {
458///         self.new_constant.expect(Self::CONSTANT_ERR_MSG)
459///     }
460///      pub fn new_constant_as_option(&self) -> Option<u64> {
461///         self.new_constant.expect(Self::CONSTANT_ERR_MSG)
462///     }
463/// ```
464/// With `pub fn new_constant(&self) -> u64`, if the constant is accessed in a
465/// protocol version in which it is not defined, the validator will crash.
466/// (Crashing is necessary because this type of error would almost always result
467/// in forking if not prevented here). If you don't want the validator to crash,
468/// you can use the `pub fn new_constant_as_option(&self) -> Option<u64>`
469/// getter, which will return `None` if the field is not defined at that
470/// version.
471/// - If you want a customized getter, you can add a method in the impl.
472#[skip_serializing_none]
473#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
474pub struct ProtocolConfig {
475    pub version: ProtocolVersion,
476
477    feature_flags: FeatureFlags,
478
479    // ==== Transaction input limits ====
480
481    //
482    /// Maximum serialized size of a transaction (in bytes).
483    max_tx_size_bytes: Option<u64>,
484
485    /// Maximum number of input objects to a transaction. Enforced by the
486    /// transaction input checker
487    max_input_objects: Option<u64>,
488
489    /// Max size of objects a transaction can write to disk after completion.
490    /// Enforce by the IOTA adapter. This is the sum of the serialized size
491    /// of all objects written to disk. The max size of individual objects
492    /// on the other hand is `max_move_object_size`.
493    max_size_written_objects: Option<u64>,
494    /// Max size of objects a system transaction can write to disk after
495    /// completion. Enforce by the IOTA adapter. Similar to
496    /// `max_size_written_objects` but for system transactions.
497    max_size_written_objects_system_tx: Option<u64>,
498
499    /// Maximum size of serialized transaction effects.
500    max_serialized_tx_effects_size_bytes: Option<u64>,
501
502    /// Maximum size of serialized transaction effects for system transactions.
503    max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
504
505    /// Maximum number of gas payment objects for a transaction.
506    max_gas_payment_objects: Option<u32>,
507
508    /// Maximum number of modules in a Publish transaction.
509    max_modules_in_publish: Option<u32>,
510
511    /// Maximum number of transitive dependencies in a package when publishing.
512    max_package_dependencies: Option<u32>,
513
514    /// Maximum number of arguments in a move call or a
515    /// ProgrammableTransaction's TransferObjects command.
516    max_arguments: Option<u32>,
517
518    /// Maximum number of total type arguments, computed recursively.
519    max_type_arguments: Option<u32>,
520
521    /// Maximum depth of an individual type argument.
522    max_type_argument_depth: Option<u32>,
523
524    /// Maximum size of a Pure CallArg.
525    max_pure_argument_size: Option<u32>,
526
527    /// Maximum number of Commands in a ProgrammableTransaction.
528    max_programmable_tx_commands: Option<u32>,
529
530    // ==== Move VM, Move bytecode verifier, and execution limits ===
531
532    //
533    /// Maximum Move bytecode version the VM understands. All older versions are
534    /// accepted.
535    move_binary_format_version: Option<u32>,
536    min_move_binary_format_version: Option<u32>,
537
538    /// Configuration controlling binary tables size.
539    binary_module_handles: Option<u16>,
540    binary_struct_handles: Option<u16>,
541    binary_function_handles: Option<u16>,
542    binary_function_instantiations: Option<u16>,
543    binary_signatures: Option<u16>,
544    binary_constant_pool: Option<u16>,
545    binary_identifiers: Option<u16>,
546    binary_address_identifiers: Option<u16>,
547    binary_struct_defs: Option<u16>,
548    binary_struct_def_instantiations: Option<u16>,
549    binary_function_defs: Option<u16>,
550    binary_field_handles: Option<u16>,
551    binary_field_instantiations: Option<u16>,
552    binary_friend_decls: Option<u16>,
553    binary_enum_defs: Option<u16>,
554    binary_enum_def_instantiations: Option<u16>,
555    binary_variant_handles: Option<u16>,
556    binary_variant_instantiation_handles: Option<u16>,
557
558    /// Maximum size of the `contents` part of an object, in bytes. Enforced by
559    /// the IOTA adapter when effects are produced.
560    max_move_object_size: Option<u64>,
561
562    // TODO: Option<increase to 500 KB. currently, publishing a package > 500 KB exceeds the max
563    // computation gas cost
564    /// Maximum size of a Move package object, in bytes. Enforced by the IOTA
565    /// adapter at the end of a publish transaction.
566    max_move_package_size: Option<u64>,
567
568    /// Max number of publish or upgrade commands allowed in a programmable
569    /// transaction block.
570    max_publish_or_upgrade_per_ptb: Option<u64>,
571
572    /// Maximum gas budget in NANOS that a transaction can use.
573    max_tx_gas: Option<u64>,
574
575    /// Maximum amount of the proposed gas price in NANOS (defined in the
576    /// transaction).
577    max_gas_price: Option<u64>,
578
579    /// The max computation bucket for gas. This is the max that can be charged
580    /// for computation.
581    max_gas_computation_bucket: Option<u64>,
582
583    // Define the value used to round up computation gas charges
584    gas_rounding_step: Option<u64>,
585
586    /// Maximum number of nested loops. Enforced by the Move bytecode verifier.
587    max_loop_depth: Option<u64>,
588
589    /// Maximum number of type arguments that can be bound to generic type
590    /// parameters. Enforced by the Move bytecode verifier.
591    max_generic_instantiation_length: Option<u64>,
592
593    /// Maximum number of parameters that a Move function can have. Enforced by
594    /// the Move bytecode verifier.
595    max_function_parameters: Option<u64>,
596
597    /// Maximum number of basic blocks that a Move function can have. Enforced
598    /// by the Move bytecode verifier.
599    max_basic_blocks: Option<u64>,
600
601    /// Maximum stack size value. Enforced by the Move bytecode verifier.
602    max_value_stack_size: Option<u64>,
603
604    /// Maximum number of "type nodes", a metric for how big a SignatureToken
605    /// will be when expanded into a fully qualified type. Enforced by the Move
606    /// bytecode verifier.
607    max_type_nodes: Option<u64>,
608
609    /// Maximum number of push instructions in one function. Enforced by the
610    /// Move bytecode verifier.
611    max_push_size: Option<u64>,
612
613    /// Maximum number of struct definitions in a module. Enforced by the Move
614    /// bytecode verifier.
615    max_struct_definitions: Option<u64>,
616
617    /// Maximum number of function definitions in a module. Enforced by the Move
618    /// bytecode verifier.
619    max_function_definitions: Option<u64>,
620
621    /// Maximum number of fields allowed in a struct definition. Enforced by the
622    /// Move bytecode verifier.
623    max_fields_in_struct: Option<u64>,
624
625    /// Maximum dependency depth. Enforced by the Move linker when loading
626    /// dependent modules.
627    max_dependency_depth: Option<u64>,
628
629    /// Maximum number of Move events that a single transaction can emit.
630    /// Enforced by the VM during execution.
631    max_num_event_emit: Option<u64>,
632
633    /// Maximum number of new IDs that a single transaction can create. Enforced
634    /// by the VM during execution.
635    max_num_new_move_object_ids: Option<u64>,
636
637    /// Maximum number of new IDs that a single system transaction can create.
638    /// Enforced by the VM during execution.
639    max_num_new_move_object_ids_system_tx: Option<u64>,
640
641    /// Maximum number of IDs that a single transaction can delete. Enforced by
642    /// the VM during execution.
643    max_num_deleted_move_object_ids: Option<u64>,
644
645    /// Maximum number of IDs that a single system transaction can delete.
646    /// Enforced by the VM during execution.
647    max_num_deleted_move_object_ids_system_tx: Option<u64>,
648
649    /// Maximum number of IDs that a single transaction can transfer. Enforced
650    /// by the VM during execution.
651    max_num_transferred_move_object_ids: Option<u64>,
652
653    /// Maximum number of IDs that a single system transaction can transfer.
654    /// Enforced by the VM during execution.
655    max_num_transferred_move_object_ids_system_tx: Option<u64>,
656
657    /// Maximum size of a Move user event. Enforced by the VM during execution.
658    max_event_emit_size: Option<u64>,
659
660    /// Maximum size of a Move user event. Enforced by the VM during execution.
661    max_event_emit_size_total: Option<u64>,
662
663    /// Maximum length of a vector in Move. Enforced by the VM during execution,
664    /// and for constants, by the verifier.
665    max_move_vector_len: Option<u64>,
666
667    /// Maximum length of an `Identifier` in Move. Enforced by the bytecode
668    /// verifier at signing.
669    max_move_identifier_len: Option<u64>,
670
671    /// Maximum depth of a Move value within the VM.
672    max_move_value_depth: Option<u64>,
673
674    /// Maximum number of variants in an enum. Enforced by the bytecode verifier
675    /// at signing.
676    max_move_enum_variants: Option<u64>,
677
678    /// Maximum number of back edges in Move function. Enforced by the bytecode
679    /// verifier at signing.
680    max_back_edges_per_function: Option<u64>,
681
682    /// Maximum number of back edges in Move module. Enforced by the bytecode
683    /// verifier at signing.
684    max_back_edges_per_module: Option<u64>,
685
686    /// Maximum number of meter `ticks` spent verifying a Move function.
687    /// Enforced by the bytecode verifier at signing.
688    max_verifier_meter_ticks_per_function: Option<u64>,
689
690    /// Maximum number of meter `ticks` spent verifying a Move function.
691    /// Enforced by the bytecode verifier at signing.
692    max_meter_ticks_per_module: Option<u64>,
693
694    /// Maximum number of meter `ticks` spent verifying a Move package. Enforced
695    /// by the bytecode verifier at signing.
696    max_meter_ticks_per_package: Option<u64>,
697
698    // === Object runtime internal operation limits ====
699    // These affect dynamic fields
700
701    //
702    /// Maximum number of cached objects in the object runtime ObjectStore.
703    /// Enforced by object runtime during execution
704    object_runtime_max_num_cached_objects: Option<u64>,
705
706    /// Maximum number of cached objects in the object runtime ObjectStore in
707    /// system transaction. Enforced by object runtime during execution
708    object_runtime_max_num_cached_objects_system_tx: Option<u64>,
709
710    /// Maximum number of stored objects accessed by object runtime ObjectStore.
711    /// Enforced by object runtime during execution
712    object_runtime_max_num_store_entries: Option<u64>,
713
714    /// Maximum number of stored objects accessed by object runtime ObjectStore
715    /// in system transaction. Enforced by object runtime during execution
716    object_runtime_max_num_store_entries_system_tx: Option<u64>,
717
718    // === Execution gas costs ====
719
720    //
721    /// Base cost for any IOTA transaction
722    base_tx_cost_fixed: Option<u64>,
723
724    /// Additional cost for a transaction that publishes a package
725    /// i.e., the base cost of such a transaction is base_tx_cost_fixed +
726    /// package_publish_cost_fixed
727    package_publish_cost_fixed: Option<u64>,
728
729    /// Cost per byte of a Move call transaction
730    /// i.e., the cost of such a transaction is base_cost +
731    /// (base_tx_cost_per_byte * size)
732    base_tx_cost_per_byte: Option<u64>,
733
734    /// Cost per byte for a transaction that publishes a package
735    package_publish_cost_per_byte: Option<u64>,
736
737    // Per-byte cost of reading an object during transaction execution
738    obj_access_cost_read_per_byte: Option<u64>,
739
740    // Per-byte cost of writing an object during transaction execution
741    obj_access_cost_mutate_per_byte: Option<u64>,
742
743    // Per-byte cost of deleting an object during transaction execution
744    obj_access_cost_delete_per_byte: Option<u64>,
745
746    /// Per-byte cost charged for each input object to a transaction.
747    /// Meant to approximate the cost of checking locks for each object
748    // TODO: Option<I'm not sure that this cost makes sense. Checking locks is "free"
749    // in the sense that an invalid tx that can never be committed/pay gas can
750    // force validators to check an arbitrary number of locks. If those checks are
751    // "free" for invalid transactions, why charge for them in valid transactions
752    // TODO: Option<if we keep this, I think we probably want it to be a fixed cost rather
753    // than a per-byte cost. checking an object lock should not require loading an
754    // entire object, just consulting an ID -> tx digest map
755    obj_access_cost_verify_per_byte: Option<u64>,
756
757    // Maximal nodes which are allowed when converting to a type layout.
758    max_type_to_layout_nodes: Option<u64>,
759
760    // Maximal size in bytes that a PTB value can be
761    max_ptb_value_size: Option<u64>,
762
763    // === Gas version. gas model ===
764
765    //
766    /// Gas model version, what code we are using to charge gas
767    gas_model_version: Option<u64>,
768
769    // === Storage gas costs ===
770
771    //
772    /// Per-byte cost of storing an object in the IOTA global object store. Some
773    /// of this cost may be refundable if the object is later freed
774    obj_data_cost_refundable: Option<u64>,
775
776    // Per-byte cost of storing an object in the IOTA transaction log (e.g., in
777    // CertifiedTransactionEffects) This depends on the size of various fields including the
778    // effects TODO: Option<I don't fully understand this^ and more details would be useful
779    obj_metadata_cost_non_refundable: Option<u64>,
780
781    // === Tokenomics ===
782
783    // TODO: Option<this should be changed to u64.
784    /// Sender of a txn that touches an object will get this percent of the
785    /// storage rebate back. In basis point.
786    storage_rebate_rate: Option<u64>,
787
788    /// The share of rewards that will be slashed and redistributed is 50%.
789    /// In basis point.
790    reward_slashing_rate: Option<u64>,
791
792    /// Unit storage gas price, Nanos per internal gas unit.
793    storage_gas_price: Option<u64>,
794
795    // Base gas price for computation gas, nanos per computation unit.
796    base_gas_price: Option<u64>,
797
798    /// The number of tokens minted as a validator subsidy per epoch.
799    validator_target_reward: Option<u64>,
800
801    // === Core Protocol ===
802
803    //
804    /// Max number of transactions per checkpoint.
805    /// Note that this is a protocol constant and not a config as validators
806    /// must have this set to the same value, otherwise they *will* fork.
807    max_transactions_per_checkpoint: Option<u64>,
808
809    /// Max size of a checkpoint in bytes.
810    /// Note that this is a protocol constant and not a config as validators
811    /// must have this set to the same value, otherwise they *will* fork.
812    max_checkpoint_size_bytes: Option<u64>,
813
814    /// A protocol upgrade always requires 2f+1 stake to agree. We support a
815    /// buffer of additional stake (as a fraction of f, expressed in basis
816    /// points) that is required before an upgrade can happen automatically.
817    /// 10000bps would indicate that complete unanimity is required (all
818    /// 3f+1 must vote), while 0bps would indicate that 2f+1 is sufficient.
819    buffer_stake_for_protocol_upgrade_bps: Option<u64>,
820
821    // === Native Function Costs ===
822
823    // `address` module
824    // Cost params for the Move native function `address::from_bytes(bytes: vector<u8>)`
825    address_from_bytes_cost_base: Option<u64>,
826    // Cost params for the Move native function `address::to_u256(address): u256`
827    address_to_u256_cost_base: Option<u64>,
828    // Cost params for the Move native function `address::from_u256(u256): address`
829    address_from_u256_cost_base: Option<u64>,
830
831    // `config` module
832    // Cost params for the Move native function `read_setting_impl<Name: copy + drop + store,
833    // SettingValue: key + store, SettingDataValue: store, Value: copy + drop + store,
834    // >(config: address, name: address, current_epoch: u64): Option<Value>`
835    config_read_setting_impl_cost_base: Option<u64>,
836    config_read_setting_impl_cost_per_byte: Option<u64>,
837
838    // `dynamic_field` module
839    // Cost params for the Move native function `hash_type_and_key<K: copy + drop + store>(parent:
840    // address, k: K): address`
841    dynamic_field_hash_type_and_key_cost_base: Option<u64>,
842    dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
843    dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
844    dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
845    // Cost params for the Move native function `add_child_object<Child: key>(parent: address,
846    // child: Child)`
847    dynamic_field_add_child_object_cost_base: Option<u64>,
848    dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
849    dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
850    dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
851    // Cost params for the Move native function `borrow_child_object_mut<Child: key>(parent: &mut
852    // UID, id: address): &mut Child`
853    dynamic_field_borrow_child_object_cost_base: Option<u64>,
854    dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
855    dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
856    // Cost params for the Move native function `remove_child_object<Child: key>(parent: address,
857    // id: address): Child`
858    dynamic_field_remove_child_object_cost_base: Option<u64>,
859    dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
860    dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
861    // Cost params for the Move native function `has_child_object(parent: address, id: address):
862    // bool`
863    dynamic_field_has_child_object_cost_base: Option<u64>,
864    // Cost params for the Move native function `has_child_object_with_ty<Child: key>(parent:
865    // address, id: address): bool`
866    dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
867    dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
868    dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
869
870    // `event` module
871    // Cost params for the Move native function `event::emit<T: copy + drop>(event: T)`
872    event_emit_cost_base: Option<u64>,
873    event_emit_value_size_derivation_cost_per_byte: Option<u64>,
874    event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
875    event_emit_output_cost_per_byte: Option<u64>,
876
877    //  `object` module
878    // Cost params for the Move native function `borrow_uid<T: key>(obj: &T): &UID`
879    object_borrow_uid_cost_base: Option<u64>,
880    // Cost params for the Move native function `delete_impl(id: address)`
881    object_delete_impl_cost_base: Option<u64>,
882    // Cost params for the Move native function `record_new_uid(id: address)`
883    object_record_new_uid_cost_base: Option<u64>,
884
885    // Transfer
886    // Cost params for the Move native function `transfer_impl<T: key>(obj: T, recipient: address)`
887    transfer_transfer_internal_cost_base: Option<u64>,
888    // Cost params for the Move native function `freeze_object<T: key>(obj: T)`
889    transfer_freeze_object_cost_base: Option<u64>,
890    // Cost params for the Move native function `share_object<T: key>(obj: T)`
891    transfer_share_object_cost_base: Option<u64>,
892    // Cost params for the Move native function
893    // `receive_object<T: key>(p: &mut UID, recv: Receiving<T>T)`
894    transfer_receive_object_cost_base: Option<u64>,
895
896    // TxContext
897    // Cost params for the Move native function `transfer_impl<T: key>(obj: T, recipient: address)`
898    tx_context_derive_id_cost_base: Option<u64>,
899
900    // Types
901    // Cost params for the Move native function `is_one_time_witness<T: drop>(_: &T): bool`
902    types_is_one_time_witness_cost_base: Option<u64>,
903    types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
904    types_is_one_time_witness_type_cost_per_byte: Option<u64>,
905
906    // Validator
907    // Cost params for the Move native function `validate_metadata_bcs(metadata: vector<u8>)`
908    validator_validate_metadata_cost_base: Option<u64>,
909    validator_validate_metadata_data_cost_per_byte: Option<u64>,
910
911    // Crypto natives
912    crypto_invalid_arguments_cost: Option<u64>,
913    // bls12381::bls12381_min_sig_verify
914    bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
915    bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
916    bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
917
918    // bls12381::bls12381_min_pk_verify
919    bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
920    bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
921    bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
922
923    // ecdsa_k1::ecrecover
924    ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
925    ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
926    ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
927    ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
928    ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
929    ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
930
931    // ecdsa_k1::decompress_pubkey
932    ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
933
934    // ecdsa_k1::secp256k1_verify
935    ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
936    ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
937    ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
938    ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
939    ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
940    ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
941
942    // ecdsa_r1::ecrecover
943    ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
944    ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
945    ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
946    ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
947    ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
948    ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
949
950    // ecdsa_r1::secp256k1_verify
951    ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
952    ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
953    ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
954    ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
955    ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
956    ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
957
958    // ecvrf::verify
959    ecvrf_ecvrf_verify_cost_base: Option<u64>,
960    ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
961    ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
962
963    // ed25519
964    ed25519_ed25519_verify_cost_base: Option<u64>,
965    ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
966    ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
967
968    // groth16::prepare_verifying_key
969    groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
970    groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
971
972    // groth16::verify_groth16_proof_internal
973    groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
974    groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
975    groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
976    groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
977    groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
978
979    // hash::blake2b256
980    hash_blake2b256_cost_base: Option<u64>,
981    hash_blake2b256_data_cost_per_byte: Option<u64>,
982    hash_blake2b256_data_cost_per_block: Option<u64>,
983
984    // hash::keccak256
985    hash_keccak256_cost_base: Option<u64>,
986    hash_keccak256_data_cost_per_byte: Option<u64>,
987    hash_keccak256_data_cost_per_block: Option<u64>,
988
989    // poseidon::poseidon_bn254
990    poseidon_bn254_cost_base: Option<u64>,
991    poseidon_bn254_cost_per_block: Option<u64>,
992
993    // group_ops
994    group_ops_bls12381_decode_scalar_cost: Option<u64>,
995    group_ops_bls12381_decode_g1_cost: Option<u64>,
996    group_ops_bls12381_decode_g2_cost: Option<u64>,
997    group_ops_bls12381_decode_gt_cost: Option<u64>,
998    group_ops_bls12381_scalar_add_cost: Option<u64>,
999    group_ops_bls12381_g1_add_cost: Option<u64>,
1000    group_ops_bls12381_g2_add_cost: Option<u64>,
1001    group_ops_bls12381_gt_add_cost: Option<u64>,
1002    group_ops_bls12381_scalar_sub_cost: Option<u64>,
1003    group_ops_bls12381_g1_sub_cost: Option<u64>,
1004    group_ops_bls12381_g2_sub_cost: Option<u64>,
1005    group_ops_bls12381_gt_sub_cost: Option<u64>,
1006    group_ops_bls12381_scalar_mul_cost: Option<u64>,
1007    group_ops_bls12381_g1_mul_cost: Option<u64>,
1008    group_ops_bls12381_g2_mul_cost: Option<u64>,
1009    group_ops_bls12381_gt_mul_cost: Option<u64>,
1010    group_ops_bls12381_scalar_div_cost: Option<u64>,
1011    group_ops_bls12381_g1_div_cost: Option<u64>,
1012    group_ops_bls12381_g2_div_cost: Option<u64>,
1013    group_ops_bls12381_gt_div_cost: Option<u64>,
1014    group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1015    group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1016    group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1017    group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1018    group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1019    group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1020    group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1021    group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1022    group_ops_bls12381_msm_max_len: Option<u32>,
1023    group_ops_bls12381_pairing_cost: Option<u64>,
1024    group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1025    group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1026    group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1027    group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1028    group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1029
1030    // hmac::hmac_sha3_256
1031    hmac_hmac_sha3_256_cost_base: Option<u64>,
1032    hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1033    hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1034
1035    // zklogin::check_zklogin_id
1036    check_zklogin_id_cost_base: Option<u64>,
1037    // zklogin::check_zklogin_issuer
1038    check_zklogin_issuer_cost_base: Option<u64>,
1039
1040    vdf_verify_vdf_cost: Option<u64>,
1041    vdf_hash_to_input_cost: Option<u64>,
1042
1043    // Stdlib costs
1044    bcs_per_byte_serialized_cost: Option<u64>,
1045    bcs_legacy_min_output_size_cost: Option<u64>,
1046    bcs_failure_cost: Option<u64>,
1047
1048    hash_sha2_256_base_cost: Option<u64>,
1049    hash_sha2_256_per_byte_cost: Option<u64>,
1050    hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1051    hash_sha3_256_base_cost: Option<u64>,
1052    hash_sha3_256_per_byte_cost: Option<u64>,
1053    hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1054    type_name_get_base_cost: Option<u64>,
1055    type_name_get_per_byte_cost: Option<u64>,
1056
1057    string_check_utf8_base_cost: Option<u64>,
1058    string_check_utf8_per_byte_cost: Option<u64>,
1059    string_is_char_boundary_base_cost: Option<u64>,
1060    string_sub_string_base_cost: Option<u64>,
1061    string_sub_string_per_byte_cost: Option<u64>,
1062    string_index_of_base_cost: Option<u64>,
1063    string_index_of_per_byte_pattern_cost: Option<u64>,
1064    string_index_of_per_byte_searched_cost: Option<u64>,
1065
1066    vector_empty_base_cost: Option<u64>,
1067    vector_length_base_cost: Option<u64>,
1068    vector_push_back_base_cost: Option<u64>,
1069    vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1070    vector_borrow_base_cost: Option<u64>,
1071    vector_pop_back_base_cost: Option<u64>,
1072    vector_destroy_empty_base_cost: Option<u64>,
1073    vector_swap_base_cost: Option<u64>,
1074    debug_print_base_cost: Option<u64>,
1075    debug_print_stack_trace_base_cost: Option<u64>,
1076
1077    // === Execution Version ===
1078    execution_version: Option<u64>,
1079
1080    // Dictates the threshold (percentage of stake) that is used to calculate the "bad" nodes to be
1081    // swapped when creating the consensus schedule. The values should be of the range [0 - 33].
1082    // Anything above 33 (f) will not be allowed.
1083    consensus_bad_nodes_stake_threshold: Option<u64>,
1084
1085    max_jwk_votes_per_validator_per_epoch: Option<u64>,
1086    // The maximum age of a JWK in epochs before it is removed from the AuthenticatorState object.
1087    // Applied at the end of an epoch as a delta from the new epoch value, so setting this to 1
1088    // will cause the new epoch to start with JWKs from the previous epoch still valid.
1089    max_age_of_jwk_in_epochs: Option<u64>,
1090
1091    // === random beacon ===
1092    /// Maximum allowed precision loss when reducing voting weights for the
1093    /// random beacon protocol.
1094    random_beacon_reduction_allowed_delta: Option<u16>,
1095
1096    /// Minimum number of shares below which voting weights will not be reduced
1097    /// for the random beacon protocol.
1098    random_beacon_reduction_lower_bound: Option<u32>,
1099
1100    /// Consensus Round after which DKG should be aborted and randomness
1101    /// disabled for the epoch, if it hasn't already completed.
1102    random_beacon_dkg_timeout_round: Option<u32>,
1103
1104    /// Minimum interval between consecutive rounds of generated randomness.
1105    random_beacon_min_round_interval_ms: Option<u64>,
1106
1107    /// Version of the random beacon DKG protocol.
1108    /// 0 was deprecated (and currently not supported), 1 is the default
1109    /// version.
1110    random_beacon_dkg_version: Option<u64>,
1111
1112    /// The maximum serialized transaction size (in bytes) accepted by
1113    /// consensus. `consensus_max_transaction_size_bytes` should include
1114    /// space for additional metadata, on top of the `max_tx_size_bytes`
1115    /// value.
1116    consensus_max_transaction_size_bytes: Option<u64>,
1117    /// The maximum size of transactions included in a consensus block.
1118    consensus_max_transactions_in_block_bytes: Option<u64>,
1119    /// The maximum number of transactions included in a consensus block.
1120    consensus_max_num_transactions_in_block: Option<u64>,
1121
1122    /// The max number of consensus rounds a transaction can be deferred due to
1123    /// shared object congestion. Transactions will be cancelled after this
1124    /// many rounds.
1125    max_deferral_rounds_for_congestion_control: Option<u64>,
1126
1127    /// Minimum interval of commit timestamps between consecutive checkpoints.
1128    min_checkpoint_interval_ms: Option<u64>,
1129
1130    /// Version number to use for version_specific_data in `CheckpointSummary`.
1131    checkpoint_summary_version_specific_data: Option<u64>,
1132
1133    /// The max number of transactions that can be included in a single Soft
1134    /// Bundle.
1135    max_soft_bundle_size: Option<u64>,
1136
1137    /// Deprecated because of bridge removal.
1138    /// Whether to try to form bridge committee
1139    // Note: this is not a feature flag because we want to distinguish between
1140    // `None` and `Some(false)`, as committee was already finalized on Testnet.
1141    bridge_should_try_to_finalize_committee: Option<bool>,
1142
1143    /// The max accumulated txn execution cost per object in a mysticeti commit.
1144    /// Transactions in a commit will be deferred once their touch shared
1145    /// objects hit this limit. Note that if
1146    /// `max_congestion_limit_overshoot_per_commit` is set, this may be overshot
1147    /// within a single commit, but the limit will be enforced in the long run.
1148    max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1149
1150    /// Maximum number of committee (validators taking part in consensus)
1151    /// validators at any moment. We do not allow the number of committee
1152    /// validators in any epoch to go above this.
1153    max_committee_members_count: Option<u64>,
1154
1155    /// Configures the garbage collection depth for consensus. When is unset or
1156    /// `0` then the garbage collection is disabled.
1157    consensus_gc_depth: Option<u32>,
1158
1159    /// Configures the maximum number of acknowledgments to be included in a
1160    /// block. It must be reasonably larger than the number of validators
1161    /// because not all validators create their blocks at the same pace.
1162    /// Default value set to 400. (5 x expected committee size (80)).
1163    /// Applicable only to `starfish` consensus.
1164    consensus_max_acknowledgments_per_block: Option<u32>,
1165
1166    /// The maximum amount that is allowed to overshoot the congestion limit
1167    /// specified by 'max_accumulated_txn_cost_per_object_in_mysticeti_commit'
1168    /// for any single commit. Any overshoot is tracked as a debt that must
1169    /// be accounted for in subsequent commits.
1170    max_congestion_limit_overshoot_per_commit: Option<u64>,
1171}
1172
1173// feature flags
1174impl ProtocolConfig {
1175    // Add checks for feature flag support here, e.g.:
1176    // pub fn check_new_protocol_feature_supported(&self) -> Result<(), Error> {
1177    //     if self.feature_flags.new_protocol_feature_supported {
1178    //         Ok(())
1179    //     } else {
1180    //         Err(Error(format!(
1181    //             "new_protocol_feature is not supported at {:?}",
1182    //             self.version
1183    //         )))
1184    //     }
1185    // }
1186
1187    pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1188        self.feature_flags
1189            .disable_invariant_violation_check_in_swap_loc
1190    }
1191
1192    pub fn no_extraneous_module_bytes(&self) -> bool {
1193        self.feature_flags.no_extraneous_module_bytes
1194    }
1195
1196    pub fn zklogin_auth(&self) -> bool {
1197        self.feature_flags.zklogin_auth
1198    }
1199
1200    pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1201        self.feature_flags.consensus_transaction_ordering
1202    }
1203
1204    pub fn enable_jwk_consensus_updates(&self) -> bool {
1205        self.feature_flags.enable_jwk_consensus_updates
1206    }
1207
1208    // this function only exists for readability in the genesis code.
1209    pub fn create_authenticator_state_in_genesis(&self) -> bool {
1210        self.enable_jwk_consensus_updates()
1211    }
1212
1213    pub fn dkg_version(&self) -> u64 {
1214        // Version 0 was deprecated and removed, the default is 1 if not set.
1215        self.random_beacon_dkg_version.unwrap_or(1)
1216    }
1217
1218    pub fn accept_zklogin_in_multisig(&self) -> bool {
1219        self.feature_flags.accept_zklogin_in_multisig
1220    }
1221
1222    pub fn zklogin_max_epoch_upper_bound_delta(&self) -> Option<u64> {
1223        self.feature_flags.zklogin_max_epoch_upper_bound_delta
1224    }
1225
1226    pub fn hardened_otw_check(&self) -> bool {
1227        self.feature_flags.hardened_otw_check
1228    }
1229
1230    pub fn enable_poseidon(&self) -> bool {
1231        self.feature_flags.enable_poseidon
1232    }
1233
1234    pub fn enable_group_ops_native_function_msm(&self) -> bool {
1235        self.feature_flags.enable_group_ops_native_function_msm
1236    }
1237
1238    pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1239        self.feature_flags.per_object_congestion_control_mode
1240    }
1241
1242    pub fn consensus_choice(&self) -> ConsensusChoice {
1243        self.feature_flags.consensus_choice
1244    }
1245
1246    pub fn consensus_network(&self) -> ConsensusNetwork {
1247        self.feature_flags.consensus_network
1248    }
1249
1250    pub fn enable_vdf(&self) -> bool {
1251        self.feature_flags.enable_vdf
1252    }
1253
1254    pub fn passkey_auth(&self) -> bool {
1255        self.feature_flags.passkey_auth
1256    }
1257
1258    pub fn max_transaction_size_bytes(&self) -> u64 {
1259        // Provide a default value if protocol config version is too low.
1260        self.consensus_max_transaction_size_bytes
1261            .unwrap_or(256 * 1024)
1262    }
1263
1264    pub fn max_transactions_in_block_bytes(&self) -> u64 {
1265        if cfg!(msim) {
1266            256 * 1024
1267        } else {
1268            self.consensus_max_transactions_in_block_bytes
1269                .unwrap_or(512 * 1024)
1270        }
1271    }
1272
1273    pub fn max_num_transactions_in_block(&self) -> u64 {
1274        if cfg!(msim) {
1275            8
1276        } else {
1277            self.consensus_max_num_transactions_in_block.unwrap_or(512)
1278        }
1279    }
1280
1281    pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1282        self.feature_flags.rethrow_serialization_type_layout_errors
1283    }
1284
1285    pub fn relocate_event_module(&self) -> bool {
1286        self.feature_flags.relocate_event_module
1287    }
1288
1289    pub fn protocol_defined_base_fee(&self) -> bool {
1290        self.feature_flags.protocol_defined_base_fee
1291    }
1292
1293    pub fn uncompressed_g1_group_elements(&self) -> bool {
1294        self.feature_flags.uncompressed_g1_group_elements
1295    }
1296
1297    pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1298        self.feature_flags
1299            .disallow_new_modules_in_deps_only_packages
1300    }
1301
1302    pub fn native_charging_v2(&self) -> bool {
1303        self.feature_flags.native_charging_v2
1304    }
1305
1306    pub fn consensus_round_prober(&self) -> bool {
1307        self.feature_flags.consensus_round_prober
1308    }
1309
1310    pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1311        self.feature_flags
1312            .consensus_distributed_vote_scoring_strategy
1313    }
1314
1315    pub fn gc_depth(&self) -> u32 {
1316        if cfg!(msim) {
1317            // exercise a very low gc_depth
1318            min(5, self.consensus_gc_depth.unwrap_or(0))
1319        } else {
1320            self.consensus_gc_depth.unwrap_or(0)
1321        }
1322    }
1323
1324    pub fn consensus_linearize_subdag_v2(&self) -> bool {
1325        let res = self.feature_flags.consensus_linearize_subdag_v2;
1326        assert!(
1327            !res || self.gc_depth() > 0,
1328            "The consensus linearize sub dag V2 requires GC to be enabled"
1329        );
1330        res
1331    }
1332
1333    pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1334        self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1335    }
1336
1337    pub fn variant_nodes(&self) -> bool {
1338        self.feature_flags.variant_nodes
1339    }
1340
1341    pub fn consensus_smart_ancestor_selection(&self) -> bool {
1342        self.feature_flags.consensus_smart_ancestor_selection
1343    }
1344
1345    pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1346        self.feature_flags
1347            .consensus_round_prober_probe_accepted_rounds
1348    }
1349
1350    pub fn consensus_zstd_compression(&self) -> bool {
1351        self.feature_flags.consensus_zstd_compression
1352    }
1353
1354    pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1355        self.feature_flags
1356            .congestion_control_min_free_execution_slot
1357    }
1358
1359    pub fn accept_passkey_in_multisig(&self) -> bool {
1360        self.feature_flags.accept_passkey_in_multisig
1361    }
1362
1363    pub fn consensus_batched_block_sync(&self) -> bool {
1364        self.feature_flags.consensus_batched_block_sync
1365    }
1366
1367    /// Check if the gas price feedback mechanism (which is used for
1368    /// transactions cancelled due to shared object congestion) is enabled
1369    pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1370        self.feature_flags
1371            .congestion_control_gas_price_feedback_mechanism
1372    }
1373
1374    pub fn validate_identifier_inputs(&self) -> bool {
1375        self.feature_flags.validate_identifier_inputs
1376    }
1377
1378    pub fn minimize_child_object_mutations(&self) -> bool {
1379        self.feature_flags.minimize_child_object_mutations
1380    }
1381
1382    pub fn dependency_linkage_error(&self) -> bool {
1383        self.feature_flags.dependency_linkage_error
1384    }
1385
1386    pub fn additional_multisig_checks(&self) -> bool {
1387        self.feature_flags.additional_multisig_checks
1388    }
1389
1390    pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1391        // TODO: this will eventually be the max of some number of other
1392        // parameters.
1393        0
1394    }
1395
1396    pub fn normalize_ptb_arguments(&self) -> bool {
1397        self.feature_flags.normalize_ptb_arguments
1398    }
1399
1400    pub fn select_committee_from_eligible_validators(&self) -> bool {
1401        let res = self.feature_flags.select_committee_from_eligible_validators;
1402        assert!(
1403            !res || (self.protocol_defined_base_fee()
1404                && self.max_committee_members_count_as_option().is_some()),
1405            "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1406        );
1407        res
1408    }
1409
1410    pub fn track_non_committee_eligible_validators(&self) -> bool {
1411        self.feature_flags.track_non_committee_eligible_validators
1412    }
1413
1414    pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1415        let res = self
1416            .feature_flags
1417            .select_committee_supporting_next_epoch_version;
1418        assert!(
1419            !res || (self.track_non_committee_eligible_validators()
1420                && self.select_committee_from_eligible_validators()),
1421            "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1422        );
1423        res
1424    }
1425
1426    pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1427        let res = self
1428            .feature_flags
1429            .consensus_median_timestamp_with_checkpoint_enforcement;
1430        assert!(
1431            !res || self.gc_depth() > 0,
1432            "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1433        );
1434        res
1435    }
1436}
1437
1438#[cfg(not(msim))]
1439static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1440
1441// Use a thread local in sim tests for test isolation.
1442#[cfg(msim)]
1443thread_local! {
1444    static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1445}
1446
1447// Instantiations for each protocol version.
1448impl ProtocolConfig {
1449    /// Get the value ProtocolConfig that are in effect during the given
1450    /// protocol version.
1451    pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1452        // ProtocolVersion can be deserialized so we need to check it here as well.
1453        assert!(
1454            version >= ProtocolVersion::MIN,
1455            "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1456            version,
1457            ProtocolVersion::MIN.0,
1458        );
1459        assert!(
1460            version <= ProtocolVersion::MAX_ALLOWED,
1461            "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1462            version,
1463            ProtocolVersion::MAX_ALLOWED.0,
1464        );
1465
1466        let mut ret = Self::get_for_version_impl(version, chain);
1467        ret.version = version;
1468
1469        ret = CONFIG_OVERRIDE.with(|ovr| {
1470            if let Some(override_fn) = &*ovr.borrow() {
1471                warn!(
1472                    "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1473                );
1474                override_fn(version, ret)
1475            } else {
1476                ret
1477            }
1478        });
1479
1480        if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1481            warn!(
1482                "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1483            );
1484            let overrides: ProtocolConfigOptional =
1485                serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1486                    .expect("failed to parse ProtocolConfig override env variables");
1487            overrides.apply_to(&mut ret);
1488        }
1489
1490        ret
1491    }
1492
1493    /// Get the value ProtocolConfig that are in effect during the given
1494    /// protocol version. Or none if the version is not supported.
1495    pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1496        if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1497            let mut ret = Self::get_for_version_impl(version, chain);
1498            ret.version = version;
1499            Some(ret)
1500        } else {
1501            None
1502        }
1503    }
1504
1505    #[cfg(not(msim))]
1506    pub fn poison_get_for_min_version() {
1507        POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1508    }
1509
1510    #[cfg(not(msim))]
1511    fn load_poison_get_for_min_version() -> bool {
1512        POISON_VERSION_METHODS.load(Ordering::Relaxed)
1513    }
1514
1515    #[cfg(msim)]
1516    pub fn poison_get_for_min_version() {
1517        POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1518    }
1519
1520    #[cfg(msim)]
1521    fn load_poison_get_for_min_version() -> bool {
1522        POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1523    }
1524
1525    pub fn convert_type_argument_error(&self) -> bool {
1526        self.feature_flags.convert_type_argument_error
1527    }
1528
1529    /// Convenience to get the constants at the current minimum supported
1530    /// version. Mainly used by client code that may not yet be
1531    /// protocol-version aware.
1532    pub fn get_for_min_version() -> Self {
1533        if Self::load_poison_get_for_min_version() {
1534            panic!("get_for_min_version called on validator");
1535        }
1536        ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1537    }
1538
1539    /// CAREFUL! - You probably want to use `get_for_version` instead.
1540    ///
1541    /// Convenience to get the constants at the current maximum supported
1542    /// version. Mainly used by genesis. Note well that this function uses
1543    /// the max version supported locally by the node, which is not
1544    /// necessarily the current version of the network. ALSO, this function
1545    /// disregards chain specific config (by using Chain::Unknown), thereby
1546    /// potentially returning a protocol config that is incorrect for some
1547    /// feature flags. Definitely safe for testing and for protocol version
1548    /// 11 and prior.
1549    #[expect(non_snake_case)]
1550    pub fn get_for_max_version_UNSAFE() -> Self {
1551        if Self::load_poison_get_for_min_version() {
1552            panic!("get_for_max_version_UNSAFE called on validator");
1553        }
1554        ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1555    }
1556
1557    fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1558        #[cfg(msim)]
1559        {
1560            // populate the fake simulator version # with a different base tx cost.
1561            if version > ProtocolVersion::MAX {
1562                let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1563                config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1564                return config;
1565            }
1566        }
1567
1568        // IMPORTANT: Never modify the value of any constant for a pre-existing protocol
1569        // version. To change the values here you must create a new protocol
1570        // version with the new values!
1571        let mut cfg = Self {
1572            version,
1573
1574            feature_flags: Default::default(),
1575
1576            max_tx_size_bytes: Some(128 * 1024),
1577            // We need this number to be at least 100x less than
1578            // `max_serialized_tx_effects_size_bytes`otherwise effects can be huge
1579            max_input_objects: Some(2048),
1580            max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1581            max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1582            max_gas_payment_objects: Some(256),
1583            max_modules_in_publish: Some(64),
1584            max_package_dependencies: Some(32),
1585            max_arguments: Some(512),
1586            max_type_arguments: Some(16),
1587            max_type_argument_depth: Some(16),
1588            max_pure_argument_size: Some(16 * 1024),
1589            max_programmable_tx_commands: Some(1024),
1590            move_binary_format_version: Some(7),
1591            min_move_binary_format_version: Some(6),
1592            binary_module_handles: Some(100),
1593            binary_struct_handles: Some(300),
1594            binary_function_handles: Some(1500),
1595            binary_function_instantiations: Some(750),
1596            binary_signatures: Some(1000),
1597            binary_constant_pool: Some(4000),
1598            binary_identifiers: Some(10000),
1599            binary_address_identifiers: Some(100),
1600            binary_struct_defs: Some(200),
1601            binary_struct_def_instantiations: Some(100),
1602            binary_function_defs: Some(1000),
1603            binary_field_handles: Some(500),
1604            binary_field_instantiations: Some(250),
1605            binary_friend_decls: Some(100),
1606            binary_enum_defs: None,
1607            binary_enum_def_instantiations: None,
1608            binary_variant_handles: None,
1609            binary_variant_instantiation_handles: None,
1610            max_move_object_size: Some(250 * 1024),
1611            max_move_package_size: Some(100 * 1024),
1612            max_publish_or_upgrade_per_ptb: Some(5),
1613            // max gas budget is in NANOS and an absolute value 50IOTA
1614            max_tx_gas: Some(50_000_000_000),
1615            max_gas_price: Some(100_000),
1616            max_gas_computation_bucket: Some(5_000_000),
1617            max_loop_depth: Some(5),
1618            max_generic_instantiation_length: Some(32),
1619            max_function_parameters: Some(128),
1620            max_basic_blocks: Some(1024),
1621            max_value_stack_size: Some(1024),
1622            max_type_nodes: Some(256),
1623            max_push_size: Some(10000),
1624            max_struct_definitions: Some(200),
1625            max_function_definitions: Some(1000),
1626            max_fields_in_struct: Some(32),
1627            max_dependency_depth: Some(100),
1628            max_num_event_emit: Some(1024),
1629            max_num_new_move_object_ids: Some(2048),
1630            max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1631            max_num_deleted_move_object_ids: Some(2048),
1632            max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1633            max_num_transferred_move_object_ids: Some(2048),
1634            max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1635            max_event_emit_size: Some(250 * 1024),
1636            max_move_vector_len: Some(256 * 1024),
1637            max_type_to_layout_nodes: None,
1638            max_ptb_value_size: None,
1639
1640            max_back_edges_per_function: Some(10_000),
1641            max_back_edges_per_module: Some(10_000),
1642
1643            max_verifier_meter_ticks_per_function: Some(16_000_000),
1644
1645            max_meter_ticks_per_module: Some(16_000_000),
1646            max_meter_ticks_per_package: Some(16_000_000),
1647
1648            object_runtime_max_num_cached_objects: Some(1000),
1649            object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
1650            object_runtime_max_num_store_entries: Some(1000),
1651            object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
1652            // min gas budget is in NANOS and an absolute value 1000 NANOS or 0.000001IOTA
1653            base_tx_cost_fixed: Some(1_000),
1654            package_publish_cost_fixed: Some(1_000),
1655            base_tx_cost_per_byte: Some(0),
1656            package_publish_cost_per_byte: Some(80),
1657            obj_access_cost_read_per_byte: Some(15),
1658            obj_access_cost_mutate_per_byte: Some(40),
1659            obj_access_cost_delete_per_byte: Some(40),
1660            obj_access_cost_verify_per_byte: Some(200),
1661            obj_data_cost_refundable: Some(100),
1662            obj_metadata_cost_non_refundable: Some(50),
1663            gas_model_version: Some(1),
1664            storage_rebate_rate: Some(10000),
1665            // Change reward slashing rate to 100%.
1666            reward_slashing_rate: Some(10000),
1667            storage_gas_price: Some(76),
1668            base_gas_price: None,
1669            // The initial subsidy (target reward) for validators per epoch.
1670            // Refer to the IOTA tokenomics for the origin of this value.
1671            validator_target_reward: Some(767_000 * 1_000_000_000),
1672            max_transactions_per_checkpoint: Some(10_000),
1673            max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
1674
1675            // For now, perform upgrades with a bare quorum of validators.
1676            buffer_stake_for_protocol_upgrade_bps: Some(5000),
1677
1678            // === Native Function Costs ===
1679            // `address` module
1680            // Cost params for the Move native function `address::from_bytes(bytes: vector<u8>)`
1681            address_from_bytes_cost_base: Some(52),
1682            // Cost params for the Move native function `address::to_u256(address): u256`
1683            address_to_u256_cost_base: Some(52),
1684            // Cost params for the Move native function `address::from_u256(u256): address`
1685            address_from_u256_cost_base: Some(52),
1686
1687            // `config` module
1688            // Cost params for the Move native function `read_setting_impl``
1689            config_read_setting_impl_cost_base: Some(100),
1690            config_read_setting_impl_cost_per_byte: Some(40),
1691
1692            // `dynamic_field` module
1693            // Cost params for the Move native function `hash_type_and_key<K: copy + drop +
1694            // store>(parent: address, k: K): address`
1695            dynamic_field_hash_type_and_key_cost_base: Some(100),
1696            dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
1697            dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
1698            dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
1699            // Cost params for the Move native function `add_child_object<Child: key>(parent:
1700            // address, child: Child)`
1701            dynamic_field_add_child_object_cost_base: Some(100),
1702            dynamic_field_add_child_object_type_cost_per_byte: Some(10),
1703            dynamic_field_add_child_object_value_cost_per_byte: Some(10),
1704            dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
1705            // Cost params for the Move native function `borrow_child_object_mut<Child: key>(parent:
1706            // &mut UID, id: address): &mut Child`
1707            dynamic_field_borrow_child_object_cost_base: Some(100),
1708            dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
1709            dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
1710            // Cost params for the Move native function `remove_child_object<Child: key>(parent:
1711            // address, id: address): Child`
1712            dynamic_field_remove_child_object_cost_base: Some(100),
1713            dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
1714            dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
1715            // Cost params for the Move native function `has_child_object(parent: address, id:
1716            // address): bool`
1717            dynamic_field_has_child_object_cost_base: Some(100),
1718            // Cost params for the Move native function `has_child_object_with_ty<Child:
1719            // key>(parent: address, id: address): bool`
1720            dynamic_field_has_child_object_with_ty_cost_base: Some(100),
1721            dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
1722            dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
1723
1724            // `event` module
1725            // Cost params for the Move native function `event::emit<T: copy + drop>(event: T)`
1726            event_emit_cost_base: Some(52),
1727            event_emit_value_size_derivation_cost_per_byte: Some(2),
1728            event_emit_tag_size_derivation_cost_per_byte: Some(5),
1729            event_emit_output_cost_per_byte: Some(10),
1730
1731            //  `object` module
1732            // Cost params for the Move native function `borrow_uid<T: key>(obj: &T): &UID`
1733            object_borrow_uid_cost_base: Some(52),
1734            // Cost params for the Move native function `delete_impl(id: address)`
1735            object_delete_impl_cost_base: Some(52),
1736            // Cost params for the Move native function `record_new_uid(id: address)`
1737            object_record_new_uid_cost_base: Some(52),
1738
1739            // `transfer` module
1740            // Cost params for the Move native function `transfer_impl<T: key>(obj: T, recipient:
1741            // address)`
1742            transfer_transfer_internal_cost_base: Some(52),
1743            // Cost params for the Move native function `freeze_object<T: key>(obj: T)`
1744            transfer_freeze_object_cost_base: Some(52),
1745            // Cost params for the Move native function `share_object<T: key>(obj: T)`
1746            transfer_share_object_cost_base: Some(52),
1747            transfer_receive_object_cost_base: Some(52),
1748
1749            // `tx_context` module
1750            // Cost params for the Move native function `transfer_impl<T: key>(obj: T, recipient:
1751            // address)`
1752            tx_context_derive_id_cost_base: Some(52),
1753
1754            // `types` module
1755            // Cost params for the Move native function `is_one_time_witness<T: drop>(_: &T): bool`
1756            types_is_one_time_witness_cost_base: Some(52),
1757            types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
1758            types_is_one_time_witness_type_cost_per_byte: Some(2),
1759
1760            // `validator` module
1761            // Cost params for the Move native function `validate_metadata_bcs(metadata:
1762            // vector<u8>)`
1763            validator_validate_metadata_cost_base: Some(52),
1764            validator_validate_metadata_data_cost_per_byte: Some(2),
1765
1766            // Crypto
1767            crypto_invalid_arguments_cost: Some(100),
1768            // bls12381::bls12381_min_pk_verify
1769            bls12381_bls12381_min_sig_verify_cost_base: Some(52),
1770            bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
1771            bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
1772
1773            // bls12381::bls12381_min_pk_verify
1774            bls12381_bls12381_min_pk_verify_cost_base: Some(52),
1775            bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
1776            bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
1777
1778            // ecdsa_k1::ecrecover
1779            ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
1780            ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1781            ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1782            ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
1783            ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1784            ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
1785
1786            // ecdsa_k1::decompress_pubkey
1787            ecdsa_k1_decompress_pubkey_cost_base: Some(52),
1788
1789            // ecdsa_k1::secp256k1_verify
1790            ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
1791            ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
1792            ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
1793            ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
1794            ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
1795            ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
1796
1797            // ecdsa_r1::ecrecover
1798            ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
1799            ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1800            ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1801            ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
1802            ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1803            ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
1804
1805            // ecdsa_r1::secp256k1_verify
1806            ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
1807            ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
1808            ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
1809            ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
1810            ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
1811            ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
1812
1813            // ecvrf::verify
1814            ecvrf_ecvrf_verify_cost_base: Some(52),
1815            ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
1816            ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
1817
1818            // ed25519
1819            ed25519_ed25519_verify_cost_base: Some(52),
1820            ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
1821            ed25519_ed25519_verify_msg_cost_per_block: Some(2),
1822
1823            // groth16::prepare_verifying_key
1824            groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
1825            groth16_prepare_verifying_key_bn254_cost_base: Some(52),
1826
1827            // groth16::verify_groth16_proof_internal
1828            groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
1829            groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
1830            groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
1831            groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
1832            groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
1833
1834            // hash::blake2b256
1835            hash_blake2b256_cost_base: Some(52),
1836            hash_blake2b256_data_cost_per_byte: Some(2),
1837            hash_blake2b256_data_cost_per_block: Some(2),
1838            // hash::keccak256
1839            hash_keccak256_cost_base: Some(52),
1840            hash_keccak256_data_cost_per_byte: Some(2),
1841            hash_keccak256_data_cost_per_block: Some(2),
1842
1843            poseidon_bn254_cost_base: None,
1844            poseidon_bn254_cost_per_block: None,
1845
1846            // hmac::hmac_sha3_256
1847            hmac_hmac_sha3_256_cost_base: Some(52),
1848            hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
1849            hmac_hmac_sha3_256_input_cost_per_block: Some(2),
1850
1851            // group ops
1852            group_ops_bls12381_decode_scalar_cost: Some(52),
1853            group_ops_bls12381_decode_g1_cost: Some(52),
1854            group_ops_bls12381_decode_g2_cost: Some(52),
1855            group_ops_bls12381_decode_gt_cost: Some(52),
1856            group_ops_bls12381_scalar_add_cost: Some(52),
1857            group_ops_bls12381_g1_add_cost: Some(52),
1858            group_ops_bls12381_g2_add_cost: Some(52),
1859            group_ops_bls12381_gt_add_cost: Some(52),
1860            group_ops_bls12381_scalar_sub_cost: Some(52),
1861            group_ops_bls12381_g1_sub_cost: Some(52),
1862            group_ops_bls12381_g2_sub_cost: Some(52),
1863            group_ops_bls12381_gt_sub_cost: Some(52),
1864            group_ops_bls12381_scalar_mul_cost: Some(52),
1865            group_ops_bls12381_g1_mul_cost: Some(52),
1866            group_ops_bls12381_g2_mul_cost: Some(52),
1867            group_ops_bls12381_gt_mul_cost: Some(52),
1868            group_ops_bls12381_scalar_div_cost: Some(52),
1869            group_ops_bls12381_g1_div_cost: Some(52),
1870            group_ops_bls12381_g2_div_cost: Some(52),
1871            group_ops_bls12381_gt_div_cost: Some(52),
1872            group_ops_bls12381_g1_hash_to_base_cost: Some(52),
1873            group_ops_bls12381_g2_hash_to_base_cost: Some(52),
1874            group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
1875            group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
1876            group_ops_bls12381_g1_msm_base_cost: Some(52),
1877            group_ops_bls12381_g2_msm_base_cost: Some(52),
1878            group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
1879            group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
1880            group_ops_bls12381_msm_max_len: Some(32),
1881            group_ops_bls12381_pairing_cost: Some(52),
1882            group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
1883            group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
1884            group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
1885            group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
1886            group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
1887
1888            // zklogin::check_zklogin_id
1889            check_zklogin_id_cost_base: Some(200),
1890            // zklogin::check_zklogin_issuer
1891            check_zklogin_issuer_cost_base: Some(200),
1892
1893            vdf_verify_vdf_cost: None,
1894            vdf_hash_to_input_cost: None,
1895
1896            bcs_per_byte_serialized_cost: Some(2),
1897            bcs_legacy_min_output_size_cost: Some(1),
1898            bcs_failure_cost: Some(52),
1899            hash_sha2_256_base_cost: Some(52),
1900            hash_sha2_256_per_byte_cost: Some(2),
1901            hash_sha2_256_legacy_min_input_len_cost: Some(1),
1902            hash_sha3_256_base_cost: Some(52),
1903            hash_sha3_256_per_byte_cost: Some(2),
1904            hash_sha3_256_legacy_min_input_len_cost: Some(1),
1905            type_name_get_base_cost: Some(52),
1906            type_name_get_per_byte_cost: Some(2),
1907            string_check_utf8_base_cost: Some(52),
1908            string_check_utf8_per_byte_cost: Some(2),
1909            string_is_char_boundary_base_cost: Some(52),
1910            string_sub_string_base_cost: Some(52),
1911            string_sub_string_per_byte_cost: Some(2),
1912            string_index_of_base_cost: Some(52),
1913            string_index_of_per_byte_pattern_cost: Some(2),
1914            string_index_of_per_byte_searched_cost: Some(2),
1915            vector_empty_base_cost: Some(52),
1916            vector_length_base_cost: Some(52),
1917            vector_push_back_base_cost: Some(52),
1918            vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
1919            vector_borrow_base_cost: Some(52),
1920            vector_pop_back_base_cost: Some(52),
1921            vector_destroy_empty_base_cost: Some(52),
1922            vector_swap_base_cost: Some(52),
1923            debug_print_base_cost: Some(52),
1924            debug_print_stack_trace_base_cost: Some(52),
1925
1926            max_size_written_objects: Some(5 * 1000 * 1000),
1927            // max size of written objects during a system TXn to allow for larger writes
1928            // akin to `max_size_written_objects` but for system TXns
1929            max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
1930
1931            // Limits the length of a Move identifier
1932            max_move_identifier_len: Some(128),
1933            max_move_value_depth: Some(128),
1934            max_move_enum_variants: None,
1935
1936            gas_rounding_step: Some(1_000),
1937
1938            execution_version: Some(1),
1939
1940            // We maintain the same total size limit for events, but increase the number of
1941            // events that can be emitted.
1942            max_event_emit_size_total: Some(
1943                256 /* former event count limit */ * 250 * 1024, // size limit per event
1944            ),
1945
1946            // Taking a baby step approach, we consider only 20% by stake as bad nodes so we
1947            // have a 80% by stake of nodes participating in the leader committee. That
1948            // allow us for more redundancy in case we have validators
1949            // under performing - since the responsibility is shared
1950            // amongst more nodes. We can increase that once we do have
1951            // higher confidence.
1952            consensus_bad_nodes_stake_threshold: Some(20),
1953
1954            // Max of 10 votes per hour.
1955            max_jwk_votes_per_validator_per_epoch: Some(240),
1956
1957            max_age_of_jwk_in_epochs: Some(1),
1958
1959            consensus_max_transaction_size_bytes: Some(256 * 1024), // 256KB
1960
1961            // Assume 1KB per transaction and 500 transactions per block.
1962            consensus_max_transactions_in_block_bytes: Some(512 * 1024),
1963
1964            random_beacon_reduction_allowed_delta: Some(800),
1965
1966            random_beacon_reduction_lower_bound: Some(1000),
1967            random_beacon_dkg_timeout_round: Some(3000),
1968            random_beacon_min_round_interval_ms: Some(500),
1969
1970            random_beacon_dkg_version: Some(1),
1971
1972            // Assume 20_000 TPS * 5% max stake per validator / (minimum) 4 blocks per round
1973            // = 250 transactions per block maximum Using a higher limit
1974            // that is 512, to account for bursty traffic and system transactions.
1975            consensus_max_num_transactions_in_block: Some(512),
1976
1977            max_deferral_rounds_for_congestion_control: Some(10),
1978
1979            min_checkpoint_interval_ms: Some(200),
1980
1981            checkpoint_summary_version_specific_data: Some(1),
1982
1983            max_soft_bundle_size: Some(5),
1984
1985            bridge_should_try_to_finalize_committee: None,
1986
1987            max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
1988
1989            max_committee_members_count: None,
1990
1991            consensus_gc_depth: None,
1992
1993            consensus_max_acknowledgments_per_block: None,
1994
1995            max_congestion_limit_overshoot_per_commit: None,
1996            // When adding a new constant, set it to None in the earliest version, like this:
1997            // new_constant: None,
1998        };
1999
2000        cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2001
2002        // MoveVM related flags
2003        {
2004            cfg.feature_flags
2005                .disable_invariant_violation_check_in_swap_loc = true;
2006            cfg.feature_flags.no_extraneous_module_bytes = true;
2007            cfg.feature_flags.hardened_otw_check = true;
2008            cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2009        }
2010
2011        // zkLogin related flags
2012        {
2013            cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2014        }
2015
2016        // Enable Mysticeti on mainnet.
2017        cfg.feature_flags.consensus_choice = ConsensusChoice::Mysticeti;
2018        // Use tonic networking for Mysticeti.
2019        cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2020
2021        cfg.feature_flags.per_object_congestion_control_mode =
2022            PerObjectCongestionControlMode::TotalTxCount;
2023
2024        // Do not allow bridge committee to finalize on mainnet.
2025        cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2026
2027        // Devnet
2028        if chain != Chain::Mainnet && chain != Chain::Testnet {
2029            cfg.feature_flags.enable_poseidon = true;
2030            cfg.poseidon_bn254_cost_base = Some(260);
2031            cfg.poseidon_bn254_cost_per_block = Some(10);
2032
2033            cfg.feature_flags.enable_group_ops_native_function_msm = true;
2034
2035            cfg.feature_flags.enable_vdf = true;
2036            // Set to 30x and 2x the cost of a signature verification for now. This
2037            // should be updated along with other native crypto functions.
2038            cfg.vdf_verify_vdf_cost = Some(1500);
2039            cfg.vdf_hash_to_input_cost = Some(100);
2040
2041            cfg.feature_flags.passkey_auth = true;
2042        }
2043
2044        for cur in 2..=version.0 {
2045            match cur {
2046                1 => unreachable!(),
2047                // version 2 is a new framework version but with no config changes
2048                2 => {}
2049                3 => {
2050                    cfg.feature_flags.relocate_event_module = true;
2051                }
2052                4 => {
2053                    cfg.max_type_to_layout_nodes = Some(512);
2054                }
2055                5 => {
2056                    cfg.feature_flags.protocol_defined_base_fee = true;
2057                    cfg.base_gas_price = Some(1000);
2058
2059                    cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2060                    cfg.feature_flags.convert_type_argument_error = true;
2061                    cfg.feature_flags.native_charging_v2 = true;
2062
2063                    if chain != Chain::Mainnet && chain != Chain::Testnet {
2064                        cfg.feature_flags.uncompressed_g1_group_elements = true;
2065                    }
2066
2067                    cfg.gas_model_version = Some(2);
2068
2069                    cfg.poseidon_bn254_cost_per_block = Some(388);
2070
2071                    cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2072                    cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2073                    cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2074                    cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2075                    cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2076                    cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2077                    cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2078                    cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2079
2080                    // Manually changed to be "under cost"
2081                    cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2082                    cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2083                    cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2084                    cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2085
2086                    cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2087                    cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2088                    cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2089                    cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2090                        Some(8213);
2091                    cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2092                    cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2093                        Some(9484);
2094
2095                    cfg.hash_keccak256_cost_base = Some(10);
2096                    cfg.hash_blake2b256_cost_base = Some(10);
2097
2098                    // group ops
2099                    cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2100                    cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2101                    cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2102                    cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2103
2104                    cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2105                    cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2106                    cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2107                    cfg.group_ops_bls12381_gt_add_cost = Some(188);
2108
2109                    cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2110                    cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2111                    cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2112                    cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2113
2114                    cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2115                    cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2116                    cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2117                    cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2118
2119                    cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2120                    cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2121                    cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2122                    cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2123
2124                    cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2125                    cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2126
2127                    cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2128                    cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2129                    cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2130                    cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2131
2132                    cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2133                    cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2134                    cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2135                    cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2136                    cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2137
2138                    cfg.group_ops_bls12381_pairing_cost = Some(26897);
2139
2140                    cfg.validator_validate_metadata_cost_base = Some(20000);
2141
2142                    cfg.max_committee_members_count = Some(50);
2143                }
2144                6 => {
2145                    cfg.max_ptb_value_size = Some(1024 * 1024);
2146                }
2147                7 => {
2148                    // version 7 is a new framework version but with no config
2149                    // changes
2150                }
2151                8 => {
2152                    cfg.feature_flags.variant_nodes = true;
2153
2154                    if chain != Chain::Mainnet {
2155                        // Enable round prober in consensus.
2156                        cfg.feature_flags.consensus_round_prober = true;
2157                        // Enable distributed vote scoring.
2158                        cfg.feature_flags
2159                            .consensus_distributed_vote_scoring_strategy = true;
2160                        cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2161                        // Enable smart ancestor selection for testnet
2162                        cfg.feature_flags.consensus_smart_ancestor_selection = true;
2163                        // Enable probing for accepted rounds in round prober for testnet
2164                        cfg.feature_flags
2165                            .consensus_round_prober_probe_accepted_rounds = true;
2166                        // Enable zstd compression for consensus in testnet
2167                        cfg.feature_flags.consensus_zstd_compression = true;
2168                        // Assuming a round rate of max 15/sec, then using a gc depth of 60 allow
2169                        // blocks within a window of ~4 seconds
2170                        // to be included before be considered garbage collected.
2171                        cfg.consensus_gc_depth = Some(60);
2172                    }
2173
2174                    // Enable min_free_execution_slot for the shared object congestion tracker in
2175                    // devnet.
2176                    if chain != Chain::Testnet && chain != Chain::Mainnet {
2177                        cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2178                    }
2179                }
2180                9 => {
2181                    if chain != Chain::Mainnet {
2182                        // Disable smart ancestor selection in the testnet and devnet.
2183                        cfg.feature_flags.consensus_smart_ancestor_selection = false;
2184                    }
2185
2186                    // Enable zstd compression for consensus
2187                    cfg.feature_flags.consensus_zstd_compression = true;
2188
2189                    // Enable passkey in multisig in devnet.
2190                    if chain != Chain::Testnet && chain != Chain::Mainnet {
2191                        cfg.feature_flags.accept_passkey_in_multisig = true;
2192                    }
2193
2194                    // this flag is now deprecated because of the bridge removal.
2195                    cfg.bridge_should_try_to_finalize_committee = None;
2196                }
2197                10 => {
2198                    // Enable min_free_execution_slot for the shared object congestion tracker in
2199                    // all networks.
2200                    cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2201
2202                    // Increase the committee size to 80 on all networks.
2203                    cfg.max_committee_members_count = Some(80);
2204
2205                    // Enable round prober in consensus.
2206                    cfg.feature_flags.consensus_round_prober = true;
2207                    // Enable probing for accepted rounds in round.
2208                    cfg.feature_flags
2209                        .consensus_round_prober_probe_accepted_rounds = true;
2210                    // Enable distributed vote scoring.
2211                    cfg.feature_flags
2212                        .consensus_distributed_vote_scoring_strategy = true;
2213                    // Enable the new consensus commit rule.
2214                    cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2215
2216                    // Enable consensus garbage collection
2217                    // Assuming a round rate of max 15/sec, then using a gc depth of 60 allow
2218                    // blocks within a window of ~4 seconds
2219                    // to be included before be considered garbage collected.
2220                    cfg.consensus_gc_depth = Some(60);
2221
2222                    // Enable minimized child object mutation counting.
2223                    cfg.feature_flags.minimize_child_object_mutations = true;
2224
2225                    if chain != Chain::Mainnet {
2226                        // Enable batched block sync in devnet and testnet.
2227                        cfg.feature_flags.consensus_batched_block_sync = true;
2228                    }
2229
2230                    if chain != Chain::Testnet && chain != Chain::Mainnet {
2231                        // Enable the gas price feedback mechanism (which is used for
2232                        // transactions cancelled due to shared object congestion) in devnet
2233                        cfg.feature_flags
2234                            .congestion_control_gas_price_feedback_mechanism = true;
2235                    }
2236
2237                    cfg.feature_flags.validate_identifier_inputs = true;
2238                    cfg.feature_flags.dependency_linkage_error = true;
2239                    cfg.feature_flags.additional_multisig_checks = true;
2240                }
2241                11 => {
2242                    // version 11 is a new framework version but with no config
2243                    // changes
2244                }
2245                12 => {
2246                    // Enable the gas price feedback mechanism for transactions
2247                    // cancelled due to congestion in all networks
2248                    cfg.feature_flags
2249                        .congestion_control_gas_price_feedback_mechanism = true;
2250
2251                    // Enable normalization of PTB arguments in all networks.
2252                    cfg.feature_flags.normalize_ptb_arguments = true;
2253                }
2254                13 => {
2255                    // Enable selecting committee based on eligible active validators on all
2256                    // networks.
2257                    cfg.feature_flags.select_committee_from_eligible_validators = true;
2258                    // Enable tracking non-committee eligible active
2259                    // validators on all networks.
2260                    cfg.feature_flags.track_non_committee_eligible_validators = true;
2261
2262                    if chain != Chain::Testnet && chain != Chain::Mainnet {
2263                        // Enable selecting committee only from active validators that next epoch
2264                        // version and issued valid AuthorityCapabilities notification in devnet.
2265                        cfg.feature_flags
2266                            .select_committee_supporting_next_epoch_version = true;
2267                    }
2268                }
2269                14 => {
2270                    // Enable batched block sync for mainnet.
2271                    cfg.feature_flags.consensus_batched_block_sync = true;
2272
2273                    if chain != Chain::Mainnet {
2274                        // Enable median-based commit timestamp calculation in consensus and
2275                        // enforce checkpoint timestamp monotonicity for testnet.
2276                        cfg.feature_flags
2277                            .consensus_median_timestamp_with_checkpoint_enforcement = true;
2278                        // Enable selecting committee only from active validators that support the
2279                        // next epoch's version and issued valid AuthorityCapabilities notification
2280                        // in testnet.
2281                        cfg.feature_flags
2282                            .select_committee_supporting_next_epoch_version = true;
2283                    }
2284                    if chain != Chain::Testnet && chain != Chain::Mainnet {
2285                        // Switch consensus protocol to Starfish in devnet
2286                        cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2287                    }
2288                }
2289                15 => {
2290                    if chain != Chain::Mainnet && chain != Chain::Testnet {
2291                        // Enable overshoot of 100 in congestion control. This allows bursts of
2292                        // shared object transactions up to 10 times the average allowable
2293                        // load set by `max_accumulated_txn_cost_per_object_in_mysticeti_commit`.
2294                        cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2295                    }
2296                }
2297                // Use this template when making changes:
2298                //
2299                //     // modify an existing constant.
2300                //     move_binary_format_version: Some(7),
2301                //
2302                //     // Add a new constant (which is set to None in prior versions).
2303                //     new_constant: Some(new_value),
2304                //
2305                //     // Remove a constant (ensure that it is never accessed during this version).
2306                //     max_move_object_size: None,
2307                _ => panic!("unsupported version {version:?}"),
2308            }
2309        }
2310        cfg
2311    }
2312
2313    // Extract the bytecode verifier config from this protocol config. `for_signing`
2314    // indicates whether this config is used for verification during signing or
2315    // execution.
2316    pub fn verifier_config(&self, signing_limits: Option<(usize, usize)>) -> VerifierConfig {
2317        let (max_back_edges_per_function, max_back_edges_per_module) = if let Some((
2318            max_back_edges_per_function,
2319            max_back_edges_per_module,
2320        )) = signing_limits
2321        {
2322            (
2323                Some(max_back_edges_per_function),
2324                Some(max_back_edges_per_module),
2325            )
2326        } else {
2327            (None, None)
2328        };
2329
2330        VerifierConfig {
2331            max_loop_depth: Some(self.max_loop_depth() as usize),
2332            max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2333            max_function_parameters: Some(self.max_function_parameters() as usize),
2334            max_basic_blocks: Some(self.max_basic_blocks() as usize),
2335            max_value_stack_size: self.max_value_stack_size() as usize,
2336            max_type_nodes: Some(self.max_type_nodes() as usize),
2337            max_push_size: Some(self.max_push_size() as usize),
2338            max_dependency_depth: Some(self.max_dependency_depth() as usize),
2339            max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2340            max_function_definitions: Some(self.max_function_definitions() as usize),
2341            max_data_definitions: Some(self.max_struct_definitions() as usize),
2342            max_constant_vector_len: Some(self.max_move_vector_len()),
2343            max_back_edges_per_function,
2344            max_back_edges_per_module,
2345            max_basic_blocks_in_script: None,
2346            max_identifier_len: self.max_move_identifier_len_as_option(), /* Before protocol
2347                                                                           * version 9, there was
2348                                                                           * no limit */
2349            bytecode_version: self.move_binary_format_version(),
2350            max_variants_in_enum: self.max_move_enum_variants_as_option(),
2351        }
2352    }
2353
2354    /// Override one or more settings in the config, for testing.
2355    /// This must be called at the beginning of the test, before
2356    /// get_for_(min|max)_version is called, since those functions cache
2357    /// their return value.
2358    pub fn apply_overrides_for_testing(
2359        override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
2360    ) -> OverrideGuard {
2361        CONFIG_OVERRIDE.with(|ovr| {
2362            let mut cur = ovr.borrow_mut();
2363            assert!(cur.is_none(), "config override already present");
2364            *cur = Some(Box::new(override_fn));
2365            OverrideGuard
2366        })
2367    }
2368}
2369
2370// Setters for tests.
2371// This is only needed for feature_flags. Please suffix each setter with
2372// `_for_testing`. Non-feature_flags should already have test setters defined
2373// through macros.
2374impl ProtocolConfig {
2375    pub fn set_zklogin_auth_for_testing(&mut self, val: bool) {
2376        self.feature_flags.zklogin_auth = val
2377    }
2378    pub fn set_enable_jwk_consensus_updates_for_testing(&mut self, val: bool) {
2379        self.feature_flags.enable_jwk_consensus_updates = val
2380    }
2381
2382    pub fn set_accept_zklogin_in_multisig_for_testing(&mut self, val: bool) {
2383        self.feature_flags.accept_zklogin_in_multisig = val
2384    }
2385
2386    pub fn set_per_object_congestion_control_mode_for_testing(
2387        &mut self,
2388        val: PerObjectCongestionControlMode,
2389    ) {
2390        self.feature_flags.per_object_congestion_control_mode = val;
2391    }
2392
2393    pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
2394        self.feature_flags.consensus_choice = val;
2395    }
2396
2397    pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
2398        self.feature_flags.consensus_network = val;
2399    }
2400
2401    pub fn set_zklogin_max_epoch_upper_bound_delta_for_testing(&mut self, val: Option<u64>) {
2402        self.feature_flags.zklogin_max_epoch_upper_bound_delta = val
2403    }
2404
2405    pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
2406        self.feature_flags.passkey_auth = val
2407    }
2408
2409    pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
2410        self.feature_flags
2411            .disallow_new_modules_in_deps_only_packages = val;
2412    }
2413
2414    pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
2415        self.feature_flags.consensus_round_prober = val;
2416    }
2417
2418    pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
2419        self.feature_flags
2420            .consensus_distributed_vote_scoring_strategy = val;
2421    }
2422
2423    pub fn set_gc_depth_for_testing(&mut self, val: u32) {
2424        self.consensus_gc_depth = Some(val);
2425    }
2426
2427    pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
2428        self.feature_flags.consensus_linearize_subdag_v2 = val;
2429    }
2430
2431    pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
2432        self.feature_flags
2433            .consensus_round_prober_probe_accepted_rounds = val;
2434    }
2435
2436    pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
2437        self.feature_flags.accept_passkey_in_multisig = val;
2438    }
2439
2440    pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
2441        self.feature_flags.consensus_smart_ancestor_selection = val;
2442    }
2443
2444    pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
2445        self.feature_flags.consensus_batched_block_sync = val;
2446    }
2447
2448    pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
2449        self.feature_flags
2450            .congestion_control_min_free_execution_slot = val;
2451    }
2452
2453    pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
2454        self.feature_flags
2455            .congestion_control_gas_price_feedback_mechanism = val;
2456    }
2457    pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
2458        self.feature_flags.select_committee_from_eligible_validators = val;
2459    }
2460
2461    pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
2462        self.feature_flags.track_non_committee_eligible_validators = val;
2463    }
2464
2465    pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
2466        self.feature_flags
2467            .select_committee_supporting_next_epoch_version = val;
2468    }
2469
2470    pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
2471        &mut self,
2472        val: bool,
2473    ) {
2474        self.feature_flags
2475            .consensus_median_timestamp_with_checkpoint_enforcement = val;
2476    }
2477}
2478
2479type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
2480
2481thread_local! {
2482    static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
2483}
2484
2485#[must_use]
2486pub struct OverrideGuard;
2487
2488impl Drop for OverrideGuard {
2489    fn drop(&mut self) {
2490        info!("restoring override fn");
2491        CONFIG_OVERRIDE.with(|ovr| {
2492            *ovr.borrow_mut() = None;
2493        });
2494    }
2495}
2496
2497/// Defines which limit got crossed.
2498/// The value which crossed the limit and value of the limit crossed are
2499/// embedded
2500#[derive(PartialEq, Eq)]
2501pub enum LimitThresholdCrossed {
2502    None,
2503    Soft(u128, u128),
2504    Hard(u128, u128),
2505}
2506
2507/// Convenience function for comparing limit ranges
2508/// V::MAX must be at >= U::MAX and T::MAX
2509pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
2510    x: T,
2511    soft_limit: U,
2512    hard_limit: V,
2513) -> LimitThresholdCrossed {
2514    let x: V = x.into();
2515    let soft_limit: V = soft_limit.into();
2516
2517    debug_assert!(soft_limit <= hard_limit);
2518
2519    // It is important to preserve this comparison order because if soft_limit ==
2520    // hard_limit we want LimitThresholdCrossed::Hard
2521    if x >= hard_limit {
2522        LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
2523    } else if x < soft_limit {
2524        LimitThresholdCrossed::None
2525    } else {
2526        LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
2527    }
2528}
2529
2530#[macro_export]
2531macro_rules! check_limit {
2532    ($x:expr, $hard:expr) => {
2533        check_limit!($x, $hard, $hard)
2534    };
2535    ($x:expr, $soft:expr, $hard:expr) => {
2536        check_limit_in_range($x as u64, $soft, $hard)
2537    };
2538}
2539
2540/// Used to check which limits were crossed if the TX is metered (not system tx)
2541/// Args are: is_metered, value_to_check, metered_limit, unmetered_limit
2542/// metered_limit is always less than or equal to unmetered_hard_limit
2543#[macro_export]
2544macro_rules! check_limit_by_meter {
2545    ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
2546        // If this is metered, we use the metered_limit limit as the upper bound
2547        let (h, metered_str) = if $is_metered {
2548            ($metered_limit, "metered")
2549        } else {
2550            // Unmetered gets more headroom
2551            ($unmetered_hard_limit, "unmetered")
2552        };
2553        use iota_protocol_config::check_limit_in_range;
2554        let result = check_limit_in_range($x as u64, $metered_limit, h);
2555        match result {
2556            LimitThresholdCrossed::None => {}
2557            LimitThresholdCrossed::Soft(_, _) => {
2558                $metric.with_label_values(&[metered_str, "soft"]).inc();
2559            }
2560            LimitThresholdCrossed::Hard(_, _) => {
2561                $metric.with_label_values(&[metered_str, "hard"]).inc();
2562            }
2563        };
2564        result
2565    }};
2566}
2567
2568#[cfg(all(test, not(msim)))]
2569mod test {
2570    use insta::assert_yaml_snapshot;
2571
2572    use super::*;
2573
2574    #[test]
2575    fn snapshot_tests() {
2576        println!("\n============================================================================");
2577        println!("!                                                                          !");
2578        println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
2579        println!("!                                                                          !");
2580        println!("============================================================================\n");
2581        for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
2582            // make Chain::Unknown snapshots compatible with pre-chain-id snapshots so that
2583            // we don't break the release-time compatibility tests. Once Chain
2584            // Id configs have been released everywhere, we can remove this and
2585            // only test Mainnet and Testnet
2586            let chain_str = match chain_id {
2587                Chain::Unknown => "".to_string(),
2588                _ => format!("{chain_id:?}_"),
2589            };
2590            for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
2591                let cur = ProtocolVersion::new(i);
2592                assert_yaml_snapshot!(
2593                    format!("{}version_{}", chain_str, cur.as_u64()),
2594                    ProtocolConfig::get_for_version(cur, *chain_id)
2595                );
2596            }
2597        }
2598    }
2599
2600    #[test]
2601    fn test_getters() {
2602        let prot: ProtocolConfig =
2603            ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2604        assert_eq!(
2605            prot.max_arguments(),
2606            prot.max_arguments_as_option().unwrap()
2607        );
2608    }
2609
2610    #[test]
2611    fn test_setters() {
2612        let mut prot: ProtocolConfig =
2613            ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2614        prot.set_max_arguments_for_testing(123);
2615        assert_eq!(prot.max_arguments(), 123);
2616
2617        prot.set_max_arguments_from_str_for_testing("321".to_string());
2618        assert_eq!(prot.max_arguments(), 321);
2619
2620        prot.disable_max_arguments_for_testing();
2621        assert_eq!(prot.max_arguments_as_option(), None);
2622
2623        prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
2624        assert_eq!(prot.max_arguments(), 456);
2625    }
2626
2627    #[test]
2628    #[should_panic(expected = "unsupported version")]
2629    fn max_version_test() {
2630        // When this does not panic, version higher than MAX_PROTOCOL_VERSION exists.
2631        // To fix, bump MAX_PROTOCOL_VERSION or disable this check for the version.
2632        let _ = ProtocolConfig::get_for_version_impl(
2633            ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
2634            Chain::Unknown,
2635        );
2636    }
2637
2638    #[test]
2639    fn lookup_by_string_test() {
2640        let prot: ProtocolConfig =
2641            ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2642        // Does not exist
2643        assert!(prot.lookup_attr("some random string".to_string()).is_none());
2644
2645        assert!(
2646            prot.lookup_attr("max_arguments".to_string())
2647                == Some(ProtocolConfigValue::u32(prot.max_arguments())),
2648        );
2649
2650        // We didnt have this in version 1 on Mainnet
2651        assert!(
2652            prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2653                .is_none()
2654        );
2655        assert!(
2656            prot.attr_map()
2657                .get("poseidon_bn254_cost_base")
2658                .unwrap()
2659                .is_none()
2660        );
2661
2662        // But we did in version 1 on Devnet
2663        let prot: ProtocolConfig =
2664            ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2665
2666        assert!(
2667            prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2668                == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2669        );
2670        assert!(
2671            prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
2672                == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2673        );
2674
2675        // Check feature flags
2676        let prot: ProtocolConfig =
2677            ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2678        // Does not exist
2679        assert!(
2680            prot.feature_flags
2681                .lookup_attr("some random string".to_owned())
2682                .is_none()
2683        );
2684        assert!(
2685            !prot
2686                .feature_flags
2687                .attr_map()
2688                .contains_key("some random string")
2689        );
2690
2691        // Was false in v1 on Mainnet
2692        assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
2693        assert!(
2694            prot.feature_flags
2695                .attr_map()
2696                .get("enable_poseidon")
2697                .unwrap()
2698                == &false
2699        );
2700        let prot: ProtocolConfig =
2701            ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2702        // Was true from v1 and up on Devnet
2703        assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
2704        assert!(
2705            prot.feature_flags
2706                .attr_map()
2707                .get("enable_poseidon")
2708                .unwrap()
2709                == &true
2710        );
2711    }
2712
2713    #[test]
2714    fn limit_range_fn_test() {
2715        let low = 100u32;
2716        let high = 10000u64;
2717
2718        assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
2719        assert!(matches!(
2720            check_limit!(255u16, low, high),
2721            LimitThresholdCrossed::Soft(255u128, 100)
2722        ));
2723        // This wont compile because lossy
2724        // assert!(check_limit!(100000000u128, low, high) ==
2725        // LimitThresholdCrossed::None); This wont compile because lossy
2726        // assert!(check_limit!(100000000usize, low, high) ==
2727        // LimitThresholdCrossed::None);
2728
2729        assert!(matches!(
2730            check_limit!(2550000u64, low, high),
2731            LimitThresholdCrossed::Hard(2550000, 10000)
2732        ));
2733
2734        assert!(matches!(
2735            check_limit!(2550000u64, high, high),
2736            LimitThresholdCrossed::Hard(2550000, 10000)
2737        ));
2738
2739        assert!(matches!(
2740            check_limit!(1u8, high),
2741            LimitThresholdCrossed::None
2742        ));
2743
2744        assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
2745
2746        assert!(matches!(
2747            check_limit!(2550000u64, high),
2748            LimitThresholdCrossed::Hard(2550000, 10000)
2749        ));
2750    }
2751}