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::{MeterConfig, 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 = 42;
23
24/// Protocol version that IIP8 took effect.
25pub const PROTOCOL_VERSION_IIP8: u64 = 20;
26// Record history of protocol version allocations here:
27//
28// Version 1: Original version.
29// Version 2: Don't redistribute slashed staking rewards, fix computation of
30// SystemEpochInfoEventV1.
31// Version 3: Set the `relocate_event_module` to be true so that the module
32// that is associated as the "sending module" for an event is
33// relocated by linkage.
34// Add `Clock` based unlock to `Timelock` objects.
35// Version 4: Introduce the `max_type_to_layout_nodes` config that sets the
36// maximal nodes which are allowed when converting to a type layout.
37// Version 5: Introduce fixed protocol-defined base fee, IotaSystemStateV2 and
38// SystemEpochInfoEventV2.
39// Disallow adding new modules in `deps-only` packages.
40// Improve gas/wall time efficiency of some Move stdlib vector
41// functions.
42// Add new gas model version to update charging of functions.
43// Enable proper conversion of certain type argument errors in the
44// execution layer.
45// Version 6: Bound size of values created in the adapter.
46// Version 7: Improve handling of stake withdrawal from candidate validators.
47// Version 8: Variants as type nodes.
48// Enable smart ancestor selection for testnet.
49// Enable probing for accepted rounds in round prober for testnet.
50// Switch to distributed vote scoring in consensus in testnet.
51// Enable zstd compression for consensus tonic network in testnet.
52// Enable consensus garbage collection for testnet
53// Enable the new consensus commit rule for testnet.
54// Enable min_free_execution_slot for the shared object congestion
55// tracker in devnet.
56// Version 9: Disable smart ancestor selection for the testnet.
57// Enable zstd compression for consensus tonic network in mainnet.
58// Enable passkey auth in multisig for devnet.
59// Remove the iota-bridge from the framework.
60// Version 10: Enable min_free_execution_slot for the shared object congestion
61// tracker in all networks.
62// Increase the committee size to 80 on all networks.
63// Enable round prober in consensus for mainnet.
64// Enable probing for accepted rounds in round prober for mainnet.
65// Switch to distributed vote scoring in consensus for mainnet.
66// Enable the new consensus commit rule for mainnet.
67// Enable consensus garbage collection for mainnet with GC depth set
68// to 60 rounds.
69// Enable batching in synchronizer for testnet
70// Enable the gas price feedback mechanism in devnet.
71// Enable Identifier input validation.
72// Removes unnecessary child object mutations
73// Add additional signature checks
74// Add additional linkage checks
75// Version 11: Framework fix regarding candidate validator commission rate.
76// Version 12: Enable the gas price feedback mechanism in all networks.
77// Enable the normalization of PTB arguments.
78// Version 13: Introduce logic to allow the committee to be selected from a set
79// of eligible active validators.
80// Enable processing and tracking AuthorityCapabilitiesV1 from
81// non-committee validators in the devnet.
82// Version 14: Switches the consensus protocol to Starfish in devnet.
83// Enable median-based commit timestamp calculation in consensus,
84// and enforce checkpoint timestamp monotonicity for testnet.
85// Enable batched block sync for mainnet.
86// Enable selecting committee only from active validators that
87// support the next epoch's version and issued valid
88// AuthorityCapabilities notification in testnet.
89// Version 15: Enable shared object transaction bursts of 10 times average load
90// on devnet.
91// Version 16: Enable selecting committee only from active validators that
92// support the next epoch's version and issued valid
93// AuthorityCapabilities notification.
94// Enable committing transactions only for traversed headers in
95// Starfish.
96// Version 17: Increase the committee size to 100 on all networks.
97// Version 18: Enable passkey authentication support in testnet.
98// Version 19: Enable congestion limit overshoot in the gas price feedback
99// mechanism on devnet.
100// Enable a separate gas price feedback mechanism for transactions
101// using randomness on devnet.
102// Allow metadata bytes indexed with a dedicated key in compiled
103// Move modules in devnet.
104// Enable publishing package metadata v1 along with the package in
105// devnet.
106// Enable Move-based account authentication in devnet.
107// Increase the base cost for transfer receive object in devnet.
108// Switch consensus protocol to Starfish in testnet.
109// Enable passkey authentication support in mainnet.
110// Change epoch transaction will contain validator scores.
111// Enable validator scoring on testnet and enable adjustment of
112// validator rewards based on scores on Devnet.
113// Version 20: Supports the calculation of validator scores while still passing
114// a default score value to the advance_epoch call. Enables this
115// decoupling on Testnet; Devnet and Mainnet behavior remain the
116// same.
117// Introduce Dynamic Minimum Commission (IIP-8) on all networks.
118// Version 21: Enable overshoot of 100 in congestion control on testnet.
119// Enable congestion limit overshoot in the gas price feedback
120// mechanism on testnet.
121// Enable a separate gas price feedback mechanism for transactions
122// using randomness on testnet.
123// Enable fast commit syncer for faster recovery in devnet.
124// Add auth_context_tx native functions costs.
125// Reduce max_auth_gas in Devnet.
126// Version 22: Enable overshoot of 100 in congestion control on all networks.
127// Enable congestion limit overshoot in the gas price feedback
128// mechanism on all networks.
129// Enable a separate gas price feedback mechanism for transactions
130// using randomness on all networks.
131// Enable Move-based account authentication in testnet.
132// Enable fast commit syncer for faster recovery on testnet.
133// Version 23: Enable Move native context (TxContext via native functions) in
134// all networks. TxContext fields are read via native functions
135// instead of being deserialized from a BCS-encoded struct.
136// Enables sponsor, rgp, gas_price, and gas_budget to be exposed to
137// Move.
138// Version 24: Switch consensus protocol to Starfish in all networks.
139// Enable Move-based sponsor account authentication in devnet.
140// Add AuthContext native functions cost for reading tx_data_bytes.
141// Enable additional borrow checks.
142// Version 25: Deprecate zkLogin related parameters since zkLogin is no longer
143// supported.
144// Version 26: Introduce a module to allow Move code to query protocol feature
145// flags at runtime.
146// Version 27: Only sponsor Move authentication is performed pre-consensus in
147// devnet.
148// Enable consensus block restrictions on testnet and devnet:
149// bound block-header size to O(committee_size) and enable
150// garbage collection in the block manager.
151// Version 28: Move authenticator contracts can now inspect which authenticator
152// function the sender and sponsor used during transaction execution
153// via new AuthContext accessors.
154// Enable Move-based account authentication in mainnet.
155// Enable Move-based sponsor account authentication in testnet.
156// Version 29: Keep advancing the random beacon DKG state machine on every
157// commit while it is still pending -- regardless of whether new DKG
158// messages or confirmations arrived that commit -- so DKG resolves
159// from persisted state (completing, or failing once the timeout
160// round passes) even with no fresh inbound traffic, e.g. after a
161// validator restart. Without this it can stay pending forever and
162// block epoch close.
163// Enable median-based commit timestamp calculation in consensus,
164// and enforce checkpoint timestamp monotonicity for mainnet.
165// Enable fast commit syncer for faster recovery on all networks.
166// Enable consensus block restrictions on all networks:
167// bound block-header size to O(committee_size) and enable
168// garbage collection in the block manager.
169// Version 30: Extend the protocol_config framework module with a generic
170// `get_attr<T>` native that lets Move code read any numeric or
171// boolean protocol parameter by name, returning T directly and
172// aborting on error.
173// Expose `is_feature_enabled` and `get_attr<T>` natives to the
174// iota_system package via a new iota_system::protocol_config
175// module.
176// Version 31: Rebuild the framework binaries for the latest iota_system
177// validator set changes.
178// Enable validator metadata verification v2.
179// Amortize the minimum checkpoint interval over a sliding window
180// on non-Mainnet/Testnet chains.
181// Start publishing package metadata using module metadata as a
182// dynamic field.
183// Report a failure of the Move authentication with a distinct
184// `MoveAuthentication` execution error.
185// Enable the optimistic commit rule (StarfishSpeed) in Starfish
186// consensus on devnet.
187// Version 32: Move validator count limits (min/max validator count) and
188// stake thresholds (joining stake, low/very low stake
189// thresholds, grace period) into the protocol config.
190// Enable the optimistic commit rule (StarfishSpeed) in Starfish
191// consensus on testnet.
192// Amortize the minimum checkpoint interval over a sliding window
193// on testnet.
194// Start publishing package metadata using module metadata as a
195// dynamic field on testnet.
196// Enable the redesigned leader schedule (sliding-window reputation
197// scoring and absolute-score bad-node selection) in Starfish
198// consensus on devnet.
199// Enable Move-based sponsor account authentication on mainnet.
200// Only sponsor Move authentication is performed pre-consensus on
201// mainnet.
202// Enable the P-COOL flow on devnet.
203// Version 33: Amortize the minimum checkpoint interval over a sliding window
204// on mainnet.
205// Enable the sliding-window reputation scoring and absolute-score
206// bad-node selection on testnet
207// Version 34: Bump the scorer version to 2 on devnet: misbehavior reports
208// carry a dedicated counter for invalid bundle parts, previously
209// folded into the unprovable block-fault counter.
210// Add the `iota::transaction_deny_rules` framework module and its
211// reserved object ID 0xDE9 (dormant until deny-rule governance
212// activates).
213// Stop locking immutable objects in post-consensus conflict
214// resolution.
215// Disable Move-based sponsor account authentication on mainnet.
216// Version 35: Scale the PTB value size limit by the value's type.
217// Allow objects created or mutated by system transactions to exceed
218// the max object size limit.
219// Enable the optimistic commit rule (StarfishSpeed) in Starfish
220// consensus on mainnet.
221// Meter the packages a transaction publishes with the protocol
222// config's verifier limits in post-consensus validation, and set
223// those limits to the node config's defaults on all chains
224// (inert where the P-COOL flow is off).
225// Start publishing package metadata using module metadata as a
226// dynamic field on mainnet.
227// Enable the redesigned leader schedule (sliding-window reputation
228// scoring and absolute-score bad-node selection) in Starfish
229// consensus on mainnet.
230// Version 36: Reject a transaction whose sender or sponsor is authenticated by
231// a `MoveAuthenticator` with an immutable account object.
232// Version 37: Reject a transaction that names an object version in the range
233// assigned to canceled transactions, or one below it, from the
234// transaction bytes, before any object is loaded.
235// Reject `<SELF>` as an identifier in published modules.
236// Make the enum variant count limit explicit in the protocol
237// config.
238// Check the package that holds a `MoveAuthenticator`'s
239// authenticate function, and that package's dependencies, against
240// the package deny list.
241// Require the version field of a published module header to be the
242// encoding the serializer produces for that version, rejecting a
243// non-zero flavor byte below binary format version 7.
244// Reject the randomness state object as a `MoveAuthenticator`
245// input.
246// Traverse the module graph when checking a published module for
247// cyclic dependencies, instead of stopping at its immediate
248// dependencies.
249// Version 38: Bound system Move packages by `max_move_system_package_size`
250// rather than the limit that applies to user packages.
251// Abort `iota::account::create_immutable_account_v1`, so no new
252// immutable account object can be created.
253// Validate PTB indices at signing time.
254// Version 39: Allow random beacon DKG to complete after its timeout on devnet
255// and testnet.
256// The consensus handler's processed-transaction cache holds only
257// messages recorded as processed, so a cache hit gives the same
258// answer as the processed-message table on every validator. A
259// user transaction from an authority that has sent EndOfPublish
260// no longer makes a later transaction with the same key in the
261// same commit be skipped as a duplicate.
262// Raise the minimum validator joining stake to 6M IOTA, the low
263// stake threshold to 5.5M IOTA and the very low stake threshold to
264// 5M IOTA on all chains.
265// Reject a multisig whose committee mixes Ed25519 with other key
266// schemes unless every committee member has signed.
267// Enable Groth16 verifying key input length checks before deserialization.
268// Reject the deprecated global storage instructions and non-empty
269// `acquires` lists when execution deserializes a module, and
270// verify modules without the acquires pass and with vector element
271// borrows checked by the call rule.
272// Version 40: Post-consensus validation takes the instantiation-loop graph
273// edge limit, and whether the instantiation-loop check is
274// metered, from the protocol config.
275// Make the packages named by a `MoveAuthenticator`'s type
276// arguments inputs of that authenticator.
277// Limit the struct, enum and vector values in Move-call
278// arguments, per call and per transaction.
279// Reject `<SELF>` as an identifier in transactions, at signing,
280// after consensus and in block verification. Block verification
281// also rejects a block that carries a system transaction kind in
282// a user transaction or certificate.
283// Update the gas model version to 3.
284// Enable validator attestation on devnet, with the checkpoint
285// summary data version that certifies the verdicts.
286// Version 41: Commit a block's transactions once its header is traversed even
287// if its acknowledgment quorum was reached first, outside Mainnet.
288// `ecdsa_r1::secp256r1_ecrecover` rejects a signature whose
289// restored x-coordinate is not below the field modulus.
290// Outside Mainnet and Testnet, a programmable transaction may
291// carry a transaction dependency input: its commands run only if
292// the named transaction succeeded in the current epoch. If that
293// transaction fails after the dependent was sequenced, the
294// dependent executes as failed with `TransactionDependencyFailed`.
295// Raise `max_auth_gas` to 0.001 IOTA on devnet.
296// Set the attestation freshness window on devnet.
297// Set the penalty for refuted attestations on devnet.
298// Version 42: Enable built-in Move authenticators in devnet.
299// Enable creating SmartAccounts in devnet.
300// Introduce Move native functions for validating public keys for
301// Ed25519, Secp256k1, Secp256r1, and MultiSig signature schemes,
302// deriving IOTA addresses from public keys, and verifying a
303// signature of a personal message by a public key.
304// Introduce the Move native functions that return the nonce of the
305// transaction and the text a key holder signs to approve attaching
306// their key to a SmartAccount.
307// Set the gas costs of those natives on all networks, and of the
308// built-in Move authenticators in devnet.
309// Add `tx_context::chain_identifier`, which returns the digest of
310// the genesis checkpoint, and set the gas cost of its native on
311// all networks.
312#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
313pub struct ProtocolVersion(u64);
314
315impl ProtocolVersion {
316 // The minimum and maximum protocol version supported by this binary.
317 // Counterintuitively, this constant may change over time as support for old
318 // protocol versions is removed from the source. This ensures that when a
319 // new network (such as a testnet) is created, its genesis committee will
320 // use a protocol version that is actually supported by the binary.
321 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
322
323 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
324
325 #[cfg(not(msim))]
326 const MAX_ALLOWED: Self = Self::MAX;
327
328 // We create one additional "fake" version in simulator builds so that we can
329 // test upgrades.
330 #[cfg(msim)]
331 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
332
333 pub fn new(v: u64) -> Self {
334 Self(v)
335 }
336
337 pub const fn as_u64(&self) -> u64 {
338 self.0
339 }
340
341 // For serde deserialization - we don't define a Default impl because there
342 // isn't a single universally appropriate default value.
343 pub fn max() -> Self {
344 Self::MAX
345 }
346}
347
348impl From<u64> for ProtocolVersion {
349 fn from(v: u64) -> Self {
350 Self::new(v)
351 }
352}
353
354impl std::ops::Sub<u64> for ProtocolVersion {
355 type Output = Self;
356 fn sub(self, rhs: u64) -> Self::Output {
357 Self::new(self.0 - rhs)
358 }
359}
360
361impl std::ops::Add<u64> for ProtocolVersion {
362 type Output = Self;
363 fn add(self, rhs: u64) -> Self::Output {
364 Self::new(self.0 + rhs)
365 }
366}
367
368#[derive(
369 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
370)]
371pub enum Chain {
372 Mainnet,
373 Testnet,
374 #[default]
375 Unknown,
376}
377
378impl Chain {
379 pub fn as_str(self) -> &'static str {
380 match self {
381 Chain::Mainnet => "mainnet",
382 Chain::Testnet => "testnet",
383 Chain::Unknown => "unknown",
384 }
385 }
386}
387
388pub struct Error(pub String);
389
390// TODO: There are quite a few non boolean values in the feature flags. We
391// should move them out.
392/// Records on/off feature flags that may vary at each protocol version.
393#[derive(
394 Default,
395 Clone,
396 Serialize,
397 Deserialize,
398 Debug,
399 ProtocolConfigFeatureFlagsGetters,
400 ProtocolConfigOverride,
401)]
402struct FeatureFlags {
403 // Add feature flags here, e.g.:
404 // new_protocol_feature: bool,
405
406 // Disables unnecessary invariant check in the Move VM when swapping the value out of a local
407 // This flag is used to provide the correct MoveVM configuration for clients.
408 #[serde(skip_serializing_if = "is_true")]
409 disable_invariant_violation_check_in_swap_loc: bool,
410
411 // If true, checks no extra bytes in a compiled module
412 // This flag is used to provide the correct MoveVM configuration for clients.
413 #[serde(skip_serializing_if = "is_true")]
414 no_extraneous_module_bytes: bool,
415
416 // How we order transactions coming out of consensus before sending to execution.
417 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
418 consensus_transaction_ordering: ConsensusTransactionOrdering,
419
420 // If true, use the hardened OTW check
421 // This flag is used to provide the correct MoveVM configuration for clients.
422 #[serde(skip_serializing_if = "is_true")]
423 hardened_otw_check: bool,
424
425 // Enable the poseidon hash function
426 #[serde(skip_serializing_if = "is_false")]
427 enable_poseidon: bool,
428
429 // Enable native function for msm.
430 #[serde(skip_serializing_if = "is_false")]
431 enable_group_ops_native_function_msm: bool,
432
433 // Controls the behavior of per object congestion control in consensus handler.
434 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
435 per_object_congestion_control_mode: PerObjectCongestionControlMode,
436
437 // The consensus protocol to be used for the epoch.
438 #[serde(
439 default = "ConsensusChoice::mysticeti_deprecated",
440 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
441 )]
442 consensus_choice: ConsensusChoice,
443
444 // Consensus network to use.
445 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
446 consensus_network: ConsensusNetwork,
447
448 // Set the upper bound allowed for max_epoch in zklogin signature.
449 #[deprecated]
450 #[serde(skip_serializing_if = "Option::is_none")]
451 zklogin_max_epoch_upper_bound_delta: Option<u64>,
452
453 // Enable VDF
454 #[serde(skip_serializing_if = "is_false")]
455 enable_vdf: bool,
456
457 // Enable passkey auth (SIP-9)
458 #[serde(skip_serializing_if = "is_false")]
459 passkey_auth: bool,
460
461 // Rethrow type layout errors during serialization instead of trying to convert them.
462 // This flag is used to provide the correct MoveVM configuration for clients.
463 #[serde(skip_serializing_if = "is_true")]
464 rethrow_serialization_type_layout_errors: bool,
465
466 // Makes the event's sending module version-aware.
467 #[serde(skip_serializing_if = "is_false")]
468 relocate_event_module: bool,
469
470 // Enable a protocol-defined base gas price for all transactions.
471 #[serde(skip_serializing_if = "is_false")]
472 protocol_defined_base_fee: bool,
473
474 // Enable uncompressed group elements in BLS123-81 G1
475 #[serde(skip_serializing_if = "is_false")]
476 uncompressed_g1_group_elements: bool,
477
478 // Disallow adding new modules in `deps-only` packages.
479 #[serde(skip_serializing_if = "is_false")]
480 disallow_new_modules_in_deps_only_packages: bool,
481
482 // Enable v2 native charging for natives.
483 #[serde(skip_serializing_if = "is_false")]
484 native_charging_v2: bool,
485
486 // Properly convert certain type argument errors in the execution layer.
487 #[serde(skip_serializing_if = "is_false")]
488 convert_type_argument_error: bool,
489
490 // Probe rounds received by peers from every authority.
491 #[serde(skip_serializing_if = "is_false")]
492 consensus_round_prober: bool,
493
494 // Use distributed vote leader scoring strategy in consensus.
495 #[serde(skip_serializing_if = "is_false")]
496 consensus_distributed_vote_scoring_strategy: bool,
497
498 // Enables the new logic for collecting the subdag in the consensus linearizer. The new logic
499 // does not stop the recursion at the highest committed round for each authority, but
500 // allows to commit uncommitted blocks up to gc round (excluded) for that authority.
501 #[serde(skip_serializing_if = "is_false")]
502 consensus_linearize_subdag_v2: bool,
503
504 // Variants count as nodes
505 #[serde(skip_serializing_if = "is_false")]
506 variant_nodes: bool,
507
508 // Use smart ancestor selection in consensus.
509 #[serde(skip_serializing_if = "is_false")]
510 consensus_smart_ancestor_selection: bool,
511
512 // Probe accepted rounds in round prober.
513 #[serde(skip_serializing_if = "is_false")]
514 consensus_round_prober_probe_accepted_rounds: bool,
515
516 // If true, enable zstd compression for consensus tonic network.
517 #[serde(skip_serializing_if = "is_false")]
518 consensus_zstd_compression: bool,
519
520 // Use the minimum free execution slot to schedule execution of a transaction in the shared
521 // object congestion tracker.
522 #[serde(skip_serializing_if = "is_false")]
523 congestion_control_min_free_execution_slot: bool,
524
525 // If true, multisig containing passkey sig is accepted.
526 #[serde(skip_serializing_if = "is_false")]
527 accept_passkey_in_multisig: bool,
528
529 // If true, enabled batched block sync in consensus.
530 #[serde(skip_serializing_if = "is_false")]
531 consensus_batched_block_sync: bool,
532
533 // To enable/disable the gas price feedback mechanism used for transactions
534 // cancelled due to shared object congestion
535 #[serde(skip_serializing_if = "is_false")]
536 congestion_control_gas_price_feedback_mechanism: bool,
537
538 // Validate identifier inputs separately
539 #[serde(skip_serializing_if = "is_false")]
540 validate_identifier_inputs: bool,
541
542 // If true, enables the optimizations for child object mutations, removing unnecessary
543 // mutations
544 #[serde(skip_serializing_if = "is_false")]
545 minimize_child_object_mutations: bool,
546
547 // If true enable additional linkage checks.
548 #[serde(skip_serializing_if = "is_false")]
549 dependency_linkage_error: bool,
550
551 // If true enable additional multisig checks.
552 #[serde(skip_serializing_if = "is_false")]
553 additional_multisig_checks: bool,
554
555 // If true, enables the normalization of PTB arguments but does not yet enable splatting
556 // `Result`s of length not equal to 1
557 #[serde(skip_serializing_if = "is_false")]
558 normalize_ptb_arguments: bool,
559
560 // If true, use ChangeEpochV3 for epoch change to pass an additional eligible_active_validators
561 // parameter to IotaSystem's advance_epoch call. This should only be enabled when on-chain
562 // IotaSystem objects are updated as well.
563 #[serde(skip_serializing_if = "is_false")]
564 select_committee_from_eligible_validators: bool,
565
566 // If true, non-committee active validators will sign and send AuthorityCapabilitiesV1 to the
567 // committee. Once the committee reaches consensus over the AuthorityCapabilitiesV1, it is
568 // recorded and possible to use in the committee selection if
569 // select_validators_supporting_next_epoch_version is enabled. This flag does not change the
570 // way that eligible_validators vector is created - still all active validators are used for
571 // selecting the committee.
572 #[serde(skip_serializing_if = "is_false")]
573 track_non_committee_eligible_validators: bool,
574
575 // The committee be selected from active_validators who support the next protocol version AND
576 // have issued a correct AuthorityCapabilities notification. This flag should only be enabled
577 // if both select_committee_from_eligible_validators and
578 // track_non_committee_eligible_validators are enabled. If this is disabled, then all
579 // active validators are used for selecting the committee (default behavior).
580 #[serde(skip_serializing_if = "is_false")]
581 select_committee_supporting_next_epoch_version: bool,
582
583 // If true, then it (1) will not enforce monotonicity checks for a block's ancestors, (2)
584 // calculates the commit's timestamp based on the weighted by stake median timestamp of the
585 // leader's ancestors, and (3) enforces checkpoint timestamps are non-decreasing.
586 #[serde(skip_serializing_if = "is_false")]
587 consensus_median_timestamp_with_checkpoint_enforcement: bool,
588
589 // If true, then transactions are committed only for traversed headers
590 #[serde(skip_serializing_if = "is_false")]
591 consensus_commit_transactions_only_for_traversed_headers: bool,
592
593 // To enable/disable congestion limit overshoot in the gas price feedback mechanism.
594 #[serde(skip_serializing_if = "is_false")]
595 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
596
597 // To enable/disable a separate gas price feedback mechanism for transactions using
598 // randomness.
599 #[serde(skip_serializing_if = "is_false")]
600 separate_gas_price_feedback_mechanism_for_randomness: bool,
601
602 // If true, it allows metadata bytes indexed with a dedicated key in a compiled module.
603 // This flag is used to provide the correct MoveVM configuration for clients.
604 #[serde(skip_serializing_if = "is_false")]
605 metadata_in_module_bytes: bool,
606
607 // If true, enables publishing package metadata v1 along with the package.
608 #[serde(skip_serializing_if = "is_false")]
609 publish_package_metadata: bool,
610
611 // If true, enables the authentication of account using Move code.
612 #[serde(skip_serializing_if = "is_false")]
613 enable_move_authentication: bool,
614
615 // If true, enables the authentication of a sponsor account using Move code.
616 #[serde(skip_serializing_if = "is_false")]
617 enable_move_authentication_for_sponsor: bool,
618
619 // If true, the change epoch transaction will contain validator scores.
620 #[serde(skip_serializing_if = "is_false")]
621 pass_validator_scores_to_advance_epoch: bool,
622
623 // If true, enables calculation of validator scores.
624 #[serde(skip_serializing_if = "is_false")]
625 calculate_validator_scores: bool,
626
627 // If true, validators will use the committee's score to adjust rewards.
628 #[serde(skip_serializing_if = "is_false")]
629 adjust_rewards_by_score: bool,
630
631 // If true, the change epoch transaction will contain the locally calculated validator scores.
632 // If false, a default score (MAX_SCORE) is passed
633 #[serde(skip_serializing_if = "is_false")]
634 pass_calculated_validator_scores_to_advance_epoch: bool,
635
636 // If true, enables the fast commit syncer in Starfish consensus for faster recovery
637 // from large commit gaps. Also controls whether TransactionRef is used in commits
638 // instead of BlockRef, and enables the associated gRPC endpoints for fetching
639 // commits and transactions.
640 #[serde(skip_serializing_if = "is_false")]
641 consensus_fast_commit_sync: bool,
642
643 // If true, enables consensus block restrictions: bounds the block header size for
644 // a given committee size.
645 #[serde(skip_serializing_if = "is_false")]
646 consensus_block_restrictions: bool,
647
648 // If true, enable `TxContext` Move API to go native.
649 #[serde(skip_serializing_if = "is_false")]
650 move_native_tx_context: bool,
651
652 // If true, perform additional borrow checks
653 #[serde(skip_serializing_if = "is_false")]
654 additional_borrow_checks: bool,
655
656 // If true, only sponsor Move authentication is performed pre-consensus.
657 #[serde(skip_serializing_if = "is_false")]
658 pre_consensus_sponsor_only_move_authentication: bool,
659
660 // If true, enables the optimistic commit rule (StarfishSpeed) in Starfish consensus.
661 #[serde(skip_serializing_if = "is_false")]
662 consensus_starfish_speed: bool,
663
664 // If true, keep advancing the random beacon DKG state machine on every
665 // consensus commit while DKG is still pending, even when no new messages or
666 // confirmations were processed that commit. This lets a validator resolve
667 // DKG from already-persisted state (completing, or failing once the timeout
668 // round passes) with no fresh inbound traffic -- e.g. after a restart --
669 // instead of staying pending forever.
670 #[serde(skip_serializing_if = "is_false")]
671 always_advance_dkg_to_resolution: bool,
672
673 // If true, enables the P-COOL (post-consensus owned-object locking) flow:
674 // transactions bypass pre-consensus certification and owned-object locking,
675 // and conflicts are resolved deterministically post-consensus (white-flag
676 // conflict resolution) using persistent locks. Post-consensus deny checks
677 // use a consensus-governed deny rule set instead of each validator's local
678 // `TransactionDenyConfig`: validators announce proposed rules, and the
679 // active set is their stake-weighted aggregate. The active set is mirrored
680 // into the on-chain `TransactionDenyRules` object, which is created at the
681 // end of the first epoch with the flow and updated by system transactions
682 // when the active set changes.
683 //
684 // Post-consensus validation is deterministic: it reads object state as of
685 // `pcool_deterministic_validation_horizon_distance` commits below the
686 // commit it validates, and checks the sender against the coin deny list
687 // for the coin types of its inputs there, with changes made this epoch
688 // counting; execution no longer checks inputs against it. A committee
689 // validator does not execute state-synced checkpoints while its epoch is
690 // running: it waits for its own checkpoint builder and takes only
691 // randomness signatures from state sync. Once the certified last
692 // checkpoint of the epoch is known, it executes the rest of the epoch from
693 // state sync and stops processing consensus commits.
694 //
695 // From protocol version 39 requires `max_meter_ticks_regex_reference_safety`,
696 // `consensus_dedup_only_recorded_messages`, a positive
697 // `pcool_deterministic_validation_horizon_distance` and
698 // `deny_rule_update_max_entries_per_tx`, and excludes
699 // `pre_consensus_sponsor_only_move_authentication`.
700 #[serde(skip_serializing_if = "is_false")]
701 enable_pcool_flow: bool,
702
703 // No longer read: post-consensus validation never locks immutable inputs.
704 // Kept because shipped protocol versions set it.
705 #[serde(skip_serializing_if = "is_false")]
706 pcool_skip_immutable_object_locks: bool,
707
708 // No longer read: post-consensus validation always meters published
709 // packages with the verifier limits from this config. Kept because
710 // shipped protocol versions set it.
711 #[serde(skip_serializing_if = "is_false")]
712 pcool_verifier_limits_from_protocol_config: bool,
713
714 // If true perform consistent verification of metadata
715 #[serde(skip_serializing_if = "is_false")]
716 validator_metadata_verify_v2: bool,
717
718 // If true, the package holding a `MoveAuthenticator`'s authenticate function,
719 // together with that package's dependencies, is checked against the package
720 // deny list.
721 #[serde(skip_serializing_if = "is_false")]
722 deny_authenticator_packages: bool,
723
724 // If true, package metadata can be published with ModuleMetadata as a dynamic
725 // field.
726 #[serde(skip_serializing_if = "is_false")]
727 package_metadata_with_dynamic_module_metadata: bool,
728
729 // If true, a failure of the Move authentication is reported with a distinct
730 // `MoveAuthentication` execution error.
731 #[serde(skip_serializing_if = "is_false")]
732 report_move_authentication_error: bool,
733
734 // If true, the Starfish leader schedule scores reputation over a sliding
735 // window and rebuilds the swap table every `consensus_commits_per_schedule`
736 // commits with a uniform base election; when false, V2 snapshot scoring +
737 // stake-weighted base election is used.
738 #[serde(skip_serializing_if = "is_false")]
739 consensus_enable_sliding_window_leader_schedule: bool,
740
741 // If true, Starfish selects "bad" leader-schedule nodes by absolute
742 // normalized reputation score: exclude validators below a low threshold,
743 // capped at a maximum number of validators, and keep a minimum-size good
744 // (swap-in) pool; when false, the fixed stake cut by rank is used.
745 #[serde(skip_serializing_if = "is_false")]
746 consensus_enable_absolute_score_leader_schedule: bool,
747
748 // If true, enables better errors and bounds for max ptb values
749 #[serde(skip_serializing_if = "is_false")]
750 max_ptb_value_size_v2: bool,
751
752 // Allow objects created or mutated in system transactions to exceed the max object size limit.
753 #[serde(skip_serializing_if = "is_false")]
754 allow_unbounded_system_objects: bool,
755
756 // If true, transaction validation rejects a `MoveAuthenticator` whose
757 // account object is immutable.
758 #[serde(skip_serializing_if = "is_false")]
759 reject_immutable_account_objects: bool,
760
761 // If true, `iota::account::create_immutable_account_v1` aborts, so no new
762 // immutable account object can be created.
763 #[serde(skip_serializing_if = "is_false")]
764 reject_immutable_account_creation: bool,
765
766 // If true, `validity_check` rejects a transaction that names an object
767 // version at or above `Version::MAX_VALID_EXCL`, the range assigned to the
768 // objects of canceled transactions, or right below it, from the transaction
769 // bytes alone. Version assignment increments the largest input version and
770 // halts the node when the result is not a valid version.
771 #[serde(skip_serializing_if = "is_false")]
772 validate_input_object_versions: bool,
773
774 // Disallow self identifier
775 #[serde(skip_serializing_if = "is_false")]
776 disallow_self_identifier: bool,
777
778 // Reject a transaction whose type arguments, Move call module or function
779 // name, or Move authenticator type arguments carry an identifier that
780 // move-core rejects (`<SELF>`), at signing, after consensus and in block
781 // verification.
782 #[serde(skip_serializing_if = "is_false")]
783 disallow_self_identifier_in_transactions: bool,
784
785 // If true, the version field of a published module header must be the encoding
786 // the serializer produces for the version it decodes to. Below binary format
787 // version 7 the flavor byte is not part of the header, and without this check
788 // a non-zero flavor byte is masked off instead of rejected.
789 #[serde(skip_serializing_if = "is_false")]
790 check_canonical_module_version_header: bool,
791
792 // If true, `validity_check` rejects a `MoveAuthenticator` that names the
793 // randomness state object among its inputs. An authenticate function cannot
794 // derive randomness from it, but naming it schedules the transaction as
795 // randomness-using and defers it to a randomness round for nothing.
796 #[serde(skip_serializing_if = "is_false")]
797 disallow_randomness_in_move_authenticator: bool,
798
799 // If true, the cyclic dependency check traverses the module graph. Without it
800 // the traversal descends only into modules it has already visited, so it stops
801 // at the immediate dependencies and never reports a cycle.
802 #[serde(skip_serializing_if = "is_false")]
803 check_cyclic_dependencies: bool,
804
805 // Validate PTB input and result indices before signing.
806 #[serde(skip_serializing_if = "is_false")]
807 validate_ptb_argument_indices: bool,
808
809 // If true, keep DKG pending after its timeout so that it can complete later
810 // in the epoch.
811 #[serde(skip_serializing_if = "is_false")]
812 allow_dkg_completion_after_timeout: bool,
813
814 // If true, a consensus message is skipped as a duplicate of an earlier message with the same
815 // key that was recorded as processed or passed verification in the same commit:
816 // - The consensus handler adds a message to its processed-transaction cache only after the
817 // epoch store recorded it as processed. Otherwise the cache also holds messages that were
818 // dropped without being recorded, and since it differs between validators and after a
819 // restart, skipping on a cache hit lets validators disagree about a later message with the
820 // same key.
821 // - A user transaction from an authority that has sent EndOfPublish fails verification, so it
822 // does not make a later transaction with the same key in its commit be skipped.
823 #[serde(skip_serializing_if = "is_false")]
824 consensus_dedup_only_recorded_messages: bool,
825
826 // If true, a multisig whose committee mixes Ed25519 with other key schemes
827 // is only accepted when every committee member has signed. Ed25519 members
828 // carry no flag byte in the multisig address preimage, so two different
829 // mixed committees can derive the same address.
830 #[serde(skip_serializing_if = "is_false")]
831 reject_partially_signed_mixed_ed25519_multisig: bool,
832
833 // If true, groth16::prepare_verifying_key checks that the verifying key has
834 // no more than MAX_PUBLIC_INPUTS public inputs.
835 #[serde(skip_serializing_if = "is_false")]
836 limit_groth16_pvk_inputs: bool,
837
838 // If true, groth16::verify_groth16_proof checks that the prepared verifying
839 // key has the length implied by the number of public inputs, and aborts
840 // with EInvalidVerifyingKey if it does not.
841 #[serde(skip_serializing_if = "is_false")]
842 check_groth16_pvk_length: bool,
843
844 // If true, deprecate global storage ops everywhere. A module that uses the
845 // deprecated global storage instructions, or has a non-empty `acquires`
846 // list, fails to deserialize. The verifier skips the acquires pass, checks
847 // vector element borrows with the same rule as calls, and fails if a
848 // deprecated instruction reaches it. This applies to every module the VM
849 // verifies, including published packages it loads. Signing always runs
850 // with it on; post-consensus validation follows this flag.
851 #[serde(skip_serializing_if = "is_false")]
852 deprecate_global_storage_ops: bool,
853
854 // If true, post-consensus validation meters the instantiation-loop check
855 // of the bytecode verifier. Signing always meters it.
856 #[serde(skip_serializing_if = "is_false")]
857 meter_instantiation_loops: bool,
858
859 // If true, the packages named by a `MoveAuthenticator`'s type arguments are
860 // inputs of that authenticator, as those of a `MoveCall` are. Without it no
861 // node waits for them, so a node that has not executed such a package's
862 // publish yet fails an authentication that the others pass.
863 #[serde(skip_serializing_if = "is_false")]
864 move_authenticator_type_arg_packages_as_inputs: bool,
865
866 // If true, the block-proposing validator attests each received user transaction
867 // before sending it to consensus. The attestor certifies that Move authentication
868 // passed and the attestation carries a computation cost estimate for
869 // shared-object scheduling. The Move authenticators run at execution, and
870 // in the attestor's dry run, then share at most `max_auth_gas`; the
871 // transaction body gets the rest of the budget.
872 #[serde(skip_serializing_if = "is_false")]
873 enable_validator_attestation: bool,
874
875 // If true, a block whose transactions reach their acknowledgment quorum
876 // before its header is traversed is committed once its header is traversed.
877 #[serde(skip_serializing_if = "is_false")]
878 consensus_commit_transactions_once_traversed: bool,
879
880 // If true, `ecdsa_r1::secp256r1_ecrecover` rejects a signature whose
881 // restored x-coordinate `r + n` is not below the field modulus, instead
882 // of wrapping it at 2^256.
883 #[serde(skip_serializing_if = "is_false")]
884 secp256r1_ecrecover_checks_x_below_p: bool,
885
886 // If true, a programmable transaction may carry a transaction dependency
887 // input. It executes after the named transaction, and fails without running
888 // its commands if that transaction failed.
889 #[serde(skip_serializing_if = "is_false")]
890 enable_transaction_dependencies: bool,
891
892 // If true, enables the authentication with built-in Move authenticators.
893 #[serde(skip_serializing_if = "is_false")]
894 enable_builtin_move_authenticators: bool,
895
896 // If true, the `ClaimAccount` user transaction kind is accepted. It creates an
897 // account object whose id is the sender's address, so a usable account also
898 // requires `enable_builtin_move_authenticators`.
899 #[serde(skip_serializing_if = "is_false")]
900 enable_claim_account_transaction: bool,
901
902 // If true, `smart_account::builder_v1` and a smart account `ClaimAccount` create a
903 // `SmartAccount`; otherwise they abort.
904 #[serde(skip_serializing_if = "is_false")]
905 enable_smart_accounts: bool,
906}
907
908fn is_true(b: &bool) -> bool {
909 *b
910}
911
912fn is_false(b: &bool) -> bool {
913 !b
914}
915
916/// Ordering mechanism for transactions in one consensus output.
917#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
918pub enum ConsensusTransactionOrdering {
919 /// No ordering. Transactions are processed in the order they appear in the
920 /// consensus output.
921 #[default]
922 None,
923 /// Order transactions by gas price, highest first.
924 ByGasPrice,
925}
926
927impl ConsensusTransactionOrdering {
928 pub fn is_none(&self) -> bool {
929 matches!(self, ConsensusTransactionOrdering::None)
930 }
931}
932
933// The config for per object congestion control in consensus handler.
934#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
935pub enum PerObjectCongestionControlMode {
936 #[default]
937 None, // No congestion control.
938 TotalGasBudget, // Use txn gas budget as execution cost.
939 TotalTxCount, // Use total txn count as execution cost.
940 TotalComputationUnits, // Use attested computation units as execution cost.
941}
942
943impl PerObjectCongestionControlMode {
944 pub fn is_none(&self) -> bool {
945 matches!(self, PerObjectCongestionControlMode::None)
946 }
947}
948
949// Configuration options for consensus algorithm.
950#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
951pub enum ConsensusChoice {
952 /// Kept only so protocol-config serialization of historical epochs stays
953 /// bit-for-bit identical; no runtime code branches on it.
954 #[deprecated(note = "Mysticeti was replaced by Starfish")]
955 MysticetiDeprecated,
956 #[default]
957 Starfish,
958}
959
960#[expect(deprecated)]
961impl ConsensusChoice {
962 /// serde deserialization default: an absent `consensus_choice` field in a
963 /// historical snapshot deserializes to `MysticetiDeprecated` so that
964 /// re-serialization stays byte-identical (the skip condition below also
965 /// triggers on that variant). Decoupled from the Rust `Default` impl,
966 /// which returns `Starfish` to reflect that Starfish is the current
967 /// consensus protocol.
968 fn mysticeti_deprecated() -> Self {
969 ConsensusChoice::MysticetiDeprecated
970 }
971
972 pub fn is_mysticeti_deprecated(&self) -> bool {
973 matches!(self, ConsensusChoice::MysticetiDeprecated)
974 }
975 pub fn is_starfish(&self) -> bool {
976 matches!(self, ConsensusChoice::Starfish)
977 }
978}
979
980// Configuration options for consensus network.
981#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
982pub enum ConsensusNetwork {
983 #[default]
984 Tonic,
985}
986
987impl ConsensusNetwork {
988 pub fn is_tonic(&self) -> bool {
989 matches!(self, ConsensusNetwork::Tonic)
990 }
991}
992
993/// Constants that change the behavior of the protocol.
994///
995/// The value of each constant here must be fixed for a given protocol version.
996/// To change the value of a constant, advance the protocol version, and add
997/// support for it in `get_for_version` under the new version number.
998/// (below).
999///
1000/// To add a new field to this struct, use the following procedure:
1001/// - Advance the protocol version.
1002/// - Add the field as a private `Option<T>` to the struct.
1003/// - Initialize the field to `None` in prior protocol versions.
1004/// - Initialize the field to `Some(val)` for your new protocol version.
1005/// - Add a public getter that simply unwraps the field.
1006/// - Two public getters of the form `field(&self) -> field_type` and `field_as_option(&self) ->
1007/// Option<field_type>` will be automatically generated for you.
1008/// Example for a field: `new_constant: Option<u64>`
1009/// ```rust,ignore
1010/// pub fn new_constant(&self) -> u64 {
1011/// self.new_constant.expect(Self::CONSTANT_ERR_MSG)
1012/// }
1013/// pub fn new_constant_as_option(&self) -> Option<u64> {
1014/// self.new_constant.expect(Self::CONSTANT_ERR_MSG)
1015/// }
1016/// ```
1017/// With `pub fn new_constant(&self) -> u64`, if the constant is accessed in a
1018/// protocol version in which it is not defined, the validator will crash.
1019/// (Crashing is necessary because this type of error would almost always result
1020/// in forking if not prevented here). If you don't want the validator to crash,
1021/// you can use the `pub fn new_constant_as_option(&self) -> Option<u64>`
1022/// getter, which will return `None` if the field is not defined at that
1023/// version.
1024/// - If you want a customized getter, you can add a method in the impl.
1025#[skip_serializing_none]
1026#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
1027pub struct ProtocolConfig {
1028 pub version: ProtocolVersion,
1029
1030 feature_flags: FeatureFlags,
1031
1032 // ==== Transaction input limits ====
1033
1034 //
1035 /// Maximum serialized size of a transaction (in bytes).
1036 max_tx_size_bytes: Option<u64>,
1037
1038 /// Maximum number of input objects to a transaction. Enforced by the
1039 /// transaction input checker. Pure inputs do not count towards it; all
1040 /// inputs together cannot exceed
1041 /// `iota_types::transaction::MAX_PROGRAMMABLE_TX_INPUTS`.
1042 max_input_objects: Option<u64>,
1043
1044 /// Max size of objects a transaction can write to disk after completion.
1045 /// Enforce by the IOTA adapter. This is the sum of the serialized size
1046 /// of all objects written to disk. The max size of individual objects
1047 /// on the other hand is `max_move_object_size`.
1048 max_size_written_objects: Option<u64>,
1049 /// Max size of objects a system transaction can write to disk after
1050 /// completion. Enforce by the IOTA adapter. Similar to
1051 /// `max_size_written_objects` but for system transactions.
1052 max_size_written_objects_system_tx: Option<u64>,
1053
1054 /// Maximum size of serialized transaction effects.
1055 max_serialized_tx_effects_size_bytes: Option<u64>,
1056
1057 /// Maximum size of serialized transaction effects for system transactions.
1058 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
1059
1060 /// Maximum number of gas payment objects for a transaction.
1061 max_gas_payment_objects: Option<u32>,
1062
1063 /// Maximum number of modules in a Publish transaction.
1064 max_modules_in_publish: Option<u32>,
1065
1066 /// Maximum number of transitive dependencies in a package when publishing.
1067 max_package_dependencies: Option<u32>,
1068
1069 /// Maximum number of arguments in a move call or a
1070 /// ProgrammableTransaction's TransferObjects command.
1071 max_arguments: Option<u32>,
1072
1073 /// Maximum number of total type arguments, computed recursively.
1074 max_type_arguments: Option<u32>,
1075
1076 /// Maximum depth of an individual type argument.
1077 max_type_argument_depth: Option<u32>,
1078
1079 /// Maximum size of a Pure CallArg.
1080 max_pure_argument_size: Option<u32>,
1081
1082 /// Maximum number of Commands in a ProgrammableTransaction.
1083 max_programmable_tx_commands: Option<u32>,
1084
1085 // ==== Move VM, Move bytecode verifier, and execution limits ===
1086
1087 //
1088 /// Maximum Move bytecode version the VM understands. All older versions are
1089 /// accepted.
1090 move_binary_format_version: Option<u32>,
1091 min_move_binary_format_version: Option<u32>,
1092
1093 /// Configuration controlling binary tables size.
1094 binary_module_handles: Option<u16>,
1095 binary_struct_handles: Option<u16>,
1096 binary_function_handles: Option<u16>,
1097 binary_function_instantiations: Option<u16>,
1098 binary_signatures: Option<u16>,
1099 binary_constant_pool: Option<u16>,
1100 binary_identifiers: Option<u16>,
1101 binary_address_identifiers: Option<u16>,
1102 binary_struct_defs: Option<u16>,
1103 binary_struct_def_instantiations: Option<u16>,
1104 binary_function_defs: Option<u16>,
1105 binary_field_handles: Option<u16>,
1106 binary_field_instantiations: Option<u16>,
1107 binary_friend_decls: Option<u16>,
1108 binary_enum_defs: Option<u16>,
1109 binary_enum_def_instantiations: Option<u16>,
1110 binary_variant_handles: Option<u16>,
1111 binary_variant_instantiation_handles: Option<u16>,
1112
1113 /// Maximum size of the `contents` part of an object, in bytes. Enforced by
1114 /// the IOTA adapter when effects are produced.
1115 max_move_object_size: Option<u64>,
1116
1117 // TODO: Option<increase to 500 KB. currently, publishing a package > 500 KB exceeds the max
1118 // computation gas cost
1119 /// Maximum size of a Move package object, in bytes. Enforced by the IOTA
1120 /// adapter at the end of a publish transaction.
1121 max_move_package_size: Option<u64>,
1122
1123 /// Max number of publish or upgrade commands allowed in a programmable
1124 /// transaction block.
1125 max_publish_or_upgrade_per_ptb: Option<u64>,
1126
1127 /// Maximum gas budget in NANOS that a transaction can use.
1128 max_tx_gas: Option<u64>,
1129
1130 /// Maximum gas budget in NANOS that a authentication transaction can use.
1131 max_auth_gas: Option<u64>,
1132
1133 /// Maximum amount of the proposed gas price in NANOS (defined in the
1134 /// transaction).
1135 max_gas_price: Option<u64>,
1136
1137 /// The max computation bucket for gas. This is the max that can be charged
1138 /// for computation.
1139 max_gas_computation_bucket: Option<u64>,
1140
1141 // Define the value used to round up computation gas charges
1142 gas_rounding_step: Option<u64>,
1143
1144 /// Maximum number of nested loops. Enforced by the Move bytecode verifier.
1145 max_loop_depth: Option<u64>,
1146
1147 /// Maximum number of type arguments that can be bound to generic type
1148 /// parameters. Enforced by the Move bytecode verifier.
1149 max_generic_instantiation_length: Option<u64>,
1150
1151 /// Maximum number of parameters that a Move function can have. Enforced by
1152 /// the Move bytecode verifier.
1153 max_function_parameters: Option<u64>,
1154
1155 /// Maximum number of basic blocks that a Move function can have. Enforced
1156 /// by the Move bytecode verifier.
1157 max_basic_blocks: Option<u64>,
1158
1159 /// Maximum stack size value. Enforced by the Move bytecode verifier.
1160 max_value_stack_size: Option<u64>,
1161
1162 /// Maximum number of "type nodes", a metric for how big a SignatureToken
1163 /// will be when expanded into a fully qualified type. Enforced by the Move
1164 /// bytecode verifier.
1165 max_type_nodes: Option<u64>,
1166
1167 /// Maximum number of push instructions in one function. Enforced by the
1168 /// Move bytecode verifier.
1169 max_push_size: Option<u64>,
1170
1171 /// Maximum number of struct definitions in a module. Enforced by the Move
1172 /// bytecode verifier.
1173 max_struct_definitions: Option<u64>,
1174
1175 /// Maximum number of function definitions in a module. Enforced by the Move
1176 /// bytecode verifier.
1177 max_function_definitions: Option<u64>,
1178
1179 /// Maximum number of fields allowed in a struct definition. Enforced by the
1180 /// Move bytecode verifier.
1181 max_fields_in_struct: Option<u64>,
1182
1183 /// Maximum dependency depth. Enforced by the Move linker when loading
1184 /// dependent modules.
1185 max_dependency_depth: Option<u64>,
1186
1187 /// Maximum number of Move events that a single transaction can emit.
1188 /// Enforced by the VM during execution.
1189 max_num_event_emit: Option<u64>,
1190
1191 /// Maximum number of new IDs that a single transaction can create. Enforced
1192 /// by the VM during execution.
1193 max_num_new_move_object_ids: Option<u64>,
1194
1195 /// Maximum number of new IDs that a single system transaction can create.
1196 /// Enforced by the VM during execution.
1197 max_num_new_move_object_ids_system_tx: Option<u64>,
1198
1199 /// Maximum number of IDs that a single transaction can delete. Enforced by
1200 /// the VM during execution.
1201 max_num_deleted_move_object_ids: Option<u64>,
1202
1203 /// Maximum number of IDs that a single system transaction can delete.
1204 /// Enforced by the VM during execution.
1205 max_num_deleted_move_object_ids_system_tx: Option<u64>,
1206
1207 /// Maximum number of IDs that a single transaction can transfer. Enforced
1208 /// by the VM during execution.
1209 max_num_transferred_move_object_ids: Option<u64>,
1210
1211 /// Maximum number of IDs that a single system transaction can transfer.
1212 /// Enforced by the VM during execution.
1213 max_num_transferred_move_object_ids_system_tx: Option<u64>,
1214
1215 /// Maximum size of a Move user event. Enforced by the VM during execution.
1216 max_event_emit_size: Option<u64>,
1217
1218 /// Maximum size of a Move user event. Enforced by the VM during execution.
1219 max_event_emit_size_total: Option<u64>,
1220
1221 /// Maximum length of a vector in Move. Enforced by the VM during execution,
1222 /// and for constants, by the verifier.
1223 max_move_vector_len: Option<u64>,
1224
1225 /// Maximum length of an `Identifier` in Move. Enforced by the bytecode
1226 /// verifier at signing.
1227 max_move_identifier_len: Option<u64>,
1228
1229 /// Maximum depth of a Move value within the VM.
1230 max_move_value_depth: Option<u64>,
1231
1232 /// Maximum number of struct, enum and vector values in the arguments of
1233 /// one Move call.
1234 max_move_call_argument_nodes: Option<u64>,
1235
1236 /// Maximum number of struct, enum and vector values in the arguments of
1237 /// all Move calls of one programmable transaction.
1238 max_move_call_argument_nodes_total: Option<u64>,
1239
1240 /// Maximum number of variants in an enum. Enforced by the bytecode verifier
1241 /// at signing.
1242 max_move_enum_variants: Option<u64>,
1243
1244 // === Metered bytecode verifier limits ===
1245 // Enforced on the packages a transaction publishes when post-consensus
1246 // validation checks them.
1247 // Signing, admission and simulation are validator-local decisions and use
1248 // each validator's own `VerifierSigningConfig` instead.
1249
1250 //
1251 /// Maximum number of back edges in a Move function.
1252 max_back_edges_per_function: Option<u64>,
1253
1254 /// Maximum number of back edges in a Move module.
1255 max_back_edges_per_module: Option<u64>,
1256
1257 /// Maximum number of meter `ticks` spent verifying a Move function.
1258 max_verifier_meter_ticks_per_function: Option<u64>,
1259
1260 /// Maximum number of meter `ticks` spent verifying a Move module.
1261 max_meter_ticks_per_module: Option<u64>,
1262
1263 /// Maximum number of meter `ticks` spent verifying a Move package.
1264 max_meter_ticks_per_package: Option<u64>,
1265
1266 /// Maximum number of meter `ticks` the regex-based reference safety check
1267 /// may spend per function, module and package. The check rejects a module
1268 /// it cannot finish within the limit.
1269 max_meter_ticks_regex_reference_safety: Option<u64>,
1270
1271 /// Maximum number of edges in the instantiation-loop graph of a Move
1272 /// module, checked only by post-consensus validation. Signing uses a limit
1273 /// set in the binary instead, and execution does not check it.
1274 max_instantiation_loop_graph_edges: Option<u64>,
1275
1276 // === Object runtime internal operation limits ====
1277 // These affect dynamic fields
1278
1279 //
1280 /// Maximum number of cached objects in the object runtime ObjectStore.
1281 /// Enforced by object runtime during execution
1282 object_runtime_max_num_cached_objects: Option<u64>,
1283
1284 /// Maximum number of cached objects in the object runtime ObjectStore in
1285 /// system transaction. Enforced by object runtime during execution
1286 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
1287
1288 /// Maximum number of stored objects accessed by object runtime ObjectStore.
1289 /// Enforced by object runtime during execution
1290 object_runtime_max_num_store_entries: Option<u64>,
1291
1292 /// Maximum number of stored objects accessed by object runtime ObjectStore
1293 /// in system transaction. Enforced by object runtime during execution
1294 object_runtime_max_num_store_entries_system_tx: Option<u64>,
1295
1296 // === Execution gas costs ====
1297
1298 //
1299 /// Base cost for any IOTA transaction
1300 base_tx_cost_fixed: Option<u64>,
1301
1302 /// Additional cost for a transaction that publishes a package
1303 /// i.e., the base cost of such a transaction is base_tx_cost_fixed +
1304 /// package_publish_cost_fixed
1305 package_publish_cost_fixed: Option<u64>,
1306
1307 /// Cost per byte of a Move call transaction
1308 /// i.e., the cost of such a transaction is base_cost +
1309 /// (base_tx_cost_per_byte * size)
1310 base_tx_cost_per_byte: Option<u64>,
1311
1312 /// Cost per byte for a transaction that publishes a package
1313 package_publish_cost_per_byte: Option<u64>,
1314
1315 // Per-byte cost of reading an object during transaction execution
1316 obj_access_cost_read_per_byte: Option<u64>,
1317
1318 // Per-byte cost of writing an object during transaction execution
1319 obj_access_cost_mutate_per_byte: Option<u64>,
1320
1321 // Per-byte cost of deleting an object during transaction execution
1322 obj_access_cost_delete_per_byte: Option<u64>,
1323
1324 /// Per-byte cost charged for each input object to a transaction.
1325 /// Meant to approximate the cost of checking locks for each object
1326 // TODO: Option<I'm not sure that this cost makes sense. Checking locks is "free"
1327 // in the sense that an invalid tx that can never be committed/pay gas can
1328 // force validators to check an arbitrary number of locks. If those checks are
1329 // "free" for invalid transactions, why charge for them in valid transactions
1330 // TODO: Option<if we keep this, I think we probably want it to be a fixed cost rather
1331 // than a per-byte cost. checking an object lock should not require loading an
1332 // entire object, just consulting an ID -> tx digest map
1333 obj_access_cost_verify_per_byte: Option<u64>,
1334
1335 // Maximal nodes which are allowed when converting to a type layout.
1336 max_type_to_layout_nodes: Option<u64>,
1337
1338 // Maximal size in bytes that a PTB value can be
1339 max_ptb_value_size: Option<u64>,
1340
1341 // === Gas version. gas model ===
1342
1343 //
1344 /// Gas model version, what code we are using to charge gas
1345 gas_model_version: Option<u64>,
1346
1347 // === Storage gas costs ===
1348
1349 //
1350 /// Per-byte cost of storing an object in the IOTA global object store. Some
1351 /// of this cost may be refundable if the object is later freed
1352 obj_data_cost_refundable: Option<u64>,
1353
1354 // Per-byte cost of storing an object in the IOTA transaction log (e.g., in
1355 // CertifiedTransactionEffects) This depends on the size of various fields including the
1356 // effects TODO: Option<I don't fully understand this^ and more details would be useful
1357 obj_metadata_cost_non_refundable: Option<u64>,
1358
1359 // === Tokenomics ===
1360
1361 // TODO: Option<this should be changed to u64.
1362 /// Sender of a txn that touches an object will get this percent of the
1363 /// storage rebate back. In basis point.
1364 storage_rebate_rate: Option<u64>,
1365
1366 /// The share of rewards that will be slashed and redistributed is 50%.
1367 /// In basis point.
1368 reward_slashing_rate: Option<u64>,
1369
1370 /// Unit storage gas price, Nanos per internal gas unit.
1371 storage_gas_price: Option<u64>,
1372
1373 // Base gas price for computation gas, nanos per computation unit.
1374 base_gas_price: Option<u64>,
1375
1376 /// The number of tokens minted as a validator subsidy per epoch.
1377 validator_target_reward: Option<u64>,
1378
1379 // === Core Protocol ===
1380
1381 //
1382 /// Max number of transactions per checkpoint.
1383 /// Note that this is a protocol constant and not a config as validators
1384 /// must have this set to the same value, otherwise they *will* fork.
1385 max_transactions_per_checkpoint: Option<u64>,
1386
1387 /// Max size of a checkpoint in bytes.
1388 /// Note that this is a protocol constant and not a config as validators
1389 /// must have this set to the same value, otherwise they *will* fork.
1390 max_checkpoint_size_bytes: Option<u64>,
1391
1392 /// A protocol upgrade always requires 2f+1 stake to agree. We support a
1393 /// buffer of additional stake (as a fraction of f, expressed in basis
1394 /// points) that is required before an upgrade can happen automatically.
1395 /// 10000bps would indicate that complete unanimity is required (all
1396 /// 3f+1 must vote), while 0bps would indicate that 2f+1 is sufficient.
1397 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
1398
1399 // === Native Function Costs ===
1400
1401 // `address` module
1402 // Cost params for the Move native function `address::from_bytes(bytes: vector<u8>)`
1403 address_from_bytes_cost_base: Option<u64>,
1404 // Cost params for the Move native function `address::to_u256(address): u256`
1405 address_to_u256_cost_base: Option<u64>,
1406 // Cost params for the Move native function `address::from_u256(u256): address`
1407 address_from_u256_cost_base: Option<u64>,
1408
1409 // `config` module
1410 // Cost params for the Move native function `read_setting_impl<Name: copy + drop + store,
1411 // SettingValue: key + store, SettingDataValue: store, Value: copy + drop + store,
1412 // >(config: address, name: address, current_epoch: u64): Option<Value>`
1413 config_read_setting_impl_cost_base: Option<u64>,
1414 config_read_setting_impl_cost_per_byte: Option<u64>,
1415
1416 // `dynamic_field` module
1417 // Cost params for the Move native function `hash_type_and_key<K: copy + drop + store>(parent:
1418 // address, k: K): address`
1419 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
1420 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
1421 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
1422 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
1423 // Cost params for the Move native function `add_child_object<Child: key>(parent: address,
1424 // child: Child)`
1425 dynamic_field_add_child_object_cost_base: Option<u64>,
1426 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
1427 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
1428 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
1429 // Cost params for the Move native function `borrow_child_object_mut<Child: key>(parent: &mut
1430 // UID, id: address): &mut Child`
1431 dynamic_field_borrow_child_object_cost_base: Option<u64>,
1432 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1433 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1434 // Cost params for the Move native function `remove_child_object<Child: key>(parent: address,
1435 // id: address): Child`
1436 dynamic_field_remove_child_object_cost_base: Option<u64>,
1437 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1438 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1439 // Cost params for the Move native function `has_child_object(parent: address, id: address):
1440 // bool`
1441 dynamic_field_has_child_object_cost_base: Option<u64>,
1442 // Cost params for the Move native function `has_child_object_with_ty<Child: key>(parent:
1443 // address, id: address): bool`
1444 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1445 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1446 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1447
1448 // `event` module
1449 // Cost params for the Move native function `event::emit<T: copy + drop>(event: T)`
1450 event_emit_cost_base: Option<u64>,
1451 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1452 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1453 event_emit_output_cost_per_byte: Option<u64>,
1454
1455 // `object` module
1456 // Cost params for the Move native function `borrow_uid<T: key>(obj: &T): &UID`
1457 object_borrow_uid_cost_base: Option<u64>,
1458 // Cost params for the Move native function `delete_impl(id: address)`
1459 object_delete_impl_cost_base: Option<u64>,
1460 // Cost params for the Move native function `record_new_uid(id: address)`
1461 object_record_new_uid_cost_base: Option<u64>,
1462
1463 // Transfer
1464 // Cost params for the Move native function `transfer_impl<T: key>(obj: T, recipient: address)`
1465 transfer_transfer_internal_cost_base: Option<u64>,
1466 // Cost params for the Move native function `freeze_object<T: key>(obj: T)`
1467 transfer_freeze_object_cost_base: Option<u64>,
1468 // Cost params for the Move native function `share_object<T: key>(obj: T)`
1469 transfer_share_object_cost_base: Option<u64>,
1470 // Cost params for the Move native function
1471 // `receive_object<T: key>(p: &mut UID, recv: Receiving<T>T)`
1472 transfer_receive_object_cost_base: Option<u64>,
1473
1474 // TxContext
1475 // Cost params for the Move native function `transfer_impl<T: key>(obj: T, recipient: address)`
1476 tx_context_derive_id_cost_base: Option<u64>,
1477 tx_context_fresh_id_cost_base: Option<u64>,
1478 tx_context_sender_cost_base: Option<u64>,
1479 tx_context_digest_cost_base: Option<u64>,
1480 tx_context_epoch_cost_base: Option<u64>,
1481 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1482 tx_context_sponsor_cost_base: Option<u64>,
1483 tx_context_rgp_cost_base: Option<u64>,
1484 tx_context_gas_price_cost_base: Option<u64>,
1485 tx_context_gas_budget_cost_base: Option<u64>,
1486 tx_context_ids_created_cost_base: Option<u64>,
1487 tx_context_replace_cost_base: Option<u64>,
1488 // Cost param for the Move native function `tx_context::native_tx_nonce(): vector<u8>`
1489 tx_context_tx_nonce_cost_base: Option<u64>,
1490 // Cost param for the Move native function
1491 // `smart_account_builtin_authenticator::key_proof_message(chain_identifier: vector<u8>,
1492 // account: address, new_account: bool, nonce: vector<u8>, valid_until_epoch: u64):
1493 // vector<u8>`
1494 smart_account_builtin_authenticator_key_proof_message_cost_base: Option<u64>,
1495
1496 // Types
1497 // Cost params for the Move native function `is_one_time_witness<T: drop>(_: &T): bool`
1498 types_is_one_time_witness_cost_base: Option<u64>,
1499 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1500 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1501
1502 // Validator
1503 // Cost params for the Move native function `validate_metadata_bcs(metadata: vector<u8>)`
1504 validator_validate_metadata_cost_base: Option<u64>,
1505 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1506
1507 // Crypto natives
1508 crypto_invalid_arguments_cost: Option<u64>,
1509 // bls12381::bls12381_min_sig_verify
1510 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1511 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1512 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1513
1514 // bls12381::bls12381_min_pk_verify
1515 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1516 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1517 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1518
1519 // ecdsa_k1::ecrecover
1520 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1521 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1522 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1523 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1524 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1525 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1526
1527 // ecdsa_k1::decompress_pubkey
1528 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1529
1530 // ecdsa_k1::secp256k1_verify
1531 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1532 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1533 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1534 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1535 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1536 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1537
1538 // ecdsa_r1::ecrecover
1539 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1540 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1541 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1542 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1543 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1544 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1545
1546 // ecdsa_r1::secp256k1_verify
1547 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1548 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1549 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1550 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1551 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1552 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1553
1554 // ecvrf::verify
1555 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1556 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1557 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1558
1559 // ed25519
1560 ed25519_ed25519_verify_cost_base: Option<u64>,
1561 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1562 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1563
1564 // groth16::prepare_verifying_key
1565 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1566 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1567
1568 // groth16::verify_groth16_proof_internal
1569 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1570 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1571 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1572 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1573 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1574
1575 // hash::blake2b256
1576 hash_blake2b256_cost_base: Option<u64>,
1577 hash_blake2b256_data_cost_per_byte: Option<u64>,
1578 hash_blake2b256_data_cost_per_block: Option<u64>,
1579
1580 // hash::keccak256
1581 hash_keccak256_cost_base: Option<u64>,
1582 hash_keccak256_data_cost_per_byte: Option<u64>,
1583 hash_keccak256_data_cost_per_block: Option<u64>,
1584
1585 // poseidon::poseidon_bn254
1586 poseidon_bn254_cost_base: Option<u64>,
1587 poseidon_bn254_cost_per_block: Option<u64>,
1588
1589 // group_ops
1590 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1591 group_ops_bls12381_decode_g1_cost: Option<u64>,
1592 group_ops_bls12381_decode_g2_cost: Option<u64>,
1593 group_ops_bls12381_decode_gt_cost: Option<u64>,
1594 group_ops_bls12381_scalar_add_cost: Option<u64>,
1595 group_ops_bls12381_g1_add_cost: Option<u64>,
1596 group_ops_bls12381_g2_add_cost: Option<u64>,
1597 group_ops_bls12381_gt_add_cost: Option<u64>,
1598 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1599 group_ops_bls12381_g1_sub_cost: Option<u64>,
1600 group_ops_bls12381_g2_sub_cost: Option<u64>,
1601 group_ops_bls12381_gt_sub_cost: Option<u64>,
1602 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1603 group_ops_bls12381_g1_mul_cost: Option<u64>,
1604 group_ops_bls12381_g2_mul_cost: Option<u64>,
1605 group_ops_bls12381_gt_mul_cost: Option<u64>,
1606 group_ops_bls12381_scalar_div_cost: Option<u64>,
1607 group_ops_bls12381_g1_div_cost: Option<u64>,
1608 group_ops_bls12381_g2_div_cost: Option<u64>,
1609 group_ops_bls12381_gt_div_cost: Option<u64>,
1610 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1611 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1612 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1613 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1614 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1615 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1616 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1617 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1618 group_ops_bls12381_msm_max_len: Option<u32>,
1619 group_ops_bls12381_pairing_cost: Option<u64>,
1620 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1621 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1622 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1623 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1624 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1625
1626 // hmac::hmac_sha3_256
1627 hmac_hmac_sha3_256_cost_base: Option<u64>,
1628 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1629 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1630
1631 // zklogin::check_zklogin_id
1632 #[deprecated]
1633 check_zklogin_id_cost_base: Option<u64>,
1634 // zklogin::check_zklogin_issuer
1635 #[deprecated]
1636 check_zklogin_issuer_cost_base: Option<u64>,
1637
1638 vdf_verify_vdf_cost: Option<u64>,
1639 vdf_hash_to_input_cost: Option<u64>,
1640
1641 // Stdlib costs
1642 bcs_per_byte_serialized_cost: Option<u64>,
1643 bcs_legacy_min_output_size_cost: Option<u64>,
1644 bcs_failure_cost: Option<u64>,
1645
1646 hash_sha2_256_base_cost: Option<u64>,
1647 hash_sha2_256_per_byte_cost: Option<u64>,
1648 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1649 hash_sha3_256_base_cost: Option<u64>,
1650 hash_sha3_256_per_byte_cost: Option<u64>,
1651 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1652 type_name_get_base_cost: Option<u64>,
1653 type_name_get_per_byte_cost: Option<u64>,
1654
1655 string_check_utf8_base_cost: Option<u64>,
1656 string_check_utf8_per_byte_cost: Option<u64>,
1657 string_is_char_boundary_base_cost: Option<u64>,
1658 string_sub_string_base_cost: Option<u64>,
1659 string_sub_string_per_byte_cost: Option<u64>,
1660 string_index_of_base_cost: Option<u64>,
1661 string_index_of_per_byte_pattern_cost: Option<u64>,
1662 string_index_of_per_byte_searched_cost: Option<u64>,
1663
1664 vector_empty_base_cost: Option<u64>,
1665 vector_length_base_cost: Option<u64>,
1666 vector_push_back_base_cost: Option<u64>,
1667 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1668 vector_borrow_base_cost: Option<u64>,
1669 vector_pop_back_base_cost: Option<u64>,
1670 vector_destroy_empty_base_cost: Option<u64>,
1671 vector_swap_base_cost: Option<u64>,
1672 debug_print_base_cost: Option<u64>,
1673 debug_print_stack_trace_base_cost: Option<u64>,
1674
1675 // === Execution Version ===
1676 execution_version: Option<u64>,
1677
1678 // Dictates the threshold (percentage of stake) that is used to calculate the "bad" nodes to be
1679 // swapped when creating the consensus schedule. The values should be of the range [0 - 33].
1680 // Anything above 33 (f) will not be allowed.
1681 consensus_bad_nodes_stake_threshold: Option<u64>,
1682
1683 #[deprecated]
1684 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1685 // The maximum age of a JWK in epochs before it is removed from the AuthenticatorState object.
1686 // Applied at the end of an epoch as a delta from the new epoch value, so setting this to 1
1687 // will cause the new epoch to start with JWKs from the previous epoch still valid.
1688 #[deprecated]
1689 max_age_of_jwk_in_epochs: Option<u64>,
1690
1691 // === random beacon ===
1692 /// Maximum allowed precision loss when reducing voting weights for the
1693 /// random beacon protocol.
1694 random_beacon_reduction_allowed_delta: Option<u16>,
1695
1696 /// Minimum number of shares below which voting weights will not be reduced
1697 /// for the random beacon protocol.
1698 random_beacon_reduction_lower_bound: Option<u32>,
1699
1700 /// Consensus Round after which DKG should be aborted and randomness
1701 /// disabled for the epoch, if it hasn't already completed.
1702 random_beacon_dkg_timeout_round: Option<u32>,
1703
1704 /// Minimum interval between consecutive rounds of generated randomness.
1705 random_beacon_min_round_interval_ms: Option<u64>,
1706
1707 /// Version of the random beacon DKG protocol.
1708 /// 0 was deprecated (and currently not supported), 1 is the default
1709 /// version.
1710 random_beacon_dkg_version: Option<u64>,
1711
1712 /// The maximum serialized transaction size (in bytes) accepted by
1713 /// consensus. `consensus_max_transaction_size_bytes` should include
1714 /// space for additional metadata, on top of the `max_tx_size_bytes`
1715 /// value.
1716 consensus_max_transaction_size_bytes: Option<u64>,
1717 /// The maximum size of transactions included in a consensus block.
1718 consensus_max_transactions_in_block_bytes: Option<u64>,
1719 /// The maximum number of transactions included in a consensus block.
1720 consensus_max_num_transactions_in_block: Option<u64>,
1721
1722 /// The max number of consensus rounds a transaction can be deferred due to
1723 /// shared object congestion. Transactions will be cancelled after this
1724 /// many rounds.
1725 max_deferral_rounds_for_congestion_control: Option<u64>,
1726
1727 /// Minimum interval of commit timestamps between consecutive checkpoints.
1728 min_checkpoint_interval_ms: Option<u64>,
1729
1730 /// Number of recent checkpoints over which `min_checkpoint_interval_ms`
1731 /// may be amortized. When set, a checkpoint is built once the full
1732 /// interval elapsed since the previous checkpoint, or once the checkpoint
1733 /// this many back in the current epoch is at least that many intervals
1734 /// older. The windowed arm recycles the slack that discrete commit
1735 /// timestamps add to the strict arm, holding the sustained rate at the
1736 /// ceiling, while the strict arm keeps quiet gaps within one interval.
1737 /// The window does not cross epoch boundaries; before it fills — and
1738 /// always when unset — only the strict adjacent check applies.
1739 checkpoint_rate_window_size: Option<u64>,
1740
1741 /// Version number to use for version_specific_data in `CheckpointSummary`.
1742 /// 2 adds the attestation entries and totals and is required by
1743 /// `enable_validator_attestation`.
1744 checkpoint_summary_version_specific_data: Option<u64>,
1745
1746 /// Tolerance, in percent of the executed computation units, within which
1747 /// an attestor's claimed units count as accurate. Both sides are rounded
1748 /// up to `gas_rounding_step` and capped at the budget on out-of-gas, and
1749 /// the check only applies when the transaction body ran. Unset disables
1750 /// it.
1751 attestor_accuracy_tolerance_percentage: Option<u64>,
1752
1753 /// Sum of the squared wasted authentication units of an attestor's refuted
1754 /// attestations at which the cut takes its whole epoch reward, through its
1755 /// entry in the change-epoch scores: one fault of √value units takes it
1756 /// all, one of half that size a quarter; 0 takes the whole reward on the
1757 /// first refuted attestation. The cut reaches the reward only under
1758 /// `adjust_rewards_by_score`. An attestor whose sum reaches it has its
1759 /// attested transactions dropped at post-consensus validation for the rest
1760 /// of the epoch. Unset disables the penalty and the cutoff.
1761 attestation_max_refuted_units_squared: Option<u64>,
1762
1763 /// How many commits before the one an attested transaction was first
1764 /// sequenced in a recorded version may have stopped being current for the
1765 /// judge to re-run authentication at it; leader rounds for a version a
1766 /// commit prologue or a deny-rules update superseded, the only position
1767 /// those carry. Unset admits any commit of the epoch.
1768 attestation_freshness_window_commits: Option<u64>,
1769
1770 /// The max number of transactions that can be included in a single Soft
1771 /// Bundle.
1772 max_soft_bundle_size: Option<u64>,
1773
1774 /// Deprecated because of bridge removal.
1775 /// Whether to try to form bridge committee
1776 // Note: this is not a feature flag because we want to distinguish between
1777 // `None` and `Some(false)`, as committee was already finalized on Testnet.
1778 bridge_should_try_to_finalize_committee: Option<bool>,
1779
1780 /// The max accumulated txn execution cost per object in a mysticeti commit.
1781 /// Transactions in a commit will be deferred once their touch shared
1782 /// objects hit this limit. Note that if
1783 /// `max_congestion_limit_overshoot_per_commit` is set, this may be overshot
1784 /// within a single commit, but the limit will be enforced in the long run.
1785 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1786
1787 /// Maximum number of committee (validators taking part in consensus)
1788 /// validators at any moment. We do not allow the number of committee
1789 /// validators in any epoch to go above this.
1790 max_committee_members_count: Option<u64>,
1791
1792 /// Maximum number of added plus removed entries one injected
1793 /// `TransactionDenyRulesUpdate` transaction may carry; a larger diff is
1794 /// split into multiple transactions in the same commit. Required by
1795 /// `enable_pcool_flow` from protocol version 39.
1796 deny_rule_update_max_entries_per_tx: Option<u64>,
1797
1798 /// Configures the garbage collection depth for consensus. When is unset or
1799 /// `0` then the garbage collection is disabled.
1800 consensus_gc_depth: Option<u32>,
1801
1802 /// Configures the maximum number of acknowledgments to be included in a
1803 /// block. It must be reasonably larger than the number of validators
1804 /// because not all validators create their blocks at the same pace.
1805 /// Default value set to 400. (5 x expected committee size (80)).
1806 /// Applicable only to `starfish` consensus.
1807 consensus_max_acknowledgments_per_block: Option<u32>,
1808
1809 /// The maximum amount that is allowed to overshoot the congestion limit
1810 /// specified by 'max_accumulated_txn_cost_per_object_in_mysticeti_commit'
1811 /// for any single commit. Any overshoot is tracked as a debt that must
1812 /// be accounted for in subsequent commits.
1813 max_congestion_limit_overshoot_per_commit: Option<u64>,
1814
1815 /// Maximum number of transactions from a single consensus commit that may
1816 /// be scheduled to execute concurrently (the execution-worker pool size).
1817 /// `Some` activates execution-worker congestion control, under which
1818 /// owned-object-only transactions are also scheduled, deferred and shed
1819 /// by the congestion tracker; `None` disables it. Must be positive when
1820 /// set. Requires `enable_pcool_flow`.
1821 max_concurrent_execution_workers: Option<u16>,
1822
1823 /// How many consensus commits back post-consensus validation reads object
1824 /// state. Validating a transaction in commit C reads object state as of
1825 /// commit C - K, where K is this distance; that commit is the horizon of
1826 /// C, and it must be fully executed before C is validated. Set on Devnet
1827 /// from protocol version 39. Required by `enable_pcool_flow` from that
1828 /// version.
1829 pcool_deterministic_validation_horizon_distance: Option<u64>,
1830
1831 /// Scorer version. When set to `None`, MisbehaviorReports are not sent nor
1832 /// considered valid. When set to `Some(version)`, scores are included in
1833 /// the MisbehaviorReports messages, where `version` determines the scoring
1834 /// formulas and metrics to be used. Even if set to None, the Scorer
1835 /// component is created, having access to metrics and being able to expose
1836 /// validator scores. Also gates the wire format of the
1837 /// `MisbehaviorReport` consensus transaction — scorer and report bump
1838 /// together.
1839 scorer_version: Option<u16>,
1840
1841 // `auth_context` module
1842 // Cost params for the Move native function `native_digest(): vector<u8>`
1843 auth_context_digest_cost_base: Option<u64>,
1844 // Cost params for the Move native function `native_tx_data_bytes(): &vector<u8>`
1845 auth_context_tx_data_bytes_cost_base: Option<u64>,
1846 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1847 // Cost params for the Move native function `native_tx_commands<C>(): vector<C>`
1848 auth_context_tx_commands_cost_base: Option<u64>,
1849 auth_context_tx_commands_cost_per_byte: Option<u64>,
1850 // Cost params for the Move native function `native_tx_inputs<I>(): vector<I>`
1851 auth_context_tx_inputs_cost_base: Option<u64>,
1852 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1853 // Cost params for the Move native function `fun native_replace<I, C>(auth_digest: vector<u8>,
1854 // tx_inputs: vector<I>, tx_commands: vector<C>, tx_data_bytes: vector<u8>)`
1855 auth_context_replace_cost_base: Option<u64>,
1856 auth_context_replace_cost_per_byte: Option<u64>,
1857 // Cost params for the Move native functions
1858 // `fun native_sender_authenticator_function_info_v1<F>(): &Option<F>`
1859 // `fun native_sponsor_authenticator_function_info_v1<F>(): &Option<F>`
1860 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1861
1862 /// Number of committed subdags between leader-schedule recomputations.
1863 /// When unset, defaults to 300.
1864 consensus_commits_per_schedule: Option<u32>,
1865
1866 /// Minimum number of active validators at any moment.
1867 /// Supersedes `SystemParametersV1::min_validator_count`.
1868 min_validator_count: Option<u64>,
1869
1870 /// Maximum number of active validators at any moment. The number of
1871 /// validators in any epoch is not allowed to go above this.
1872 /// Supersedes `SystemParametersV1::max_validator_count`.
1873 max_validator_count: Option<u64>,
1874
1875 /// Minimum stake, in nanos, a validator candidate needs to join the
1876 /// active set. Supersedes
1877 /// `SystemParametersV1::min_validator_joining_stake`.
1878 min_validator_joining_stake: Option<u64>,
1879
1880 /// Active validators with stake, in nanos, below this threshold are
1881 /// considered at risk and are removed after
1882 /// `validator_low_stake_grace_period` consecutive epochs below it.
1883 /// Supersedes `SystemParametersV1::validator_low_stake_threshold`.
1884 validator_low_stake_threshold: Option<u64>,
1885
1886 /// Active validators with stake, in nanos, below this threshold are
1887 /// removed at the next epoch boundary without a grace period.
1888 /// Supersedes `SystemParametersV1::validator_very_low_stake_threshold`.
1889 validator_very_low_stake_threshold: Option<u64>,
1890
1891 /// Number of consecutive epochs a validator may stay below
1892 /// `validator_low_stake_threshold` before being removed.
1893 /// Supersedes `SystemParametersV1::validator_low_stake_grace_period`.
1894 validator_low_stake_grace_period: Option<u64>,
1895
1896 /// Number of committed subdags the sliding-window leader scorer aggregates
1897 /// over (the scoring depth). When unset, defaults to 600. Must be at least
1898 /// `consensus_commits_per_schedule`.
1899 consensus_leader_schedule_window_size: Option<u32>,
1900
1901 /// Maximum size of a system Move package object, in bytes. System packages
1902 /// are published by the network rather than by users, so they are held to a
1903 /// larger bound than `max_move_package_size`. When unset, system packages
1904 /// are bound by `max_move_package_size` like any other package.
1905 max_move_system_package_size: Option<u64>,
1906
1907 // Cost param for the Move native function
1908 // `public_key::verify_builtin_authenticator_signature_impl(public_key: &PublicKey,
1909 // signature: &vector<u8>): bool`, the signature check of the built-in Move
1910 // authenticators. It runs only while a built-in authenticator authenticates a
1911 // transaction.
1912 public_key_verify_builtin_authenticator_signature_impl_cost_base: Option<u64>,
1913
1914 // Cost param for the Move native function `ed25519::ed25519_validate_pubkey(public_key:
1915 // &vector<u8>): bool`
1916 ed25519_ed25519_validate_pubkey_cost_base: Option<u64>,
1917 // Cost param for the Move native function `ecdsa_k1::secp256k1_validate_pubkey(public_key:
1918 // &vector<u8>): bool`
1919 ecdsa_k1_secp256k1_validate_pubkey_cost_base: Option<u64>,
1920 // Cost param for the Move native function `ecdsa_r1::secp256r1_validate_pubkey(public_key:
1921 // &vector<u8>): bool`
1922 ecdsa_r1_secp256r1_validate_pubkey_cost_base: Option<u64>,
1923 // Cost param for the Move native function `multisig::multisig_validate_pubkey(public_key:
1924 // &vector<u8>): bool`
1925 multisig_multisig_validate_pubkey_cost_base: Option<u64>,
1926 // Cost param for the Move native function `public_key::to_iota_address_impl(flag: u8,
1927 // raw_bytes: &vector<u8>): address`
1928 public_key_to_iota_address_impl_cost_base: Option<u64>,
1929 // Cost params for the Move native function
1930 // `public_key::verify_personal_message_signature_impl(public_key: &PublicKey, signature:
1931 // &vector<u8>, message: &vector<u8>): bool`
1932 public_key_verify_personal_message_signature_impl_cost_base: Option<u64>,
1933 public_key_verify_personal_message_signature_impl_msg_cost_per_byte: Option<u64>,
1934 public_key_verify_personal_message_signature_impl_sig_cost_per_byte: Option<u64>,
1935 // Cost param for the Move native function `tx_context::native_chain_identifier():
1936 // vector<u8>`
1937 tx_context_chain_identifier_cost_base: Option<u64>,
1938
1939 // Upper bound on the computation units a `ClaimAccount` is charged, after rounding.
1940 //
1941 // The claim runs a fixed pipeline with no user code, so its cost is bounded by this many
1942 // units at the transaction's own gas price plus the storage bound below. Requiring the
1943 // budget to clear that sum rejects, from the transaction bytes alone, a claim that would
1944 // run out of gas at execution.
1945 claim_account_max_computation_units: Option<u64>,
1946 // Upper bound on the bytes a `ClaimAccount` stores beyond its raw public key bytes: the
1947 // account object, its authenticator function reference and the field holding the key.
1948 claim_account_storage_bytes_bound: Option<u64>,
1949}
1950
1951// feature flags
1952impl ProtocolConfig {
1953 // Add checks for feature flag support here, e.g.:
1954 // pub fn check_new_protocol_feature_supported(&self) -> Result<(), Error> {
1955 // if self.feature_flags.new_protocol_feature_supported {
1956 // Ok(())
1957 // } else {
1958 // Err(Error(format!(
1959 // "new_protocol_feature is not supported at {:?}",
1960 // self.version
1961 // )))
1962 // }
1963 // }
1964
1965 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1966 self.feature_flags
1967 .disable_invariant_violation_check_in_swap_loc
1968 }
1969
1970 pub fn no_extraneous_module_bytes(&self) -> bool {
1971 self.feature_flags.no_extraneous_module_bytes
1972 }
1973
1974 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1975 self.feature_flags.consensus_transaction_ordering
1976 }
1977
1978 pub fn dkg_version(&self) -> u64 {
1979 // Version 0 was deprecated and removed, the default is 1 if not set.
1980 self.random_beacon_dkg_version.unwrap_or(1)
1981 }
1982
1983 pub fn hardened_otw_check(&self) -> bool {
1984 self.feature_flags.hardened_otw_check
1985 }
1986
1987 pub fn enable_poseidon(&self) -> bool {
1988 self.feature_flags.enable_poseidon
1989 }
1990
1991 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1992 self.feature_flags.enable_group_ops_native_function_msm
1993 }
1994
1995 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1996 self.feature_flags.per_object_congestion_control_mode
1997 }
1998
1999 pub fn consensus_choice(&self) -> ConsensusChoice {
2000 self.feature_flags.consensus_choice
2001 }
2002
2003 pub fn consensus_network(&self) -> ConsensusNetwork {
2004 self.feature_flags.consensus_network
2005 }
2006
2007 pub fn enable_vdf(&self) -> bool {
2008 self.feature_flags.enable_vdf
2009 }
2010
2011 pub fn passkey_auth(&self) -> bool {
2012 self.feature_flags.passkey_auth
2013 }
2014
2015 pub fn max_transaction_size_bytes(&self) -> u64 {
2016 // Provide a default value if protocol config version is too low.
2017 self.consensus_max_transaction_size_bytes
2018 .unwrap_or(256 * 1024)
2019 }
2020
2021 pub fn max_transactions_in_block_bytes(&self) -> u64 {
2022 if cfg!(msim) {
2023 256 * 1024
2024 } else {
2025 self.consensus_max_transactions_in_block_bytes
2026 .unwrap_or(512 * 1024)
2027 }
2028 }
2029
2030 pub fn max_num_transactions_in_block(&self) -> u64 {
2031 if cfg!(msim) {
2032 8
2033 } else {
2034 self.consensus_max_num_transactions_in_block.unwrap_or(512)
2035 }
2036 }
2037
2038 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
2039 self.feature_flags.rethrow_serialization_type_layout_errors
2040 }
2041
2042 pub fn relocate_event_module(&self) -> bool {
2043 self.feature_flags.relocate_event_module
2044 }
2045
2046 pub fn protocol_defined_base_fee(&self) -> bool {
2047 self.feature_flags.protocol_defined_base_fee
2048 }
2049
2050 pub fn uncompressed_g1_group_elements(&self) -> bool {
2051 self.feature_flags.uncompressed_g1_group_elements
2052 }
2053
2054 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
2055 self.feature_flags
2056 .disallow_new_modules_in_deps_only_packages
2057 }
2058
2059 pub fn native_charging_v2(&self) -> bool {
2060 self.feature_flags.native_charging_v2
2061 }
2062
2063 pub fn consensus_round_prober(&self) -> bool {
2064 self.feature_flags.consensus_round_prober
2065 }
2066
2067 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
2068 self.feature_flags
2069 .consensus_distributed_vote_scoring_strategy
2070 }
2071
2072 pub fn gc_depth(&self) -> u32 {
2073 if cfg!(msim) {
2074 // exercise a very low gc_depth
2075 min(5, self.consensus_gc_depth.unwrap_or(0))
2076 } else {
2077 self.consensus_gc_depth.unwrap_or(0)
2078 }
2079 }
2080
2081 pub fn consensus_linearize_subdag_v2(&self) -> bool {
2082 let res = self.feature_flags.consensus_linearize_subdag_v2;
2083 assert!(
2084 !res || self.gc_depth() > 0,
2085 "The consensus linearize sub dag V2 requires GC to be enabled"
2086 );
2087 res
2088 }
2089
2090 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
2091 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
2092 }
2093
2094 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
2095 2 * committee_size
2096 }
2097
2098 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
2099 committee_size
2100 }
2101
2102 pub fn variant_nodes(&self) -> bool {
2103 self.feature_flags.variant_nodes
2104 }
2105
2106 pub fn consensus_smart_ancestor_selection(&self) -> bool {
2107 self.feature_flags.consensus_smart_ancestor_selection
2108 }
2109
2110 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
2111 self.feature_flags
2112 .consensus_round_prober_probe_accepted_rounds
2113 }
2114
2115 pub fn consensus_zstd_compression(&self) -> bool {
2116 self.feature_flags.consensus_zstd_compression
2117 }
2118
2119 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
2120 self.feature_flags
2121 .congestion_control_min_free_execution_slot
2122 }
2123
2124 pub fn accept_passkey_in_multisig(&self) -> bool {
2125 self.feature_flags.accept_passkey_in_multisig
2126 }
2127
2128 pub fn consensus_batched_block_sync(&self) -> bool {
2129 self.feature_flags.consensus_batched_block_sync
2130 }
2131
2132 /// Check if the gas price feedback mechanism (which is used for
2133 /// transactions cancelled due to shared object congestion) is enabled
2134 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
2135 self.feature_flags
2136 .congestion_control_gas_price_feedback_mechanism
2137 }
2138
2139 pub fn validate_identifier_inputs(&self) -> bool {
2140 self.feature_flags.validate_identifier_inputs
2141 }
2142
2143 pub fn minimize_child_object_mutations(&self) -> bool {
2144 self.feature_flags.minimize_child_object_mutations
2145 }
2146
2147 pub fn dependency_linkage_error(&self) -> bool {
2148 self.feature_flags.dependency_linkage_error
2149 }
2150
2151 pub fn additional_multisig_checks(&self) -> bool {
2152 self.feature_flags.additional_multisig_checks
2153 }
2154
2155 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
2156 // TODO: this will eventually be the max of some number of other
2157 // parameters.
2158 0
2159 }
2160
2161 pub fn normalize_ptb_arguments(&self) -> bool {
2162 self.feature_flags.normalize_ptb_arguments
2163 }
2164
2165 pub fn select_committee_from_eligible_validators(&self) -> bool {
2166 let res = self.feature_flags.select_committee_from_eligible_validators;
2167 assert!(
2168 !res || (self.protocol_defined_base_fee()
2169 && self.max_committee_members_count_as_option().is_some()),
2170 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
2171 );
2172 res
2173 }
2174
2175 pub fn track_non_committee_eligible_validators(&self) -> bool {
2176 self.feature_flags.track_non_committee_eligible_validators
2177 }
2178
2179 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
2180 let res = self
2181 .feature_flags
2182 .select_committee_supporting_next_epoch_version;
2183 assert!(
2184 !res || (self.track_non_committee_eligible_validators()
2185 && self.select_committee_from_eligible_validators()),
2186 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
2187 );
2188 res
2189 }
2190
2191 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
2192 let res = self
2193 .feature_flags
2194 .consensus_median_timestamp_with_checkpoint_enforcement;
2195 assert!(
2196 !res || self.gc_depth() > 0,
2197 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
2198 );
2199 res
2200 }
2201
2202 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
2203 self.feature_flags
2204 .consensus_commit_transactions_only_for_traversed_headers
2205 }
2206
2207 /// Whether a block whose transactions reached their acknowledgment quorum
2208 /// before its header was traversed is committed once its header is
2209 /// traversed.
2210 ///
2211 /// # Panics
2212 ///
2213 /// If the flag is set without
2214 /// `consensus_commit_transactions_only_for_traversed_headers`.
2215 pub fn consensus_commit_transactions_once_traversed(&self) -> bool {
2216 let res = self
2217 .feature_flags
2218 .consensus_commit_transactions_once_traversed;
2219 assert!(
2220 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
2221 "consensus_commit_transactions_once_traversed requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
2222 );
2223 res
2224 }
2225
2226 /// Check whether congestion limit overshoot is enabled in the gas price
2227 /// feedback mechanism.
2228 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
2229 self.feature_flags
2230 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
2231 }
2232
2233 /// Check whether a separate gas price feedback mechanism is used for
2234 /// randomness transactions.
2235 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
2236 self.feature_flags
2237 .separate_gas_price_feedback_mechanism_for_randomness
2238 }
2239
2240 pub fn metadata_in_module_bytes(&self) -> bool {
2241 self.feature_flags.metadata_in_module_bytes
2242 }
2243
2244 pub fn publish_package_metadata(&self) -> bool {
2245 self.feature_flags.publish_package_metadata
2246 }
2247
2248 pub fn enable_move_authentication(&self) -> bool {
2249 self.feature_flags.enable_move_authentication
2250 }
2251
2252 pub fn additional_borrow_checks(&self) -> bool {
2253 self.feature_flags.additional_borrow_checks
2254 }
2255
2256 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
2257 let enable_move_authentication_for_sponsor =
2258 self.feature_flags.enable_move_authentication_for_sponsor;
2259 assert!(
2260 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
2261 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
2262 );
2263 enable_move_authentication_for_sponsor
2264 }
2265
2266 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
2267 self.feature_flags.pass_validator_scores_to_advance_epoch
2268 }
2269
2270 pub fn calculate_validator_scores(&self) -> bool {
2271 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
2272 assert!(
2273 !calculate_validator_scores || self.scorer_version.is_some(),
2274 "calculate_validator_scores requires scorer_version to be set"
2275 );
2276 calculate_validator_scores
2277 }
2278
2279 pub fn adjust_rewards_by_score(&self) -> bool {
2280 let adjust = self.feature_flags.adjust_rewards_by_score;
2281 assert!(
2282 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
2283 "adjust_rewards_by_score requires scorer_version to be set"
2284 );
2285 adjust
2286 }
2287
2288 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
2289 let pass = self
2290 .feature_flags
2291 .pass_calculated_validator_scores_to_advance_epoch;
2292 assert!(
2293 !pass
2294 || (self.pass_validator_scores_to_advance_epoch()
2295 && self.calculate_validator_scores()),
2296 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
2297 );
2298 pass
2299 }
2300 pub fn consensus_fast_commit_sync(&self) -> bool {
2301 let res = self.feature_flags.consensus_fast_commit_sync;
2302 assert!(
2303 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
2304 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
2305 );
2306 res
2307 }
2308
2309 pub fn consensus_block_restrictions(&self) -> bool {
2310 self.feature_flags.consensus_block_restrictions
2311 }
2312
2313 pub fn move_native_tx_context(&self) -> bool {
2314 self.feature_flags.move_native_tx_context
2315 }
2316
2317 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
2318 let pre_consensus_sponsor_only_move_authentication = self
2319 .feature_flags
2320 .pre_consensus_sponsor_only_move_authentication;
2321 if pre_consensus_sponsor_only_move_authentication {
2322 assert!(
2323 self.enable_move_authentication(),
2324 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
2325 );
2326 assert!(
2327 self.enable_move_authentication_for_sponsor(),
2328 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
2329 );
2330 }
2331 pre_consensus_sponsor_only_move_authentication
2332 }
2333
2334 pub fn consensus_starfish_speed(&self) -> bool {
2335 let res = self.feature_flags.consensus_starfish_speed;
2336 assert!(
2337 !res || self.consensus_fast_commit_sync(),
2338 "consensus_starfish_speed requires consensus_fast_commit_sync to be enabled"
2339 );
2340 res
2341 }
2342
2343 pub fn always_advance_dkg_to_resolution(&self) -> bool {
2344 self.feature_flags.always_advance_dkg_to_resolution
2345 }
2346
2347 pub fn enable_pcool_flow(&self) -> bool {
2348 self.feature_flags.enable_pcool_flow
2349 }
2350
2351 pub fn validator_metadata_verify_v2(&self) -> bool {
2352 self.feature_flags.validator_metadata_verify_v2
2353 }
2354
2355 pub fn commits_per_schedule(&self) -> u32 {
2356 let commits_per_schedule = if cfg!(msim) {
2357 // Exercise faster leader-schedule rotation in simtests.
2358 min(10, self.consensus_commits_per_schedule.unwrap_or(300))
2359 } else {
2360 self.consensus_commits_per_schedule.unwrap_or(300)
2361 };
2362 assert!(
2363 commits_per_schedule > 0,
2364 "consensus_commits_per_schedule must be greater than 0"
2365 );
2366 commits_per_schedule
2367 }
2368
2369 pub fn leader_schedule_window_size(&self) -> u32 {
2370 let window_size = if cfg!(msim) {
2371 // Keep the scoring window commensurate with the msim-scaled
2372 // commit sync parameters.
2373 min(
2374 20,
2375 self.consensus_leader_schedule_window_size.unwrap_or(600),
2376 )
2377 } else {
2378 self.consensus_leader_schedule_window_size.unwrap_or(600)
2379 };
2380 assert!(
2381 window_size >= self.commits_per_schedule(),
2382 "consensus_leader_schedule_window_size must be at least consensus_commits_per_schedule"
2383 );
2384 window_size
2385 }
2386
2387 pub fn consensus_enable_sliding_window_leader_schedule(&self) -> bool {
2388 self.feature_flags
2389 .consensus_enable_sliding_window_leader_schedule
2390 }
2391
2392 pub fn consensus_enable_absolute_score_leader_schedule(&self) -> bool {
2393 self.feature_flags
2394 .consensus_enable_absolute_score_leader_schedule
2395 }
2396
2397 pub fn max_ptb_value_size_v2(&self) -> bool {
2398 self.feature_flags.max_ptb_value_size_v2
2399 }
2400
2401 pub fn deny_authenticator_packages(&self) -> bool {
2402 self.feature_flags.deny_authenticator_packages
2403 }
2404
2405 pub fn package_metadata_with_dynamic_module_metadata(&self) -> bool {
2406 let res = self
2407 .feature_flags
2408 .package_metadata_with_dynamic_module_metadata;
2409 assert!(
2410 !res || self.publish_package_metadata(),
2411 "package_metadata_with_dynamic_module_metadata requires publish_package_metadata to be enabled"
2412 );
2413 res
2414 }
2415
2416 pub fn report_move_authentication_error(&self) -> bool {
2417 let report_move_authentication_error = self.feature_flags.report_move_authentication_error;
2418 assert!(
2419 !report_move_authentication_error || self.enable_move_authentication(),
2420 "report_move_authentication_error requires enable_move_authentication to be set"
2421 );
2422 report_move_authentication_error
2423 }
2424
2425 /// Named to avoid colliding with the derive-generated
2426 /// `max_concurrent_execution_workers[_as_option]()`, which bypass the
2427 /// checks below — always read the parameter through this getter.
2428 pub fn concurrent_execution_workers(&self) -> Option<u16> {
2429 let res = self.max_concurrent_execution_workers;
2430 assert!(
2431 res.is_none() || self.enable_pcool_flow(),
2432 "max_concurrent_execution_workers requires enable_pcool_flow to be enabled"
2433 );
2434 assert!(
2435 res.is_none()
2436 || self
2437 .max_accumulated_txn_cost_per_object_in_mysticeti_commit
2438 .is_some(),
2439 "max_concurrent_execution_workers requires per-object congestion control \
2440 (max_accumulated_txn_cost_per_object_in_mysticeti_commit) to be enabled"
2441 );
2442 assert!(
2443 res.is_none() || self.congestion_control_gas_price_feedback_mechanism(),
2444 "max_concurrent_execution_workers requires the gas price feedback mechanism \
2445 (congestion_control_gas_price_feedback_mechanism), which carries the suggested \
2446 gas price of an execution-worker congestion cancellation"
2447 );
2448 assert!(
2449 res.is_none() || !self.separate_gas_price_feedback_mechanism_for_randomness(),
2450 "max_concurrent_execution_workers implies a single congestion tracker and suggested \
2451 gas price calculator for all transactions, which is incompatible with \
2452 separate_gas_price_feedback_mechanism_for_randomness"
2453 );
2454 assert!(
2455 res != Some(0),
2456 "max_concurrent_execution_workers must be positive when set"
2457 );
2458 res
2459 }
2460
2461 pub fn allow_unbounded_system_objects(&self) -> bool {
2462 self.feature_flags.allow_unbounded_system_objects
2463 }
2464
2465 pub fn reject_immutable_account_objects(&self) -> bool {
2466 let reject_immutable_account_objects = self.feature_flags.reject_immutable_account_objects;
2467 assert!(
2468 !reject_immutable_account_objects || self.enable_move_authentication(),
2469 "reject_immutable_account_objects requires enable_move_authentication to be set"
2470 );
2471 reject_immutable_account_objects
2472 }
2473
2474 pub fn reject_immutable_account_creation(&self) -> bool {
2475 let reject_immutable_account_creation =
2476 self.feature_flags.reject_immutable_account_creation;
2477 assert!(
2478 !reject_immutable_account_creation || self.reject_immutable_account_objects(),
2479 "reject_immutable_account_creation requires reject_immutable_account_objects to be set"
2480 );
2481 reject_immutable_account_creation
2482 }
2483
2484 pub fn validate_input_object_versions(&self) -> bool {
2485 self.feature_flags.validate_input_object_versions
2486 }
2487
2488 pub fn check_canonical_module_version_header(&self) -> bool {
2489 self.feature_flags.check_canonical_module_version_header
2490 }
2491
2492 pub fn disallow_randomness_in_move_authenticator(&self) -> bool {
2493 self.feature_flags.disallow_randomness_in_move_authenticator
2494 }
2495
2496 pub fn check_cyclic_dependencies(&self) -> bool {
2497 self.feature_flags.check_cyclic_dependencies
2498 }
2499
2500 pub fn validate_ptb_argument_indices(&self) -> bool {
2501 self.feature_flags.validate_ptb_argument_indices
2502 }
2503
2504 pub fn allow_dkg_completion_after_timeout(&self) -> bool {
2505 self.feature_flags.allow_dkg_completion_after_timeout
2506 }
2507
2508 pub fn disallow_self_identifier_in_transactions(&self) -> bool {
2509 self.feature_flags.disallow_self_identifier_in_transactions
2510 }
2511
2512 pub fn consensus_dedup_only_recorded_messages(&self) -> bool {
2513 self.feature_flags.consensus_dedup_only_recorded_messages
2514 }
2515
2516 pub fn reject_partially_signed_mixed_ed25519_multisig(&self) -> bool {
2517 self.feature_flags
2518 .reject_partially_signed_mixed_ed25519_multisig
2519 }
2520
2521 pub fn limit_groth16_pvk_inputs(&self) -> bool {
2522 self.feature_flags.limit_groth16_pvk_inputs
2523 }
2524
2525 pub fn check_groth16_pvk_length(&self) -> bool {
2526 self.feature_flags.check_groth16_pvk_length
2527 }
2528
2529 pub fn deprecate_global_storage_ops(&self) -> bool {
2530 self.feature_flags.deprecate_global_storage_ops
2531 }
2532
2533 pub fn meter_instantiation_loops(&self) -> bool {
2534 self.feature_flags.meter_instantiation_loops
2535 }
2536
2537 pub fn move_authenticator_type_arg_packages_as_inputs(&self) -> bool {
2538 self.feature_flags
2539 .move_authenticator_type_arg_packages_as_inputs
2540 }
2541
2542 /// Its prerequisites are checked once, in [`Self::get_for_version`].
2543 pub fn enable_validator_attestation(&self) -> bool {
2544 self.feature_flags.enable_validator_attestation
2545 }
2546
2547 pub fn secp256r1_ecrecover_checks_x_below_p(&self) -> bool {
2548 self.feature_flags.secp256r1_ecrecover_checks_x_below_p
2549 }
2550
2551 /// Its prerequisites are checked once, in [`Self::get_for_version`].
2552 pub fn enable_transaction_dependencies(&self) -> bool {
2553 self.feature_flags.enable_transaction_dependencies
2554 }
2555
2556 pub fn enable_builtin_move_authenticators(&self) -> bool {
2557 let enable_builtin_move_authenticators =
2558 self.feature_flags.enable_builtin_move_authenticators;
2559 if enable_builtin_move_authenticators {
2560 assert!(
2561 self.enable_move_authentication(),
2562 "enable_builtin_move_authenticators requires enable_move_authentication to be set"
2563 );
2564 assert!(
2565 self.public_key_verify_builtin_authenticator_signature_impl_cost_base
2566 .is_some(),
2567 "enable_builtin_move_authenticators requires public_key_verify_builtin_authenticator_signature_impl_cost_base to be set"
2568 );
2569 }
2570 enable_builtin_move_authenticators
2571 }
2572
2573 pub fn enable_claim_account_transaction(&self) -> bool {
2574 let enable_claim_account_transaction = self.feature_flags.enable_claim_account_transaction;
2575 if enable_claim_account_transaction {
2576 // A claimed account is authenticated by the built-in authenticator
2577 // of its key's scheme, so without them it could never send a
2578 // transaction, and an address can only be claimed once.
2579 assert!(
2580 self.enable_builtin_move_authenticators(),
2581 "enable_claim_account_transaction requires enable_builtin_move_authenticators to be set"
2582 );
2583 // The validity check rejects a claim whose budget cannot cover the
2584 // pipeline, so the bounds that define that floor must be set.
2585 assert!(
2586 self.claim_account_max_computation_units.is_some()
2587 && self.claim_account_storage_bytes_bound.is_some(),
2588 "enable_claim_account_transaction requires claim_account_max_computation_units \
2589 and claim_account_storage_bytes_bound to be set"
2590 );
2591 }
2592 enable_claim_account_transaction
2593 }
2594
2595 pub fn enable_smart_accounts(&self) -> bool {
2596 let enable_smart_accounts = self.feature_flags.enable_smart_accounts;
2597 assert!(
2598 !enable_smart_accounts || self.enable_move_authentication(),
2599 "enable_smart_accounts requires enable_move_authentication to be set"
2600 );
2601 enable_smart_accounts
2602 }
2603}
2604
2605#[cfg(not(msim))]
2606static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2607
2608// Use a thread local in sim tests for test isolation.
2609#[cfg(msim)]
2610thread_local! {
2611 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2612}
2613
2614// Instantiations for each protocol version.
2615impl ProtocolConfig {
2616 /// Get the value ProtocolConfig that are in effect during the given
2617 /// protocol version.
2618 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
2619 // ProtocolVersion can be deserialized so we need to check it here as well.
2620 assert!(
2621 version >= ProtocolVersion::MIN,
2622 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
2623 version,
2624 ProtocolVersion::MIN.0,
2625 );
2626 assert!(
2627 version <= ProtocolVersion::MAX_ALLOWED,
2628 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
2629 version,
2630 ProtocolVersion::MAX_ALLOWED.0,
2631 );
2632
2633 let mut ret = Self::get_for_version_impl(version, chain);
2634 ret.version = version;
2635
2636 ret = CONFIG_OVERRIDE.with(|ovr| {
2637 if let Some(override_fn) = &*ovr.borrow() {
2638 warn!(
2639 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
2640 );
2641 override_fn(version, ret)
2642 } else {
2643 ret
2644 }
2645 });
2646
2647 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
2648 warn!(
2649 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
2650 );
2651
2652 // First, deserialize the top-level ProtocolConfig fields
2653 let overrides: ProtocolConfigOptional =
2654 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
2655 .expect("failed to parse ProtocolConfig override env variables");
2656 overrides.apply_to(&mut ret);
2657
2658 // Then, separately deserialize FeatureFlags fields
2659 let feature_flag_overrides: FeatureFlagsOptional =
2660 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_FEATURE_FLAGS_OVERRIDE")
2661 .expect("failed to parse ProtocolConfig feature flags override env variables");
2662
2663 feature_flag_overrides.apply_to(&mut ret.feature_flags);
2664
2665 // An environment override can switch attestation off but cannot
2666 // unset a parameter, so the parameters that require it go with
2667 // the flag.
2668 if !ret.feature_flags.enable_validator_attestation {
2669 ret.unset_attestation_parameters();
2670 }
2671 }
2672
2673 // Devnet runs the P-COOL flow from version 32, before the settings it
2674 // requires exist; only versions from 39 on are checked for them. A test
2675 // override can return the config of another version, so the check
2676 // reads the version of the config returned.
2677 let pcool_requirements_apply =
2678 ret.feature_flags.enable_pcool_flow && ret.version >= ProtocolVersion::new(39);
2679 // Post-consensus validation meters published packages with the
2680 // verifier limits from this config, and reads the regex check budget
2681 // through the panicking accessor.
2682 assert!(
2683 !pcool_requirements_apply || ret.max_meter_ticks_regex_reference_safety.is_some(),
2684 "enable_pcool_flow requires max_meter_ticks_regex_reference_safety"
2685 );
2686 // For the same reason, the consensus handler must not skip a message
2687 // as a duplicate of one that was dropped without being recorded, as
2688 // its cache of such messages differs between validators.
2689 assert!(
2690 !pcool_requirements_apply || ret.feature_flags.consensus_dedup_only_recorded_messages,
2691 "enable_pcool_flow requires consensus_dedup_only_recorded_messages"
2692 );
2693 // With a distance of 0, the consensus handler processing commit C
2694 // would wait for C itself to be fully executed, which cannot happen
2695 // before the handler finishes processing C.
2696 assert!(
2697 !pcool_requirements_apply
2698 || ret
2699 .pcool_deterministic_validation_horizon_distance
2700 .is_some_and(|distance| distance > 0),
2701 "enable_pcool_flow requires a positive pcool_deterministic_validation_horizon_distance"
2702 );
2703 // Without the sender's authenticator run before consensus, a sponsor
2704 // alone could get a transaction sequenced that locks a Move account's
2705 // owned objects.
2706 assert!(
2707 !pcool_requirements_apply
2708 || !ret
2709 .feature_flags
2710 .pre_consensus_sponsor_only_move_authentication,
2711 "enable_pcool_flow excludes pre_consensus_sponsor_only_move_authentication"
2712 );
2713 // The injection cannot chunk updates without its limit.
2714 assert!(
2715 !pcool_requirements_apply || ret.deny_rule_update_max_entries_per_tx.is_some(),
2716 "enable_pcool_flow requires deny_rule_update_max_entries_per_tx"
2717 );
2718 // A deny-rule update chunk must always execute, or the object falls
2719 // permanently behind the mirrored state on every validator at once.
2720 // The binding limits are `max_event_emit_size` (the update event
2721 // carries every entry, ~32 bytes each) and the object-runtime store
2722 // entries touched when removals re-link `LinkedTable` nodes — neither
2723 // expressible as an entry count here, so the constant keeps a wide
2724 // margin below them (tightest is roughly 5000 entries).
2725 const DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING: u64 = 2048;
2726 assert!(
2727 ret.deny_rule_update_max_entries_per_tx
2728 .is_none_or(|max_entries| {
2729 max_entries > 0
2730 && max_entries <= DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING
2731 && [
2732 ret.max_num_new_move_object_ids_system_tx,
2733 ret.max_num_deleted_move_object_ids_system_tx,
2734 ret.object_runtime_max_num_cached_objects_system_tx,
2735 ret.object_runtime_max_num_store_entries_system_tx,
2736 ]
2737 .iter()
2738 .all(|limit| limit.is_none_or(|limit| max_entries <= limit))
2739 }),
2740 "deny_rule_update_max_entries_per_tx must be positive, at most {DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING}, and within the system transaction object limits"
2741 );
2742
2743 if ret.enable_validator_attestation() {
2744 assert!(
2745 ret.enable_pcool_flow(),
2746 "enable_validator_attestation requires enable_pcool_flow to be set"
2747 );
2748 assert!(
2749 ret.report_move_authentication_error(),
2750 "enable_validator_attestation requires report_move_authentication_error to be set"
2751 );
2752 // The attestation verdicts are certified in the summary's version 2.
2753 assert!(
2754 ret.checkpoint_summary_version_specific_data == Some(2),
2755 "enable_validator_attestation requires checkpoint_summary_version_specific_data = 2"
2756 );
2757 // Execution and the attestor's dry run limit the Move
2758 // authenticators to `max_auth_gas`.
2759 assert!(
2760 ret.max_auth_gas.is_some(),
2761 "enable_validator_attestation requires max_auth_gas to be set"
2762 );
2763 }
2764 if ret.attestation_max_refuted_units_squared.is_some() {
2765 assert!(
2766 ret.enable_validator_attestation(),
2767 "attestation_max_refuted_units_squared requires enable_validator_attestation"
2768 );
2769 assert!(
2770 ret.pass_validator_scores_to_advance_epoch(),
2771 "attestation_max_refuted_units_squared requires \
2772 pass_validator_scores_to_advance_epoch"
2773 );
2774 }
2775 if ret.attestation_freshness_window_commits.is_some() {
2776 assert!(
2777 ret.enable_validator_attestation(),
2778 "attestation_freshness_window_commits requires enable_validator_attestation"
2779 );
2780 }
2781 // A transaction without shared inputs that waits too long for its
2782 // dependency is cancelled through its gas object, which carries the
2783 // suggested gas price.
2784 if ret.enable_transaction_dependencies() {
2785 assert!(
2786 ret.congestion_control_gas_price_feedback_mechanism(),
2787 "enable_transaction_dependencies requires \
2788 congestion_control_gas_price_feedback_mechanism to be set"
2789 );
2790 }
2791
2792 ret
2793 }
2794
2795 /// Unsets the parameters [`Self::get_for_version`] accepts only with
2796 /// `enable_validator_attestation`.
2797 fn unset_attestation_parameters(&mut self) {
2798 self.attestation_max_refuted_units_squared = None;
2799 self.attestation_freshness_window_commits = None;
2800 }
2801
2802 /// Get the value ProtocolConfig that are in effect during the given
2803 /// protocol version. Or none if the version is not supported.
2804 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
2805 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
2806 let mut ret = Self::get_for_version_impl(version, chain);
2807 ret.version = version;
2808 Some(ret)
2809 } else {
2810 None
2811 }
2812 }
2813
2814 #[cfg(not(msim))]
2815 pub fn poison_get_for_min_version() {
2816 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
2817 }
2818
2819 #[cfg(not(msim))]
2820 fn load_poison_get_for_min_version() -> bool {
2821 POISON_VERSION_METHODS.load(Ordering::Relaxed)
2822 }
2823
2824 #[cfg(msim)]
2825 pub fn poison_get_for_min_version() {
2826 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
2827 }
2828
2829 #[cfg(msim)]
2830 fn load_poison_get_for_min_version() -> bool {
2831 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
2832 }
2833
2834 pub fn convert_type_argument_error(&self) -> bool {
2835 self.feature_flags.convert_type_argument_error
2836 }
2837
2838 /// Convenience to get the constants at the current minimum supported
2839 /// version. Mainly used by client code that may not yet be
2840 /// protocol-version aware.
2841 pub fn get_for_min_version() -> Self {
2842 if Self::load_poison_get_for_min_version() {
2843 panic!("get_for_min_version called on validator");
2844 }
2845 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
2846 }
2847
2848 /// CAREFUL! - You probably want to use `get_for_version` instead.
2849 ///
2850 /// Convenience to get the constants at the current maximum supported
2851 /// version. Mainly used by genesis. Note well that this function uses
2852 /// the max version supported locally by the node, which is not
2853 /// necessarily the current version of the network. ALSO, this function
2854 /// disregards chain specific config (by using Chain::Unknown), thereby
2855 /// potentially returning a protocol config that is incorrect for some
2856 /// feature flags. Definitely safe for testing and for protocol version
2857 /// 11 and prior.
2858 #[expect(non_snake_case)]
2859 pub fn get_for_max_version_UNSAFE() -> Self {
2860 if Self::load_poison_get_for_min_version() {
2861 panic!("get_for_max_version_UNSAFE called on validator");
2862 }
2863 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
2864 }
2865
2866 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
2867 #[cfg(msim)]
2868 {
2869 // populate the fake simulator version # with a different base tx cost.
2870 if version > ProtocolVersion::MAX {
2871 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
2872 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
2873 return config;
2874 }
2875 }
2876
2877 // IMPORTANT: Never modify the value of any constant for a pre-existing protocol
2878 // version. To change the values here you must create a new protocol
2879 // version with the new values!
2880 let mut cfg = Self {
2881 version,
2882
2883 feature_flags: Default::default(),
2884
2885 max_tx_size_bytes: Some(128 * 1024),
2886 // We need this number to be at least 100x less than
2887 // `max_serialized_tx_effects_size_bytes`otherwise effects can be huge
2888 max_input_objects: Some(2048),
2889 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
2890 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
2891 max_gas_payment_objects: Some(256),
2892 max_modules_in_publish: Some(64),
2893 max_package_dependencies: Some(32),
2894 max_arguments: Some(512),
2895 max_type_arguments: Some(16),
2896 max_type_argument_depth: Some(16),
2897 max_pure_argument_size: Some(16 * 1024),
2898 max_programmable_tx_commands: Some(1024),
2899 move_binary_format_version: Some(7),
2900 min_move_binary_format_version: Some(6),
2901 binary_module_handles: Some(100),
2902 binary_struct_handles: Some(300),
2903 binary_function_handles: Some(1500),
2904 binary_function_instantiations: Some(750),
2905 binary_signatures: Some(1000),
2906 binary_constant_pool: Some(4000),
2907 binary_identifiers: Some(10000),
2908 binary_address_identifiers: Some(100),
2909 binary_struct_defs: Some(200),
2910 binary_struct_def_instantiations: Some(100),
2911 binary_function_defs: Some(1000),
2912 binary_field_handles: Some(500),
2913 binary_field_instantiations: Some(250),
2914 binary_friend_decls: Some(100),
2915 binary_enum_defs: None,
2916 binary_enum_def_instantiations: None,
2917 binary_variant_handles: None,
2918 binary_variant_instantiation_handles: None,
2919 max_move_object_size: Some(250 * 1024),
2920 max_move_package_size: Some(100 * 1024),
2921 max_publish_or_upgrade_per_ptb: Some(5),
2922 // max gas budget for an authentication is in NANOS
2923 max_auth_gas: None,
2924 // max gas budget is in NANOS and an absolute value 50IOTA
2925 max_tx_gas: Some(50_000_000_000),
2926 max_gas_price: Some(100_000),
2927 max_gas_computation_bucket: Some(5_000_000),
2928 max_loop_depth: Some(5),
2929 max_generic_instantiation_length: Some(32),
2930 max_function_parameters: Some(128),
2931 max_basic_blocks: Some(1024),
2932 max_value_stack_size: Some(1024),
2933 max_type_nodes: Some(256),
2934 max_push_size: Some(10000),
2935 max_struct_definitions: Some(200),
2936 max_function_definitions: Some(1000),
2937 max_fields_in_struct: Some(32),
2938 max_dependency_depth: Some(100),
2939 max_num_event_emit: Some(1024),
2940 max_num_new_move_object_ids: Some(2048),
2941 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
2942 max_num_deleted_move_object_ids: Some(2048),
2943 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
2944 max_num_transferred_move_object_ids: Some(2048),
2945 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
2946 max_event_emit_size: Some(250 * 1024),
2947 max_move_vector_len: Some(256 * 1024),
2948 max_type_to_layout_nodes: None,
2949 max_ptb_value_size: None,
2950
2951 max_back_edges_per_function: Some(10_000),
2952 max_back_edges_per_module: Some(10_000),
2953
2954 max_verifier_meter_ticks_per_function: Some(16_000_000),
2955
2956 max_meter_ticks_per_module: Some(16_000_000),
2957 max_meter_ticks_per_package: Some(16_000_000),
2958 max_meter_ticks_regex_reference_safety: None,
2959 max_instantiation_loop_graph_edges: None,
2960
2961 object_runtime_max_num_cached_objects: Some(1000),
2962 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2963 object_runtime_max_num_store_entries: Some(1000),
2964 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2965 // min gas budget is in NANOS and an absolute value 1000 NANOS or 0.000001IOTA
2966 base_tx_cost_fixed: Some(1_000),
2967 package_publish_cost_fixed: Some(1_000),
2968 base_tx_cost_per_byte: Some(0),
2969 package_publish_cost_per_byte: Some(80),
2970 obj_access_cost_read_per_byte: Some(15),
2971 obj_access_cost_mutate_per_byte: Some(40),
2972 obj_access_cost_delete_per_byte: Some(40),
2973 obj_access_cost_verify_per_byte: Some(200),
2974 obj_data_cost_refundable: Some(100),
2975 obj_metadata_cost_non_refundable: Some(50),
2976 gas_model_version: Some(1),
2977 storage_rebate_rate: Some(10000),
2978 // Change reward slashing rate to 100%.
2979 reward_slashing_rate: Some(10000),
2980 storage_gas_price: Some(76),
2981 base_gas_price: None,
2982 // The initial subsidy (target reward) for validators per epoch.
2983 // Refer to the IOTA tokenomics for the origin of this value.
2984 validator_target_reward: Some(767_000 * 1_000_000_000),
2985 max_transactions_per_checkpoint: Some(10_000),
2986 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2987
2988 // For now, perform upgrades with a bare quorum of validators.
2989 buffer_stake_for_protocol_upgrade_bps: Some(5000),
2990
2991 // === Native Function Costs ===
2992 // `address` module
2993 // Cost params for the Move native function `address::from_bytes(bytes: vector<u8>)`
2994 address_from_bytes_cost_base: Some(52),
2995 // Cost params for the Move native function `address::to_u256(address): u256`
2996 address_to_u256_cost_base: Some(52),
2997 // Cost params for the Move native function `address::from_u256(u256): address`
2998 address_from_u256_cost_base: Some(52),
2999
3000 // `config` module
3001 // Cost params for the Move native function `read_setting_impl``
3002 config_read_setting_impl_cost_base: Some(100),
3003 config_read_setting_impl_cost_per_byte: Some(40),
3004
3005 // `dynamic_field` module
3006 // Cost params for the Move native function `hash_type_and_key<K: copy + drop +
3007 // store>(parent: address, k: K): address`
3008 dynamic_field_hash_type_and_key_cost_base: Some(100),
3009 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
3010 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
3011 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
3012 // Cost params for the Move native function `add_child_object<Child: key>(parent:
3013 // address, child: Child)`
3014 dynamic_field_add_child_object_cost_base: Some(100),
3015 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
3016 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
3017 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
3018 // Cost params for the Move native function `borrow_child_object_mut<Child: key>(parent:
3019 // &mut UID, id: address): &mut Child`
3020 dynamic_field_borrow_child_object_cost_base: Some(100),
3021 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
3022 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
3023 // Cost params for the Move native function `remove_child_object<Child: key>(parent:
3024 // address, id: address): Child`
3025 dynamic_field_remove_child_object_cost_base: Some(100),
3026 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
3027 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
3028 // Cost params for the Move native function `has_child_object(parent: address, id:
3029 // address): bool`
3030 dynamic_field_has_child_object_cost_base: Some(100),
3031 // Cost params for the Move native function `has_child_object_with_ty<Child:
3032 // key>(parent: address, id: address): bool`
3033 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
3034 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
3035 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
3036
3037 // `event` module
3038 // Cost params for the Move native function `event::emit<T: copy + drop>(event: T)`
3039 event_emit_cost_base: Some(52),
3040 event_emit_value_size_derivation_cost_per_byte: Some(2),
3041 event_emit_tag_size_derivation_cost_per_byte: Some(5),
3042 event_emit_output_cost_per_byte: Some(10),
3043
3044 // `object` module
3045 // Cost params for the Move native function `borrow_uid<T: key>(obj: &T): &UID`
3046 object_borrow_uid_cost_base: Some(52),
3047 // Cost params for the Move native function `delete_impl(id: address)`
3048 object_delete_impl_cost_base: Some(52),
3049 // Cost params for the Move native function `record_new_uid(id: address)`
3050 object_record_new_uid_cost_base: Some(52),
3051
3052 // `transfer` module
3053 // Cost params for the Move native function `transfer_impl<T: key>(obj: T, recipient:
3054 // address)`
3055 transfer_transfer_internal_cost_base: Some(52),
3056 // Cost params for the Move native function `freeze_object<T: key>(obj: T)`
3057 transfer_freeze_object_cost_base: Some(52),
3058 // Cost params for the Move native function `share_object<T: key>(obj: T)`
3059 transfer_share_object_cost_base: Some(52),
3060 transfer_receive_object_cost_base: Some(52),
3061
3062 // `tx_context` module
3063 // Cost params for the Move native function `transfer_impl<T: key>(obj: T, recipient:
3064 // address)`
3065 tx_context_derive_id_cost_base: Some(52),
3066 tx_context_fresh_id_cost_base: None,
3067 tx_context_sender_cost_base: None,
3068 tx_context_digest_cost_base: None,
3069 tx_context_epoch_cost_base: None,
3070 tx_context_epoch_timestamp_ms_cost_base: None,
3071 tx_context_sponsor_cost_base: None,
3072 tx_context_rgp_cost_base: None,
3073 tx_context_gas_price_cost_base: None,
3074 tx_context_gas_budget_cost_base: None,
3075 tx_context_ids_created_cost_base: None,
3076 tx_context_replace_cost_base: None,
3077 tx_context_tx_nonce_cost_base: None,
3078 smart_account_builtin_authenticator_key_proof_message_cost_base: None,
3079
3080 // `types` module
3081 // Cost params for the Move native function `is_one_time_witness<T: drop>(_: &T): bool`
3082 types_is_one_time_witness_cost_base: Some(52),
3083 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
3084 types_is_one_time_witness_type_cost_per_byte: Some(2),
3085
3086 // `validator` module
3087 // Cost params for the Move native function `validate_metadata_bcs(metadata:
3088 // vector<u8>)`
3089 validator_validate_metadata_cost_base: Some(52),
3090 validator_validate_metadata_data_cost_per_byte: Some(2),
3091
3092 // Crypto
3093 crypto_invalid_arguments_cost: Some(100),
3094 // bls12381::bls12381_min_pk_verify
3095 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
3096 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
3097 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
3098
3099 // bls12381::bls12381_min_pk_verify
3100 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
3101 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
3102 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
3103
3104 // ecdsa_k1::ecrecover
3105 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
3106 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
3107 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
3108 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
3109 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
3110 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
3111
3112 // ecdsa_k1::decompress_pubkey
3113 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
3114
3115 // ecdsa_k1::secp256k1_verify
3116 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
3117 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
3118 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
3119 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
3120 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
3121 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
3122
3123 // ecdsa_r1::ecrecover
3124 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
3125 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
3126 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
3127 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
3128 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
3129 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
3130
3131 // ecdsa_r1::secp256k1_verify
3132 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
3133 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
3134 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
3135 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
3136 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
3137 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
3138
3139 // ecvrf::verify
3140 ecvrf_ecvrf_verify_cost_base: Some(52),
3141 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
3142 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
3143
3144 // ed25519
3145 ed25519_ed25519_verify_cost_base: Some(52),
3146 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
3147 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
3148
3149 // groth16::prepare_verifying_key
3150 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
3151 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
3152
3153 // groth16::verify_groth16_proof_internal
3154 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
3155 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
3156 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
3157 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
3158 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
3159
3160 // hash::blake2b256
3161 hash_blake2b256_cost_base: Some(52),
3162 hash_blake2b256_data_cost_per_byte: Some(2),
3163 hash_blake2b256_data_cost_per_block: Some(2),
3164 // hash::keccak256
3165 hash_keccak256_cost_base: Some(52),
3166 hash_keccak256_data_cost_per_byte: Some(2),
3167 hash_keccak256_data_cost_per_block: Some(2),
3168
3169 poseidon_bn254_cost_base: None,
3170 poseidon_bn254_cost_per_block: None,
3171
3172 // hmac::hmac_sha3_256
3173 hmac_hmac_sha3_256_cost_base: Some(52),
3174 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
3175 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
3176
3177 // group ops
3178 group_ops_bls12381_decode_scalar_cost: Some(52),
3179 group_ops_bls12381_decode_g1_cost: Some(52),
3180 group_ops_bls12381_decode_g2_cost: Some(52),
3181 group_ops_bls12381_decode_gt_cost: Some(52),
3182 group_ops_bls12381_scalar_add_cost: Some(52),
3183 group_ops_bls12381_g1_add_cost: Some(52),
3184 group_ops_bls12381_g2_add_cost: Some(52),
3185 group_ops_bls12381_gt_add_cost: Some(52),
3186 group_ops_bls12381_scalar_sub_cost: Some(52),
3187 group_ops_bls12381_g1_sub_cost: Some(52),
3188 group_ops_bls12381_g2_sub_cost: Some(52),
3189 group_ops_bls12381_gt_sub_cost: Some(52),
3190 group_ops_bls12381_scalar_mul_cost: Some(52),
3191 group_ops_bls12381_g1_mul_cost: Some(52),
3192 group_ops_bls12381_g2_mul_cost: Some(52),
3193 group_ops_bls12381_gt_mul_cost: Some(52),
3194 group_ops_bls12381_scalar_div_cost: Some(52),
3195 group_ops_bls12381_g1_div_cost: Some(52),
3196 group_ops_bls12381_g2_div_cost: Some(52),
3197 group_ops_bls12381_gt_div_cost: Some(52),
3198 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
3199 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
3200 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
3201 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
3202 group_ops_bls12381_g1_msm_base_cost: Some(52),
3203 group_ops_bls12381_g2_msm_base_cost: Some(52),
3204 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
3205 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
3206 group_ops_bls12381_msm_max_len: Some(32),
3207 group_ops_bls12381_pairing_cost: Some(52),
3208 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
3209 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
3210 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
3211 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
3212 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
3213
3214 // zklogin::check_zklogin_id
3215 #[allow(deprecated)]
3216 check_zklogin_id_cost_base: Some(200),
3217 #[allow(deprecated)]
3218 // zklogin::check_zklogin_issuer
3219 check_zklogin_issuer_cost_base: Some(200),
3220
3221 vdf_verify_vdf_cost: None,
3222 vdf_hash_to_input_cost: None,
3223
3224 bcs_per_byte_serialized_cost: Some(2),
3225 bcs_legacy_min_output_size_cost: Some(1),
3226 bcs_failure_cost: Some(52),
3227 hash_sha2_256_base_cost: Some(52),
3228 hash_sha2_256_per_byte_cost: Some(2),
3229 hash_sha2_256_legacy_min_input_len_cost: Some(1),
3230 hash_sha3_256_base_cost: Some(52),
3231 hash_sha3_256_per_byte_cost: Some(2),
3232 hash_sha3_256_legacy_min_input_len_cost: Some(1),
3233 type_name_get_base_cost: Some(52),
3234 type_name_get_per_byte_cost: Some(2),
3235 string_check_utf8_base_cost: Some(52),
3236 string_check_utf8_per_byte_cost: Some(2),
3237 string_is_char_boundary_base_cost: Some(52),
3238 string_sub_string_base_cost: Some(52),
3239 string_sub_string_per_byte_cost: Some(2),
3240 string_index_of_base_cost: Some(52),
3241 string_index_of_per_byte_pattern_cost: Some(2),
3242 string_index_of_per_byte_searched_cost: Some(2),
3243 vector_empty_base_cost: Some(52),
3244 vector_length_base_cost: Some(52),
3245 vector_push_back_base_cost: Some(52),
3246 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
3247 vector_borrow_base_cost: Some(52),
3248 vector_pop_back_base_cost: Some(52),
3249 vector_destroy_empty_base_cost: Some(52),
3250 vector_swap_base_cost: Some(52),
3251 debug_print_base_cost: Some(52),
3252 debug_print_stack_trace_base_cost: Some(52),
3253
3254 max_size_written_objects: Some(5 * 1000 * 1000),
3255 // max size of written objects during a system TXn to allow for larger writes
3256 // akin to `max_size_written_objects` but for system TXns
3257 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
3258
3259 // Limits the length of a Move identifier
3260 max_move_identifier_len: Some(128),
3261 max_move_value_depth: Some(128),
3262 max_move_call_argument_nodes: None,
3263 max_move_call_argument_nodes_total: None,
3264 max_move_enum_variants: None,
3265
3266 gas_rounding_step: Some(1_000),
3267
3268 execution_version: Some(1),
3269
3270 // We maintain the same total size limit for events, but increase the number of
3271 // events that can be emitted.
3272 max_event_emit_size_total: Some(
3273 256 /* former event count limit */ * 250 * 1024, // size limit per event
3274 ),
3275
3276 // Taking a baby step approach, we consider only 20% by stake as bad nodes so we
3277 // have a 80% by stake of nodes participating in the leader committee. That
3278 // allow us for more redundancy in case we have validators
3279 // under performing - since the responsibility is shared
3280 // amongst more nodes. We can increase that once we do have
3281 // higher confidence.
3282 consensus_bad_nodes_stake_threshold: Some(20),
3283
3284 // Max of 10 votes per hour.
3285 #[allow(deprecated)]
3286 max_jwk_votes_per_validator_per_epoch: Some(240),
3287
3288 #[allow(deprecated)]
3289 max_age_of_jwk_in_epochs: Some(1),
3290
3291 consensus_max_transaction_size_bytes: Some(256 * 1024), // 256KB
3292
3293 // Assume 1KB per transaction and 500 transactions per block.
3294 consensus_max_transactions_in_block_bytes: Some(512 * 1024),
3295
3296 random_beacon_reduction_allowed_delta: Some(800),
3297
3298 random_beacon_reduction_lower_bound: Some(1000),
3299 random_beacon_dkg_timeout_round: Some(3000),
3300 random_beacon_min_round_interval_ms: Some(500),
3301
3302 random_beacon_dkg_version: Some(1),
3303
3304 // Assume 20_000 TPS * 5% max stake per validator / (minimum) 4 blocks per round
3305 // = 250 transactions per block maximum Using a higher limit
3306 // that is 512, to account for bursty traffic and system transactions.
3307 consensus_max_num_transactions_in_block: Some(512),
3308
3309 max_deferral_rounds_for_congestion_control: Some(10),
3310
3311 min_checkpoint_interval_ms: Some(200),
3312
3313 checkpoint_rate_window_size: None,
3314
3315 checkpoint_summary_version_specific_data: Some(1),
3316 attestor_accuracy_tolerance_percentage: None,
3317 attestation_max_refuted_units_squared: None,
3318 attestation_freshness_window_commits: None,
3319
3320 max_soft_bundle_size: Some(5),
3321
3322 bridge_should_try_to_finalize_committee: None,
3323
3324 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
3325
3326 max_committee_members_count: None,
3327 deny_rule_update_max_entries_per_tx: None,
3328
3329 consensus_gc_depth: None,
3330
3331 consensus_max_acknowledgments_per_block: None,
3332
3333 max_congestion_limit_overshoot_per_commit: None,
3334
3335 max_concurrent_execution_workers: None,
3336
3337 pcool_deterministic_validation_horizon_distance: None,
3338
3339 scorer_version: None,
3340
3341 // `auth_context` module
3342 auth_context_digest_cost_base: None,
3343 auth_context_tx_data_bytes_cost_base: None,
3344 auth_context_tx_data_bytes_cost_per_byte: None,
3345 auth_context_tx_commands_cost_base: None,
3346 auth_context_tx_commands_cost_per_byte: None,
3347 auth_context_tx_inputs_cost_base: None,
3348 auth_context_tx_inputs_cost_per_byte: None,
3349 auth_context_replace_cost_base: None,
3350 auth_context_replace_cost_per_byte: None,
3351 auth_context_authenticator_function_info_v1_cost_base: None,
3352 consensus_commits_per_schedule: None,
3353 min_validator_count: None,
3354 max_validator_count: None,
3355 min_validator_joining_stake: None,
3356 validator_low_stake_threshold: None,
3357 validator_very_low_stake_threshold: None,
3358 validator_low_stake_grace_period: None,
3359 consensus_leader_schedule_window_size: None,
3360
3361 max_move_system_package_size: None,
3362
3363 // Built-in Move authenticators
3364 public_key_verify_builtin_authenticator_signature_impl_cost_base: None,
3365
3366 ed25519_ed25519_validate_pubkey_cost_base: None,
3367 ecdsa_k1_secp256k1_validate_pubkey_cost_base: None,
3368 ecdsa_r1_secp256r1_validate_pubkey_cost_base: None,
3369 multisig_multisig_validate_pubkey_cost_base: None,
3370 public_key_to_iota_address_impl_cost_base: None,
3371 public_key_verify_personal_message_signature_impl_cost_base: None,
3372 public_key_verify_personal_message_signature_impl_msg_cost_per_byte: None,
3373 public_key_verify_personal_message_signature_impl_sig_cost_per_byte: None,
3374 tx_context_chain_identifier_cost_base: None,
3375
3376 claim_account_max_computation_units: None,
3377 claim_account_storage_bytes_bound: None,
3378
3379 // When adding a new constant, set it to None in the earliest version, like this:
3380 // new_constant: None,
3381 };
3382
3383 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
3384
3385 // MoveVM related flags
3386 {
3387 cfg.feature_flags
3388 .disable_invariant_violation_check_in_swap_loc = true;
3389 cfg.feature_flags.no_extraneous_module_bytes = true;
3390 cfg.feature_flags.hardened_otw_check = true;
3391 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
3392 }
3393
3394 // zkLogin related flags
3395 {
3396 #[allow(deprecated)]
3397 {
3398 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
3399 }
3400 }
3401
3402 // Historical default: Mysticeti. Kept explicitly to match the
3403 // serialized form of pre-v14/v19/v24 configs. No runtime behavior
3404 // depends on this — Starfish is the only consensus protocol.
3405 #[expect(deprecated)]
3406 {
3407 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
3408 }
3409 // Use tonic networking for consensus.
3410 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
3411
3412 cfg.feature_flags.per_object_congestion_control_mode =
3413 PerObjectCongestionControlMode::TotalTxCount;
3414
3415 // Do not allow bridge committee to finalize on mainnet.
3416 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
3417
3418 // Devnet
3419 if chain != Chain::Mainnet && chain != Chain::Testnet {
3420 cfg.feature_flags.enable_poseidon = true;
3421 cfg.poseidon_bn254_cost_base = Some(260);
3422 cfg.poseidon_bn254_cost_per_block = Some(10);
3423
3424 cfg.feature_flags.enable_group_ops_native_function_msm = true;
3425
3426 cfg.feature_flags.enable_vdf = true;
3427 // Set to 30x and 2x the cost of a signature verification for now. This
3428 // should be updated along with other native crypto functions.
3429 cfg.vdf_verify_vdf_cost = Some(1500);
3430 cfg.vdf_hash_to_input_cost = Some(100);
3431
3432 cfg.feature_flags.passkey_auth = true;
3433 }
3434
3435 for cur in 2..=version.0 {
3436 match cur {
3437 1 => unreachable!(),
3438 // version 2 is a new framework version but with no config changes
3439 2 => {}
3440 3 => {
3441 cfg.feature_flags.relocate_event_module = true;
3442 }
3443 4 => {
3444 cfg.max_type_to_layout_nodes = Some(512);
3445 }
3446 5 => {
3447 cfg.feature_flags.protocol_defined_base_fee = true;
3448 cfg.base_gas_price = Some(1000);
3449
3450 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
3451 cfg.feature_flags.convert_type_argument_error = true;
3452 cfg.feature_flags.native_charging_v2 = true;
3453
3454 if chain != Chain::Mainnet && chain != Chain::Testnet {
3455 cfg.feature_flags.uncompressed_g1_group_elements = true;
3456 }
3457
3458 cfg.gas_model_version = Some(2);
3459
3460 cfg.poseidon_bn254_cost_per_block = Some(388);
3461
3462 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
3463 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
3464 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
3465 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
3466 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
3467 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
3468 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
3469 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
3470
3471 // Manually changed to be "under cost"
3472 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
3473 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
3474 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
3475 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
3476
3477 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
3478 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
3479 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
3480 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
3481 Some(8213);
3482 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
3483 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
3484 Some(9484);
3485
3486 cfg.hash_keccak256_cost_base = Some(10);
3487 cfg.hash_blake2b256_cost_base = Some(10);
3488
3489 // group ops
3490 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
3491 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
3492 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
3493 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
3494
3495 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
3496 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
3497 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
3498 cfg.group_ops_bls12381_gt_add_cost = Some(188);
3499
3500 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
3501 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
3502 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
3503 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
3504
3505 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
3506 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
3507 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
3508 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
3509
3510 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
3511 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
3512 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
3513 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
3514
3515 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
3516 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
3517
3518 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
3519 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
3520 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
3521 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
3522
3523 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
3524 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
3525 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
3526 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
3527 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
3528
3529 cfg.group_ops_bls12381_pairing_cost = Some(26897);
3530
3531 cfg.validator_validate_metadata_cost_base = Some(20000);
3532
3533 cfg.max_committee_members_count = Some(50);
3534 }
3535 6 => {
3536 cfg.max_ptb_value_size = Some(1024 * 1024);
3537 }
3538 7 => {
3539 // version 7 is a new framework version but with no config
3540 // changes
3541 }
3542 8 => {
3543 cfg.feature_flags.variant_nodes = true;
3544
3545 if chain != Chain::Mainnet {
3546 // Enable round prober in consensus.
3547 cfg.feature_flags.consensus_round_prober = true;
3548 // Enable distributed vote scoring.
3549 cfg.feature_flags
3550 .consensus_distributed_vote_scoring_strategy = true;
3551 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
3552 // Enable smart ancestor selection for testnet
3553 cfg.feature_flags.consensus_smart_ancestor_selection = true;
3554 // Enable probing for accepted rounds in round prober for testnet
3555 cfg.feature_flags
3556 .consensus_round_prober_probe_accepted_rounds = true;
3557 // Enable zstd compression for consensus in testnet
3558 cfg.feature_flags.consensus_zstd_compression = true;
3559 // Assuming a round rate of max 15/sec, then using a gc depth of 60 allow
3560 // blocks within a window of ~4 seconds
3561 // to be included before be considered garbage collected.
3562 cfg.consensus_gc_depth = Some(60);
3563 }
3564
3565 // Enable min_free_execution_slot for the shared object congestion tracker in
3566 // devnet.
3567 if chain != Chain::Testnet && chain != Chain::Mainnet {
3568 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
3569 }
3570 }
3571 9 => {
3572 if chain != Chain::Mainnet {
3573 // Disable smart ancestor selection in the testnet and devnet.
3574 cfg.feature_flags.consensus_smart_ancestor_selection = false;
3575 }
3576
3577 // Enable zstd compression for consensus
3578 cfg.feature_flags.consensus_zstd_compression = true;
3579
3580 // Enable passkey in multisig in devnet.
3581 if chain != Chain::Testnet && chain != Chain::Mainnet {
3582 cfg.feature_flags.accept_passkey_in_multisig = true;
3583 }
3584
3585 // this flag is now deprecated because of the bridge removal.
3586 cfg.bridge_should_try_to_finalize_committee = None;
3587 }
3588 10 => {
3589 // Enable min_free_execution_slot for the shared object congestion tracker in
3590 // all networks.
3591 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
3592
3593 // Increase the committee size to 80 on all networks.
3594 cfg.max_committee_members_count = Some(80);
3595
3596 // Enable round prober in consensus.
3597 cfg.feature_flags.consensus_round_prober = true;
3598 // Enable probing for accepted rounds in round.
3599 cfg.feature_flags
3600 .consensus_round_prober_probe_accepted_rounds = true;
3601 // Enable distributed vote scoring.
3602 cfg.feature_flags
3603 .consensus_distributed_vote_scoring_strategy = true;
3604 // Enable the new consensus commit rule.
3605 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
3606
3607 // Enable consensus garbage collection
3608 // Assuming a round rate of max 15/sec, then using a gc depth of 60 allow
3609 // blocks within a window of ~4 seconds
3610 // to be included before be considered garbage collected.
3611 cfg.consensus_gc_depth = Some(60);
3612
3613 // Enable minimized child object mutation counting.
3614 cfg.feature_flags.minimize_child_object_mutations = true;
3615
3616 if chain != Chain::Mainnet {
3617 // Enable batched block sync in devnet and testnet.
3618 cfg.feature_flags.consensus_batched_block_sync = true;
3619 }
3620
3621 if chain != Chain::Testnet && chain != Chain::Mainnet {
3622 // Enable the gas price feedback mechanism (which is used for
3623 // transactions cancelled due to shared object congestion) in devnet
3624 cfg.feature_flags
3625 .congestion_control_gas_price_feedback_mechanism = true;
3626 }
3627
3628 cfg.feature_flags.validate_identifier_inputs = true;
3629 cfg.feature_flags.dependency_linkage_error = true;
3630 cfg.feature_flags.additional_multisig_checks = true;
3631 }
3632 11 => {
3633 // version 11 is a new framework version but with no config
3634 // changes
3635 }
3636 12 => {
3637 // Enable the gas price feedback mechanism for transactions
3638 // cancelled due to congestion in all networks
3639 cfg.feature_flags
3640 .congestion_control_gas_price_feedback_mechanism = true;
3641
3642 // Enable normalization of PTB arguments in all networks.
3643 cfg.feature_flags.normalize_ptb_arguments = true;
3644 }
3645 13 => {
3646 // Enable selecting committee based on eligible active validators on all
3647 // networks.
3648 cfg.feature_flags.select_committee_from_eligible_validators = true;
3649 // Enable tracking non-committee eligible active
3650 // validators on all networks.
3651 cfg.feature_flags.track_non_committee_eligible_validators = true;
3652
3653 if chain != Chain::Testnet && chain != Chain::Mainnet {
3654 // Enable selecting committee only from active validators that next epoch
3655 // version and issued valid AuthorityCapabilities notification in devnet.
3656 cfg.feature_flags
3657 .select_committee_supporting_next_epoch_version = true;
3658 }
3659 }
3660 14 => {
3661 // Enable batched block sync for mainnet.
3662 cfg.feature_flags.consensus_batched_block_sync = true;
3663
3664 if chain != Chain::Mainnet {
3665 // Enable median-based commit timestamp calculation in consensus and
3666 // enforce checkpoint timestamp monotonicity for testnet.
3667 cfg.feature_flags
3668 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3669 // Enable selecting committee only from active validators that support the
3670 // next epoch's version and issued valid AuthorityCapabilities notification
3671 // in testnet.
3672 cfg.feature_flags
3673 .select_committee_supporting_next_epoch_version = true;
3674 }
3675 if chain != Chain::Testnet && chain != Chain::Mainnet {
3676 // Switch consensus protocol to Starfish in devnet
3677 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3678 }
3679 }
3680 15 => {
3681 if chain != Chain::Mainnet && chain != Chain::Testnet {
3682 // Enable overshoot of 100 in congestion control. This allows bursts of
3683 // shared object transactions up to 10 times the average allowable
3684 // load set by `max_accumulated_txn_cost_per_object_in_mysticeti_commit`.
3685 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3686 }
3687 }
3688 16 => {
3689 // Enable selecting committee only from active validators that support the
3690 // next epoch's version and issued valid AuthorityCapabilities notification.
3691 cfg.feature_flags
3692 .select_committee_supporting_next_epoch_version = true;
3693 // Enable committing transactions only for traversed headers in Starfish
3694 cfg.feature_flags
3695 .consensus_commit_transactions_only_for_traversed_headers = true;
3696 }
3697 17 => {
3698 // Increase the committee size to 100 on all networks.
3699 cfg.max_committee_members_count = Some(100);
3700 }
3701 18 => {
3702 if chain != Chain::Mainnet {
3703 // Enable passkey authentication support in testnet.
3704 cfg.feature_flags.passkey_auth = true;
3705 }
3706 }
3707 19 => {
3708 if chain != Chain::Testnet && chain != Chain::Mainnet {
3709 // Enable congestion limit overshoot in the gas price feedback
3710 // mechanism on devnet.
3711 cfg.feature_flags
3712 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3713 // Enable a separate gas price feedback mechanism for transactions using
3714 // randomness on devnet.
3715 cfg.feature_flags
3716 .separate_gas_price_feedback_mechanism_for_randomness = true;
3717 // Enable storing metadata in module bytes and then
3718 // publishing package metadata in devnet
3719 cfg.feature_flags.metadata_in_module_bytes = true;
3720 cfg.feature_flags.publish_package_metadata = true;
3721 // Enable Move authentication in devnet
3722 cfg.feature_flags.enable_move_authentication = true;
3723 // Max auth gas budget is in NANOS and an absolute value 0.25 IOTA
3724 cfg.max_auth_gas = Some(250_000_000);
3725 // Increase the base cost for transfer receive object in devnet, since the
3726 // implementation now does check if parent is not an account.
3727 cfg.transfer_receive_object_cost_base = Some(100);
3728 // Enable adjustment of validator rewards based on score in devnet.
3729 cfg.feature_flags.adjust_rewards_by_score = true;
3730 }
3731
3732 if chain != Chain::Mainnet {
3733 // Switch consensus protocol to Starfish in testnet.
3734 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3735
3736 // Enable validator score calculation on testnet
3737 cfg.feature_flags.calculate_validator_scores = true;
3738 cfg.scorer_version = Some(1);
3739 }
3740
3741 // Change epoch transaction will contain validator scores
3742 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
3743
3744 // Enable passkey authentication support in mainnet
3745 cfg.feature_flags.passkey_auth = true;
3746 }
3747 20 => {
3748 if chain != Chain::Testnet && chain != Chain::Mainnet {
3749 // Passes the calculated validator scores to advance epoch only on Devnet
3750 cfg.feature_flags
3751 .pass_calculated_validator_scores_to_advance_epoch = true;
3752 }
3753 }
3754 21 => {
3755 if chain != Chain::Testnet && chain != Chain::Mainnet {
3756 // Enable fast commit syncer for faster recovery in devnet.
3757 cfg.feature_flags.consensus_fast_commit_sync = true;
3758 }
3759 if chain != Chain::Mainnet {
3760 // Enable overshoot of 100 in congestion control on testnet.
3761 // This allows bursts of shared-object transactions
3762 // up to 10 times the average allowable load set by
3763 // `max_accumulated_txn_cost_per_object_in_mysticeti_commit`.
3764 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3765 // Enable congestion limit overshoot in the gas price feedback
3766 // mechanism on testnet.
3767 cfg.feature_flags
3768 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3769 // Enable a separate gas price feedback mechanism for transactions using
3770 // randomness on testnet.
3771 cfg.feature_flags
3772 .separate_gas_price_feedback_mechanism_for_randomness = true;
3773 }
3774
3775 cfg.auth_context_digest_cost_base = Some(30);
3776 cfg.auth_context_tx_commands_cost_base = Some(30);
3777 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
3778 cfg.auth_context_tx_inputs_cost_base = Some(30);
3779 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
3780 cfg.auth_context_replace_cost_base = Some(30);
3781 cfg.auth_context_replace_cost_per_byte = Some(2);
3782
3783 if chain != Chain::Testnet && chain != Chain::Mainnet {
3784 // Decrease max_auth_gas to 0.00025 IOTA
3785 cfg.max_auth_gas = Some(250_000);
3786 }
3787 }
3788 22 => {
3789 // Enable overshoot of 100 in congestion control on all networks.
3790 // This allows bursts of shared-object transactions
3791 // up to 10 times the average allowable load set by
3792 // `max_accumulated_txn_cost_per_object_in_mysticeti_commit`.
3793 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3794 // Enable congestion limit overshoot in the gas price feedback
3795 // mechanism on all networks.
3796 cfg.feature_flags
3797 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3798 // Enable a separate gas price feedback mechanism for transactions using
3799 // randomness on all networks.
3800 cfg.feature_flags
3801 .separate_gas_price_feedback_mechanism_for_randomness = true;
3802
3803 if chain != Chain::Mainnet {
3804 // Enable storing metadata in module bytes and then
3805 // publishing package metadata in testnet
3806 cfg.feature_flags.metadata_in_module_bytes = true;
3807 cfg.feature_flags.publish_package_metadata = true;
3808 // Enable Move authentication in testnet
3809 cfg.feature_flags.enable_move_authentication = true;
3810 // Max_auth_gas is 0.00025 IOTA
3811 cfg.max_auth_gas = Some(250_000);
3812 // Increase the base cost for transfer receive object in testnet, since the
3813 // implementation now does check if parent is not an account.
3814 cfg.transfer_receive_object_cost_base = Some(100);
3815 }
3816
3817 if chain != Chain::Mainnet {
3818 // Enable fast commit syncer for faster recovery on testnet.
3819 cfg.feature_flags.consensus_fast_commit_sync = true;
3820 }
3821 }
3822 23 => {
3823 // Enable Move native context (TxContext via native functions) in all networks.
3824 cfg.feature_flags.move_native_tx_context = true;
3825 cfg.tx_context_fresh_id_cost_base = Some(52);
3826 cfg.tx_context_sender_cost_base = Some(30);
3827 cfg.tx_context_digest_cost_base = Some(30);
3828 cfg.tx_context_epoch_cost_base = Some(30);
3829 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
3830 cfg.tx_context_sponsor_cost_base = Some(30);
3831 cfg.tx_context_rgp_cost_base = Some(30);
3832 cfg.tx_context_gas_price_cost_base = Some(30);
3833 cfg.tx_context_gas_budget_cost_base = Some(30);
3834 cfg.tx_context_ids_created_cost_base = Some(30);
3835 cfg.tx_context_replace_cost_base = Some(30);
3836 }
3837 24 => {
3838 // Switch consensus protocol to Starfish in all networks.
3839 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3840
3841 if chain != Chain::Testnet && chain != Chain::Mainnet {
3842 // Enable Move-based sponsor account authentication in devnet.
3843 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3844 }
3845
3846 // Add tx_data_bytes to AuthContext for intent-based signature
3847 // verification in account abstraction.
3848 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
3849 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
3850
3851 // Enable additional borrow checks.
3852 cfg.feature_flags.additional_borrow_checks = true;
3853 }
3854 #[allow(deprecated)]
3855 25 => {
3856 // Deprecate zkLogin related parameters since zkLogin is deprecated and was
3857 // never enabled on IOTA.
3858 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
3859 cfg.check_zklogin_id_cost_base = None;
3860 cfg.check_zklogin_issuer_cost_base = None;
3861 cfg.max_jwk_votes_per_validator_per_epoch = None;
3862 cfg.max_age_of_jwk_in_epochs = None;
3863 }
3864 26 => {
3865 // Introduce a module to allow Move code to query protocol
3866 // feature flags at runtime.
3867 }
3868 27 => {
3869 if chain != Chain::Mainnet {
3870 // Enable consensus block restrictions on testnet/devnet to bound
3871 // header size by committee size.
3872 cfg.feature_flags.consensus_block_restrictions = true;
3873 }
3874
3875 if chain != Chain::Testnet && chain != Chain::Mainnet {
3876 // Only sponsor Move authentication is performed pre-consensus in devnet.
3877 cfg.feature_flags
3878 .pre_consensus_sponsor_only_move_authentication = true;
3879 }
3880 }
3881 28 => {
3882 // AuthenticatorFunctionInfoV1 max BCS size:
3883 // package (32) + module_name (128) + function_name (128) = 288 bytes = 9 ×
3884 // digest. auth_context_digest_cost_base = 30 for 32 bytes →
3885 // 9 × 30 = 270.
3886 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
3887
3888 // Enable storing metadata in module bytes and then
3889 // publishing package metadata in mainnet.
3890 cfg.feature_flags.metadata_in_module_bytes = true;
3891 cfg.feature_flags.publish_package_metadata = true;
3892 // Enable Move authentication in mainnet.
3893 cfg.feature_flags.enable_move_authentication = true;
3894 // Increase the base cost for transfer receive object in mainnet, since the
3895 // implementation now does check if parent is not an account.
3896 cfg.transfer_receive_object_cost_base = Some(100);
3897
3898 if chain != Chain::Unknown {
3899 // max_auth_gas is 0.00002 IOTA in testnet and mainnet.
3900 cfg.max_auth_gas = Some(20_000);
3901 }
3902
3903 if chain != Chain::Mainnet {
3904 // Enable Move-based sponsor account authentication in testnet.
3905 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3906 // Only sponsor Move authentication is performed pre-consensus in testnet.
3907 cfg.feature_flags
3908 .pre_consensus_sponsor_only_move_authentication = true;
3909 }
3910 }
3911 29 => {
3912 // Keep advancing the random beacon DKG state machine on every commit
3913 // while it is still pending so DKG resolves from persisted state
3914 // (completing, or failing once the timeout round passes) even with no
3915 // fresh inbound traffic -- e.g. after a validator restart -- instead of
3916 // staying pending forever and blocking epoch close.
3917 cfg.feature_flags.always_advance_dkg_to_resolution = true;
3918
3919 // Enable median-based commit timestamp calculation in consensus and
3920 // enforce checkpoint timestamp monotonicity for mainnet.
3921 cfg.feature_flags
3922 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3923
3924 // Enable fast commit syncer for faster recovery on all networks.
3925 cfg.feature_flags.consensus_fast_commit_sync = true;
3926 // Enable consensus block restrictions on all networks to bound
3927 // header size by committee size and garbage-collect the block
3928 // manager.
3929 cfg.feature_flags.consensus_block_restrictions = true;
3930 }
3931 30 => {
3932 // Extend the protocol_config framework module with
3933 // `get_attr<T>`, a generic native that lets Move code
3934 // read any numeric or boolean protocol parameter by name,
3935 // returning T directly and aborting on error.
3936 // Also expose `is_feature_enabled` and `get_attr<T>` to
3937 // iota_system via a new iota_system::protocol_config
3938 // module.
3939 }
3940 31 => {
3941 cfg.feature_flags.validator_metadata_verify_v2 = true;
3942
3943 if chain != Chain::Mainnet && chain != Chain::Testnet {
3944 // Amortize the minimum checkpoint interval over a sliding
3945 // window so the checkpoint rate holds at the ceiling.
3946 cfg.checkpoint_rate_window_size = Some(20);
3947 // Publish package metadata with the module metadata stored as a
3948 // dynamic field.
3949 cfg.feature_flags
3950 .package_metadata_with_dynamic_module_metadata = true;
3951 // Enable the optimistic commit rule (StarfishSpeed) in
3952 // Starfish consensus.
3953 cfg.feature_flags.consensus_starfish_speed = true;
3954 }
3955
3956 cfg.feature_flags.report_move_authentication_error = true;
3957 }
3958 32 => {
3959 // Identical to the genesis SystemParametersV1 values on
3960 // all existing networks; enforcement moves from on-chain
3961 // state to the protocol config.
3962 cfg.min_validator_count = Some(4);
3963 cfg.max_validator_count = Some(150);
3964 cfg.min_validator_joining_stake = Some(2_000_000_000_000_000);
3965 cfg.validator_low_stake_threshold = Some(1_500_000_000_000_000);
3966 cfg.validator_very_low_stake_threshold = Some(1_000_000_000_000_000);
3967 cfg.validator_low_stake_grace_period = Some(7);
3968
3969 // Enable Move-based sponsor account authentication in mainnet.
3970 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3971 // Only sponsor Move authentication is performed pre-consensus in mainnet.
3972 cfg.feature_flags
3973 .pre_consensus_sponsor_only_move_authentication = true;
3974
3975 if chain != Chain::Mainnet {
3976 // Enable the optimistic commit rule (StarfishSpeed) in
3977 // Starfish consensus.
3978 cfg.feature_flags.consensus_starfish_speed = true;
3979 // Amortize the minimum checkpoint interval over a sliding
3980 // window so the checkpoint rate holds at the ceiling.
3981 cfg.checkpoint_rate_window_size = Some(20);
3982 // Publish package metadata with the module metadata stored as a
3983 // dynamic field.
3984 cfg.feature_flags
3985 .package_metadata_with_dynamic_module_metadata = true;
3986 }
3987
3988 if chain != Chain::Mainnet && chain != Chain::Testnet {
3989 // Enable the redesigned leader schedule: sliding-window
3990 // reputation scoring and absolute-score bad-node
3991 // selection.
3992 cfg.feature_flags
3993 .consensus_enable_sliding_window_leader_schedule = true;
3994 cfg.feature_flags
3995 .consensus_enable_absolute_score_leader_schedule = true;
3996 // Enable the P-COOL flow: transactions skip
3997 // pre-consensus certification and owned-object locking,
3998 // and conflicts are resolved after consensus.
3999 cfg.feature_flags.enable_pcool_flow = true;
4000 }
4001 }
4002 33 => {
4003 // Amortize the minimum checkpoint interval over a sliding
4004 // window so the checkpoint rate holds at the ceiling.
4005 cfg.checkpoint_rate_window_size = Some(20);
4006 // Enable the redesigned leader schedule: sliding-window
4007 // reputation scoring and absolute-score bad-node
4008 // selection.
4009 if chain != Chain::Mainnet {
4010 cfg.feature_flags
4011 .consensus_enable_sliding_window_leader_schedule = true;
4012 cfg.feature_flags
4013 .consensus_enable_absolute_score_leader_schedule = true;
4014 }
4015 }
4016 34 => {
4017 if chain != Chain::Testnet && chain != Chain::Mainnet {
4018 // Misbehavior reports carry a dedicated counter for
4019 // invalid bundle parts, previously folded into the
4020 // unprovable block-fault counter.
4021 cfg.scorer_version = Some(2);
4022 }
4023 // Stop locking immutable objects in post-consensus conflict
4024 // resolution. Set on all chains; inert where the P-COOL flow
4025 // is off.
4026 cfg.feature_flags.pcool_skip_immutable_object_locks = true;
4027
4028 if chain == Chain::Mainnet {
4029 // Disable Move-based sponsor account authentication.
4030 cfg.feature_flags.enable_move_authentication_for_sponsor = false;
4031 // The pre-consensus sponsor-only flag requires
4032 // `enable_move_authentication_for_sponsor`, so clear it too.
4033 cfg.feature_flags
4034 .pre_consensus_sponsor_only_move_authentication = false;
4035 }
4036 }
4037 35 => {
4038 // Scale the PTB value size limit by the value's type.
4039 cfg.feature_flags.max_ptb_value_size_v2 = true;
4040 // Let system objects grow past the per-object size bound.
4041 cfg.feature_flags.allow_unbounded_system_objects = true;
4042
4043 // Enable the optimistic commit rule (StarfishSpeed) in
4044 // Starfish consensus.
4045 cfg.feature_flags.consensus_starfish_speed = true;
4046
4047 // Post-consensus validation meters published packages with
4048 // the limits below instead of each validator's own
4049 // `VerifierSigningConfig`. The values are that config's
4050 // defaults, so a validator that leaves it alone reaches
4051 // the same result at admission and post-consensus. Set on
4052 // all chains; inert where the P-COOL flow is off.
4053 cfg.max_verifier_meter_ticks_per_function = Some(2_200_000);
4054 cfg.max_meter_ticks_per_module = Some(2_200_000);
4055 cfg.max_meter_ticks_per_package = Some(2_200_000);
4056 cfg.max_meter_ticks_regex_reference_safety = Some(2_200_000);
4057 cfg.feature_flags.pcool_verifier_limits_from_protocol_config = true;
4058 // Publish package metadata with the module metadata stored as a
4059 // dynamic field.
4060 cfg.feature_flags
4061 .package_metadata_with_dynamic_module_metadata = true;
4062 // Enable the redesigned leader schedule: sliding-window
4063 // reputation scoring and absolute-score bad-node
4064 // selection.
4065 cfg.feature_flags
4066 .consensus_enable_sliding_window_leader_schedule = true;
4067 cfg.feature_flags
4068 .consensus_enable_absolute_score_leader_schedule = true;
4069
4070 // Enable Move-based sponsor account authentication on all
4071 // networks.
4072 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
4073 // Run every `MoveAuthenticator` pre-consensus again, not
4074 // just the sponsor's, on all networks.
4075 cfg.feature_flags
4076 .pre_consensus_sponsor_only_move_authentication = false;
4077 }
4078 36 => {
4079 // No immutable account object can authenticate a sender or
4080 // a sponsor.
4081 cfg.feature_flags.reject_immutable_account_objects = true;
4082 }
4083 37 => {
4084 // Refuse object versions in, or right below, the range
4085 // assigned to canceled transactions before any object is
4086 // loaded, by consulting the transaction bytes only.
4087 cfg.feature_flags.validate_input_object_versions = true;
4088 cfg.feature_flags.disallow_self_identifier = true;
4089 cfg.max_move_enum_variants = Some(move_core_types::VARIANT_COUNT_MAX);
4090 // Apply the package deny list to the package that holds a
4091 // `MoveAuthenticator`'s authenticate function.
4092 cfg.feature_flags.deny_authenticator_packages = true;
4093 // Require a published module header to carry the canonical
4094 // encoding of its binary format version.
4095 cfg.feature_flags.check_canonical_module_version_header = true;
4096 // An authenticate function cannot read randomness, so the
4097 // randomness state object is refused as an authenticator
4098 // input instead of scheduling the transaction as
4099 // randomness-using for nothing.
4100 cfg.feature_flags.disallow_randomness_in_move_authenticator = true;
4101 // Traverse the module graph when checking for cyclic
4102 // dependencies.
4103 cfg.feature_flags.check_cyclic_dependencies = true;
4104 }
4105 38 => {
4106 // A system package is published by the network, not by a
4107 // user, so the user-package bound was never meant to apply
4108 // to it: an existing system package is already exempt when
4109 // it is upgraded at an epoch change, and only a first
4110 // publish (genesis, or a newly added system package) is
4111 // checked against it.
4112 cfg.max_move_system_package_size = Some(200 * 1024);
4113 // An immutable account object cannot authenticate anything
4114 // since version 36, so stop creating new ones.
4115 cfg.feature_flags.reject_immutable_account_creation = true;
4116
4117 cfg.feature_flags.validate_ptb_argument_indices = true;
4118 }
4119 39 => {
4120 // Keep random beacon DKG running after its timeout round, so
4121 // randomness is enabled again mid-epoch if DKG completes late.
4122 if chain != Chain::Mainnet {
4123 cfg.feature_flags.allow_dkg_completion_after_timeout = true;
4124 }
4125
4126 cfg.feature_flags.consensus_dedup_only_recorded_messages = true;
4127
4128 // Raise the minimum validator joining stake to 6M IOTA, the low
4129 // stake threshold to 5.5M IOTA and the very low stake threshold to
4130 // 5M IOTA on all chains.
4131 cfg.min_validator_joining_stake = Some(6_000_000_000_000_000);
4132 cfg.validator_low_stake_threshold = Some(5_500_000_000_000_000);
4133 cfg.validator_very_low_stake_threshold = Some(5_000_000_000_000_000);
4134
4135 // Reject a multisig whose committee mixes Ed25519 with other key
4136 // schemes unless every committee member has signed.
4137 cfg.feature_flags
4138 .reject_partially_signed_mixed_ed25519_multisig = true;
4139
4140 if chain != Chain::Mainnet && chain != Chain::Testnet {
4141 // Post-consensus validation reads object state as of
4142 // 4 commits below the one it validates.
4143 cfg.pcool_deterministic_validation_horizon_distance = Some(4);
4144 // Mirror the governed deny rules into the on-chain
4145 // object in chunks of at most 1000 entries.
4146 cfg.deny_rule_update_max_entries_per_tx = Some(1000);
4147 }
4148
4149 // Reject Groth16 verifying keys whose size does not match the
4150 // number of public inputs before deserializing them.
4151 cfg.feature_flags.limit_groth16_pvk_inputs = true;
4152 cfg.feature_flags.check_groth16_pvk_length = true;
4153
4154 // At execution too, not only at signing: reject the
4155 // deprecated global storage instructions and non-empty
4156 // `acquires` lists when deserializing a module, and verify
4157 // modules without the acquires pass and with vector element
4158 // borrows checked by the call rule.
4159 cfg.feature_flags.deprecate_global_storage_ops = true;
4160 }
4161 40 => {
4162 // Post-consensus validation meters the instantiation-loop
4163 // check and caps its graph with these values, which signing
4164 // also uses.
4165 cfg.feature_flags.meter_instantiation_loops = true;
4166 cfg.max_instantiation_loop_graph_edges = Some(100_000);
4167
4168 // Make the packages named by a `MoveAuthenticator`'s type
4169 // arguments inputs of that authenticator.
4170 cfg.feature_flags
4171 .move_authenticator_type_arg_packages_as_inputs = true;
4172
4173 // Limit the struct, enum and vector values in Move-call
4174 // arguments.
4175 cfg.max_move_call_argument_nodes = Some(2_097_152);
4176 cfg.max_move_call_argument_nodes_total = Some(16_777_216);
4177
4178 // Reject `<SELF>` as an identifier in transactions, at
4179 // signing, after consensus and in block verification.
4180 cfg.feature_flags.disallow_self_identifier_in_transactions = true;
4181
4182 // Update the gas model version.
4183 cfg.gas_model_version = Some(3);
4184
4185 if chain != Chain::Mainnet && chain != Chain::Testnet {
4186 // Validators attest the user transactions they propose,
4187 // and the checkpoint summary certifies the verdicts.
4188 cfg.feature_flags.enable_validator_attestation = true;
4189 cfg.checkpoint_summary_version_specific_data = Some(2);
4190 }
4191 }
4192 41 => {
4193 // Commit a block's transactions once its header is
4194 // traversed, also when their acknowledgment quorum came
4195 // first.
4196 if chain != Chain::Mainnet {
4197 cfg.feature_flags
4198 .consensus_commit_transactions_once_traversed = true;
4199 }
4200
4201 // `ecdsa_r1::secp256r1_ecrecover` rejects a signature
4202 // whose restored x-coordinate is not below the field
4203 // modulus.
4204 cfg.feature_flags.secp256r1_ecrecover_checks_x_below_p = true;
4205
4206 if chain != Chain::Mainnet && chain != Chain::Testnet {
4207 // A programmable transaction may carry a transaction
4208 // dependency input.
4209 cfg.feature_flags.enable_transaction_dependencies = true;
4210 // Raise max_auth_gas to 0.001 IOTA, the minimum transaction
4211 // cost at a gas price of 1000.
4212 cfg.max_auth_gas = Some(1_000_000);
4213
4214 // Ten minutes at devnet's 20 commits a second.
4215 cfg.attestation_freshness_window_commits = Some(12_000);
4216
4217 // Cuts an attestor off after no more than 100 refuted
4218 // attestations per epoch at the current `max_auth_gas`.
4219 cfg.attestation_max_refuted_units_squared = Some(100_000_000);
4220 }
4221 }
4222 42 => {
4223 if chain != Chain::Testnet && chain != Chain::Mainnet {
4224 // Enable built-in Move authenticators in devnet.
4225 cfg.feature_flags.enable_builtin_move_authenticators = true;
4226 // Enable creating smart accounts in devnet only.
4227 cfg.feature_flags.enable_smart_accounts = true;
4228
4229 // Set the cost for built-in Move authenticators to 0 for now.
4230 cfg.public_key_verify_builtin_authenticator_signature_impl_cost_base =
4231 Some(0);
4232 }
4233
4234 cfg.ed25519_ed25519_validate_pubkey_cost_base = Some(170);
4235 cfg.ecdsa_k1_secp256k1_validate_pubkey_cost_base = Some(176);
4236 cfg.ecdsa_r1_secp256r1_validate_pubkey_cost_base = Some(325);
4237 cfg.multisig_multisig_validate_pubkey_cost_base = Some(72);
4238 cfg.public_key_to_iota_address_impl_cost_base = Some(341);
4239 cfg.public_key_verify_personal_message_signature_impl_cost_base = Some(4225);
4240 cfg.public_key_verify_personal_message_signature_impl_msg_cost_per_byte =
4241 Some(2);
4242 cfg.public_key_verify_personal_message_signature_impl_sig_cost_per_byte =
4243 Some(2);
4244 cfg.tx_context_chain_identifier_cost_base = Some(30);
4245 cfg.tx_context_tx_nonce_cost_base = Some(30);
4246 cfg.smart_account_builtin_authenticator_key_proof_message_cost_base = Some(52);
4247 }
4248 // Use this template when making changes:
4249 //
4250 // // modify an existing constant.
4251 // move_binary_format_version: Some(7),
4252 //
4253 // // Add a new constant (which is set to None in prior versions).
4254 // new_constant: Some(new_value),
4255 //
4256 // // Remove a constant (ensure that it is never accessed during this version).
4257 // max_move_object_size: None,
4258 _ => panic!("unsupported version {version:?}"),
4259 }
4260 }
4261 cfg
4262 }
4263
4264 // Extract the bytecode verifier config from this protocol config.
4265 // If used during signing, `signing_limits` should be set.
4266 // The third limit configures`sanity_check_with_regex_reference_safety`,
4267 // which runs the new regex-based reference safety check to check that it is
4268 // strictly more permissive than the current implementation.
4269 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
4270 let (
4271 max_back_edges_per_function,
4272 max_back_edges_per_module,
4273 sanity_check_with_regex_reference_safety,
4274 ) = if let Some((
4275 max_back_edges_per_function,
4276 max_back_edges_per_module,
4277 sanity_check_with_regex_reference_safety,
4278 )) = signing_limits
4279 {
4280 (
4281 Some(max_back_edges_per_function),
4282 Some(max_back_edges_per_module),
4283 Some(sanity_check_with_regex_reference_safety),
4284 )
4285 } else {
4286 (None, None, None)
4287 };
4288
4289 let additional_borrow_checks = if signing_limits.is_some() {
4290 // Always apply additional borrow checks during signing regardless of
4291 // protocol version, to prevent accepting potentially unsafe bytecode.
4292 true
4293 } else {
4294 self.additional_borrow_checks()
4295 };
4296 let deprecate_global_storage_ops = if signing_limits.is_some() {
4297 // Always on during signing, regardless of protocol version: reject
4298 // the deprecated global storage instructions, skip the acquires
4299 // pass and check vector element borrows with the call rule.
4300 true
4301 } else {
4302 self.deprecate_global_storage_ops()
4303 };
4304
4305 // Far above the largest instantiation-loop graph in the system packages
4306 // and examples.
4307 const MAX_INSTANTIATION_LOOP_GRAPH_EDGES_AT_SIGNING: usize = 100_000;
4308
4309 // Applied with the signing limits only: execution verifies without a
4310 // meter. Both fail with PROGRAM_TOO_COMPLEX, which signing rejects.
4311 // Post-consensus validation takes them from the protocol config, see
4312 // `post_consensus_verifier_config`.
4313 let (meter_instantiation_loops, max_instantiation_loop_graph_edges) =
4314 if signing_limits.is_some() {
4315 (true, Some(MAX_INSTANTIATION_LOOP_GRAPH_EDGES_AT_SIGNING))
4316 } else {
4317 (false, None)
4318 };
4319
4320 VerifierConfig {
4321 max_loop_depth: Some(self.max_loop_depth() as usize),
4322 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
4323 max_function_parameters: Some(self.max_function_parameters() as usize),
4324 max_basic_blocks: Some(self.max_basic_blocks() as usize),
4325 max_value_stack_size: self.max_value_stack_size() as usize,
4326 max_type_nodes: Some(self.max_type_nodes() as usize),
4327 max_push_size: Some(self.max_push_size() as usize),
4328 max_dependency_depth: Some(self.max_dependency_depth() as usize),
4329 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
4330 max_function_definitions: Some(self.max_function_definitions() as usize),
4331 max_data_definitions: Some(self.max_struct_definitions() as usize),
4332 max_constant_vector_len: Some(self.max_move_vector_len()),
4333 max_back_edges_per_function,
4334 max_back_edges_per_module,
4335 max_basic_blocks_in_script: None,
4336 max_identifier_len: self.max_move_identifier_len_as_option(), /* Before protocol
4337 * version 9, there was
4338 * no limit */
4339 disallow_self_identifier: self.feature_flags.disallow_self_identifier,
4340 bytecode_version: self.move_binary_format_version(),
4341 max_variants_in_enum: self.max_move_enum_variants_as_option(),
4342 additional_borrow_checks,
4343 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
4344 .map(|limit| limit as u128),
4345 check_cyclic_dependencies: self.feature_flags.check_cyclic_dependencies,
4346 meter_instantiation_loops,
4347 max_instantiation_loop_graph_edges,
4348 deprecate_global_storage_ops,
4349 }
4350 }
4351
4352 /// The bytecode verifier config for post-consensus validation: the
4353 /// protocol's sign-time limits, with `deprecate_global_storage_ops`, the
4354 /// instantiation-loop graph edge limit and the metering of that check
4355 /// taken from the protocol config rather than set as at signing.
4356 ///
4357 /// # Panics
4358 ///
4359 /// Panics before protocol version 35, which has no
4360 /// `max_meter_ticks_regex_reference_safety`.
4361 pub fn post_consensus_verifier_config(&self) -> VerifierConfig {
4362 // Before protocol version 40, the check is metered and capped at
4363 // 100,000 edges, the values signing used then.
4364 let (meter_instantiation_loops, max_instantiation_loop_graph_edges) =
4365 if self.version < ProtocolVersion::new(40) {
4366 (true, Some(100_000))
4367 } else {
4368 (
4369 self.meter_instantiation_loops(),
4370 self.max_instantiation_loop_graph_edges_as_option()
4371 .map(|edges| edges as usize),
4372 )
4373 };
4374 VerifierConfig {
4375 deprecate_global_storage_ops: self.deprecate_global_storage_ops(),
4376 meter_instantiation_loops,
4377 max_instantiation_loop_graph_edges,
4378 ..self.verifier_config(Some(self.verifier_signing_limits()))
4379 }
4380 }
4381
4382 /// The sign-time verifier limits as protocol parameters, in the shape
4383 /// `verifier_config` takes: back edges per function, back edges per module,
4384 /// and the meter limit of the regex-based reference safety check.
4385 /// `VerifierSigningConfig::limits_for_signing` is the validator-local
4386 /// counterpart. Defined from protocol version 35, which sets
4387 /// `max_meter_ticks_regex_reference_safety`.
4388 pub fn verifier_signing_limits(&self) -> (usize, usize, usize) {
4389 (
4390 self.max_back_edges_per_function() as usize,
4391 self.max_back_edges_per_module() as usize,
4392 self.max_meter_ticks_regex_reference_safety() as usize,
4393 )
4394 }
4395
4396 /// The meter limits for verifying the packages a transaction publishes, as
4397 /// protocol parameters. `VerifierSigningConfig::meter_config_for_signing`
4398 /// is the validator-local counterpart.
4399 pub fn meter_config(&self) -> MeterConfig {
4400 MeterConfig {
4401 max_per_fun_meter_units: Some(self.max_verifier_meter_ticks_per_function() as u128),
4402 max_per_mod_meter_units: Some(self.max_meter_ticks_per_module() as u128),
4403 max_per_pkg_meter_units: Some(self.max_meter_ticks_per_package() as u128),
4404 }
4405 }
4406
4407 /// Override one or more settings in the config, for testing.
4408 /// This must be called at the beginning of the test, before
4409 /// get_for_(min|max)_version is called, since those functions cache
4410 /// their return value.
4411 pub fn apply_overrides_for_testing(
4412 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
4413 ) -> OverrideGuard {
4414 CONFIG_OVERRIDE.with(|ovr| {
4415 let mut cur = ovr.borrow_mut();
4416 assert!(cur.is_none(), "config override already present");
4417 *cur = Some(Box::new(override_fn));
4418 OverrideGuard
4419 })
4420 }
4421}
4422
4423// Setters for tests.
4424// This is only needed for feature_flags. Please suffix each setter with
4425// `_for_testing`. Non-feature_flags should already have test setters defined
4426// through macros.
4427impl ProtocolConfig {
4428 pub fn set_per_object_congestion_control_mode_for_testing(
4429 &mut self,
4430 val: PerObjectCongestionControlMode,
4431 ) {
4432 self.feature_flags.per_object_congestion_control_mode = val;
4433 }
4434
4435 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
4436 self.feature_flags.consensus_choice = val;
4437 }
4438
4439 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
4440 self.feature_flags.consensus_network = val;
4441 }
4442
4443 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
4444 self.feature_flags.passkey_auth = val
4445 }
4446
4447 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
4448 self.feature_flags
4449 .disallow_new_modules_in_deps_only_packages = val;
4450 }
4451
4452 pub fn set_check_canonical_module_version_header_for_testing(&mut self, val: bool) {
4453 self.feature_flags.check_canonical_module_version_header = val;
4454 }
4455
4456 pub fn set_deprecate_global_storage_ops_for_testing(&mut self, val: bool) {
4457 self.feature_flags.deprecate_global_storage_ops = val;
4458 }
4459
4460 pub fn set_meter_instantiation_loops_for_testing(&mut self, val: bool) {
4461 self.feature_flags.meter_instantiation_loops = val;
4462 }
4463
4464 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
4465 self.feature_flags.consensus_round_prober = val;
4466 }
4467
4468 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
4469 self.feature_flags
4470 .consensus_distributed_vote_scoring_strategy = val;
4471 }
4472
4473 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
4474 self.consensus_gc_depth = Some(val);
4475 }
4476
4477 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
4478 self.feature_flags.consensus_linearize_subdag_v2 = val;
4479 }
4480
4481 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
4482 self.feature_flags
4483 .consensus_round_prober_probe_accepted_rounds = val;
4484 }
4485
4486 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
4487 self.feature_flags.accept_passkey_in_multisig = val;
4488 }
4489
4490 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
4491 self.feature_flags.consensus_smart_ancestor_selection = val;
4492 }
4493
4494 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
4495 self.feature_flags.consensus_batched_block_sync = val;
4496 }
4497
4498 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
4499 self.feature_flags
4500 .congestion_control_min_free_execution_slot = val;
4501 }
4502
4503 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
4504 self.feature_flags
4505 .congestion_control_gas_price_feedback_mechanism = val;
4506 }
4507
4508 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
4509 self.feature_flags.select_committee_from_eligible_validators = val;
4510 }
4511
4512 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
4513 self.feature_flags.track_non_committee_eligible_validators = val;
4514 }
4515
4516 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
4517 self.feature_flags
4518 .select_committee_supporting_next_epoch_version = val;
4519 }
4520
4521 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
4522 &mut self,
4523 val: bool,
4524 ) {
4525 self.feature_flags
4526 .consensus_median_timestamp_with_checkpoint_enforcement = val;
4527 }
4528
4529 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
4530 &mut self,
4531 val: bool,
4532 ) {
4533 self.feature_flags
4534 .consensus_commit_transactions_only_for_traversed_headers = val;
4535 }
4536
4537 pub fn set_consensus_commit_transactions_once_traversed_for_testing(&mut self, val: bool) {
4538 self.feature_flags
4539 .consensus_commit_transactions_once_traversed = val;
4540 }
4541
4542 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
4543 &mut self,
4544 val: bool,
4545 ) {
4546 self.feature_flags
4547 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
4548 }
4549
4550 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
4551 &mut self,
4552 val: bool,
4553 ) {
4554 self.feature_flags
4555 .separate_gas_price_feedback_mechanism_for_randomness = val;
4556 }
4557
4558 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
4559 self.feature_flags.metadata_in_module_bytes = val;
4560 }
4561
4562 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
4563 self.feature_flags.publish_package_metadata = val;
4564 }
4565
4566 /// Turning Move authentication off also turns off reporting Move
4567 /// authentication errors and validator attestation, which require it.
4568 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
4569 self.feature_flags.enable_move_authentication = val;
4570 if !val {
4571 self.set_report_move_authentication_error_for_testing(false);
4572 self.set_enable_validator_attestation_for_testing(false);
4573 }
4574 }
4575
4576 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
4577 self.feature_flags.enable_move_authentication_for_sponsor = val;
4578 }
4579
4580 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
4581 self.feature_flags.consensus_fast_commit_sync = val;
4582 }
4583
4584 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
4585 self.feature_flags.consensus_block_restrictions = val;
4586 }
4587
4588 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
4589 self.feature_flags
4590 .pre_consensus_sponsor_only_move_authentication = val;
4591 }
4592
4593 pub fn set_consensus_starfish_speed_for_testing(&mut self, val: bool) {
4594 self.feature_flags.consensus_starfish_speed = val;
4595 }
4596
4597 pub fn set_always_advance_dkg_to_resolution_for_testing(&mut self, val: bool) {
4598 self.feature_flags.always_advance_dkg_to_resolution = val;
4599 }
4600
4601 pub fn set_enable_transaction_dependencies_for_testing(&mut self, val: bool) {
4602 self.feature_flags.enable_transaction_dependencies = val;
4603 }
4604
4605 /// Turning the flow on also turns on the flags it requires, turns off
4606 /// `pre_consensus_sponsor_only_move_authentication`, which it excludes, and
4607 /// fills in the settings it requires when unset, whatever the version.
4608 /// Turning the flow off also turns validator attestation off, since
4609 /// attestation cannot run without the flow.
4610 pub fn set_enable_pcool_flow_for_testing(&mut self, val: bool) {
4611 self.feature_flags.enable_pcool_flow = val;
4612 if val {
4613 self.feature_flags
4614 .pre_consensus_sponsor_only_move_authentication = false;
4615 // Post-consensus validation reads this budget; versions before 35
4616 // leave it unset.
4617 self.max_meter_ticks_regex_reference_safety
4618 .get_or_insert(2_200_000);
4619 self.feature_flags.consensus_dedup_only_recorded_messages = true;
4620 self.pcool_deterministic_validation_horizon_distance
4621 .get_or_insert(4);
4622 self.deny_rule_update_max_entries_per_tx.get_or_insert(1000);
4623 } else {
4624 self.set_enable_validator_attestation_for_testing(false);
4625 }
4626 }
4627
4628 pub fn set_reject_immutable_account_objects_for_testing(&mut self, val: bool) {
4629 self.feature_flags.reject_immutable_account_objects = val;
4630 }
4631
4632 pub fn set_reject_immutable_account_creation_for_testing(&mut self, val: bool) {
4633 self.feature_flags.reject_immutable_account_creation = val;
4634 }
4635
4636 pub fn set_validate_input_object_versions_for_testing(&mut self, val: bool) {
4637 self.feature_flags.validate_input_object_versions = val;
4638 }
4639
4640 pub fn set_disallow_randomness_in_move_authenticator_for_testing(&mut self, val: bool) {
4641 self.feature_flags.disallow_randomness_in_move_authenticator = val;
4642 }
4643
4644 pub fn set_move_authenticator_type_arg_packages_as_inputs_for_testing(&mut self, val: bool) {
4645 self.feature_flags
4646 .move_authenticator_type_arg_packages_as_inputs = val;
4647 }
4648
4649 pub fn set_disallow_self_identifier_in_transactions_for_testing(&mut self, val: bool) {
4650 self.feature_flags.disallow_self_identifier_in_transactions = val;
4651 }
4652
4653 pub fn set_commits_per_schedule_for_testing(&mut self, val: u32) {
4654 self.consensus_commits_per_schedule = Some(val);
4655 }
4656
4657 pub fn set_deny_authenticator_packages_for_testing(&mut self, val: bool) {
4658 self.feature_flags.deny_authenticator_packages = val;
4659 }
4660
4661 /// Keeps the config consistent with the getters that assert on this flag:
4662 /// enabling fills in `scorer_version` when unset, disabling also switches
4663 /// off `adjust_rewards_by_score` and
4664 /// `pass_calculated_validator_scores_to_advance_epoch`.
4665 pub fn set_calculate_validator_scores_for_testing(&mut self, val: bool) {
4666 self.feature_flags.calculate_validator_scores = val;
4667 if val {
4668 self.scorer_version.get_or_insert(1);
4669 } else {
4670 self.feature_flags.adjust_rewards_by_score = false;
4671 self.feature_flags
4672 .pass_calculated_validator_scores_to_advance_epoch = false;
4673 }
4674 }
4675
4676 pub fn set_pass_calculated_validator_scores_to_advance_epoch_for_testing(&mut self, val: bool) {
4677 self.feature_flags
4678 .pass_calculated_validator_scores_to_advance_epoch = val;
4679 }
4680
4681 pub fn set_package_metadata_with_dynamic_module_metadata_for_testing(&mut self, val: bool) {
4682 self.feature_flags
4683 .package_metadata_with_dynamic_module_metadata = val;
4684 }
4685
4686 pub fn set_report_move_authentication_error_for_testing(&mut self, val: bool) {
4687 self.feature_flags.report_move_authentication_error = val;
4688 }
4689
4690 pub fn set_leader_schedule_window_size_for_testing(&mut self, val: u32) {
4691 self.consensus_leader_schedule_window_size = Some(val);
4692 }
4693
4694 pub fn set_consensus_enable_sliding_window_leader_schedule_for_testing(&mut self, val: bool) {
4695 self.feature_flags
4696 .consensus_enable_sliding_window_leader_schedule = val;
4697 }
4698
4699 pub fn set_consensus_enable_absolute_score_leader_schedule_for_testing(&mut self, val: bool) {
4700 self.feature_flags
4701 .consensus_enable_absolute_score_leader_schedule = val;
4702 }
4703
4704 pub fn set_allow_dkg_completion_after_timeout_for_testing(&mut self, val: bool) {
4705 self.feature_flags.allow_dkg_completion_after_timeout = val;
4706 }
4707
4708 /// Turning the flag off also turns off `enable_pcool_flow`, which requires
4709 /// it.
4710 pub fn set_consensus_dedup_only_recorded_messages_for_testing(&mut self, val: bool) {
4711 self.feature_flags.consensus_dedup_only_recorded_messages = val;
4712 if !val {
4713 self.set_enable_pcool_flow_for_testing(false);
4714 }
4715 }
4716
4717 /// Turning attestation off also unsets the parameters that require it.
4718 pub fn set_enable_validator_attestation_for_testing(&mut self, val: bool) {
4719 self.feature_flags.enable_validator_attestation = val;
4720 if !val {
4721 self.unset_attestation_parameters();
4722 }
4723 }
4724
4725 pub fn set_enable_builtin_move_authenticators_for_testing(&mut self, val: bool) {
4726 self.feature_flags.enable_builtin_move_authenticators = val;
4727 }
4728
4729 pub fn set_enable_claim_account_transaction_for_testing(&mut self, val: bool) {
4730 self.feature_flags.enable_claim_account_transaction = val;
4731 }
4732
4733 pub fn set_enable_smart_accounts_for_testing(&mut self, val: bool) {
4734 self.feature_flags.enable_smart_accounts = val;
4735 }
4736}
4737
4738type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
4739
4740thread_local! {
4741 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
4742}
4743
4744#[must_use]
4745pub struct OverrideGuard;
4746
4747impl Drop for OverrideGuard {
4748 fn drop(&mut self) {
4749 info!("restoring override fn");
4750 CONFIG_OVERRIDE.with(|ovr| {
4751 *ovr.borrow_mut() = None;
4752 });
4753 }
4754}
4755
4756/// Defines which limit got crossed.
4757/// The value which crossed the limit and value of the limit crossed are
4758/// embedded
4759#[derive(PartialEq, Eq)]
4760pub enum LimitThresholdCrossed {
4761 None,
4762 Soft(u128, u128),
4763 Hard(u128, u128),
4764}
4765
4766/// Convenience function for comparing limit ranges
4767/// V::MAX must be at >= U::MAX and T::MAX
4768pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
4769 x: T,
4770 soft_limit: U,
4771 hard_limit: V,
4772) -> LimitThresholdCrossed {
4773 let x: V = x.into();
4774 let soft_limit: V = soft_limit.into();
4775
4776 debug_assert!(soft_limit <= hard_limit);
4777
4778 // It is important to preserve this comparison order because if soft_limit ==
4779 // hard_limit we want LimitThresholdCrossed::Hard
4780 if x >= hard_limit {
4781 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
4782 } else if x < soft_limit {
4783 LimitThresholdCrossed::None
4784 } else {
4785 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
4786 }
4787}
4788
4789#[macro_export]
4790macro_rules! check_limit {
4791 ($x:expr, $hard:expr) => {
4792 check_limit!($x, $hard, $hard)
4793 };
4794 ($x:expr, $soft:expr, $hard:expr) => {
4795 check_limit_in_range($x as u64, $soft, $hard)
4796 };
4797}
4798
4799/// Used to check which limits were crossed if the TX is metered (not system tx)
4800/// Args are: is_metered, value_to_check, metered_limit, unmetered_limit
4801/// metered_limit is always less than or equal to unmetered_hard_limit
4802#[macro_export]
4803macro_rules! check_limit_by_meter {
4804 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
4805 // If this is metered, we use the metered_limit limit as the upper bound
4806 let (h, metered_str) = if $is_metered {
4807 ($metered_limit, "metered")
4808 } else {
4809 // Unmetered gets more headroom
4810 ($unmetered_hard_limit, "unmetered")
4811 };
4812 use iota_protocol_config::check_limit_in_range;
4813 let result = check_limit_in_range($x as u64, $metered_limit, h);
4814 match result {
4815 LimitThresholdCrossed::None => {}
4816 LimitThresholdCrossed::Soft(_, _) => {
4817 $metric.with_label_values(&[metered_str, "soft"]).inc();
4818 }
4819 LimitThresholdCrossed::Hard(_, _) => {
4820 $metric.with_label_values(&[metered_str, "hard"]).inc();
4821 }
4822 };
4823 result
4824 }};
4825}
4826
4827#[cfg(all(test, not(msim)))]
4828mod test {
4829 use insta::assert_yaml_snapshot;
4830
4831 use super::*;
4832
4833 #[test]
4834 fn snapshot_tests() {
4835 println!("\n============================================================================");
4836 println!("! !");
4837 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
4838 println!("! !");
4839 println!("============================================================================\n");
4840 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
4841 // make Chain::Unknown snapshots compatible with pre-chain-id snapshots so that
4842 // we don't break the release-time compatibility tests. Once Chain
4843 // Id configs have been released everywhere, we can remove this and
4844 // only test Mainnet and Testnet
4845 let chain_str = match chain_id {
4846 Chain::Unknown => "".to_string(),
4847 _ => format!("{chain_id:?}_"),
4848 };
4849 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
4850 let cur = ProtocolVersion::new(i);
4851 assert_yaml_snapshot!(
4852 format!("{}version_{}", chain_str, cur.as_u64()),
4853 ProtocolConfig::get_for_version(cur, *chain_id)
4854 );
4855 }
4856 }
4857 }
4858
4859 #[test]
4860 fn commit_transactions_once_traversed_activation() {
4861 for chain in [Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
4862 for version in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
4863 let config = ProtocolConfig::get_for_version(ProtocolVersion::new(version), chain);
4864 assert_eq!(
4865 config.consensus_commit_transactions_once_traversed(),
4866 version >= 41 && chain != Chain::Mainnet,
4867 "unexpected activation for {chain:?} at version {version}"
4868 );
4869 }
4870 }
4871 }
4872
4873 #[test]
4874 fn test_getters() {
4875 let prot: ProtocolConfig =
4876 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4877 assert_eq!(
4878 prot.max_arguments(),
4879 prot.max_arguments_as_option().unwrap()
4880 );
4881 }
4882
4883 #[test]
4884 fn only_signing_bounds_the_instantiation_loop_checker() {
4885 let prot = ProtocolConfig::get_for_max_version_UNSAFE();
4886
4887 let signing = prot.verifier_config(Some((0, 0, 0)));
4888 assert!(signing.max_instantiation_loop_graph_edges.is_some());
4889 assert!(signing.meter_instantiation_loops);
4890
4891 let execution = prot.verifier_config(None);
4892 assert_eq!(execution.max_instantiation_loop_graph_edges, None);
4893 assert!(!execution.meter_instantiation_loops);
4894 }
4895
4896 #[test]
4897 fn post_consensus_verifier_config_follows_deprecate_global_storage_ops() {
4898 let mut prot = ProtocolConfig::get_for_max_version_UNSAFE();
4899 prot.set_deprecate_global_storage_ops_for_testing(false);
4900
4901 assert!(
4902 prot.verifier_config(Some((0, 0, 0)))
4903 .deprecate_global_storage_ops
4904 );
4905 let post_consensus = prot.post_consensus_verifier_config();
4906 assert!(!post_consensus.deprecate_global_storage_ops);
4907 assert_eq!(
4908 post_consensus.max_back_edges_per_function,
4909 Some(prot.max_back_edges_per_function() as usize)
4910 );
4911
4912 prot.set_deprecate_global_storage_ops_for_testing(true);
4913 assert!(
4914 prot.post_consensus_verifier_config()
4915 .deprecate_global_storage_ops
4916 );
4917 }
4918
4919 #[test]
4920 fn post_consensus_verifier_config_bounds_the_instantiation_loop_checker() {
4921 let before = ProtocolConfig::get_for_version(ProtocolVersion::new(39), Chain::Unknown);
4922 let config = before.post_consensus_verifier_config();
4923 assert!(config.meter_instantiation_loops);
4924 assert_eq!(config.max_instantiation_loop_graph_edges, Some(100_000));
4925
4926 let mut prot = ProtocolConfig::get_for_version(ProtocolVersion::new(40), Chain::Unknown);
4927 prot.set_max_instantiation_loop_graph_edges_for_testing(7);
4928 prot.set_meter_instantiation_loops_for_testing(false);
4929 let config = prot.post_consensus_verifier_config();
4930 assert!(!config.meter_instantiation_loops);
4931 assert_eq!(config.max_instantiation_loop_graph_edges, Some(7));
4932
4933 // The node's signing config keeps its own values.
4934 let signing = prot.verifier_config(Some((0, 0, 0)));
4935 assert!(signing.meter_instantiation_loops);
4936 assert_eq!(signing.max_instantiation_loop_graph_edges, Some(100_000));
4937 }
4938
4939 #[test]
4940 fn signing_and_post_consensus_instantiation_loop_limits_match() {
4941 let prot = ProtocolConfig::get_for_max_version_UNSAFE();
4942 let signing = prot.verifier_config(Some(prot.verifier_signing_limits()));
4943 let post_consensus = prot.post_consensus_verifier_config();
4944
4945 assert_eq!(
4946 signing.meter_instantiation_loops,
4947 post_consensus.meter_instantiation_loops
4948 );
4949 assert_eq!(
4950 signing.max_instantiation_loop_graph_edges,
4951 post_consensus.max_instantiation_loop_graph_edges
4952 );
4953 }
4954
4955 #[test]
4956 fn test_setters() {
4957 let mut prot: ProtocolConfig =
4958 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4959 prot.set_max_arguments_for_testing(123);
4960 assert_eq!(prot.max_arguments(), 123);
4961
4962 prot.set_max_arguments_from_str_for_testing("321".to_string());
4963 assert_eq!(prot.max_arguments(), 321);
4964
4965 prot.disable_max_arguments_for_testing();
4966 assert_eq!(prot.max_arguments_as_option(), None);
4967
4968 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
4969 assert_eq!(prot.max_arguments(), 456);
4970 }
4971
4972 #[test]
4973 fn reject_immutable_account_creation_implies_rejecting_the_objects() {
4974 for chain in [Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
4975 for version in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
4976 // The getter asserts the dependency on
4977 // `reject_immutable_account_objects`.
4978 ProtocolConfig::get_for_version(ProtocolVersion::new(version), chain)
4979 .reject_immutable_account_creation();
4980 }
4981 }
4982 }
4983
4984 #[test]
4985 #[should_panic(expected = "unsupported version")]
4986 fn max_version_test() {
4987 // When this does not panic, version higher than MAX_PROTOCOL_VERSION exists.
4988 // To fix, bump MAX_PROTOCOL_VERSION or disable this check for the version.
4989 let _ = ProtocolConfig::get_for_version_impl(
4990 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
4991 Chain::Unknown,
4992 );
4993 }
4994
4995 #[test]
4996 fn lookup_by_string_test() {
4997 let prot: ProtocolConfig =
4998 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
4999 // Does not exist
5000 assert!(prot.lookup_attr("some random string".to_string()).is_none());
5001
5002 assert!(
5003 prot.lookup_attr("max_arguments".to_string())
5004 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
5005 );
5006
5007 // We didnt have this in version 1 on Mainnet
5008 assert!(
5009 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
5010 .is_none()
5011 );
5012 assert!(
5013 prot.attr_map()
5014 .get("poseidon_bn254_cost_base")
5015 .unwrap()
5016 .is_none()
5017 );
5018
5019 // But we did in version 1 on Devnet
5020 let prot: ProtocolConfig =
5021 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
5022
5023 assert!(
5024 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
5025 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
5026 );
5027 assert!(
5028 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
5029 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
5030 );
5031
5032 // Check feature flags
5033 let prot: ProtocolConfig =
5034 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
5035 // Does not exist
5036 assert!(
5037 prot.feature_flags
5038 .lookup_attr("some random string".to_owned())
5039 .is_none()
5040 );
5041 assert!(
5042 !prot
5043 .feature_flags
5044 .attr_map()
5045 .contains_key("some random string")
5046 );
5047
5048 // Was false in v1 on Mainnet
5049 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
5050 assert!(
5051 prot.feature_flags
5052 .attr_map()
5053 .get("enable_poseidon")
5054 .unwrap()
5055 == &false
5056 );
5057 let prot: ProtocolConfig =
5058 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
5059 // Was true from v1 and up on Devnet
5060 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
5061 assert!(
5062 prot.feature_flags
5063 .attr_map()
5064 .get("enable_poseidon")
5065 .unwrap()
5066 == &true
5067 );
5068 }
5069
5070 /// A chunk limit above the executability ceiling would fail execution on
5071 /// every validator at once, so the configuration is rejected at startup
5072 /// rather than at the flip.
5073 #[test]
5074 #[should_panic(expected = "deny_rule_update_max_entries_per_tx must be positive")]
5075 fn deny_rule_chunk_limit_above_the_ceiling_is_rejected() {
5076 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5077 config.set_enable_pcool_flow_for_testing(true);
5078 config.set_deny_rule_update_max_entries_per_tx_for_testing(2048 + 1);
5079 config
5080 });
5081 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5082 }
5083
5084 /// Execution and the attestor's dry run read `max_auth_gas` under
5085 /// attestation, so a configuration without it is rejected at startup
5086 /// rather than stopping the validator at the first transaction.
5087 #[test]
5088 #[should_panic(expected = "enable_validator_attestation requires max_auth_gas to be set")]
5089 fn attestation_without_max_auth_gas_is_rejected() {
5090 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5091 config.disable_max_auth_gas_for_testing();
5092 config
5093 });
5094 let config = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5095 assert!(
5096 config.enable_validator_attestation(),
5097 "the latest devnet configuration should run attestation"
5098 );
5099 }
5100
5101 /// A zero chunk limit would make every delta unsplittable; the pure
5102 /// chunking function clamps it, but the configuration is still invalid.
5103 #[test]
5104 #[should_panic(expected = "deny_rule_update_max_entries_per_tx must be positive")]
5105 fn deny_rule_chunk_limit_of_zero_is_rejected() {
5106 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5107 config.set_enable_pcool_flow_for_testing(true);
5108 config.set_deny_rule_update_max_entries_per_tx_for_testing(0);
5109 config
5110 });
5111 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5112 }
5113
5114 /// The value the flip is expected to ship stays inside the limits.
5115 #[test]
5116 fn deny_rule_chunk_limit_within_system_tx_object_id_limit_is_accepted() {
5117 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5118 config.set_enable_pcool_flow_for_testing(true);
5119 config.set_deny_rule_update_max_entries_per_tx_for_testing(1000);
5120 config
5121 });
5122 let config = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5123 assert_eq!(config.deny_rule_update_max_entries_per_tx(), 1000);
5124 }
5125
5126 /// From version 39 the P-COOL flow requires the deny rule settings, which
5127 /// mirror the governed deny rules into the on-chain object.
5128 #[test]
5129 #[should_panic(expected = "enable_pcool_flow requires deny_rule_update_max_entries_per_tx")]
5130 fn pcool_flow_without_the_deny_rule_settings_is_rejected() {
5131 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5132 config.set_enable_pcool_flow_for_testing(true);
5133 config.disable_deny_rule_update_max_entries_per_tx_for_testing();
5134 config
5135 });
5136 let _ = ProtocolConfig::get_for_version(ProtocolVersion::new(39), Chain::Unknown);
5137 }
5138
5139 /// Devnet runs the P-COOL flow from version 32, before the settings it
5140 /// requires exist. Those versions are not checked for them.
5141 #[test]
5142 fn devnet_versions_before_39_run_the_pcool_flow_without_its_settings() {
5143 for version in 32..39 {
5144 let config =
5145 ProtocolConfig::get_for_version(ProtocolVersion::new(version), Chain::Unknown);
5146 assert!(config.enable_pcool_flow(), "version {version}");
5147 assert_eq!(
5148 config.deny_rule_update_max_entries_per_tx_as_option(),
5149 None,
5150 "version {version}"
5151 );
5152 }
5153 }
5154
5155 /// Devnet sets the horizon distance from version 39 on; Mainnet, Testnet
5156 /// and earlier versions leave it unset. An override still wins.
5157 #[test]
5158 fn horizon_distance_is_set_on_devnet_from_version_39() {
5159 let config = ProtocolConfig::get_for_version(ProtocolVersion::new(39), Chain::Unknown);
5160 assert_eq!(config.pcool_deterministic_validation_horizon_distance(), 4);
5161 for (version, chain) in [
5162 (38, Chain::Unknown),
5163 (39, Chain::Mainnet),
5164 (39, Chain::Testnet),
5165 ] {
5166 let config = ProtocolConfig::get_for_version(ProtocolVersion::new(version), chain);
5167 assert_eq!(
5168 config.pcool_deterministic_validation_horizon_distance_as_option(),
5169 None,
5170 "version {version} on {chain:?}"
5171 );
5172 }
5173
5174 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5175 config.set_pcool_deterministic_validation_horizon_distance_for_testing(5);
5176 config
5177 });
5178 let config = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5179 assert_eq!(config.pcool_deterministic_validation_horizon_distance(), 5);
5180 }
5181
5182 /// The P-COOL flow has no horizon distance to fall back on.
5183 #[test]
5184 #[should_panic(expected = "pcool_deterministic_validation_horizon_distance")]
5185 fn pcool_flow_without_a_horizon_distance_is_rejected() {
5186 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5187 config.set_enable_pcool_flow_for_testing(true);
5188 config.disable_pcool_deterministic_validation_horizon_distance_for_testing();
5189 config
5190 });
5191 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5192 }
5193
5194 /// With a horizon distance of 0, the consensus handler processing commit C
5195 /// would wait for C itself to be fully executed, which cannot happen before
5196 /// the handler finishes processing C, so the network would halt. The
5197 /// configuration is rejected at startup.
5198 #[test]
5199 #[should_panic(expected = "pcool_deterministic_validation_horizon_distance")]
5200 fn horizon_distance_of_zero_with_the_pcool_flow_is_rejected() {
5201 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5202 config.set_enable_pcool_flow_for_testing(true);
5203 config.set_pcool_deterministic_validation_horizon_distance_for_testing(0);
5204 config
5205 });
5206 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5207 }
5208
5209 /// Every version from 39 and chain that turns the P-COOL flow on sets a
5210 /// positive horizon distance and the verifier limits post-consensus
5211 /// validation meters published packages with.
5212 #[test]
5213 fn every_version_with_the_pcool_flow_sets_its_requirements() {
5214 for chain in [Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
5215 for version in 39..=MAX_PROTOCOL_VERSION {
5216 let config = ProtocolConfig::get_for_version(ProtocolVersion::new(version), chain);
5217 if config.enable_pcool_flow() {
5218 assert!(
5219 config
5220 .pcool_deterministic_validation_horizon_distance_as_option()
5221 .is_some_and(|distance| distance > 0),
5222 "version {version} on {chain:?} runs the P-COOL flow without a positive \
5223 horizon distance"
5224 );
5225 assert!(
5226 config
5227 .max_meter_ticks_regex_reference_safety_as_option()
5228 .is_some(),
5229 "version {version} on {chain:?} runs the P-COOL flow without the \
5230 regex reference safety budget"
5231 );
5232 }
5233 }
5234 }
5235 }
5236
5237 /// The penalty's value is calibrated for refuted attestations of at most
5238 /// 2 × `gas_rounding_step` units, execution's run plus the judge's re-run.
5239 /// That holds while `max_auth_gas` buys no more than one step per run at a
5240 /// gas price of 1,000.
5241 #[test]
5242 fn refuted_attestation_penalty_requires_max_auth_gas_within_one_rounding_step() {
5243 const GAS_PRICE: u64 = 1_000;
5244 for chain in [Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
5245 for version in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
5246 let config = ProtocolConfig::get_for_version(ProtocolVersion::new(version), chain);
5247 if config
5248 .attestation_max_refuted_units_squared_as_option()
5249 .is_some()
5250 {
5251 assert!(
5252 config.max_auth_gas() <= config.gas_rounding_step() * GAS_PRICE,
5253 "version {version} on {chain:?} penalizes refuted attestations while \
5254 max_auth_gas buys more than one gas_rounding_step"
5255 );
5256 }
5257 }
5258 }
5259 }
5260
5261 /// Turning the P-COOL flow on for a test also turns on what it requires,
5262 /// as a version that turns it on must, whatever the version the test
5263 /// starts from.
5264 #[test]
5265 fn enabling_the_pcool_flow_for_testing_enables_its_requirements() {
5266 let mut config = ProtocolConfig::get_for_version(
5267 ProtocolVersion::new(MIN_PROTOCOL_VERSION),
5268 Chain::Unknown,
5269 );
5270 assert!(
5271 config
5272 .max_meter_ticks_regex_reference_safety_as_option()
5273 .is_none()
5274 );
5275 config.set_enable_pcool_flow_for_testing(true);
5276 assert!(config.enable_pcool_flow());
5277 assert_eq!(config.max_meter_ticks_regex_reference_safety(), 2_200_000);
5278 assert!(config.consensus_dedup_only_recorded_messages());
5279 assert_eq!(config.pcool_deterministic_validation_horizon_distance(), 4);
5280 assert_eq!(config.deny_rule_update_max_entries_per_tx(), 1000);
5281 }
5282
5283 /// An override that returns an older version's config for every version
5284 /// asked for, as `TestAuthorityBuilder` installs, is checked against the
5285 /// version of that config, which runs the P-COOL flow on Devnet before the
5286 /// settings it requires exist.
5287 #[test]
5288 fn an_override_returning_an_older_config_is_checked_against_its_version() {
5289 let older = ProtocolConfig::get_for_version(ProtocolVersion::new(37), Chain::Unknown);
5290 assert!(older.enable_pcool_flow());
5291 assert!(!older.consensus_dedup_only_recorded_messages());
5292 let _guard = ProtocolConfig::apply_overrides_for_testing(move |_, _| older.clone());
5293 let config = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5294 assert_eq!(config.version, ProtocolVersion::new(37));
5295 }
5296
5297 /// Without `consensus_dedup_only_recorded_messages` the consensus handler
5298 /// could skip a message as a duplicate of one only some validators saw
5299 /// dropped, so the combination is rejected at startup.
5300 #[test]
5301 #[should_panic(expected = "enable_pcool_flow requires consensus_dedup_only_recorded_messages")]
5302 fn pcool_flow_without_dedup_of_recorded_messages_is_rejected() {
5303 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5304 config.feature_flags.consensus_dedup_only_recorded_messages = false;
5305 config
5306 });
5307 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5308 }
5309
5310 /// With sponsor-only pre-consensus authentication, a sponsor alone could get
5311 /// a transaction sequenced that locks a Move account's owned objects, so
5312 /// the P-COOL flow excludes it.
5313 #[test]
5314 #[should_panic(
5315 expected = "enable_pcool_flow excludes pre_consensus_sponsor_only_move_authentication"
5316 )]
5317 fn pcool_flow_with_sponsor_only_pre_consensus_authentication_is_rejected() {
5318 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5319 config
5320 .feature_flags
5321 .pre_consensus_sponsor_only_move_authentication = true;
5322 config
5323 });
5324 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5325 }
5326
5327 /// Turning the P-COOL flow on for testing turns sponsor-only pre-consensus
5328 /// authentication off, which Testnet's version 34 has on.
5329 #[test]
5330 fn turning_the_pcool_flow_on_turns_sponsor_only_authentication_off() {
5331 let mut config = ProtocolConfig::get_for_version(ProtocolVersion::new(34), Chain::Testnet);
5332 assert!(config.pre_consensus_sponsor_only_move_authentication());
5333 config.set_enable_pcool_flow_for_testing(true);
5334 assert!(!config.pre_consensus_sponsor_only_move_authentication());
5335 }
5336
5337 /// A test that turns a requirement off keeps a valid config instead of
5338 /// tripping the startup check.
5339 #[test]
5340 fn disabling_a_requirement_for_testing_disables_the_pcool_flow() {
5341 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5342 config.set_consensus_dedup_only_recorded_messages_for_testing(false);
5343 config
5344 });
5345 let config = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5346 assert!(!config.enable_pcool_flow());
5347 }
5348
5349 #[test]
5350 fn limit_range_fn_test() {
5351 let low = 100u32;
5352 let high = 10000u64;
5353
5354 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
5355 assert!(matches!(
5356 check_limit!(255u16, low, high),
5357 LimitThresholdCrossed::Soft(255u128, 100)
5358 ));
5359 // This wont compile because lossy
5360 // assert!(check_limit!(100000000u128, low, high) ==
5361 // LimitThresholdCrossed::None); This wont compile because lossy
5362 // assert!(check_limit!(100000000usize, low, high) ==
5363 // LimitThresholdCrossed::None);
5364
5365 assert!(matches!(
5366 check_limit!(2550000u64, low, high),
5367 LimitThresholdCrossed::Hard(2550000, 10000)
5368 ));
5369
5370 assert!(matches!(
5371 check_limit!(2550000u64, high, high),
5372 LimitThresholdCrossed::Hard(2550000, 10000)
5373 ));
5374
5375 assert!(matches!(
5376 check_limit!(1u8, high),
5377 LimitThresholdCrossed::None
5378 ));
5379
5380 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
5381
5382 assert!(matches!(
5383 check_limit!(2550000u64, high),
5384 LimitThresholdCrossed::Hard(2550000, 10000)
5385 ));
5386 }
5387}