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