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