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