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