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