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