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