sui_protocol_config/
lib.rs

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