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