sui_protocol_config/
lib.rs

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