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. Consulted only
1898 /// when `consensus_enable_sliding_window_leader_schedule` is set.
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 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 }
2381
2382 pub fn consensus_enable_sliding_window_leader_schedule(&self) -> bool {
2383 let res = self
2384 .feature_flags
2385 .consensus_enable_sliding_window_leader_schedule;
2386 assert!(
2387 !res || self.leader_schedule_window_size() >= self.commits_per_schedule(),
2388 "consensus_enable_sliding_window_leader_schedule requires window_size >= commits_per_schedule"
2389 );
2390 res
2391 }
2392
2393 pub fn consensus_enable_absolute_score_leader_schedule(&self) -> bool {
2394 self.feature_flags
2395 .consensus_enable_absolute_score_leader_schedule
2396 }
2397
2398 pub fn max_ptb_value_size_v2(&self) -> bool {
2399 self.feature_flags.max_ptb_value_size_v2
2400 }
2401
2402 pub fn deny_authenticator_packages(&self) -> bool {
2403 self.feature_flags.deny_authenticator_packages
2404 }
2405
2406 pub fn package_metadata_with_dynamic_module_metadata(&self) -> bool {
2407 let res = self
2408 .feature_flags
2409 .package_metadata_with_dynamic_module_metadata;
2410 assert!(
2411 !res || self.publish_package_metadata(),
2412 "package_metadata_with_dynamic_module_metadata requires publish_package_metadata to be enabled"
2413 );
2414 res
2415 }
2416
2417 pub fn report_move_authentication_error(&self) -> bool {
2418 let report_move_authentication_error = self.feature_flags.report_move_authentication_error;
2419 assert!(
2420 !report_move_authentication_error || self.enable_move_authentication(),
2421 "report_move_authentication_error requires enable_move_authentication to be set"
2422 );
2423 report_move_authentication_error
2424 }
2425
2426 /// Named to avoid colliding with the derive-generated
2427 /// `max_concurrent_execution_workers[_as_option]()`, which bypass the
2428 /// checks below — always read the parameter through this getter.
2429 pub fn concurrent_execution_workers(&self) -> Option<u16> {
2430 let res = self.max_concurrent_execution_workers;
2431 assert!(
2432 res.is_none() || self.enable_pcool_flow(),
2433 "max_concurrent_execution_workers requires enable_pcool_flow to be enabled"
2434 );
2435 assert!(
2436 res.is_none()
2437 || self
2438 .max_accumulated_txn_cost_per_object_in_mysticeti_commit
2439 .is_some(),
2440 "max_concurrent_execution_workers requires per-object congestion control \
2441 (max_accumulated_txn_cost_per_object_in_mysticeti_commit) to be enabled"
2442 );
2443 assert!(
2444 res.is_none() || self.congestion_control_gas_price_feedback_mechanism(),
2445 "max_concurrent_execution_workers requires the gas price feedback mechanism \
2446 (congestion_control_gas_price_feedback_mechanism), which carries the suggested \
2447 gas price of an execution-worker congestion cancellation"
2448 );
2449 assert!(
2450 res.is_none() || !self.separate_gas_price_feedback_mechanism_for_randomness(),
2451 "max_concurrent_execution_workers implies a single congestion tracker and suggested \
2452 gas price calculator for all transactions, which is incompatible with \
2453 separate_gas_price_feedback_mechanism_for_randomness"
2454 );
2455 assert!(
2456 res != Some(0),
2457 "max_concurrent_execution_workers must be positive when set"
2458 );
2459 res
2460 }
2461
2462 pub fn allow_unbounded_system_objects(&self) -> bool {
2463 self.feature_flags.allow_unbounded_system_objects
2464 }
2465
2466 pub fn reject_immutable_account_objects(&self) -> bool {
2467 let reject_immutable_account_objects = self.feature_flags.reject_immutable_account_objects;
2468 assert!(
2469 !reject_immutable_account_objects || self.enable_move_authentication(),
2470 "reject_immutable_account_objects requires enable_move_authentication to be set"
2471 );
2472 reject_immutable_account_objects
2473 }
2474
2475 pub fn reject_immutable_account_creation(&self) -> bool {
2476 let reject_immutable_account_creation =
2477 self.feature_flags.reject_immutable_account_creation;
2478 assert!(
2479 !reject_immutable_account_creation || self.reject_immutable_account_objects(),
2480 "reject_immutable_account_creation requires reject_immutable_account_objects to be set"
2481 );
2482 reject_immutable_account_creation
2483 }
2484
2485 pub fn validate_input_object_versions(&self) -> bool {
2486 self.feature_flags.validate_input_object_versions
2487 }
2488
2489 pub fn check_canonical_module_version_header(&self) -> bool {
2490 self.feature_flags.check_canonical_module_version_header
2491 }
2492
2493 pub fn disallow_randomness_in_move_authenticator(&self) -> bool {
2494 self.feature_flags.disallow_randomness_in_move_authenticator
2495 }
2496
2497 pub fn check_cyclic_dependencies(&self) -> bool {
2498 self.feature_flags.check_cyclic_dependencies
2499 }
2500
2501 pub fn validate_ptb_argument_indices(&self) -> bool {
2502 self.feature_flags.validate_ptb_argument_indices
2503 }
2504
2505 pub fn allow_dkg_completion_after_timeout(&self) -> bool {
2506 self.feature_flags.allow_dkg_completion_after_timeout
2507 }
2508
2509 pub fn disallow_self_identifier_in_transactions(&self) -> bool {
2510 self.feature_flags.disallow_self_identifier_in_transactions
2511 }
2512
2513 pub fn consensus_dedup_only_recorded_messages(&self) -> bool {
2514 self.feature_flags.consensus_dedup_only_recorded_messages
2515 }
2516
2517 pub fn reject_partially_signed_mixed_ed25519_multisig(&self) -> bool {
2518 self.feature_flags
2519 .reject_partially_signed_mixed_ed25519_multisig
2520 }
2521
2522 pub fn limit_groth16_pvk_inputs(&self) -> bool {
2523 self.feature_flags.limit_groth16_pvk_inputs
2524 }
2525
2526 pub fn check_groth16_pvk_length(&self) -> bool {
2527 self.feature_flags.check_groth16_pvk_length
2528 }
2529
2530 pub fn deprecate_global_storage_ops(&self) -> bool {
2531 self.feature_flags.deprecate_global_storage_ops
2532 }
2533
2534 pub fn meter_instantiation_loops(&self) -> bool {
2535 self.feature_flags.meter_instantiation_loops
2536 }
2537
2538 pub fn move_authenticator_type_arg_packages_as_inputs(&self) -> bool {
2539 self.feature_flags
2540 .move_authenticator_type_arg_packages_as_inputs
2541 }
2542
2543 /// Its prerequisites are checked once, in [`Self::get_for_version`].
2544 pub fn enable_validator_attestation(&self) -> bool {
2545 self.feature_flags.enable_validator_attestation
2546 }
2547
2548 pub fn secp256r1_ecrecover_checks_x_below_p(&self) -> bool {
2549 self.feature_flags.secp256r1_ecrecover_checks_x_below_p
2550 }
2551
2552 /// Its prerequisites are checked once, in [`Self::get_for_version`].
2553 pub fn enable_transaction_dependencies(&self) -> bool {
2554 self.feature_flags.enable_transaction_dependencies
2555 }
2556
2557 pub fn enable_builtin_move_authenticators(&self) -> bool {
2558 let enable_builtin_move_authenticators =
2559 self.feature_flags.enable_builtin_move_authenticators;
2560 if enable_builtin_move_authenticators {
2561 assert!(
2562 self.enable_move_authentication(),
2563 "enable_builtin_move_authenticators requires enable_move_authentication to be set"
2564 );
2565 assert!(
2566 self.public_key_verify_builtin_authenticator_signature_impl_cost_base
2567 .is_some(),
2568 "enable_builtin_move_authenticators requires public_key_verify_builtin_authenticator_signature_impl_cost_base to be set"
2569 );
2570 }
2571 enable_builtin_move_authenticators
2572 }
2573
2574 pub fn enable_claim_account_transaction(&self) -> bool {
2575 let enable_claim_account_transaction = self.feature_flags.enable_claim_account_transaction;
2576 if enable_claim_account_transaction {
2577 // A claimed account is authenticated by the built-in authenticator
2578 // of its key's scheme, so without them it could never send a
2579 // transaction, and an address can only be claimed once.
2580 assert!(
2581 self.enable_builtin_move_authenticators(),
2582 "enable_claim_account_transaction requires enable_builtin_move_authenticators to be set"
2583 );
2584 // The validity check rejects a claim whose budget cannot cover the
2585 // pipeline, so the bounds that define that floor must be set.
2586 assert!(
2587 self.claim_account_max_computation_units.is_some()
2588 && self.claim_account_storage_bytes_bound.is_some(),
2589 "enable_claim_account_transaction requires claim_account_max_computation_units \
2590 and claim_account_storage_bytes_bound to be set"
2591 );
2592 }
2593 enable_claim_account_transaction
2594 }
2595
2596 pub fn enable_smart_accounts(&self) -> bool {
2597 let enable_smart_accounts = self.feature_flags.enable_smart_accounts;
2598 assert!(
2599 !enable_smart_accounts || self.enable_move_authentication(),
2600 "enable_smart_accounts requires enable_move_authentication to be set"
2601 );
2602 enable_smart_accounts
2603 }
2604}
2605
2606#[cfg(not(msim))]
2607static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2608
2609// Use a thread local in sim tests for test isolation.
2610#[cfg(msim)]
2611thread_local! {
2612 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2613}
2614
2615// Instantiations for each protocol version.
2616impl ProtocolConfig {
2617 /// Get the value ProtocolConfig that are in effect during the given
2618 /// protocol version.
2619 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
2620 // ProtocolVersion can be deserialized so we need to check it here as well.
2621 assert!(
2622 version >= ProtocolVersion::MIN,
2623 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
2624 version,
2625 ProtocolVersion::MIN.0,
2626 );
2627 assert!(
2628 version <= ProtocolVersion::MAX_ALLOWED,
2629 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
2630 version,
2631 ProtocolVersion::MAX_ALLOWED.0,
2632 );
2633
2634 let mut ret = Self::get_for_version_impl(version, chain);
2635 ret.version = version;
2636
2637 ret = CONFIG_OVERRIDE.with(|ovr| {
2638 if let Some(override_fn) = &*ovr.borrow() {
2639 warn!(
2640 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
2641 );
2642 override_fn(version, ret)
2643 } else {
2644 ret
2645 }
2646 });
2647
2648 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
2649 warn!(
2650 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
2651 );
2652
2653 // First, deserialize the top-level ProtocolConfig fields
2654 let overrides: ProtocolConfigOptional =
2655 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
2656 .expect("failed to parse ProtocolConfig override env variables");
2657 overrides.apply_to(&mut ret);
2658
2659 // Then, separately deserialize FeatureFlags fields
2660 let feature_flag_overrides: FeatureFlagsOptional =
2661 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_FEATURE_FLAGS_OVERRIDE")
2662 .expect("failed to parse ProtocolConfig feature flags override env variables");
2663
2664 feature_flag_overrides.apply_to(&mut ret.feature_flags);
2665
2666 // An environment override can switch attestation off but cannot
2667 // unset a parameter, so the parameters that require it go with
2668 // the flag.
2669 if !ret.feature_flags.enable_validator_attestation {
2670 ret.unset_attestation_parameters();
2671 }
2672 }
2673
2674 // Devnet runs the P-COOL flow from version 32, before the settings it
2675 // requires exist; only versions from 39 on are checked for them. A test
2676 // override can return the config of another version, so the check
2677 // reads the version of the config returned.
2678 let pcool_requirements_apply =
2679 ret.feature_flags.enable_pcool_flow && ret.version >= ProtocolVersion::new(39);
2680 // Post-consensus validation meters published packages with the
2681 // verifier limits from this config, and reads the regex check budget
2682 // through the panicking accessor.
2683 assert!(
2684 !pcool_requirements_apply || ret.max_meter_ticks_regex_reference_safety.is_some(),
2685 "enable_pcool_flow requires max_meter_ticks_regex_reference_safety"
2686 );
2687 // For the same reason, the consensus handler must not skip a message
2688 // as a duplicate of one that was dropped without being recorded, as
2689 // its cache of such messages differs between validators.
2690 assert!(
2691 !pcool_requirements_apply || ret.feature_flags.consensus_dedup_only_recorded_messages,
2692 "enable_pcool_flow requires consensus_dedup_only_recorded_messages"
2693 );
2694 // With a distance of 0, the consensus handler processing commit C
2695 // would wait for C itself to be fully executed, which cannot happen
2696 // before the handler finishes processing C.
2697 assert!(
2698 !pcool_requirements_apply
2699 || ret
2700 .pcool_deterministic_validation_horizon_distance
2701 .is_some_and(|distance| distance > 0),
2702 "enable_pcool_flow requires a positive pcool_deterministic_validation_horizon_distance"
2703 );
2704 // Without the sender's authenticator run before consensus, a sponsor
2705 // alone could get a transaction sequenced that locks a Move account's
2706 // owned objects.
2707 assert!(
2708 !pcool_requirements_apply
2709 || !ret
2710 .feature_flags
2711 .pre_consensus_sponsor_only_move_authentication,
2712 "enable_pcool_flow excludes pre_consensus_sponsor_only_move_authentication"
2713 );
2714 // The injection cannot chunk updates without its limit.
2715 assert!(
2716 !pcool_requirements_apply || ret.deny_rule_update_max_entries_per_tx.is_some(),
2717 "enable_pcool_flow requires deny_rule_update_max_entries_per_tx"
2718 );
2719 // A deny-rule update chunk must always execute, or the object falls
2720 // permanently behind the mirrored state on every validator at once.
2721 // The binding limits are `max_event_emit_size` (the update event
2722 // carries every entry, ~32 bytes each) and the object-runtime store
2723 // entries touched when removals re-link `LinkedTable` nodes — neither
2724 // expressible as an entry count here, so the constant keeps a wide
2725 // margin below them (tightest is roughly 5000 entries).
2726 const DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING: u64 = 2048;
2727 assert!(
2728 ret.deny_rule_update_max_entries_per_tx
2729 .is_none_or(|max_entries| {
2730 max_entries > 0
2731 && max_entries <= DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING
2732 && [
2733 ret.max_num_new_move_object_ids_system_tx,
2734 ret.max_num_deleted_move_object_ids_system_tx,
2735 ret.object_runtime_max_num_cached_objects_system_tx,
2736 ret.object_runtime_max_num_store_entries_system_tx,
2737 ]
2738 .iter()
2739 .all(|limit| limit.is_none_or(|limit| max_entries <= limit))
2740 }),
2741 "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"
2742 );
2743
2744 if ret.enable_validator_attestation() {
2745 assert!(
2746 ret.enable_pcool_flow(),
2747 "enable_validator_attestation requires enable_pcool_flow to be set"
2748 );
2749 assert!(
2750 ret.report_move_authentication_error(),
2751 "enable_validator_attestation requires report_move_authentication_error to be set"
2752 );
2753 // The attestation verdicts are certified in the summary's version 2.
2754 assert!(
2755 ret.checkpoint_summary_version_specific_data == Some(2),
2756 "enable_validator_attestation requires checkpoint_summary_version_specific_data = 2"
2757 );
2758 // Execution and the attestor's dry run limit the Move
2759 // authenticators to `max_auth_gas`.
2760 assert!(
2761 ret.max_auth_gas.is_some(),
2762 "enable_validator_attestation requires max_auth_gas to be set"
2763 );
2764 }
2765 if ret.attestation_max_refuted_units_squared.is_some() {
2766 assert!(
2767 ret.enable_validator_attestation(),
2768 "attestation_max_refuted_units_squared requires enable_validator_attestation"
2769 );
2770 assert!(
2771 ret.pass_validator_scores_to_advance_epoch(),
2772 "attestation_max_refuted_units_squared requires \
2773 pass_validator_scores_to_advance_epoch"
2774 );
2775 }
2776 if ret.attestation_freshness_window_commits.is_some() {
2777 assert!(
2778 ret.enable_validator_attestation(),
2779 "attestation_freshness_window_commits requires enable_validator_attestation"
2780 );
2781 }
2782 // A transaction without shared inputs that waits too long for its
2783 // dependency is cancelled through its gas object, which carries the
2784 // suggested gas price.
2785 if ret.enable_transaction_dependencies() {
2786 assert!(
2787 ret.congestion_control_gas_price_feedback_mechanism(),
2788 "enable_transaction_dependencies requires \
2789 congestion_control_gas_price_feedback_mechanism to be set"
2790 );
2791 }
2792
2793 ret
2794 }
2795
2796 /// Unsets the parameters [`Self::get_for_version`] accepts only with
2797 /// `enable_validator_attestation`.
2798 fn unset_attestation_parameters(&mut self) {
2799 self.attestation_max_refuted_units_squared = None;
2800 self.attestation_freshness_window_commits = None;
2801 }
2802
2803 /// Get the value ProtocolConfig that are in effect during the given
2804 /// protocol version. Or none if the version is not supported.
2805 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
2806 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
2807 let mut ret = Self::get_for_version_impl(version, chain);
2808 ret.version = version;
2809 Some(ret)
2810 } else {
2811 None
2812 }
2813 }
2814
2815 #[cfg(not(msim))]
2816 pub fn poison_get_for_min_version() {
2817 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
2818 }
2819
2820 #[cfg(not(msim))]
2821 fn load_poison_get_for_min_version() -> bool {
2822 POISON_VERSION_METHODS.load(Ordering::Relaxed)
2823 }
2824
2825 #[cfg(msim)]
2826 pub fn poison_get_for_min_version() {
2827 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
2828 }
2829
2830 #[cfg(msim)]
2831 fn load_poison_get_for_min_version() -> bool {
2832 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
2833 }
2834
2835 pub fn convert_type_argument_error(&self) -> bool {
2836 self.feature_flags.convert_type_argument_error
2837 }
2838
2839 /// Convenience to get the constants at the current minimum supported
2840 /// version. Mainly used by client code that may not yet be
2841 /// protocol-version aware.
2842 pub fn get_for_min_version() -> Self {
2843 if Self::load_poison_get_for_min_version() {
2844 panic!("get_for_min_version called on validator");
2845 }
2846 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
2847 }
2848
2849 /// CAREFUL! - You probably want to use `get_for_version` instead.
2850 ///
2851 /// Convenience to get the constants at the current maximum supported
2852 /// version. Mainly used by genesis. Note well that this function uses
2853 /// the max version supported locally by the node, which is not
2854 /// necessarily the current version of the network. ALSO, this function
2855 /// disregards chain specific config (by using Chain::Unknown), thereby
2856 /// potentially returning a protocol config that is incorrect for some
2857 /// feature flags. Definitely safe for testing and for protocol version
2858 /// 11 and prior.
2859 #[expect(non_snake_case)]
2860 pub fn get_for_max_version_UNSAFE() -> Self {
2861 if Self::load_poison_get_for_min_version() {
2862 panic!("get_for_max_version_UNSAFE called on validator");
2863 }
2864 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
2865 }
2866
2867 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
2868 #[cfg(msim)]
2869 {
2870 // populate the fake simulator version # with a different base tx cost.
2871 if version > ProtocolVersion::MAX {
2872 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
2873 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
2874 return config;
2875 }
2876 }
2877
2878 // IMPORTANT: Never modify the value of any constant for a pre-existing protocol
2879 // version. To change the values here you must create a new protocol
2880 // version with the new values!
2881 let mut cfg = Self {
2882 version,
2883
2884 feature_flags: Default::default(),
2885
2886 max_tx_size_bytes: Some(128 * 1024),
2887 // We need this number to be at least 100x less than
2888 // `max_serialized_tx_effects_size_bytes`otherwise effects can be huge
2889 max_input_objects: Some(2048),
2890 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
2891 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
2892 max_gas_payment_objects: Some(256),
2893 max_modules_in_publish: Some(64),
2894 max_package_dependencies: Some(32),
2895 max_arguments: Some(512),
2896 max_type_arguments: Some(16),
2897 max_type_argument_depth: Some(16),
2898 max_pure_argument_size: Some(16 * 1024),
2899 max_programmable_tx_commands: Some(1024),
2900 move_binary_format_version: Some(7),
2901 min_move_binary_format_version: Some(6),
2902 binary_module_handles: Some(100),
2903 binary_struct_handles: Some(300),
2904 binary_function_handles: Some(1500),
2905 binary_function_instantiations: Some(750),
2906 binary_signatures: Some(1000),
2907 binary_constant_pool: Some(4000),
2908 binary_identifiers: Some(10000),
2909 binary_address_identifiers: Some(100),
2910 binary_struct_defs: Some(200),
2911 binary_struct_def_instantiations: Some(100),
2912 binary_function_defs: Some(1000),
2913 binary_field_handles: Some(500),
2914 binary_field_instantiations: Some(250),
2915 binary_friend_decls: Some(100),
2916 binary_enum_defs: None,
2917 binary_enum_def_instantiations: None,
2918 binary_variant_handles: None,
2919 binary_variant_instantiation_handles: None,
2920 max_move_object_size: Some(250 * 1024),
2921 max_move_package_size: Some(100 * 1024),
2922 max_publish_or_upgrade_per_ptb: Some(5),
2923 // max gas budget for an authentication is in NANOS
2924 max_auth_gas: None,
2925 // max gas budget is in NANOS and an absolute value 50IOTA
2926 max_tx_gas: Some(50_000_000_000),
2927 max_gas_price: Some(100_000),
2928 max_gas_computation_bucket: Some(5_000_000),
2929 max_loop_depth: Some(5),
2930 max_generic_instantiation_length: Some(32),
2931 max_function_parameters: Some(128),
2932 max_basic_blocks: Some(1024),
2933 max_value_stack_size: Some(1024),
2934 max_type_nodes: Some(256),
2935 max_push_size: Some(10000),
2936 max_struct_definitions: Some(200),
2937 max_function_definitions: Some(1000),
2938 max_fields_in_struct: Some(32),
2939 max_dependency_depth: Some(100),
2940 max_num_event_emit: Some(1024),
2941 max_num_new_move_object_ids: Some(2048),
2942 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
2943 max_num_deleted_move_object_ids: Some(2048),
2944 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
2945 max_num_transferred_move_object_ids: Some(2048),
2946 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
2947 max_event_emit_size: Some(250 * 1024),
2948 max_move_vector_len: Some(256 * 1024),
2949 max_type_to_layout_nodes: None,
2950 max_ptb_value_size: None,
2951
2952 max_back_edges_per_function: Some(10_000),
2953 max_back_edges_per_module: Some(10_000),
2954
2955 max_verifier_meter_ticks_per_function: Some(16_000_000),
2956
2957 max_meter_ticks_per_module: Some(16_000_000),
2958 max_meter_ticks_per_package: Some(16_000_000),
2959 max_meter_ticks_regex_reference_safety: None,
2960 max_instantiation_loop_graph_edges: None,
2961
2962 object_runtime_max_num_cached_objects: Some(1000),
2963 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2964 object_runtime_max_num_store_entries: Some(1000),
2965 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2966 // min gas budget is in NANOS and an absolute value 1000 NANOS or 0.000001IOTA
2967 base_tx_cost_fixed: Some(1_000),
2968 package_publish_cost_fixed: Some(1_000),
2969 base_tx_cost_per_byte: Some(0),
2970 package_publish_cost_per_byte: Some(80),
2971 obj_access_cost_read_per_byte: Some(15),
2972 obj_access_cost_mutate_per_byte: Some(40),
2973 obj_access_cost_delete_per_byte: Some(40),
2974 obj_access_cost_verify_per_byte: Some(200),
2975 obj_data_cost_refundable: Some(100),
2976 obj_metadata_cost_non_refundable: Some(50),
2977 gas_model_version: Some(1),
2978 storage_rebate_rate: Some(10000),
2979 // Change reward slashing rate to 100%.
2980 reward_slashing_rate: Some(10000),
2981 storage_gas_price: Some(76),
2982 base_gas_price: None,
2983 // The initial subsidy (target reward) for validators per epoch.
2984 // Refer to the IOTA tokenomics for the origin of this value.
2985 validator_target_reward: Some(767_000 * 1_000_000_000),
2986 max_transactions_per_checkpoint: Some(10_000),
2987 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2988
2989 // For now, perform upgrades with a bare quorum of validators.
2990 buffer_stake_for_protocol_upgrade_bps: Some(5000),
2991
2992 // === Native Function Costs ===
2993 // `address` module
2994 // Cost params for the Move native function `address::from_bytes(bytes: vector<u8>)`
2995 address_from_bytes_cost_base: Some(52),
2996 // Cost params for the Move native function `address::to_u256(address): u256`
2997 address_to_u256_cost_base: Some(52),
2998 // Cost params for the Move native function `address::from_u256(u256): address`
2999 address_from_u256_cost_base: Some(52),
3000
3001 // `config` module
3002 // Cost params for the Move native function `read_setting_impl``
3003 config_read_setting_impl_cost_base: Some(100),
3004 config_read_setting_impl_cost_per_byte: Some(40),
3005
3006 // `dynamic_field` module
3007 // Cost params for the Move native function `hash_type_and_key<K: copy + drop +
3008 // store>(parent: address, k: K): address`
3009 dynamic_field_hash_type_and_key_cost_base: Some(100),
3010 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
3011 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
3012 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
3013 // Cost params for the Move native function `add_child_object<Child: key>(parent:
3014 // address, child: Child)`
3015 dynamic_field_add_child_object_cost_base: Some(100),
3016 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
3017 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
3018 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
3019 // Cost params for the Move native function `borrow_child_object_mut<Child: key>(parent:
3020 // &mut UID, id: address): &mut Child`
3021 dynamic_field_borrow_child_object_cost_base: Some(100),
3022 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
3023 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
3024 // Cost params for the Move native function `remove_child_object<Child: key>(parent:
3025 // address, id: address): Child`
3026 dynamic_field_remove_child_object_cost_base: Some(100),
3027 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
3028 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
3029 // Cost params for the Move native function `has_child_object(parent: address, id:
3030 // address): bool`
3031 dynamic_field_has_child_object_cost_base: Some(100),
3032 // Cost params for the Move native function `has_child_object_with_ty<Child:
3033 // key>(parent: address, id: address): bool`
3034 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
3035 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
3036 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
3037
3038 // `event` module
3039 // Cost params for the Move native function `event::emit<T: copy + drop>(event: T)`
3040 event_emit_cost_base: Some(52),
3041 event_emit_value_size_derivation_cost_per_byte: Some(2),
3042 event_emit_tag_size_derivation_cost_per_byte: Some(5),
3043 event_emit_output_cost_per_byte: Some(10),
3044
3045 // `object` module
3046 // Cost params for the Move native function `borrow_uid<T: key>(obj: &T): &UID`
3047 object_borrow_uid_cost_base: Some(52),
3048 // Cost params for the Move native function `delete_impl(id: address)`
3049 object_delete_impl_cost_base: Some(52),
3050 // Cost params for the Move native function `record_new_uid(id: address)`
3051 object_record_new_uid_cost_base: Some(52),
3052
3053 // `transfer` module
3054 // Cost params for the Move native function `transfer_impl<T: key>(obj: T, recipient:
3055 // address)`
3056 transfer_transfer_internal_cost_base: Some(52),
3057 // Cost params for the Move native function `freeze_object<T: key>(obj: T)`
3058 transfer_freeze_object_cost_base: Some(52),
3059 // Cost params for the Move native function `share_object<T: key>(obj: T)`
3060 transfer_share_object_cost_base: Some(52),
3061 transfer_receive_object_cost_base: Some(52),
3062
3063 // `tx_context` module
3064 // Cost params for the Move native function `transfer_impl<T: key>(obj: T, recipient:
3065 // address)`
3066 tx_context_derive_id_cost_base: Some(52),
3067 tx_context_fresh_id_cost_base: None,
3068 tx_context_sender_cost_base: None,
3069 tx_context_digest_cost_base: None,
3070 tx_context_epoch_cost_base: None,
3071 tx_context_epoch_timestamp_ms_cost_base: None,
3072 tx_context_sponsor_cost_base: None,
3073 tx_context_rgp_cost_base: None,
3074 tx_context_gas_price_cost_base: None,
3075 tx_context_gas_budget_cost_base: None,
3076 tx_context_ids_created_cost_base: None,
3077 tx_context_replace_cost_base: None,
3078 tx_context_tx_nonce_cost_base: None,
3079 smart_account_builtin_authenticator_key_proof_message_cost_base: None,
3080
3081 // `types` module
3082 // Cost params for the Move native function `is_one_time_witness<T: drop>(_: &T): bool`
3083 types_is_one_time_witness_cost_base: Some(52),
3084 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
3085 types_is_one_time_witness_type_cost_per_byte: Some(2),
3086
3087 // `validator` module
3088 // Cost params for the Move native function `validate_metadata_bcs(metadata:
3089 // vector<u8>)`
3090 validator_validate_metadata_cost_base: Some(52),
3091 validator_validate_metadata_data_cost_per_byte: Some(2),
3092
3093 // Crypto
3094 crypto_invalid_arguments_cost: Some(100),
3095 // bls12381::bls12381_min_pk_verify
3096 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
3097 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
3098 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
3099
3100 // bls12381::bls12381_min_pk_verify
3101 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
3102 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
3103 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
3104
3105 // ecdsa_k1::ecrecover
3106 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
3107 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
3108 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
3109 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
3110 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
3111 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
3112
3113 // ecdsa_k1::decompress_pubkey
3114 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
3115
3116 // ecdsa_k1::secp256k1_verify
3117 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
3118 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
3119 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
3120 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
3121 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
3122 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
3123
3124 // ecdsa_r1::ecrecover
3125 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
3126 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
3127 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
3128 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
3129 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
3130 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
3131
3132 // ecdsa_r1::secp256k1_verify
3133 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
3134 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
3135 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
3136 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
3137 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
3138 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
3139
3140 // ecvrf::verify
3141 ecvrf_ecvrf_verify_cost_base: Some(52),
3142 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
3143 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
3144
3145 // ed25519
3146 ed25519_ed25519_verify_cost_base: Some(52),
3147 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
3148 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
3149
3150 // groth16::prepare_verifying_key
3151 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
3152 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
3153
3154 // groth16::verify_groth16_proof_internal
3155 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
3156 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
3157 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
3158 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
3159 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
3160
3161 // hash::blake2b256
3162 hash_blake2b256_cost_base: Some(52),
3163 hash_blake2b256_data_cost_per_byte: Some(2),
3164 hash_blake2b256_data_cost_per_block: Some(2),
3165 // hash::keccak256
3166 hash_keccak256_cost_base: Some(52),
3167 hash_keccak256_data_cost_per_byte: Some(2),
3168 hash_keccak256_data_cost_per_block: Some(2),
3169
3170 poseidon_bn254_cost_base: None,
3171 poseidon_bn254_cost_per_block: None,
3172
3173 // hmac::hmac_sha3_256
3174 hmac_hmac_sha3_256_cost_base: Some(52),
3175 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
3176 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
3177
3178 // group ops
3179 group_ops_bls12381_decode_scalar_cost: Some(52),
3180 group_ops_bls12381_decode_g1_cost: Some(52),
3181 group_ops_bls12381_decode_g2_cost: Some(52),
3182 group_ops_bls12381_decode_gt_cost: Some(52),
3183 group_ops_bls12381_scalar_add_cost: Some(52),
3184 group_ops_bls12381_g1_add_cost: Some(52),
3185 group_ops_bls12381_g2_add_cost: Some(52),
3186 group_ops_bls12381_gt_add_cost: Some(52),
3187 group_ops_bls12381_scalar_sub_cost: Some(52),
3188 group_ops_bls12381_g1_sub_cost: Some(52),
3189 group_ops_bls12381_g2_sub_cost: Some(52),
3190 group_ops_bls12381_gt_sub_cost: Some(52),
3191 group_ops_bls12381_scalar_mul_cost: Some(52),
3192 group_ops_bls12381_g1_mul_cost: Some(52),
3193 group_ops_bls12381_g2_mul_cost: Some(52),
3194 group_ops_bls12381_gt_mul_cost: Some(52),
3195 group_ops_bls12381_scalar_div_cost: Some(52),
3196 group_ops_bls12381_g1_div_cost: Some(52),
3197 group_ops_bls12381_g2_div_cost: Some(52),
3198 group_ops_bls12381_gt_div_cost: Some(52),
3199 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
3200 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
3201 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
3202 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
3203 group_ops_bls12381_g1_msm_base_cost: Some(52),
3204 group_ops_bls12381_g2_msm_base_cost: Some(52),
3205 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
3206 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
3207 group_ops_bls12381_msm_max_len: Some(32),
3208 group_ops_bls12381_pairing_cost: Some(52),
3209 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
3210 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
3211 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
3212 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
3213 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
3214
3215 // zklogin::check_zklogin_id
3216 #[allow(deprecated)]
3217 check_zklogin_id_cost_base: Some(200),
3218 #[allow(deprecated)]
3219 // zklogin::check_zklogin_issuer
3220 check_zklogin_issuer_cost_base: Some(200),
3221
3222 vdf_verify_vdf_cost: None,
3223 vdf_hash_to_input_cost: None,
3224
3225 bcs_per_byte_serialized_cost: Some(2),
3226 bcs_legacy_min_output_size_cost: Some(1),
3227 bcs_failure_cost: Some(52),
3228 hash_sha2_256_base_cost: Some(52),
3229 hash_sha2_256_per_byte_cost: Some(2),
3230 hash_sha2_256_legacy_min_input_len_cost: Some(1),
3231 hash_sha3_256_base_cost: Some(52),
3232 hash_sha3_256_per_byte_cost: Some(2),
3233 hash_sha3_256_legacy_min_input_len_cost: Some(1),
3234 type_name_get_base_cost: Some(52),
3235 type_name_get_per_byte_cost: Some(2),
3236 string_check_utf8_base_cost: Some(52),
3237 string_check_utf8_per_byte_cost: Some(2),
3238 string_is_char_boundary_base_cost: Some(52),
3239 string_sub_string_base_cost: Some(52),
3240 string_sub_string_per_byte_cost: Some(2),
3241 string_index_of_base_cost: Some(52),
3242 string_index_of_per_byte_pattern_cost: Some(2),
3243 string_index_of_per_byte_searched_cost: Some(2),
3244 vector_empty_base_cost: Some(52),
3245 vector_length_base_cost: Some(52),
3246 vector_push_back_base_cost: Some(52),
3247 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
3248 vector_borrow_base_cost: Some(52),
3249 vector_pop_back_base_cost: Some(52),
3250 vector_destroy_empty_base_cost: Some(52),
3251 vector_swap_base_cost: Some(52),
3252 debug_print_base_cost: Some(52),
3253 debug_print_stack_trace_base_cost: Some(52),
3254
3255 max_size_written_objects: Some(5 * 1000 * 1000),
3256 // max size of written objects during a system TXn to allow for larger writes
3257 // akin to `max_size_written_objects` but for system TXns
3258 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
3259
3260 // Limits the length of a Move identifier
3261 max_move_identifier_len: Some(128),
3262 max_move_value_depth: Some(128),
3263 max_move_call_argument_nodes: None,
3264 max_move_call_argument_nodes_total: None,
3265 max_move_enum_variants: None,
3266
3267 gas_rounding_step: Some(1_000),
3268
3269 execution_version: Some(1),
3270
3271 // We maintain the same total size limit for events, but increase the number of
3272 // events that can be emitted.
3273 max_event_emit_size_total: Some(
3274 256 /* former event count limit */ * 250 * 1024, // size limit per event
3275 ),
3276
3277 // Taking a baby step approach, we consider only 20% by stake as bad nodes so we
3278 // have a 80% by stake of nodes participating in the leader committee. That
3279 // allow us for more redundancy in case we have validators
3280 // under performing - since the responsibility is shared
3281 // amongst more nodes. We can increase that once we do have
3282 // higher confidence.
3283 consensus_bad_nodes_stake_threshold: Some(20),
3284
3285 // Max of 10 votes per hour.
3286 #[allow(deprecated)]
3287 max_jwk_votes_per_validator_per_epoch: Some(240),
3288
3289 #[allow(deprecated)]
3290 max_age_of_jwk_in_epochs: Some(1),
3291
3292 consensus_max_transaction_size_bytes: Some(256 * 1024), // 256KB
3293
3294 // Assume 1KB per transaction and 500 transactions per block.
3295 consensus_max_transactions_in_block_bytes: Some(512 * 1024),
3296
3297 random_beacon_reduction_allowed_delta: Some(800),
3298
3299 random_beacon_reduction_lower_bound: Some(1000),
3300 random_beacon_dkg_timeout_round: Some(3000),
3301 random_beacon_min_round_interval_ms: Some(500),
3302
3303 random_beacon_dkg_version: Some(1),
3304
3305 // Assume 20_000 TPS * 5% max stake per validator / (minimum) 4 blocks per round
3306 // = 250 transactions per block maximum Using a higher limit
3307 // that is 512, to account for bursty traffic and system transactions.
3308 consensus_max_num_transactions_in_block: Some(512),
3309
3310 max_deferral_rounds_for_congestion_control: Some(10),
3311
3312 min_checkpoint_interval_ms: Some(200),
3313
3314 checkpoint_rate_window_size: None,
3315
3316 checkpoint_summary_version_specific_data: Some(1),
3317 attestor_accuracy_tolerance_percentage: None,
3318 attestation_max_refuted_units_squared: None,
3319 attestation_freshness_window_commits: None,
3320
3321 max_soft_bundle_size: Some(5),
3322
3323 bridge_should_try_to_finalize_committee: None,
3324
3325 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
3326
3327 max_committee_members_count: None,
3328 deny_rule_update_max_entries_per_tx: None,
3329
3330 consensus_gc_depth: None,
3331
3332 consensus_max_acknowledgments_per_block: None,
3333
3334 max_congestion_limit_overshoot_per_commit: None,
3335
3336 max_concurrent_execution_workers: None,
3337
3338 pcool_deterministic_validation_horizon_distance: None,
3339
3340 scorer_version: None,
3341
3342 // `auth_context` module
3343 auth_context_digest_cost_base: None,
3344 auth_context_tx_data_bytes_cost_base: None,
3345 auth_context_tx_data_bytes_cost_per_byte: None,
3346 auth_context_tx_commands_cost_base: None,
3347 auth_context_tx_commands_cost_per_byte: None,
3348 auth_context_tx_inputs_cost_base: None,
3349 auth_context_tx_inputs_cost_per_byte: None,
3350 auth_context_replace_cost_base: None,
3351 auth_context_replace_cost_per_byte: None,
3352 auth_context_authenticator_function_info_v1_cost_base: None,
3353 consensus_commits_per_schedule: None,
3354 min_validator_count: None,
3355 max_validator_count: None,
3356 min_validator_joining_stake: None,
3357 validator_low_stake_threshold: None,
3358 validator_very_low_stake_threshold: None,
3359 validator_low_stake_grace_period: None,
3360 consensus_leader_schedule_window_size: None,
3361
3362 max_move_system_package_size: None,
3363
3364 // Built-in Move authenticators
3365 public_key_verify_builtin_authenticator_signature_impl_cost_base: None,
3366
3367 ed25519_ed25519_validate_pubkey_cost_base: None,
3368 ecdsa_k1_secp256k1_validate_pubkey_cost_base: None,
3369 ecdsa_r1_secp256r1_validate_pubkey_cost_base: None,
3370 multisig_multisig_validate_pubkey_cost_base: None,
3371 public_key_to_iota_address_impl_cost_base: None,
3372 public_key_verify_personal_message_signature_impl_cost_base: None,
3373 public_key_verify_personal_message_signature_impl_msg_cost_per_byte: None,
3374 public_key_verify_personal_message_signature_impl_sig_cost_per_byte: None,
3375 tx_context_chain_identifier_cost_base: None,
3376
3377 claim_account_max_computation_units: None,
3378 claim_account_storage_bytes_bound: None,
3379
3380 // When adding a new constant, set it to None in the earliest version, like this:
3381 // new_constant: None,
3382 };
3383
3384 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
3385
3386 // MoveVM related flags
3387 {
3388 cfg.feature_flags
3389 .disable_invariant_violation_check_in_swap_loc = true;
3390 cfg.feature_flags.no_extraneous_module_bytes = true;
3391 cfg.feature_flags.hardened_otw_check = true;
3392 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
3393 }
3394
3395 // zkLogin related flags
3396 {
3397 #[allow(deprecated)]
3398 {
3399 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
3400 }
3401 }
3402
3403 // Historical default: Mysticeti. Kept explicitly to match the
3404 // serialized form of pre-v14/v19/v24 configs. No runtime behavior
3405 // depends on this — Starfish is the only consensus protocol.
3406 #[expect(deprecated)]
3407 {
3408 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
3409 }
3410 // Use tonic networking for consensus.
3411 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
3412
3413 cfg.feature_flags.per_object_congestion_control_mode =
3414 PerObjectCongestionControlMode::TotalTxCount;
3415
3416 // Do not allow bridge committee to finalize on mainnet.
3417 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
3418
3419 // Devnet
3420 if chain != Chain::Mainnet && chain != Chain::Testnet {
3421 cfg.feature_flags.enable_poseidon = true;
3422 cfg.poseidon_bn254_cost_base = Some(260);
3423 cfg.poseidon_bn254_cost_per_block = Some(10);
3424
3425 cfg.feature_flags.enable_group_ops_native_function_msm = true;
3426
3427 cfg.feature_flags.enable_vdf = true;
3428 // Set to 30x and 2x the cost of a signature verification for now. This
3429 // should be updated along with other native crypto functions.
3430 cfg.vdf_verify_vdf_cost = Some(1500);
3431 cfg.vdf_hash_to_input_cost = Some(100);
3432
3433 cfg.feature_flags.passkey_auth = true;
3434 }
3435
3436 for cur in 2..=version.0 {
3437 match cur {
3438 1 => unreachable!(),
3439 // version 2 is a new framework version but with no config changes
3440 2 => {}
3441 3 => {
3442 cfg.feature_flags.relocate_event_module = true;
3443 }
3444 4 => {
3445 cfg.max_type_to_layout_nodes = Some(512);
3446 }
3447 5 => {
3448 cfg.feature_flags.protocol_defined_base_fee = true;
3449 cfg.base_gas_price = Some(1000);
3450
3451 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
3452 cfg.feature_flags.convert_type_argument_error = true;
3453 cfg.feature_flags.native_charging_v2 = true;
3454
3455 if chain != Chain::Mainnet && chain != Chain::Testnet {
3456 cfg.feature_flags.uncompressed_g1_group_elements = true;
3457 }
3458
3459 cfg.gas_model_version = Some(2);
3460
3461 cfg.poseidon_bn254_cost_per_block = Some(388);
3462
3463 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
3464 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
3465 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
3466 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
3467 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
3468 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
3469 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
3470 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
3471
3472 // Manually changed to be "under cost"
3473 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
3474 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
3475 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
3476 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
3477
3478 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
3479 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
3480 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
3481 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
3482 Some(8213);
3483 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
3484 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
3485 Some(9484);
3486
3487 cfg.hash_keccak256_cost_base = Some(10);
3488 cfg.hash_blake2b256_cost_base = Some(10);
3489
3490 // group ops
3491 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
3492 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
3493 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
3494 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
3495
3496 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
3497 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
3498 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
3499 cfg.group_ops_bls12381_gt_add_cost = Some(188);
3500
3501 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
3502 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
3503 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
3504 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
3505
3506 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
3507 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
3508 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
3509 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
3510
3511 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
3512 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
3513 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
3514 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
3515
3516 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
3517 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
3518
3519 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
3520 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
3521 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
3522 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
3523
3524 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
3525 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
3526 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
3527 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
3528 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
3529
3530 cfg.group_ops_bls12381_pairing_cost = Some(26897);
3531
3532 cfg.validator_validate_metadata_cost_base = Some(20000);
3533
3534 cfg.max_committee_members_count = Some(50);
3535 }
3536 6 => {
3537 cfg.max_ptb_value_size = Some(1024 * 1024);
3538 }
3539 7 => {
3540 // version 7 is a new framework version but with no config
3541 // changes
3542 }
3543 8 => {
3544 cfg.feature_flags.variant_nodes = true;
3545
3546 if chain != Chain::Mainnet {
3547 // Enable round prober in consensus.
3548 cfg.feature_flags.consensus_round_prober = true;
3549 // Enable distributed vote scoring.
3550 cfg.feature_flags
3551 .consensus_distributed_vote_scoring_strategy = true;
3552 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
3553 // Enable smart ancestor selection for testnet
3554 cfg.feature_flags.consensus_smart_ancestor_selection = true;
3555 // Enable probing for accepted rounds in round prober for testnet
3556 cfg.feature_flags
3557 .consensus_round_prober_probe_accepted_rounds = true;
3558 // Enable zstd compression for consensus in testnet
3559 cfg.feature_flags.consensus_zstd_compression = true;
3560 // Assuming a round rate of max 15/sec, then using a gc depth of 60 allow
3561 // blocks within a window of ~4 seconds
3562 // to be included before be considered garbage collected.
3563 cfg.consensus_gc_depth = Some(60);
3564 }
3565
3566 // Enable min_free_execution_slot for the shared object congestion tracker in
3567 // devnet.
3568 if chain != Chain::Testnet && chain != Chain::Mainnet {
3569 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
3570 }
3571 }
3572 9 => {
3573 if chain != Chain::Mainnet {
3574 // Disable smart ancestor selection in the testnet and devnet.
3575 cfg.feature_flags.consensus_smart_ancestor_selection = false;
3576 }
3577
3578 // Enable zstd compression for consensus
3579 cfg.feature_flags.consensus_zstd_compression = true;
3580
3581 // Enable passkey in multisig in devnet.
3582 if chain != Chain::Testnet && chain != Chain::Mainnet {
3583 cfg.feature_flags.accept_passkey_in_multisig = true;
3584 }
3585
3586 // this flag is now deprecated because of the bridge removal.
3587 cfg.bridge_should_try_to_finalize_committee = None;
3588 }
3589 10 => {
3590 // Enable min_free_execution_slot for the shared object congestion tracker in
3591 // all networks.
3592 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
3593
3594 // Increase the committee size to 80 on all networks.
3595 cfg.max_committee_members_count = Some(80);
3596
3597 // Enable round prober in consensus.
3598 cfg.feature_flags.consensus_round_prober = true;
3599 // Enable probing for accepted rounds in round.
3600 cfg.feature_flags
3601 .consensus_round_prober_probe_accepted_rounds = true;
3602 // Enable distributed vote scoring.
3603 cfg.feature_flags
3604 .consensus_distributed_vote_scoring_strategy = true;
3605 // Enable the new consensus commit rule.
3606 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
3607
3608 // Enable consensus garbage collection
3609 // Assuming a round rate of max 15/sec, then using a gc depth of 60 allow
3610 // blocks within a window of ~4 seconds
3611 // to be included before be considered garbage collected.
3612 cfg.consensus_gc_depth = Some(60);
3613
3614 // Enable minimized child object mutation counting.
3615 cfg.feature_flags.minimize_child_object_mutations = true;
3616
3617 if chain != Chain::Mainnet {
3618 // Enable batched block sync in devnet and testnet.
3619 cfg.feature_flags.consensus_batched_block_sync = true;
3620 }
3621
3622 if chain != Chain::Testnet && chain != Chain::Mainnet {
3623 // Enable the gas price feedback mechanism (which is used for
3624 // transactions cancelled due to shared object congestion) in devnet
3625 cfg.feature_flags
3626 .congestion_control_gas_price_feedback_mechanism = true;
3627 }
3628
3629 cfg.feature_flags.validate_identifier_inputs = true;
3630 cfg.feature_flags.dependency_linkage_error = true;
3631 cfg.feature_flags.additional_multisig_checks = true;
3632 }
3633 11 => {
3634 // version 11 is a new framework version but with no config
3635 // changes
3636 }
3637 12 => {
3638 // Enable the gas price feedback mechanism for transactions
3639 // cancelled due to congestion in all networks
3640 cfg.feature_flags
3641 .congestion_control_gas_price_feedback_mechanism = true;
3642
3643 // Enable normalization of PTB arguments in all networks.
3644 cfg.feature_flags.normalize_ptb_arguments = true;
3645 }
3646 13 => {
3647 // Enable selecting committee based on eligible active validators on all
3648 // networks.
3649 cfg.feature_flags.select_committee_from_eligible_validators = true;
3650 // Enable tracking non-committee eligible active
3651 // validators on all networks.
3652 cfg.feature_flags.track_non_committee_eligible_validators = true;
3653
3654 if chain != Chain::Testnet && chain != Chain::Mainnet {
3655 // Enable selecting committee only from active validators that next epoch
3656 // version and issued valid AuthorityCapabilities notification in devnet.
3657 cfg.feature_flags
3658 .select_committee_supporting_next_epoch_version = true;
3659 }
3660 }
3661 14 => {
3662 // Enable batched block sync for mainnet.
3663 cfg.feature_flags.consensus_batched_block_sync = true;
3664
3665 if chain != Chain::Mainnet {
3666 // Enable median-based commit timestamp calculation in consensus and
3667 // enforce checkpoint timestamp monotonicity for testnet.
3668 cfg.feature_flags
3669 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3670 // Enable selecting committee only from active validators that support the
3671 // next epoch's version and issued valid AuthorityCapabilities notification
3672 // in testnet.
3673 cfg.feature_flags
3674 .select_committee_supporting_next_epoch_version = true;
3675 }
3676 if chain != Chain::Testnet && chain != Chain::Mainnet {
3677 // Switch consensus protocol to Starfish in devnet
3678 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3679 }
3680 }
3681 15 => {
3682 if chain != Chain::Mainnet && chain != Chain::Testnet {
3683 // Enable overshoot of 100 in congestion control. This allows bursts of
3684 // shared object transactions up to 10 times the average allowable
3685 // load set by `max_accumulated_txn_cost_per_object_in_mysticeti_commit`.
3686 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3687 }
3688 }
3689 16 => {
3690 // Enable selecting committee only from active validators that support the
3691 // next epoch's version and issued valid AuthorityCapabilities notification.
3692 cfg.feature_flags
3693 .select_committee_supporting_next_epoch_version = true;
3694 // Enable committing transactions only for traversed headers in Starfish
3695 cfg.feature_flags
3696 .consensus_commit_transactions_only_for_traversed_headers = true;
3697 }
3698 17 => {
3699 // Increase the committee size to 100 on all networks.
3700 cfg.max_committee_members_count = Some(100);
3701 }
3702 18 => {
3703 if chain != Chain::Mainnet {
3704 // Enable passkey authentication support in testnet.
3705 cfg.feature_flags.passkey_auth = true;
3706 }
3707 }
3708 19 => {
3709 if chain != Chain::Testnet && chain != Chain::Mainnet {
3710 // Enable congestion limit overshoot in the gas price feedback
3711 // mechanism on devnet.
3712 cfg.feature_flags
3713 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3714 // Enable a separate gas price feedback mechanism for transactions using
3715 // randomness on devnet.
3716 cfg.feature_flags
3717 .separate_gas_price_feedback_mechanism_for_randomness = true;
3718 // Enable storing metadata in module bytes and then
3719 // publishing package metadata in devnet
3720 cfg.feature_flags.metadata_in_module_bytes = true;
3721 cfg.feature_flags.publish_package_metadata = true;
3722 // Enable Move authentication in devnet
3723 cfg.feature_flags.enable_move_authentication = true;
3724 // Max auth gas budget is in NANOS and an absolute value 0.25 IOTA
3725 cfg.max_auth_gas = Some(250_000_000);
3726 // Increase the base cost for transfer receive object in devnet, since the
3727 // implementation now does check if parent is not an account.
3728 cfg.transfer_receive_object_cost_base = Some(100);
3729 // Enable adjustment of validator rewards based on score in devnet.
3730 cfg.feature_flags.adjust_rewards_by_score = true;
3731 }
3732
3733 if chain != Chain::Mainnet {
3734 // Switch consensus protocol to Starfish in testnet.
3735 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3736
3737 // Enable validator score calculation on testnet
3738 cfg.feature_flags.calculate_validator_scores = true;
3739 cfg.scorer_version = Some(1);
3740 }
3741
3742 // Change epoch transaction will contain validator scores
3743 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
3744
3745 // Enable passkey authentication support in mainnet
3746 cfg.feature_flags.passkey_auth = true;
3747 }
3748 20 => {
3749 if chain != Chain::Testnet && chain != Chain::Mainnet {
3750 // Passes the calculated validator scores to advance epoch only on Devnet
3751 cfg.feature_flags
3752 .pass_calculated_validator_scores_to_advance_epoch = true;
3753 }
3754 }
3755 21 => {
3756 if chain != Chain::Testnet && chain != Chain::Mainnet {
3757 // Enable fast commit syncer for faster recovery in devnet.
3758 cfg.feature_flags.consensus_fast_commit_sync = true;
3759 }
3760 if chain != Chain::Mainnet {
3761 // Enable overshoot of 100 in congestion control on testnet.
3762 // This allows bursts of shared-object transactions
3763 // up to 10 times the average allowable load set by
3764 // `max_accumulated_txn_cost_per_object_in_mysticeti_commit`.
3765 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3766 // Enable congestion limit overshoot in the gas price feedback
3767 // mechanism on testnet.
3768 cfg.feature_flags
3769 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3770 // Enable a separate gas price feedback mechanism for transactions using
3771 // randomness on testnet.
3772 cfg.feature_flags
3773 .separate_gas_price_feedback_mechanism_for_randomness = true;
3774 }
3775
3776 cfg.auth_context_digest_cost_base = Some(30);
3777 cfg.auth_context_tx_commands_cost_base = Some(30);
3778 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
3779 cfg.auth_context_tx_inputs_cost_base = Some(30);
3780 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
3781 cfg.auth_context_replace_cost_base = Some(30);
3782 cfg.auth_context_replace_cost_per_byte = Some(2);
3783
3784 if chain != Chain::Testnet && chain != Chain::Mainnet {
3785 // Decrease max_auth_gas to 0.00025 IOTA
3786 cfg.max_auth_gas = Some(250_000);
3787 }
3788 }
3789 22 => {
3790 // Enable overshoot of 100 in congestion control on all networks.
3791 // This allows bursts of shared-object transactions
3792 // up to 10 times the average allowable load set by
3793 // `max_accumulated_txn_cost_per_object_in_mysticeti_commit`.
3794 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3795 // Enable congestion limit overshoot in the gas price feedback
3796 // mechanism on all networks.
3797 cfg.feature_flags
3798 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3799 // Enable a separate gas price feedback mechanism for transactions using
3800 // randomness on all networks.
3801 cfg.feature_flags
3802 .separate_gas_price_feedback_mechanism_for_randomness = true;
3803
3804 if chain != Chain::Mainnet {
3805 // Enable storing metadata in module bytes and then
3806 // publishing package metadata in testnet
3807 cfg.feature_flags.metadata_in_module_bytes = true;
3808 cfg.feature_flags.publish_package_metadata = true;
3809 // Enable Move authentication in testnet
3810 cfg.feature_flags.enable_move_authentication = true;
3811 // Max_auth_gas is 0.00025 IOTA
3812 cfg.max_auth_gas = Some(250_000);
3813 // Increase the base cost for transfer receive object in testnet, since the
3814 // implementation now does check if parent is not an account.
3815 cfg.transfer_receive_object_cost_base = Some(100);
3816 }
3817
3818 if chain != Chain::Mainnet {
3819 // Enable fast commit syncer for faster recovery on testnet.
3820 cfg.feature_flags.consensus_fast_commit_sync = true;
3821 }
3822 }
3823 23 => {
3824 // Enable Move native context (TxContext via native functions) in all networks.
3825 cfg.feature_flags.move_native_tx_context = true;
3826 cfg.tx_context_fresh_id_cost_base = Some(52);
3827 cfg.tx_context_sender_cost_base = Some(30);
3828 cfg.tx_context_digest_cost_base = Some(30);
3829 cfg.tx_context_epoch_cost_base = Some(30);
3830 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
3831 cfg.tx_context_sponsor_cost_base = Some(30);
3832 cfg.tx_context_rgp_cost_base = Some(30);
3833 cfg.tx_context_gas_price_cost_base = Some(30);
3834 cfg.tx_context_gas_budget_cost_base = Some(30);
3835 cfg.tx_context_ids_created_cost_base = Some(30);
3836 cfg.tx_context_replace_cost_base = Some(30);
3837 }
3838 24 => {
3839 // Switch consensus protocol to Starfish in all networks.
3840 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3841
3842 if chain != Chain::Testnet && chain != Chain::Mainnet {
3843 // Enable Move-based sponsor account authentication in devnet.
3844 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3845 }
3846
3847 // Add tx_data_bytes to AuthContext for intent-based signature
3848 // verification in account abstraction.
3849 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
3850 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
3851
3852 // Enable additional borrow checks.
3853 cfg.feature_flags.additional_borrow_checks = true;
3854 }
3855 #[allow(deprecated)]
3856 25 => {
3857 // Deprecate zkLogin related parameters since zkLogin is deprecated and was
3858 // never enabled on IOTA.
3859 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
3860 cfg.check_zklogin_id_cost_base = None;
3861 cfg.check_zklogin_issuer_cost_base = None;
3862 cfg.max_jwk_votes_per_validator_per_epoch = None;
3863 cfg.max_age_of_jwk_in_epochs = None;
3864 }
3865 26 => {
3866 // Introduce a module to allow Move code to query protocol
3867 // feature flags at runtime.
3868 }
3869 27 => {
3870 if chain != Chain::Mainnet {
3871 // Enable consensus block restrictions on testnet/devnet to bound
3872 // header size by committee size.
3873 cfg.feature_flags.consensus_block_restrictions = true;
3874 }
3875
3876 if chain != Chain::Testnet && chain != Chain::Mainnet {
3877 // Only sponsor Move authentication is performed pre-consensus in devnet.
3878 cfg.feature_flags
3879 .pre_consensus_sponsor_only_move_authentication = true;
3880 }
3881 }
3882 28 => {
3883 // AuthenticatorFunctionInfoV1 max BCS size:
3884 // package (32) + module_name (128) + function_name (128) = 288 bytes = 9 ×
3885 // digest. auth_context_digest_cost_base = 30 for 32 bytes →
3886 // 9 × 30 = 270.
3887 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
3888
3889 // Enable storing metadata in module bytes and then
3890 // publishing package metadata in mainnet.
3891 cfg.feature_flags.metadata_in_module_bytes = true;
3892 cfg.feature_flags.publish_package_metadata = true;
3893 // Enable Move authentication in mainnet.
3894 cfg.feature_flags.enable_move_authentication = true;
3895 // Increase the base cost for transfer receive object in mainnet, since the
3896 // implementation now does check if parent is not an account.
3897 cfg.transfer_receive_object_cost_base = Some(100);
3898
3899 if chain != Chain::Unknown {
3900 // max_auth_gas is 0.00002 IOTA in testnet and mainnet.
3901 cfg.max_auth_gas = Some(20_000);
3902 }
3903
3904 if chain != Chain::Mainnet {
3905 // Enable Move-based sponsor account authentication in testnet.
3906 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3907 // Only sponsor Move authentication is performed pre-consensus in testnet.
3908 cfg.feature_flags
3909 .pre_consensus_sponsor_only_move_authentication = true;
3910 }
3911 }
3912 29 => {
3913 // Keep advancing the random beacon DKG state machine on every commit
3914 // while it is still pending so DKG resolves from persisted state
3915 // (completing, or failing once the timeout round passes) even with no
3916 // fresh inbound traffic -- e.g. after a validator restart -- instead of
3917 // staying pending forever and blocking epoch close.
3918 cfg.feature_flags.always_advance_dkg_to_resolution = true;
3919
3920 // Enable median-based commit timestamp calculation in consensus and
3921 // enforce checkpoint timestamp monotonicity for mainnet.
3922 cfg.feature_flags
3923 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3924
3925 // Enable fast commit syncer for faster recovery on all networks.
3926 cfg.feature_flags.consensus_fast_commit_sync = true;
3927 // Enable consensus block restrictions on all networks to bound
3928 // header size by committee size and garbage-collect the block
3929 // manager.
3930 cfg.feature_flags.consensus_block_restrictions = true;
3931 }
3932 30 => {
3933 // Extend the protocol_config framework module with
3934 // `get_attr<T>`, a generic native that lets Move code
3935 // read any numeric or boolean protocol parameter by name,
3936 // returning T directly and aborting on error.
3937 // Also expose `is_feature_enabled` and `get_attr<T>` to
3938 // iota_system via a new iota_system::protocol_config
3939 // module.
3940 }
3941 31 => {
3942 cfg.feature_flags.validator_metadata_verify_v2 = true;
3943
3944 if chain != Chain::Mainnet && chain != Chain::Testnet {
3945 // Amortize the minimum checkpoint interval over a sliding
3946 // window so the checkpoint rate holds at the ceiling.
3947 cfg.checkpoint_rate_window_size = Some(20);
3948 // Publish package metadata with the module metadata stored as a
3949 // dynamic field.
3950 cfg.feature_flags
3951 .package_metadata_with_dynamic_module_metadata = true;
3952 // Enable the optimistic commit rule (StarfishSpeed) in
3953 // Starfish consensus.
3954 cfg.feature_flags.consensus_starfish_speed = true;
3955 }
3956
3957 cfg.feature_flags.report_move_authentication_error = true;
3958 }
3959 32 => {
3960 // Identical to the genesis SystemParametersV1 values on
3961 // all existing networks; enforcement moves from on-chain
3962 // state to the protocol config.
3963 cfg.min_validator_count = Some(4);
3964 cfg.max_validator_count = Some(150);
3965 cfg.min_validator_joining_stake = Some(2_000_000_000_000_000);
3966 cfg.validator_low_stake_threshold = Some(1_500_000_000_000_000);
3967 cfg.validator_very_low_stake_threshold = Some(1_000_000_000_000_000);
3968 cfg.validator_low_stake_grace_period = Some(7);
3969
3970 // Enable Move-based sponsor account authentication in mainnet.
3971 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3972 // Only sponsor Move authentication is performed pre-consensus in mainnet.
3973 cfg.feature_flags
3974 .pre_consensus_sponsor_only_move_authentication = true;
3975
3976 if chain != Chain::Mainnet {
3977 // Enable the optimistic commit rule (StarfishSpeed) in
3978 // Starfish consensus.
3979 cfg.feature_flags.consensus_starfish_speed = true;
3980 // Amortize the minimum checkpoint interval over a sliding
3981 // window so the checkpoint rate holds at the ceiling.
3982 cfg.checkpoint_rate_window_size = Some(20);
3983 // Publish package metadata with the module metadata stored as a
3984 // dynamic field.
3985 cfg.feature_flags
3986 .package_metadata_with_dynamic_module_metadata = true;
3987 }
3988
3989 if chain != Chain::Mainnet && chain != Chain::Testnet {
3990 // Enable the redesigned leader schedule: sliding-window
3991 // reputation scoring and absolute-score bad-node
3992 // selection.
3993 cfg.feature_flags
3994 .consensus_enable_sliding_window_leader_schedule = true;
3995 cfg.feature_flags
3996 .consensus_enable_absolute_score_leader_schedule = true;
3997 // Enable the P-COOL flow: transactions skip
3998 // pre-consensus certification and owned-object locking,
3999 // and conflicts are resolved after consensus.
4000 cfg.feature_flags.enable_pcool_flow = true;
4001 }
4002 }
4003 33 => {
4004 // Amortize the minimum checkpoint interval over a sliding
4005 // window so the checkpoint rate holds at the ceiling.
4006 cfg.checkpoint_rate_window_size = Some(20);
4007 // Enable the redesigned leader schedule: sliding-window
4008 // reputation scoring and absolute-score bad-node
4009 // selection.
4010 if chain != Chain::Mainnet {
4011 cfg.feature_flags
4012 .consensus_enable_sliding_window_leader_schedule = true;
4013 cfg.feature_flags
4014 .consensus_enable_absolute_score_leader_schedule = true;
4015 }
4016 }
4017 34 => {
4018 if chain != Chain::Testnet && chain != Chain::Mainnet {
4019 // Misbehavior reports carry a dedicated counter for
4020 // invalid bundle parts, previously folded into the
4021 // unprovable block-fault counter.
4022 cfg.scorer_version = Some(2);
4023 }
4024 // Stop locking immutable objects in post-consensus conflict
4025 // resolution. Set on all chains; inert where the P-COOL flow
4026 // is off.
4027 cfg.feature_flags.pcool_skip_immutable_object_locks = true;
4028
4029 if chain == Chain::Mainnet {
4030 // Disable Move-based sponsor account authentication.
4031 cfg.feature_flags.enable_move_authentication_for_sponsor = false;
4032 // The pre-consensus sponsor-only flag requires
4033 // `enable_move_authentication_for_sponsor`, so clear it too.
4034 cfg.feature_flags
4035 .pre_consensus_sponsor_only_move_authentication = false;
4036 }
4037 }
4038 35 => {
4039 // Scale the PTB value size limit by the value's type.
4040 cfg.feature_flags.max_ptb_value_size_v2 = true;
4041 // Let system objects grow past the per-object size bound.
4042 cfg.feature_flags.allow_unbounded_system_objects = true;
4043
4044 // Enable the optimistic commit rule (StarfishSpeed) in
4045 // Starfish consensus.
4046 cfg.feature_flags.consensus_starfish_speed = true;
4047
4048 // Post-consensus validation meters published packages with
4049 // the limits below instead of each validator's own
4050 // `VerifierSigningConfig`. The values are that config's
4051 // defaults, so a validator that leaves it alone reaches
4052 // the same result at admission and post-consensus. Set on
4053 // all chains; inert where the P-COOL flow is off.
4054 cfg.max_verifier_meter_ticks_per_function = Some(2_200_000);
4055 cfg.max_meter_ticks_per_module = Some(2_200_000);
4056 cfg.max_meter_ticks_per_package = Some(2_200_000);
4057 cfg.max_meter_ticks_regex_reference_safety = Some(2_200_000);
4058 cfg.feature_flags.pcool_verifier_limits_from_protocol_config = true;
4059 // Publish package metadata with the module metadata stored as a
4060 // dynamic field.
4061 cfg.feature_flags
4062 .package_metadata_with_dynamic_module_metadata = true;
4063 // Enable the redesigned leader schedule: sliding-window
4064 // reputation scoring and absolute-score bad-node
4065 // selection.
4066 cfg.feature_flags
4067 .consensus_enable_sliding_window_leader_schedule = true;
4068 cfg.feature_flags
4069 .consensus_enable_absolute_score_leader_schedule = true;
4070
4071 // Enable Move-based sponsor account authentication on all
4072 // networks.
4073 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
4074 // Run every `MoveAuthenticator` pre-consensus again, not
4075 // just the sponsor's, on all networks.
4076 cfg.feature_flags
4077 .pre_consensus_sponsor_only_move_authentication = false;
4078 }
4079 36 => {
4080 // No immutable account object can authenticate a sender or
4081 // a sponsor.
4082 cfg.feature_flags.reject_immutable_account_objects = true;
4083 }
4084 37 => {
4085 // Refuse object versions in, or right below, the range
4086 // assigned to canceled transactions before any object is
4087 // loaded, by consulting the transaction bytes only.
4088 cfg.feature_flags.validate_input_object_versions = true;
4089 cfg.feature_flags.disallow_self_identifier = true;
4090 cfg.max_move_enum_variants = Some(move_core_types::VARIANT_COUNT_MAX);
4091 // Apply the package deny list to the package that holds a
4092 // `MoveAuthenticator`'s authenticate function.
4093 cfg.feature_flags.deny_authenticator_packages = true;
4094 // Require a published module header to carry the canonical
4095 // encoding of its binary format version.
4096 cfg.feature_flags.check_canonical_module_version_header = true;
4097 // An authenticate function cannot read randomness, so the
4098 // randomness state object is refused as an authenticator
4099 // input instead of scheduling the transaction as
4100 // randomness-using for nothing.
4101 cfg.feature_flags.disallow_randomness_in_move_authenticator = true;
4102 // Traverse the module graph when checking for cyclic
4103 // dependencies.
4104 cfg.feature_flags.check_cyclic_dependencies = true;
4105 }
4106 38 => {
4107 // A system package is published by the network, not by a
4108 // user, so the user-package bound was never meant to apply
4109 // to it: an existing system package is already exempt when
4110 // it is upgraded at an epoch change, and only a first
4111 // publish (genesis, or a newly added system package) is
4112 // checked against it.
4113 cfg.max_move_system_package_size = Some(200 * 1024);
4114 // An immutable account object cannot authenticate anything
4115 // since version 36, so stop creating new ones.
4116 cfg.feature_flags.reject_immutable_account_creation = true;
4117
4118 cfg.feature_flags.validate_ptb_argument_indices = true;
4119 }
4120 39 => {
4121 // Keep random beacon DKG running after its timeout round, so
4122 // randomness is enabled again mid-epoch if DKG completes late.
4123 if chain != Chain::Mainnet {
4124 cfg.feature_flags.allow_dkg_completion_after_timeout = true;
4125 }
4126
4127 cfg.feature_flags.consensus_dedup_only_recorded_messages = true;
4128
4129 // Raise the minimum validator joining stake to 6M IOTA, the low
4130 // stake threshold to 5.5M IOTA and the very low stake threshold to
4131 // 5M IOTA on all chains.
4132 cfg.min_validator_joining_stake = Some(6_000_000_000_000_000);
4133 cfg.validator_low_stake_threshold = Some(5_500_000_000_000_000);
4134 cfg.validator_very_low_stake_threshold = Some(5_000_000_000_000_000);
4135
4136 // Reject a multisig whose committee mixes Ed25519 with other key
4137 // schemes unless every committee member has signed.
4138 cfg.feature_flags
4139 .reject_partially_signed_mixed_ed25519_multisig = true;
4140
4141 if chain != Chain::Mainnet && chain != Chain::Testnet {
4142 // Post-consensus validation reads object state as of
4143 // 4 commits below the one it validates.
4144 cfg.pcool_deterministic_validation_horizon_distance = Some(4);
4145 // Mirror the governed deny rules into the on-chain
4146 // object in chunks of at most 1000 entries.
4147 cfg.deny_rule_update_max_entries_per_tx = Some(1000);
4148 }
4149
4150 // Reject Groth16 verifying keys whose size does not match the
4151 // number of public inputs before deserializing them.
4152 cfg.feature_flags.limit_groth16_pvk_inputs = true;
4153 cfg.feature_flags.check_groth16_pvk_length = true;
4154
4155 // At execution too, not only at signing: reject the
4156 // deprecated global storage instructions and non-empty
4157 // `acquires` lists when deserializing a module, and verify
4158 // modules without the acquires pass and with vector element
4159 // borrows checked by the call rule.
4160 cfg.feature_flags.deprecate_global_storage_ops = true;
4161 }
4162 40 => {
4163 // Post-consensus validation meters the instantiation-loop
4164 // check and caps its graph with these values, which signing
4165 // also uses.
4166 cfg.feature_flags.meter_instantiation_loops = true;
4167 cfg.max_instantiation_loop_graph_edges = Some(100_000);
4168
4169 // Make the packages named by a `MoveAuthenticator`'s type
4170 // arguments inputs of that authenticator.
4171 cfg.feature_flags
4172 .move_authenticator_type_arg_packages_as_inputs = true;
4173
4174 // Limit the struct, enum and vector values in Move-call
4175 // arguments.
4176 cfg.max_move_call_argument_nodes = Some(2_097_152);
4177 cfg.max_move_call_argument_nodes_total = Some(16_777_216);
4178
4179 // Reject `<SELF>` as an identifier in transactions, at
4180 // signing, after consensus and in block verification.
4181 cfg.feature_flags.disallow_self_identifier_in_transactions = true;
4182
4183 // Update the gas model version.
4184 cfg.gas_model_version = Some(3);
4185
4186 if chain != Chain::Mainnet && chain != Chain::Testnet {
4187 // Validators attest the user transactions they propose,
4188 // and the checkpoint summary certifies the verdicts.
4189 cfg.feature_flags.enable_validator_attestation = true;
4190 cfg.checkpoint_summary_version_specific_data = Some(2);
4191 }
4192 }
4193 41 => {
4194 // Commit a block's transactions once its header is
4195 // traversed, also when their acknowledgment quorum came
4196 // first.
4197 if chain != Chain::Mainnet {
4198 cfg.feature_flags
4199 .consensus_commit_transactions_once_traversed = true;
4200 }
4201
4202 // `ecdsa_r1::secp256r1_ecrecover` rejects a signature
4203 // whose restored x-coordinate is not below the field
4204 // modulus.
4205 cfg.feature_flags.secp256r1_ecrecover_checks_x_below_p = true;
4206
4207 if chain != Chain::Mainnet && chain != Chain::Testnet {
4208 // A programmable transaction may carry a transaction
4209 // dependency input.
4210 cfg.feature_flags.enable_transaction_dependencies = true;
4211 // Raise max_auth_gas to 0.001 IOTA, the minimum transaction
4212 // cost at a gas price of 1000.
4213 cfg.max_auth_gas = Some(1_000_000);
4214
4215 // Ten minutes at devnet's 20 commits a second.
4216 cfg.attestation_freshness_window_commits = Some(12_000);
4217
4218 // Cuts an attestor off after no more than 100 refuted
4219 // attestations per epoch at the current `max_auth_gas`.
4220 cfg.attestation_max_refuted_units_squared = Some(100_000_000);
4221 }
4222 }
4223 42 => {
4224 if chain != Chain::Testnet && chain != Chain::Mainnet {
4225 // Enable built-in Move authenticators in devnet.
4226 cfg.feature_flags.enable_builtin_move_authenticators = true;
4227 // Enable creating smart accounts in devnet only.
4228 cfg.feature_flags.enable_smart_accounts = true;
4229
4230 // Set the cost for built-in Move authenticators to 0 for now.
4231 cfg.public_key_verify_builtin_authenticator_signature_impl_cost_base =
4232 Some(0);
4233 }
4234
4235 cfg.ed25519_ed25519_validate_pubkey_cost_base = Some(170);
4236 cfg.ecdsa_k1_secp256k1_validate_pubkey_cost_base = Some(176);
4237 cfg.ecdsa_r1_secp256r1_validate_pubkey_cost_base = Some(325);
4238 cfg.multisig_multisig_validate_pubkey_cost_base = Some(72);
4239 cfg.public_key_to_iota_address_impl_cost_base = Some(341);
4240 cfg.public_key_verify_personal_message_signature_impl_cost_base = Some(4225);
4241 cfg.public_key_verify_personal_message_signature_impl_msg_cost_per_byte =
4242 Some(2);
4243 cfg.public_key_verify_personal_message_signature_impl_sig_cost_per_byte =
4244 Some(2);
4245 cfg.tx_context_chain_identifier_cost_base = Some(30);
4246 cfg.tx_context_tx_nonce_cost_base = Some(30);
4247 cfg.smart_account_builtin_authenticator_key_proof_message_cost_base = Some(52);
4248 }
4249 // Use this template when making changes:
4250 //
4251 // // modify an existing constant.
4252 // move_binary_format_version: Some(7),
4253 //
4254 // // Add a new constant (which is set to None in prior versions).
4255 // new_constant: Some(new_value),
4256 //
4257 // // Remove a constant (ensure that it is never accessed during this version).
4258 // max_move_object_size: None,
4259 _ => panic!("unsupported version {version:?}"),
4260 }
4261 }
4262 cfg
4263 }
4264
4265 // Extract the bytecode verifier config from this protocol config.
4266 // If used during signing, `signing_limits` should be set.
4267 // The third limit configures`sanity_check_with_regex_reference_safety`,
4268 // which runs the new regex-based reference safety check to check that it is
4269 // strictly more permissive than the current implementation.
4270 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
4271 let (
4272 max_back_edges_per_function,
4273 max_back_edges_per_module,
4274 sanity_check_with_regex_reference_safety,
4275 ) = if let Some((
4276 max_back_edges_per_function,
4277 max_back_edges_per_module,
4278 sanity_check_with_regex_reference_safety,
4279 )) = signing_limits
4280 {
4281 (
4282 Some(max_back_edges_per_function),
4283 Some(max_back_edges_per_module),
4284 Some(sanity_check_with_regex_reference_safety),
4285 )
4286 } else {
4287 (None, None, None)
4288 };
4289
4290 let additional_borrow_checks = if signing_limits.is_some() {
4291 // Always apply additional borrow checks during signing regardless of
4292 // protocol version, to prevent accepting potentially unsafe bytecode.
4293 true
4294 } else {
4295 self.additional_borrow_checks()
4296 };
4297 let deprecate_global_storage_ops = if signing_limits.is_some() {
4298 // Always on during signing, regardless of protocol version: reject
4299 // the deprecated global storage instructions, skip the acquires
4300 // pass and check vector element borrows with the call rule.
4301 true
4302 } else {
4303 self.deprecate_global_storage_ops()
4304 };
4305
4306 // Far above the largest instantiation-loop graph in the system packages
4307 // and examples.
4308 const MAX_INSTANTIATION_LOOP_GRAPH_EDGES_AT_SIGNING: usize = 100_000;
4309
4310 // Applied with the signing limits only: execution verifies without a
4311 // meter. Both fail with PROGRAM_TOO_COMPLEX, which signing rejects.
4312 // Post-consensus validation takes them from the protocol config, see
4313 // `post_consensus_verifier_config`.
4314 let (meter_instantiation_loops, max_instantiation_loop_graph_edges) =
4315 if signing_limits.is_some() {
4316 (true, Some(MAX_INSTANTIATION_LOOP_GRAPH_EDGES_AT_SIGNING))
4317 } else {
4318 (false, None)
4319 };
4320
4321 VerifierConfig {
4322 max_loop_depth: Some(self.max_loop_depth() as usize),
4323 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
4324 max_function_parameters: Some(self.max_function_parameters() as usize),
4325 max_basic_blocks: Some(self.max_basic_blocks() as usize),
4326 max_value_stack_size: self.max_value_stack_size() as usize,
4327 max_type_nodes: Some(self.max_type_nodes() as usize),
4328 max_push_size: Some(self.max_push_size() as usize),
4329 max_dependency_depth: Some(self.max_dependency_depth() as usize),
4330 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
4331 max_function_definitions: Some(self.max_function_definitions() as usize),
4332 max_data_definitions: Some(self.max_struct_definitions() as usize),
4333 max_constant_vector_len: Some(self.max_move_vector_len()),
4334 max_back_edges_per_function,
4335 max_back_edges_per_module,
4336 max_basic_blocks_in_script: None,
4337 max_identifier_len: self.max_move_identifier_len_as_option(), /* Before protocol
4338 * version 9, there was
4339 * no limit */
4340 disallow_self_identifier: self.feature_flags.disallow_self_identifier,
4341 bytecode_version: self.move_binary_format_version(),
4342 max_variants_in_enum: self.max_move_enum_variants_as_option(),
4343 additional_borrow_checks,
4344 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
4345 .map(|limit| limit as u128),
4346 check_cyclic_dependencies: self.feature_flags.check_cyclic_dependencies,
4347 meter_instantiation_loops,
4348 max_instantiation_loop_graph_edges,
4349 deprecate_global_storage_ops,
4350 }
4351 }
4352
4353 /// The bytecode verifier config for post-consensus validation: the
4354 /// protocol's sign-time limits, with `deprecate_global_storage_ops`, the
4355 /// instantiation-loop graph edge limit and the metering of that check
4356 /// taken from the protocol config rather than set as at signing.
4357 ///
4358 /// # Panics
4359 ///
4360 /// Panics before protocol version 35, which has no
4361 /// `max_meter_ticks_regex_reference_safety`.
4362 pub fn post_consensus_verifier_config(&self) -> VerifierConfig {
4363 // Before protocol version 40, the check is metered and capped at
4364 // 100,000 edges, the values signing used then.
4365 let (meter_instantiation_loops, max_instantiation_loop_graph_edges) =
4366 if self.version < ProtocolVersion::new(40) {
4367 (true, Some(100_000))
4368 } else {
4369 (
4370 self.meter_instantiation_loops(),
4371 self.max_instantiation_loop_graph_edges_as_option()
4372 .map(|edges| edges as usize),
4373 )
4374 };
4375 VerifierConfig {
4376 deprecate_global_storage_ops: self.deprecate_global_storage_ops(),
4377 meter_instantiation_loops,
4378 max_instantiation_loop_graph_edges,
4379 ..self.verifier_config(Some(self.verifier_signing_limits()))
4380 }
4381 }
4382
4383 /// The sign-time verifier limits as protocol parameters, in the shape
4384 /// `verifier_config` takes: back edges per function, back edges per module,
4385 /// and the meter limit of the regex-based reference safety check.
4386 /// `VerifierSigningConfig::limits_for_signing` is the validator-local
4387 /// counterpart. Defined from protocol version 35, which sets
4388 /// `max_meter_ticks_regex_reference_safety`.
4389 pub fn verifier_signing_limits(&self) -> (usize, usize, usize) {
4390 (
4391 self.max_back_edges_per_function() as usize,
4392 self.max_back_edges_per_module() as usize,
4393 self.max_meter_ticks_regex_reference_safety() as usize,
4394 )
4395 }
4396
4397 /// The meter limits for verifying the packages a transaction publishes, as
4398 /// protocol parameters. `VerifierSigningConfig::meter_config_for_signing`
4399 /// is the validator-local counterpart.
4400 pub fn meter_config(&self) -> MeterConfig {
4401 MeterConfig {
4402 max_per_fun_meter_units: Some(self.max_verifier_meter_ticks_per_function() as u128),
4403 max_per_mod_meter_units: Some(self.max_meter_ticks_per_module() as u128),
4404 max_per_pkg_meter_units: Some(self.max_meter_ticks_per_package() as u128),
4405 }
4406 }
4407
4408 /// Override one or more settings in the config, for testing.
4409 /// This must be called at the beginning of the test, before
4410 /// get_for_(min|max)_version is called, since those functions cache
4411 /// their return value.
4412 pub fn apply_overrides_for_testing(
4413 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
4414 ) -> OverrideGuard {
4415 CONFIG_OVERRIDE.with(|ovr| {
4416 let mut cur = ovr.borrow_mut();
4417 assert!(cur.is_none(), "config override already present");
4418 *cur = Some(Box::new(override_fn));
4419 OverrideGuard
4420 })
4421 }
4422}
4423
4424// Setters for tests.
4425// This is only needed for feature_flags. Please suffix each setter with
4426// `_for_testing`. Non-feature_flags should already have test setters defined
4427// through macros.
4428impl ProtocolConfig {
4429 pub fn set_per_object_congestion_control_mode_for_testing(
4430 &mut self,
4431 val: PerObjectCongestionControlMode,
4432 ) {
4433 self.feature_flags.per_object_congestion_control_mode = val;
4434 }
4435
4436 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
4437 self.feature_flags.consensus_choice = val;
4438 }
4439
4440 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
4441 self.feature_flags.consensus_network = val;
4442 }
4443
4444 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
4445 self.feature_flags.passkey_auth = val
4446 }
4447
4448 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
4449 self.feature_flags
4450 .disallow_new_modules_in_deps_only_packages = val;
4451 }
4452
4453 pub fn set_check_canonical_module_version_header_for_testing(&mut self, val: bool) {
4454 self.feature_flags.check_canonical_module_version_header = val;
4455 }
4456
4457 pub fn set_deprecate_global_storage_ops_for_testing(&mut self, val: bool) {
4458 self.feature_flags.deprecate_global_storage_ops = val;
4459 }
4460
4461 pub fn set_meter_instantiation_loops_for_testing(&mut self, val: bool) {
4462 self.feature_flags.meter_instantiation_loops = val;
4463 }
4464
4465 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
4466 self.feature_flags.consensus_round_prober = val;
4467 }
4468
4469 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
4470 self.feature_flags
4471 .consensus_distributed_vote_scoring_strategy = val;
4472 }
4473
4474 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
4475 self.consensus_gc_depth = Some(val);
4476 }
4477
4478 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
4479 self.feature_flags.consensus_linearize_subdag_v2 = val;
4480 }
4481
4482 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
4483 self.feature_flags
4484 .consensus_round_prober_probe_accepted_rounds = val;
4485 }
4486
4487 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
4488 self.feature_flags.accept_passkey_in_multisig = val;
4489 }
4490
4491 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
4492 self.feature_flags.consensus_smart_ancestor_selection = val;
4493 }
4494
4495 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
4496 self.feature_flags.consensus_batched_block_sync = val;
4497 }
4498
4499 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
4500 self.feature_flags
4501 .congestion_control_min_free_execution_slot = val;
4502 }
4503
4504 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
4505 self.feature_flags
4506 .congestion_control_gas_price_feedback_mechanism = val;
4507 }
4508
4509 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
4510 self.feature_flags.select_committee_from_eligible_validators = val;
4511 }
4512
4513 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
4514 self.feature_flags.track_non_committee_eligible_validators = val;
4515 }
4516
4517 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
4518 self.feature_flags
4519 .select_committee_supporting_next_epoch_version = val;
4520 }
4521
4522 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
4523 &mut self,
4524 val: bool,
4525 ) {
4526 self.feature_flags
4527 .consensus_median_timestamp_with_checkpoint_enforcement = val;
4528 }
4529
4530 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
4531 &mut self,
4532 val: bool,
4533 ) {
4534 self.feature_flags
4535 .consensus_commit_transactions_only_for_traversed_headers = val;
4536 }
4537
4538 pub fn set_consensus_commit_transactions_once_traversed_for_testing(&mut self, val: bool) {
4539 self.feature_flags
4540 .consensus_commit_transactions_once_traversed = val;
4541 }
4542
4543 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
4544 &mut self,
4545 val: bool,
4546 ) {
4547 self.feature_flags
4548 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
4549 }
4550
4551 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
4552 &mut self,
4553 val: bool,
4554 ) {
4555 self.feature_flags
4556 .separate_gas_price_feedback_mechanism_for_randomness = val;
4557 }
4558
4559 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
4560 self.feature_flags.metadata_in_module_bytes = val;
4561 }
4562
4563 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
4564 self.feature_flags.publish_package_metadata = val;
4565 }
4566
4567 /// Turning Move authentication off also turns off reporting Move
4568 /// authentication errors and validator attestation, which require it.
4569 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
4570 self.feature_flags.enable_move_authentication = val;
4571 if !val {
4572 self.set_report_move_authentication_error_for_testing(false);
4573 self.set_enable_validator_attestation_for_testing(false);
4574 }
4575 }
4576
4577 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
4578 self.feature_flags.enable_move_authentication_for_sponsor = val;
4579 }
4580
4581 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
4582 self.feature_flags.consensus_fast_commit_sync = val;
4583 }
4584
4585 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
4586 self.feature_flags.consensus_block_restrictions = val;
4587 }
4588
4589 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
4590 self.feature_flags
4591 .pre_consensus_sponsor_only_move_authentication = val;
4592 }
4593
4594 pub fn set_consensus_starfish_speed_for_testing(&mut self, val: bool) {
4595 self.feature_flags.consensus_starfish_speed = val;
4596 }
4597
4598 pub fn set_always_advance_dkg_to_resolution_for_testing(&mut self, val: bool) {
4599 self.feature_flags.always_advance_dkg_to_resolution = val;
4600 }
4601
4602 pub fn set_enable_transaction_dependencies_for_testing(&mut self, val: bool) {
4603 self.feature_flags.enable_transaction_dependencies = val;
4604 }
4605
4606 /// Turning the flow on also turns on the flags it requires, turns off
4607 /// `pre_consensus_sponsor_only_move_authentication`, which it excludes, and
4608 /// fills in the settings it requires when unset, whatever the version.
4609 /// Turning the flow off also turns validator attestation off, since
4610 /// attestation cannot run without the flow.
4611 pub fn set_enable_pcool_flow_for_testing(&mut self, val: bool) {
4612 self.feature_flags.enable_pcool_flow = val;
4613 if val {
4614 self.feature_flags
4615 .pre_consensus_sponsor_only_move_authentication = false;
4616 // Post-consensus validation reads this budget; versions before 35
4617 // leave it unset.
4618 self.max_meter_ticks_regex_reference_safety
4619 .get_or_insert(2_200_000);
4620 self.feature_flags.consensus_dedup_only_recorded_messages = true;
4621 self.pcool_deterministic_validation_horizon_distance
4622 .get_or_insert(4);
4623 self.deny_rule_update_max_entries_per_tx.get_or_insert(1000);
4624 } else {
4625 self.set_enable_validator_attestation_for_testing(false);
4626 }
4627 }
4628
4629 pub fn set_reject_immutable_account_objects_for_testing(&mut self, val: bool) {
4630 self.feature_flags.reject_immutable_account_objects = val;
4631 }
4632
4633 pub fn set_reject_immutable_account_creation_for_testing(&mut self, val: bool) {
4634 self.feature_flags.reject_immutable_account_creation = val;
4635 }
4636
4637 pub fn set_validate_input_object_versions_for_testing(&mut self, val: bool) {
4638 self.feature_flags.validate_input_object_versions = val;
4639 }
4640
4641 pub fn set_disallow_randomness_in_move_authenticator_for_testing(&mut self, val: bool) {
4642 self.feature_flags.disallow_randomness_in_move_authenticator = val;
4643 }
4644
4645 pub fn set_move_authenticator_type_arg_packages_as_inputs_for_testing(&mut self, val: bool) {
4646 self.feature_flags
4647 .move_authenticator_type_arg_packages_as_inputs = val;
4648 }
4649
4650 pub fn set_disallow_self_identifier_in_transactions_for_testing(&mut self, val: bool) {
4651 self.feature_flags.disallow_self_identifier_in_transactions = val;
4652 }
4653
4654 pub fn set_commits_per_schedule_for_testing(&mut self, val: u32) {
4655 self.consensus_commits_per_schedule = Some(val);
4656 }
4657
4658 pub fn set_deny_authenticator_packages_for_testing(&mut self, val: bool) {
4659 self.feature_flags.deny_authenticator_packages = val;
4660 }
4661
4662 /// Keeps the config consistent with the getters that assert on this flag:
4663 /// enabling fills in `scorer_version` when unset, disabling also switches
4664 /// off `adjust_rewards_by_score` and
4665 /// `pass_calculated_validator_scores_to_advance_epoch`.
4666 pub fn set_calculate_validator_scores_for_testing(&mut self, val: bool) {
4667 self.feature_flags.calculate_validator_scores = val;
4668 if val {
4669 self.scorer_version.get_or_insert(1);
4670 } else {
4671 self.feature_flags.adjust_rewards_by_score = false;
4672 self.feature_flags
4673 .pass_calculated_validator_scores_to_advance_epoch = false;
4674 }
4675 }
4676
4677 pub fn set_pass_calculated_validator_scores_to_advance_epoch_for_testing(&mut self, val: bool) {
4678 self.feature_flags
4679 .pass_calculated_validator_scores_to_advance_epoch = val;
4680 }
4681
4682 pub fn set_package_metadata_with_dynamic_module_metadata_for_testing(&mut self, val: bool) {
4683 self.feature_flags
4684 .package_metadata_with_dynamic_module_metadata = val;
4685 }
4686
4687 pub fn set_report_move_authentication_error_for_testing(&mut self, val: bool) {
4688 self.feature_flags.report_move_authentication_error = val;
4689 }
4690
4691 pub fn set_leader_schedule_window_size_for_testing(&mut self, val: u32) {
4692 self.consensus_leader_schedule_window_size = Some(val);
4693 }
4694
4695 pub fn set_consensus_enable_sliding_window_leader_schedule_for_testing(&mut self, val: bool) {
4696 self.feature_flags
4697 .consensus_enable_sliding_window_leader_schedule = val;
4698 }
4699
4700 pub fn set_consensus_enable_absolute_score_leader_schedule_for_testing(&mut self, val: bool) {
4701 self.feature_flags
4702 .consensus_enable_absolute_score_leader_schedule = val;
4703 }
4704
4705 pub fn set_allow_dkg_completion_after_timeout_for_testing(&mut self, val: bool) {
4706 self.feature_flags.allow_dkg_completion_after_timeout = val;
4707 }
4708
4709 /// Turning the flag off also turns off `enable_pcool_flow`, which requires
4710 /// it.
4711 pub fn set_consensus_dedup_only_recorded_messages_for_testing(&mut self, val: bool) {
4712 self.feature_flags.consensus_dedup_only_recorded_messages = val;
4713 if !val {
4714 self.set_enable_pcool_flow_for_testing(false);
4715 }
4716 }
4717
4718 /// Turning attestation off also unsets the parameters that require it.
4719 pub fn set_enable_validator_attestation_for_testing(&mut self, val: bool) {
4720 self.feature_flags.enable_validator_attestation = val;
4721 if !val {
4722 self.unset_attestation_parameters();
4723 }
4724 }
4725
4726 pub fn set_enable_builtin_move_authenticators_for_testing(&mut self, val: bool) {
4727 self.feature_flags.enable_builtin_move_authenticators = val;
4728 }
4729
4730 pub fn set_enable_claim_account_transaction_for_testing(&mut self, val: bool) {
4731 self.feature_flags.enable_claim_account_transaction = val;
4732 }
4733
4734 pub fn set_enable_smart_accounts_for_testing(&mut self, val: bool) {
4735 self.feature_flags.enable_smart_accounts = val;
4736 }
4737}
4738
4739type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
4740
4741thread_local! {
4742 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
4743}
4744
4745#[must_use]
4746pub struct OverrideGuard;
4747
4748impl Drop for OverrideGuard {
4749 fn drop(&mut self) {
4750 info!("restoring override fn");
4751 CONFIG_OVERRIDE.with(|ovr| {
4752 *ovr.borrow_mut() = None;
4753 });
4754 }
4755}
4756
4757/// Defines which limit got crossed.
4758/// The value which crossed the limit and value of the limit crossed are
4759/// embedded
4760#[derive(PartialEq, Eq)]
4761pub enum LimitThresholdCrossed {
4762 None,
4763 Soft(u128, u128),
4764 Hard(u128, u128),
4765}
4766
4767/// Convenience function for comparing limit ranges
4768/// V::MAX must be at >= U::MAX and T::MAX
4769pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
4770 x: T,
4771 soft_limit: U,
4772 hard_limit: V,
4773) -> LimitThresholdCrossed {
4774 let x: V = x.into();
4775 let soft_limit: V = soft_limit.into();
4776
4777 debug_assert!(soft_limit <= hard_limit);
4778
4779 // It is important to preserve this comparison order because if soft_limit ==
4780 // hard_limit we want LimitThresholdCrossed::Hard
4781 if x >= hard_limit {
4782 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
4783 } else if x < soft_limit {
4784 LimitThresholdCrossed::None
4785 } else {
4786 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
4787 }
4788}
4789
4790#[macro_export]
4791macro_rules! check_limit {
4792 ($x:expr, $hard:expr) => {
4793 check_limit!($x, $hard, $hard)
4794 };
4795 ($x:expr, $soft:expr, $hard:expr) => {
4796 check_limit_in_range($x as u64, $soft, $hard)
4797 };
4798}
4799
4800/// Used to check which limits were crossed if the TX is metered (not system tx)
4801/// Args are: is_metered, value_to_check, metered_limit, unmetered_limit
4802/// metered_limit is always less than or equal to unmetered_hard_limit
4803#[macro_export]
4804macro_rules! check_limit_by_meter {
4805 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
4806 // If this is metered, we use the metered_limit limit as the upper bound
4807 let (h, metered_str) = if $is_metered {
4808 ($metered_limit, "metered")
4809 } else {
4810 // Unmetered gets more headroom
4811 ($unmetered_hard_limit, "unmetered")
4812 };
4813 use iota_protocol_config::check_limit_in_range;
4814 let result = check_limit_in_range($x as u64, $metered_limit, h);
4815 match result {
4816 LimitThresholdCrossed::None => {}
4817 LimitThresholdCrossed::Soft(_, _) => {
4818 $metric.with_label_values(&[metered_str, "soft"]).inc();
4819 }
4820 LimitThresholdCrossed::Hard(_, _) => {
4821 $metric.with_label_values(&[metered_str, "hard"]).inc();
4822 }
4823 };
4824 result
4825 }};
4826}
4827
4828#[cfg(all(test, not(msim)))]
4829mod test {
4830 use insta::assert_yaml_snapshot;
4831
4832 use super::*;
4833
4834 #[test]
4835 fn snapshot_tests() {
4836 println!("\n============================================================================");
4837 println!("! !");
4838 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
4839 println!("! !");
4840 println!("============================================================================\n");
4841 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
4842 // make Chain::Unknown snapshots compatible with pre-chain-id snapshots so that
4843 // we don't break the release-time compatibility tests. Once Chain
4844 // Id configs have been released everywhere, we can remove this and
4845 // only test Mainnet and Testnet
4846 let chain_str = match chain_id {
4847 Chain::Unknown => "".to_string(),
4848 _ => format!("{chain_id:?}_"),
4849 };
4850 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
4851 let cur = ProtocolVersion::new(i);
4852 assert_yaml_snapshot!(
4853 format!("{}version_{}", chain_str, cur.as_u64()),
4854 ProtocolConfig::get_for_version(cur, *chain_id)
4855 );
4856 }
4857 }
4858 }
4859
4860 #[test]
4861 fn commit_transactions_once_traversed_activation() {
4862 for chain in [Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
4863 for version in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
4864 let config = ProtocolConfig::get_for_version(ProtocolVersion::new(version), chain);
4865 assert_eq!(
4866 config.consensus_commit_transactions_once_traversed(),
4867 version >= 41 && chain != Chain::Mainnet,
4868 "unexpected activation for {chain:?} at version {version}"
4869 );
4870 }
4871 }
4872 }
4873
4874 #[test]
4875 fn test_getters() {
4876 let prot: ProtocolConfig =
4877 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4878 assert_eq!(
4879 prot.max_arguments(),
4880 prot.max_arguments_as_option().unwrap()
4881 );
4882 }
4883
4884 #[test]
4885 fn only_signing_bounds_the_instantiation_loop_checker() {
4886 let prot = ProtocolConfig::get_for_max_version_UNSAFE();
4887
4888 let signing = prot.verifier_config(Some((0, 0, 0)));
4889 assert!(signing.max_instantiation_loop_graph_edges.is_some());
4890 assert!(signing.meter_instantiation_loops);
4891
4892 let execution = prot.verifier_config(None);
4893 assert_eq!(execution.max_instantiation_loop_graph_edges, None);
4894 assert!(!execution.meter_instantiation_loops);
4895 }
4896
4897 #[test]
4898 fn post_consensus_verifier_config_follows_deprecate_global_storage_ops() {
4899 let mut prot = ProtocolConfig::get_for_max_version_UNSAFE();
4900 prot.set_deprecate_global_storage_ops_for_testing(false);
4901
4902 assert!(
4903 prot.verifier_config(Some((0, 0, 0)))
4904 .deprecate_global_storage_ops
4905 );
4906 let post_consensus = prot.post_consensus_verifier_config();
4907 assert!(!post_consensus.deprecate_global_storage_ops);
4908 assert_eq!(
4909 post_consensus.max_back_edges_per_function,
4910 Some(prot.max_back_edges_per_function() as usize)
4911 );
4912
4913 prot.set_deprecate_global_storage_ops_for_testing(true);
4914 assert!(
4915 prot.post_consensus_verifier_config()
4916 .deprecate_global_storage_ops
4917 );
4918 }
4919
4920 #[test]
4921 fn post_consensus_verifier_config_bounds_the_instantiation_loop_checker() {
4922 let before = ProtocolConfig::get_for_version(ProtocolVersion::new(39), Chain::Unknown);
4923 let config = before.post_consensus_verifier_config();
4924 assert!(config.meter_instantiation_loops);
4925 assert_eq!(config.max_instantiation_loop_graph_edges, Some(100_000));
4926
4927 let mut prot = ProtocolConfig::get_for_version(ProtocolVersion::new(40), Chain::Unknown);
4928 prot.set_max_instantiation_loop_graph_edges_for_testing(7);
4929 prot.set_meter_instantiation_loops_for_testing(false);
4930 let config = prot.post_consensus_verifier_config();
4931 assert!(!config.meter_instantiation_loops);
4932 assert_eq!(config.max_instantiation_loop_graph_edges, Some(7));
4933
4934 // The node's signing config keeps its own values.
4935 let signing = prot.verifier_config(Some((0, 0, 0)));
4936 assert!(signing.meter_instantiation_loops);
4937 assert_eq!(signing.max_instantiation_loop_graph_edges, Some(100_000));
4938 }
4939
4940 #[test]
4941 fn signing_and_post_consensus_instantiation_loop_limits_match() {
4942 let prot = ProtocolConfig::get_for_max_version_UNSAFE();
4943 let signing = prot.verifier_config(Some(prot.verifier_signing_limits()));
4944 let post_consensus = prot.post_consensus_verifier_config();
4945
4946 assert_eq!(
4947 signing.meter_instantiation_loops,
4948 post_consensus.meter_instantiation_loops
4949 );
4950 assert_eq!(
4951 signing.max_instantiation_loop_graph_edges,
4952 post_consensus.max_instantiation_loop_graph_edges
4953 );
4954 }
4955
4956 #[test]
4957 fn test_setters() {
4958 let mut prot: ProtocolConfig =
4959 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4960 prot.set_max_arguments_for_testing(123);
4961 assert_eq!(prot.max_arguments(), 123);
4962
4963 prot.set_max_arguments_from_str_for_testing("321".to_string());
4964 assert_eq!(prot.max_arguments(), 321);
4965
4966 prot.disable_max_arguments_for_testing();
4967 assert_eq!(prot.max_arguments_as_option(), None);
4968
4969 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
4970 assert_eq!(prot.max_arguments(), 456);
4971 }
4972
4973 #[test]
4974 fn reject_immutable_account_creation_implies_rejecting_the_objects() {
4975 for chain in [Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
4976 for version in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
4977 // The getter asserts the dependency on
4978 // `reject_immutable_account_objects`.
4979 ProtocolConfig::get_for_version(ProtocolVersion::new(version), chain)
4980 .reject_immutable_account_creation();
4981 }
4982 }
4983 }
4984
4985 #[test]
4986 #[should_panic(expected = "unsupported version")]
4987 fn max_version_test() {
4988 // When this does not panic, version higher than MAX_PROTOCOL_VERSION exists.
4989 // To fix, bump MAX_PROTOCOL_VERSION or disable this check for the version.
4990 let _ = ProtocolConfig::get_for_version_impl(
4991 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
4992 Chain::Unknown,
4993 );
4994 }
4995
4996 #[test]
4997 fn lookup_by_string_test() {
4998 let prot: ProtocolConfig =
4999 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
5000 // Does not exist
5001 assert!(prot.lookup_attr("some random string".to_string()).is_none());
5002
5003 assert!(
5004 prot.lookup_attr("max_arguments".to_string())
5005 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
5006 );
5007
5008 // We didnt have this in version 1 on Mainnet
5009 assert!(
5010 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
5011 .is_none()
5012 );
5013 assert!(
5014 prot.attr_map()
5015 .get("poseidon_bn254_cost_base")
5016 .unwrap()
5017 .is_none()
5018 );
5019
5020 // But we did in version 1 on Devnet
5021 let prot: ProtocolConfig =
5022 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
5023
5024 assert!(
5025 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
5026 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
5027 );
5028 assert!(
5029 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
5030 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
5031 );
5032
5033 // Check feature flags
5034 let prot: ProtocolConfig =
5035 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
5036 // Does not exist
5037 assert!(
5038 prot.feature_flags
5039 .lookup_attr("some random string".to_owned())
5040 .is_none()
5041 );
5042 assert!(
5043 !prot
5044 .feature_flags
5045 .attr_map()
5046 .contains_key("some random string")
5047 );
5048
5049 // Was false in v1 on Mainnet
5050 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
5051 assert!(
5052 prot.feature_flags
5053 .attr_map()
5054 .get("enable_poseidon")
5055 .unwrap()
5056 == &false
5057 );
5058 let prot: ProtocolConfig =
5059 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
5060 // Was true from v1 and up on Devnet
5061 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
5062 assert!(
5063 prot.feature_flags
5064 .attr_map()
5065 .get("enable_poseidon")
5066 .unwrap()
5067 == &true
5068 );
5069 }
5070
5071 /// A chunk limit above the executability ceiling would fail execution on
5072 /// every validator at once, so the configuration is rejected at startup
5073 /// rather than at the flip.
5074 #[test]
5075 #[should_panic(expected = "deny_rule_update_max_entries_per_tx must be positive")]
5076 fn deny_rule_chunk_limit_above_the_ceiling_is_rejected() {
5077 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5078 config.set_enable_pcool_flow_for_testing(true);
5079 config.set_deny_rule_update_max_entries_per_tx_for_testing(2048 + 1);
5080 config
5081 });
5082 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5083 }
5084
5085 /// Execution and the attestor's dry run read `max_auth_gas` under
5086 /// attestation, so a configuration without it is rejected at startup
5087 /// rather than stopping the validator at the first transaction.
5088 #[test]
5089 #[should_panic(expected = "enable_validator_attestation requires max_auth_gas to be set")]
5090 fn attestation_without_max_auth_gas_is_rejected() {
5091 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5092 config.disable_max_auth_gas_for_testing();
5093 config
5094 });
5095 let config = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5096 assert!(
5097 config.enable_validator_attestation(),
5098 "the latest devnet configuration should run attestation"
5099 );
5100 }
5101
5102 /// A zero chunk limit would make every delta unsplittable; the pure
5103 /// chunking function clamps it, but the configuration is still invalid.
5104 #[test]
5105 #[should_panic(expected = "deny_rule_update_max_entries_per_tx must be positive")]
5106 fn deny_rule_chunk_limit_of_zero_is_rejected() {
5107 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5108 config.set_enable_pcool_flow_for_testing(true);
5109 config.set_deny_rule_update_max_entries_per_tx_for_testing(0);
5110 config
5111 });
5112 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5113 }
5114
5115 /// The value the flip is expected to ship stays inside the limits.
5116 #[test]
5117 fn deny_rule_chunk_limit_within_system_tx_object_id_limit_is_accepted() {
5118 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5119 config.set_enable_pcool_flow_for_testing(true);
5120 config.set_deny_rule_update_max_entries_per_tx_for_testing(1000);
5121 config
5122 });
5123 let config = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5124 assert_eq!(config.deny_rule_update_max_entries_per_tx(), 1000);
5125 }
5126
5127 /// From version 39 the P-COOL flow requires the deny rule settings, which
5128 /// mirror the governed deny rules into the on-chain object.
5129 #[test]
5130 #[should_panic(expected = "enable_pcool_flow requires deny_rule_update_max_entries_per_tx")]
5131 fn pcool_flow_without_the_deny_rule_settings_is_rejected() {
5132 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5133 config.set_enable_pcool_flow_for_testing(true);
5134 config.disable_deny_rule_update_max_entries_per_tx_for_testing();
5135 config
5136 });
5137 let _ = ProtocolConfig::get_for_version(ProtocolVersion::new(39), Chain::Unknown);
5138 }
5139
5140 /// Devnet runs the P-COOL flow from version 32, before the settings it
5141 /// requires exist. Those versions are not checked for them.
5142 #[test]
5143 fn devnet_versions_before_39_run_the_pcool_flow_without_its_settings() {
5144 for version in 32..39 {
5145 let config =
5146 ProtocolConfig::get_for_version(ProtocolVersion::new(version), Chain::Unknown);
5147 assert!(config.enable_pcool_flow(), "version {version}");
5148 assert_eq!(
5149 config.deny_rule_update_max_entries_per_tx_as_option(),
5150 None,
5151 "version {version}"
5152 );
5153 }
5154 }
5155
5156 /// Devnet sets the horizon distance from version 39 on; Mainnet, Testnet
5157 /// and earlier versions leave it unset. An override still wins.
5158 #[test]
5159 fn horizon_distance_is_set_on_devnet_from_version_39() {
5160 let config = ProtocolConfig::get_for_version(ProtocolVersion::new(39), Chain::Unknown);
5161 assert_eq!(config.pcool_deterministic_validation_horizon_distance(), 4);
5162 for (version, chain) in [
5163 (38, Chain::Unknown),
5164 (39, Chain::Mainnet),
5165 (39, Chain::Testnet),
5166 ] {
5167 let config = ProtocolConfig::get_for_version(ProtocolVersion::new(version), chain);
5168 assert_eq!(
5169 config.pcool_deterministic_validation_horizon_distance_as_option(),
5170 None,
5171 "version {version} on {chain:?}"
5172 );
5173 }
5174
5175 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5176 config.set_pcool_deterministic_validation_horizon_distance_for_testing(5);
5177 config
5178 });
5179 let config = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5180 assert_eq!(config.pcool_deterministic_validation_horizon_distance(), 5);
5181 }
5182
5183 /// The P-COOL flow has no horizon distance to fall back on.
5184 #[test]
5185 #[should_panic(expected = "pcool_deterministic_validation_horizon_distance")]
5186 fn pcool_flow_without_a_horizon_distance_is_rejected() {
5187 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5188 config.set_enable_pcool_flow_for_testing(true);
5189 config.disable_pcool_deterministic_validation_horizon_distance_for_testing();
5190 config
5191 });
5192 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5193 }
5194
5195 /// With a horizon distance of 0, the consensus handler processing commit C
5196 /// would wait for C itself to be fully executed, which cannot happen before
5197 /// the handler finishes processing C, so the network would halt. The
5198 /// configuration is rejected at startup.
5199 #[test]
5200 #[should_panic(expected = "pcool_deterministic_validation_horizon_distance")]
5201 fn horizon_distance_of_zero_with_the_pcool_flow_is_rejected() {
5202 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5203 config.set_enable_pcool_flow_for_testing(true);
5204 config.set_pcool_deterministic_validation_horizon_distance_for_testing(0);
5205 config
5206 });
5207 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5208 }
5209
5210 /// Every version from 39 and chain that turns the P-COOL flow on sets a
5211 /// positive horizon distance and the verifier limits post-consensus
5212 /// validation meters published packages with.
5213 #[test]
5214 fn every_version_with_the_pcool_flow_sets_its_requirements() {
5215 for chain in [Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
5216 for version in 39..=MAX_PROTOCOL_VERSION {
5217 let config = ProtocolConfig::get_for_version(ProtocolVersion::new(version), chain);
5218 if config.enable_pcool_flow() {
5219 assert!(
5220 config
5221 .pcool_deterministic_validation_horizon_distance_as_option()
5222 .is_some_and(|distance| distance > 0),
5223 "version {version} on {chain:?} runs the P-COOL flow without a positive \
5224 horizon distance"
5225 );
5226 assert!(
5227 config
5228 .max_meter_ticks_regex_reference_safety_as_option()
5229 .is_some(),
5230 "version {version} on {chain:?} runs the P-COOL flow without the \
5231 regex reference safety budget"
5232 );
5233 }
5234 }
5235 }
5236 }
5237
5238 /// The penalty's value is calibrated for refuted attestations of at most
5239 /// 2 × `gas_rounding_step` units, execution's run plus the judge's re-run.
5240 /// That holds while `max_auth_gas` buys no more than one step per run at a
5241 /// gas price of 1,000.
5242 #[test]
5243 fn refuted_attestation_penalty_requires_max_auth_gas_within_one_rounding_step() {
5244 const GAS_PRICE: u64 = 1_000;
5245 for chain in [Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
5246 for version in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
5247 let config = ProtocolConfig::get_for_version(ProtocolVersion::new(version), chain);
5248 if config
5249 .attestation_max_refuted_units_squared_as_option()
5250 .is_some()
5251 {
5252 assert!(
5253 config.max_auth_gas() <= config.gas_rounding_step() * GAS_PRICE,
5254 "version {version} on {chain:?} penalizes refuted attestations while \
5255 max_auth_gas buys more than one gas_rounding_step"
5256 );
5257 }
5258 }
5259 }
5260 }
5261
5262 /// Turning the P-COOL flow on for a test also turns on what it requires,
5263 /// as a version that turns it on must, whatever the version the test
5264 /// starts from.
5265 #[test]
5266 fn enabling_the_pcool_flow_for_testing_enables_its_requirements() {
5267 let mut config = ProtocolConfig::get_for_version(
5268 ProtocolVersion::new(MIN_PROTOCOL_VERSION),
5269 Chain::Unknown,
5270 );
5271 assert!(
5272 config
5273 .max_meter_ticks_regex_reference_safety_as_option()
5274 .is_none()
5275 );
5276 config.set_enable_pcool_flow_for_testing(true);
5277 assert!(config.enable_pcool_flow());
5278 assert_eq!(config.max_meter_ticks_regex_reference_safety(), 2_200_000);
5279 assert!(config.consensus_dedup_only_recorded_messages());
5280 assert_eq!(config.pcool_deterministic_validation_horizon_distance(), 4);
5281 assert_eq!(config.deny_rule_update_max_entries_per_tx(), 1000);
5282 }
5283
5284 /// An override that returns an older version's config for every version
5285 /// asked for, as `TestAuthorityBuilder` installs, is checked against the
5286 /// version of that config, which runs the P-COOL flow on Devnet before the
5287 /// settings it requires exist.
5288 #[test]
5289 fn an_override_returning_an_older_config_is_checked_against_its_version() {
5290 let older = ProtocolConfig::get_for_version(ProtocolVersion::new(37), Chain::Unknown);
5291 assert!(older.enable_pcool_flow());
5292 assert!(!older.consensus_dedup_only_recorded_messages());
5293 let _guard = ProtocolConfig::apply_overrides_for_testing(move |_, _| older.clone());
5294 let config = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5295 assert_eq!(config.version, ProtocolVersion::new(37));
5296 }
5297
5298 /// Without `consensus_dedup_only_recorded_messages` the consensus handler
5299 /// could skip a message as a duplicate of one only some validators saw
5300 /// dropped, so the combination is rejected at startup.
5301 #[test]
5302 #[should_panic(expected = "enable_pcool_flow requires consensus_dedup_only_recorded_messages")]
5303 fn pcool_flow_without_dedup_of_recorded_messages_is_rejected() {
5304 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5305 config.feature_flags.consensus_dedup_only_recorded_messages = false;
5306 config
5307 });
5308 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5309 }
5310
5311 /// With sponsor-only pre-consensus authentication, a sponsor alone could get
5312 /// a transaction sequenced that locks a Move account's owned objects, so
5313 /// the P-COOL flow excludes it.
5314 #[test]
5315 #[should_panic(
5316 expected = "enable_pcool_flow excludes pre_consensus_sponsor_only_move_authentication"
5317 )]
5318 fn pcool_flow_with_sponsor_only_pre_consensus_authentication_is_rejected() {
5319 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5320 config
5321 .feature_flags
5322 .pre_consensus_sponsor_only_move_authentication = true;
5323 config
5324 });
5325 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5326 }
5327
5328 /// Turning the P-COOL flow on for testing turns sponsor-only pre-consensus
5329 /// authentication off, which Testnet's version 34 has on.
5330 #[test]
5331 fn turning_the_pcool_flow_on_turns_sponsor_only_authentication_off() {
5332 let mut config = ProtocolConfig::get_for_version(ProtocolVersion::new(34), Chain::Testnet);
5333 assert!(config.pre_consensus_sponsor_only_move_authentication());
5334 config.set_enable_pcool_flow_for_testing(true);
5335 assert!(!config.pre_consensus_sponsor_only_move_authentication());
5336 }
5337
5338 /// A test that turns a requirement off keeps a valid config instead of
5339 /// tripping the startup check.
5340 #[test]
5341 fn disabling_a_requirement_for_testing_disables_the_pcool_flow() {
5342 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
5343 config.set_consensus_dedup_only_recorded_messages_for_testing(false);
5344 config
5345 });
5346 let config = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
5347 assert!(!config.enable_pcool_flow());
5348 }
5349
5350 #[test]
5351 fn limit_range_fn_test() {
5352 let low = 100u32;
5353 let high = 10000u64;
5354
5355 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
5356 assert!(matches!(
5357 check_limit!(255u16, low, high),
5358 LimitThresholdCrossed::Soft(255u128, 100)
5359 ));
5360 // This wont compile because lossy
5361 // assert!(check_limit!(100000000u128, low, high) ==
5362 // LimitThresholdCrossed::None); This wont compile because lossy
5363 // assert!(check_limit!(100000000usize, low, high) ==
5364 // LimitThresholdCrossed::None);
5365
5366 assert!(matches!(
5367 check_limit!(2550000u64, low, high),
5368 LimitThresholdCrossed::Hard(2550000, 10000)
5369 ));
5370
5371 assert!(matches!(
5372 check_limit!(2550000u64, high, high),
5373 LimitThresholdCrossed::Hard(2550000, 10000)
5374 ));
5375
5376 assert!(matches!(
5377 check_limit!(1u8, high),
5378 LimitThresholdCrossed::None
5379 ));
5380
5381 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
5382
5383 assert!(matches!(
5384 check_limit!(2550000u64, high),
5385 LimitThresholdCrossed::Hard(2550000, 10000)
5386 ));
5387 }
5388}