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