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