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