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