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