iota_protocol_config/
lib.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use std::{
6    cell::RefCell,
7    cmp::min,
8    sync::atomic::{AtomicBool, Ordering},
9};
10
11use clap::*;
12use iota_protocol_config_macros::{
13    ProtocolConfigAccessors, ProtocolConfigFeatureFlagsGetters, ProtocolConfigOverride,
14};
15use move_vm_config::verifier::VerifierConfig;
16use serde::{Deserialize, Serialize};
17use serde_with::skip_serializing_none;
18use tracing::{info, warn};
19
20/// The minimum and maximum protocol versions supported by this build.
21const MIN_PROTOCOL_VERSION: u64 = 1;
22pub const MAX_PROTOCOL_VERSION: u64 = 19;
23
24// Record history of protocol version allocations here:
25//
26// Version 1:  Original version.
27// Version 2:  Don't redistribute slashed staking rewards, fix computation of
28//             SystemEpochInfoEventV1.
29// Version 3:  Set the `relocate_event_module` to be true so that the module
30//             that is associated as the "sending module" for an event is
31//             relocated by linkage.
32//             Add `Clock` based unlock to `Timelock` objects.
33// Version 4:  Introduce the `max_type_to_layout_nodes` config that sets the
34//             maximal nodes which are allowed when converting to a type layout.
35// Version 5:  Introduce fixed protocol-defined base fee, IotaSystemStateV2 and
36//             SystemEpochInfoEventV2.
37//             Disallow adding new modules in `deps-only` packages.
38//             Improve gas/wall time efficiency of some Move stdlib vector
39//             functions.
40//             Add new gas model version to update charging of functions.
41//             Enable proper conversion of certain type argument errors in the
42//             execution layer.
43// Version 6:  Bound size of values created in the adapter.
44// Version 7:  Improve handling of stake withdrawal from candidate validators.
45// Version 8:  Variants as type nodes.
46//             Enable smart ancestor selection for testnet.
47//             Enable probing for accepted rounds in round prober for testnet.
48//             Switch to distributed vote scoring in consensus in testnet.
49//             Enable zstd compression for consensus tonic network in testnet.
50//             Enable consensus garbage collection for testnet
51//             Enable the new consensus commit rule for testnet.
52//             Enable min_free_execution_slot for the shared object congestion
53//             tracker in devnet.
54// Version 9:  Disable smart ancestor selection for the testnet.
55//             Enable zstd compression for consensus tonic network in mainnet.
56//             Enable passkey auth in multisig for devnet.
57//             Remove the iota-bridge from the framework.
58// Version 10: Enable min_free_execution_slot for the shared object congestion
59//             tracker in all networks.
60//             Increase the committee size to 80 on all networks.
61//             Enable round prober in consensus for mainnet.
62//             Enable probing for accepted rounds in round prober for mainnet.
63//             Switch to distributed vote scoring in consensus for mainnet.
64//             Enable the new consensus commit rule for mainnet.
65//             Enable consensus garbage collection for mainnet with GC depth set
66//             to 60 rounds.
67//             Enable batching in synchronizer for testnet
68//             Enable the gas price feedback mechanism in devnet.
69//             Enable Identifier input validation.
70//             Removes unnecessary child object mutations
71//             Add additional signature checks
72//             Add additional linkage checks
73// Version 11: Framework fix regarding candidate validator commission rate.
74// Version 12: Enable the gas price feedback mechanism in all networks.
75//             Enable the normalization of PTB arguments.
76// Version 13: Introduce logic to allow the committee to be selected from a set
77//             of eligible active validators.
78//             Enable processing and tracking AuthorityCapabilitiesV1 from
79//             non-committee validators in the devnet.
80// Version 14: Switches the consensus protocol to Starfish in devnet.
81//             Enable median-based commit timestamp calculation in consensus,
82//             and enforce checkpoint timestamp monotonicity for testnet.
83//             Enable batched block sync for mainnet.
84//             Enable selecting committee only from active validators that
85//             support the next epoch's version and issued valid
86//             AuthorityCapabilities notification in testnet.
87// Version 15: Enable shared object transaction bursts of 10 times average load
88//             on devnet.
89// Version 16: Enable selecting committee only from active validators that
90//             support the next epoch's version and issued valid
91//             AuthorityCapabilities notification.
92//             Enable committing transactions only for traversed headers in
93//             Starfish.
94// Version 17: Increase the committee size to 100 on all networks.
95// Version 18: Enable passkey authentication support in testnet.
96// Version 19: Enable congestion limit overshoot in the gas price feedback
97//             mechanism on devnet.
98//             Enable a separate gas price feedback mechanism for transactions
99//             using randomness on devnet.
100#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
101pub struct ProtocolVersion(u64);
102
103impl ProtocolVersion {
104    // The minimum and maximum protocol version supported by this binary.
105    // Counterintuitively, this constant may change over time as support for old
106    // protocol versions is removed from the source. This ensures that when a
107    // new network (such as a testnet) is created, its genesis committee will
108    // use a protocol version that is actually supported by the binary.
109    pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
110
111    pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
112
113    #[cfg(not(msim))]
114    const MAX_ALLOWED: Self = Self::MAX;
115
116    // We create one additional "fake" version in simulator builds so that we can
117    // test upgrades.
118    #[cfg(msim)]
119    pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
120
121    pub fn new(v: u64) -> Self {
122        Self(v)
123    }
124
125    pub const fn as_u64(&self) -> u64 {
126        self.0
127    }
128
129    // For serde deserialization - we don't define a Default impl because there
130    // isn't a single universally appropriate default value.
131    pub fn max() -> Self {
132        Self::MAX
133    }
134}
135
136impl From<u64> for ProtocolVersion {
137    fn from(v: u64) -> Self {
138        Self::new(v)
139    }
140}
141
142impl std::ops::Sub<u64> for ProtocolVersion {
143    type Output = Self;
144    fn sub(self, rhs: u64) -> Self::Output {
145        Self::new(self.0 - rhs)
146    }
147}
148
149impl std::ops::Add<u64> for ProtocolVersion {
150    type Output = Self;
151    fn add(self, rhs: u64) -> Self::Output {
152        Self::new(self.0 + rhs)
153    }
154}
155
156#[derive(
157    Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
158)]
159pub enum Chain {
160    Mainnet,
161    Testnet,
162    #[default]
163    Unknown,
164}
165
166impl Chain {
167    pub fn as_str(self) -> &'static str {
168        match self {
169            Chain::Mainnet => "mainnet",
170            Chain::Testnet => "testnet",
171            Chain::Unknown => "unknown",
172        }
173    }
174}
175
176pub struct Error(pub String);
177
178// TODO: There are quite a few non boolean values in the feature flags. We
179// should move them out.
180/// Records on/off feature flags that may vary at each protocol version.
181#[derive(Default, Clone, Serialize, Deserialize, Debug, ProtocolConfigFeatureFlagsGetters)]
182struct FeatureFlags {
183    // Add feature flags here, e.g.:
184    // new_protocol_feature: bool,
185
186    // Disables unnecessary invariant check in the Move VM when swapping the value out of a local
187    // This flag is used to provide the correct MoveVM configuration for clients.
188    #[serde(skip_serializing_if = "is_true")]
189    disable_invariant_violation_check_in_swap_loc: bool,
190
191    // If true, checks no extra bytes in a compiled module
192    // This flag is used to provide the correct MoveVM configuration for clients.
193    #[serde(skip_serializing_if = "is_true")]
194    no_extraneous_module_bytes: bool,
195
196    // Enable zklogin auth
197    #[serde(skip_serializing_if = "is_false")]
198    zklogin_auth: bool,
199
200    // How we order transactions coming out of consensus before sending to execution.
201    #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
202    consensus_transaction_ordering: ConsensusTransactionOrdering,
203
204    #[serde(skip_serializing_if = "is_false")]
205    enable_jwk_consensus_updates: bool,
206
207    // If true, multisig containing zkLogin sig is accepted.
208    #[serde(skip_serializing_if = "is_false")]
209    accept_zklogin_in_multisig: bool,
210
211    // If true, use the hardened OTW check
212    // This flag is used to provide the correct MoveVM configuration for clients.
213    #[serde(skip_serializing_if = "is_true")]
214    hardened_otw_check: bool,
215
216    // Enable the poseidon hash function
217    #[serde(skip_serializing_if = "is_false")]
218    enable_poseidon: bool,
219
220    // Enable native function for msm.
221    #[serde(skip_serializing_if = "is_false")]
222    enable_group_ops_native_function_msm: bool,
223
224    // Controls the behavior of per object congestion control in consensus handler.
225    #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
226    per_object_congestion_control_mode: PerObjectCongestionControlMode,
227
228    // The consensus protocol to be used for the epoch.
229    #[serde(skip_serializing_if = "ConsensusChoice::is_mysticeti")]
230    consensus_choice: ConsensusChoice,
231
232    // Consensus network to use.
233    #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
234    consensus_network: ConsensusNetwork,
235
236    // Set the upper bound allowed for max_epoch in zklogin signature.
237    #[serde(skip_serializing_if = "Option::is_none")]
238    zklogin_max_epoch_upper_bound_delta: Option<u64>,
239
240    // Enable VDF
241    #[serde(skip_serializing_if = "is_false")]
242    enable_vdf: bool,
243
244    // Enable passkey auth (SIP-9)
245    #[serde(skip_serializing_if = "is_false")]
246    passkey_auth: bool,
247
248    // Rethrow type layout errors during serialization instead of trying to convert them.
249    // This flag is used to provide the correct MoveVM configuration for clients.
250    #[serde(skip_serializing_if = "is_true")]
251    rethrow_serialization_type_layout_errors: bool,
252
253    // Makes the event's sending module version-aware.
254    #[serde(skip_serializing_if = "is_false")]
255    relocate_event_module: bool,
256
257    // Enable a protocol-defined base gas price for all transactions.
258    #[serde(skip_serializing_if = "is_false")]
259    protocol_defined_base_fee: bool,
260
261    // Enable uncompressed group elements in BLS123-81 G1
262    #[serde(skip_serializing_if = "is_false")]
263    uncompressed_g1_group_elements: bool,
264
265    // Disallow adding new modules in `deps-only` packages.
266    #[serde(skip_serializing_if = "is_false")]
267    disallow_new_modules_in_deps_only_packages: bool,
268
269    // Enable v2 native charging for natives.
270    #[serde(skip_serializing_if = "is_false")]
271    native_charging_v2: bool,
272
273    // Properly convert certain type argument errors in the execution layer.
274    #[serde(skip_serializing_if = "is_false")]
275    convert_type_argument_error: bool,
276
277    // Probe rounds received by peers from every authority.
278    #[serde(skip_serializing_if = "is_false")]
279    consensus_round_prober: bool,
280
281    // Use distributed vote leader scoring strategy in consensus.
282    #[serde(skip_serializing_if = "is_false")]
283    consensus_distributed_vote_scoring_strategy: bool,
284
285    // Enables the new logic for collecting the subdag in the consensus linearizer. The new logic
286    // does not stop the recursion at the highest committed round for each authority, but
287    // allows to commit uncommitted blocks up to gc round (excluded) for that authority.
288    #[serde(skip_serializing_if = "is_false")]
289    consensus_linearize_subdag_v2: bool,
290
291    // Variants count as nodes
292    #[serde(skip_serializing_if = "is_false")]
293    variant_nodes: bool,
294
295    // Use smart ancestor selection in consensus.
296    #[serde(skip_serializing_if = "is_false")]
297    consensus_smart_ancestor_selection: bool,
298
299    // Probe accepted rounds in round prober.
300    #[serde(skip_serializing_if = "is_false")]
301    consensus_round_prober_probe_accepted_rounds: bool,
302
303    // If true, enable zstd compression for consensus tonic network.
304    #[serde(skip_serializing_if = "is_false")]
305    consensus_zstd_compression: bool,
306
307    // Use the minimum free execution slot to schedule execution of a transaction in the shared
308    // object congestion tracker.
309    #[serde(skip_serializing_if = "is_false")]
310    congestion_control_min_free_execution_slot: bool,
311
312    // If true, multisig containing passkey sig is accepted.
313    #[serde(skip_serializing_if = "is_false")]
314    accept_passkey_in_multisig: bool,
315
316    // If true, enabled batched block sync in consensus.
317    #[serde(skip_serializing_if = "is_false")]
318    consensus_batched_block_sync: bool,
319
320    // To enable/disable the gas price feedback mechanism used for transactions
321    // cancelled due to shared object congestion
322    #[serde(skip_serializing_if = "is_false")]
323    congestion_control_gas_price_feedback_mechanism: bool,
324
325    // Validate identifier inputs separately
326    #[serde(skip_serializing_if = "is_false")]
327    validate_identifier_inputs: bool,
328
329    // If true, enables the optimizations for child object mutations, removing unnecessary
330    // mutations
331    #[serde(skip_serializing_if = "is_false")]
332    minimize_child_object_mutations: bool,
333
334    // If true enable additional linkage checks.
335    #[serde(skip_serializing_if = "is_false")]
336    dependency_linkage_error: bool,
337
338    // If true enable additional multisig checks.
339    #[serde(skip_serializing_if = "is_false")]
340    additional_multisig_checks: bool,
341
342    // If true, enables the normalization of PTB arguments but does not yet enable splatting
343    // `Result`s of length not equal to 1
344    #[serde(skip_serializing_if = "is_false")]
345    normalize_ptb_arguments: bool,
346
347    // If true, use ChangeEpochV3 for epoch change to pass an additional eligible_active_validators
348    // parameter to IotaSystem's advance_epoch call. This should only be enabled when on-chain
349    // IotaSystem objects are updated as well.
350    #[serde(skip_serializing_if = "is_false")]
351    select_committee_from_eligible_validators: bool,
352
353    // If true, non-committee active validators will sign and send AuthorityCapabilitiesV1 to the
354    // committee. Once the committee reaches consensus over the AuthorityCapabilitiesV1, it is
355    // recorded and possible to use in the committee selection if
356    // select_validators_supporting_next_epoch_version is enabled. This flag does not change the
357    // way that eligible_validators vector is created - still all active validators are used for
358    // selecting the committee.
359    #[serde(skip_serializing_if = "is_false")]
360    track_non_committee_eligible_validators: bool,
361
362    // The committee be selected from active_validators who support the next protocol version AND
363    // have issued a correct AuthorityCapabilities notification. This flag should only be enabled
364    // if both select_committee_from_eligible_validators and
365    // track_non_committee_eligible_validators are enabled. If this is disabled, then all
366    // active validators are used for selecting the committee (default behavior).
367    #[serde(skip_serializing_if = "is_false")]
368    select_committee_supporting_next_epoch_version: bool,
369
370    // If true, then it (1) will not enforce monotonicity checks for a block's ancestors, (2)
371    // calculates the commit's timestamp based on the weighted by stake median timestamp of the
372    // leader's ancestors, and (3) enforces checkpoint timestamps are non-decreasing.
373    #[serde(skip_serializing_if = "is_false")]
374    consensus_median_timestamp_with_checkpoint_enforcement: bool,
375
376    // If true, then transactions are committed only for traversed headers
377    #[serde(skip_serializing_if = "is_false")]
378    consensus_commit_transactions_only_for_traversed_headers: bool,
379
380    // To enable/disable congestion limit overshoot in the gas price feedback mechanism.
381    #[serde(skip_serializing_if = "is_false")]
382    congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
383
384    // To enable/disable a separate gas price feedback mechanism for transactions using
385    // randomness.
386    #[serde(skip_serializing_if = "is_false")]
387    separate_gas_price_feedback_mechanism_for_randomness: bool,
388}
389
390fn is_true(b: &bool) -> bool {
391    *b
392}
393
394fn is_false(b: &bool) -> bool {
395    !b
396}
397
398/// Ordering mechanism for transactions in one consensus output.
399#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
400pub enum ConsensusTransactionOrdering {
401    /// No ordering. Transactions are processed in the order they appear in the
402    /// consensus output.
403    #[default]
404    None,
405    /// Order transactions by gas price, highest first.
406    ByGasPrice,
407}
408
409impl ConsensusTransactionOrdering {
410    pub fn is_none(&self) -> bool {
411        matches!(self, ConsensusTransactionOrdering::None)
412    }
413}
414
415// The config for per object congestion control in consensus handler.
416#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
417pub enum PerObjectCongestionControlMode {
418    #[default]
419    None, // No congestion control.
420    TotalGasBudget, // Use txn gas budget as execution cost.
421    TotalTxCount,   // Use total txn count as execution cost.
422}
423
424impl PerObjectCongestionControlMode {
425    pub fn is_none(&self) -> bool {
426        matches!(self, PerObjectCongestionControlMode::None)
427    }
428}
429
430// Configuration options for consensus algorithm.
431#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
432pub enum ConsensusChoice {
433    #[default]
434    Mysticeti,
435    Starfish,
436}
437
438impl ConsensusChoice {
439    pub fn is_mysticeti(&self) -> bool {
440        matches!(self, ConsensusChoice::Mysticeti)
441    }
442    pub fn is_starfish(&self) -> bool {
443        matches!(self, ConsensusChoice::Starfish)
444    }
445}
446
447// Configuration options for consensus network.
448#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
449pub enum ConsensusNetwork {
450    #[default]
451    Tonic,
452}
453
454impl ConsensusNetwork {
455    pub fn is_tonic(&self) -> bool {
456        matches!(self, ConsensusNetwork::Tonic)
457    }
458}
459
460/// Constants that change the behavior of the protocol.
461///
462/// The value of each constant here must be fixed for a given protocol version.
463/// To change the value of a constant, advance the protocol version, and add
464/// support for it in `get_for_version` under the new version number.
465/// (below).
466///
467/// To add a new field to this struct, use the following procedure:
468/// - Advance the protocol version.
469/// - Add the field as a private `Option<T>` to the struct.
470/// - Initialize the field to `None` in prior protocol versions.
471/// - Initialize the field to `Some(val)` for your new protocol version.
472/// - Add a public getter that simply unwraps the field.
473/// - Two public getters of the form `field(&self) -> field_type` and
474///   `field_as_option(&self) -> Option<field_type>` will be automatically
475///   generated for you.
476/// Example for a field: `new_constant: Option<u64>`
477/// ```rust,ignore
478///      pub fn new_constant(&self) -> u64 {
479///         self.new_constant.expect(Self::CONSTANT_ERR_MSG)
480///     }
481///      pub fn new_constant_as_option(&self) -> Option<u64> {
482///         self.new_constant.expect(Self::CONSTANT_ERR_MSG)
483///     }
484/// ```
485/// With `pub fn new_constant(&self) -> u64`, if the constant is accessed in a
486/// protocol version in which it is not defined, the validator will crash.
487/// (Crashing is necessary because this type of error would almost always result
488/// in forking if not prevented here). If you don't want the validator to crash,
489/// you can use the `pub fn new_constant_as_option(&self) -> Option<u64>`
490/// getter, which will return `None` if the field is not defined at that
491/// version.
492/// - If you want a customized getter, you can add a method in the impl.
493#[skip_serializing_none]
494#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
495pub struct ProtocolConfig {
496    pub version: ProtocolVersion,
497
498    feature_flags: FeatureFlags,
499
500    // ==== Transaction input limits ====
501
502    //
503    /// Maximum serialized size of a transaction (in bytes).
504    max_tx_size_bytes: Option<u64>,
505
506    /// Maximum number of input objects to a transaction. Enforced by the
507    /// transaction input checker
508    max_input_objects: Option<u64>,
509
510    /// Max size of objects a transaction can write to disk after completion.
511    /// Enforce by the IOTA adapter. This is the sum of the serialized size
512    /// of all objects written to disk. The max size of individual objects
513    /// on the other hand is `max_move_object_size`.
514    max_size_written_objects: Option<u64>,
515    /// Max size of objects a system transaction can write to disk after
516    /// completion. Enforce by the IOTA adapter. Similar to
517    /// `max_size_written_objects` but for system transactions.
518    max_size_written_objects_system_tx: Option<u64>,
519
520    /// Maximum size of serialized transaction effects.
521    max_serialized_tx_effects_size_bytes: Option<u64>,
522
523    /// Maximum size of serialized transaction effects for system transactions.
524    max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
525
526    /// Maximum number of gas payment objects for a transaction.
527    max_gas_payment_objects: Option<u32>,
528
529    /// Maximum number of modules in a Publish transaction.
530    max_modules_in_publish: Option<u32>,
531
532    /// Maximum number of transitive dependencies in a package when publishing.
533    max_package_dependencies: Option<u32>,
534
535    /// Maximum number of arguments in a move call or a
536    /// ProgrammableTransaction's TransferObjects command.
537    max_arguments: Option<u32>,
538
539    /// Maximum number of total type arguments, computed recursively.
540    max_type_arguments: Option<u32>,
541
542    /// Maximum depth of an individual type argument.
543    max_type_argument_depth: Option<u32>,
544
545    /// Maximum size of a Pure CallArg.
546    max_pure_argument_size: Option<u32>,
547
548    /// Maximum number of Commands in a ProgrammableTransaction.
549    max_programmable_tx_commands: Option<u32>,
550
551    // ==== Move VM, Move bytecode verifier, and execution limits ===
552
553    //
554    /// Maximum Move bytecode version the VM understands. All older versions are
555    /// accepted.
556    move_binary_format_version: Option<u32>,
557    min_move_binary_format_version: Option<u32>,
558
559    /// Configuration controlling binary tables size.
560    binary_module_handles: Option<u16>,
561    binary_struct_handles: Option<u16>,
562    binary_function_handles: Option<u16>,
563    binary_function_instantiations: Option<u16>,
564    binary_signatures: Option<u16>,
565    binary_constant_pool: Option<u16>,
566    binary_identifiers: Option<u16>,
567    binary_address_identifiers: Option<u16>,
568    binary_struct_defs: Option<u16>,
569    binary_struct_def_instantiations: Option<u16>,
570    binary_function_defs: Option<u16>,
571    binary_field_handles: Option<u16>,
572    binary_field_instantiations: Option<u16>,
573    binary_friend_decls: Option<u16>,
574    binary_enum_defs: Option<u16>,
575    binary_enum_def_instantiations: Option<u16>,
576    binary_variant_handles: Option<u16>,
577    binary_variant_instantiation_handles: Option<u16>,
578
579    /// Maximum size of the `contents` part of an object, in bytes. Enforced by
580    /// the IOTA adapter when effects are produced.
581    max_move_object_size: Option<u64>,
582
583    // TODO: Option<increase to 500 KB. currently, publishing a package > 500 KB exceeds the max
584    // computation gas cost
585    /// Maximum size of a Move package object, in bytes. Enforced by the IOTA
586    /// adapter at the end of a publish transaction.
587    max_move_package_size: Option<u64>,
588
589    /// Max number of publish or upgrade commands allowed in a programmable
590    /// transaction block.
591    max_publish_or_upgrade_per_ptb: Option<u64>,
592
593    /// Maximum gas budget in NANOS that a transaction can use.
594    max_tx_gas: Option<u64>,
595
596    /// Maximum amount of the proposed gas price in NANOS (defined in the
597    /// transaction).
598    max_gas_price: Option<u64>,
599
600    /// The max computation bucket for gas. This is the max that can be charged
601    /// for computation.
602    max_gas_computation_bucket: Option<u64>,
603
604    // Define the value used to round up computation gas charges
605    gas_rounding_step: Option<u64>,
606
607    /// Maximum number of nested loops. Enforced by the Move bytecode verifier.
608    max_loop_depth: Option<u64>,
609
610    /// Maximum number of type arguments that can be bound to generic type
611    /// parameters. Enforced by the Move bytecode verifier.
612    max_generic_instantiation_length: Option<u64>,
613
614    /// Maximum number of parameters that a Move function can have. Enforced by
615    /// the Move bytecode verifier.
616    max_function_parameters: Option<u64>,
617
618    /// Maximum number of basic blocks that a Move function can have. Enforced
619    /// by the Move bytecode verifier.
620    max_basic_blocks: Option<u64>,
621
622    /// Maximum stack size value. Enforced by the Move bytecode verifier.
623    max_value_stack_size: Option<u64>,
624
625    /// Maximum number of "type nodes", a metric for how big a SignatureToken
626    /// will be when expanded into a fully qualified type. Enforced by the Move
627    /// bytecode verifier.
628    max_type_nodes: Option<u64>,
629
630    /// Maximum number of push instructions in one function. Enforced by the
631    /// Move bytecode verifier.
632    max_push_size: Option<u64>,
633
634    /// Maximum number of struct definitions in a module. Enforced by the Move
635    /// bytecode verifier.
636    max_struct_definitions: Option<u64>,
637
638    /// Maximum number of function definitions in a module. Enforced by the Move
639    /// bytecode verifier.
640    max_function_definitions: Option<u64>,
641
642    /// Maximum number of fields allowed in a struct definition. Enforced by the
643    /// Move bytecode verifier.
644    max_fields_in_struct: Option<u64>,
645
646    /// Maximum dependency depth. Enforced by the Move linker when loading
647    /// dependent modules.
648    max_dependency_depth: Option<u64>,
649
650    /// Maximum number of Move events that a single transaction can emit.
651    /// Enforced by the VM during execution.
652    max_num_event_emit: Option<u64>,
653
654    /// Maximum number of new IDs that a single transaction can create. Enforced
655    /// by the VM during execution.
656    max_num_new_move_object_ids: Option<u64>,
657
658    /// Maximum number of new IDs that a single system transaction can create.
659    /// Enforced by the VM during execution.
660    max_num_new_move_object_ids_system_tx: Option<u64>,
661
662    /// Maximum number of IDs that a single transaction can delete. Enforced by
663    /// the VM during execution.
664    max_num_deleted_move_object_ids: Option<u64>,
665
666    /// Maximum number of IDs that a single system transaction can delete.
667    /// Enforced by the VM during execution.
668    max_num_deleted_move_object_ids_system_tx: Option<u64>,
669
670    /// Maximum number of IDs that a single transaction can transfer. Enforced
671    /// by the VM during execution.
672    max_num_transferred_move_object_ids: Option<u64>,
673
674    /// Maximum number of IDs that a single system transaction can transfer.
675    /// Enforced by the VM during execution.
676    max_num_transferred_move_object_ids_system_tx: Option<u64>,
677
678    /// Maximum size of a Move user event. Enforced by the VM during execution.
679    max_event_emit_size: Option<u64>,
680
681    /// Maximum size of a Move user event. Enforced by the VM during execution.
682    max_event_emit_size_total: Option<u64>,
683
684    /// Maximum length of a vector in Move. Enforced by the VM during execution,
685    /// and for constants, by the verifier.
686    max_move_vector_len: Option<u64>,
687
688    /// Maximum length of an `Identifier` in Move. Enforced by the bytecode
689    /// verifier at signing.
690    max_move_identifier_len: Option<u64>,
691
692    /// Maximum depth of a Move value within the VM.
693    max_move_value_depth: Option<u64>,
694
695    /// Maximum number of variants in an enum. Enforced by the bytecode verifier
696    /// at signing.
697    max_move_enum_variants: Option<u64>,
698
699    /// Maximum number of back edges in Move function. Enforced by the bytecode
700    /// verifier at signing.
701    max_back_edges_per_function: Option<u64>,
702
703    /// Maximum number of back edges in Move module. Enforced by the bytecode
704    /// verifier at signing.
705    max_back_edges_per_module: Option<u64>,
706
707    /// Maximum number of meter `ticks` spent verifying a Move function.
708    /// Enforced by the bytecode verifier at signing.
709    max_verifier_meter_ticks_per_function: Option<u64>,
710
711    /// Maximum number of meter `ticks` spent verifying a Move function.
712    /// Enforced by the bytecode verifier at signing.
713    max_meter_ticks_per_module: Option<u64>,
714
715    /// Maximum number of meter `ticks` spent verifying a Move package. Enforced
716    /// by the bytecode verifier at signing.
717    max_meter_ticks_per_package: Option<u64>,
718
719    // === Object runtime internal operation limits ====
720    // These affect dynamic fields
721
722    //
723    /// Maximum number of cached objects in the object runtime ObjectStore.
724    /// Enforced by object runtime during execution
725    object_runtime_max_num_cached_objects: Option<u64>,
726
727    /// Maximum number of cached objects in the object runtime ObjectStore in
728    /// system transaction. Enforced by object runtime during execution
729    object_runtime_max_num_cached_objects_system_tx: Option<u64>,
730
731    /// Maximum number of stored objects accessed by object runtime ObjectStore.
732    /// Enforced by object runtime during execution
733    object_runtime_max_num_store_entries: Option<u64>,
734
735    /// Maximum number of stored objects accessed by object runtime ObjectStore
736    /// in system transaction. Enforced by object runtime during execution
737    object_runtime_max_num_store_entries_system_tx: Option<u64>,
738
739    // === Execution gas costs ====
740
741    //
742    /// Base cost for any IOTA transaction
743    base_tx_cost_fixed: Option<u64>,
744
745    /// Additional cost for a transaction that publishes a package
746    /// i.e., the base cost of such a transaction is base_tx_cost_fixed +
747    /// package_publish_cost_fixed
748    package_publish_cost_fixed: Option<u64>,
749
750    /// Cost per byte of a Move call transaction
751    /// i.e., the cost of such a transaction is base_cost +
752    /// (base_tx_cost_per_byte * size)
753    base_tx_cost_per_byte: Option<u64>,
754
755    /// Cost per byte for a transaction that publishes a package
756    package_publish_cost_per_byte: Option<u64>,
757
758    // Per-byte cost of reading an object during transaction execution
759    obj_access_cost_read_per_byte: Option<u64>,
760
761    // Per-byte cost of writing an object during transaction execution
762    obj_access_cost_mutate_per_byte: Option<u64>,
763
764    // Per-byte cost of deleting an object during transaction execution
765    obj_access_cost_delete_per_byte: Option<u64>,
766
767    /// Per-byte cost charged for each input object to a transaction.
768    /// Meant to approximate the cost of checking locks for each object
769    // TODO: Option<I'm not sure that this cost makes sense. Checking locks is "free"
770    // in the sense that an invalid tx that can never be committed/pay gas can
771    // force validators to check an arbitrary number of locks. If those checks are
772    // "free" for invalid transactions, why charge for them in valid transactions
773    // TODO: Option<if we keep this, I think we probably want it to be a fixed cost rather
774    // than a per-byte cost. checking an object lock should not require loading an
775    // entire object, just consulting an ID -> tx digest map
776    obj_access_cost_verify_per_byte: Option<u64>,
777
778    // Maximal nodes which are allowed when converting to a type layout.
779    max_type_to_layout_nodes: Option<u64>,
780
781    // Maximal size in bytes that a PTB value can be
782    max_ptb_value_size: Option<u64>,
783
784    // === Gas version. gas model ===
785
786    //
787    /// Gas model version, what code we are using to charge gas
788    gas_model_version: Option<u64>,
789
790    // === Storage gas costs ===
791
792    //
793    /// Per-byte cost of storing an object in the IOTA global object store. Some
794    /// of this cost may be refundable if the object is later freed
795    obj_data_cost_refundable: Option<u64>,
796
797    // Per-byte cost of storing an object in the IOTA transaction log (e.g., in
798    // CertifiedTransactionEffects) This depends on the size of various fields including the
799    // effects TODO: Option<I don't fully understand this^ and more details would be useful
800    obj_metadata_cost_non_refundable: Option<u64>,
801
802    // === Tokenomics ===
803
804    // TODO: Option<this should be changed to u64.
805    /// Sender of a txn that touches an object will get this percent of the
806    /// storage rebate back. In basis point.
807    storage_rebate_rate: Option<u64>,
808
809    /// The share of rewards that will be slashed and redistributed is 50%.
810    /// In basis point.
811    reward_slashing_rate: Option<u64>,
812
813    /// Unit storage gas price, Nanos per internal gas unit.
814    storage_gas_price: Option<u64>,
815
816    // Base gas price for computation gas, nanos per computation unit.
817    base_gas_price: Option<u64>,
818
819    /// The number of tokens minted as a validator subsidy per epoch.
820    validator_target_reward: Option<u64>,
821
822    // === Core Protocol ===
823
824    //
825    /// Max number of transactions per checkpoint.
826    /// Note that this is a protocol constant and not a config as validators
827    /// must have this set to the same value, otherwise they *will* fork.
828    max_transactions_per_checkpoint: Option<u64>,
829
830    /// Max size of a checkpoint in bytes.
831    /// Note that this is a protocol constant and not a config as validators
832    /// must have this set to the same value, otherwise they *will* fork.
833    max_checkpoint_size_bytes: Option<u64>,
834
835    /// A protocol upgrade always requires 2f+1 stake to agree. We support a
836    /// buffer of additional stake (as a fraction of f, expressed in basis
837    /// points) that is required before an upgrade can happen automatically.
838    /// 10000bps would indicate that complete unanimity is required (all
839    /// 3f+1 must vote), while 0bps would indicate that 2f+1 is sufficient.
840    buffer_stake_for_protocol_upgrade_bps: Option<u64>,
841
842    // === Native Function Costs ===
843
844    // `address` module
845    // Cost params for the Move native function `address::from_bytes(bytes: vector<u8>)`
846    address_from_bytes_cost_base: Option<u64>,
847    // Cost params for the Move native function `address::to_u256(address): u256`
848    address_to_u256_cost_base: Option<u64>,
849    // Cost params for the Move native function `address::from_u256(u256): address`
850    address_from_u256_cost_base: Option<u64>,
851
852    // `config` module
853    // Cost params for the Move native function `read_setting_impl<Name: copy + drop + store,
854    // SettingValue: key + store, SettingDataValue: store, Value: copy + drop + store,
855    // >(config: address, name: address, current_epoch: u64): Option<Value>`
856    config_read_setting_impl_cost_base: Option<u64>,
857    config_read_setting_impl_cost_per_byte: Option<u64>,
858
859    // `dynamic_field` module
860    // Cost params for the Move native function `hash_type_and_key<K: copy + drop + store>(parent:
861    // address, k: K): address`
862    dynamic_field_hash_type_and_key_cost_base: Option<u64>,
863    dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
864    dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
865    dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
866    // Cost params for the Move native function `add_child_object<Child: key>(parent: address,
867    // child: Child)`
868    dynamic_field_add_child_object_cost_base: Option<u64>,
869    dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
870    dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
871    dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
872    // Cost params for the Move native function `borrow_child_object_mut<Child: key>(parent: &mut
873    // UID, id: address): &mut Child`
874    dynamic_field_borrow_child_object_cost_base: Option<u64>,
875    dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
876    dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
877    // Cost params for the Move native function `remove_child_object<Child: key>(parent: address,
878    // id: address): Child`
879    dynamic_field_remove_child_object_cost_base: Option<u64>,
880    dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
881    dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
882    // Cost params for the Move native function `has_child_object(parent: address, id: address):
883    // bool`
884    dynamic_field_has_child_object_cost_base: Option<u64>,
885    // Cost params for the Move native function `has_child_object_with_ty<Child: key>(parent:
886    // address, id: address): bool`
887    dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
888    dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
889    dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
890
891    // `event` module
892    // Cost params for the Move native function `event::emit<T: copy + drop>(event: T)`
893    event_emit_cost_base: Option<u64>,
894    event_emit_value_size_derivation_cost_per_byte: Option<u64>,
895    event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
896    event_emit_output_cost_per_byte: Option<u64>,
897
898    //  `object` module
899    // Cost params for the Move native function `borrow_uid<T: key>(obj: &T): &UID`
900    object_borrow_uid_cost_base: Option<u64>,
901    // Cost params for the Move native function `delete_impl(id: address)`
902    object_delete_impl_cost_base: Option<u64>,
903    // Cost params for the Move native function `record_new_uid(id: address)`
904    object_record_new_uid_cost_base: Option<u64>,
905
906    // Transfer
907    // Cost params for the Move native function `transfer_impl<T: key>(obj: T, recipient: address)`
908    transfer_transfer_internal_cost_base: Option<u64>,
909    // Cost params for the Move native function `freeze_object<T: key>(obj: T)`
910    transfer_freeze_object_cost_base: Option<u64>,
911    // Cost params for the Move native function `share_object<T: key>(obj: T)`
912    transfer_share_object_cost_base: Option<u64>,
913    // Cost params for the Move native function
914    // `receive_object<T: key>(p: &mut UID, recv: Receiving<T>T)`
915    transfer_receive_object_cost_base: Option<u64>,
916
917    // TxContext
918    // Cost params for the Move native function `transfer_impl<T: key>(obj: T, recipient: address)`
919    tx_context_derive_id_cost_base: Option<u64>,
920
921    // Types
922    // Cost params for the Move native function `is_one_time_witness<T: drop>(_: &T): bool`
923    types_is_one_time_witness_cost_base: Option<u64>,
924    types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
925    types_is_one_time_witness_type_cost_per_byte: Option<u64>,
926
927    // Validator
928    // Cost params for the Move native function `validate_metadata_bcs(metadata: vector<u8>)`
929    validator_validate_metadata_cost_base: Option<u64>,
930    validator_validate_metadata_data_cost_per_byte: Option<u64>,
931
932    // Crypto natives
933    crypto_invalid_arguments_cost: Option<u64>,
934    // bls12381::bls12381_min_sig_verify
935    bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
936    bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
937    bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
938
939    // bls12381::bls12381_min_pk_verify
940    bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
941    bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
942    bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
943
944    // ecdsa_k1::ecrecover
945    ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
946    ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
947    ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
948    ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
949    ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
950    ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
951
952    // ecdsa_k1::decompress_pubkey
953    ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
954
955    // ecdsa_k1::secp256k1_verify
956    ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
957    ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
958    ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
959    ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
960    ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
961    ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
962
963    // ecdsa_r1::ecrecover
964    ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
965    ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
966    ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
967    ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
968    ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
969    ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
970
971    // ecdsa_r1::secp256k1_verify
972    ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
973    ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
974    ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
975    ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
976    ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
977    ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
978
979    // ecvrf::verify
980    ecvrf_ecvrf_verify_cost_base: Option<u64>,
981    ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
982    ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
983
984    // ed25519
985    ed25519_ed25519_verify_cost_base: Option<u64>,
986    ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
987    ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
988
989    // groth16::prepare_verifying_key
990    groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
991    groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
992
993    // groth16::verify_groth16_proof_internal
994    groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
995    groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
996    groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
997    groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
998    groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
999
1000    // hash::blake2b256
1001    hash_blake2b256_cost_base: Option<u64>,
1002    hash_blake2b256_data_cost_per_byte: Option<u64>,
1003    hash_blake2b256_data_cost_per_block: Option<u64>,
1004
1005    // hash::keccak256
1006    hash_keccak256_cost_base: Option<u64>,
1007    hash_keccak256_data_cost_per_byte: Option<u64>,
1008    hash_keccak256_data_cost_per_block: Option<u64>,
1009
1010    // poseidon::poseidon_bn254
1011    poseidon_bn254_cost_base: Option<u64>,
1012    poseidon_bn254_cost_per_block: Option<u64>,
1013
1014    // group_ops
1015    group_ops_bls12381_decode_scalar_cost: Option<u64>,
1016    group_ops_bls12381_decode_g1_cost: Option<u64>,
1017    group_ops_bls12381_decode_g2_cost: Option<u64>,
1018    group_ops_bls12381_decode_gt_cost: Option<u64>,
1019    group_ops_bls12381_scalar_add_cost: Option<u64>,
1020    group_ops_bls12381_g1_add_cost: Option<u64>,
1021    group_ops_bls12381_g2_add_cost: Option<u64>,
1022    group_ops_bls12381_gt_add_cost: Option<u64>,
1023    group_ops_bls12381_scalar_sub_cost: Option<u64>,
1024    group_ops_bls12381_g1_sub_cost: Option<u64>,
1025    group_ops_bls12381_g2_sub_cost: Option<u64>,
1026    group_ops_bls12381_gt_sub_cost: Option<u64>,
1027    group_ops_bls12381_scalar_mul_cost: Option<u64>,
1028    group_ops_bls12381_g1_mul_cost: Option<u64>,
1029    group_ops_bls12381_g2_mul_cost: Option<u64>,
1030    group_ops_bls12381_gt_mul_cost: Option<u64>,
1031    group_ops_bls12381_scalar_div_cost: Option<u64>,
1032    group_ops_bls12381_g1_div_cost: Option<u64>,
1033    group_ops_bls12381_g2_div_cost: Option<u64>,
1034    group_ops_bls12381_gt_div_cost: Option<u64>,
1035    group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1036    group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1037    group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1038    group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1039    group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1040    group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1041    group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1042    group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1043    group_ops_bls12381_msm_max_len: Option<u32>,
1044    group_ops_bls12381_pairing_cost: Option<u64>,
1045    group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1046    group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1047    group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1048    group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1049    group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1050
1051    // hmac::hmac_sha3_256
1052    hmac_hmac_sha3_256_cost_base: Option<u64>,
1053    hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1054    hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1055
1056    // zklogin::check_zklogin_id
1057    check_zklogin_id_cost_base: Option<u64>,
1058    // zklogin::check_zklogin_issuer
1059    check_zklogin_issuer_cost_base: Option<u64>,
1060
1061    vdf_verify_vdf_cost: Option<u64>,
1062    vdf_hash_to_input_cost: Option<u64>,
1063
1064    // Stdlib costs
1065    bcs_per_byte_serialized_cost: Option<u64>,
1066    bcs_legacy_min_output_size_cost: Option<u64>,
1067    bcs_failure_cost: Option<u64>,
1068
1069    hash_sha2_256_base_cost: Option<u64>,
1070    hash_sha2_256_per_byte_cost: Option<u64>,
1071    hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1072    hash_sha3_256_base_cost: Option<u64>,
1073    hash_sha3_256_per_byte_cost: Option<u64>,
1074    hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1075    type_name_get_base_cost: Option<u64>,
1076    type_name_get_per_byte_cost: Option<u64>,
1077
1078    string_check_utf8_base_cost: Option<u64>,
1079    string_check_utf8_per_byte_cost: Option<u64>,
1080    string_is_char_boundary_base_cost: Option<u64>,
1081    string_sub_string_base_cost: Option<u64>,
1082    string_sub_string_per_byte_cost: Option<u64>,
1083    string_index_of_base_cost: Option<u64>,
1084    string_index_of_per_byte_pattern_cost: Option<u64>,
1085    string_index_of_per_byte_searched_cost: Option<u64>,
1086
1087    vector_empty_base_cost: Option<u64>,
1088    vector_length_base_cost: Option<u64>,
1089    vector_push_back_base_cost: Option<u64>,
1090    vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1091    vector_borrow_base_cost: Option<u64>,
1092    vector_pop_back_base_cost: Option<u64>,
1093    vector_destroy_empty_base_cost: Option<u64>,
1094    vector_swap_base_cost: Option<u64>,
1095    debug_print_base_cost: Option<u64>,
1096    debug_print_stack_trace_base_cost: Option<u64>,
1097
1098    // === Execution Version ===
1099    execution_version: Option<u64>,
1100
1101    // Dictates the threshold (percentage of stake) that is used to calculate the "bad" nodes to be
1102    // swapped when creating the consensus schedule. The values should be of the range [0 - 33].
1103    // Anything above 33 (f) will not be allowed.
1104    consensus_bad_nodes_stake_threshold: Option<u64>,
1105
1106    max_jwk_votes_per_validator_per_epoch: Option<u64>,
1107    // The maximum age of a JWK in epochs before it is removed from the AuthenticatorState object.
1108    // Applied at the end of an epoch as a delta from the new epoch value, so setting this to 1
1109    // will cause the new epoch to start with JWKs from the previous epoch still valid.
1110    max_age_of_jwk_in_epochs: Option<u64>,
1111
1112    // === random beacon ===
1113    /// Maximum allowed precision loss when reducing voting weights for the
1114    /// random beacon protocol.
1115    random_beacon_reduction_allowed_delta: Option<u16>,
1116
1117    /// Minimum number of shares below which voting weights will not be reduced
1118    /// for the random beacon protocol.
1119    random_beacon_reduction_lower_bound: Option<u32>,
1120
1121    /// Consensus Round after which DKG should be aborted and randomness
1122    /// disabled for the epoch, if it hasn't already completed.
1123    random_beacon_dkg_timeout_round: Option<u32>,
1124
1125    /// Minimum interval between consecutive rounds of generated randomness.
1126    random_beacon_min_round_interval_ms: Option<u64>,
1127
1128    /// Version of the random beacon DKG protocol.
1129    /// 0 was deprecated (and currently not supported), 1 is the default
1130    /// version.
1131    random_beacon_dkg_version: Option<u64>,
1132
1133    /// The maximum serialized transaction size (in bytes) accepted by
1134    /// consensus. `consensus_max_transaction_size_bytes` should include
1135    /// space for additional metadata, on top of the `max_tx_size_bytes`
1136    /// value.
1137    consensus_max_transaction_size_bytes: Option<u64>,
1138    /// The maximum size of transactions included in a consensus block.
1139    consensus_max_transactions_in_block_bytes: Option<u64>,
1140    /// The maximum number of transactions included in a consensus block.
1141    consensus_max_num_transactions_in_block: Option<u64>,
1142
1143    /// The max number of consensus rounds a transaction can be deferred due to
1144    /// shared object congestion. Transactions will be cancelled after this
1145    /// many rounds.
1146    max_deferral_rounds_for_congestion_control: Option<u64>,
1147
1148    /// Minimum interval of commit timestamps between consecutive checkpoints.
1149    min_checkpoint_interval_ms: Option<u64>,
1150
1151    /// Version number to use for version_specific_data in `CheckpointSummary`.
1152    checkpoint_summary_version_specific_data: Option<u64>,
1153
1154    /// The max number of transactions that can be included in a single Soft
1155    /// Bundle.
1156    max_soft_bundle_size: Option<u64>,
1157
1158    /// Deprecated because of bridge removal.
1159    /// Whether to try to form bridge committee
1160    // Note: this is not a feature flag because we want to distinguish between
1161    // `None` and `Some(false)`, as committee was already finalized on Testnet.
1162    bridge_should_try_to_finalize_committee: Option<bool>,
1163
1164    /// The max accumulated txn execution cost per object in a mysticeti commit.
1165    /// Transactions in a commit will be deferred once their touch shared
1166    /// objects hit this limit. Note that if
1167    /// `max_congestion_limit_overshoot_per_commit` is set, this may be overshot
1168    /// within a single commit, but the limit will be enforced in the long run.
1169    max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1170
1171    /// Maximum number of committee (validators taking part in consensus)
1172    /// validators at any moment. We do not allow the number of committee
1173    /// validators in any epoch to go above this.
1174    max_committee_members_count: Option<u64>,
1175
1176    /// Configures the garbage collection depth for consensus. When is unset or
1177    /// `0` then the garbage collection is disabled.
1178    consensus_gc_depth: Option<u32>,
1179
1180    /// Configures the maximum number of acknowledgments to be included in a
1181    /// block. It must be reasonably larger than the number of validators
1182    /// because not all validators create their blocks at the same pace.
1183    /// Default value set to 400. (5 x expected committee size (80)).
1184    /// Applicable only to `starfish` consensus.
1185    consensus_max_acknowledgments_per_block: Option<u32>,
1186
1187    /// The maximum amount that is allowed to overshoot the congestion limit
1188    /// specified by 'max_accumulated_txn_cost_per_object_in_mysticeti_commit'
1189    /// for any single commit. Any overshoot is tracked as a debt that must
1190    /// be accounted for in subsequent commits.
1191    max_congestion_limit_overshoot_per_commit: Option<u64>,
1192}
1193
1194// feature flags
1195impl ProtocolConfig {
1196    // Add checks for feature flag support here, e.g.:
1197    // pub fn check_new_protocol_feature_supported(&self) -> Result<(), Error> {
1198    //     if self.feature_flags.new_protocol_feature_supported {
1199    //         Ok(())
1200    //     } else {
1201    //         Err(Error(format!(
1202    //             "new_protocol_feature is not supported at {:?}",
1203    //             self.version
1204    //         )))
1205    //     }
1206    // }
1207
1208    pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1209        self.feature_flags
1210            .disable_invariant_violation_check_in_swap_loc
1211    }
1212
1213    pub fn no_extraneous_module_bytes(&self) -> bool {
1214        self.feature_flags.no_extraneous_module_bytes
1215    }
1216
1217    pub fn zklogin_auth(&self) -> bool {
1218        self.feature_flags.zklogin_auth
1219    }
1220
1221    pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1222        self.feature_flags.consensus_transaction_ordering
1223    }
1224
1225    pub fn enable_jwk_consensus_updates(&self) -> bool {
1226        self.feature_flags.enable_jwk_consensus_updates
1227    }
1228
1229    // this function only exists for readability in the genesis code.
1230    pub fn create_authenticator_state_in_genesis(&self) -> bool {
1231        self.enable_jwk_consensus_updates()
1232    }
1233
1234    pub fn dkg_version(&self) -> u64 {
1235        // Version 0 was deprecated and removed, the default is 1 if not set.
1236        self.random_beacon_dkg_version.unwrap_or(1)
1237    }
1238
1239    pub fn accept_zklogin_in_multisig(&self) -> bool {
1240        self.feature_flags.accept_zklogin_in_multisig
1241    }
1242
1243    pub fn zklogin_max_epoch_upper_bound_delta(&self) -> Option<u64> {
1244        self.feature_flags.zklogin_max_epoch_upper_bound_delta
1245    }
1246
1247    pub fn hardened_otw_check(&self) -> bool {
1248        self.feature_flags.hardened_otw_check
1249    }
1250
1251    pub fn enable_poseidon(&self) -> bool {
1252        self.feature_flags.enable_poseidon
1253    }
1254
1255    pub fn enable_group_ops_native_function_msm(&self) -> bool {
1256        self.feature_flags.enable_group_ops_native_function_msm
1257    }
1258
1259    pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1260        self.feature_flags.per_object_congestion_control_mode
1261    }
1262
1263    pub fn consensus_choice(&self) -> ConsensusChoice {
1264        self.feature_flags.consensus_choice
1265    }
1266
1267    pub fn consensus_network(&self) -> ConsensusNetwork {
1268        self.feature_flags.consensus_network
1269    }
1270
1271    pub fn enable_vdf(&self) -> bool {
1272        self.feature_flags.enable_vdf
1273    }
1274
1275    pub fn passkey_auth(&self) -> bool {
1276        self.feature_flags.passkey_auth
1277    }
1278
1279    pub fn max_transaction_size_bytes(&self) -> u64 {
1280        // Provide a default value if protocol config version is too low.
1281        self.consensus_max_transaction_size_bytes
1282            .unwrap_or(256 * 1024)
1283    }
1284
1285    pub fn max_transactions_in_block_bytes(&self) -> u64 {
1286        if cfg!(msim) {
1287            256 * 1024
1288        } else {
1289            self.consensus_max_transactions_in_block_bytes
1290                .unwrap_or(512 * 1024)
1291        }
1292    }
1293
1294    pub fn max_num_transactions_in_block(&self) -> u64 {
1295        if cfg!(msim) {
1296            8
1297        } else {
1298            self.consensus_max_num_transactions_in_block.unwrap_or(512)
1299        }
1300    }
1301
1302    pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1303        self.feature_flags.rethrow_serialization_type_layout_errors
1304    }
1305
1306    pub fn relocate_event_module(&self) -> bool {
1307        self.feature_flags.relocate_event_module
1308    }
1309
1310    pub fn protocol_defined_base_fee(&self) -> bool {
1311        self.feature_flags.protocol_defined_base_fee
1312    }
1313
1314    pub fn uncompressed_g1_group_elements(&self) -> bool {
1315        self.feature_flags.uncompressed_g1_group_elements
1316    }
1317
1318    pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1319        self.feature_flags
1320            .disallow_new_modules_in_deps_only_packages
1321    }
1322
1323    pub fn native_charging_v2(&self) -> bool {
1324        self.feature_flags.native_charging_v2
1325    }
1326
1327    pub fn consensus_round_prober(&self) -> bool {
1328        self.feature_flags.consensus_round_prober
1329    }
1330
1331    pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1332        self.feature_flags
1333            .consensus_distributed_vote_scoring_strategy
1334    }
1335
1336    pub fn gc_depth(&self) -> u32 {
1337        if cfg!(msim) {
1338            // exercise a very low gc_depth
1339            min(5, self.consensus_gc_depth.unwrap_or(0))
1340        } else {
1341            self.consensus_gc_depth.unwrap_or(0)
1342        }
1343    }
1344
1345    pub fn consensus_linearize_subdag_v2(&self) -> bool {
1346        let res = self.feature_flags.consensus_linearize_subdag_v2;
1347        assert!(
1348            !res || self.gc_depth() > 0,
1349            "The consensus linearize sub dag V2 requires GC to be enabled"
1350        );
1351        res
1352    }
1353
1354    pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1355        self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1356    }
1357
1358    pub fn variant_nodes(&self) -> bool {
1359        self.feature_flags.variant_nodes
1360    }
1361
1362    pub fn consensus_smart_ancestor_selection(&self) -> bool {
1363        self.feature_flags.consensus_smart_ancestor_selection
1364    }
1365
1366    pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1367        self.feature_flags
1368            .consensus_round_prober_probe_accepted_rounds
1369    }
1370
1371    pub fn consensus_zstd_compression(&self) -> bool {
1372        self.feature_flags.consensus_zstd_compression
1373    }
1374
1375    pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1376        self.feature_flags
1377            .congestion_control_min_free_execution_slot
1378    }
1379
1380    pub fn accept_passkey_in_multisig(&self) -> bool {
1381        self.feature_flags.accept_passkey_in_multisig
1382    }
1383
1384    pub fn consensus_batched_block_sync(&self) -> bool {
1385        self.feature_flags.consensus_batched_block_sync
1386    }
1387
1388    /// Check if the gas price feedback mechanism (which is used for
1389    /// transactions cancelled due to shared object congestion) is enabled
1390    pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1391        self.feature_flags
1392            .congestion_control_gas_price_feedback_mechanism
1393    }
1394
1395    pub fn validate_identifier_inputs(&self) -> bool {
1396        self.feature_flags.validate_identifier_inputs
1397    }
1398
1399    pub fn minimize_child_object_mutations(&self) -> bool {
1400        self.feature_flags.minimize_child_object_mutations
1401    }
1402
1403    pub fn dependency_linkage_error(&self) -> bool {
1404        self.feature_flags.dependency_linkage_error
1405    }
1406
1407    pub fn additional_multisig_checks(&self) -> bool {
1408        self.feature_flags.additional_multisig_checks
1409    }
1410
1411    pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1412        // TODO: this will eventually be the max of some number of other
1413        // parameters.
1414        0
1415    }
1416
1417    pub fn normalize_ptb_arguments(&self) -> bool {
1418        self.feature_flags.normalize_ptb_arguments
1419    }
1420
1421    pub fn select_committee_from_eligible_validators(&self) -> bool {
1422        let res = self.feature_flags.select_committee_from_eligible_validators;
1423        assert!(
1424            !res || (self.protocol_defined_base_fee()
1425                && self.max_committee_members_count_as_option().is_some()),
1426            "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1427        );
1428        res
1429    }
1430
1431    pub fn track_non_committee_eligible_validators(&self) -> bool {
1432        self.feature_flags.track_non_committee_eligible_validators
1433    }
1434
1435    pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1436        let res = self
1437            .feature_flags
1438            .select_committee_supporting_next_epoch_version;
1439        assert!(
1440            !res || (self.track_non_committee_eligible_validators()
1441                && self.select_committee_from_eligible_validators()),
1442            "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1443        );
1444        res
1445    }
1446
1447    pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1448        let res = self
1449            .feature_flags
1450            .consensus_median_timestamp_with_checkpoint_enforcement;
1451        assert!(
1452            !res || self.gc_depth() > 0,
1453            "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1454        );
1455        res
1456    }
1457
1458    pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1459        self.feature_flags
1460            .consensus_commit_transactions_only_for_traversed_headers
1461    }
1462
1463    /// Check whether congestion limit overshoot is enabled in the gas price
1464    /// feedback mechanism.
1465    pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1466        self.feature_flags
1467            .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1468    }
1469
1470    /// Check whether a separate gas price feedback mechanism is used for
1471    /// randomness transactions.
1472    pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1473        self.feature_flags
1474            .separate_gas_price_feedback_mechanism_for_randomness
1475    }
1476}
1477
1478#[cfg(not(msim))]
1479static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1480
1481// Use a thread local in sim tests for test isolation.
1482#[cfg(msim)]
1483thread_local! {
1484    static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1485}
1486
1487// Instantiations for each protocol version.
1488impl ProtocolConfig {
1489    /// Get the value ProtocolConfig that are in effect during the given
1490    /// protocol version.
1491    pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1492        // ProtocolVersion can be deserialized so we need to check it here as well.
1493        assert!(
1494            version >= ProtocolVersion::MIN,
1495            "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1496            version,
1497            ProtocolVersion::MIN.0,
1498        );
1499        assert!(
1500            version <= ProtocolVersion::MAX_ALLOWED,
1501            "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1502            version,
1503            ProtocolVersion::MAX_ALLOWED.0,
1504        );
1505
1506        let mut ret = Self::get_for_version_impl(version, chain);
1507        ret.version = version;
1508
1509        ret = CONFIG_OVERRIDE.with(|ovr| {
1510            if let Some(override_fn) = &*ovr.borrow() {
1511                warn!(
1512                    "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1513                );
1514                override_fn(version, ret)
1515            } else {
1516                ret
1517            }
1518        });
1519
1520        if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1521            warn!(
1522                "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1523            );
1524            let overrides: ProtocolConfigOptional =
1525                serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1526                    .expect("failed to parse ProtocolConfig override env variables");
1527            overrides.apply_to(&mut ret);
1528        }
1529
1530        ret
1531    }
1532
1533    /// Get the value ProtocolConfig that are in effect during the given
1534    /// protocol version. Or none if the version is not supported.
1535    pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1536        if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1537            let mut ret = Self::get_for_version_impl(version, chain);
1538            ret.version = version;
1539            Some(ret)
1540        } else {
1541            None
1542        }
1543    }
1544
1545    #[cfg(not(msim))]
1546    pub fn poison_get_for_min_version() {
1547        POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1548    }
1549
1550    #[cfg(not(msim))]
1551    fn load_poison_get_for_min_version() -> bool {
1552        POISON_VERSION_METHODS.load(Ordering::Relaxed)
1553    }
1554
1555    #[cfg(msim)]
1556    pub fn poison_get_for_min_version() {
1557        POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1558    }
1559
1560    #[cfg(msim)]
1561    fn load_poison_get_for_min_version() -> bool {
1562        POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1563    }
1564
1565    pub fn convert_type_argument_error(&self) -> bool {
1566        self.feature_flags.convert_type_argument_error
1567    }
1568
1569    /// Convenience to get the constants at the current minimum supported
1570    /// version. Mainly used by client code that may not yet be
1571    /// protocol-version aware.
1572    pub fn get_for_min_version() -> Self {
1573        if Self::load_poison_get_for_min_version() {
1574            panic!("get_for_min_version called on validator");
1575        }
1576        ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1577    }
1578
1579    /// CAREFUL! - You probably want to use `get_for_version` instead.
1580    ///
1581    /// Convenience to get the constants at the current maximum supported
1582    /// version. Mainly used by genesis. Note well that this function uses
1583    /// the max version supported locally by the node, which is not
1584    /// necessarily the current version of the network. ALSO, this function
1585    /// disregards chain specific config (by using Chain::Unknown), thereby
1586    /// potentially returning a protocol config that is incorrect for some
1587    /// feature flags. Definitely safe for testing and for protocol version
1588    /// 11 and prior.
1589    #[expect(non_snake_case)]
1590    pub fn get_for_max_version_UNSAFE() -> Self {
1591        if Self::load_poison_get_for_min_version() {
1592            panic!("get_for_max_version_UNSAFE called on validator");
1593        }
1594        ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1595    }
1596
1597    fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1598        #[cfg(msim)]
1599        {
1600            // populate the fake simulator version # with a different base tx cost.
1601            if version > ProtocolVersion::MAX {
1602                let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1603                config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1604                return config;
1605            }
1606        }
1607
1608        // IMPORTANT: Never modify the value of any constant for a pre-existing protocol
1609        // version. To change the values here you must create a new protocol
1610        // version with the new values!
1611        let mut cfg = Self {
1612            version,
1613
1614            feature_flags: Default::default(),
1615
1616            max_tx_size_bytes: Some(128 * 1024),
1617            // We need this number to be at least 100x less than
1618            // `max_serialized_tx_effects_size_bytes`otherwise effects can be huge
1619            max_input_objects: Some(2048),
1620            max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1621            max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1622            max_gas_payment_objects: Some(256),
1623            max_modules_in_publish: Some(64),
1624            max_package_dependencies: Some(32),
1625            max_arguments: Some(512),
1626            max_type_arguments: Some(16),
1627            max_type_argument_depth: Some(16),
1628            max_pure_argument_size: Some(16 * 1024),
1629            max_programmable_tx_commands: Some(1024),
1630            move_binary_format_version: Some(7),
1631            min_move_binary_format_version: Some(6),
1632            binary_module_handles: Some(100),
1633            binary_struct_handles: Some(300),
1634            binary_function_handles: Some(1500),
1635            binary_function_instantiations: Some(750),
1636            binary_signatures: Some(1000),
1637            binary_constant_pool: Some(4000),
1638            binary_identifiers: Some(10000),
1639            binary_address_identifiers: Some(100),
1640            binary_struct_defs: Some(200),
1641            binary_struct_def_instantiations: Some(100),
1642            binary_function_defs: Some(1000),
1643            binary_field_handles: Some(500),
1644            binary_field_instantiations: Some(250),
1645            binary_friend_decls: Some(100),
1646            binary_enum_defs: None,
1647            binary_enum_def_instantiations: None,
1648            binary_variant_handles: None,
1649            binary_variant_instantiation_handles: None,
1650            max_move_object_size: Some(250 * 1024),
1651            max_move_package_size: Some(100 * 1024),
1652            max_publish_or_upgrade_per_ptb: Some(5),
1653            // max gas budget is in NANOS and an absolute value 50IOTA
1654            max_tx_gas: Some(50_000_000_000),
1655            max_gas_price: Some(100_000),
1656            max_gas_computation_bucket: Some(5_000_000),
1657            max_loop_depth: Some(5),
1658            max_generic_instantiation_length: Some(32),
1659            max_function_parameters: Some(128),
1660            max_basic_blocks: Some(1024),
1661            max_value_stack_size: Some(1024),
1662            max_type_nodes: Some(256),
1663            max_push_size: Some(10000),
1664            max_struct_definitions: Some(200),
1665            max_function_definitions: Some(1000),
1666            max_fields_in_struct: Some(32),
1667            max_dependency_depth: Some(100),
1668            max_num_event_emit: Some(1024),
1669            max_num_new_move_object_ids: Some(2048),
1670            max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1671            max_num_deleted_move_object_ids: Some(2048),
1672            max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1673            max_num_transferred_move_object_ids: Some(2048),
1674            max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1675            max_event_emit_size: Some(250 * 1024),
1676            max_move_vector_len: Some(256 * 1024),
1677            max_type_to_layout_nodes: None,
1678            max_ptb_value_size: None,
1679
1680            max_back_edges_per_function: Some(10_000),
1681            max_back_edges_per_module: Some(10_000),
1682
1683            max_verifier_meter_ticks_per_function: Some(16_000_000),
1684
1685            max_meter_ticks_per_module: Some(16_000_000),
1686            max_meter_ticks_per_package: Some(16_000_000),
1687
1688            object_runtime_max_num_cached_objects: Some(1000),
1689            object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
1690            object_runtime_max_num_store_entries: Some(1000),
1691            object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
1692            // min gas budget is in NANOS and an absolute value 1000 NANOS or 0.000001IOTA
1693            base_tx_cost_fixed: Some(1_000),
1694            package_publish_cost_fixed: Some(1_000),
1695            base_tx_cost_per_byte: Some(0),
1696            package_publish_cost_per_byte: Some(80),
1697            obj_access_cost_read_per_byte: Some(15),
1698            obj_access_cost_mutate_per_byte: Some(40),
1699            obj_access_cost_delete_per_byte: Some(40),
1700            obj_access_cost_verify_per_byte: Some(200),
1701            obj_data_cost_refundable: Some(100),
1702            obj_metadata_cost_non_refundable: Some(50),
1703            gas_model_version: Some(1),
1704            storage_rebate_rate: Some(10000),
1705            // Change reward slashing rate to 100%.
1706            reward_slashing_rate: Some(10000),
1707            storage_gas_price: Some(76),
1708            base_gas_price: None,
1709            // The initial subsidy (target reward) for validators per epoch.
1710            // Refer to the IOTA tokenomics for the origin of this value.
1711            validator_target_reward: Some(767_000 * 1_000_000_000),
1712            max_transactions_per_checkpoint: Some(10_000),
1713            max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
1714
1715            // For now, perform upgrades with a bare quorum of validators.
1716            buffer_stake_for_protocol_upgrade_bps: Some(5000),
1717
1718            // === Native Function Costs ===
1719            // `address` module
1720            // Cost params for the Move native function `address::from_bytes(bytes: vector<u8>)`
1721            address_from_bytes_cost_base: Some(52),
1722            // Cost params for the Move native function `address::to_u256(address): u256`
1723            address_to_u256_cost_base: Some(52),
1724            // Cost params for the Move native function `address::from_u256(u256): address`
1725            address_from_u256_cost_base: Some(52),
1726
1727            // `config` module
1728            // Cost params for the Move native function `read_setting_impl``
1729            config_read_setting_impl_cost_base: Some(100),
1730            config_read_setting_impl_cost_per_byte: Some(40),
1731
1732            // `dynamic_field` module
1733            // Cost params for the Move native function `hash_type_and_key<K: copy + drop +
1734            // store>(parent: address, k: K): address`
1735            dynamic_field_hash_type_and_key_cost_base: Some(100),
1736            dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
1737            dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
1738            dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
1739            // Cost params for the Move native function `add_child_object<Child: key>(parent:
1740            // address, child: Child)`
1741            dynamic_field_add_child_object_cost_base: Some(100),
1742            dynamic_field_add_child_object_type_cost_per_byte: Some(10),
1743            dynamic_field_add_child_object_value_cost_per_byte: Some(10),
1744            dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
1745            // Cost params for the Move native function `borrow_child_object_mut<Child: key>(parent:
1746            // &mut UID, id: address): &mut Child`
1747            dynamic_field_borrow_child_object_cost_base: Some(100),
1748            dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
1749            dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
1750            // Cost params for the Move native function `remove_child_object<Child: key>(parent:
1751            // address, id: address): Child`
1752            dynamic_field_remove_child_object_cost_base: Some(100),
1753            dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
1754            dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
1755            // Cost params for the Move native function `has_child_object(parent: address, id:
1756            // address): bool`
1757            dynamic_field_has_child_object_cost_base: Some(100),
1758            // Cost params for the Move native function `has_child_object_with_ty<Child:
1759            // key>(parent: address, id: address): bool`
1760            dynamic_field_has_child_object_with_ty_cost_base: Some(100),
1761            dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
1762            dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
1763
1764            // `event` module
1765            // Cost params for the Move native function `event::emit<T: copy + drop>(event: T)`
1766            event_emit_cost_base: Some(52),
1767            event_emit_value_size_derivation_cost_per_byte: Some(2),
1768            event_emit_tag_size_derivation_cost_per_byte: Some(5),
1769            event_emit_output_cost_per_byte: Some(10),
1770
1771            //  `object` module
1772            // Cost params for the Move native function `borrow_uid<T: key>(obj: &T): &UID`
1773            object_borrow_uid_cost_base: Some(52),
1774            // Cost params for the Move native function `delete_impl(id: address)`
1775            object_delete_impl_cost_base: Some(52),
1776            // Cost params for the Move native function `record_new_uid(id: address)`
1777            object_record_new_uid_cost_base: Some(52),
1778
1779            // `transfer` module
1780            // Cost params for the Move native function `transfer_impl<T: key>(obj: T, recipient:
1781            // address)`
1782            transfer_transfer_internal_cost_base: Some(52),
1783            // Cost params for the Move native function `freeze_object<T: key>(obj: T)`
1784            transfer_freeze_object_cost_base: Some(52),
1785            // Cost params for the Move native function `share_object<T: key>(obj: T)`
1786            transfer_share_object_cost_base: Some(52),
1787            transfer_receive_object_cost_base: Some(52),
1788
1789            // `tx_context` module
1790            // Cost params for the Move native function `transfer_impl<T: key>(obj: T, recipient:
1791            // address)`
1792            tx_context_derive_id_cost_base: Some(52),
1793
1794            // `types` module
1795            // Cost params for the Move native function `is_one_time_witness<T: drop>(_: &T): bool`
1796            types_is_one_time_witness_cost_base: Some(52),
1797            types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
1798            types_is_one_time_witness_type_cost_per_byte: Some(2),
1799
1800            // `validator` module
1801            // Cost params for the Move native function `validate_metadata_bcs(metadata:
1802            // vector<u8>)`
1803            validator_validate_metadata_cost_base: Some(52),
1804            validator_validate_metadata_data_cost_per_byte: Some(2),
1805
1806            // Crypto
1807            crypto_invalid_arguments_cost: Some(100),
1808            // bls12381::bls12381_min_pk_verify
1809            bls12381_bls12381_min_sig_verify_cost_base: Some(52),
1810            bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
1811            bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
1812
1813            // bls12381::bls12381_min_pk_verify
1814            bls12381_bls12381_min_pk_verify_cost_base: Some(52),
1815            bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
1816            bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
1817
1818            // ecdsa_k1::ecrecover
1819            ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
1820            ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1821            ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1822            ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
1823            ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1824            ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
1825
1826            // ecdsa_k1::decompress_pubkey
1827            ecdsa_k1_decompress_pubkey_cost_base: Some(52),
1828
1829            // ecdsa_k1::secp256k1_verify
1830            ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
1831            ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
1832            ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
1833            ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
1834            ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
1835            ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
1836
1837            // ecdsa_r1::ecrecover
1838            ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
1839            ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1840            ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1841            ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
1842            ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1843            ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
1844
1845            // ecdsa_r1::secp256k1_verify
1846            ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
1847            ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
1848            ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
1849            ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
1850            ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
1851            ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
1852
1853            // ecvrf::verify
1854            ecvrf_ecvrf_verify_cost_base: Some(52),
1855            ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
1856            ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
1857
1858            // ed25519
1859            ed25519_ed25519_verify_cost_base: Some(52),
1860            ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
1861            ed25519_ed25519_verify_msg_cost_per_block: Some(2),
1862
1863            // groth16::prepare_verifying_key
1864            groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
1865            groth16_prepare_verifying_key_bn254_cost_base: Some(52),
1866
1867            // groth16::verify_groth16_proof_internal
1868            groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
1869            groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
1870            groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
1871            groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
1872            groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
1873
1874            // hash::blake2b256
1875            hash_blake2b256_cost_base: Some(52),
1876            hash_blake2b256_data_cost_per_byte: Some(2),
1877            hash_blake2b256_data_cost_per_block: Some(2),
1878            // hash::keccak256
1879            hash_keccak256_cost_base: Some(52),
1880            hash_keccak256_data_cost_per_byte: Some(2),
1881            hash_keccak256_data_cost_per_block: Some(2),
1882
1883            poseidon_bn254_cost_base: None,
1884            poseidon_bn254_cost_per_block: None,
1885
1886            // hmac::hmac_sha3_256
1887            hmac_hmac_sha3_256_cost_base: Some(52),
1888            hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
1889            hmac_hmac_sha3_256_input_cost_per_block: Some(2),
1890
1891            // group ops
1892            group_ops_bls12381_decode_scalar_cost: Some(52),
1893            group_ops_bls12381_decode_g1_cost: Some(52),
1894            group_ops_bls12381_decode_g2_cost: Some(52),
1895            group_ops_bls12381_decode_gt_cost: Some(52),
1896            group_ops_bls12381_scalar_add_cost: Some(52),
1897            group_ops_bls12381_g1_add_cost: Some(52),
1898            group_ops_bls12381_g2_add_cost: Some(52),
1899            group_ops_bls12381_gt_add_cost: Some(52),
1900            group_ops_bls12381_scalar_sub_cost: Some(52),
1901            group_ops_bls12381_g1_sub_cost: Some(52),
1902            group_ops_bls12381_g2_sub_cost: Some(52),
1903            group_ops_bls12381_gt_sub_cost: Some(52),
1904            group_ops_bls12381_scalar_mul_cost: Some(52),
1905            group_ops_bls12381_g1_mul_cost: Some(52),
1906            group_ops_bls12381_g2_mul_cost: Some(52),
1907            group_ops_bls12381_gt_mul_cost: Some(52),
1908            group_ops_bls12381_scalar_div_cost: Some(52),
1909            group_ops_bls12381_g1_div_cost: Some(52),
1910            group_ops_bls12381_g2_div_cost: Some(52),
1911            group_ops_bls12381_gt_div_cost: Some(52),
1912            group_ops_bls12381_g1_hash_to_base_cost: Some(52),
1913            group_ops_bls12381_g2_hash_to_base_cost: Some(52),
1914            group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
1915            group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
1916            group_ops_bls12381_g1_msm_base_cost: Some(52),
1917            group_ops_bls12381_g2_msm_base_cost: Some(52),
1918            group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
1919            group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
1920            group_ops_bls12381_msm_max_len: Some(32),
1921            group_ops_bls12381_pairing_cost: Some(52),
1922            group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
1923            group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
1924            group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
1925            group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
1926            group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
1927
1928            // zklogin::check_zklogin_id
1929            check_zklogin_id_cost_base: Some(200),
1930            // zklogin::check_zklogin_issuer
1931            check_zklogin_issuer_cost_base: Some(200),
1932
1933            vdf_verify_vdf_cost: None,
1934            vdf_hash_to_input_cost: None,
1935
1936            bcs_per_byte_serialized_cost: Some(2),
1937            bcs_legacy_min_output_size_cost: Some(1),
1938            bcs_failure_cost: Some(52),
1939            hash_sha2_256_base_cost: Some(52),
1940            hash_sha2_256_per_byte_cost: Some(2),
1941            hash_sha2_256_legacy_min_input_len_cost: Some(1),
1942            hash_sha3_256_base_cost: Some(52),
1943            hash_sha3_256_per_byte_cost: Some(2),
1944            hash_sha3_256_legacy_min_input_len_cost: Some(1),
1945            type_name_get_base_cost: Some(52),
1946            type_name_get_per_byte_cost: Some(2),
1947            string_check_utf8_base_cost: Some(52),
1948            string_check_utf8_per_byte_cost: Some(2),
1949            string_is_char_boundary_base_cost: Some(52),
1950            string_sub_string_base_cost: Some(52),
1951            string_sub_string_per_byte_cost: Some(2),
1952            string_index_of_base_cost: Some(52),
1953            string_index_of_per_byte_pattern_cost: Some(2),
1954            string_index_of_per_byte_searched_cost: Some(2),
1955            vector_empty_base_cost: Some(52),
1956            vector_length_base_cost: Some(52),
1957            vector_push_back_base_cost: Some(52),
1958            vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
1959            vector_borrow_base_cost: Some(52),
1960            vector_pop_back_base_cost: Some(52),
1961            vector_destroy_empty_base_cost: Some(52),
1962            vector_swap_base_cost: Some(52),
1963            debug_print_base_cost: Some(52),
1964            debug_print_stack_trace_base_cost: Some(52),
1965
1966            max_size_written_objects: Some(5 * 1000 * 1000),
1967            // max size of written objects during a system TXn to allow for larger writes
1968            // akin to `max_size_written_objects` but for system TXns
1969            max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
1970
1971            // Limits the length of a Move identifier
1972            max_move_identifier_len: Some(128),
1973            max_move_value_depth: Some(128),
1974            max_move_enum_variants: None,
1975
1976            gas_rounding_step: Some(1_000),
1977
1978            execution_version: Some(1),
1979
1980            // We maintain the same total size limit for events, but increase the number of
1981            // events that can be emitted.
1982            max_event_emit_size_total: Some(
1983                256 /* former event count limit */ * 250 * 1024, // size limit per event
1984            ),
1985
1986            // Taking a baby step approach, we consider only 20% by stake as bad nodes so we
1987            // have a 80% by stake of nodes participating in the leader committee. That
1988            // allow us for more redundancy in case we have validators
1989            // under performing - since the responsibility is shared
1990            // amongst more nodes. We can increase that once we do have
1991            // higher confidence.
1992            consensus_bad_nodes_stake_threshold: Some(20),
1993
1994            // Max of 10 votes per hour.
1995            max_jwk_votes_per_validator_per_epoch: Some(240),
1996
1997            max_age_of_jwk_in_epochs: Some(1),
1998
1999            consensus_max_transaction_size_bytes: Some(256 * 1024), // 256KB
2000
2001            // Assume 1KB per transaction and 500 transactions per block.
2002            consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2003
2004            random_beacon_reduction_allowed_delta: Some(800),
2005
2006            random_beacon_reduction_lower_bound: Some(1000),
2007            random_beacon_dkg_timeout_round: Some(3000),
2008            random_beacon_min_round_interval_ms: Some(500),
2009
2010            random_beacon_dkg_version: Some(1),
2011
2012            // Assume 20_000 TPS * 5% max stake per validator / (minimum) 4 blocks per round
2013            // = 250 transactions per block maximum Using a higher limit
2014            // that is 512, to account for bursty traffic and system transactions.
2015            consensus_max_num_transactions_in_block: Some(512),
2016
2017            max_deferral_rounds_for_congestion_control: Some(10),
2018
2019            min_checkpoint_interval_ms: Some(200),
2020
2021            checkpoint_summary_version_specific_data: Some(1),
2022
2023            max_soft_bundle_size: Some(5),
2024
2025            bridge_should_try_to_finalize_committee: None,
2026
2027            max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2028
2029            max_committee_members_count: None,
2030
2031            consensus_gc_depth: None,
2032
2033            consensus_max_acknowledgments_per_block: None,
2034
2035            max_congestion_limit_overshoot_per_commit: None,
2036            // When adding a new constant, set it to None in the earliest version, like this:
2037            // new_constant: None,
2038        };
2039
2040        cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2041
2042        // MoveVM related flags
2043        {
2044            cfg.feature_flags
2045                .disable_invariant_violation_check_in_swap_loc = true;
2046            cfg.feature_flags.no_extraneous_module_bytes = true;
2047            cfg.feature_flags.hardened_otw_check = true;
2048            cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2049        }
2050
2051        // zkLogin related flags
2052        {
2053            cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2054        }
2055
2056        // Enable Mysticeti on mainnet.
2057        cfg.feature_flags.consensus_choice = ConsensusChoice::Mysticeti;
2058        // Use tonic networking for Mysticeti.
2059        cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2060
2061        cfg.feature_flags.per_object_congestion_control_mode =
2062            PerObjectCongestionControlMode::TotalTxCount;
2063
2064        // Do not allow bridge committee to finalize on mainnet.
2065        cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2066
2067        // Devnet
2068        if chain != Chain::Mainnet && chain != Chain::Testnet {
2069            cfg.feature_flags.enable_poseidon = true;
2070            cfg.poseidon_bn254_cost_base = Some(260);
2071            cfg.poseidon_bn254_cost_per_block = Some(10);
2072
2073            cfg.feature_flags.enable_group_ops_native_function_msm = true;
2074
2075            cfg.feature_flags.enable_vdf = true;
2076            // Set to 30x and 2x the cost of a signature verification for now. This
2077            // should be updated along with other native crypto functions.
2078            cfg.vdf_verify_vdf_cost = Some(1500);
2079            cfg.vdf_hash_to_input_cost = Some(100);
2080
2081            cfg.feature_flags.passkey_auth = true;
2082        }
2083
2084        for cur in 2..=version.0 {
2085            match cur {
2086                1 => unreachable!(),
2087                // version 2 is a new framework version but with no config changes
2088                2 => {}
2089                3 => {
2090                    cfg.feature_flags.relocate_event_module = true;
2091                }
2092                4 => {
2093                    cfg.max_type_to_layout_nodes = Some(512);
2094                }
2095                5 => {
2096                    cfg.feature_flags.protocol_defined_base_fee = true;
2097                    cfg.base_gas_price = Some(1000);
2098
2099                    cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2100                    cfg.feature_flags.convert_type_argument_error = true;
2101                    cfg.feature_flags.native_charging_v2 = true;
2102
2103                    if chain != Chain::Mainnet && chain != Chain::Testnet {
2104                        cfg.feature_flags.uncompressed_g1_group_elements = true;
2105                    }
2106
2107                    cfg.gas_model_version = Some(2);
2108
2109                    cfg.poseidon_bn254_cost_per_block = Some(388);
2110
2111                    cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2112                    cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2113                    cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2114                    cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2115                    cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2116                    cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2117                    cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2118                    cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2119
2120                    // Manually changed to be "under cost"
2121                    cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2122                    cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2123                    cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2124                    cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2125
2126                    cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2127                    cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2128                    cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2129                    cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2130                        Some(8213);
2131                    cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2132                    cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2133                        Some(9484);
2134
2135                    cfg.hash_keccak256_cost_base = Some(10);
2136                    cfg.hash_blake2b256_cost_base = Some(10);
2137
2138                    // group ops
2139                    cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2140                    cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2141                    cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2142                    cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2143
2144                    cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2145                    cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2146                    cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2147                    cfg.group_ops_bls12381_gt_add_cost = Some(188);
2148
2149                    cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2150                    cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2151                    cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2152                    cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2153
2154                    cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2155                    cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2156                    cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2157                    cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2158
2159                    cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2160                    cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2161                    cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2162                    cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2163
2164                    cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2165                    cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2166
2167                    cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2168                    cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2169                    cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2170                    cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2171
2172                    cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2173                    cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2174                    cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2175                    cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2176                    cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2177
2178                    cfg.group_ops_bls12381_pairing_cost = Some(26897);
2179
2180                    cfg.validator_validate_metadata_cost_base = Some(20000);
2181
2182                    cfg.max_committee_members_count = Some(50);
2183                }
2184                6 => {
2185                    cfg.max_ptb_value_size = Some(1024 * 1024);
2186                }
2187                7 => {
2188                    // version 7 is a new framework version but with no config
2189                    // changes
2190                }
2191                8 => {
2192                    cfg.feature_flags.variant_nodes = true;
2193
2194                    if chain != Chain::Mainnet {
2195                        // Enable round prober in consensus.
2196                        cfg.feature_flags.consensus_round_prober = true;
2197                        // Enable distributed vote scoring.
2198                        cfg.feature_flags
2199                            .consensus_distributed_vote_scoring_strategy = true;
2200                        cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2201                        // Enable smart ancestor selection for testnet
2202                        cfg.feature_flags.consensus_smart_ancestor_selection = true;
2203                        // Enable probing for accepted rounds in round prober for testnet
2204                        cfg.feature_flags
2205                            .consensus_round_prober_probe_accepted_rounds = true;
2206                        // Enable zstd compression for consensus in testnet
2207                        cfg.feature_flags.consensus_zstd_compression = true;
2208                        // Assuming a round rate of max 15/sec, then using a gc depth of 60 allow
2209                        // blocks within a window of ~4 seconds
2210                        // to be included before be considered garbage collected.
2211                        cfg.consensus_gc_depth = Some(60);
2212                    }
2213
2214                    // Enable min_free_execution_slot for the shared object congestion tracker in
2215                    // devnet.
2216                    if chain != Chain::Testnet && chain != Chain::Mainnet {
2217                        cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2218                    }
2219                }
2220                9 => {
2221                    if chain != Chain::Mainnet {
2222                        // Disable smart ancestor selection in the testnet and devnet.
2223                        cfg.feature_flags.consensus_smart_ancestor_selection = false;
2224                    }
2225
2226                    // Enable zstd compression for consensus
2227                    cfg.feature_flags.consensus_zstd_compression = true;
2228
2229                    // Enable passkey in multisig in devnet.
2230                    if chain != Chain::Testnet && chain != Chain::Mainnet {
2231                        cfg.feature_flags.accept_passkey_in_multisig = true;
2232                    }
2233
2234                    // this flag is now deprecated because of the bridge removal.
2235                    cfg.bridge_should_try_to_finalize_committee = None;
2236                }
2237                10 => {
2238                    // Enable min_free_execution_slot for the shared object congestion tracker in
2239                    // all networks.
2240                    cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2241
2242                    // Increase the committee size to 80 on all networks.
2243                    cfg.max_committee_members_count = Some(80);
2244
2245                    // Enable round prober in consensus.
2246                    cfg.feature_flags.consensus_round_prober = true;
2247                    // Enable probing for accepted rounds in round.
2248                    cfg.feature_flags
2249                        .consensus_round_prober_probe_accepted_rounds = true;
2250                    // Enable distributed vote scoring.
2251                    cfg.feature_flags
2252                        .consensus_distributed_vote_scoring_strategy = true;
2253                    // Enable the new consensus commit rule.
2254                    cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2255
2256                    // Enable consensus garbage collection
2257                    // Assuming a round rate of max 15/sec, then using a gc depth of 60 allow
2258                    // blocks within a window of ~4 seconds
2259                    // to be included before be considered garbage collected.
2260                    cfg.consensus_gc_depth = Some(60);
2261
2262                    // Enable minimized child object mutation counting.
2263                    cfg.feature_flags.minimize_child_object_mutations = true;
2264
2265                    if chain != Chain::Mainnet {
2266                        // Enable batched block sync in devnet and testnet.
2267                        cfg.feature_flags.consensus_batched_block_sync = true;
2268                    }
2269
2270                    if chain != Chain::Testnet && chain != Chain::Mainnet {
2271                        // Enable the gas price feedback mechanism (which is used for
2272                        // transactions cancelled due to shared object congestion) in devnet
2273                        cfg.feature_flags
2274                            .congestion_control_gas_price_feedback_mechanism = true;
2275                    }
2276
2277                    cfg.feature_flags.validate_identifier_inputs = true;
2278                    cfg.feature_flags.dependency_linkage_error = true;
2279                    cfg.feature_flags.additional_multisig_checks = true;
2280                }
2281                11 => {
2282                    // version 11 is a new framework version but with no config
2283                    // changes
2284                }
2285                12 => {
2286                    // Enable the gas price feedback mechanism for transactions
2287                    // cancelled due to congestion in all networks
2288                    cfg.feature_flags
2289                        .congestion_control_gas_price_feedback_mechanism = true;
2290
2291                    // Enable normalization of PTB arguments in all networks.
2292                    cfg.feature_flags.normalize_ptb_arguments = true;
2293                }
2294                13 => {
2295                    // Enable selecting committee based on eligible active validators on all
2296                    // networks.
2297                    cfg.feature_flags.select_committee_from_eligible_validators = true;
2298                    // Enable tracking non-committee eligible active
2299                    // validators on all networks.
2300                    cfg.feature_flags.track_non_committee_eligible_validators = true;
2301
2302                    if chain != Chain::Testnet && chain != Chain::Mainnet {
2303                        // Enable selecting committee only from active validators that next epoch
2304                        // version and issued valid AuthorityCapabilities notification in devnet.
2305                        cfg.feature_flags
2306                            .select_committee_supporting_next_epoch_version = true;
2307                    }
2308                }
2309                14 => {
2310                    // Enable batched block sync for mainnet.
2311                    cfg.feature_flags.consensus_batched_block_sync = true;
2312
2313                    if chain != Chain::Mainnet {
2314                        // Enable median-based commit timestamp calculation in consensus and
2315                        // enforce checkpoint timestamp monotonicity for testnet.
2316                        cfg.feature_flags
2317                            .consensus_median_timestamp_with_checkpoint_enforcement = true;
2318                        // Enable selecting committee only from active validators that support the
2319                        // next epoch's version and issued valid AuthorityCapabilities notification
2320                        // in testnet.
2321                        cfg.feature_flags
2322                            .select_committee_supporting_next_epoch_version = true;
2323                    }
2324                    if chain != Chain::Testnet && chain != Chain::Mainnet {
2325                        // Switch consensus protocol to Starfish in devnet
2326                        cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2327                    }
2328                }
2329                15 => {
2330                    if chain != Chain::Mainnet && chain != Chain::Testnet {
2331                        // Enable overshoot of 100 in congestion control. This allows bursts of
2332                        // shared object transactions up to 10 times the average allowable
2333                        // load set by `max_accumulated_txn_cost_per_object_in_mysticeti_commit`.
2334                        cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2335                    }
2336                }
2337                16 => {
2338                    // Enable selecting committee only from active validators that support the
2339                    // next epoch's version and issued valid AuthorityCapabilities notification.
2340                    cfg.feature_flags
2341                        .select_committee_supporting_next_epoch_version = true;
2342                    // Enable committing transactions only for traversed headers in Starfish
2343                    cfg.feature_flags
2344                        .consensus_commit_transactions_only_for_traversed_headers = true;
2345                }
2346                17 => {
2347                    // Increase the committee size to 100 on all networks.
2348                    cfg.max_committee_members_count = Some(100);
2349                }
2350                18 => {
2351                    if chain != Chain::Mainnet {
2352                        // Enable passkey authentication support in testnet.
2353                        cfg.feature_flags.passkey_auth = true;
2354                    }
2355                }
2356                19 => {
2357                    if chain != Chain::Testnet && chain != Chain::Mainnet {
2358                        // Enable congestion limit overshoot in the gas price feedback
2359                        // mechanism on devnet.
2360                        cfg.feature_flags
2361                            .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2362                        // Enable a separate gas price feedback mechanism for transactions using
2363                        // randomness on devnet.
2364                        cfg.feature_flags
2365                            .separate_gas_price_feedback_mechanism_for_randomness = true;
2366                    }
2367                }
2368                // Use this template when making changes:
2369                //
2370                //     // modify an existing constant.
2371                //     move_binary_format_version: Some(7),
2372                //
2373                //     // Add a new constant (which is set to None in prior versions).
2374                //     new_constant: Some(new_value),
2375                //
2376                //     // Remove a constant (ensure that it is never accessed during this version).
2377                //     max_move_object_size: None,
2378                _ => panic!("unsupported version {version:?}"),
2379            }
2380        }
2381        cfg
2382    }
2383
2384    // Extract the bytecode verifier config from this protocol config. `for_signing`
2385    // indicates whether this config is used for verification during signing or
2386    // execution.
2387    pub fn verifier_config(&self, signing_limits: Option<(usize, usize)>) -> VerifierConfig {
2388        let (max_back_edges_per_function, max_back_edges_per_module) = if let Some((
2389            max_back_edges_per_function,
2390            max_back_edges_per_module,
2391        )) = signing_limits
2392        {
2393            (
2394                Some(max_back_edges_per_function),
2395                Some(max_back_edges_per_module),
2396            )
2397        } else {
2398            (None, None)
2399        };
2400
2401        VerifierConfig {
2402            max_loop_depth: Some(self.max_loop_depth() as usize),
2403            max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2404            max_function_parameters: Some(self.max_function_parameters() as usize),
2405            max_basic_blocks: Some(self.max_basic_blocks() as usize),
2406            max_value_stack_size: self.max_value_stack_size() as usize,
2407            max_type_nodes: Some(self.max_type_nodes() as usize),
2408            max_push_size: Some(self.max_push_size() as usize),
2409            max_dependency_depth: Some(self.max_dependency_depth() as usize),
2410            max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2411            max_function_definitions: Some(self.max_function_definitions() as usize),
2412            max_data_definitions: Some(self.max_struct_definitions() as usize),
2413            max_constant_vector_len: Some(self.max_move_vector_len()),
2414            max_back_edges_per_function,
2415            max_back_edges_per_module,
2416            max_basic_blocks_in_script: None,
2417            max_identifier_len: self.max_move_identifier_len_as_option(), /* Before protocol
2418                                                                           * version 9, there was
2419                                                                           * no limit */
2420            bytecode_version: self.move_binary_format_version(),
2421            max_variants_in_enum: self.max_move_enum_variants_as_option(),
2422        }
2423    }
2424
2425    /// Override one or more settings in the config, for testing.
2426    /// This must be called at the beginning of the test, before
2427    /// get_for_(min|max)_version is called, since those functions cache
2428    /// their return value.
2429    pub fn apply_overrides_for_testing(
2430        override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
2431    ) -> OverrideGuard {
2432        CONFIG_OVERRIDE.with(|ovr| {
2433            let mut cur = ovr.borrow_mut();
2434            assert!(cur.is_none(), "config override already present");
2435            *cur = Some(Box::new(override_fn));
2436            OverrideGuard
2437        })
2438    }
2439}
2440
2441// Setters for tests.
2442// This is only needed for feature_flags. Please suffix each setter with
2443// `_for_testing`. Non-feature_flags should already have test setters defined
2444// through macros.
2445impl ProtocolConfig {
2446    pub fn set_zklogin_auth_for_testing(&mut self, val: bool) {
2447        self.feature_flags.zklogin_auth = val
2448    }
2449    pub fn set_enable_jwk_consensus_updates_for_testing(&mut self, val: bool) {
2450        self.feature_flags.enable_jwk_consensus_updates = val
2451    }
2452
2453    pub fn set_accept_zklogin_in_multisig_for_testing(&mut self, val: bool) {
2454        self.feature_flags.accept_zklogin_in_multisig = val
2455    }
2456
2457    pub fn set_per_object_congestion_control_mode_for_testing(
2458        &mut self,
2459        val: PerObjectCongestionControlMode,
2460    ) {
2461        self.feature_flags.per_object_congestion_control_mode = val;
2462    }
2463
2464    pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
2465        self.feature_flags.consensus_choice = val;
2466    }
2467
2468    pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
2469        self.feature_flags.consensus_network = val;
2470    }
2471
2472    pub fn set_zklogin_max_epoch_upper_bound_delta_for_testing(&mut self, val: Option<u64>) {
2473        self.feature_flags.zklogin_max_epoch_upper_bound_delta = val
2474    }
2475
2476    pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
2477        self.feature_flags.passkey_auth = val
2478    }
2479
2480    pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
2481        self.feature_flags
2482            .disallow_new_modules_in_deps_only_packages = val;
2483    }
2484
2485    pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
2486        self.feature_flags.consensus_round_prober = val;
2487    }
2488
2489    pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
2490        self.feature_flags
2491            .consensus_distributed_vote_scoring_strategy = val;
2492    }
2493
2494    pub fn set_gc_depth_for_testing(&mut self, val: u32) {
2495        self.consensus_gc_depth = Some(val);
2496    }
2497
2498    pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
2499        self.feature_flags.consensus_linearize_subdag_v2 = val;
2500    }
2501
2502    pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
2503        self.feature_flags
2504            .consensus_round_prober_probe_accepted_rounds = val;
2505    }
2506
2507    pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
2508        self.feature_flags.accept_passkey_in_multisig = val;
2509    }
2510
2511    pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
2512        self.feature_flags.consensus_smart_ancestor_selection = val;
2513    }
2514
2515    pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
2516        self.feature_flags.consensus_batched_block_sync = val;
2517    }
2518
2519    pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
2520        self.feature_flags
2521            .congestion_control_min_free_execution_slot = val;
2522    }
2523
2524    pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
2525        self.feature_flags
2526            .congestion_control_gas_price_feedback_mechanism = val;
2527    }
2528
2529    pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
2530        self.feature_flags.select_committee_from_eligible_validators = val;
2531    }
2532
2533    pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
2534        self.feature_flags.track_non_committee_eligible_validators = val;
2535    }
2536
2537    pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
2538        self.feature_flags
2539            .select_committee_supporting_next_epoch_version = val;
2540    }
2541
2542    pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
2543        &mut self,
2544        val: bool,
2545    ) {
2546        self.feature_flags
2547            .consensus_median_timestamp_with_checkpoint_enforcement = val;
2548    }
2549
2550    pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
2551        &mut self,
2552        val: bool,
2553    ) {
2554        self.feature_flags
2555            .consensus_commit_transactions_only_for_traversed_headers = val;
2556    }
2557
2558    pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
2559        &mut self,
2560        val: bool,
2561    ) {
2562        self.feature_flags
2563            .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
2564    }
2565
2566    pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
2567        &mut self,
2568        val: bool,
2569    ) {
2570        self.feature_flags
2571            .separate_gas_price_feedback_mechanism_for_randomness = val;
2572    }
2573}
2574
2575type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
2576
2577thread_local! {
2578    static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
2579}
2580
2581#[must_use]
2582pub struct OverrideGuard;
2583
2584impl Drop for OverrideGuard {
2585    fn drop(&mut self) {
2586        info!("restoring override fn");
2587        CONFIG_OVERRIDE.with(|ovr| {
2588            *ovr.borrow_mut() = None;
2589        });
2590    }
2591}
2592
2593/// Defines which limit got crossed.
2594/// The value which crossed the limit and value of the limit crossed are
2595/// embedded
2596#[derive(PartialEq, Eq)]
2597pub enum LimitThresholdCrossed {
2598    None,
2599    Soft(u128, u128),
2600    Hard(u128, u128),
2601}
2602
2603/// Convenience function for comparing limit ranges
2604/// V::MAX must be at >= U::MAX and T::MAX
2605pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
2606    x: T,
2607    soft_limit: U,
2608    hard_limit: V,
2609) -> LimitThresholdCrossed {
2610    let x: V = x.into();
2611    let soft_limit: V = soft_limit.into();
2612
2613    debug_assert!(soft_limit <= hard_limit);
2614
2615    // It is important to preserve this comparison order because if soft_limit ==
2616    // hard_limit we want LimitThresholdCrossed::Hard
2617    if x >= hard_limit {
2618        LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
2619    } else if x < soft_limit {
2620        LimitThresholdCrossed::None
2621    } else {
2622        LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
2623    }
2624}
2625
2626#[macro_export]
2627macro_rules! check_limit {
2628    ($x:expr, $hard:expr) => {
2629        check_limit!($x, $hard, $hard)
2630    };
2631    ($x:expr, $soft:expr, $hard:expr) => {
2632        check_limit_in_range($x as u64, $soft, $hard)
2633    };
2634}
2635
2636/// Used to check which limits were crossed if the TX is metered (not system tx)
2637/// Args are: is_metered, value_to_check, metered_limit, unmetered_limit
2638/// metered_limit is always less than or equal to unmetered_hard_limit
2639#[macro_export]
2640macro_rules! check_limit_by_meter {
2641    ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
2642        // If this is metered, we use the metered_limit limit as the upper bound
2643        let (h, metered_str) = if $is_metered {
2644            ($metered_limit, "metered")
2645        } else {
2646            // Unmetered gets more headroom
2647            ($unmetered_hard_limit, "unmetered")
2648        };
2649        use iota_protocol_config::check_limit_in_range;
2650        let result = check_limit_in_range($x as u64, $metered_limit, h);
2651        match result {
2652            LimitThresholdCrossed::None => {}
2653            LimitThresholdCrossed::Soft(_, _) => {
2654                $metric.with_label_values(&[metered_str, "soft"]).inc();
2655            }
2656            LimitThresholdCrossed::Hard(_, _) => {
2657                $metric.with_label_values(&[metered_str, "hard"]).inc();
2658            }
2659        };
2660        result
2661    }};
2662}
2663
2664#[cfg(all(test, not(msim)))]
2665mod test {
2666    use insta::assert_yaml_snapshot;
2667
2668    use super::*;
2669
2670    #[test]
2671    fn snapshot_tests() {
2672        println!("\n============================================================================");
2673        println!("!                                                                          !");
2674        println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
2675        println!("!                                                                          !");
2676        println!("============================================================================\n");
2677        for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
2678            // make Chain::Unknown snapshots compatible with pre-chain-id snapshots so that
2679            // we don't break the release-time compatibility tests. Once Chain
2680            // Id configs have been released everywhere, we can remove this and
2681            // only test Mainnet and Testnet
2682            let chain_str = match chain_id {
2683                Chain::Unknown => "".to_string(),
2684                _ => format!("{chain_id:?}_"),
2685            };
2686            for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
2687                let cur = ProtocolVersion::new(i);
2688                assert_yaml_snapshot!(
2689                    format!("{}version_{}", chain_str, cur.as_u64()),
2690                    ProtocolConfig::get_for_version(cur, *chain_id)
2691                );
2692            }
2693        }
2694    }
2695
2696    #[test]
2697    fn test_getters() {
2698        let prot: ProtocolConfig =
2699            ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2700        assert_eq!(
2701            prot.max_arguments(),
2702            prot.max_arguments_as_option().unwrap()
2703        );
2704    }
2705
2706    #[test]
2707    fn test_setters() {
2708        let mut prot: ProtocolConfig =
2709            ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2710        prot.set_max_arguments_for_testing(123);
2711        assert_eq!(prot.max_arguments(), 123);
2712
2713        prot.set_max_arguments_from_str_for_testing("321".to_string());
2714        assert_eq!(prot.max_arguments(), 321);
2715
2716        prot.disable_max_arguments_for_testing();
2717        assert_eq!(prot.max_arguments_as_option(), None);
2718
2719        prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
2720        assert_eq!(prot.max_arguments(), 456);
2721    }
2722
2723    #[test]
2724    #[should_panic(expected = "unsupported version")]
2725    fn max_version_test() {
2726        // When this does not panic, version higher than MAX_PROTOCOL_VERSION exists.
2727        // To fix, bump MAX_PROTOCOL_VERSION or disable this check for the version.
2728        let _ = ProtocolConfig::get_for_version_impl(
2729            ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
2730            Chain::Unknown,
2731        );
2732    }
2733
2734    #[test]
2735    fn lookup_by_string_test() {
2736        let prot: ProtocolConfig =
2737            ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2738        // Does not exist
2739        assert!(prot.lookup_attr("some random string".to_string()).is_none());
2740
2741        assert!(
2742            prot.lookup_attr("max_arguments".to_string())
2743                == Some(ProtocolConfigValue::u32(prot.max_arguments())),
2744        );
2745
2746        // We didnt have this in version 1 on Mainnet
2747        assert!(
2748            prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2749                .is_none()
2750        );
2751        assert!(
2752            prot.attr_map()
2753                .get("poseidon_bn254_cost_base")
2754                .unwrap()
2755                .is_none()
2756        );
2757
2758        // But we did in version 1 on Devnet
2759        let prot: ProtocolConfig =
2760            ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2761
2762        assert!(
2763            prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2764                == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2765        );
2766        assert!(
2767            prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
2768                == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2769        );
2770
2771        // Check feature flags
2772        let prot: ProtocolConfig =
2773            ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2774        // Does not exist
2775        assert!(
2776            prot.feature_flags
2777                .lookup_attr("some random string".to_owned())
2778                .is_none()
2779        );
2780        assert!(
2781            !prot
2782                .feature_flags
2783                .attr_map()
2784                .contains_key("some random string")
2785        );
2786
2787        // Was false in v1 on Mainnet
2788        assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
2789        assert!(
2790            prot.feature_flags
2791                .attr_map()
2792                .get("enable_poseidon")
2793                .unwrap()
2794                == &false
2795        );
2796        let prot: ProtocolConfig =
2797            ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2798        // Was true from v1 and up on Devnet
2799        assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
2800        assert!(
2801            prot.feature_flags
2802                .attr_map()
2803                .get("enable_poseidon")
2804                .unwrap()
2805                == &true
2806        );
2807    }
2808
2809    #[test]
2810    fn limit_range_fn_test() {
2811        let low = 100u32;
2812        let high = 10000u64;
2813
2814        assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
2815        assert!(matches!(
2816            check_limit!(255u16, low, high),
2817            LimitThresholdCrossed::Soft(255u128, 100)
2818        ));
2819        // This wont compile because lossy
2820        // assert!(check_limit!(100000000u128, low, high) ==
2821        // LimitThresholdCrossed::None); This wont compile because lossy
2822        // assert!(check_limit!(100000000usize, low, high) ==
2823        // LimitThresholdCrossed::None);
2824
2825        assert!(matches!(
2826            check_limit!(2550000u64, low, high),
2827            LimitThresholdCrossed::Hard(2550000, 10000)
2828        ));
2829
2830        assert!(matches!(
2831            check_limit!(2550000u64, high, high),
2832            LimitThresholdCrossed::Hard(2550000, 10000)
2833        ));
2834
2835        assert!(matches!(
2836            check_limit!(1u8, high),
2837            LimitThresholdCrossed::None
2838        ));
2839
2840        assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
2841
2842        assert!(matches!(
2843            check_limit!(2550000u64, high),
2844            LimitThresholdCrossed::Hard(2550000, 10000)
2845        ));
2846    }
2847}