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