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