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