sui_protocol_config/
lib.rs

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