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