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