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