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