sui_protocol_config/
lib.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use std::{
5    cell::RefCell,
6    collections::BTreeSet,
7    sync::atomic::{AtomicBool, Ordering},
8};
9
10use clap::*;
11use fastcrypto::encoding::{Base58, Encoding, Hex};
12use move_binary_format::{
13    binary_config::{BinaryConfig, TableConfig},
14    file_format_common::VERSION_1,
15};
16use move_vm_config::verifier::VerifierConfig;
17use mysten_common::in_integration_test;
18use serde::{Deserialize, Serialize};
19use serde_with::skip_serializing_none;
20use sui_protocol_config_macros::{
21    ProtocolConfigAccessors, ProtocolConfigFeatureFlagsGetters, ProtocolConfigOverride,
22};
23use tracing::{info, warn};
24
25/// The minimum and maximum protocol versions supported by this build.
26const MIN_PROTOCOL_VERSION: u64 = 1;
27const MAX_PROTOCOL_VERSION: u64 = 114;
28
29// Record history of protocol version allocations here:
30//
31// Version 1: Original version.
32// Version 2: Framework changes, including advancing epoch_start_time in safemode.
33// Version 3: gas model v2, including all sui conservation fixes. Fix for loaded child object
34//            changes, enable package upgrades, add limits on `max_size_written_objects`,
35//            `max_size_written_objects_system_tx`
36// Version 4: New reward slashing rate. Framework changes to skip stake susbidy when the epoch
37//            length is short.
38// Version 5: Package upgrade compatibility error fix. New gas cost table. New scoring decision
39//            mechanism that includes up to f scoring authorities.
40// Version 6: Change to how bytes are charged in the gas meter, increase buffer stake to 0.5f
41// Version 7: Disallow adding new abilities to types during package upgrades,
42//            disable_invariant_violation_check_in_swap_loc,
43//            disable init functions becoming entry,
44//            hash module bytes individually before computing package digest.
45// Version 8: Disallow changing abilities and type constraints for type parameters in structs
46//            during upgrades.
47// Version 9: Limit the length of Move idenfitiers to 128.
48//            Disallow extraneous module bytes,
49//            advance_to_highest_supported_protocol_version,
50// Version 10:increase bytecode verifier `max_verifier_meter_ticks_per_function` and
51//            `max_meter_ticks_per_module` limits each from 6_000_000 to 16_000_000. sui-system
52//            framework changes.
53// Version 11: Introduce `std::type_name::get_with_original_ids` to the system frameworks. Bound max depth of values within the VM.
54// Version 12: Changes to deepbook in framework to add API for querying marketplace.
55//             Change NW Batch to use versioned metadata field.
56//             Changes to sui-system package to add PTB-friendly unstake function, and minor cleanup.
57// Version 13: System package change deprecating `0xdee9::clob` and `0xdee9::custodian`, replaced by
58//             `0xdee9::clob_v2` and `0xdee9::custodian_v2`.
59// Version 14: Introduce a config variable to allow charging of computation to be either
60//             bucket base or rounding up. The presence of `gas_rounding_step` (or `None`)
61//             decides whether rounding is applied or not.
62// Version 15: Add reordering of user transactions by gas price after consensus.
63//             Add `sui::table_vec::drop` to the framework via a system package upgrade.
64// Version 16: Enabled simplified_unwrap_then_delete feature flag, which allows the execution engine
65//             to no longer consult the object store when generating unwrapped_then_deleted in the
66//             effects; this also allows us to stop including wrapped tombstones in accumulator.
67//             Add self-matching prevention for deepbook.
68// Version 17: Enable upgraded multisig support.
69// Version 18: Introduce execution layer versioning, preserve all existing behaviour in v0.
70//             Gas minimum charges moved to be a multiplier over the reference gas price. In this
71//             protocol version the multiplier is the same as the lowest bucket of computation
72//             such that the minimum transaction cost is the same as the minimum computation
73//             bucket.
74//             Add a feature flag to indicate the changes semantics of `base_tx_cost_fixed`.
75// Version 19: Changes to sui-system package to enable liquid staking.
76//             Add limit for total size of events.
77//             Increase limit for number of events emitted to 1024.
78// Version 20: Enables the flag `narwhal_new_leader_election_schedule` for the new narwhal leader
79//             schedule algorithm for enhanced fault tolerance and sets the bad node stake threshold
80//             value. Both values are set for all the environments except mainnet.
81// Version 21: ZKLogin known providers.
82// Version 22: Child object format change.
83// Version 23: Enabling the flag `narwhal_new_leader_election_schedule` for the new narwhal leader
84//             schedule algorithm for enhanced fault tolerance and sets the bad node stake threshold
85//             value for mainnet.
86// Version 24: Re-enable simple gas conservation checks.
87//             Package publish/upgrade number in a single transaction limited.
88//             JWK / authenticator state flags.
89// Version 25: Add sui::table_vec::swap and sui::table_vec::swap_remove to system packages.
90// Version 26: New gas model version.
91//             Add support for receiving objects off of other objects in devnet only.
92// Version 28: Add sui::zklogin::verify_zklogin_id and related functions to sui framework.
93//             Enable transaction effects v2 in devnet.
94// Version 29: Add verify_legacy_zklogin_address flag to sui framework, this add ability to verify
95//             transactions from a legacy zklogin address.
96// Version 30: Enable Narwhal CertificateV2
97//             Add support for random beacon.
98//             Enable transaction effects v2 in testnet.
99//             Deprecate supported oauth providers from protocol config and rely on node config
100//             instead.
101//             In execution, has_public_transfer is recomputed when loading the object.
102//             Add support for shared obj deletion and receiving objects off of other objects in devnet only.
103// Version 31: Add support for shared object deletion in devnet only.
104//             Add support for getting object ID referenced by receiving object in sui framework.
105//             Create new execution layer version, and preserve previous behavior in v1.
106//             Update semantics of `sui::transfer::receive` and add `sui::transfer::public_receive`.
107// Version 32: Add delete functions for VerifiedID and VerifiedIssuer.
108//             Add sui::token module to sui framework.
109//             Enable transfer to object in testnet.
110//             Enable Narwhal CertificateV2 on mainnet
111//             Make critbit tree and order getters public in deepbook.
112// Version 33: Add support for `receiving_object_id` function in framework
113//             Hardened OTW check.
114//             Enable transfer-to-object in mainnet.
115//             Enable shared object deletion in testnet.
116//             Enable effects v2 in mainnet.
117// Version 34: Framework changes for random beacon.
118// Version 35: Add poseidon hash function.
119//             Enable coin deny list.
120// Version 36: Enable group operations native functions in devnet.
121//             Enable shared object deletion in mainnet.
122//             Set the consensus accepted transaction size and the included transactions size in the proposed block.
123// Version 37: Reject entry functions with mutable Random.
124// Version 38: Introduce limits for binary tables size.
125// Version 39: Allow skipped epochs for randomness updates.
126//             Extra version to fix `test_upgrade_compatibility` simtest.
127// Version 40:
128// Version 41: Enable group operations native functions in testnet and mainnet (without msm).
129// Version 42: Migrate sui framework and related code to Move 2024
130// Version 43: Introduce the upper bound delta config for a zklogin signature's max epoch.
131//             Introduce an explicit parameter for the tick limit per package (previously this was
132//             represented by the parameter for the tick limit per module).
133// Version 44: Enable consensus fork detection on mainnet.
134//             Switch between Narwhal and Mysticeti consensus in tests, devnet and testnet.
135// Version 45: Use tonic networking for Mysticeti consensus.
136//             Set min Move binary format version to 6.
137//             Enable transactions to be signed with zkLogin inside multisig signature.
138//             Add native bridge.
139//             Enable native bridge in devnet
140//             Enable Leader Scoring & Schedule Change for Mysticeti consensus on testnet.
141// Version 46: Enable native bridge in testnet
142//             Enable resharing at the same initial shared version.
143// Version 47: Deepbook changes (framework update)
144// Version 48: Use tonic networking for Mysticeti.
145//             Resolve Move abort locations to the package id instead of the runtime module ID.
146//             Enable random beacon in testnet.
147//             Use new VM when verifying framework packages.
148// Version 49: Enable Move enums on devnet.
149//             Enable VDF in devnet
150//             Enable consensus commit prologue V3 in devnet.
151//             Run Mysticeti consensus by default.
152// Version 50: Add update_node_url to native bridge,
153//             New Move stdlib integer modules
154//             Enable checkpoint batching in testnet.
155//             Prepose consensus commit prologue in checkpoints.
156//             Set number of leaders per round for Mysticeti commits.
157// Version 51: Switch to DKG V1.
158//             Enable deny list v2 on devnet.
159// Version 52: Emit `CommitteeMemberUrlUpdateEvent` when updating bridge node url.
160//             std::config native functions.
161//             Modified sui-system package to enable withdrawal of stake before it becomes active.
162//             Enable soft bundle in devnet and testnet.
163//             Core macro visibility in sui core framework.
164//             Enable checkpoint batching in mainnet.
165//             Enable Mysticeti on mainnet.
166//             Enable Leader Scoring & Schedule Change for Mysticeti consensus on mainnet.
167//             Turn on count based shared object congestion control in devnet.
168//             Enable consensus commit prologue V3 in testnet.
169//             Enable enums on testnet.
170//             Add support for passkey in devnet.
171//             Enable deny list v2 on testnet and mainnet.
172// Version 53: Add feature flag to decide whether to attempt to finalize bridge committee
173//             Enable consensus commit prologue V3 on testnet.
174//             Turn on shared object congestion control in testnet.
175//             Update stdlib natives costs
176// Version 54: Enable random beacon on mainnet.
177//             Enable soft bundle on mainnet.
178// Version 55: Enable enums on mainnet.
179//             Rethrow serialization type layout errors instead of converting them.
180// Version 56: Enable bridge on mainnet.
181//             Note: do not use version 56 for any new features.
182// Version 57: Reduce minimum number of random beacon shares.
183// Version 58: Optimize boolean binops
184//             Finalize bridge committee on mainnet.
185//             Switch to distributed vote scoring in consensus in devnet
186// Version 59: Enable round prober in consensus.
187// Version 60: Validation of public inputs for Groth16 verification.
188//             Enable configuration of maximum number of type nodes in a type layout.
189// Version 61: Switch to distributed vote scoring in consensus in testnet
190//             Further reduce minimum number of random beacon shares.
191//             Add feature flag for Mysticeti fastpath.
192// Version 62: Makes the event's sending module package upgrade-aware.
193// Version 63: Enable gas based congestion control in consensus commit.
194// Version 64: Revert congestion control change.
195// Version 65: Enable distributed vote scoring in mainnet.
196// Version 66: Revert distributed vote scoring in mainnet.
197//             Framework fix for fungible staking book-keeping.
198// Version 67: Re-enable distributed vote scoring in mainnet.
199// Version 68: Add G1Uncompressed group to group ops.
200//             Update to Move stdlib.
201//             Enable gas based congestion control with overage.
202//             Further reduce minimum number of random beacon shares.
203//             Disallow adding new modules in `deps-only` packages.
204// Version 69: Sets number of rounds allowed for fastpath voting in consensus.
205//             Enable smart ancestor selection in devnet.
206//             Enable G1Uncompressed group in testnet.
207// Version 70: Enable smart ancestor selection in testnet.
208//             Enable probing for accepted rounds in round prober in testnet
209//             Add new gas model version to update charging of native functions.
210//             Add std::uq64_64 module to Move stdlib.
211//             Improve gas/wall time efficiency of some Move stdlib vector functions
212// Version 71: [SIP-45] Enable consensus amplification.
213// Version 72: Fix issue where `convert_type_argument_error` wasn't being used in all cases.
214//             Max gas budget moved to 50_000 SUI
215//             Max gas price moved to 50 SUI
216//             Variants as type nodes.
217// Version 73: Enable new marker table version.
218//             Enable consensus garbage collection and new commit rule for devnet.
219//             Enable zstd compression for consensus tonic network in testnet.
220//             Enable smart ancestor selection in mainnet.
221//             Enable probing for accepted rounds in round prober in mainnet
222// Version 74: Enable load_nitro_attestation move function in sui framework in devnet.
223//             Enable all gas costs for load_nitro_attestation.
224//             Enable zstd compression for consensus tonic network in mainnet.
225//             Enable the new commit rule for devnet.
226// Version 75: Enable passkey auth in testnet.
227// Version 76: Deprecate Deepbook V2 order placement and deposit.
228//             Removes unnecessary child object mutations
229//             Enable passkey auth in multisig for testnet.
230// Version 77: Enable uncompressed point group ops on mainnet.
231//             Enable consensus garbage collection for testnet
232//             Enable the new consensus commit rule for testnet.
233// Version 78: Make `TxContext` Move API native
234//             Enable execution time estimate mode for congestion control on testnet.
235// Version 79: Enable median based commit timestamp in consensus on testnet.
236//             Increase threshold for bad nodes that won't be considered leaders in consensus in testnet
237//             Enable load_nitro_attestation move function in sui framework in testnet.
238//             Enable consensus garbage collection for mainnet
239//             Enable the new consensus commit rule for mainnet.
240// Version 80: Bound size of values created in the adapter.
241// Version 81: Enable median based commit timestamp in consensus on mainnet.
242//             Enforce checkpoint timestamps are non-decreasing for testnet and mainnet.
243//             Increase threshold for bad nodes that won't be considered leaders in consensus in mainnet
244// Version 82: Relax bounding of size of values created in the adapter.
245// Version 83: Resolve `TypeInput` IDs to defining ID when converting to `TypeTag`s in the adapter.
246//             Enable execution time estimate mode for congestion control on mainnet.
247//             Enable nitro attestation upgraded parsing and mainnet.
248// Version 84: Limit number of stored execution time observations between epochs.
249// Version 85: Enable party transfer in devnet.
250// Version 86: Use type tags in the object runtime and adapter instead of `Type`s.
251//             Make variant count limit explicit in protocol config.
252//             Enable party transfer in testnet.
253// Version 87: Enable better type resolution errors in the adapter.
254// Version 88: Update `sui-system` package to use `calculate_rewards` function.
255//             Define the cost for the native Move function `rgp`.
256//             Ignore execution time observations after validator stops accepting certs.
257// Version 89: Add additional signature checks
258//             Add additional linkage checks
259// Version 90: Standard library improvements.
260//             Enable `debug_fatal` on Move invariant violations.
261//             Enable passkey and passkey inside multisig for mainnet.
262// Version 91: Minor changes in Sui Framework. Include CheckpointDigest in consensus dedup key for checkpoint signatures (V2).
263// Version 92: Disable checking shared object transfer restrictions per command = false
264// Version 93: Enable CheckpointDigest in consensus dedup key for checkpoint signatures.
265// Version 94: Decrease stored observations limit by 10% to stay within system object size limit.
266//             Enable party transfer on mainnet.
267// Version 95: Change type name id base cost to 52, increase max transactions per checkpoint to 20000.
268// Version 96: Enable authority capabilities v2.
269//             Fix bug where MFP transaction shared inputs' debts were not loaded
270//             Create Coin Registry object
271//             Enable checkpoint artifacts digest in devnet.
272// Version 97: Enable additional borrow checks
273// Version 98: Add authenticated event streams support via emit_authenticated function.
274//             Add better error messages to the loader.
275// Version 99: Enable new commit handler.
276// Version 100: Framework update
277// Version 101: Framework update
278//              Set max updates per settlement txn to 100.
279// Version 103: Framework update: internal Coin methods
280// Version 104: Framework update: CoinRegistry follow up for Coin methods
281//              Enable all non-zero PCRs parsing for nitro attestation native function in Devnet and Testnet.
282// Version 105: Framework update: address aliases
283//              Enable multi-epoch transaction expiration.
284//              Enable always include required PCRs (0-4 & 8) parsing even if they are zeros for
285//              nitro attestation native function in Devnet and Testnet.
286// Version 106: Framework update: accumulator storage fund calculations
287//              Enable address balances on devnet
288// Version 108: Enable new digit based gas rounding.
289//              Support TxContext in all parameter positions.
290//              Disable entry point signature check.
291//              Enable address aliases on testnet.
292//              Enable poseidon_bn254 on mainnet.
293// Version 109: Update where we set bounds for some binary tables to be a bit more idiomatic.
294// Version 110: Enable parsing on all nonzero custom pcrs in nitro attestation parsing native
295//              function on mainnet.
296//              split_checkpoints_in_consensus_handler in devnet
297//              Enable additional validation on zkLogin public identifier.
298// Version 111: Validator metadata
299// Version 112: Enable Ristretto255 in devnet.
300// Version 113: Validate gas price >= RGP at signing for address balance gas payments.
301// Version 114: Gate seeded test overrides for checkpoint tx limit behind feature flag.
302
303#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
304pub struct ProtocolVersion(u64);
305
306impl ProtocolVersion {
307    // The minimum and maximum protocol version supported by this binary. Counterintuitively, this constant may
308    // change over time as support for old protocol versions is removed from the source. This
309    // ensures that when a new network (such as a testnet) is created, its genesis committee will
310    // use a protocol version that is actually supported by the binary.
311    pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
312
313    pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
314
315    #[cfg(not(msim))]
316    pub const MAX_ALLOWED: Self = Self::MAX;
317
318    // We create one additional "fake" version in simulator builds so that we can test upgrades.
319    #[cfg(msim)]
320    pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
321
322    pub fn new(v: u64) -> Self {
323        Self(v)
324    }
325
326    pub const fn as_u64(&self) -> u64 {
327        self.0
328    }
329
330    // For serde deserialization - we don't define a Default impl because there isn't a single
331    // universally appropriate default value.
332    pub fn max() -> Self {
333        Self::MAX
334    }
335
336    pub fn prev(self) -> Self {
337        Self(self.0.checked_sub(1).unwrap())
338    }
339}
340
341impl From<u64> for ProtocolVersion {
342    fn from(v: u64) -> Self {
343        Self::new(v)
344    }
345}
346
347impl std::ops::Sub<u64> for ProtocolVersion {
348    type Output = Self;
349    fn sub(self, rhs: u64) -> Self::Output {
350        Self::new(self.0 - rhs)
351    }
352}
353
354impl std::ops::Add<u64> for ProtocolVersion {
355    type Output = Self;
356    fn add(self, rhs: u64) -> Self::Output {
357        Self::new(self.0 + rhs)
358    }
359}
360
361#[derive(
362    Clone, Serialize, Deserialize, Debug, Default, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum,
363)]
364pub enum Chain {
365    Mainnet,
366    Testnet,
367    #[default]
368    Unknown,
369}
370
371impl Chain {
372    pub fn as_str(self) -> &'static str {
373        match self {
374            Chain::Mainnet => "mainnet",
375            Chain::Testnet => "testnet",
376            Chain::Unknown => "unknown",
377        }
378    }
379}
380
381pub struct Error(pub String);
382
383// TODO: There are quite a few non boolean values in the feature flags. We should move them out.
384/// Records on/off feature flags that may vary at each protocol version.
385#[derive(Default, Clone, Serialize, Deserialize, Debug, ProtocolConfigFeatureFlagsGetters)]
386struct FeatureFlags {
387    // Add feature flags here, e.g.:
388    // new_protocol_feature: bool,
389    #[serde(skip_serializing_if = "is_false")]
390    package_upgrades: bool,
391    // If true, validators will commit to the root state digest
392    // in end of epoch checkpoint proposals
393    #[serde(skip_serializing_if = "is_false")]
394    commit_root_state_digest: bool,
395    // Pass epoch start time to advance_epoch safe mode function.
396    #[serde(skip_serializing_if = "is_false")]
397    advance_epoch_start_time_in_safe_mode: bool,
398    // If true, apply the fix to correctly capturing loaded child object versions in execution's
399    // object runtime.
400    #[serde(skip_serializing_if = "is_false")]
401    loaded_child_objects_fixed: bool,
402    // If true, treat missing types in the upgraded modules when creating an upgraded package as a
403    // compatibility error.
404    #[serde(skip_serializing_if = "is_false")]
405    missing_type_is_compatibility_error: bool,
406    // If true, then the scoring decision mechanism will not get disabled when we do have more than
407    // f low scoring authorities, but it will simply flag as low scoring only up to f authorities.
408    #[serde(skip_serializing_if = "is_false")]
409    scoring_decision_with_validity_cutoff: bool,
410
411    // DEPRECATED: this was an ephemeral feature flag only used by consensus handler, which has now
412    // been deployed everywhere.
413    #[serde(skip_serializing_if = "is_false")]
414    consensus_order_end_of_epoch_last: bool,
415
416    // Disallow adding abilities to types during package upgrades.
417    #[serde(skip_serializing_if = "is_false")]
418    disallow_adding_abilities_on_upgrade: bool,
419    // Disables unnecessary invariant check in the Move VM when swapping the value out of a local
420    #[serde(skip_serializing_if = "is_false")]
421    disable_invariant_violation_check_in_swap_loc: bool,
422    // advance to highest supported protocol version at epoch change, instead of the next consecutive
423    // protocol version.
424    #[serde(skip_serializing_if = "is_false")]
425    advance_to_highest_supported_protocol_version: bool,
426    // If true, disallow entry modifiers on entry functions
427    #[serde(skip_serializing_if = "is_false")]
428    ban_entry_init: bool,
429    // If true, hash module bytes individually when calculating package digests for upgrades
430    #[serde(skip_serializing_if = "is_false")]
431    package_digest_hash_module: bool,
432    // If true, disallow changing struct type parameters during package upgrades
433    #[serde(skip_serializing_if = "is_false")]
434    disallow_change_struct_type_params_on_upgrade: bool,
435    // If true, checks no extra bytes in a compiled module
436    #[serde(skip_serializing_if = "is_false")]
437    no_extraneous_module_bytes: bool,
438    // If true, then use the versioned metadata format in narwhal entities.
439    #[serde(skip_serializing_if = "is_false")]
440    narwhal_versioned_metadata: bool,
441
442    // Enable zklogin auth
443    #[serde(skip_serializing_if = "is_false")]
444    zklogin_auth: bool,
445    // How we order transactions coming out of consensus before sending to execution.
446    #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
447    consensus_transaction_ordering: ConsensusTransactionOrdering,
448
449    // Previously, the unwrapped_then_deleted field in TransactionEffects makes a distinction between
450    // whether an object has existed in the store previously (i.e. whether there is a tombstone).
451    // Such dependency makes effects generation inefficient, and requires us to include wrapped
452    // tombstone in state root hash.
453    // To prepare for effects V2, with this flag set to true, we simplify the definition of
454    // unwrapped_then_deleted to always include unwrapped then deleted objects,
455    // regardless of their previous state in the store.
456    #[serde(skip_serializing_if = "is_false")]
457    simplified_unwrap_then_delete: bool,
458    // Enable upgraded multisig support
459    #[serde(skip_serializing_if = "is_false")]
460    upgraded_multisig_supported: bool,
461    // If true minimum txn charge is a multiplier of the gas price
462    #[serde(skip_serializing_if = "is_false")]
463    txn_base_cost_as_multiplier: bool,
464
465    // If true, the ability to delete shared objects is in effect
466    #[serde(skip_serializing_if = "is_false")]
467    shared_object_deletion: bool,
468
469    // If true, then the new algorithm for the leader election schedule will be used
470    #[serde(skip_serializing_if = "is_false")]
471    narwhal_new_leader_election_schedule: bool,
472
473    // A list of supported OIDC providers that can be used for zklogin.
474    #[serde(skip_serializing_if = "is_empty")]
475    zklogin_supported_providers: BTreeSet<String>,
476
477    // If true, use the new child object format
478    #[serde(skip_serializing_if = "is_false")]
479    loaded_child_object_format: bool,
480
481    #[serde(skip_serializing_if = "is_false")]
482    enable_jwk_consensus_updates: bool,
483
484    #[serde(skip_serializing_if = "is_false")]
485    end_of_epoch_transaction_supported: bool,
486
487    // Perform simple conservation checks keeping into account out of gas scenarios
488    // while charging for storage.
489    #[serde(skip_serializing_if = "is_false")]
490    simple_conservation_checks: bool,
491
492    // If true, use the new child object format type logging
493    #[serde(skip_serializing_if = "is_false")]
494    loaded_child_object_format_type: bool,
495
496    // Enable receiving sent objects
497    #[serde(skip_serializing_if = "is_false")]
498    receive_objects: bool,
499
500    // If true, include CheckpointDigest in consensus dedup key for checkpoint signatures (V2).
501    #[serde(skip_serializing_if = "is_false")]
502    consensus_checkpoint_signature_key_includes_digest: bool,
503
504    // Enable random beacon protocol
505    #[serde(skip_serializing_if = "is_false")]
506    random_beacon: bool,
507
508    // Enable bridge protocol
509    #[serde(skip_serializing_if = "is_false")]
510    bridge: bool,
511
512    #[serde(skip_serializing_if = "is_false")]
513    enable_effects_v2: bool,
514
515    // If true, then use CertificateV2 in narwhal.
516    #[serde(skip_serializing_if = "is_false")]
517    narwhal_certificate_v2: bool,
518
519    // If true, allow verify with legacy zklogin address
520    #[serde(skip_serializing_if = "is_false")]
521    verify_legacy_zklogin_address: bool,
522
523    // Enable throughput aware consensus submission
524    #[serde(skip_serializing_if = "is_false")]
525    throughput_aware_consensus_submission: bool,
526
527    // If true, recompute has_public_transfer from the type instead of what is stored in the object
528    #[serde(skip_serializing_if = "is_false")]
529    recompute_has_public_transfer_in_execution: bool,
530
531    // If true, multisig containing zkLogin sig is accepted.
532    #[serde(skip_serializing_if = "is_false")]
533    accept_zklogin_in_multisig: bool,
534
535    // If true, multisig containing passkey sig is accepted.
536    #[serde(skip_serializing_if = "is_false")]
537    accept_passkey_in_multisig: bool,
538
539    // If true, additional zkLogin public identifier structure is validated.
540    #[serde(skip_serializing_if = "is_false")]
541    validate_zklogin_public_identifier: bool,
542
543    // If true, consensus prologue transaction also includes the consensus output digest.
544    // It can be used to detect consensus output folk.
545    #[serde(skip_serializing_if = "is_false")]
546    include_consensus_digest_in_prologue: bool,
547
548    // If true, use the hardened OTW check
549    #[serde(skip_serializing_if = "is_false")]
550    hardened_otw_check: bool,
551
552    // If true allow calling receiving_object_id function
553    #[serde(skip_serializing_if = "is_false")]
554    allow_receiving_object_id: bool,
555
556    // Enable the poseidon hash function
557    #[serde(skip_serializing_if = "is_false")]
558    enable_poseidon: bool,
559
560    // If true, enable the coin deny list.
561    #[serde(skip_serializing_if = "is_false")]
562    enable_coin_deny_list: bool,
563
564    // Enable native functions for group operations.
565    #[serde(skip_serializing_if = "is_false")]
566    enable_group_ops_native_functions: bool,
567
568    // Enable native function for msm.
569    #[serde(skip_serializing_if = "is_false")]
570    enable_group_ops_native_function_msm: bool,
571
572    // Enable group operations for Ristretto255
573    #[serde(skip_serializing_if = "is_false")]
574    enable_ristretto255_group_ops: bool,
575
576    // Enable nitro attestation.
577    #[serde(skip_serializing_if = "is_false")]
578    enable_nitro_attestation: bool,
579
580    // Enable upgraded parsing of nitro attestation that interprets pcrs as a map.
581    #[serde(skip_serializing_if = "is_false")]
582    enable_nitro_attestation_upgraded_parsing: bool,
583
584    // Enable upgraded parsing of nitro attestation containing all nonzero PCRs.
585    #[serde(skip_serializing_if = "is_false")]
586    enable_nitro_attestation_all_nonzero_pcrs_parsing: bool,
587
588    // Enable upgraded parsing of nitro attestation to always include required PCRs, even when all zeros.
589    #[serde(skip_serializing_if = "is_false")]
590    enable_nitro_attestation_always_include_required_pcrs_parsing: bool,
591
592    // Reject functions with mutable Random.
593    #[serde(skip_serializing_if = "is_false")]
594    reject_mutable_random_on_entry_functions: bool,
595
596    // Controls the behavior of per object congestion control in consensus handler.
597    #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
598    per_object_congestion_control_mode: PerObjectCongestionControlMode,
599
600    // The consensus protocol to be used for the epoch.
601    #[serde(skip_serializing_if = "ConsensusChoice::is_narwhal")]
602    consensus_choice: ConsensusChoice,
603
604    // Consensus network to use.
605    #[serde(skip_serializing_if = "ConsensusNetwork::is_anemo")]
606    consensus_network: ConsensusNetwork,
607
608    // If true, use the correct (<=) comparison for max_gas_payment_objects instead of (<)
609    #[serde(skip_serializing_if = "is_false")]
610    correct_gas_payment_limit_check: bool,
611
612    // Set the upper bound allowed for max_epoch in zklogin signature.
613    #[serde(skip_serializing_if = "Option::is_none")]
614    zklogin_max_epoch_upper_bound_delta: Option<u64>,
615
616    // Controls leader scoring & schedule change in Mysticeti consensus.
617    #[serde(skip_serializing_if = "is_false")]
618    mysticeti_leader_scoring_and_schedule: bool,
619
620    // Enable resharing of shared objects using the same initial shared version
621    #[serde(skip_serializing_if = "is_false")]
622    reshare_at_same_initial_version: bool,
623
624    // Resolve Move abort locations to the package id instead of the runtime module ID.
625    #[serde(skip_serializing_if = "is_false")]
626    resolve_abort_locations_to_package_id: bool,
627
628    // Enables the use of the Mysticeti committed sub dag digest to the `ConsensusCommitInfo` in checkpoints.
629    // When disabled the default digest is used instead. It's important to have this guarded behind
630    // a flag as it will lead to checkpoint forks.
631    #[serde(skip_serializing_if = "is_false")]
632    mysticeti_use_committed_subdag_digest: bool,
633
634    // Enable VDF
635    #[serde(skip_serializing_if = "is_false")]
636    enable_vdf: bool,
637
638    // Controls whether consensus handler should record consensus determined shared object version
639    // assignments in consensus commit prologue transaction.
640    // The purpose of doing this is to enable replaying transaction without transaction effects.
641    // V2 also records initial shared versions for consensus objects.
642    #[serde(skip_serializing_if = "is_false")]
643    record_consensus_determined_version_assignments_in_prologue: bool,
644    #[serde(skip_serializing_if = "is_false")]
645    record_consensus_determined_version_assignments_in_prologue_v2: bool,
646
647    // Run verification of framework upgrades using a new/fresh VM.
648    #[serde(skip_serializing_if = "is_false")]
649    fresh_vm_on_framework_upgrade: bool,
650
651    // When set to true, the consensus commit prologue transaction will be placed first
652    // in a consensus commit in checkpoints.
653    // If a checkpoint contains multiple consensus commit, say [cm1][cm2]. The each commit's
654    // consensus commit prologue will be the first transaction in each segment:
655    //     [ccp1, rest cm1][ccp2, rest cm2]
656    // The reason to prepose the prologue transaction is to provide information for transaction
657    // cancellation.
658    #[serde(skip_serializing_if = "is_false")]
659    prepend_prologue_tx_in_consensus_commit_in_checkpoints: bool,
660
661    // Set number of leaders per round for Mysticeti commits.
662    #[serde(skip_serializing_if = "Option::is_none")]
663    mysticeti_num_leaders_per_round: Option<usize>,
664
665    // Enable Soft Bundle (SIP-19).
666    #[serde(skip_serializing_if = "is_false")]
667    soft_bundle: bool,
668
669    // If true, enable the coin deny list V2.
670    #[serde(skip_serializing_if = "is_false")]
671    enable_coin_deny_list_v2: bool,
672
673    // Enable passkey auth (SIP-9)
674    #[serde(skip_serializing_if = "is_false")]
675    passkey_auth: bool,
676
677    // Use AuthorityCapabilitiesV2
678    #[serde(skip_serializing_if = "is_false")]
679    authority_capabilities_v2: bool,
680
681    // Rethrow type layout errors during serialization instead of trying to convert them.
682    #[serde(skip_serializing_if = "is_false")]
683    rethrow_serialization_type_layout_errors: bool,
684
685    // Use distributed vote leader scoring strategy in consensus.
686    #[serde(skip_serializing_if = "is_false")]
687    consensus_distributed_vote_scoring_strategy: bool,
688
689    // Probe rounds received by peers from every authority.
690    #[serde(skip_serializing_if = "is_false")]
691    consensus_round_prober: bool,
692
693    // Validate identifier inputs separately
694    #[serde(skip_serializing_if = "is_false")]
695    validate_identifier_inputs: bool,
696
697    // Disallow self identifier
698    #[serde(skip_serializing_if = "is_false")]
699    disallow_self_identifier: bool,
700
701    // Enables Mysticeti fastpath.
702    #[serde(skip_serializing_if = "is_false")]
703    mysticeti_fastpath: bool,
704
705    // If true, disable pre-consensus locking for owned objects.
706    // All transactions go through consensus, and owned object conflict detection
707    // happens post-consensus via lock acquisition.
708    #[serde(skip_serializing_if = "is_false")]
709    disable_preconsensus_locking: bool,
710
711    // Makes the event's sending module version-aware.
712    #[serde(skip_serializing_if = "is_false")]
713    relocate_event_module: bool,
714
715    // Enable uncompressed group elements in BLS123-81 G1
716    #[serde(skip_serializing_if = "is_false")]
717    uncompressed_g1_group_elements: bool,
718
719    #[serde(skip_serializing_if = "is_false")]
720    disallow_new_modules_in_deps_only_packages: bool,
721
722    // Use smart ancestor selection in consensus.
723    #[serde(skip_serializing_if = "is_false")]
724    consensus_smart_ancestor_selection: bool,
725
726    // Probe accepted rounds in round prober.
727    #[serde(skip_serializing_if = "is_false")]
728    consensus_round_prober_probe_accepted_rounds: bool,
729
730    // Enable v2 native charging for natives.
731    #[serde(skip_serializing_if = "is_false")]
732    native_charging_v2: bool,
733
734    // Enables the new logic for collecting the subdag in the consensus linearizer. The new logic does not stop the recursion at the highest
735    // committed round for each authority, but allows to commit uncommitted blocks up to gc round (excluded) for that authority.
736    #[serde(skip_serializing_if = "is_false")]
737    consensus_linearize_subdag_v2: bool,
738
739    // Properly convert certain type argument errors in the execution layer.
740    #[serde(skip_serializing_if = "is_false")]
741    convert_type_argument_error: bool,
742
743    // Variants count as nodes
744    #[serde(skip_serializing_if = "is_false")]
745    variant_nodes: bool,
746
747    // If true, enable zstd compression for consensus tonic network.
748    #[serde(skip_serializing_if = "is_false")]
749    consensus_zstd_compression: bool,
750
751    // If true, enables the optimizations for child object mutations, removing unnecessary mutations
752    #[serde(skip_serializing_if = "is_false")]
753    minimize_child_object_mutations: bool,
754
755    // If true, record the additional state digest in the consensus commit prologue.
756    #[serde(skip_serializing_if = "is_false")]
757    record_additional_state_digest_in_prologue: bool,
758
759    // If true, enable `TxContext` Move API to go native.
760    #[serde(skip_serializing_if = "is_false")]
761    move_native_context: bool,
762
763    // If true, then it (1) will not enforce monotonicity checks for a block's ancestors and (2) calculates the commit's timestamp based on the
764    // weighted by stake median timestamp of the leader's ancestors.
765    #[serde(skip_serializing_if = "is_false")]
766    consensus_median_based_commit_timestamp: bool,
767
768    // If true, enables the normalization of PTB arguments but does not yet enable splatting
769    // `Result`s of length not equal to 1
770    #[serde(skip_serializing_if = "is_false")]
771    normalize_ptb_arguments: bool,
772
773    // If true, enabled batched block sync in consensus.
774    #[serde(skip_serializing_if = "is_false")]
775    consensus_batched_block_sync: bool,
776
777    // If true, enforces checkpoint timestamps are non-decreasing.
778    #[serde(skip_serializing_if = "is_false")]
779    enforce_checkpoint_timestamp_monotonicity: bool,
780
781    // If true, enables better errors and bounds for max ptb values
782    #[serde(skip_serializing_if = "is_false")]
783    max_ptb_value_size_v2: bool,
784
785    // If true, resolves all type input ids to be defining ID based in the adapter
786    #[serde(skip_serializing_if = "is_false")]
787    resolve_type_input_ids_to_defining_id: bool,
788
789    // Enable native function for party transfer
790    #[serde(skip_serializing_if = "is_false")]
791    enable_party_transfer: bool,
792
793    // Allow objects created or mutated in system transactions to exceed the max object size limit.
794    #[serde(skip_serializing_if = "is_false")]
795    allow_unbounded_system_objects: bool,
796
797    // Signifies the cut-over of using type tags instead of `Type`s in the object runtime.
798    #[serde(skip_serializing_if = "is_false")]
799    type_tags_in_object_runtime: bool,
800
801    // Enable accumulators
802    #[serde(skip_serializing_if = "is_false")]
803    enable_accumulators: bool,
804
805    // Enable coin reservation
806    #[serde(skip_serializing_if = "is_false")]
807    enable_coin_reservation_obj_refs: bool,
808
809    // If true, create the root accumulator object in the change epoch transaction.
810    // This must be enabled and shipped before `enable_accumulators` is set to true.
811    #[serde(skip_serializing_if = "is_false")]
812    create_root_accumulator_object: bool,
813
814    // Enable authenticated event streams
815    #[serde(skip_serializing_if = "is_false")]
816    enable_authenticated_event_streams: bool,
817
818    // Enable address balance gas payments
819    #[serde(skip_serializing_if = "is_false")]
820    enable_address_balance_gas_payments: bool,
821
822    // Validate gas price >= RGP at signing for address balance gas payments
823    #[serde(skip_serializing_if = "is_false")]
824    address_balance_gas_check_rgp_at_signing: bool,
825
826    #[serde(skip_serializing_if = "is_false")]
827    address_balance_gas_reject_gas_coin_arg: bool,
828
829    // Enable multi-epoch transaction expiration (max 1 epoch difference)
830    #[serde(skip_serializing_if = "is_false")]
831    enable_multi_epoch_transaction_expiration: bool,
832
833    // Enable statically type checked ptb execution
834    #[serde(skip_serializing_if = "is_false")]
835    enable_ptb_execution_v2: bool,
836
837    // Provide better type resolution errors in the adapter.
838    #[serde(skip_serializing_if = "is_false")]
839    better_adapter_type_resolution_errors: bool,
840
841    // If true, record the time estimate processed in the consensus commit prologue.
842    #[serde(skip_serializing_if = "is_false")]
843    record_time_estimate_processed: bool,
844
845    // If true enable additional linkage checks.
846    #[serde(skip_serializing_if = "is_false")]
847    dependency_linkage_error: bool,
848
849    // If true enable additional multisig checks.
850    #[serde(skip_serializing_if = "is_false")]
851    additional_multisig_checks: bool,
852
853    // If true, ignore execution time observations after certs are closed.
854    #[serde(skip_serializing_if = "is_false")]
855    ignore_execution_time_observations_after_certs_closed: bool,
856
857    // If true use `debug_fatal` to report invariant violations.
858    // `debug_fatal` panics in debug builds and breaks tests/behavior based on older
859    // protocol versions (see make_vec_non_existent_type_v71.move)
860    #[serde(skip_serializing_if = "is_false")]
861    debug_fatal_on_move_invariant_violation: bool,
862
863    // DO NOT ENABLE THIS FOR PRODUCTION NETWORKS. used for testing only.
864    // Allow private accumulator entrypoints
865    #[serde(skip_serializing_if = "is_false")]
866    allow_private_accumulator_entrypoints: bool,
867
868    // If true, include indirect state in the additional consensus digest.
869    #[serde(skip_serializing_if = "is_false")]
870    additional_consensus_digest_indirect_state: bool,
871
872    // Check for `init` for new modules to a package on upgrade.
873    #[serde(skip_serializing_if = "is_false")]
874    check_for_init_during_upgrade: bool,
875
876    // Check shared object transfer restrictions per command.
877    #[serde(skip_serializing_if = "is_false")]
878    per_command_shared_object_transfer_rules: bool,
879
880    // Enable including checkpoint artifacts digest in the summary.
881    #[serde(skip_serializing_if = "is_false")]
882    include_checkpoint_artifacts_digest_in_summary: bool,
883
884    // If true, use MFP txns in load initial object debts.
885    #[serde(skip_serializing_if = "is_false")]
886    use_mfp_txns_in_load_initial_object_debts: bool,
887
888    // If true, cancel randomness-using txns when DKG has failed *before* doing other congestion checks.
889    #[serde(skip_serializing_if = "is_false")]
890    cancel_for_failed_dkg_early: bool,
891
892    // Enable coin registry protocol
893    #[serde(skip_serializing_if = "is_false")]
894    enable_coin_registry: bool,
895
896    // Use abstract size in the object runtime instead the legacy value size.
897    #[serde(skip_serializing_if = "is_false")]
898    abstract_size_in_object_runtime: bool,
899
900    // If true charge for loads into the cache (i.e., fetches from storage) in the object runtime.
901    #[serde(skip_serializing_if = "is_false")]
902    object_runtime_charge_cache_load_gas: bool,
903
904    // If true, perform additional borrow checks
905    #[serde(skip_serializing_if = "is_false")]
906    additional_borrow_checks: bool,
907
908    // If true, use the new commit handler.
909    #[serde(skip_serializing_if = "is_false")]
910    use_new_commit_handler: bool,
911
912    // If true return a better error message when we encounter a loader error.
913    #[serde(skip_serializing_if = "is_false")]
914    better_loader_errors: bool,
915
916    // If true generate layouts for dynamic fields
917    #[serde(skip_serializing_if = "is_false")]
918    generate_df_type_layouts: bool,
919
920    // If true, allow Move functions called in PTBs to return references
921    #[serde(skip_serializing_if = "is_false")]
922    allow_references_in_ptbs: bool,
923
924    // Enable display registry protocol
925    #[serde(skip_serializing_if = "is_false")]
926    enable_display_registry: bool,
927
928    // If true, enable private generics verifier v2
929    #[serde(skip_serializing_if = "is_false")]
930    private_generics_verifier_v2: bool,
931
932    // If true, deprecate global storage ops during Move module deserialization
933    #[serde(skip_serializing_if = "is_false")]
934    deprecate_global_storage_ops_during_deserialization: bool,
935
936    // If true, enable non-exclusive writes for user transactions.
937    // DO NOT ENABLE outside of the transaction test runner.
938    #[serde(skip_serializing_if = "is_false")]
939    enable_non_exclusive_writes: bool,
940
941    // If true, deprecate global storage ops everywhere.
942    #[serde(skip_serializing_if = "is_false")]
943    deprecate_global_storage_ops: bool,
944
945    // If true, skip GC'ed accept votes in CommitFinalizer.
946    #[serde(skip_serializing_if = "is_false")]
947    consensus_skip_gced_accept_votes: bool,
948
949    // If true, include cancelled randomness txns in the consensus commit prologue.
950    #[serde(skip_serializing_if = "is_false")]
951    include_cancelled_randomness_txns_in_prologue: bool,
952
953    // Enables address aliases.
954    #[serde(skip_serializing_if = "is_false")]
955    address_aliases: bool,
956
957    // Corrects signature-to-signer mapping in CheckpointContentsV2.
958    // TODO: remove old code and deprecate once in mainnet.
959    #[serde(skip_serializing_if = "is_false")]
960    fix_checkpoint_signature_mapping: bool,
961
962    // If true, enable object funds withdraw.
963    #[serde(skip_serializing_if = "is_false")]
964    enable_object_funds_withdraw: bool,
965
966    // If true, skip GC'ed blocks in direct finalization.
967    #[serde(skip_serializing_if = "is_false")]
968    consensus_skip_gced_blocks_in_direct_finalization: bool,
969
970    // If true, uses a new rounding mechanism for gas calculations, replacing the step-based one
971    #[serde(skip_serializing_if = "is_false")]
972    gas_rounding_halve_digits: bool,
973
974    // If true, enable tx contexts in all argument positions
975    #[serde(skip_serializing_if = "is_false")]
976    flexible_tx_context_positions: bool,
977
978    // If true, disable entry point signature check.
979    #[serde(skip_serializing_if = "is_false")]
980    disable_entry_point_signature_check: bool,
981
982    // If true, convert withdrawal compatibility PTB arguments to coins at the start of the PTB.
983    #[serde(skip_serializing_if = "is_false")]
984    convert_withdrawal_compatibility_ptb_arguments: bool,
985
986    // If true, additional restrictions for hot or not entry functions are enforced.
987    #[serde(skip_serializing_if = "is_false")]
988    restrict_hot_or_not_entry_functions: bool,
989
990    // If true, split checkpoints in consensus handler.
991    #[serde(skip_serializing_if = "is_false")]
992    split_checkpoints_in_consensus_handler: bool,
993
994    // If true, always accept committed system transactions.
995    #[serde(skip_serializing_if = "is_false")]
996    consensus_always_accept_system_transactions: bool,
997
998    // If true perform consistent verification of metadata
999    #[serde(skip_serializing_if = "is_false")]
1000    validator_metadata_verify_v2: bool,
1001
1002    // If true, defer transactions with unpaid consensus amplification
1003    // (where duplicate count exceeds gas_price / RGP + 1)
1004    #[serde(skip_serializing_if = "is_false")]
1005    defer_unpaid_amplification: bool,
1006
1007    #[serde(skip_serializing_if = "is_false")]
1008    randomize_checkpoint_tx_limit_in_tests: bool,
1009}
1010
1011fn is_false(b: &bool) -> bool {
1012    !b
1013}
1014
1015fn is_empty(b: &BTreeSet<String>) -> bool {
1016    b.is_empty()
1017}
1018
1019fn is_zero(val: &u64) -> bool {
1020    *val == 0
1021}
1022
1023/// Ordering mechanism for transactions in one Narwhal consensus output.
1024#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
1025pub enum ConsensusTransactionOrdering {
1026    /// No ordering. Transactions are processed in the order they appear in the consensus output.
1027    #[default]
1028    None,
1029    /// Order transactions by gas price, highest first.
1030    ByGasPrice,
1031}
1032
1033impl ConsensusTransactionOrdering {
1034    pub fn is_none(&self) -> bool {
1035        matches!(self, ConsensusTransactionOrdering::None)
1036    }
1037}
1038
1039#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
1040pub struct ExecutionTimeEstimateParams {
1041    // Targeted per-object utilization as an integer percentage (1-100).
1042    pub target_utilization: u64,
1043    // Schedule up to this much extra work (in microseconds) per object,
1044    // but don't allow more than a single transaction to exceed this
1045    // burst limit.
1046    pub allowed_txn_cost_overage_burst_limit_us: u64,
1047
1048    // For separate budget for randomness-using tx, the above limits are
1049    // used with this integer-percentage scaling factor (1-100).
1050    pub randomness_scalar: u64,
1051
1052    // Absolute maximum allowed transaction duration estimate (in microseconds).
1053    pub max_estimate_us: u64,
1054
1055    // Number of the final checkpoints in an epoch whose observations should be
1056    // stored for use in the next epoch.
1057    pub stored_observations_num_included_checkpoints: u64,
1058
1059    // Absolute limit on the number of saved observations at end of epoch.
1060    pub stored_observations_limit: u64,
1061
1062    // Requires observations from at least this amount of stake in order to use
1063    // observation-based execution time estimates instead of the default.
1064    #[serde(skip_serializing_if = "is_zero")]
1065    pub stake_weighted_median_threshold: u64,
1066
1067    // For backwards compatibility with old behavior we use a zero default duration when adding
1068    // new execution time observation keys and a zero generation when loading stored observations.
1069    // This can be removed once set to "true" on mainnet.
1070    #[serde(skip_serializing_if = "is_false")]
1071    pub default_none_duration_for_new_keys: bool,
1072
1073    // Number of observations per chunk. When None, chunking is disabled.
1074    #[serde(skip_serializing_if = "Option::is_none")]
1075    pub observations_chunk_size: Option<u64>,
1076}
1077
1078// The config for per object congestion control in consensus handler.
1079#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
1080pub enum PerObjectCongestionControlMode {
1081    #[default]
1082    None, // Deprecated.
1083    TotalGasBudget,                                     // Deprecated.
1084    TotalTxCount,                                       // Deprecated.
1085    TotalGasBudgetWithCap,                              // Deprecated.
1086    ExecutionTimeEstimate(ExecutionTimeEstimateParams), // Use execution time estimate as execution cost.
1087}
1088
1089impl PerObjectCongestionControlMode {
1090    pub fn is_none(&self) -> bool {
1091        matches!(self, PerObjectCongestionControlMode::None)
1092    }
1093}
1094
1095// Configuration options for consensus algorithm.
1096#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
1097pub enum ConsensusChoice {
1098    #[default]
1099    Narwhal,
1100    SwapEachEpoch,
1101    Mysticeti,
1102}
1103
1104impl ConsensusChoice {
1105    pub fn is_narwhal(&self) -> bool {
1106        matches!(self, ConsensusChoice::Narwhal)
1107    }
1108}
1109
1110// Configuration options for consensus network.
1111#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
1112pub enum ConsensusNetwork {
1113    #[default]
1114    Anemo,
1115    Tonic,
1116}
1117
1118impl ConsensusNetwork {
1119    pub fn is_anemo(&self) -> bool {
1120        matches!(self, ConsensusNetwork::Anemo)
1121    }
1122}
1123
1124/// Constants that change the behavior of the protocol.
1125///
1126/// The value of each constant here must be fixed for a given protocol version. To change the value
1127/// of a constant, advance the protocol version, and add support for it in `get_for_version` under
1128/// the new version number.
1129/// (below).
1130///
1131/// To add a new field to this struct, use the following procedure:
1132/// - Advance the protocol version.
1133/// - Add the field as a private `Option<T>` to the struct.
1134/// - Initialize the field to `None` in prior protocol versions.
1135/// - Initialize the field to `Some(val)` for your new protocol version.
1136/// - Add a public getter that simply unwraps the field.
1137/// - Two public getters of the form `field(&self) -> field_type`
1138///     and `field_as_option(&self) -> Option<field_type>` will be automatically generated for you.
1139/// Example for a field: `new_constant: Option<u64>`
1140/// ```rust,ignore
1141///      pub fn new_constant(&self) -> u64 {
1142///         self.new_constant.expect(Self::CONSTANT_ERR_MSG)
1143///     }
1144///      pub fn new_constant_as_option(&self) -> Option<u64> {
1145///         self.new_constant.expect(Self::CONSTANT_ERR_MSG)
1146///     }
1147/// ```
1148/// With `pub fn new_constant(&self) -> u64`, if the constant is accessed in a protocol version
1149/// in which it is not defined, the validator will crash. (Crashing is necessary because
1150/// this type of error would almost always result in forking if not prevented here).
1151/// If you don't want the validator to crash, you can use the
1152/// `pub fn new_constant_as_option(&self) -> Option<u64>` getter, which will
1153/// return `None` if the field is not defined at that version.
1154/// - If you want a customized getter, you can add a method in the impl.
1155#[skip_serializing_none]
1156#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
1157pub struct ProtocolConfig {
1158    pub version: ProtocolVersion,
1159
1160    feature_flags: FeatureFlags,
1161
1162    // ==== Transaction input limits ====
1163    /// Maximum serialized size of a transaction (in bytes).
1164    max_tx_size_bytes: Option<u64>,
1165
1166    /// Maximum number of input objects to a transaction. Enforced by the transaction input checker
1167    max_input_objects: Option<u64>,
1168
1169    /// Max size of objects a transaction can write to disk after completion. Enforce by the Sui adapter.
1170    /// This is the sum of the serialized size of all objects written to disk.
1171    /// The max size of individual objects on the other hand is `max_move_object_size`.
1172    max_size_written_objects: Option<u64>,
1173    /// Max size of objects a system transaction can write to disk after completion. Enforce by the Sui adapter.
1174    /// Similar to `max_size_written_objects` but for system transactions.
1175    max_size_written_objects_system_tx: Option<u64>,
1176
1177    /// Maximum size of serialized transaction effects.
1178    max_serialized_tx_effects_size_bytes: Option<u64>,
1179
1180    /// Maximum size of serialized transaction effects for system transactions.
1181    max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
1182
1183    /// Maximum number of gas payment objects for a transaction.
1184    max_gas_payment_objects: Option<u32>,
1185
1186    /// Maximum number of modules in a Publish transaction.
1187    max_modules_in_publish: Option<u32>,
1188
1189    /// Maximum number of transitive dependencies in a package when publishing.
1190    max_package_dependencies: Option<u32>,
1191
1192    /// Maximum number of arguments in a move call or a ProgrammableTransaction's
1193    /// TransferObjects command.
1194    max_arguments: Option<u32>,
1195
1196    /// Maximum number of total type arguments, computed recursively.
1197    max_type_arguments: Option<u32>,
1198
1199    /// Maximum depth of an individual type argument.
1200    max_type_argument_depth: Option<u32>,
1201
1202    /// Maximum size of a Pure CallArg.
1203    max_pure_argument_size: Option<u32>,
1204
1205    /// Maximum number of Commands in a ProgrammableTransaction.
1206    max_programmable_tx_commands: Option<u32>,
1207
1208    // ==== Move VM, Move bytecode verifier, and execution limits ===
1209    /// Maximum Move bytecode version the VM understands. All older versions are accepted.
1210    move_binary_format_version: Option<u32>,
1211    min_move_binary_format_version: Option<u32>,
1212
1213    /// Configuration controlling binary tables size.
1214    binary_module_handles: Option<u16>,
1215    binary_struct_handles: Option<u16>,
1216    binary_function_handles: Option<u16>,
1217    binary_function_instantiations: Option<u16>,
1218    binary_signatures: Option<u16>,
1219    binary_constant_pool: Option<u16>,
1220    binary_identifiers: Option<u16>,
1221    binary_address_identifiers: Option<u16>,
1222    binary_struct_defs: Option<u16>,
1223    binary_struct_def_instantiations: Option<u16>,
1224    binary_function_defs: Option<u16>,
1225    binary_field_handles: Option<u16>,
1226    binary_field_instantiations: Option<u16>,
1227    binary_friend_decls: Option<u16>,
1228    binary_enum_defs: Option<u16>,
1229    binary_enum_def_instantiations: Option<u16>,
1230    binary_variant_handles: Option<u16>,
1231    binary_variant_instantiation_handles: Option<u16>,
1232
1233    /// Maximum size of the `contents` part of an object, in bytes. Enforced by the Sui adapter when effects are produced.
1234    max_move_object_size: Option<u64>,
1235
1236    // TODO: Option<increase to 500 KB. currently, publishing a package > 500 KB exceeds the max computation gas cost
1237    /// Maximum size of a Move package object, in bytes. Enforced by the Sui adapter at the end of a publish transaction.
1238    max_move_package_size: Option<u64>,
1239
1240    /// Max number of publish or upgrade commands allowed in a programmable transaction block.
1241    max_publish_or_upgrade_per_ptb: Option<u64>,
1242
1243    /// Maximum gas budget in MIST that a transaction can use.
1244    max_tx_gas: Option<u64>,
1245
1246    /// Maximum amount of the proposed gas price in MIST (defined in the transaction).
1247    max_gas_price: Option<u64>,
1248
1249    /// For aborted txns, we cap the gas price at a factor of RGP. This lowers risk of setting higher priority gas price
1250    /// if there's a chance the txn will abort.
1251    max_gas_price_rgp_factor_for_aborted_transactions: Option<u64>,
1252
1253    /// The max computation bucket for gas. This is the max that can be charged for computation.
1254    max_gas_computation_bucket: Option<u64>,
1255
1256    // Define the value used to round up computation gas charges
1257    gas_rounding_step: Option<u64>,
1258
1259    /// Maximum number of nested loops. Enforced by the Move bytecode verifier.
1260    max_loop_depth: Option<u64>,
1261
1262    /// Maximum number of type arguments that can be bound to generic type parameters. Enforced by the Move bytecode verifier.
1263    max_generic_instantiation_length: Option<u64>,
1264
1265    /// Maximum number of parameters that a Move function can have. Enforced by the Move bytecode verifier.
1266    max_function_parameters: Option<u64>,
1267
1268    /// Maximum number of basic blocks that a Move function can have. Enforced by the Move bytecode verifier.
1269    max_basic_blocks: Option<u64>,
1270
1271    /// Maximum stack size value. Enforced by the Move bytecode verifier.
1272    max_value_stack_size: Option<u64>,
1273
1274    /// Maximum number of "type nodes", a metric for how big a SignatureToken will be when expanded into a fully qualified type. Enforced by the Move bytecode verifier.
1275    max_type_nodes: Option<u64>,
1276
1277    /// Maximum number of push instructions in one function. Enforced by the Move bytecode verifier.
1278    max_push_size: Option<u64>,
1279
1280    /// Maximum number of struct definitions in a module. Enforced by the Move bytecode verifier.
1281    max_struct_definitions: Option<u64>,
1282
1283    /// Maximum number of function definitions in a module. Enforced by the Move bytecode verifier.
1284    max_function_definitions: Option<u64>,
1285
1286    /// Maximum number of fields allowed in a struct definition. Enforced by the Move bytecode verifier.
1287    max_fields_in_struct: Option<u64>,
1288
1289    /// Maximum dependency depth. Enforced by the Move linker when loading dependent modules.
1290    max_dependency_depth: Option<u64>,
1291
1292    /// Maximum number of Move events that a single transaction can emit. Enforced by the VM during execution.
1293    max_num_event_emit: Option<u64>,
1294
1295    /// Maximum number of new IDs that a single transaction can create. Enforced by the VM during execution.
1296    max_num_new_move_object_ids: Option<u64>,
1297
1298    /// Maximum number of new IDs that a single system transaction can create. Enforced by the VM during execution.
1299    max_num_new_move_object_ids_system_tx: Option<u64>,
1300
1301    /// Maximum number of IDs that a single transaction can delete. Enforced by the VM during execution.
1302    max_num_deleted_move_object_ids: Option<u64>,
1303
1304    /// Maximum number of IDs that a single system transaction can delete. Enforced by the VM during execution.
1305    max_num_deleted_move_object_ids_system_tx: Option<u64>,
1306
1307    /// Maximum number of IDs that a single transaction can transfer. Enforced by the VM during execution.
1308    max_num_transferred_move_object_ids: Option<u64>,
1309
1310    /// Maximum number of IDs that a single system transaction can transfer. Enforced by the VM during execution.
1311    max_num_transferred_move_object_ids_system_tx: Option<u64>,
1312
1313    /// Maximum size of a Move user event. Enforced by the VM during execution.
1314    max_event_emit_size: Option<u64>,
1315
1316    /// Maximum size of a Move user event. Enforced by the VM during execution.
1317    max_event_emit_size_total: Option<u64>,
1318
1319    /// Maximum length of a vector in Move. Enforced by the VM during execution, and for constants, by the verifier.
1320    max_move_vector_len: Option<u64>,
1321
1322    /// Maximum length of an `Identifier` in Move. Enforced by the bytecode verifier at signing.
1323    max_move_identifier_len: Option<u64>,
1324
1325    /// Maximum depth of a Move value within the VM.
1326    max_move_value_depth: Option<u64>,
1327
1328    /// Maximum number of variants in an enum. Enforced by the bytecode verifier at signing.
1329    max_move_enum_variants: Option<u64>,
1330
1331    /// Maximum number of back edges in Move function. Enforced by the bytecode verifier at signing.
1332    max_back_edges_per_function: Option<u64>,
1333
1334    /// Maximum number of back edges in Move module. Enforced by the bytecode verifier at signing.
1335    max_back_edges_per_module: Option<u64>,
1336
1337    /// Maximum number of meter `ticks` spent verifying a Move function. Enforced by the bytecode verifier at signing.
1338    max_verifier_meter_ticks_per_function: Option<u64>,
1339
1340    /// Maximum number of meter `ticks` spent verifying a Move module. Enforced by the bytecode verifier at signing.
1341    max_meter_ticks_per_module: Option<u64>,
1342
1343    /// Maximum number of meter `ticks` spent verifying a Move package. Enforced by the bytecode verifier at signing.
1344    max_meter_ticks_per_package: Option<u64>,
1345
1346    // === Object runtime internal operation limits ====
1347    // These affect dynamic fields
1348    /// Maximum number of cached objects in the object runtime ObjectStore. Enforced by object runtime during execution
1349    object_runtime_max_num_cached_objects: Option<u64>,
1350
1351    /// Maximum number of cached objects in the object runtime ObjectStore in system transaction. Enforced by object runtime during execution
1352    object_runtime_max_num_cached_objects_system_tx: Option<u64>,
1353
1354    /// Maximum number of stored objects accessed by object runtime ObjectStore. Enforced by object runtime during execution
1355    object_runtime_max_num_store_entries: Option<u64>,
1356
1357    /// Maximum number of stored objects accessed by object runtime ObjectStore in system transaction. Enforced by object runtime during execution
1358    object_runtime_max_num_store_entries_system_tx: Option<u64>,
1359
1360    // === Execution gas costs ====
1361    /// Base cost for any Sui transaction
1362    base_tx_cost_fixed: Option<u64>,
1363
1364    /// Additional cost for a transaction that publishes a package
1365    /// i.e., the base cost of such a transaction is base_tx_cost_fixed + package_publish_cost_fixed
1366    package_publish_cost_fixed: Option<u64>,
1367
1368    /// Cost per byte of a Move call transaction
1369    /// i.e., the cost of such a transaction is base_cost + (base_tx_cost_per_byte * size)
1370    base_tx_cost_per_byte: Option<u64>,
1371
1372    /// Cost per byte for a transaction that publishes a package
1373    package_publish_cost_per_byte: Option<u64>,
1374
1375    // Per-byte cost of reading an object during transaction execution
1376    obj_access_cost_read_per_byte: Option<u64>,
1377
1378    // Per-byte cost of writing an object during transaction execution
1379    obj_access_cost_mutate_per_byte: Option<u64>,
1380
1381    // Per-byte cost of deleting an object during transaction execution
1382    obj_access_cost_delete_per_byte: Option<u64>,
1383
1384    /// Per-byte cost charged for each input object to a transaction.
1385    /// Meant to approximate the cost of checking locks for each object
1386    // TODO: Option<I'm not sure that this cost makes sense. Checking locks is "free"
1387    // in the sense that an invalid tx that can never be committed/pay gas can
1388    // force validators to check an arbitrary number of locks. If those checks are
1389    // "free" for invalid transactions, why charge for them in valid transactions
1390    // TODO: Option<if we keep this, I think we probably want it to be a fixed cost rather
1391    // than a per-byte cost. checking an object lock should not require loading an
1392    // entire object, just consulting an ID -> tx digest map
1393    obj_access_cost_verify_per_byte: Option<u64>,
1394
1395    // Maximal nodes which are allowed when converting to a type layout.
1396    max_type_to_layout_nodes: Option<u64>,
1397
1398    // Maximal size in bytes that a PTB value can be
1399    max_ptb_value_size: Option<u64>,
1400
1401    // === Gas version. gas model ===
1402    /// Gas model version, what code we are using to charge gas
1403    gas_model_version: Option<u64>,
1404
1405    // === Storage gas costs ===
1406    /// Per-byte cost of storing an object in the Sui global object store. Some of this cost may be refundable if the object is later freed
1407    obj_data_cost_refundable: Option<u64>,
1408
1409    // Per-byte cost of storing an object in the Sui transaction log (e.g., in CertifiedTransactionEffects)
1410    // This depends on the size of various fields including the effects
1411    // TODO: Option<I don't fully understand this^ and more details would be useful
1412    obj_metadata_cost_non_refundable: Option<u64>,
1413
1414    // === Tokenomics ===
1415
1416    // TODO: Option<this should be changed to u64.
1417    /// Sender of a txn that touches an object will get this percent of the storage rebate back.
1418    /// In basis point.
1419    storage_rebate_rate: Option<u64>,
1420
1421    /// 5% of the storage fund's share of rewards are reinvested into the storage fund.
1422    /// In basis point.
1423    storage_fund_reinvest_rate: Option<u64>,
1424
1425    /// The share of rewards that will be slashed and redistributed is 50%.
1426    /// In basis point.
1427    reward_slashing_rate: Option<u64>,
1428
1429    /// Unit gas price, Mist per internal gas unit.
1430    storage_gas_price: Option<u64>,
1431
1432    /// Per-object storage cost for accumulator objects, used during end-of-epoch accounting.
1433    accumulator_object_storage_cost: Option<u64>,
1434
1435    // === Core Protocol ===
1436    /// Max number of transactions per checkpoint.
1437    /// Note that this is a protocol constant and not a config as validators must have this set to
1438    /// the same value, otherwise they *will* fork.
1439    max_transactions_per_checkpoint: Option<u64>,
1440
1441    /// Max size of a checkpoint in bytes.
1442    /// Note that this is a protocol constant and not a config as validators must have this set to
1443    /// the same value, otherwise they *will* fork.
1444    max_checkpoint_size_bytes: Option<u64>,
1445
1446    /// A protocol upgrade always requires 2f+1 stake to agree. We support a buffer of additional
1447    /// stake (as a fraction of f, expressed in basis points) that is required before an upgrade
1448    /// can happen automatically. 10000bps would indicate that complete unanimity is required (all
1449    /// 3f+1 must vote), while 0bps would indicate that 2f+1 is sufficient.
1450    buffer_stake_for_protocol_upgrade_bps: Option<u64>,
1451
1452    // === Native Function Costs ===
1453
1454    // `address` module
1455    // Cost params for the Move native function `address::from_bytes(bytes: vector<u8>)`
1456    address_from_bytes_cost_base: Option<u64>,
1457    // Cost params for the Move native function `address::to_u256(address): u256`
1458    address_to_u256_cost_base: Option<u64>,
1459    // Cost params for the Move native function `address::from_u256(u256): address`
1460    address_from_u256_cost_base: Option<u64>,
1461
1462    // `config` module
1463    // Cost params for the Move native function `read_setting_impl<Name: copy + drop + store,
1464    // SettingValue: key + store, SettingDataValue: store, Value: copy + drop + store,
1465    // >(config: address, name: address, current_epoch: u64): Option<Value>`
1466    config_read_setting_impl_cost_base: Option<u64>,
1467    config_read_setting_impl_cost_per_byte: Option<u64>,
1468
1469    // `dynamic_field` module
1470    // Cost params for the Move native function `hash_type_and_key<K: copy + drop + store>(parent: address, k: K): address`
1471    dynamic_field_hash_type_and_key_cost_base: Option<u64>,
1472    dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
1473    dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
1474    dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
1475    // Cost params for the Move native function `add_child_object<Child: key>(parent: address, child: Child)`
1476    dynamic_field_add_child_object_cost_base: Option<u64>,
1477    dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
1478    dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
1479    dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
1480    // Cost params for the Move native function `borrow_child_object_mut<Child: key>(parent: &mut UID, id: address): &mut Child`
1481    dynamic_field_borrow_child_object_cost_base: Option<u64>,
1482    dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1483    dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1484    // Cost params for the Move native function `remove_child_object<Child: key>(parent: address, id: address): Child`
1485    dynamic_field_remove_child_object_cost_base: Option<u64>,
1486    dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1487    dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1488    // Cost params for the Move native function `has_child_object(parent: address, id: address): bool`
1489    dynamic_field_has_child_object_cost_base: Option<u64>,
1490    // Cost params for the Move native function `has_child_object_with_ty<Child: key>(parent: address, id: address): bool`
1491    dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1492    dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1493    dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1494
1495    // `event` module
1496    // Cost params for the Move native function `event::emit<T: copy + drop>(event: T)`
1497    event_emit_cost_base: Option<u64>,
1498    event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1499    event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1500    event_emit_output_cost_per_byte: Option<u64>,
1501    event_emit_auth_stream_cost: Option<u64>,
1502
1503    //  `object` module
1504    // Cost params for the Move native function `borrow_uid<T: key>(obj: &T): &UID`
1505    object_borrow_uid_cost_base: Option<u64>,
1506    // Cost params for the Move native function `delete_impl(id: address)`
1507    object_delete_impl_cost_base: Option<u64>,
1508    // Cost params for the Move native function `record_new_uid(id: address)`
1509    object_record_new_uid_cost_base: Option<u64>,
1510
1511    // Transfer
1512    // Cost params for the Move native function `transfer_impl<T: key>(obj: T, recipient: address)`
1513    transfer_transfer_internal_cost_base: Option<u64>,
1514    // Cost params for the Move native function `party_transfer_impl<T: key>(obj: T, party_members: vector<address>)`
1515    transfer_party_transfer_internal_cost_base: Option<u64>,
1516    // Cost params for the Move native function `freeze_object<T: key>(obj: T)`
1517    transfer_freeze_object_cost_base: Option<u64>,
1518    // Cost params for the Move native function `share_object<T: key>(obj: T)`
1519    transfer_share_object_cost_base: Option<u64>,
1520    // Cost params for the Move native function
1521    // `receive_object<T: key>(p: &mut UID, recv: Receiving<T>T)`
1522    transfer_receive_object_cost_base: Option<u64>,
1523
1524    // TxContext
1525    // Cost params for the Move native function `transfer_impl<T: key>(obj: T, recipient: address)`
1526    tx_context_derive_id_cost_base: Option<u64>,
1527    tx_context_fresh_id_cost_base: Option<u64>,
1528    tx_context_sender_cost_base: Option<u64>,
1529    tx_context_epoch_cost_base: Option<u64>,
1530    tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1531    tx_context_sponsor_cost_base: Option<u64>,
1532    tx_context_rgp_cost_base: Option<u64>,
1533    tx_context_gas_price_cost_base: Option<u64>,
1534    tx_context_gas_budget_cost_base: Option<u64>,
1535    tx_context_ids_created_cost_base: Option<u64>,
1536    tx_context_replace_cost_base: Option<u64>,
1537
1538    // Types
1539    // Cost params for the Move native function `is_one_time_witness<T: drop>(_: &T): bool`
1540    types_is_one_time_witness_cost_base: Option<u64>,
1541    types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1542    types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1543
1544    // Validator
1545    // Cost params for the Move native function `validate_metadata_bcs(metadata: vector<u8>)`
1546    validator_validate_metadata_cost_base: Option<u64>,
1547    validator_validate_metadata_data_cost_per_byte: Option<u64>,
1548
1549    // Crypto natives
1550    crypto_invalid_arguments_cost: Option<u64>,
1551    // bls12381::bls12381_min_sig_verify
1552    bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1553    bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1554    bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1555
1556    // bls12381::bls12381_min_pk_verify
1557    bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1558    bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1559    bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1560
1561    // ecdsa_k1::ecrecover
1562    ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1563    ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1564    ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1565    ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1566    ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1567    ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1568
1569    // ecdsa_k1::decompress_pubkey
1570    ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1571
1572    // ecdsa_k1::secp256k1_verify
1573    ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1574    ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1575    ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1576    ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1577    ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1578    ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1579
1580    // ecdsa_r1::ecrecover
1581    ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1582    ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1583    ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1584    ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1585    ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1586    ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1587
1588    // ecdsa_r1::secp256k1_verify
1589    ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1590    ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1591    ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1592    ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1593    ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1594    ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1595
1596    // ecvrf::verify
1597    ecvrf_ecvrf_verify_cost_base: Option<u64>,
1598    ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1599    ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1600
1601    // ed25519
1602    ed25519_ed25519_verify_cost_base: Option<u64>,
1603    ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1604    ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1605
1606    // groth16::prepare_verifying_key
1607    groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1608    groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1609
1610    // groth16::verify_groth16_proof_internal
1611    groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1612    groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1613    groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1614    groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1615    groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1616
1617    // hash::blake2b256
1618    hash_blake2b256_cost_base: Option<u64>,
1619    hash_blake2b256_data_cost_per_byte: Option<u64>,
1620    hash_blake2b256_data_cost_per_block: Option<u64>,
1621
1622    // hash::keccak256
1623    hash_keccak256_cost_base: Option<u64>,
1624    hash_keccak256_data_cost_per_byte: Option<u64>,
1625    hash_keccak256_data_cost_per_block: Option<u64>,
1626
1627    // poseidon::poseidon_bn254
1628    poseidon_bn254_cost_base: Option<u64>,
1629    poseidon_bn254_cost_per_block: Option<u64>,
1630
1631    // group_ops
1632    group_ops_bls12381_decode_scalar_cost: Option<u64>,
1633    group_ops_bls12381_decode_g1_cost: Option<u64>,
1634    group_ops_bls12381_decode_g2_cost: Option<u64>,
1635    group_ops_bls12381_decode_gt_cost: Option<u64>,
1636    group_ops_bls12381_scalar_add_cost: Option<u64>,
1637    group_ops_bls12381_g1_add_cost: Option<u64>,
1638    group_ops_bls12381_g2_add_cost: Option<u64>,
1639    group_ops_bls12381_gt_add_cost: Option<u64>,
1640    group_ops_bls12381_scalar_sub_cost: Option<u64>,
1641    group_ops_bls12381_g1_sub_cost: Option<u64>,
1642    group_ops_bls12381_g2_sub_cost: Option<u64>,
1643    group_ops_bls12381_gt_sub_cost: Option<u64>,
1644    group_ops_bls12381_scalar_mul_cost: Option<u64>,
1645    group_ops_bls12381_g1_mul_cost: Option<u64>,
1646    group_ops_bls12381_g2_mul_cost: Option<u64>,
1647    group_ops_bls12381_gt_mul_cost: Option<u64>,
1648    group_ops_bls12381_scalar_div_cost: Option<u64>,
1649    group_ops_bls12381_g1_div_cost: Option<u64>,
1650    group_ops_bls12381_g2_div_cost: Option<u64>,
1651    group_ops_bls12381_gt_div_cost: Option<u64>,
1652    group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1653    group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1654    group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1655    group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1656    group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1657    group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1658    group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1659    group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1660    group_ops_bls12381_msm_max_len: Option<u32>,
1661    group_ops_bls12381_pairing_cost: Option<u64>,
1662    group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1663    group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1664    group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1665    group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1666    group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1667
1668    group_ops_ristretto_decode_scalar_cost: Option<u64>,
1669    group_ops_ristretto_decode_point_cost: Option<u64>,
1670    group_ops_ristretto_scalar_add_cost: Option<u64>,
1671    group_ops_ristretto_point_add_cost: Option<u64>,
1672    group_ops_ristretto_scalar_sub_cost: Option<u64>,
1673    group_ops_ristretto_point_sub_cost: Option<u64>,
1674    group_ops_ristretto_scalar_mul_cost: Option<u64>,
1675    group_ops_ristretto_point_mul_cost: Option<u64>,
1676    group_ops_ristretto_scalar_div_cost: Option<u64>,
1677    group_ops_ristretto_point_div_cost: Option<u64>,
1678
1679    // hmac::hmac_sha3_256
1680    hmac_hmac_sha3_256_cost_base: Option<u64>,
1681    hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1682    hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1683
1684    // zklogin::check_zklogin_id
1685    check_zklogin_id_cost_base: Option<u64>,
1686    // zklogin::check_zklogin_issuer
1687    check_zklogin_issuer_cost_base: Option<u64>,
1688
1689    vdf_verify_vdf_cost: Option<u64>,
1690    vdf_hash_to_input_cost: Option<u64>,
1691
1692    // nitro_attestation::load_nitro_attestation
1693    nitro_attestation_parse_base_cost: Option<u64>,
1694    nitro_attestation_parse_cost_per_byte: Option<u64>,
1695    nitro_attestation_verify_base_cost: Option<u64>,
1696    nitro_attestation_verify_cost_per_cert: Option<u64>,
1697
1698    // Stdlib costs
1699    bcs_per_byte_serialized_cost: Option<u64>,
1700    bcs_legacy_min_output_size_cost: Option<u64>,
1701    bcs_failure_cost: Option<u64>,
1702
1703    hash_sha2_256_base_cost: Option<u64>,
1704    hash_sha2_256_per_byte_cost: Option<u64>,
1705    hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1706    hash_sha3_256_base_cost: Option<u64>,
1707    hash_sha3_256_per_byte_cost: Option<u64>,
1708    hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1709    type_name_get_base_cost: Option<u64>,
1710    type_name_get_per_byte_cost: Option<u64>,
1711    type_name_id_base_cost: Option<u64>,
1712
1713    string_check_utf8_base_cost: Option<u64>,
1714    string_check_utf8_per_byte_cost: Option<u64>,
1715    string_is_char_boundary_base_cost: Option<u64>,
1716    string_sub_string_base_cost: Option<u64>,
1717    string_sub_string_per_byte_cost: Option<u64>,
1718    string_index_of_base_cost: Option<u64>,
1719    string_index_of_per_byte_pattern_cost: Option<u64>,
1720    string_index_of_per_byte_searched_cost: Option<u64>,
1721
1722    vector_empty_base_cost: Option<u64>,
1723    vector_length_base_cost: Option<u64>,
1724    vector_push_back_base_cost: Option<u64>,
1725    vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1726    vector_borrow_base_cost: Option<u64>,
1727    vector_pop_back_base_cost: Option<u64>,
1728    vector_destroy_empty_base_cost: Option<u64>,
1729    vector_swap_base_cost: Option<u64>,
1730    debug_print_base_cost: Option<u64>,
1731    debug_print_stack_trace_base_cost: Option<u64>,
1732
1733    // ==== Ephemeral (consensus only) params deleted ====
1734    //
1735    // Const params for consensus scoring decision
1736    // The scaling factor property for the MED outlier detection
1737    // scoring_decision_mad_divisor: Option<f64>,
1738    // The cutoff value for the MED outlier detection
1739    // scoring_decision_cutoff_value: Option<f64>,
1740    /// === Execution Version ===
1741    execution_version: Option<u64>,
1742
1743    // Dictates the threshold (percentage of stake) that is used to calculate the "bad" nodes to be
1744    // swapped when creating the consensus schedule. The values should be of the range [0 - 33]. Anything
1745    // above 33 (f) will not be allowed.
1746    consensus_bad_nodes_stake_threshold: Option<u64>,
1747
1748    max_jwk_votes_per_validator_per_epoch: Option<u64>,
1749    // The maximum age of a JWK in epochs before it is removed from the AuthenticatorState object.
1750    // Applied at the end of an epoch as a delta from the new epoch value, so setting this to 1
1751    // will cause the new epoch to start with JWKs from the previous epoch still valid.
1752    max_age_of_jwk_in_epochs: Option<u64>,
1753
1754    // === random beacon ===
1755    /// Maximum allowed precision loss when reducing voting weights for the random beacon
1756    /// protocol.
1757    random_beacon_reduction_allowed_delta: Option<u16>,
1758
1759    /// Minimum number of shares below which voting weights will not be reduced for the
1760    /// random beacon protocol.
1761    random_beacon_reduction_lower_bound: Option<u32>,
1762
1763    /// Consensus Round after which DKG should be aborted and randomness disabled for
1764    /// the epoch, if it hasn't already completed.
1765    random_beacon_dkg_timeout_round: Option<u32>,
1766
1767    /// Minimum interval between consecutive rounds of generated randomness.
1768    random_beacon_min_round_interval_ms: Option<u64>,
1769
1770    /// Version of the random beacon DKG protocol.
1771    /// 0 was deprecated (and currently not supported), 1 is the default version.
1772    random_beacon_dkg_version: Option<u64>,
1773
1774    /// The maximum serialised transaction size (in bytes) accepted by consensus. That should be bigger than the
1775    /// `max_tx_size_bytes` with some additional headroom.
1776    consensus_max_transaction_size_bytes: Option<u64>,
1777    /// The maximum size of transactions included in a consensus block.
1778    consensus_max_transactions_in_block_bytes: Option<u64>,
1779    /// The maximum number of transactions included in a consensus block.
1780    consensus_max_num_transactions_in_block: Option<u64>,
1781
1782    /// The maximum number of rounds where transaction voting is allowed.
1783    consensus_voting_rounds: Option<u32>,
1784
1785    /// DEPRECATED. Do not use.
1786    max_accumulated_txn_cost_per_object_in_narwhal_commit: Option<u64>,
1787
1788    /// The max number of consensus rounds a transaction can be deferred due to shared object congestion.
1789    /// Transactions will be cancelled after this many rounds.
1790    max_deferral_rounds_for_congestion_control: Option<u64>,
1791
1792    /// DEPRECATED. Do not use.
1793    max_txn_cost_overage_per_object_in_commit: Option<u64>,
1794
1795    /// DEPRECATED. Do not use.
1796    allowed_txn_cost_overage_burst_per_object_in_commit: Option<u64>,
1797
1798    /// Minimum interval of commit timestamps between consecutive checkpoints.
1799    min_checkpoint_interval_ms: Option<u64>,
1800
1801    /// Version number to use for version_specific_data in `CheckpointSummary`.
1802    checkpoint_summary_version_specific_data: Option<u64>,
1803
1804    /// The max number of transactions that can be included in a single Soft Bundle.
1805    max_soft_bundle_size: Option<u64>,
1806
1807    /// Whether to try to form bridge committee
1808    // Note: this is not a feature flag because we want to distinguish between
1809    // `None` and `Some(false)`, as committee was already finalized on Testnet.
1810    bridge_should_try_to_finalize_committee: Option<bool>,
1811
1812    /// The max accumulated txn execution cost per object in a mysticeti. Transactions
1813    /// in a commit will be deferred once their touch shared objects hit this limit,
1814    /// unless the selected congestion control mode allows overage.
1815    /// This config plays the same role as `max_accumulated_txn_cost_per_object_in_narwhal_commit`
1816    /// but for mysticeti commits due to that mysticeti has higher commit rate.
1817    max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1818
1819    /// As above, but separate per-commit budget for transactions that use randomness.
1820    /// If not configured, uses the setting for `max_accumulated_txn_cost_per_object_in_mysticeti_commit`.
1821    max_accumulated_randomness_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1822
1823    /// Configures the garbage collection depth for consensus. When is unset or `0` then the garbage collection
1824    /// is disabled.
1825    consensus_gc_depth: Option<u32>,
1826
1827    /// DEPRECATED. Do not use.
1828    gas_budget_based_txn_cost_cap_factor: Option<u64>,
1829
1830    /// DEPRECATED. Do not use.
1831    gas_budget_based_txn_cost_absolute_cap_commit_count: Option<u64>,
1832
1833    /// SIP-45: K in the formula `amplification_factor = max(0, gas_price / reference_gas_price - K)`.
1834    /// This is the threshold for activating consensus amplification.
1835    sip_45_consensus_amplification_threshold: Option<u64>,
1836
1837    /// DEPRECATED: this was an ephemeral feature flag only used in per-epoch tables, which has now
1838    /// been deployed everywhere.
1839    use_object_per_epoch_marker_table_v2: Option<bool>,
1840
1841    /// The number of commits to consider when computing a deterministic commit rate.
1842    consensus_commit_rate_estimation_window_size: Option<u32>,
1843
1844    /// A list of effective AliasedAddress.
1845    /// For each pair, `aliased` is allowed to act as `original` for any of the transaction digests
1846    /// listed in `tx_digests`
1847    #[serde(skip_serializing_if = "Vec::is_empty")]
1848    aliased_addresses: Vec<AliasedAddress>,
1849
1850    /// The base charge for each command in a programmable transaction. This is a fixed cost to
1851    /// account for the overhead of processing each command.
1852    translation_per_command_base_charge: Option<u64>,
1853
1854    /// The base charge for each input in a programmable transaction regardless of if it is used or
1855    /// not, or a pure/object/funds withdrawal input.
1856    translation_per_input_base_charge: Option<u64>,
1857
1858    /// The base charge for each byte of pure input in a programmable transaction.
1859    translation_pure_input_per_byte_charge: Option<u64>,
1860
1861    /// The multiplier for the number of type nodes when charging for type loading.
1862    /// This is multiplied by the number of type nodes to get the total cost.
1863    /// This should be a small number to avoid excessive gas costs for loading types.
1864    translation_per_type_node_charge: Option<u64>,
1865
1866    /// The multiplier for the number of type references when charging for type checking and reference
1867    /// checking.
1868    translation_per_reference_node_charge: Option<u64>,
1869
1870    /// The multiplier for each linkage entry when charging for linkage tables that we have
1871    /// created.
1872    translation_per_linkage_entry_charge: Option<u64>,
1873
1874    /// The maximum number of updates per settlement transaction.
1875    max_updates_per_settlement_txn: Option<u32>,
1876}
1877
1878/// An aliased address.
1879#[derive(Clone, Serialize, Deserialize, Debug)]
1880pub struct AliasedAddress {
1881    /// The original address.
1882    pub original: [u8; 32],
1883    /// An aliased address which is allowed to act as the original address.
1884    pub aliased: [u8; 32],
1885    /// A list of transaction digests for which the aliasing is allowed to be in effect.
1886    pub allowed_tx_digests: Vec<[u8; 32]>,
1887}
1888
1889// feature flags
1890impl ProtocolConfig {
1891    // Add checks for feature flag support here, e.g.:
1892    // pub fn check_new_protocol_feature_supported(&self) -> Result<(), Error> {
1893    //     if self.feature_flags.new_protocol_feature_supported {
1894    //         Ok(())
1895    //     } else {
1896    //         Err(Error(format!(
1897    //             "new_protocol_feature is not supported at {:?}",
1898    //             self.version
1899    //         )))
1900    //     }
1901    // }
1902
1903    pub fn check_package_upgrades_supported(&self) -> Result<(), Error> {
1904        if self.feature_flags.package_upgrades {
1905            Ok(())
1906        } else {
1907            Err(Error(format!(
1908                "package upgrades are not supported at {:?}",
1909                self.version
1910            )))
1911        }
1912    }
1913
1914    pub fn allow_receiving_object_id(&self) -> bool {
1915        self.feature_flags.allow_receiving_object_id
1916    }
1917
1918    pub fn receiving_objects_supported(&self) -> bool {
1919        self.feature_flags.receive_objects
1920    }
1921
1922    pub fn package_upgrades_supported(&self) -> bool {
1923        self.feature_flags.package_upgrades
1924    }
1925
1926    pub fn check_commit_root_state_digest_supported(&self) -> bool {
1927        self.feature_flags.commit_root_state_digest
1928    }
1929
1930    pub fn get_advance_epoch_start_time_in_safe_mode(&self) -> bool {
1931        self.feature_flags.advance_epoch_start_time_in_safe_mode
1932    }
1933
1934    pub fn loaded_child_objects_fixed(&self) -> bool {
1935        self.feature_flags.loaded_child_objects_fixed
1936    }
1937
1938    pub fn missing_type_is_compatibility_error(&self) -> bool {
1939        self.feature_flags.missing_type_is_compatibility_error
1940    }
1941
1942    pub fn scoring_decision_with_validity_cutoff(&self) -> bool {
1943        self.feature_flags.scoring_decision_with_validity_cutoff
1944    }
1945
1946    pub fn narwhal_versioned_metadata(&self) -> bool {
1947        self.feature_flags.narwhal_versioned_metadata
1948    }
1949
1950    pub fn consensus_order_end_of_epoch_last(&self) -> bool {
1951        self.feature_flags.consensus_order_end_of_epoch_last
1952    }
1953
1954    pub fn disallow_adding_abilities_on_upgrade(&self) -> bool {
1955        self.feature_flags.disallow_adding_abilities_on_upgrade
1956    }
1957
1958    pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1959        self.feature_flags
1960            .disable_invariant_violation_check_in_swap_loc
1961    }
1962
1963    pub fn advance_to_highest_supported_protocol_version(&self) -> bool {
1964        self.feature_flags
1965            .advance_to_highest_supported_protocol_version
1966    }
1967
1968    pub fn ban_entry_init(&self) -> bool {
1969        self.feature_flags.ban_entry_init
1970    }
1971
1972    pub fn package_digest_hash_module(&self) -> bool {
1973        self.feature_flags.package_digest_hash_module
1974    }
1975
1976    pub fn disallow_change_struct_type_params_on_upgrade(&self) -> bool {
1977        self.feature_flags
1978            .disallow_change_struct_type_params_on_upgrade
1979    }
1980
1981    pub fn no_extraneous_module_bytes(&self) -> bool {
1982        self.feature_flags.no_extraneous_module_bytes
1983    }
1984
1985    pub fn zklogin_auth(&self) -> bool {
1986        self.feature_flags.zklogin_auth
1987    }
1988
1989    pub fn zklogin_supported_providers(&self) -> &BTreeSet<String> {
1990        &self.feature_flags.zklogin_supported_providers
1991    }
1992
1993    pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1994        self.feature_flags.consensus_transaction_ordering
1995    }
1996
1997    pub fn simplified_unwrap_then_delete(&self) -> bool {
1998        self.feature_flags.simplified_unwrap_then_delete
1999    }
2000
2001    pub fn supports_upgraded_multisig(&self) -> bool {
2002        self.feature_flags.upgraded_multisig_supported
2003    }
2004
2005    pub fn txn_base_cost_as_multiplier(&self) -> bool {
2006        self.feature_flags.txn_base_cost_as_multiplier
2007    }
2008
2009    pub fn shared_object_deletion(&self) -> bool {
2010        self.feature_flags.shared_object_deletion
2011    }
2012
2013    pub fn narwhal_new_leader_election_schedule(&self) -> bool {
2014        self.feature_flags.narwhal_new_leader_election_schedule
2015    }
2016
2017    pub fn loaded_child_object_format(&self) -> bool {
2018        self.feature_flags.loaded_child_object_format
2019    }
2020
2021    pub fn enable_jwk_consensus_updates(&self) -> bool {
2022        let ret = self.feature_flags.enable_jwk_consensus_updates;
2023        if ret {
2024            // jwk updates required end-of-epoch transactions
2025            assert!(self.feature_flags.end_of_epoch_transaction_supported);
2026        }
2027        ret
2028    }
2029
2030    pub fn simple_conservation_checks(&self) -> bool {
2031        self.feature_flags.simple_conservation_checks
2032    }
2033
2034    pub fn loaded_child_object_format_type(&self) -> bool {
2035        self.feature_flags.loaded_child_object_format_type
2036    }
2037
2038    pub fn end_of_epoch_transaction_supported(&self) -> bool {
2039        let ret = self.feature_flags.end_of_epoch_transaction_supported;
2040        if !ret {
2041            // jwk updates required end-of-epoch transactions
2042            assert!(!self.feature_flags.enable_jwk_consensus_updates);
2043        }
2044        ret
2045    }
2046
2047    pub fn recompute_has_public_transfer_in_execution(&self) -> bool {
2048        self.feature_flags
2049            .recompute_has_public_transfer_in_execution
2050    }
2051
2052    // this function only exists for readability in the genesis code.
2053    pub fn create_authenticator_state_in_genesis(&self) -> bool {
2054        self.enable_jwk_consensus_updates()
2055    }
2056
2057    pub fn random_beacon(&self) -> bool {
2058        self.feature_flags.random_beacon
2059    }
2060
2061    pub fn dkg_version(&self) -> u64 {
2062        // Version 0 was deprecated and removed, the default is 1 if not set.
2063        self.random_beacon_dkg_version.unwrap_or(1)
2064    }
2065
2066    pub fn enable_bridge(&self) -> bool {
2067        let ret = self.feature_flags.bridge;
2068        if ret {
2069            // bridge required end-of-epoch transactions
2070            assert!(self.feature_flags.end_of_epoch_transaction_supported);
2071        }
2072        ret
2073    }
2074
2075    pub fn should_try_to_finalize_bridge_committee(&self) -> bool {
2076        if !self.enable_bridge() {
2077            return false;
2078        }
2079        // In the older protocol version, always try to finalize the committee.
2080        self.bridge_should_try_to_finalize_committee.unwrap_or(true)
2081    }
2082
2083    pub fn enable_effects_v2(&self) -> bool {
2084        self.feature_flags.enable_effects_v2
2085    }
2086
2087    pub fn narwhal_certificate_v2(&self) -> bool {
2088        self.feature_flags.narwhal_certificate_v2
2089    }
2090
2091    pub fn verify_legacy_zklogin_address(&self) -> bool {
2092        self.feature_flags.verify_legacy_zklogin_address
2093    }
2094
2095    pub fn accept_zklogin_in_multisig(&self) -> bool {
2096        self.feature_flags.accept_zklogin_in_multisig
2097    }
2098
2099    pub fn accept_passkey_in_multisig(&self) -> bool {
2100        self.feature_flags.accept_passkey_in_multisig
2101    }
2102
2103    pub fn validate_zklogin_public_identifier(&self) -> bool {
2104        self.feature_flags.validate_zklogin_public_identifier
2105    }
2106
2107    pub fn zklogin_max_epoch_upper_bound_delta(&self) -> Option<u64> {
2108        self.feature_flags.zklogin_max_epoch_upper_bound_delta
2109    }
2110
2111    pub fn throughput_aware_consensus_submission(&self) -> bool {
2112        self.feature_flags.throughput_aware_consensus_submission
2113    }
2114
2115    pub fn include_consensus_digest_in_prologue(&self) -> bool {
2116        self.feature_flags.include_consensus_digest_in_prologue
2117    }
2118
2119    pub fn record_consensus_determined_version_assignments_in_prologue(&self) -> bool {
2120        self.feature_flags
2121            .record_consensus_determined_version_assignments_in_prologue
2122    }
2123
2124    pub fn record_additional_state_digest_in_prologue(&self) -> bool {
2125        self.feature_flags
2126            .record_additional_state_digest_in_prologue
2127    }
2128
2129    pub fn record_consensus_determined_version_assignments_in_prologue_v2(&self) -> bool {
2130        self.feature_flags
2131            .record_consensus_determined_version_assignments_in_prologue_v2
2132    }
2133
2134    pub fn prepend_prologue_tx_in_consensus_commit_in_checkpoints(&self) -> bool {
2135        self.feature_flags
2136            .prepend_prologue_tx_in_consensus_commit_in_checkpoints
2137    }
2138
2139    pub fn hardened_otw_check(&self) -> bool {
2140        self.feature_flags.hardened_otw_check
2141    }
2142
2143    pub fn enable_poseidon(&self) -> bool {
2144        self.feature_flags.enable_poseidon
2145    }
2146
2147    pub fn enable_coin_deny_list_v1(&self) -> bool {
2148        self.feature_flags.enable_coin_deny_list
2149    }
2150
2151    pub fn enable_accumulators(&self) -> bool {
2152        self.feature_flags.enable_accumulators
2153    }
2154
2155    pub fn enable_coin_reservation_obj_refs(&self) -> bool {
2156        self.feature_flags.enable_coin_reservation_obj_refs
2157    }
2158
2159    pub fn create_root_accumulator_object(&self) -> bool {
2160        self.feature_flags.create_root_accumulator_object
2161    }
2162
2163    pub fn enable_address_balance_gas_payments(&self) -> bool {
2164        self.feature_flags.enable_address_balance_gas_payments
2165    }
2166
2167    pub fn address_balance_gas_check_rgp_at_signing(&self) -> bool {
2168        self.feature_flags.address_balance_gas_check_rgp_at_signing
2169    }
2170
2171    pub fn address_balance_gas_reject_gas_coin_arg(&self) -> bool {
2172        self.feature_flags.address_balance_gas_reject_gas_coin_arg
2173    }
2174
2175    pub fn enable_multi_epoch_transaction_expiration(&self) -> bool {
2176        self.feature_flags.enable_multi_epoch_transaction_expiration
2177    }
2178
2179    pub fn enable_authenticated_event_streams(&self) -> bool {
2180        self.feature_flags.enable_authenticated_event_streams && self.enable_accumulators()
2181    }
2182
2183    pub fn enable_non_exclusive_writes(&self) -> bool {
2184        self.feature_flags.enable_non_exclusive_writes
2185    }
2186
2187    pub fn enable_coin_registry(&self) -> bool {
2188        self.feature_flags.enable_coin_registry
2189    }
2190
2191    pub fn enable_display_registry(&self) -> bool {
2192        self.feature_flags.enable_display_registry
2193    }
2194
2195    pub fn enable_coin_deny_list_v2(&self) -> bool {
2196        self.feature_flags.enable_coin_deny_list_v2
2197    }
2198
2199    pub fn enable_group_ops_native_functions(&self) -> bool {
2200        self.feature_flags.enable_group_ops_native_functions
2201    }
2202
2203    pub fn enable_group_ops_native_function_msm(&self) -> bool {
2204        self.feature_flags.enable_group_ops_native_function_msm
2205    }
2206
2207    pub fn enable_ristretto255_group_ops(&self) -> bool {
2208        self.feature_flags.enable_ristretto255_group_ops
2209    }
2210
2211    pub fn reject_mutable_random_on_entry_functions(&self) -> bool {
2212        self.feature_flags.reject_mutable_random_on_entry_functions
2213    }
2214
2215    pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
2216        self.feature_flags.per_object_congestion_control_mode
2217    }
2218
2219    pub fn consensus_choice(&self) -> ConsensusChoice {
2220        self.feature_flags.consensus_choice
2221    }
2222
2223    pub fn consensus_network(&self) -> ConsensusNetwork {
2224        self.feature_flags.consensus_network
2225    }
2226
2227    pub fn correct_gas_payment_limit_check(&self) -> bool {
2228        self.feature_flags.correct_gas_payment_limit_check
2229    }
2230
2231    pub fn reshare_at_same_initial_version(&self) -> bool {
2232        self.feature_flags.reshare_at_same_initial_version
2233    }
2234
2235    pub fn resolve_abort_locations_to_package_id(&self) -> bool {
2236        self.feature_flags.resolve_abort_locations_to_package_id
2237    }
2238
2239    pub fn mysticeti_use_committed_subdag_digest(&self) -> bool {
2240        self.feature_flags.mysticeti_use_committed_subdag_digest
2241    }
2242
2243    pub fn enable_vdf(&self) -> bool {
2244        self.feature_flags.enable_vdf
2245    }
2246
2247    pub fn fresh_vm_on_framework_upgrade(&self) -> bool {
2248        self.feature_flags.fresh_vm_on_framework_upgrade
2249    }
2250
2251    pub fn mysticeti_num_leaders_per_round(&self) -> Option<usize> {
2252        self.feature_flags.mysticeti_num_leaders_per_round
2253    }
2254
2255    pub fn soft_bundle(&self) -> bool {
2256        self.feature_flags.soft_bundle
2257    }
2258
2259    pub fn passkey_auth(&self) -> bool {
2260        self.feature_flags.passkey_auth
2261    }
2262
2263    pub fn authority_capabilities_v2(&self) -> bool {
2264        self.feature_flags.authority_capabilities_v2
2265    }
2266
2267    pub fn max_transaction_size_bytes(&self) -> u64 {
2268        // Provide a default value if protocol config version is too low.
2269        self.consensus_max_transaction_size_bytes
2270            .unwrap_or(256 * 1024)
2271    }
2272
2273    pub fn max_transactions_in_block_bytes(&self) -> u64 {
2274        if cfg!(msim) {
2275            256 * 1024
2276        } else {
2277            self.consensus_max_transactions_in_block_bytes
2278                .unwrap_or(512 * 1024)
2279        }
2280    }
2281
2282    pub fn max_num_transactions_in_block(&self) -> u64 {
2283        if cfg!(msim) {
2284            8
2285        } else {
2286            self.consensus_max_num_transactions_in_block.unwrap_or(512)
2287        }
2288    }
2289
2290    pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
2291        self.feature_flags.rethrow_serialization_type_layout_errors
2292    }
2293
2294    pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
2295        self.feature_flags
2296            .consensus_distributed_vote_scoring_strategy
2297    }
2298
2299    pub fn consensus_round_prober(&self) -> bool {
2300        self.feature_flags.consensus_round_prober
2301    }
2302
2303    pub fn validate_identifier_inputs(&self) -> bool {
2304        self.feature_flags.validate_identifier_inputs
2305    }
2306
2307    pub fn gc_depth(&self) -> u32 {
2308        self.consensus_gc_depth.unwrap_or(0)
2309    }
2310
2311    pub fn mysticeti_fastpath(&self) -> bool {
2312        self.feature_flags.mysticeti_fastpath
2313    }
2314
2315    pub fn relocate_event_module(&self) -> bool {
2316        self.feature_flags.relocate_event_module
2317    }
2318
2319    pub fn uncompressed_g1_group_elements(&self) -> bool {
2320        self.feature_flags.uncompressed_g1_group_elements
2321    }
2322
2323    pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
2324        self.feature_flags
2325            .disallow_new_modules_in_deps_only_packages
2326    }
2327
2328    pub fn consensus_smart_ancestor_selection(&self) -> bool {
2329        self.feature_flags.consensus_smart_ancestor_selection
2330    }
2331
2332    pub fn disable_preconsensus_locking(&self) -> bool {
2333        self.feature_flags.disable_preconsensus_locking
2334    }
2335
2336    pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
2337        self.feature_flags
2338            .consensus_round_prober_probe_accepted_rounds
2339    }
2340
2341    pub fn native_charging_v2(&self) -> bool {
2342        self.feature_flags.native_charging_v2
2343    }
2344
2345    pub fn consensus_linearize_subdag_v2(&self) -> bool {
2346        let res = self.feature_flags.consensus_linearize_subdag_v2;
2347        assert!(
2348            !res || self.gc_depth() > 0,
2349            "The consensus linearize sub dag V2 requires GC to be enabled"
2350        );
2351        res
2352    }
2353
2354    pub fn consensus_median_based_commit_timestamp(&self) -> bool {
2355        let res = self.feature_flags.consensus_median_based_commit_timestamp;
2356        assert!(
2357            !res || self.gc_depth() > 0,
2358            "The consensus median based commit timestamp requires GC to be enabled"
2359        );
2360        res
2361    }
2362
2363    pub fn consensus_batched_block_sync(&self) -> bool {
2364        self.feature_flags.consensus_batched_block_sync
2365    }
2366
2367    pub fn convert_type_argument_error(&self) -> bool {
2368        self.feature_flags.convert_type_argument_error
2369    }
2370
2371    pub fn variant_nodes(&self) -> bool {
2372        self.feature_flags.variant_nodes
2373    }
2374
2375    pub fn consensus_zstd_compression(&self) -> bool {
2376        self.feature_flags.consensus_zstd_compression
2377    }
2378
2379    pub fn enable_nitro_attestation(&self) -> bool {
2380        self.feature_flags.enable_nitro_attestation
2381    }
2382
2383    pub fn enable_nitro_attestation_upgraded_parsing(&self) -> bool {
2384        self.feature_flags.enable_nitro_attestation_upgraded_parsing
2385    }
2386
2387    pub fn enable_nitro_attestation_all_nonzero_pcrs_parsing(&self) -> bool {
2388        self.feature_flags
2389            .enable_nitro_attestation_all_nonzero_pcrs_parsing
2390    }
2391
2392    pub fn enable_nitro_attestation_always_include_required_pcrs_parsing(&self) -> bool {
2393        self.feature_flags
2394            .enable_nitro_attestation_always_include_required_pcrs_parsing
2395    }
2396
2397    pub fn get_consensus_commit_rate_estimation_window_size(&self) -> u32 {
2398        self.consensus_commit_rate_estimation_window_size
2399            .unwrap_or(0)
2400    }
2401
2402    pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
2403        // Currently there is only one parameter driving this value. If there are multiple
2404        // things computed from prior consensus commits, this function must return the max
2405        // of all of them.
2406        let window_size = self.get_consensus_commit_rate_estimation_window_size();
2407        // Ensure we are not using past commits without recording a state digest in the prologue.
2408        assert!(window_size == 0 || self.record_additional_state_digest_in_prologue());
2409        window_size
2410    }
2411
2412    pub fn minimize_child_object_mutations(&self) -> bool {
2413        self.feature_flags.minimize_child_object_mutations
2414    }
2415
2416    pub fn move_native_context(&self) -> bool {
2417        self.feature_flags.move_native_context
2418    }
2419
2420    pub fn normalize_ptb_arguments(&self) -> bool {
2421        self.feature_flags.normalize_ptb_arguments
2422    }
2423
2424    pub fn enforce_checkpoint_timestamp_monotonicity(&self) -> bool {
2425        self.feature_flags.enforce_checkpoint_timestamp_monotonicity
2426    }
2427
2428    pub fn max_ptb_value_size_v2(&self) -> bool {
2429        self.feature_flags.max_ptb_value_size_v2
2430    }
2431
2432    pub fn resolve_type_input_ids_to_defining_id(&self) -> bool {
2433        self.feature_flags.resolve_type_input_ids_to_defining_id
2434    }
2435
2436    pub fn enable_party_transfer(&self) -> bool {
2437        self.feature_flags.enable_party_transfer
2438    }
2439
2440    pub fn allow_unbounded_system_objects(&self) -> bool {
2441        self.feature_flags.allow_unbounded_system_objects
2442    }
2443
2444    pub fn type_tags_in_object_runtime(&self) -> bool {
2445        self.feature_flags.type_tags_in_object_runtime
2446    }
2447
2448    pub fn enable_ptb_execution_v2(&self) -> bool {
2449        self.feature_flags.enable_ptb_execution_v2
2450    }
2451
2452    pub fn better_adapter_type_resolution_errors(&self) -> bool {
2453        self.feature_flags.better_adapter_type_resolution_errors
2454    }
2455
2456    pub fn record_time_estimate_processed(&self) -> bool {
2457        self.feature_flags.record_time_estimate_processed
2458    }
2459
2460    pub fn ignore_execution_time_observations_after_certs_closed(&self) -> bool {
2461        self.feature_flags
2462            .ignore_execution_time_observations_after_certs_closed
2463    }
2464
2465    pub fn dependency_linkage_error(&self) -> bool {
2466        self.feature_flags.dependency_linkage_error
2467    }
2468
2469    pub fn additional_multisig_checks(&self) -> bool {
2470        self.feature_flags.additional_multisig_checks
2471    }
2472
2473    pub fn debug_fatal_on_move_invariant_violation(&self) -> bool {
2474        self.feature_flags.debug_fatal_on_move_invariant_violation
2475    }
2476
2477    pub fn allow_private_accumulator_entrypoints(&self) -> bool {
2478        self.feature_flags.allow_private_accumulator_entrypoints
2479    }
2480
2481    pub fn additional_consensus_digest_indirect_state(&self) -> bool {
2482        self.feature_flags
2483            .additional_consensus_digest_indirect_state
2484    }
2485
2486    pub fn check_for_init_during_upgrade(&self) -> bool {
2487        self.feature_flags.check_for_init_during_upgrade
2488    }
2489
2490    pub fn per_command_shared_object_transfer_rules(&self) -> bool {
2491        self.feature_flags.per_command_shared_object_transfer_rules
2492    }
2493
2494    pub fn consensus_checkpoint_signature_key_includes_digest(&self) -> bool {
2495        self.feature_flags
2496            .consensus_checkpoint_signature_key_includes_digest
2497    }
2498
2499    pub fn include_checkpoint_artifacts_digest_in_summary(&self) -> bool {
2500        self.feature_flags
2501            .include_checkpoint_artifacts_digest_in_summary
2502    }
2503
2504    pub fn use_mfp_txns_in_load_initial_object_debts(&self) -> bool {
2505        self.feature_flags.use_mfp_txns_in_load_initial_object_debts
2506    }
2507
2508    pub fn cancel_for_failed_dkg_early(&self) -> bool {
2509        self.feature_flags.cancel_for_failed_dkg_early
2510    }
2511
2512    pub fn abstract_size_in_object_runtime(&self) -> bool {
2513        self.feature_flags.abstract_size_in_object_runtime
2514    }
2515
2516    pub fn object_runtime_charge_cache_load_gas(&self) -> bool {
2517        self.feature_flags.object_runtime_charge_cache_load_gas
2518    }
2519
2520    pub fn additional_borrow_checks(&self) -> bool {
2521        self.feature_flags.additional_borrow_checks
2522    }
2523
2524    pub fn use_new_commit_handler(&self) -> bool {
2525        self.feature_flags.use_new_commit_handler
2526    }
2527
2528    pub fn better_loader_errors(&self) -> bool {
2529        self.feature_flags.better_loader_errors
2530    }
2531
2532    pub fn generate_df_type_layouts(&self) -> bool {
2533        self.feature_flags.generate_df_type_layouts
2534    }
2535
2536    pub fn allow_references_in_ptbs(&self) -> bool {
2537        self.feature_flags.allow_references_in_ptbs
2538    }
2539
2540    pub fn private_generics_verifier_v2(&self) -> bool {
2541        self.feature_flags.private_generics_verifier_v2
2542    }
2543
2544    pub fn deprecate_global_storage_ops_during_deserialization(&self) -> bool {
2545        self.feature_flags
2546            .deprecate_global_storage_ops_during_deserialization
2547    }
2548
2549    pub fn enable_observation_chunking(&self) -> bool {
2550        matches!(self.feature_flags.per_object_congestion_control_mode,
2551            PerObjectCongestionControlMode::ExecutionTimeEstimate(ref params)
2552                if params.observations_chunk_size.is_some()
2553        )
2554    }
2555
2556    pub fn deprecate_global_storage_ops(&self) -> bool {
2557        self.feature_flags.deprecate_global_storage_ops
2558    }
2559
2560    pub fn consensus_skip_gced_accept_votes(&self) -> bool {
2561        self.feature_flags.consensus_skip_gced_accept_votes
2562    }
2563
2564    pub fn include_cancelled_randomness_txns_in_prologue(&self) -> bool {
2565        self.feature_flags
2566            .include_cancelled_randomness_txns_in_prologue
2567    }
2568
2569    pub fn address_aliases(&self) -> bool {
2570        let address_aliases = self.feature_flags.address_aliases;
2571        assert!(
2572            !address_aliases || self.mysticeti_fastpath(),
2573            "Address aliases requires Mysticeti fastpath to be enabled"
2574        );
2575        if address_aliases {
2576            assert!(
2577                self.feature_flags.disable_preconsensus_locking,
2578                "Address aliases requires CertifiedTransaction to be disabled"
2579            );
2580        }
2581        address_aliases
2582    }
2583
2584    pub fn fix_checkpoint_signature_mapping(&self) -> bool {
2585        self.feature_flags.fix_checkpoint_signature_mapping
2586    }
2587
2588    pub fn enable_object_funds_withdraw(&self) -> bool {
2589        self.feature_flags.enable_object_funds_withdraw
2590    }
2591
2592    pub fn gas_rounding_halve_digits(&self) -> bool {
2593        self.feature_flags.gas_rounding_halve_digits
2594    }
2595
2596    pub fn flexible_tx_context_positions(&self) -> bool {
2597        self.feature_flags.flexible_tx_context_positions
2598    }
2599
2600    pub fn disable_entry_point_signature_check(&self) -> bool {
2601        self.feature_flags.disable_entry_point_signature_check
2602    }
2603
2604    pub fn consensus_skip_gced_blocks_in_direct_finalization(&self) -> bool {
2605        self.feature_flags
2606            .consensus_skip_gced_blocks_in_direct_finalization
2607    }
2608
2609    pub fn convert_withdrawal_compatibility_ptb_arguments(&self) -> bool {
2610        self.feature_flags
2611            .convert_withdrawal_compatibility_ptb_arguments
2612    }
2613
2614    pub fn restrict_hot_or_not_entry_functions(&self) -> bool {
2615        self.feature_flags.restrict_hot_or_not_entry_functions
2616    }
2617
2618    pub fn split_checkpoints_in_consensus_handler(&self) -> bool {
2619        self.feature_flags.split_checkpoints_in_consensus_handler
2620    }
2621
2622    pub fn consensus_always_accept_system_transactions(&self) -> bool {
2623        self.feature_flags
2624            .consensus_always_accept_system_transactions
2625    }
2626
2627    pub fn validator_metadata_verify_v2(&self) -> bool {
2628        self.feature_flags.validator_metadata_verify_v2
2629    }
2630
2631    pub fn defer_unpaid_amplification(&self) -> bool {
2632        self.feature_flags.defer_unpaid_amplification
2633    }
2634}
2635
2636#[cfg(not(msim))]
2637static POISON_VERSION_METHODS: AtomicBool = AtomicBool::new(false);
2638
2639// Use a thread local in sim tests for test isolation.
2640#[cfg(msim)]
2641thread_local! {
2642    static POISON_VERSION_METHODS: AtomicBool = AtomicBool::new(false);
2643}
2644
2645// Instantiations for each protocol version.
2646impl ProtocolConfig {
2647    /// Get the value ProtocolConfig that are in effect during the given protocol version.
2648    pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
2649        // ProtocolVersion can be deserialized so we need to check it here as well.
2650        assert!(
2651            version >= ProtocolVersion::MIN,
2652            "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
2653            version,
2654            ProtocolVersion::MIN.0,
2655        );
2656        assert!(
2657            version <= ProtocolVersion::MAX_ALLOWED,
2658            "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
2659            version,
2660            ProtocolVersion::MAX_ALLOWED.0,
2661        );
2662
2663        let mut ret = Self::get_for_version_impl(version, chain);
2664        ret.version = version;
2665
2666        ret = CONFIG_OVERRIDE.with(|ovr| {
2667            if let Some(override_fn) = &*ovr.borrow() {
2668                warn!(
2669                    "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
2670                );
2671                override_fn(version, ret)
2672            } else {
2673                ret
2674            }
2675        });
2676
2677        if std::env::var("SUI_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
2678            warn!(
2679                "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
2680            );
2681            let overrides: ProtocolConfigOptional =
2682                serde_env::from_env_with_prefix("SUI_PROTOCOL_CONFIG_OVERRIDE")
2683                    .expect("failed to parse ProtocolConfig override env variables");
2684            overrides.apply_to(&mut ret);
2685        }
2686
2687        ret
2688    }
2689
2690    /// Get the value ProtocolConfig that are in effect during the given protocol version.
2691    /// Or none if the version is not supported.
2692    pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
2693        if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
2694            let mut ret = Self::get_for_version_impl(version, chain);
2695            ret.version = version;
2696            Some(ret)
2697        } else {
2698            None
2699        }
2700    }
2701
2702    #[cfg(not(msim))]
2703    pub fn poison_get_for_min_version() {
2704        POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
2705    }
2706
2707    #[cfg(not(msim))]
2708    fn load_poison_get_for_min_version() -> bool {
2709        POISON_VERSION_METHODS.load(Ordering::Relaxed)
2710    }
2711
2712    #[cfg(msim)]
2713    pub fn poison_get_for_min_version() {
2714        POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
2715    }
2716
2717    #[cfg(msim)]
2718    fn load_poison_get_for_min_version() -> bool {
2719        POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
2720    }
2721
2722    /// Convenience to get the constants at the current minimum supported version.
2723    /// Mainly used by client code that may not yet be protocol-version aware.
2724    pub fn get_for_min_version() -> Self {
2725        if Self::load_poison_get_for_min_version() {
2726            panic!("get_for_min_version called on validator");
2727        }
2728        ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
2729    }
2730
2731    /// CAREFUL! - You probably want to use `get_for_version` instead.
2732    ///
2733    /// Convenience to get the constants at the current maximum supported version.
2734    /// Mainly used by genesis. Note well that this function uses the max version
2735    /// supported locally by the node, which is not necessarily the current version
2736    /// of the network. ALSO, this function disregards chain specific config (by
2737    /// using Chain::Unknown), thereby potentially returning a protocol config that
2738    /// is incorrect for some feature flags. Definitely safe for testing and for
2739    /// protocol version 11 and prior.
2740    #[allow(non_snake_case)]
2741    pub fn get_for_max_version_UNSAFE() -> Self {
2742        if Self::load_poison_get_for_min_version() {
2743            panic!("get_for_max_version_UNSAFE called on validator");
2744        }
2745        ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
2746    }
2747
2748    fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
2749        #[cfg(msim)]
2750        {
2751            // populate the fake simulator version # with a different base tx cost.
2752            if version == ProtocolVersion::MAX_ALLOWED {
2753                let mut config = Self::get_for_version_impl(version - 1, Chain::Unknown);
2754                config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
2755                return config;
2756            }
2757        }
2758
2759        // IMPORTANT: Never modify the value of any constant for a pre-existing protocol version.
2760        // To change the values here you must create a new protocol version with the new values!
2761        let mut cfg = Self {
2762            // will be overwritten before being returned
2763            version,
2764
2765            // All flags are disabled in V1
2766            feature_flags: Default::default(),
2767
2768            max_tx_size_bytes: Some(128 * 1024),
2769            // We need this number to be at least 100x less than `max_serialized_tx_effects_size_bytes`otherwise effects can be huge
2770            max_input_objects: Some(2048),
2771            max_serialized_tx_effects_size_bytes: Some(512 * 1024),
2772            max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
2773            max_gas_payment_objects: Some(256),
2774            max_modules_in_publish: Some(128),
2775            max_package_dependencies: None,
2776            max_arguments: Some(512),
2777            max_type_arguments: Some(16),
2778            max_type_argument_depth: Some(16),
2779            max_pure_argument_size: Some(16 * 1024),
2780            max_programmable_tx_commands: Some(1024),
2781            move_binary_format_version: Some(6),
2782            min_move_binary_format_version: None,
2783            binary_module_handles: None,
2784            binary_struct_handles: None,
2785            binary_function_handles: None,
2786            binary_function_instantiations: None,
2787            binary_signatures: None,
2788            binary_constant_pool: None,
2789            binary_identifiers: None,
2790            binary_address_identifiers: None,
2791            binary_struct_defs: None,
2792            binary_struct_def_instantiations: None,
2793            binary_function_defs: None,
2794            binary_field_handles: None,
2795            binary_field_instantiations: None,
2796            binary_friend_decls: None,
2797            binary_enum_defs: None,
2798            binary_enum_def_instantiations: None,
2799            binary_variant_handles: None,
2800            binary_variant_instantiation_handles: None,
2801            max_move_object_size: Some(250 * 1024),
2802            max_move_package_size: Some(100 * 1024),
2803            max_publish_or_upgrade_per_ptb: None,
2804            max_tx_gas: Some(10_000_000_000),
2805            max_gas_price: Some(100_000),
2806            max_gas_price_rgp_factor_for_aborted_transactions: None,
2807            max_gas_computation_bucket: Some(5_000_000),
2808            max_loop_depth: Some(5),
2809            max_generic_instantiation_length: Some(32),
2810            max_function_parameters: Some(128),
2811            max_basic_blocks: Some(1024),
2812            max_value_stack_size: Some(1024),
2813            max_type_nodes: Some(256),
2814            max_push_size: Some(10000),
2815            max_struct_definitions: Some(200),
2816            max_function_definitions: Some(1000),
2817            max_fields_in_struct: Some(32),
2818            max_dependency_depth: Some(100),
2819            max_num_event_emit: Some(256),
2820            max_num_new_move_object_ids: Some(2048),
2821            max_num_new_move_object_ids_system_tx: Some(2048 * 16),
2822            max_num_deleted_move_object_ids: Some(2048),
2823            max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
2824            max_num_transferred_move_object_ids: Some(2048),
2825            max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
2826            max_event_emit_size: Some(250 * 1024),
2827            max_move_vector_len: Some(256 * 1024),
2828            max_type_to_layout_nodes: None,
2829            max_ptb_value_size: None,
2830
2831            max_back_edges_per_function: Some(10_000),
2832            max_back_edges_per_module: Some(10_000),
2833            max_verifier_meter_ticks_per_function: Some(6_000_000),
2834            max_meter_ticks_per_module: Some(6_000_000),
2835            max_meter_ticks_per_package: None,
2836
2837            object_runtime_max_num_cached_objects: Some(1000),
2838            object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2839            object_runtime_max_num_store_entries: Some(1000),
2840            object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2841            base_tx_cost_fixed: Some(110_000),
2842            package_publish_cost_fixed: Some(1_000),
2843            base_tx_cost_per_byte: Some(0),
2844            package_publish_cost_per_byte: Some(80),
2845            obj_access_cost_read_per_byte: Some(15),
2846            obj_access_cost_mutate_per_byte: Some(40),
2847            obj_access_cost_delete_per_byte: Some(40),
2848            obj_access_cost_verify_per_byte: Some(200),
2849            obj_data_cost_refundable: Some(100),
2850            obj_metadata_cost_non_refundable: Some(50),
2851            gas_model_version: Some(1),
2852            storage_rebate_rate: Some(9900),
2853            storage_fund_reinvest_rate: Some(500),
2854            reward_slashing_rate: Some(5000),
2855            storage_gas_price: Some(1),
2856            accumulator_object_storage_cost: None,
2857            max_transactions_per_checkpoint: Some(10_000),
2858            max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2859
2860            // For now, perform upgrades with a bare quorum of validators.
2861            // MUSTFIX: This number should be increased to at least 2000 (20%) for mainnet.
2862            buffer_stake_for_protocol_upgrade_bps: Some(0),
2863
2864            // === Native Function Costs ===
2865            // `address` module
2866            // Cost params for the Move native function `address::from_bytes(bytes: vector<u8>)`
2867            address_from_bytes_cost_base: Some(52),
2868            // Cost params for the Move native function `address::to_u256(address): u256`
2869            address_to_u256_cost_base: Some(52),
2870            // Cost params for the Move native function `address::from_u256(u256): address`
2871            address_from_u256_cost_base: Some(52),
2872
2873            // `config` module
2874            // Cost params for the Move native function `read_setting_impl``
2875            config_read_setting_impl_cost_base: None,
2876            config_read_setting_impl_cost_per_byte: None,
2877
2878            // `dynamic_field` module
2879            // Cost params for the Move native function `hash_type_and_key<K: copy + drop + store>(parent: address, k: K): address`
2880            dynamic_field_hash_type_and_key_cost_base: Some(100),
2881            dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
2882            dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
2883            dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
2884            // Cost params for the Move native function `add_child_object<Child: key>(parent: address, child: Child)`
2885            dynamic_field_add_child_object_cost_base: Some(100),
2886            dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2887            dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2888            dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2889            // Cost params for the Move native function `borrow_child_object_mut<Child: key>(parent: &mut UID, id: address): &mut Child`
2890            dynamic_field_borrow_child_object_cost_base: Some(100),
2891            dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2892            dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2893            // Cost params for the Move native function `remove_child_object<Child: key>(parent: address, id: address): Child`
2894            dynamic_field_remove_child_object_cost_base: Some(100),
2895            dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2896            dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2897            // Cost params for the Move native function `has_child_object(parent: address, id: address): bool`
2898            dynamic_field_has_child_object_cost_base: Some(100),
2899            // Cost params for the Move native function `has_child_object_with_ty<Child: key>(parent: address, id: address): bool`
2900            dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2901            dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2902            dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2903
2904            // `event` module
2905            // Cost params for the Move native function `event::emit<T: copy + drop>(event: T)`
2906            event_emit_cost_base: Some(52),
2907            event_emit_value_size_derivation_cost_per_byte: Some(2),
2908            event_emit_tag_size_derivation_cost_per_byte: Some(5),
2909            event_emit_output_cost_per_byte: Some(10),
2910            event_emit_auth_stream_cost: None,
2911
2912            //  `object` module
2913            // Cost params for the Move native function `borrow_uid<T: key>(obj: &T): &UID`
2914            object_borrow_uid_cost_base: Some(52),
2915            // Cost params for the Move native function `delete_impl(id: address)`
2916            object_delete_impl_cost_base: Some(52),
2917            // Cost params for the Move native function `record_new_uid(id: address)`
2918            object_record_new_uid_cost_base: Some(52),
2919
2920            // `transfer` module
2921            // Cost params for the Move native function `transfer_impl<T: key>(obj: T, recipient: address)`
2922            transfer_transfer_internal_cost_base: Some(52),
2923            // Cost params for the Move native function `party_transfer_impl<T: key>(obj: T, party_members: vector<address>)`
2924            transfer_party_transfer_internal_cost_base: None,
2925            // Cost params for the Move native function `freeze_object<T: key>(obj: T)`
2926            transfer_freeze_object_cost_base: Some(52),
2927            // Cost params for the Move native function `share_object<T: key>(obj: T)`
2928            transfer_share_object_cost_base: Some(52),
2929            transfer_receive_object_cost_base: None,
2930
2931            // `tx_context` module
2932            // Cost params for the Move native function `transfer_impl<T: key>(obj: T, recipient: address)`
2933            tx_context_derive_id_cost_base: Some(52),
2934            tx_context_fresh_id_cost_base: None,
2935            tx_context_sender_cost_base: None,
2936            tx_context_epoch_cost_base: None,
2937            tx_context_epoch_timestamp_ms_cost_base: None,
2938            tx_context_sponsor_cost_base: None,
2939            tx_context_rgp_cost_base: None,
2940            tx_context_gas_price_cost_base: None,
2941            tx_context_gas_budget_cost_base: None,
2942            tx_context_ids_created_cost_base: None,
2943            tx_context_replace_cost_base: None,
2944
2945            // `types` module
2946            // Cost params for the Move native function `is_one_time_witness<T: drop>(_: &T): bool`
2947            types_is_one_time_witness_cost_base: Some(52),
2948            types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2949            types_is_one_time_witness_type_cost_per_byte: Some(2),
2950
2951            // `validator` module
2952            // Cost params for the Move native function `validate_metadata_bcs(metadata: vector<u8>)`
2953            validator_validate_metadata_cost_base: Some(52),
2954            validator_validate_metadata_data_cost_per_byte: Some(2),
2955
2956            // Crypto
2957            crypto_invalid_arguments_cost: Some(100),
2958            // bls12381::bls12381_min_pk_verify
2959            bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2960            bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2961            bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2962
2963            // bls12381::bls12381_min_pk_verify
2964            bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2965            bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2966            bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2967
2968            // ecdsa_k1::ecrecover
2969            ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2970            ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2971            ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2972            ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2973            ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2974            ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2975
2976            // ecdsa_k1::decompress_pubkey
2977            ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2978
2979            // ecdsa_k1::secp256k1_verify
2980            ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2981            ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2982            ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2983            ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2984            ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2985            ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2986
2987            // ecdsa_r1::ecrecover
2988            ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2989            ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2990            ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2991            ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2992            ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2993            ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2994
2995            // ecdsa_r1::secp256k1_verify
2996            ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2997            ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2998            ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2999            ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
3000            ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
3001            ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
3002
3003            // ecvrf::verify
3004            ecvrf_ecvrf_verify_cost_base: Some(52),
3005            ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
3006            ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
3007
3008            // ed25519
3009            ed25519_ed25519_verify_cost_base: Some(52),
3010            ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
3011            ed25519_ed25519_verify_msg_cost_per_block: Some(2),
3012
3013            // groth16::prepare_verifying_key
3014            groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
3015            groth16_prepare_verifying_key_bn254_cost_base: Some(52),
3016
3017            // groth16::verify_groth16_proof_internal
3018            groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
3019            groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
3020            groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
3021            groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
3022            groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
3023
3024            // hash::blake2b256
3025            hash_blake2b256_cost_base: Some(52),
3026            hash_blake2b256_data_cost_per_byte: Some(2),
3027            hash_blake2b256_data_cost_per_block: Some(2),
3028
3029            // hash::keccak256
3030            hash_keccak256_cost_base: Some(52),
3031            hash_keccak256_data_cost_per_byte: Some(2),
3032            hash_keccak256_data_cost_per_block: Some(2),
3033
3034            poseidon_bn254_cost_base: None,
3035            poseidon_bn254_cost_per_block: None,
3036
3037            // hmac::hmac_sha3_256
3038            hmac_hmac_sha3_256_cost_base: Some(52),
3039            hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
3040            hmac_hmac_sha3_256_input_cost_per_block: Some(2),
3041
3042            // group ops
3043            group_ops_bls12381_decode_scalar_cost: None,
3044            group_ops_bls12381_decode_g1_cost: None,
3045            group_ops_bls12381_decode_g2_cost: None,
3046            group_ops_bls12381_decode_gt_cost: None,
3047            group_ops_bls12381_scalar_add_cost: None,
3048            group_ops_bls12381_g1_add_cost: None,
3049            group_ops_bls12381_g2_add_cost: None,
3050            group_ops_bls12381_gt_add_cost: None,
3051            group_ops_bls12381_scalar_sub_cost: None,
3052            group_ops_bls12381_g1_sub_cost: None,
3053            group_ops_bls12381_g2_sub_cost: None,
3054            group_ops_bls12381_gt_sub_cost: None,
3055            group_ops_bls12381_scalar_mul_cost: None,
3056            group_ops_bls12381_g1_mul_cost: None,
3057            group_ops_bls12381_g2_mul_cost: None,
3058            group_ops_bls12381_gt_mul_cost: None,
3059            group_ops_bls12381_scalar_div_cost: None,
3060            group_ops_bls12381_g1_div_cost: None,
3061            group_ops_bls12381_g2_div_cost: None,
3062            group_ops_bls12381_gt_div_cost: None,
3063            group_ops_bls12381_g1_hash_to_base_cost: None,
3064            group_ops_bls12381_g2_hash_to_base_cost: None,
3065            group_ops_bls12381_g1_hash_to_cost_per_byte: None,
3066            group_ops_bls12381_g2_hash_to_cost_per_byte: None,
3067            group_ops_bls12381_g1_msm_base_cost: None,
3068            group_ops_bls12381_g2_msm_base_cost: None,
3069            group_ops_bls12381_g1_msm_base_cost_per_input: None,
3070            group_ops_bls12381_g2_msm_base_cost_per_input: None,
3071            group_ops_bls12381_msm_max_len: None,
3072            group_ops_bls12381_pairing_cost: None,
3073            group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
3074            group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
3075            group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
3076            group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
3077            group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
3078
3079            group_ops_ristretto_decode_scalar_cost: None,
3080            group_ops_ristretto_decode_point_cost: None,
3081            group_ops_ristretto_scalar_add_cost: None,
3082            group_ops_ristretto_point_add_cost: None,
3083            group_ops_ristretto_scalar_sub_cost: None,
3084            group_ops_ristretto_point_sub_cost: None,
3085            group_ops_ristretto_scalar_mul_cost: None,
3086            group_ops_ristretto_point_mul_cost: None,
3087            group_ops_ristretto_scalar_div_cost: None,
3088            group_ops_ristretto_point_div_cost: None,
3089
3090            // zklogin::check_zklogin_id
3091            check_zklogin_id_cost_base: None,
3092            // zklogin::check_zklogin_issuer
3093            check_zklogin_issuer_cost_base: None,
3094
3095            vdf_verify_vdf_cost: None,
3096            vdf_hash_to_input_cost: None,
3097
3098            // nitro_attestation::verify_nitro_attestation
3099            nitro_attestation_parse_base_cost: None,
3100            nitro_attestation_parse_cost_per_byte: None,
3101            nitro_attestation_verify_base_cost: None,
3102            nitro_attestation_verify_cost_per_cert: None,
3103
3104            bcs_per_byte_serialized_cost: None,
3105            bcs_legacy_min_output_size_cost: None,
3106            bcs_failure_cost: None,
3107            hash_sha2_256_base_cost: None,
3108            hash_sha2_256_per_byte_cost: None,
3109            hash_sha2_256_legacy_min_input_len_cost: None,
3110            hash_sha3_256_base_cost: None,
3111            hash_sha3_256_per_byte_cost: None,
3112            hash_sha3_256_legacy_min_input_len_cost: None,
3113            type_name_get_base_cost: None,
3114            type_name_get_per_byte_cost: None,
3115            type_name_id_base_cost: None,
3116            string_check_utf8_base_cost: None,
3117            string_check_utf8_per_byte_cost: None,
3118            string_is_char_boundary_base_cost: None,
3119            string_sub_string_base_cost: None,
3120            string_sub_string_per_byte_cost: None,
3121            string_index_of_base_cost: None,
3122            string_index_of_per_byte_pattern_cost: None,
3123            string_index_of_per_byte_searched_cost: None,
3124            vector_empty_base_cost: None,
3125            vector_length_base_cost: None,
3126            vector_push_back_base_cost: None,
3127            vector_push_back_legacy_per_abstract_memory_unit_cost: None,
3128            vector_borrow_base_cost: None,
3129            vector_pop_back_base_cost: None,
3130            vector_destroy_empty_base_cost: None,
3131            vector_swap_base_cost: None,
3132            debug_print_base_cost: None,
3133            debug_print_stack_trace_base_cost: None,
3134
3135            max_size_written_objects: None,
3136            max_size_written_objects_system_tx: None,
3137
3138            // ==== Ephemeral (consensus only) params deleted ====
3139            // Const params for consensus scoring decision
3140            // scoring_decision_mad_divisor: None,
3141            // scoring_decision_cutoff_value: None,
3142
3143            // Limits the length of a Move identifier
3144            max_move_identifier_len: None,
3145            max_move_value_depth: None,
3146            max_move_enum_variants: None,
3147
3148            gas_rounding_step: None,
3149
3150            execution_version: None,
3151
3152            max_event_emit_size_total: None,
3153
3154            consensus_bad_nodes_stake_threshold: None,
3155
3156            max_jwk_votes_per_validator_per_epoch: None,
3157
3158            max_age_of_jwk_in_epochs: None,
3159
3160            random_beacon_reduction_allowed_delta: None,
3161
3162            random_beacon_reduction_lower_bound: None,
3163
3164            random_beacon_dkg_timeout_round: None,
3165
3166            random_beacon_min_round_interval_ms: None,
3167
3168            random_beacon_dkg_version: None,
3169
3170            consensus_max_transaction_size_bytes: None,
3171
3172            consensus_max_transactions_in_block_bytes: None,
3173
3174            consensus_max_num_transactions_in_block: None,
3175
3176            consensus_voting_rounds: None,
3177
3178            max_accumulated_txn_cost_per_object_in_narwhal_commit: None,
3179
3180            max_deferral_rounds_for_congestion_control: None,
3181
3182            max_txn_cost_overage_per_object_in_commit: None,
3183
3184            allowed_txn_cost_overage_burst_per_object_in_commit: None,
3185
3186            min_checkpoint_interval_ms: None,
3187
3188            checkpoint_summary_version_specific_data: None,
3189
3190            max_soft_bundle_size: None,
3191
3192            bridge_should_try_to_finalize_committee: None,
3193
3194            max_accumulated_txn_cost_per_object_in_mysticeti_commit: None,
3195
3196            max_accumulated_randomness_txn_cost_per_object_in_mysticeti_commit: None,
3197
3198            consensus_gc_depth: None,
3199
3200            gas_budget_based_txn_cost_cap_factor: None,
3201
3202            gas_budget_based_txn_cost_absolute_cap_commit_count: None,
3203
3204            sip_45_consensus_amplification_threshold: None,
3205
3206            use_object_per_epoch_marker_table_v2: None,
3207
3208            consensus_commit_rate_estimation_window_size: None,
3209
3210            aliased_addresses: vec![],
3211
3212            translation_per_command_base_charge: None,
3213            translation_per_input_base_charge: None,
3214            translation_pure_input_per_byte_charge: None,
3215            translation_per_type_node_charge: None,
3216            translation_per_reference_node_charge: None,
3217            translation_per_linkage_entry_charge: None,
3218
3219            max_updates_per_settlement_txn: None,
3220            // When adding a new constant, set it to None in the earliest version, like this:
3221            // new_constant: None,
3222        };
3223        for cur in 2..=version.0 {
3224            match cur {
3225                1 => unreachable!(),
3226                2 => {
3227                    cfg.feature_flags.advance_epoch_start_time_in_safe_mode = true;
3228                }
3229                3 => {
3230                    // changes for gas model
3231                    cfg.gas_model_version = Some(2);
3232                    // max gas budget is in MIST and an absolute value 50SUI
3233                    cfg.max_tx_gas = Some(50_000_000_000);
3234                    // min gas budget is in MIST and an absolute value 2000MIST or 0.000002SUI
3235                    cfg.base_tx_cost_fixed = Some(2_000);
3236                    // storage gas price multiplier
3237                    cfg.storage_gas_price = Some(76);
3238                    cfg.feature_flags.loaded_child_objects_fixed = true;
3239                    // max size of written objects during a TXn
3240                    // this is a sum of all objects written during a TXn
3241                    cfg.max_size_written_objects = Some(5 * 1000 * 1000);
3242                    // max size of written objects during a system TXn to allow for larger writes
3243                    // akin to `max_size_written_objects` but for system TXns
3244                    cfg.max_size_written_objects_system_tx = Some(50 * 1000 * 1000);
3245                    cfg.feature_flags.package_upgrades = true;
3246                }
3247                // This is the first protocol version currently possible.
3248                // Mainnet starts with version 4. Previous versions are pre mainnet and have
3249                // all been wiped out.
3250                // Every other chain is after version 4.
3251                4 => {
3252                    // Change reward slashing rate to 100%.
3253                    cfg.reward_slashing_rate = Some(10000);
3254                    // protect old and new lookup for object version
3255                    cfg.gas_model_version = Some(3);
3256                }
3257                5 => {
3258                    cfg.feature_flags.missing_type_is_compatibility_error = true;
3259                    cfg.gas_model_version = Some(4);
3260                    cfg.feature_flags.scoring_decision_with_validity_cutoff = true;
3261                    // ==== Ephemeral (consensus only) params deleted ====
3262                    // cfg.scoring_decision_mad_divisor = Some(2.3);
3263                    // cfg.scoring_decision_cutoff_value = Some(2.5);
3264                }
3265                6 => {
3266                    cfg.gas_model_version = Some(5);
3267                    cfg.buffer_stake_for_protocol_upgrade_bps = Some(5000);
3268                    cfg.feature_flags.consensus_order_end_of_epoch_last = true;
3269                }
3270                7 => {
3271                    cfg.feature_flags.disallow_adding_abilities_on_upgrade = true;
3272                    cfg.feature_flags
3273                        .disable_invariant_violation_check_in_swap_loc = true;
3274                    cfg.feature_flags.ban_entry_init = true;
3275                    cfg.feature_flags.package_digest_hash_module = true;
3276                }
3277                8 => {
3278                    cfg.feature_flags
3279                        .disallow_change_struct_type_params_on_upgrade = true;
3280                }
3281                9 => {
3282                    // Limits the length of a Move identifier
3283                    cfg.max_move_identifier_len = Some(128);
3284                    cfg.feature_flags.no_extraneous_module_bytes = true;
3285                    cfg.feature_flags
3286                        .advance_to_highest_supported_protocol_version = true;
3287                }
3288                10 => {
3289                    cfg.max_verifier_meter_ticks_per_function = Some(16_000_000);
3290                    cfg.max_meter_ticks_per_module = Some(16_000_000);
3291                }
3292                11 => {
3293                    cfg.max_move_value_depth = Some(128);
3294                }
3295                12 => {
3296                    cfg.feature_flags.narwhal_versioned_metadata = true;
3297                    if chain != Chain::Mainnet {
3298                        cfg.feature_flags.commit_root_state_digest = true;
3299                    }
3300
3301                    if chain != Chain::Mainnet && chain != Chain::Testnet {
3302                        cfg.feature_flags.zklogin_auth = true;
3303                    }
3304                }
3305                13 => {}
3306                14 => {
3307                    cfg.gas_rounding_step = Some(1_000);
3308                    cfg.gas_model_version = Some(6);
3309                }
3310                15 => {
3311                    cfg.feature_flags.consensus_transaction_ordering =
3312                        ConsensusTransactionOrdering::ByGasPrice;
3313                }
3314                16 => {
3315                    cfg.feature_flags.simplified_unwrap_then_delete = true;
3316                }
3317                17 => {
3318                    cfg.feature_flags.upgraded_multisig_supported = true;
3319                }
3320                18 => {
3321                    cfg.execution_version = Some(1);
3322                    // Following flags are implied by this execution version.  Once support for earlier
3323                    // protocol versions is dropped, these flags can be removed:
3324                    // cfg.feature_flags.package_upgrades = true;
3325                    // cfg.feature_flags.disallow_adding_abilities_on_upgrade = true;
3326                    // cfg.feature_flags.disallow_change_struct_type_params_on_upgrade = true;
3327                    // cfg.feature_flags.loaded_child_objects_fixed = true;
3328                    // cfg.feature_flags.ban_entry_init = true;
3329                    // cfg.feature_flags.pack_digest_hash_modules = true;
3330                    cfg.feature_flags.txn_base_cost_as_multiplier = true;
3331                    // this is a multiplier of the gas price
3332                    cfg.base_tx_cost_fixed = Some(1_000);
3333                }
3334                19 => {
3335                    cfg.max_num_event_emit = Some(1024);
3336                    // We maintain the same total size limit for events, but increase the number of
3337                    // events that can be emitted.
3338                    cfg.max_event_emit_size_total = Some(
3339                        256 /* former event count limit */ * 250 * 1024, /* size limit per event */
3340                    );
3341                }
3342                20 => {
3343                    cfg.feature_flags.commit_root_state_digest = true;
3344
3345                    if chain != Chain::Mainnet {
3346                        cfg.feature_flags.narwhal_new_leader_election_schedule = true;
3347                        cfg.consensus_bad_nodes_stake_threshold = Some(20);
3348                    }
3349                }
3350
3351                21 => {
3352                    if chain != Chain::Mainnet {
3353                        cfg.feature_flags.zklogin_supported_providers = BTreeSet::from([
3354                            "Google".to_string(),
3355                            "Facebook".to_string(),
3356                            "Twitch".to_string(),
3357                        ]);
3358                    }
3359                }
3360                22 => {
3361                    cfg.feature_flags.loaded_child_object_format = true;
3362                }
3363                23 => {
3364                    cfg.feature_flags.loaded_child_object_format_type = true;
3365                    cfg.feature_flags.narwhal_new_leader_election_schedule = true;
3366                    // Taking a baby step approach, we consider only 20% by stake as bad nodes so we
3367                    // have a 80% by stake of nodes participating in the leader committee. That allow
3368                    // us for more redundancy in case we have validators under performing - since the
3369                    // responsibility is shared amongst more nodes. We can increase that once we do have
3370                    // higher confidence.
3371                    cfg.consensus_bad_nodes_stake_threshold = Some(20);
3372                }
3373                24 => {
3374                    cfg.feature_flags.simple_conservation_checks = true;
3375                    cfg.max_publish_or_upgrade_per_ptb = Some(5);
3376
3377                    cfg.feature_flags.end_of_epoch_transaction_supported = true;
3378
3379                    if chain != Chain::Mainnet {
3380                        cfg.feature_flags.enable_jwk_consensus_updates = true;
3381                        // Max of 10 votes per hour
3382                        cfg.max_jwk_votes_per_validator_per_epoch = Some(240);
3383                        cfg.max_age_of_jwk_in_epochs = Some(1);
3384                    }
3385                }
3386                25 => {
3387                    // Enable zkLogin for all providers in all networks.
3388                    cfg.feature_flags.zklogin_supported_providers = BTreeSet::from([
3389                        "Google".to_string(),
3390                        "Facebook".to_string(),
3391                        "Twitch".to_string(),
3392                    ]);
3393                    cfg.feature_flags.zklogin_auth = true;
3394
3395                    // Enable jwk consensus updates
3396                    cfg.feature_flags.enable_jwk_consensus_updates = true;
3397                    cfg.max_jwk_votes_per_validator_per_epoch = Some(240);
3398                    cfg.max_age_of_jwk_in_epochs = Some(1);
3399                }
3400                26 => {
3401                    cfg.gas_model_version = Some(7);
3402                    // Only enable receiving objects in devnet
3403                    if chain != Chain::Mainnet && chain != Chain::Testnet {
3404                        cfg.transfer_receive_object_cost_base = Some(52);
3405                        cfg.feature_flags.receive_objects = true;
3406                    }
3407                }
3408                27 => {
3409                    cfg.gas_model_version = Some(8);
3410                }
3411                28 => {
3412                    // zklogin::check_zklogin_id
3413                    cfg.check_zklogin_id_cost_base = Some(200);
3414                    // zklogin::check_zklogin_issuer
3415                    cfg.check_zklogin_issuer_cost_base = Some(200);
3416
3417                    // Only enable effects v2 on devnet.
3418                    if chain != Chain::Mainnet && chain != Chain::Testnet {
3419                        cfg.feature_flags.enable_effects_v2 = true;
3420                    }
3421                }
3422                29 => {
3423                    cfg.feature_flags.verify_legacy_zklogin_address = true;
3424                }
3425                30 => {
3426                    // Only enable nw certificate v2 on testnet.
3427                    if chain != Chain::Mainnet {
3428                        cfg.feature_flags.narwhal_certificate_v2 = true;
3429                    }
3430
3431                    cfg.random_beacon_reduction_allowed_delta = Some(800);
3432                    // Only enable effects v2 on devnet and testnet.
3433                    if chain != Chain::Mainnet {
3434                        cfg.feature_flags.enable_effects_v2 = true;
3435                    }
3436
3437                    // zklogin_supported_providers config is deprecated, zklogin
3438                    // signature verifier will use the fetched jwk map to determine
3439                    // whether the provider is supported based on node config.
3440                    cfg.feature_flags.zklogin_supported_providers = BTreeSet::default();
3441
3442                    cfg.feature_flags.recompute_has_public_transfer_in_execution = true;
3443                }
3444                31 => {
3445                    cfg.execution_version = Some(2);
3446                    // Only enable shared object deletion on devnet
3447                    if chain != Chain::Mainnet && chain != Chain::Testnet {
3448                        cfg.feature_flags.shared_object_deletion = true;
3449                    }
3450                }
3451                32 => {
3452                    // enable zklogin in multisig in devnet and testnet
3453                    if chain != Chain::Mainnet {
3454                        cfg.feature_flags.accept_zklogin_in_multisig = true;
3455                    }
3456                    // enable receiving objects in devnet and testnet
3457                    if chain != Chain::Mainnet {
3458                        cfg.transfer_receive_object_cost_base = Some(52);
3459                        cfg.feature_flags.receive_objects = true;
3460                    }
3461                    // Only enable random beacon on devnet
3462                    if chain != Chain::Mainnet && chain != Chain::Testnet {
3463                        cfg.feature_flags.random_beacon = true;
3464                        cfg.random_beacon_reduction_lower_bound = Some(1600);
3465                        cfg.random_beacon_dkg_timeout_round = Some(3000);
3466                        cfg.random_beacon_min_round_interval_ms = Some(150);
3467                    }
3468                    // Only enable consensus digest in consensus commit prologue in devnet.
3469                    if chain != Chain::Testnet && chain != Chain::Mainnet {
3470                        cfg.feature_flags.include_consensus_digest_in_prologue = true;
3471                    }
3472
3473                    // enable nw cert v2 on mainnet
3474                    cfg.feature_flags.narwhal_certificate_v2 = true;
3475                }
3476                33 => {
3477                    cfg.feature_flags.hardened_otw_check = true;
3478                    cfg.feature_flags.allow_receiving_object_id = true;
3479
3480                    // Enable transfer-to-object in mainnet
3481                    cfg.transfer_receive_object_cost_base = Some(52);
3482                    cfg.feature_flags.receive_objects = true;
3483
3484                    // Enable shared object deletion in testnet and devnet
3485                    if chain != Chain::Mainnet {
3486                        cfg.feature_flags.shared_object_deletion = true;
3487                    }
3488
3489                    cfg.feature_flags.enable_effects_v2 = true;
3490                }
3491                34 => {}
3492                35 => {
3493                    // Add costs for poseidon::poseidon_bn254
3494                    if chain != Chain::Mainnet && chain != Chain::Testnet {
3495                        cfg.feature_flags.enable_poseidon = true;
3496                        cfg.poseidon_bn254_cost_base = Some(260);
3497                        cfg.poseidon_bn254_cost_per_block = Some(10);
3498                    }
3499
3500                    cfg.feature_flags.enable_coin_deny_list = true;
3501                }
3502                36 => {
3503                    // Only enable group ops on devnet
3504                    if chain != Chain::Mainnet && chain != Chain::Testnet {
3505                        cfg.feature_flags.enable_group_ops_native_functions = true;
3506                        cfg.feature_flags.enable_group_ops_native_function_msm = true;
3507                        // Next values are arbitrary in a similar way as the other crypto native functions.
3508                        cfg.group_ops_bls12381_decode_scalar_cost = Some(52);
3509                        cfg.group_ops_bls12381_decode_g1_cost = Some(52);
3510                        cfg.group_ops_bls12381_decode_g2_cost = Some(52);
3511                        cfg.group_ops_bls12381_decode_gt_cost = Some(52);
3512                        cfg.group_ops_bls12381_scalar_add_cost = Some(52);
3513                        cfg.group_ops_bls12381_g1_add_cost = Some(52);
3514                        cfg.group_ops_bls12381_g2_add_cost = Some(52);
3515                        cfg.group_ops_bls12381_gt_add_cost = Some(52);
3516                        cfg.group_ops_bls12381_scalar_sub_cost = Some(52);
3517                        cfg.group_ops_bls12381_g1_sub_cost = Some(52);
3518                        cfg.group_ops_bls12381_g2_sub_cost = Some(52);
3519                        cfg.group_ops_bls12381_gt_sub_cost = Some(52);
3520                        cfg.group_ops_bls12381_scalar_mul_cost = Some(52);
3521                        cfg.group_ops_bls12381_g1_mul_cost = Some(52);
3522                        cfg.group_ops_bls12381_g2_mul_cost = Some(52);
3523                        cfg.group_ops_bls12381_gt_mul_cost = Some(52);
3524                        cfg.group_ops_bls12381_scalar_div_cost = Some(52);
3525                        cfg.group_ops_bls12381_g1_div_cost = Some(52);
3526                        cfg.group_ops_bls12381_g2_div_cost = Some(52);
3527                        cfg.group_ops_bls12381_gt_div_cost = Some(52);
3528                        cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(52);
3529                        cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(52);
3530                        cfg.group_ops_bls12381_g1_hash_to_cost_per_byte = Some(2);
3531                        cfg.group_ops_bls12381_g2_hash_to_cost_per_byte = Some(2);
3532                        cfg.group_ops_bls12381_g1_msm_base_cost = Some(52);
3533                        cfg.group_ops_bls12381_g2_msm_base_cost = Some(52);
3534                        cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(52);
3535                        cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(52);
3536                        cfg.group_ops_bls12381_msm_max_len = Some(32);
3537                        cfg.group_ops_bls12381_pairing_cost = Some(52);
3538                    }
3539                    // Enable shared object deletion on all networks.
3540                    cfg.feature_flags.shared_object_deletion = true;
3541
3542                    cfg.consensus_max_transaction_size_bytes = Some(256 * 1024); // 256KB
3543                    cfg.consensus_max_transactions_in_block_bytes = Some(6 * 1_024 * 1024);
3544                    // 6 MB
3545                }
3546                37 => {
3547                    cfg.feature_flags.reject_mutable_random_on_entry_functions = true;
3548
3549                    // Enable consensus digest in consensus commit prologue in testnet and devnet.
3550                    if chain != Chain::Mainnet {
3551                        cfg.feature_flags.include_consensus_digest_in_prologue = true;
3552                    }
3553                }
3554                38 => {
3555                    cfg.binary_module_handles = Some(100);
3556                    cfg.binary_struct_handles = Some(300);
3557                    cfg.binary_function_handles = Some(1500);
3558                    cfg.binary_function_instantiations = Some(750);
3559                    cfg.binary_signatures = Some(1000);
3560                    // constants and identifiers are proportional to the binary size,
3561                    // and they vastly depend on the code, so we are leaving them
3562                    // reasonably high
3563                    cfg.binary_constant_pool = Some(4000);
3564                    cfg.binary_identifiers = Some(10000);
3565                    cfg.binary_address_identifiers = Some(100);
3566                    cfg.binary_struct_defs = Some(200);
3567                    cfg.binary_struct_def_instantiations = Some(100);
3568                    cfg.binary_function_defs = Some(1000);
3569                    cfg.binary_field_handles = Some(500);
3570                    cfg.binary_field_instantiations = Some(250);
3571                    cfg.binary_friend_decls = Some(100);
3572                    // reduce dependencies maximum
3573                    cfg.max_package_dependencies = Some(32);
3574                    cfg.max_modules_in_publish = Some(64);
3575                    // bump execution version
3576                    cfg.execution_version = Some(3);
3577                }
3578                39 => {
3579                    // It is important that we keep this protocol version blank due to an issue with random.move.
3580                }
3581                40 => {}
3582                41 => {
3583                    // Enable group ops and all networks (but not msm)
3584                    cfg.feature_flags.enable_group_ops_native_functions = true;
3585                    // Next values are arbitrary in a similar way as the other crypto native functions.
3586                    cfg.group_ops_bls12381_decode_scalar_cost = Some(52);
3587                    cfg.group_ops_bls12381_decode_g1_cost = Some(52);
3588                    cfg.group_ops_bls12381_decode_g2_cost = Some(52);
3589                    cfg.group_ops_bls12381_decode_gt_cost = Some(52);
3590                    cfg.group_ops_bls12381_scalar_add_cost = Some(52);
3591                    cfg.group_ops_bls12381_g1_add_cost = Some(52);
3592                    cfg.group_ops_bls12381_g2_add_cost = Some(52);
3593                    cfg.group_ops_bls12381_gt_add_cost = Some(52);
3594                    cfg.group_ops_bls12381_scalar_sub_cost = Some(52);
3595                    cfg.group_ops_bls12381_g1_sub_cost = Some(52);
3596                    cfg.group_ops_bls12381_g2_sub_cost = Some(52);
3597                    cfg.group_ops_bls12381_gt_sub_cost = Some(52);
3598                    cfg.group_ops_bls12381_scalar_mul_cost = Some(52);
3599                    cfg.group_ops_bls12381_g1_mul_cost = Some(52);
3600                    cfg.group_ops_bls12381_g2_mul_cost = Some(52);
3601                    cfg.group_ops_bls12381_gt_mul_cost = Some(52);
3602                    cfg.group_ops_bls12381_scalar_div_cost = Some(52);
3603                    cfg.group_ops_bls12381_g1_div_cost = Some(52);
3604                    cfg.group_ops_bls12381_g2_div_cost = Some(52);
3605                    cfg.group_ops_bls12381_gt_div_cost = Some(52);
3606                    cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(52);
3607                    cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(52);
3608                    cfg.group_ops_bls12381_g1_hash_to_cost_per_byte = Some(2);
3609                    cfg.group_ops_bls12381_g2_hash_to_cost_per_byte = Some(2);
3610                    cfg.group_ops_bls12381_g1_msm_base_cost = Some(52);
3611                    cfg.group_ops_bls12381_g2_msm_base_cost = Some(52);
3612                    cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(52);
3613                    cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(52);
3614                    cfg.group_ops_bls12381_msm_max_len = Some(32);
3615                    cfg.group_ops_bls12381_pairing_cost = Some(52);
3616                }
3617                42 => {}
3618                43 => {
3619                    cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
3620                    cfg.max_meter_ticks_per_package = Some(16_000_000);
3621                }
3622                44 => {
3623                    // Enable consensus digest in consensus commit prologue on all networks..
3624                    cfg.feature_flags.include_consensus_digest_in_prologue = true;
3625                    // Switch between Narwhal and Mysticeti per epoch in tests, devnet and testnet.
3626                    if chain != Chain::Mainnet {
3627                        cfg.feature_flags.consensus_choice = ConsensusChoice::SwapEachEpoch;
3628                    }
3629                }
3630                45 => {
3631                    // Use tonic networking for consensus, in tests and devnet.
3632                    if chain != Chain::Testnet && chain != Chain::Mainnet {
3633                        cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
3634                    }
3635
3636                    if chain != Chain::Mainnet {
3637                        // Enable leader scoring & schedule change on testnet for mysticeti.
3638                        cfg.feature_flags.mysticeti_leader_scoring_and_schedule = true;
3639                    }
3640                    cfg.min_move_binary_format_version = Some(6);
3641                    cfg.feature_flags.accept_zklogin_in_multisig = true;
3642
3643                    // Also bumps framework snapshot to fix binop issue.
3644
3645                    // enable bridge in devnet
3646                    if chain != Chain::Mainnet && chain != Chain::Testnet {
3647                        cfg.feature_flags.bridge = true;
3648                    }
3649                }
3650                46 => {
3651                    // enable bridge in devnet and testnet
3652                    if chain != Chain::Mainnet {
3653                        cfg.feature_flags.bridge = true;
3654                    }
3655
3656                    // Enable resharing at same initial version
3657                    cfg.feature_flags.reshare_at_same_initial_version = true;
3658                }
3659                47 => {}
3660                48 => {
3661                    // Use tonic networking for Mysticeti.
3662                    cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
3663
3664                    // Enable resolving abort code IDs to package ID instead of runtime module ID
3665                    cfg.feature_flags.resolve_abort_locations_to_package_id = true;
3666
3667                    // Enable random beacon on testnet.
3668                    if chain != Chain::Mainnet {
3669                        cfg.feature_flags.random_beacon = true;
3670                        cfg.random_beacon_reduction_lower_bound = Some(1600);
3671                        cfg.random_beacon_dkg_timeout_round = Some(3000);
3672                        cfg.random_beacon_min_round_interval_ms = Some(200);
3673                    }
3674
3675                    // Enable the committed sub dag digest inclusion on the commit output
3676                    cfg.feature_flags.mysticeti_use_committed_subdag_digest = true;
3677                }
3678                49 => {
3679                    if chain != Chain::Testnet && chain != Chain::Mainnet {
3680                        cfg.move_binary_format_version = Some(7);
3681                    }
3682
3683                    // enable vdf in devnet
3684                    if chain != Chain::Mainnet && chain != Chain::Testnet {
3685                        cfg.feature_flags.enable_vdf = true;
3686                        // Set to 30x and 2x the cost of a signature verification for now. This
3687                        // should be updated along with other native crypto functions.
3688                        cfg.vdf_verify_vdf_cost = Some(1500);
3689                        cfg.vdf_hash_to_input_cost = Some(100);
3690                    }
3691
3692                    // Only enable consensus commit prologue V3 in devnet.
3693                    if chain != Chain::Testnet && chain != Chain::Mainnet {
3694                        cfg.feature_flags
3695                            .record_consensus_determined_version_assignments_in_prologue = true;
3696                    }
3697
3698                    // Run Mysticeti consensus in testnet.
3699                    if chain != Chain::Mainnet {
3700                        cfg.feature_flags.consensus_choice = ConsensusChoice::Mysticeti;
3701                    }
3702
3703                    // Run Move verification on framework upgrades in its own VM
3704                    cfg.feature_flags.fresh_vm_on_framework_upgrade = true;
3705                }
3706                50 => {
3707                    // Enable checkpoint batching in testnet.
3708                    if chain != Chain::Mainnet {
3709                        cfg.checkpoint_summary_version_specific_data = Some(1);
3710                        cfg.min_checkpoint_interval_ms = Some(200);
3711                    }
3712
3713                    // Only enable prepose consensus commit prologue in checkpoints in devnet.
3714                    if chain != Chain::Testnet && chain != Chain::Mainnet {
3715                        cfg.feature_flags
3716                            .prepend_prologue_tx_in_consensus_commit_in_checkpoints = true;
3717                    }
3718
3719                    cfg.feature_flags.mysticeti_num_leaders_per_round = Some(1);
3720
3721                    // Set max transaction deferral to 10 consensus rounds.
3722                    cfg.max_deferral_rounds_for_congestion_control = Some(10);
3723                }
3724                51 => {
3725                    cfg.random_beacon_dkg_version = Some(1);
3726
3727                    if chain != Chain::Testnet && chain != Chain::Mainnet {
3728                        cfg.feature_flags.enable_coin_deny_list_v2 = true;
3729                    }
3730                }
3731                52 => {
3732                    if chain != Chain::Mainnet {
3733                        cfg.feature_flags.soft_bundle = true;
3734                        cfg.max_soft_bundle_size = Some(5);
3735                    }
3736
3737                    cfg.config_read_setting_impl_cost_base = Some(100);
3738                    cfg.config_read_setting_impl_cost_per_byte = Some(40);
3739
3740                    // Turn on shared object congestion control in devnet.
3741                    if chain != Chain::Testnet && chain != Chain::Mainnet {
3742                        cfg.max_accumulated_txn_cost_per_object_in_narwhal_commit = Some(100);
3743                        cfg.feature_flags.per_object_congestion_control_mode =
3744                            PerObjectCongestionControlMode::TotalTxCount;
3745                    }
3746
3747                    // Enable Mysticeti on mainnet.
3748                    cfg.feature_flags.consensus_choice = ConsensusChoice::Mysticeti;
3749
3750                    // Enable leader scoring & schedule change on mainnet for mysticeti.
3751                    cfg.feature_flags.mysticeti_leader_scoring_and_schedule = true;
3752
3753                    // Enable checkpoint batching on mainnet.
3754                    cfg.checkpoint_summary_version_specific_data = Some(1);
3755                    cfg.min_checkpoint_interval_ms = Some(200);
3756
3757                    // Enable consensus commit prologue V3 in testnet.
3758                    if chain != Chain::Mainnet {
3759                        cfg.feature_flags
3760                            .record_consensus_determined_version_assignments_in_prologue = true;
3761                        cfg.feature_flags
3762                            .prepend_prologue_tx_in_consensus_commit_in_checkpoints = true;
3763                    }
3764                    // Turn on enums in testnet and devnet
3765                    if chain != Chain::Mainnet {
3766                        cfg.move_binary_format_version = Some(7);
3767                    }
3768
3769                    if chain != Chain::Testnet && chain != Chain::Mainnet {
3770                        cfg.feature_flags.passkey_auth = true;
3771                    }
3772                    cfg.feature_flags.enable_coin_deny_list_v2 = true;
3773                }
3774                53 => {
3775                    // Do not allow bridge committee to finalize on mainnet.
3776                    cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
3777
3778                    // Enable consensus commit prologue V3 on mainnet.
3779                    cfg.feature_flags
3780                        .record_consensus_determined_version_assignments_in_prologue = true;
3781                    cfg.feature_flags
3782                        .prepend_prologue_tx_in_consensus_commit_in_checkpoints = true;
3783
3784                    if chain == Chain::Unknown {
3785                        cfg.feature_flags.authority_capabilities_v2 = true;
3786                    }
3787
3788                    // Turns on shared object congestion control on testnet.
3789                    if chain != Chain::Mainnet {
3790                        cfg.max_accumulated_txn_cost_per_object_in_narwhal_commit = Some(100);
3791                        cfg.max_accumulated_txn_cost_per_object_in_mysticeti_commit = Some(10);
3792                        cfg.feature_flags.per_object_congestion_control_mode =
3793                            PerObjectCongestionControlMode::TotalTxCount;
3794                    }
3795
3796                    // Adjust stdlib gas costs
3797                    cfg.bcs_per_byte_serialized_cost = Some(2);
3798                    cfg.bcs_legacy_min_output_size_cost = Some(1);
3799                    cfg.bcs_failure_cost = Some(52);
3800                    cfg.debug_print_base_cost = Some(52);
3801                    cfg.debug_print_stack_trace_base_cost = Some(52);
3802                    cfg.hash_sha2_256_base_cost = Some(52);
3803                    cfg.hash_sha2_256_per_byte_cost = Some(2);
3804                    cfg.hash_sha2_256_legacy_min_input_len_cost = Some(1);
3805                    cfg.hash_sha3_256_base_cost = Some(52);
3806                    cfg.hash_sha3_256_per_byte_cost = Some(2);
3807                    cfg.hash_sha3_256_legacy_min_input_len_cost = Some(1);
3808                    cfg.type_name_get_base_cost = Some(52);
3809                    cfg.type_name_get_per_byte_cost = Some(2);
3810                    cfg.string_check_utf8_base_cost = Some(52);
3811                    cfg.string_check_utf8_per_byte_cost = Some(2);
3812                    cfg.string_is_char_boundary_base_cost = Some(52);
3813                    cfg.string_sub_string_base_cost = Some(52);
3814                    cfg.string_sub_string_per_byte_cost = Some(2);
3815                    cfg.string_index_of_base_cost = Some(52);
3816                    cfg.string_index_of_per_byte_pattern_cost = Some(2);
3817                    cfg.string_index_of_per_byte_searched_cost = Some(2);
3818                    cfg.vector_empty_base_cost = Some(52);
3819                    cfg.vector_length_base_cost = Some(52);
3820                    cfg.vector_push_back_base_cost = Some(52);
3821                    cfg.vector_push_back_legacy_per_abstract_memory_unit_cost = Some(2);
3822                    cfg.vector_borrow_base_cost = Some(52);
3823                    cfg.vector_pop_back_base_cost = Some(52);
3824                    cfg.vector_destroy_empty_base_cost = Some(52);
3825                    cfg.vector_swap_base_cost = Some(52);
3826                }
3827                54 => {
3828                    // Enable random beacon on mainnet.
3829                    cfg.feature_flags.random_beacon = true;
3830                    cfg.random_beacon_reduction_lower_bound = Some(1000);
3831                    cfg.random_beacon_dkg_timeout_round = Some(3000);
3832                    cfg.random_beacon_min_round_interval_ms = Some(500);
3833
3834                    // Turns on shared object congestion control on mainnet.
3835                    cfg.max_accumulated_txn_cost_per_object_in_narwhal_commit = Some(100);
3836                    cfg.max_accumulated_txn_cost_per_object_in_mysticeti_commit = Some(10);
3837                    cfg.feature_flags.per_object_congestion_control_mode =
3838                        PerObjectCongestionControlMode::TotalTxCount;
3839
3840                    // Enable soft bundle on mainnet.
3841                    cfg.feature_flags.soft_bundle = true;
3842                    cfg.max_soft_bundle_size = Some(5);
3843                }
3844                55 => {
3845                    // Turn on enums mainnet
3846                    cfg.move_binary_format_version = Some(7);
3847
3848                    // Assume 1KB per transaction and 500 transactions per block.
3849                    cfg.consensus_max_transactions_in_block_bytes = Some(512 * 1024);
3850                    // Assume 20_000 TPS * 5% max stake per validator / (minimum) 4 blocks per round = 250 transactions per block maximum
3851                    // Using a higher limit that is 512, to account for bursty traffic and system transactions.
3852                    cfg.consensus_max_num_transactions_in_block = Some(512);
3853
3854                    cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
3855                }
3856                56 => {
3857                    if chain == Chain::Mainnet {
3858                        cfg.feature_flags.bridge = true;
3859                    }
3860                }
3861                57 => {
3862                    // Reduce minimum number of random beacon shares.
3863                    cfg.random_beacon_reduction_lower_bound = Some(800);
3864                }
3865                58 => {
3866                    if chain == Chain::Mainnet {
3867                        cfg.bridge_should_try_to_finalize_committee = Some(true);
3868                    }
3869
3870                    if chain != Chain::Mainnet && chain != Chain::Testnet {
3871                        // Enable distributed vote scoring for devnet
3872                        cfg.feature_flags
3873                            .consensus_distributed_vote_scoring_strategy = true;
3874                    }
3875                }
3876                59 => {
3877                    // Enable round prober in consensus.
3878                    cfg.feature_flags.consensus_round_prober = true;
3879                }
3880                60 => {
3881                    cfg.max_type_to_layout_nodes = Some(512);
3882                    cfg.feature_flags.validate_identifier_inputs = true;
3883                }
3884                61 => {
3885                    if chain != Chain::Mainnet {
3886                        // Enable distributed vote scoring for testnet
3887                        cfg.feature_flags
3888                            .consensus_distributed_vote_scoring_strategy = true;
3889                    }
3890                    // Further reduce minimum number of random beacon shares.
3891                    cfg.random_beacon_reduction_lower_bound = Some(700);
3892
3893                    if chain != Chain::Mainnet && chain != Chain::Testnet {
3894                        // Enable Mysticeti fastpath for devnet
3895                        cfg.feature_flags.mysticeti_fastpath = true;
3896                    }
3897                }
3898                62 => {
3899                    cfg.feature_flags.relocate_event_module = true;
3900                }
3901                63 => {
3902                    cfg.feature_flags.per_object_congestion_control_mode =
3903                        PerObjectCongestionControlMode::TotalGasBudgetWithCap;
3904                    cfg.gas_budget_based_txn_cost_cap_factor = Some(400_000);
3905                    cfg.max_accumulated_txn_cost_per_object_in_mysticeti_commit = Some(18_500_000);
3906                    cfg.max_accumulated_txn_cost_per_object_in_narwhal_commit = Some(240_000_000);
3907                }
3908                64 => {
3909                    cfg.feature_flags.per_object_congestion_control_mode =
3910                        PerObjectCongestionControlMode::TotalTxCount;
3911                    cfg.max_accumulated_txn_cost_per_object_in_narwhal_commit = Some(40);
3912                    cfg.max_accumulated_txn_cost_per_object_in_mysticeti_commit = Some(3);
3913                }
3914                65 => {
3915                    // Enable distributed vote scoring for mainnet
3916                    cfg.feature_flags
3917                        .consensus_distributed_vote_scoring_strategy = true;
3918                }
3919                66 => {
3920                    if chain == Chain::Mainnet {
3921                        // Revert the distributed vote scoring for mainnet (for one protocol upgrade)
3922                        cfg.feature_flags
3923                            .consensus_distributed_vote_scoring_strategy = false;
3924                    }
3925                }
3926                67 => {
3927                    // Enable it once again.
3928                    cfg.feature_flags
3929                        .consensus_distributed_vote_scoring_strategy = true;
3930                }
3931                68 => {
3932                    cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(26);
3933                    cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(52);
3934                    cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(26);
3935                    cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(13);
3936                    cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(2000);
3937
3938                    if chain != Chain::Mainnet && chain != Chain::Testnet {
3939                        cfg.feature_flags.uncompressed_g1_group_elements = true;
3940                    }
3941
3942                    cfg.feature_flags.per_object_congestion_control_mode =
3943                        PerObjectCongestionControlMode::TotalGasBudgetWithCap;
3944                    cfg.gas_budget_based_txn_cost_cap_factor = Some(400_000);
3945                    cfg.max_accumulated_txn_cost_per_object_in_mysticeti_commit = Some(18_500_000);
3946                    cfg.max_accumulated_randomness_txn_cost_per_object_in_mysticeti_commit =
3947                        Some(3_700_000); // 20% of above
3948                    cfg.max_txn_cost_overage_per_object_in_commit = Some(u64::MAX);
3949                    cfg.gas_budget_based_txn_cost_absolute_cap_commit_count = Some(50);
3950
3951                    // Further reduce minimum number of random beacon shares.
3952                    cfg.random_beacon_reduction_lower_bound = Some(500);
3953
3954                    cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
3955                }
3956                69 => {
3957                    // Sets number of rounds allowed for fastpath voting in consensus.
3958                    cfg.consensus_voting_rounds = Some(40);
3959
3960                    if chain != Chain::Mainnet && chain != Chain::Testnet {
3961                        // Enable smart ancestor selection for devnet
3962                        cfg.feature_flags.consensus_smart_ancestor_selection = true;
3963                    }
3964
3965                    if chain != Chain::Mainnet {
3966                        cfg.feature_flags.uncompressed_g1_group_elements = true;
3967                    }
3968                }
3969                70 => {
3970                    if chain != Chain::Mainnet {
3971                        // Enable smart ancestor selection for testnet
3972                        cfg.feature_flags.consensus_smart_ancestor_selection = true;
3973                        // Enable probing for accepted rounds in round prober for testnet
3974                        cfg.feature_flags
3975                            .consensus_round_prober_probe_accepted_rounds = true;
3976                    }
3977
3978                    cfg.poseidon_bn254_cost_per_block = Some(388);
3979
3980                    cfg.gas_model_version = Some(9);
3981                    cfg.feature_flags.native_charging_v2 = true;
3982                    cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
3983                    cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
3984                    cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
3985                    cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
3986                    cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
3987                    cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
3988                    cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
3989                    cfg.ed25519_ed25519_verify_cost_base = Some(1802);
3990
3991                    // Manually changed to be "under cost"
3992                    cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
3993                    cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
3994                    cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
3995                    cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
3996
3997                    cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
3998                    cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
3999                    cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
4000                    cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
4001                        Some(8213);
4002                    cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
4003                    cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
4004                        Some(9484);
4005
4006                    cfg.hash_keccak256_cost_base = Some(10);
4007                    cfg.hash_blake2b256_cost_base = Some(10);
4008
4009                    // group ops
4010                    cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
4011                    cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
4012                    cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
4013                    cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
4014
4015                    cfg.group_ops_bls12381_scalar_add_cost = Some(10);
4016                    cfg.group_ops_bls12381_g1_add_cost = Some(1556);
4017                    cfg.group_ops_bls12381_g2_add_cost = Some(3048);
4018                    cfg.group_ops_bls12381_gt_add_cost = Some(188);
4019
4020                    cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
4021                    cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
4022                    cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
4023                    cfg.group_ops_bls12381_gt_sub_cost = Some(497);
4024
4025                    cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
4026                    cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
4027                    cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
4028                    cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
4029
4030                    cfg.group_ops_bls12381_scalar_div_cost = Some(91);
4031                    cfg.group_ops_bls12381_g1_div_cost = Some(5091);
4032                    cfg.group_ops_bls12381_g2_div_cost = Some(9206);
4033                    cfg.group_ops_bls12381_gt_div_cost = Some(27804);
4034
4035                    cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
4036                    cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
4037
4038                    cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
4039                    cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
4040                    cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
4041                    cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
4042
4043                    cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
4044                    cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
4045                    cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
4046                    cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
4047
4048                    cfg.group_ops_bls12381_pairing_cost = Some(26897);
4049                    cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
4050
4051                    cfg.validator_validate_metadata_cost_base = Some(20000);
4052                }
4053                71 => {
4054                    cfg.sip_45_consensus_amplification_threshold = Some(5);
4055
4056                    // Enable bursts for congestion control. (10x the per-commit budget)
4057                    cfg.allowed_txn_cost_overage_burst_per_object_in_commit = Some(185_000_000);
4058                }
4059                72 => {
4060                    cfg.feature_flags.convert_type_argument_error = true;
4061
4062                    // Invariant: max_gas_price * base_tx_cost_fixed <= max_tx_gas
4063                    // max gas budget is in MIST and an absolute value 50_000 SUI
4064                    cfg.max_tx_gas = Some(50_000_000_000_000);
4065                    // max gas price is in MIST and an absolute value 50 SUI
4066                    cfg.max_gas_price = Some(50_000_000_000);
4067
4068                    cfg.feature_flags.variant_nodes = true;
4069                }
4070                73 => {
4071                    // Enable new marker table version.
4072                    cfg.use_object_per_epoch_marker_table_v2 = Some(true);
4073
4074                    if chain != Chain::Mainnet && chain != Chain::Testnet {
4075                        // Assuming a round rate of max 15/sec, then using a gc depth of 60 allow blocks within a window of ~4 seconds
4076                        // to be included before be considered garbage collected.
4077                        cfg.consensus_gc_depth = Some(60);
4078                    }
4079
4080                    if chain != Chain::Mainnet {
4081                        // Enable zstd compression for consensus in testnet
4082                        cfg.feature_flags.consensus_zstd_compression = true;
4083                    }
4084
4085                    // Enable smart ancestor selection for mainnet
4086                    cfg.feature_flags.consensus_smart_ancestor_selection = true;
4087                    // Enable probing for accepted rounds in round prober for mainnet
4088                    cfg.feature_flags
4089                        .consensus_round_prober_probe_accepted_rounds = true;
4090
4091                    // Increase congestion control budget.
4092                    cfg.feature_flags.per_object_congestion_control_mode =
4093                        PerObjectCongestionControlMode::TotalGasBudgetWithCap;
4094                    cfg.gas_budget_based_txn_cost_cap_factor = Some(400_000);
4095                    cfg.max_accumulated_txn_cost_per_object_in_mysticeti_commit = Some(37_000_000);
4096                    cfg.max_accumulated_randomness_txn_cost_per_object_in_mysticeti_commit =
4097                        Some(7_400_000); // 20% of above
4098                    cfg.max_txn_cost_overage_per_object_in_commit = Some(u64::MAX);
4099                    cfg.gas_budget_based_txn_cost_absolute_cap_commit_count = Some(50);
4100                    cfg.allowed_txn_cost_overage_burst_per_object_in_commit = Some(370_000_000);
4101                }
4102                74 => {
4103                    // Enable nitro attestation verify native move function for devnet
4104                    if chain != Chain::Mainnet && chain != Chain::Testnet {
4105                        cfg.feature_flags.enable_nitro_attestation = true;
4106                    }
4107                    cfg.nitro_attestation_parse_base_cost = Some(53 * 50);
4108                    cfg.nitro_attestation_parse_cost_per_byte = Some(50);
4109                    cfg.nitro_attestation_verify_base_cost = Some(49632 * 50);
4110                    cfg.nitro_attestation_verify_cost_per_cert = Some(52369 * 50);
4111
4112                    // Enable zstd compression for consensus in mainnet
4113                    cfg.feature_flags.consensus_zstd_compression = true;
4114
4115                    if chain != Chain::Mainnet && chain != Chain::Testnet {
4116                        cfg.feature_flags.consensus_linearize_subdag_v2 = true;
4117                    }
4118                }
4119                75 => {
4120                    if chain != Chain::Mainnet {
4121                        cfg.feature_flags.passkey_auth = true;
4122                    }
4123                }
4124                76 => {
4125                    if chain != Chain::Mainnet && chain != Chain::Testnet {
4126                        cfg.feature_flags.record_additional_state_digest_in_prologue = true;
4127                        cfg.consensus_commit_rate_estimation_window_size = Some(10);
4128                    }
4129                    cfg.feature_flags.minimize_child_object_mutations = true;
4130
4131                    if chain != Chain::Mainnet {
4132                        cfg.feature_flags.accept_passkey_in_multisig = true;
4133                    }
4134                }
4135                77 => {
4136                    cfg.feature_flags.uncompressed_g1_group_elements = true;
4137
4138                    if chain != Chain::Mainnet {
4139                        cfg.consensus_gc_depth = Some(60);
4140                        cfg.feature_flags.consensus_linearize_subdag_v2 = true;
4141                    }
4142                }
4143                78 => {
4144                    cfg.feature_flags.move_native_context = true;
4145                    cfg.tx_context_fresh_id_cost_base = Some(52);
4146                    cfg.tx_context_sender_cost_base = Some(30);
4147                    cfg.tx_context_epoch_cost_base = Some(30);
4148                    cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
4149                    cfg.tx_context_sponsor_cost_base = Some(30);
4150                    cfg.tx_context_gas_price_cost_base = Some(30);
4151                    cfg.tx_context_gas_budget_cost_base = Some(30);
4152                    cfg.tx_context_ids_created_cost_base = Some(30);
4153                    cfg.tx_context_replace_cost_base = Some(30);
4154                    cfg.gas_model_version = Some(10);
4155
4156                    if chain != Chain::Mainnet {
4157                        cfg.feature_flags.record_additional_state_digest_in_prologue = true;
4158                        cfg.consensus_commit_rate_estimation_window_size = Some(10);
4159
4160                        // Enable execution time estimate mode for congestion control on testnet.
4161                        cfg.feature_flags.per_object_congestion_control_mode =
4162                            PerObjectCongestionControlMode::ExecutionTimeEstimate(
4163                                ExecutionTimeEstimateParams {
4164                                    target_utilization: 30,
4165                                    allowed_txn_cost_overage_burst_limit_us: 100_000, // 100 ms
4166                                    randomness_scalar: 20,
4167                                    max_estimate_us: 1_500_000, // 1.5s
4168                                    stored_observations_num_included_checkpoints: 10,
4169                                    stored_observations_limit: u64::MAX,
4170                                    stake_weighted_median_threshold: 0,
4171                                    default_none_duration_for_new_keys: false,
4172                                    observations_chunk_size: None,
4173                                },
4174                            );
4175                    }
4176                }
4177                79 => {
4178                    if chain != Chain::Mainnet {
4179                        cfg.feature_flags.consensus_median_based_commit_timestamp = true;
4180
4181                        // Increase threshold for bad nodes that won't be considered
4182                        // leaders in consensus in testnet
4183                        cfg.consensus_bad_nodes_stake_threshold = Some(30);
4184
4185                        cfg.feature_flags.consensus_batched_block_sync = true;
4186
4187                        // Enable verify nitro attestation in testnet.
4188                        cfg.feature_flags.enable_nitro_attestation = true
4189                    }
4190                    cfg.feature_flags.normalize_ptb_arguments = true;
4191
4192                    cfg.consensus_gc_depth = Some(60);
4193                    cfg.feature_flags.consensus_linearize_subdag_v2 = true;
4194                }
4195                80 => {
4196                    cfg.max_ptb_value_size = Some(1024 * 1024);
4197                }
4198                81 => {
4199                    cfg.feature_flags.consensus_median_based_commit_timestamp = true;
4200                    cfg.feature_flags.enforce_checkpoint_timestamp_monotonicity = true;
4201                    cfg.consensus_bad_nodes_stake_threshold = Some(30)
4202                }
4203                82 => {
4204                    cfg.feature_flags.max_ptb_value_size_v2 = true;
4205                }
4206                83 => {
4207                    if chain == Chain::Mainnet {
4208                        // The address that will sign the recovery transaction.
4209                        let aliased: [u8; 32] = Hex::decode(
4210                            "0x0b2da327ba6a4cacbe75dddd50e6e8bbf81d6496e92d66af9154c61c77f7332f",
4211                        )
4212                        .unwrap()
4213                        .try_into()
4214                        .unwrap();
4215
4216                        // Allow aliasing for the two addresses that contain stolen funds.
4217                        cfg.aliased_addresses.push(AliasedAddress {
4218                            original: Hex::decode("0xcd8962dad278d8b50fa0f9eb0186bfa4cbdecc6d59377214c88d0286a0ac9562").unwrap().try_into().unwrap(),
4219                            aliased,
4220                            allowed_tx_digests: vec![
4221                                Base58::decode("B2eGLFoMHgj93Ni8dAJBfqGzo8EWSTLBesZzhEpTPA4").unwrap().try_into().unwrap(),
4222                            ],
4223                        });
4224
4225                        cfg.aliased_addresses.push(AliasedAddress {
4226                            original: Hex::decode("0xe28b50cef1d633ea43d3296a3f6b67ff0312a5f1a99f0af753c85b8b5de8ff06").unwrap().try_into().unwrap(),
4227                            aliased,
4228                            allowed_tx_digests: vec![
4229                                Base58::decode("J4QqSAgp7VrQtQpMy5wDX4QGsCSEZu3U5KuDAkbESAge").unwrap().try_into().unwrap(),
4230                            ],
4231                        });
4232                    }
4233
4234                    // These features had to be deferred to v84 for mainnet in order to ship the recovery protocol
4235                    // upgrade as a patch to 1.48
4236                    if chain != Chain::Mainnet {
4237                        cfg.feature_flags.resolve_type_input_ids_to_defining_id = true;
4238                        cfg.transfer_party_transfer_internal_cost_base = Some(52);
4239
4240                        // Enable execution time estimate mode for congestion control on mainnet.
4241                        cfg.feature_flags.record_additional_state_digest_in_prologue = true;
4242                        cfg.consensus_commit_rate_estimation_window_size = Some(10);
4243                        cfg.feature_flags.per_object_congestion_control_mode =
4244                            PerObjectCongestionControlMode::ExecutionTimeEstimate(
4245                                ExecutionTimeEstimateParams {
4246                                    target_utilization: 30,
4247                                    allowed_txn_cost_overage_burst_limit_us: 100_000, // 100 ms
4248                                    randomness_scalar: 20,
4249                                    max_estimate_us: 1_500_000, // 1.5s
4250                                    stored_observations_num_included_checkpoints: 10,
4251                                    stored_observations_limit: u64::MAX,
4252                                    stake_weighted_median_threshold: 0,
4253                                    default_none_duration_for_new_keys: false,
4254                                    observations_chunk_size: None,
4255                                },
4256                            );
4257
4258                        // Enable the new depth-first block sync logic.
4259                        cfg.feature_flags.consensus_batched_block_sync = true;
4260
4261                        // Enable nitro attestation upgraded parsing logic and enable the
4262                        // native function on mainnet.
4263                        cfg.feature_flags.enable_nitro_attestation_upgraded_parsing = true;
4264                        cfg.feature_flags.enable_nitro_attestation = true;
4265                    }
4266                }
4267                84 => {
4268                    if chain == Chain::Mainnet {
4269                        cfg.feature_flags.resolve_type_input_ids_to_defining_id = true;
4270                        cfg.transfer_party_transfer_internal_cost_base = Some(52);
4271
4272                        // Enable execution time estimate mode for congestion control on mainnet.
4273                        cfg.feature_flags.record_additional_state_digest_in_prologue = true;
4274                        cfg.consensus_commit_rate_estimation_window_size = Some(10);
4275                        cfg.feature_flags.per_object_congestion_control_mode =
4276                            PerObjectCongestionControlMode::ExecutionTimeEstimate(
4277                                ExecutionTimeEstimateParams {
4278                                    target_utilization: 30,
4279                                    allowed_txn_cost_overage_burst_limit_us: 100_000, // 100 ms
4280                                    randomness_scalar: 20,
4281                                    max_estimate_us: 1_500_000, // 1.5s
4282                                    stored_observations_num_included_checkpoints: 10,
4283                                    stored_observations_limit: u64::MAX,
4284                                    stake_weighted_median_threshold: 0,
4285                                    default_none_duration_for_new_keys: false,
4286                                    observations_chunk_size: None,
4287                                },
4288                            );
4289
4290                        // Enable the new depth-first block sync logic.
4291                        cfg.feature_flags.consensus_batched_block_sync = true;
4292
4293                        // Enable nitro attestation upgraded parsing logic and enable the
4294                        // native function on mainnet.
4295                        cfg.feature_flags.enable_nitro_attestation_upgraded_parsing = true;
4296                        cfg.feature_flags.enable_nitro_attestation = true;
4297                    }
4298
4299                    // Limit the number of stored execution time observations at end of epoch.
4300                    cfg.feature_flags.per_object_congestion_control_mode =
4301                        PerObjectCongestionControlMode::ExecutionTimeEstimate(
4302                            ExecutionTimeEstimateParams {
4303                                target_utilization: 30,
4304                                allowed_txn_cost_overage_burst_limit_us: 100_000, // 100 ms
4305                                randomness_scalar: 20,
4306                                max_estimate_us: 1_500_000, // 1.5s
4307                                stored_observations_num_included_checkpoints: 10,
4308                                stored_observations_limit: 20,
4309                                stake_weighted_median_threshold: 0,
4310                                default_none_duration_for_new_keys: false,
4311                                observations_chunk_size: None,
4312                            },
4313                        );
4314                    cfg.feature_flags.allow_unbounded_system_objects = true;
4315                }
4316                85 => {
4317                    if chain != Chain::Mainnet && chain != Chain::Testnet {
4318                        cfg.feature_flags.enable_party_transfer = true;
4319                    }
4320
4321                    cfg.feature_flags
4322                        .record_consensus_determined_version_assignments_in_prologue_v2 = true;
4323                    cfg.feature_flags.disallow_self_identifier = true;
4324                    cfg.feature_flags.per_object_congestion_control_mode =
4325                        PerObjectCongestionControlMode::ExecutionTimeEstimate(
4326                            ExecutionTimeEstimateParams {
4327                                target_utilization: 50,
4328                                allowed_txn_cost_overage_burst_limit_us: 500_000, // 500 ms
4329                                randomness_scalar: 20,
4330                                max_estimate_us: 1_500_000, // 1.5s
4331                                stored_observations_num_included_checkpoints: 10,
4332                                stored_observations_limit: 20,
4333                                stake_weighted_median_threshold: 0,
4334                                default_none_duration_for_new_keys: false,
4335                                observations_chunk_size: None,
4336                            },
4337                        );
4338                }
4339                86 => {
4340                    cfg.feature_flags.type_tags_in_object_runtime = true;
4341                    cfg.max_move_enum_variants = Some(move_core_types::VARIANT_COUNT_MAX);
4342
4343                    // Set a stake_weighted_median_threshold for congestion control.
4344                    cfg.feature_flags.per_object_congestion_control_mode =
4345                        PerObjectCongestionControlMode::ExecutionTimeEstimate(
4346                            ExecutionTimeEstimateParams {
4347                                target_utilization: 50,
4348                                allowed_txn_cost_overage_burst_limit_us: 500_000, // 500 ms
4349                                randomness_scalar: 20,
4350                                max_estimate_us: 1_500_000, // 1.5s
4351                                stored_observations_num_included_checkpoints: 10,
4352                                stored_observations_limit: 20,
4353                                stake_weighted_median_threshold: 3334,
4354                                default_none_duration_for_new_keys: false,
4355                                observations_chunk_size: None,
4356                            },
4357                        );
4358                    // Enable party transfer for testnet.
4359                    if chain != Chain::Mainnet {
4360                        cfg.feature_flags.enable_party_transfer = true;
4361                    }
4362                }
4363                87 => {
4364                    if chain == Chain::Mainnet {
4365                        cfg.feature_flags.record_time_estimate_processed = true;
4366                    }
4367                    cfg.feature_flags.better_adapter_type_resolution_errors = true;
4368                }
4369                88 => {
4370                    cfg.feature_flags.record_time_estimate_processed = true;
4371                    cfg.tx_context_rgp_cost_base = Some(30);
4372                    cfg.feature_flags
4373                        .ignore_execution_time_observations_after_certs_closed = true;
4374
4375                    // Disable backwards compatible behavior in execution time estimator for
4376                    // new protocol version.
4377                    cfg.feature_flags.per_object_congestion_control_mode =
4378                        PerObjectCongestionControlMode::ExecutionTimeEstimate(
4379                            ExecutionTimeEstimateParams {
4380                                target_utilization: 50,
4381                                allowed_txn_cost_overage_burst_limit_us: 500_000, // 500 ms
4382                                randomness_scalar: 20,
4383                                max_estimate_us: 1_500_000, // 1.5s
4384                                stored_observations_num_included_checkpoints: 10,
4385                                stored_observations_limit: 20,
4386                                stake_weighted_median_threshold: 3334,
4387                                default_none_duration_for_new_keys: true,
4388                                observations_chunk_size: None,
4389                            },
4390                        );
4391                }
4392                89 => {
4393                    cfg.feature_flags.dependency_linkage_error = true;
4394                    cfg.feature_flags.additional_multisig_checks = true;
4395                }
4396                90 => {
4397                    // 100x RGP
4398                    cfg.max_gas_price_rgp_factor_for_aborted_transactions = Some(100);
4399                    cfg.feature_flags.debug_fatal_on_move_invariant_violation = true;
4400                    cfg.feature_flags.additional_consensus_digest_indirect_state = true;
4401                    cfg.feature_flags.accept_passkey_in_multisig = true;
4402                    cfg.feature_flags.passkey_auth = true;
4403                    cfg.feature_flags.check_for_init_during_upgrade = true;
4404
4405                    // Enable Mysticeti fastpath handlers on testnet.
4406                    if chain != Chain::Mainnet {
4407                        cfg.feature_flags.mysticeti_fastpath = true;
4408                    }
4409                }
4410                91 => {
4411                    cfg.feature_flags.per_command_shared_object_transfer_rules = true;
4412                }
4413                92 => {
4414                    cfg.feature_flags.per_command_shared_object_transfer_rules = false;
4415                }
4416                93 => {
4417                    cfg.feature_flags
4418                        .consensus_checkpoint_signature_key_includes_digest = true;
4419                }
4420                94 => {
4421                    // Decrease stored observations limit 20->18 to stay within system object size limit.
4422                    cfg.feature_flags.per_object_congestion_control_mode =
4423                        PerObjectCongestionControlMode::ExecutionTimeEstimate(
4424                            ExecutionTimeEstimateParams {
4425                                target_utilization: 50,
4426                                allowed_txn_cost_overage_burst_limit_us: 500_000, // 500 ms
4427                                randomness_scalar: 20,
4428                                max_estimate_us: 1_500_000, // 1.5s
4429                                stored_observations_num_included_checkpoints: 10,
4430                                stored_observations_limit: 18,
4431                                stake_weighted_median_threshold: 3334,
4432                                default_none_duration_for_new_keys: true,
4433                                observations_chunk_size: None,
4434                            },
4435                        );
4436
4437                    // Enable party transfer on mainnet.
4438                    cfg.feature_flags.enable_party_transfer = true;
4439                }
4440                95 => {
4441                    cfg.type_name_id_base_cost = Some(52);
4442
4443                    // Reduce the frequency of checkpoint splitting under high TPS.
4444                    cfg.max_transactions_per_checkpoint = Some(20_000);
4445                }
4446                96 => {
4447                    // Enable artifacts digest in devnet.
4448                    if chain != Chain::Mainnet && chain != Chain::Testnet {
4449                        cfg.feature_flags
4450                            .include_checkpoint_artifacts_digest_in_summary = true;
4451                    }
4452                    cfg.feature_flags.correct_gas_payment_limit_check = true;
4453                    cfg.feature_flags.authority_capabilities_v2 = true;
4454                    cfg.feature_flags.use_mfp_txns_in_load_initial_object_debts = true;
4455                    cfg.feature_flags.cancel_for_failed_dkg_early = true;
4456                    cfg.feature_flags.enable_coin_registry = true;
4457
4458                    // Enable Mysticeti fastpath handlers on mainnet.
4459                    cfg.feature_flags.mysticeti_fastpath = true;
4460                }
4461                97 => {
4462                    cfg.feature_flags.additional_borrow_checks = true;
4463                }
4464                98 => {
4465                    cfg.event_emit_auth_stream_cost = Some(52);
4466                    cfg.feature_flags.better_loader_errors = true;
4467                    cfg.feature_flags.generate_df_type_layouts = true;
4468                }
4469                99 => {
4470                    cfg.feature_flags.use_new_commit_handler = true;
4471                }
4472                100 => {
4473                    cfg.feature_flags.private_generics_verifier_v2 = true;
4474                }
4475                101 => {
4476                    cfg.feature_flags.create_root_accumulator_object = true;
4477                    cfg.max_updates_per_settlement_txn = Some(100);
4478                    if chain != Chain::Mainnet {
4479                        cfg.feature_flags.enable_poseidon = true;
4480                    }
4481                }
4482                102 => {
4483                    // Enable execution time observation chunking and increase limit to 180.
4484                    // max_move_object_size is 250 KB, we've experientially determined that fits ~ 18 estimates
4485                    // so if we have 10 chunks, that's 2.5MB, < 8MB max_serialized_tx_effects_size_bytes_system_tx
4486                    cfg.feature_flags.per_object_congestion_control_mode =
4487                        PerObjectCongestionControlMode::ExecutionTimeEstimate(
4488                            ExecutionTimeEstimateParams {
4489                                target_utilization: 50,
4490                                allowed_txn_cost_overage_burst_limit_us: 500_000, // 500 ms
4491                                randomness_scalar: 20,
4492                                max_estimate_us: 1_500_000, // 1.5s
4493                                stored_observations_num_included_checkpoints: 10,
4494                                stored_observations_limit: 180,
4495                                stake_weighted_median_threshold: 3334,
4496                                default_none_duration_for_new_keys: true,
4497                                observations_chunk_size: Some(18),
4498                            },
4499                        );
4500                    cfg.feature_flags.deprecate_global_storage_ops = true;
4501                }
4502                103 => {}
4503                104 => {
4504                    cfg.translation_per_command_base_charge = Some(1);
4505                    cfg.translation_per_input_base_charge = Some(1);
4506                    cfg.translation_pure_input_per_byte_charge = Some(1);
4507                    cfg.translation_per_type_node_charge = Some(1);
4508                    cfg.translation_per_reference_node_charge = Some(1);
4509                    cfg.translation_per_linkage_entry_charge = Some(10);
4510                    cfg.gas_model_version = Some(11);
4511                    cfg.feature_flags.abstract_size_in_object_runtime = true;
4512                    cfg.feature_flags.object_runtime_charge_cache_load_gas = true;
4513                    cfg.dynamic_field_hash_type_and_key_cost_base = Some(52);
4514                    cfg.dynamic_field_add_child_object_cost_base = Some(52);
4515                    cfg.dynamic_field_add_child_object_value_cost_per_byte = Some(1);
4516                    cfg.dynamic_field_borrow_child_object_cost_base = Some(52);
4517                    cfg.dynamic_field_borrow_child_object_child_ref_cost_per_byte = Some(1);
4518                    cfg.dynamic_field_remove_child_object_cost_base = Some(52);
4519                    cfg.dynamic_field_remove_child_object_child_cost_per_byte = Some(1);
4520                    cfg.dynamic_field_has_child_object_cost_base = Some(52);
4521                    cfg.dynamic_field_has_child_object_with_ty_cost_base = Some(52);
4522                    cfg.feature_flags.enable_ptb_execution_v2 = true;
4523
4524                    cfg.poseidon_bn254_cost_base = Some(260);
4525
4526                    cfg.feature_flags.consensus_skip_gced_accept_votes = true;
4527
4528                    if chain != Chain::Mainnet {
4529                        cfg.feature_flags
4530                            .enable_nitro_attestation_all_nonzero_pcrs_parsing = true;
4531                    }
4532
4533                    cfg.feature_flags
4534                        .include_cancelled_randomness_txns_in_prologue = true;
4535                }
4536                105 => {
4537                    cfg.feature_flags.enable_multi_epoch_transaction_expiration = true;
4538                    cfg.feature_flags.disable_preconsensus_locking = true;
4539
4540                    if chain != Chain::Mainnet {
4541                        cfg.feature_flags
4542                            .enable_nitro_attestation_always_include_required_pcrs_parsing = true;
4543                    }
4544                }
4545                106 => {
4546                    // est. 100 bytes per object * 76 (storage_gas_price)
4547                    cfg.accumulator_object_storage_cost = Some(7600);
4548
4549                    if chain != Chain::Mainnet && chain != Chain::Testnet {
4550                        cfg.feature_flags.enable_accumulators = true;
4551                        cfg.feature_flags.enable_address_balance_gas_payments = true;
4552                        cfg.feature_flags.enable_authenticated_event_streams = true;
4553                        cfg.feature_flags.enable_object_funds_withdraw = true;
4554                    }
4555                }
4556                107 => {
4557                    cfg.feature_flags
4558                        .consensus_skip_gced_blocks_in_direct_finalization = true;
4559
4560                    // Trigger edge cases more often in integration tests.
4561                    if in_integration_test() {
4562                        cfg.consensus_gc_depth = Some(6);
4563                        cfg.consensus_max_num_transactions_in_block = Some(8);
4564                    }
4565                }
4566                108 => {
4567                    cfg.feature_flags.gas_rounding_halve_digits = true;
4568                    cfg.feature_flags.flexible_tx_context_positions = true;
4569                    cfg.feature_flags.disable_entry_point_signature_check = true;
4570
4571                    if chain != Chain::Mainnet {
4572                        cfg.feature_flags.address_aliases = true;
4573
4574                        cfg.feature_flags.enable_accumulators = true;
4575                        cfg.feature_flags.enable_address_balance_gas_payments = true;
4576                    }
4577
4578                    cfg.feature_flags.enable_poseidon = true;
4579                }
4580                109 => {
4581                    cfg.binary_variant_handles = Some(1024);
4582                    cfg.binary_variant_instantiation_handles = Some(1024);
4583                    cfg.feature_flags.restrict_hot_or_not_entry_functions = true;
4584                }
4585                110 => {
4586                    cfg.feature_flags
4587                        .enable_nitro_attestation_all_nonzero_pcrs_parsing = true;
4588                    cfg.feature_flags
4589                        .enable_nitro_attestation_always_include_required_pcrs_parsing = true;
4590                    if chain != Chain::Mainnet && chain != Chain::Testnet {
4591                        cfg.feature_flags.split_checkpoints_in_consensus_handler = true;
4592                    }
4593                    cfg.feature_flags.validate_zklogin_public_identifier = true;
4594                    cfg.feature_flags.fix_checkpoint_signature_mapping = true;
4595                    cfg.feature_flags
4596                        .consensus_always_accept_system_transactions = true;
4597                    if chain != Chain::Mainnet {
4598                        cfg.feature_flags.enable_object_funds_withdraw = true;
4599                    }
4600                }
4601                111 => {
4602                    cfg.feature_flags.validator_metadata_verify_v2 = true;
4603                }
4604                112 => {
4605                    cfg.group_ops_ristretto_decode_scalar_cost = Some(7);
4606                    cfg.group_ops_ristretto_decode_point_cost = Some(200);
4607                    cfg.group_ops_ristretto_scalar_add_cost = Some(10);
4608                    cfg.group_ops_ristretto_point_add_cost = Some(500);
4609                    cfg.group_ops_ristretto_scalar_sub_cost = Some(10);
4610                    cfg.group_ops_ristretto_point_sub_cost = Some(500);
4611                    cfg.group_ops_ristretto_scalar_mul_cost = Some(11);
4612                    cfg.group_ops_ristretto_point_mul_cost = Some(1200);
4613                    cfg.group_ops_ristretto_scalar_div_cost = Some(151);
4614                    cfg.group_ops_ristretto_point_div_cost = Some(2500);
4615
4616                    if chain != Chain::Mainnet && chain != Chain::Testnet {
4617                        cfg.feature_flags.enable_ristretto255_group_ops = true;
4618                    }
4619                }
4620                113 => {
4621                    cfg.feature_flags.address_balance_gas_check_rgp_at_signing = true;
4622                    if chain != Chain::Mainnet && chain != Chain::Testnet {
4623                        cfg.feature_flags.defer_unpaid_amplification = true;
4624                    }
4625                }
4626                114 => {
4627                    cfg.feature_flags.randomize_checkpoint_tx_limit_in_tests = true;
4628                    cfg.feature_flags.address_balance_gas_reject_gas_coin_arg = true;
4629                    if chain != Chain::Mainnet {
4630                        cfg.feature_flags.split_checkpoints_in_consensus_handler = true;
4631                        cfg.feature_flags.enable_authenticated_event_streams = true;
4632                        cfg.feature_flags
4633                            .include_checkpoint_artifacts_digest_in_summary = true;
4634                    }
4635                }
4636                // Use this template when making changes:
4637                //
4638                //     // modify an existing constant.
4639                //     move_binary_format_version: Some(7),
4640                //
4641                //     // Add a new constant (which is set to None in prior versions).
4642                //     new_constant: Some(new_value),
4643                //
4644                //     // Remove a constant (ensure that it is never accessed during this version).
4645                //     max_move_object_size: None,
4646                _ => panic!("unsupported version {:?}", version),
4647            }
4648        }
4649
4650        cfg
4651    }
4652
4653    pub fn apply_seeded_test_overrides(&mut self, seed: &[u8; 32]) {
4654        if !self.feature_flags.randomize_checkpoint_tx_limit_in_tests
4655            || !self.feature_flags.split_checkpoints_in_consensus_handler
4656        {
4657            return;
4658        }
4659
4660        if !mysten_common::in_test_configuration() {
4661            return;
4662        }
4663
4664        use rand::{Rng, SeedableRng, rngs::StdRng};
4665        let mut rng = StdRng::from_seed(*seed);
4666        let max_txns = rng.gen_range(10..=100u64);
4667        info!("seeded test override: max_transactions_per_checkpoint = {max_txns}");
4668        self.max_transactions_per_checkpoint = Some(max_txns);
4669    }
4670
4671    // Extract the bytecode verifier config from this protocol config.
4672    // If used during signing, `signing_limits` should be set.
4673    // The third limit configures`sanity_check_with_regex_reference_safety`,
4674    // which runs the new regex-based reference safety check to check that it is strictly more
4675    // permissive than the current implementation.
4676    pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
4677        let (
4678            max_back_edges_per_function,
4679            max_back_edges_per_module,
4680            sanity_check_with_regex_reference_safety,
4681        ) = if let Some((
4682            max_back_edges_per_function,
4683            max_back_edges_per_module,
4684            sanity_check_with_regex_reference_safety,
4685        )) = signing_limits
4686        {
4687            (
4688                Some(max_back_edges_per_function),
4689                Some(max_back_edges_per_module),
4690                Some(sanity_check_with_regex_reference_safety),
4691            )
4692        } else {
4693            (None, None, None)
4694        };
4695
4696        let additional_borrow_checks = if signing_limits.is_some() {
4697            // always turn on additional borrow checks during signing
4698            true
4699        } else {
4700            self.additional_borrow_checks()
4701        };
4702        let deprecate_global_storage_ops = if signing_limits.is_some() {
4703            // always turn on additional vector borrow checks during signing
4704            true
4705        } else {
4706            self.deprecate_global_storage_ops()
4707        };
4708
4709        VerifierConfig {
4710            max_loop_depth: Some(self.max_loop_depth() as usize),
4711            max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
4712            max_function_parameters: Some(self.max_function_parameters() as usize),
4713            max_basic_blocks: Some(self.max_basic_blocks() as usize),
4714            max_value_stack_size: self.max_value_stack_size() as usize,
4715            max_type_nodes: Some(self.max_type_nodes() as usize),
4716            max_push_size: Some(self.max_push_size() as usize),
4717            max_dependency_depth: Some(self.max_dependency_depth() as usize),
4718            max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
4719            max_function_definitions: Some(self.max_function_definitions() as usize),
4720            max_data_definitions: Some(self.max_struct_definitions() as usize),
4721            max_constant_vector_len: Some(self.max_move_vector_len()),
4722            max_back_edges_per_function,
4723            max_back_edges_per_module,
4724            max_basic_blocks_in_script: None,
4725            max_identifier_len: self.max_move_identifier_len_as_option(), // Before protocol version 9, there was no limit
4726            disallow_self_identifier: self.feature_flags.disallow_self_identifier,
4727            allow_receiving_object_id: self.allow_receiving_object_id(),
4728            reject_mutable_random_on_entry_functions: self
4729                .reject_mutable_random_on_entry_functions(),
4730            bytecode_version: self.move_binary_format_version(),
4731            max_variants_in_enum: self.max_move_enum_variants_as_option(),
4732            additional_borrow_checks,
4733            better_loader_errors: self.better_loader_errors(),
4734            private_generics_verifier_v2: self.private_generics_verifier_v2(),
4735            sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
4736                .map(|limit| limit as u128),
4737            deprecate_global_storage_ops,
4738            disable_entry_point_signature_check: self.disable_entry_point_signature_check(),
4739            switch_to_regex_reference_safety: false,
4740        }
4741    }
4742
4743    pub fn binary_config(
4744        &self,
4745        override_deprecate_global_storage_ops_during_deserialization: Option<bool>,
4746    ) -> BinaryConfig {
4747        let deprecate_global_storage_ops =
4748            override_deprecate_global_storage_ops_during_deserialization
4749                .unwrap_or_else(|| self.deprecate_global_storage_ops());
4750        BinaryConfig::new(
4751            self.move_binary_format_version(),
4752            self.min_move_binary_format_version_as_option()
4753                .unwrap_or(VERSION_1),
4754            self.no_extraneous_module_bytes(),
4755            deprecate_global_storage_ops,
4756            TableConfig {
4757                module_handles: self.binary_module_handles_as_option().unwrap_or(u16::MAX),
4758                datatype_handles: self.binary_struct_handles_as_option().unwrap_or(u16::MAX),
4759                function_handles: self.binary_function_handles_as_option().unwrap_or(u16::MAX),
4760                function_instantiations: self
4761                    .binary_function_instantiations_as_option()
4762                    .unwrap_or(u16::MAX),
4763                signatures: self.binary_signatures_as_option().unwrap_or(u16::MAX),
4764                constant_pool: self.binary_constant_pool_as_option().unwrap_or(u16::MAX),
4765                identifiers: self.binary_identifiers_as_option().unwrap_or(u16::MAX),
4766                address_identifiers: self
4767                    .binary_address_identifiers_as_option()
4768                    .unwrap_or(u16::MAX),
4769                struct_defs: self.binary_struct_defs_as_option().unwrap_or(u16::MAX),
4770                struct_def_instantiations: self
4771                    .binary_struct_def_instantiations_as_option()
4772                    .unwrap_or(u16::MAX),
4773                function_defs: self.binary_function_defs_as_option().unwrap_or(u16::MAX),
4774                field_handles: self.binary_field_handles_as_option().unwrap_or(u16::MAX),
4775                field_instantiations: self
4776                    .binary_field_instantiations_as_option()
4777                    .unwrap_or(u16::MAX),
4778                friend_decls: self.binary_friend_decls_as_option().unwrap_or(u16::MAX),
4779                enum_defs: self.binary_enum_defs_as_option().unwrap_or(u16::MAX),
4780                enum_def_instantiations: self
4781                    .binary_enum_def_instantiations_as_option()
4782                    .unwrap_or(u16::MAX),
4783                variant_handles: self.binary_variant_handles_as_option().unwrap_or(u16::MAX),
4784                variant_instantiation_handles: self
4785                    .binary_variant_instantiation_handles_as_option()
4786                    .unwrap_or(u16::MAX),
4787            },
4788        )
4789    }
4790
4791    /// Override one or more settings in the config, for testing.
4792    /// This must be called at the beginning of the test, before get_for_(min|max)_version is
4793    /// called, since those functions cache their return value.
4794    pub fn apply_overrides_for_testing(
4795        override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + 'static,
4796    ) -> OverrideGuard {
4797        CONFIG_OVERRIDE.with(|ovr| {
4798            let mut cur = ovr.borrow_mut();
4799            assert!(cur.is_none(), "config override already present");
4800            *cur = Some(Box::new(override_fn));
4801            OverrideGuard
4802        })
4803    }
4804}
4805
4806// Setters for tests.
4807// This is only needed for feature_flags. Please suffix each setter with `_for_testing`.
4808// Non-feature_flags should already have test setters defined through macros.
4809impl ProtocolConfig {
4810    pub fn set_advance_to_highest_supported_protocol_version_for_testing(&mut self, val: bool) {
4811        self.feature_flags
4812            .advance_to_highest_supported_protocol_version = val
4813    }
4814    pub fn set_commit_root_state_digest_supported_for_testing(&mut self, val: bool) {
4815        self.feature_flags.commit_root_state_digest = val
4816    }
4817    pub fn set_zklogin_auth_for_testing(&mut self, val: bool) {
4818        self.feature_flags.zklogin_auth = val
4819    }
4820    pub fn set_enable_jwk_consensus_updates_for_testing(&mut self, val: bool) {
4821        self.feature_flags.enable_jwk_consensus_updates = val
4822    }
4823    pub fn set_random_beacon_for_testing(&mut self, val: bool) {
4824        self.feature_flags.random_beacon = val
4825    }
4826
4827    pub fn set_upgraded_multisig_for_testing(&mut self, val: bool) {
4828        self.feature_flags.upgraded_multisig_supported = val
4829    }
4830    pub fn set_accept_zklogin_in_multisig_for_testing(&mut self, val: bool) {
4831        self.feature_flags.accept_zklogin_in_multisig = val
4832    }
4833
4834    pub fn set_shared_object_deletion_for_testing(&mut self, val: bool) {
4835        self.feature_flags.shared_object_deletion = val;
4836    }
4837
4838    pub fn set_narwhal_new_leader_election_schedule_for_testing(&mut self, val: bool) {
4839        self.feature_flags.narwhal_new_leader_election_schedule = val;
4840    }
4841
4842    pub fn set_receive_object_for_testing(&mut self, val: bool) {
4843        self.feature_flags.receive_objects = val
4844    }
4845    pub fn set_narwhal_certificate_v2_for_testing(&mut self, val: bool) {
4846        self.feature_flags.narwhal_certificate_v2 = val
4847    }
4848    pub fn set_verify_legacy_zklogin_address_for_testing(&mut self, val: bool) {
4849        self.feature_flags.verify_legacy_zklogin_address = val
4850    }
4851
4852    pub fn set_per_object_congestion_control_mode_for_testing(
4853        &mut self,
4854        val: PerObjectCongestionControlMode,
4855    ) {
4856        self.feature_flags.per_object_congestion_control_mode = val;
4857    }
4858
4859    pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
4860        self.feature_flags.consensus_choice = val;
4861    }
4862
4863    pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
4864        self.feature_flags.consensus_network = val;
4865    }
4866
4867    pub fn set_zklogin_max_epoch_upper_bound_delta_for_testing(&mut self, val: Option<u64>) {
4868        self.feature_flags.zklogin_max_epoch_upper_bound_delta = val
4869    }
4870
4871    pub fn set_disable_bridge_for_testing(&mut self) {
4872        self.feature_flags.bridge = false
4873    }
4874
4875    pub fn set_mysticeti_num_leaders_per_round_for_testing(&mut self, val: Option<usize>) {
4876        self.feature_flags.mysticeti_num_leaders_per_round = val;
4877    }
4878
4879    pub fn set_enable_soft_bundle_for_testing(&mut self, val: bool) {
4880        self.feature_flags.soft_bundle = val;
4881    }
4882
4883    pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
4884        self.feature_flags.passkey_auth = val
4885    }
4886
4887    pub fn set_enable_party_transfer_for_testing(&mut self, val: bool) {
4888        self.feature_flags.enable_party_transfer = val
4889    }
4890
4891    pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
4892        self.feature_flags
4893            .consensus_distributed_vote_scoring_strategy = val;
4894    }
4895
4896    pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
4897        self.feature_flags.consensus_round_prober = val;
4898    }
4899
4900    pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
4901        self.feature_flags
4902            .disallow_new_modules_in_deps_only_packages = val;
4903    }
4904
4905    pub fn set_correct_gas_payment_limit_check_for_testing(&mut self, val: bool) {
4906        self.feature_flags.correct_gas_payment_limit_check = val;
4907    }
4908
4909    pub fn set_address_aliases_for_testing(&mut self, val: bool) {
4910        self.feature_flags.address_aliases = val;
4911    }
4912
4913    pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
4914        self.feature_flags
4915            .consensus_round_prober_probe_accepted_rounds = val;
4916    }
4917
4918    pub fn set_mysticeti_fastpath_for_testing(&mut self, val: bool) {
4919        self.feature_flags.mysticeti_fastpath = val;
4920    }
4921
4922    pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
4923        self.feature_flags.accept_passkey_in_multisig = val;
4924    }
4925
4926    pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
4927        self.feature_flags.consensus_batched_block_sync = val;
4928    }
4929
4930    pub fn set_record_time_estimate_processed_for_testing(&mut self, val: bool) {
4931        self.feature_flags.record_time_estimate_processed = val;
4932    }
4933
4934    pub fn set_prepend_prologue_tx_in_consensus_commit_in_checkpoints_for_testing(
4935        &mut self,
4936        val: bool,
4937    ) {
4938        self.feature_flags
4939            .prepend_prologue_tx_in_consensus_commit_in_checkpoints = val;
4940    }
4941
4942    pub fn enable_accumulators_for_testing(&mut self) {
4943        self.feature_flags.enable_accumulators = true;
4944    }
4945
4946    pub fn disable_accumulators_for_testing(&mut self) {
4947        self.feature_flags.enable_accumulators = false;
4948        self.feature_flags.enable_address_balance_gas_payments = false;
4949    }
4950
4951    pub fn enable_coin_reservation_for_testing(&mut self) {
4952        self.feature_flags.enable_coin_reservation_obj_refs = true;
4953    }
4954
4955    pub fn create_root_accumulator_object_for_testing(&mut self) {
4956        self.feature_flags.create_root_accumulator_object = true;
4957    }
4958
4959    pub fn disable_create_root_accumulator_object_for_testing(&mut self) {
4960        self.feature_flags.create_root_accumulator_object = false;
4961    }
4962
4963    pub fn enable_address_balance_gas_payments_for_testing(&mut self) {
4964        self.feature_flags.enable_accumulators = true;
4965        self.feature_flags.allow_private_accumulator_entrypoints = true;
4966        self.feature_flags.enable_address_balance_gas_payments = true;
4967        self.feature_flags.address_balance_gas_check_rgp_at_signing = true;
4968        self.feature_flags.address_balance_gas_reject_gas_coin_arg = true;
4969    }
4970
4971    pub fn disable_address_balance_gas_payments_for_testing(&mut self) {
4972        self.feature_flags.enable_address_balance_gas_payments = false;
4973    }
4974
4975    pub fn enable_multi_epoch_transaction_expiration_for_testing(&mut self) {
4976        self.feature_flags.enable_multi_epoch_transaction_expiration = true;
4977    }
4978
4979    pub fn enable_authenticated_event_streams_for_testing(&mut self) {
4980        self.enable_accumulators_for_testing();
4981        self.feature_flags.enable_authenticated_event_streams = true;
4982        self.feature_flags
4983            .include_checkpoint_artifacts_digest_in_summary = true;
4984        self.feature_flags.split_checkpoints_in_consensus_handler = true;
4985    }
4986
4987    pub fn disable_authenticated_event_streams_for_testing(&mut self) {
4988        self.feature_flags.enable_authenticated_event_streams = false;
4989    }
4990
4991    pub fn enable_non_exclusive_writes_for_testing(&mut self) {
4992        self.feature_flags.enable_non_exclusive_writes = true;
4993    }
4994
4995    pub fn set_ignore_execution_time_observations_after_certs_closed_for_testing(
4996        &mut self,
4997        val: bool,
4998    ) {
4999        self.feature_flags
5000            .ignore_execution_time_observations_after_certs_closed = val;
5001    }
5002
5003    pub fn set_consensus_checkpoint_signature_key_includes_digest_for_testing(
5004        &mut self,
5005        val: bool,
5006    ) {
5007        self.feature_flags
5008            .consensus_checkpoint_signature_key_includes_digest = val;
5009    }
5010
5011    pub fn set_cancel_for_failed_dkg_early_for_testing(&mut self, val: bool) {
5012        self.feature_flags.cancel_for_failed_dkg_early = val;
5013    }
5014
5015    pub fn set_use_mfp_txns_in_load_initial_object_debts_for_testing(&mut self, val: bool) {
5016        self.feature_flags.use_mfp_txns_in_load_initial_object_debts = val;
5017    }
5018
5019    pub fn set_authority_capabilities_v2_for_testing(&mut self, val: bool) {
5020        self.feature_flags.authority_capabilities_v2 = val;
5021    }
5022
5023    pub fn allow_references_in_ptbs_for_testing(&mut self) {
5024        self.feature_flags.allow_references_in_ptbs = true;
5025    }
5026
5027    pub fn set_consensus_skip_gced_accept_votes_for_testing(&mut self, val: bool) {
5028        self.feature_flags.consensus_skip_gced_accept_votes = val;
5029    }
5030
5031    pub fn set_enable_object_funds_withdraw_for_testing(&mut self, val: bool) {
5032        self.feature_flags.enable_object_funds_withdraw = val;
5033    }
5034
5035    pub fn set_split_checkpoints_in_consensus_handler_for_testing(&mut self, val: bool) {
5036        self.feature_flags.split_checkpoints_in_consensus_handler = val;
5037    }
5038}
5039
5040type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send;
5041
5042thread_local! {
5043    static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = RefCell::new(None);
5044}
5045
5046#[must_use]
5047pub struct OverrideGuard;
5048
5049impl Drop for OverrideGuard {
5050    fn drop(&mut self) {
5051        info!("restoring override fn");
5052        CONFIG_OVERRIDE.with(|ovr| {
5053            *ovr.borrow_mut() = None;
5054        });
5055    }
5056}
5057
5058/// Defines which limit got crossed.
5059/// The value which crossed the limit and value of the limit crossed are embedded
5060#[derive(PartialEq, Eq)]
5061pub enum LimitThresholdCrossed {
5062    None,
5063    Soft(u128, u128),
5064    Hard(u128, u128),
5065}
5066
5067/// Convenience function for comparing limit ranges
5068/// V::MAX must be at >= U::MAX and T::MAX
5069pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
5070    x: T,
5071    soft_limit: U,
5072    hard_limit: V,
5073) -> LimitThresholdCrossed {
5074    let x: V = x.into();
5075    let soft_limit: V = soft_limit.into();
5076
5077    debug_assert!(soft_limit <= hard_limit);
5078
5079    // It is important to preserve this comparison order because if soft_limit == hard_limit
5080    // we want LimitThresholdCrossed::Hard
5081    if x >= hard_limit {
5082        LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
5083    } else if x < soft_limit {
5084        LimitThresholdCrossed::None
5085    } else {
5086        LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
5087    }
5088}
5089
5090#[macro_export]
5091macro_rules! check_limit {
5092    ($x:expr, $hard:expr) => {
5093        check_limit!($x, $hard, $hard)
5094    };
5095    ($x:expr, $soft:expr, $hard:expr) => {
5096        check_limit_in_range($x as u64, $soft, $hard)
5097    };
5098}
5099
5100/// Used to check which limits were crossed if the TX is metered (not system tx)
5101/// Args are: is_metered, value_to_check, metered_limit, unmetered_limit
5102/// metered_limit is always less than or equal to unmetered_hard_limit
5103#[macro_export]
5104macro_rules! check_limit_by_meter {
5105    ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
5106        // If this is metered, we use the metered_limit limit as the upper bound
5107        let (h, metered_str) = if $is_metered {
5108            ($metered_limit, "metered")
5109        } else {
5110            // Unmetered gets more headroom
5111            ($unmetered_hard_limit, "unmetered")
5112        };
5113        use sui_protocol_config::check_limit_in_range;
5114        let result = check_limit_in_range($x as u64, $metered_limit, h);
5115        match result {
5116            LimitThresholdCrossed::None => {}
5117            LimitThresholdCrossed::Soft(_, _) => {
5118                $metric.with_label_values(&[metered_str, "soft"]).inc();
5119            }
5120            LimitThresholdCrossed::Hard(_, _) => {
5121                $metric.with_label_values(&[metered_str, "hard"]).inc();
5122            }
5123        };
5124        result
5125    }};
5126}
5127#[cfg(all(test, not(msim)))]
5128mod test {
5129    use insta::assert_yaml_snapshot;
5130
5131    use super::*;
5132
5133    #[test]
5134    fn snapshot_tests() {
5135        println!("\n============================================================================");
5136        println!("!                                                                          !");
5137        println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
5138        println!("!                                                                          !");
5139        println!("============================================================================\n");
5140        for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
5141            // make Chain::Unknown snapshots compatible with pre-chain-id snapshots so that we
5142            // don't break the release-time compatibility tests. Once Chain Id configs have been
5143            // released everywhere, we can remove this and only test Mainnet and Testnet
5144            let chain_str = match chain_id {
5145                Chain::Unknown => "".to_string(),
5146                _ => format!("{:?}_", chain_id),
5147            };
5148            for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
5149                let cur = ProtocolVersion::new(i);
5150                assert_yaml_snapshot!(
5151                    format!("{}version_{}", chain_str, cur.as_u64()),
5152                    ProtocolConfig::get_for_version(cur, *chain_id)
5153                );
5154            }
5155        }
5156    }
5157
5158    #[test]
5159    fn test_getters() {
5160        let prot: ProtocolConfig =
5161            ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
5162        assert_eq!(
5163            prot.max_arguments(),
5164            prot.max_arguments_as_option().unwrap()
5165        );
5166    }
5167
5168    #[test]
5169    fn test_setters() {
5170        let mut prot: ProtocolConfig =
5171            ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
5172        prot.set_max_arguments_for_testing(123);
5173        assert_eq!(prot.max_arguments(), 123);
5174
5175        prot.set_max_arguments_from_str_for_testing("321".to_string());
5176        assert_eq!(prot.max_arguments(), 321);
5177
5178        prot.disable_max_arguments_for_testing();
5179        assert_eq!(prot.max_arguments_as_option(), None);
5180
5181        prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
5182        assert_eq!(prot.max_arguments(), 456);
5183    }
5184
5185    #[test]
5186    #[should_panic(expected = "unsupported version")]
5187    fn max_version_test() {
5188        // When this does not panic, version higher than MAX_PROTOCOL_VERSION exists.
5189        // To fix, bump MAX_PROTOCOL_VERSION or disable this check for the version.
5190        let _ = ProtocolConfig::get_for_version_impl(
5191            ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
5192            Chain::Unknown,
5193        );
5194    }
5195
5196    #[test]
5197    fn lookup_by_string_test() {
5198        let prot: ProtocolConfig =
5199            ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
5200        // Does not exist
5201        assert!(prot.lookup_attr("some random string".to_string()).is_none());
5202
5203        assert!(
5204            prot.lookup_attr("max_arguments".to_string())
5205                == Some(ProtocolConfigValue::u32(prot.max_arguments())),
5206        );
5207
5208        // We didnt have this in version 1
5209        assert!(
5210            prot.lookup_attr("max_move_identifier_len".to_string())
5211                .is_none()
5212        );
5213
5214        // But we did in version 9
5215        let prot: ProtocolConfig =
5216            ProtocolConfig::get_for_version(ProtocolVersion::new(9), Chain::Unknown);
5217        assert!(
5218            prot.lookup_attr("max_move_identifier_len".to_string())
5219                == Some(ProtocolConfigValue::u64(prot.max_move_identifier_len()))
5220        );
5221
5222        let prot: ProtocolConfig =
5223            ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
5224        // We didnt have this in version 1
5225        assert!(
5226            prot.attr_map()
5227                .get("max_move_identifier_len")
5228                .unwrap()
5229                .is_none()
5230        );
5231        // We had this in version 1
5232        assert!(
5233            prot.attr_map().get("max_arguments").unwrap()
5234                == &Some(ProtocolConfigValue::u32(prot.max_arguments()))
5235        );
5236
5237        // Check feature flags
5238        let prot: ProtocolConfig =
5239            ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
5240        // Does not exist
5241        assert!(
5242            prot.feature_flags
5243                .lookup_attr("some random string".to_owned())
5244                .is_none()
5245        );
5246        assert!(
5247            !prot
5248                .feature_flags
5249                .attr_map()
5250                .contains_key("some random string")
5251        );
5252
5253        // Was false in v1
5254        assert!(
5255            prot.feature_flags
5256                .lookup_attr("package_upgrades".to_owned())
5257                == Some(false)
5258        );
5259        assert!(
5260            prot.feature_flags
5261                .attr_map()
5262                .get("package_upgrades")
5263                .unwrap()
5264                == &false
5265        );
5266        let prot: ProtocolConfig =
5267            ProtocolConfig::get_for_version(ProtocolVersion::new(4), Chain::Unknown);
5268        // Was true from v3 and up
5269        assert!(
5270            prot.feature_flags
5271                .lookup_attr("package_upgrades".to_owned())
5272                == Some(true)
5273        );
5274        assert!(
5275            prot.feature_flags
5276                .attr_map()
5277                .get("package_upgrades")
5278                .unwrap()
5279                == &true
5280        );
5281    }
5282
5283    #[test]
5284    fn limit_range_fn_test() {
5285        let low = 100u32;
5286        let high = 10000u64;
5287
5288        assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
5289        assert!(matches!(
5290            check_limit!(255u16, low, high),
5291            LimitThresholdCrossed::Soft(255u128, 100)
5292        ));
5293        // This wont compile because lossy
5294        //assert!(check_limit!(100000000u128, low, high) == LimitThresholdCrossed::None);
5295        // This wont compile because lossy
5296        //assert!(check_limit!(100000000usize, low, high) == LimitThresholdCrossed::None);
5297
5298        assert!(matches!(
5299            check_limit!(2550000u64, low, high),
5300            LimitThresholdCrossed::Hard(2550000, 10000)
5301        ));
5302
5303        assert!(matches!(
5304            check_limit!(2550000u64, high, high),
5305            LimitThresholdCrossed::Hard(2550000, 10000)
5306        ));
5307
5308        assert!(matches!(
5309            check_limit!(1u8, high),
5310            LimitThresholdCrossed::None
5311        ));
5312
5313        assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
5314
5315        assert!(matches!(
5316            check_limit!(2550000u64, high),
5317            LimitThresholdCrossed::Hard(2550000, 10000)
5318        ));
5319    }
5320}