sui_protocol_config/
lib.rs

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