sui_protocol_config/
lib.rs

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