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