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