sui_protocol_config/
lib.rs

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