1use 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
20const MIN_PROTOCOL_VERSION: u64 = 1;
22pub const MAX_PROTOCOL_VERSION: u64 = 38;
23
24pub const PROTOCOL_VERSION_IIP8: u64 = 20;
26#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
254pub struct ProtocolVersion(u64);
255
256impl ProtocolVersion {
257 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
263
264 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
265
266 #[cfg(not(msim))]
267 const MAX_ALLOWED: Self = Self::MAX;
268
269 #[cfg(msim)]
272 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
273
274 pub fn new(v: u64) -> Self {
275 Self(v)
276 }
277
278 pub const fn as_u64(&self) -> u64 {
279 self.0
280 }
281
282 pub fn max() -> Self {
285 Self::MAX
286 }
287}
288
289impl From<u64> for ProtocolVersion {
290 fn from(v: u64) -> Self {
291 Self::new(v)
292 }
293}
294
295impl std::ops::Sub<u64> for ProtocolVersion {
296 type Output = Self;
297 fn sub(self, rhs: u64) -> Self::Output {
298 Self::new(self.0 - rhs)
299 }
300}
301
302impl std::ops::Add<u64> for ProtocolVersion {
303 type Output = Self;
304 fn add(self, rhs: u64) -> Self::Output {
305 Self::new(self.0 + rhs)
306 }
307}
308
309#[derive(
310 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
311)]
312pub enum Chain {
313 Mainnet,
314 Testnet,
315 #[default]
316 Unknown,
317}
318
319impl Chain {
320 pub fn as_str(self) -> &'static str {
321 match self {
322 Chain::Mainnet => "mainnet",
323 Chain::Testnet => "testnet",
324 Chain::Unknown => "unknown",
325 }
326 }
327}
328
329pub struct Error(pub String);
330
331#[derive(
335 Default,
336 Clone,
337 Serialize,
338 Deserialize,
339 Debug,
340 ProtocolConfigFeatureFlagsGetters,
341 ProtocolConfigOverride,
342)]
343struct FeatureFlags {
344 #[serde(skip_serializing_if = "is_true")]
350 disable_invariant_violation_check_in_swap_loc: bool,
351
352 #[serde(skip_serializing_if = "is_true")]
355 no_extraneous_module_bytes: bool,
356
357 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
359 consensus_transaction_ordering: ConsensusTransactionOrdering,
360
361 #[serde(skip_serializing_if = "is_true")]
364 hardened_otw_check: bool,
365
366 #[serde(skip_serializing_if = "is_false")]
368 enable_poseidon: bool,
369
370 #[serde(skip_serializing_if = "is_false")]
372 enable_group_ops_native_function_msm: bool,
373
374 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
376 per_object_congestion_control_mode: PerObjectCongestionControlMode,
377
378 #[serde(
380 default = "ConsensusChoice::mysticeti_deprecated",
381 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
382 )]
383 consensus_choice: ConsensusChoice,
384
385 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
387 consensus_network: ConsensusNetwork,
388
389 #[deprecated]
391 #[serde(skip_serializing_if = "Option::is_none")]
392 zklogin_max_epoch_upper_bound_delta: Option<u64>,
393
394 #[serde(skip_serializing_if = "is_false")]
396 enable_vdf: bool,
397
398 #[serde(skip_serializing_if = "is_false")]
400 passkey_auth: bool,
401
402 #[serde(skip_serializing_if = "is_true")]
405 rethrow_serialization_type_layout_errors: bool,
406
407 #[serde(skip_serializing_if = "is_false")]
409 relocate_event_module: bool,
410
411 #[serde(skip_serializing_if = "is_false")]
413 protocol_defined_base_fee: bool,
414
415 #[serde(skip_serializing_if = "is_false")]
417 uncompressed_g1_group_elements: bool,
418
419 #[serde(skip_serializing_if = "is_false")]
421 disallow_new_modules_in_deps_only_packages: bool,
422
423 #[serde(skip_serializing_if = "is_false")]
425 native_charging_v2: bool,
426
427 #[serde(skip_serializing_if = "is_false")]
429 convert_type_argument_error: bool,
430
431 #[serde(skip_serializing_if = "is_false")]
433 consensus_round_prober: bool,
434
435 #[serde(skip_serializing_if = "is_false")]
437 consensus_distributed_vote_scoring_strategy: bool,
438
439 #[serde(skip_serializing_if = "is_false")]
443 consensus_linearize_subdag_v2: bool,
444
445 #[serde(skip_serializing_if = "is_false")]
447 variant_nodes: bool,
448
449 #[serde(skip_serializing_if = "is_false")]
451 consensus_smart_ancestor_selection: bool,
452
453 #[serde(skip_serializing_if = "is_false")]
455 consensus_round_prober_probe_accepted_rounds: bool,
456
457 #[serde(skip_serializing_if = "is_false")]
459 consensus_zstd_compression: bool,
460
461 #[serde(skip_serializing_if = "is_false")]
464 congestion_control_min_free_execution_slot: bool,
465
466 #[serde(skip_serializing_if = "is_false")]
468 accept_passkey_in_multisig: bool,
469
470 #[serde(skip_serializing_if = "is_false")]
472 consensus_batched_block_sync: bool,
473
474 #[serde(skip_serializing_if = "is_false")]
477 congestion_control_gas_price_feedback_mechanism: bool,
478
479 #[serde(skip_serializing_if = "is_false")]
481 validate_identifier_inputs: bool,
482
483 #[serde(skip_serializing_if = "is_false")]
486 minimize_child_object_mutations: bool,
487
488 #[serde(skip_serializing_if = "is_false")]
490 dependency_linkage_error: bool,
491
492 #[serde(skip_serializing_if = "is_false")]
494 additional_multisig_checks: bool,
495
496 #[serde(skip_serializing_if = "is_false")]
499 normalize_ptb_arguments: bool,
500
501 #[serde(skip_serializing_if = "is_false")]
505 select_committee_from_eligible_validators: bool,
506
507 #[serde(skip_serializing_if = "is_false")]
514 track_non_committee_eligible_validators: bool,
515
516 #[serde(skip_serializing_if = "is_false")]
522 select_committee_supporting_next_epoch_version: bool,
523
524 #[serde(skip_serializing_if = "is_false")]
528 consensus_median_timestamp_with_checkpoint_enforcement: bool,
529
530 #[serde(skip_serializing_if = "is_false")]
532 consensus_commit_transactions_only_for_traversed_headers: bool,
533
534 #[serde(skip_serializing_if = "is_false")]
536 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
537
538 #[serde(skip_serializing_if = "is_false")]
541 separate_gas_price_feedback_mechanism_for_randomness: bool,
542
543 #[serde(skip_serializing_if = "is_false")]
546 metadata_in_module_bytes: bool,
547
548 #[serde(skip_serializing_if = "is_false")]
550 publish_package_metadata: bool,
551
552 #[serde(skip_serializing_if = "is_false")]
554 enable_move_authentication: bool,
555
556 #[serde(skip_serializing_if = "is_false")]
558 enable_move_authentication_for_sponsor: bool,
559
560 #[serde(skip_serializing_if = "is_false")]
562 pass_validator_scores_to_advance_epoch: bool,
563
564 #[serde(skip_serializing_if = "is_false")]
566 calculate_validator_scores: bool,
567
568 #[serde(skip_serializing_if = "is_false")]
570 adjust_rewards_by_score: bool,
571
572 #[serde(skip_serializing_if = "is_false")]
575 pass_calculated_validator_scores_to_advance_epoch: bool,
576
577 #[serde(skip_serializing_if = "is_false")]
582 consensus_fast_commit_sync: bool,
583
584 #[serde(skip_serializing_if = "is_false")]
587 consensus_block_restrictions: bool,
588
589 #[serde(skip_serializing_if = "is_false")]
591 move_native_tx_context: bool,
592
593 #[serde(skip_serializing_if = "is_false")]
595 additional_borrow_checks: bool,
596
597 #[serde(skip_serializing_if = "is_false")]
599 pre_consensus_sponsor_only_move_authentication: bool,
600
601 #[serde(skip_serializing_if = "is_false")]
603 consensus_starfish_speed: bool,
604
605 #[serde(skip_serializing_if = "is_false")]
612 always_advance_dkg_to_resolution: bool,
613
614 #[serde(skip_serializing_if = "is_false")]
619 enable_pcool_flow: bool,
620
621 #[serde(skip_serializing_if = "is_false")]
626 pcool_skip_immutable_object_locks: bool,
627
628 #[serde(skip_serializing_if = "is_false")]
633 pcool_verifier_limits_from_protocol_config: bool,
634
635 #[serde(skip_serializing_if = "is_false")]
637 validator_metadata_verify_v2: bool,
638
639 #[serde(skip_serializing_if = "is_false")]
643 deny_rule_governance: bool,
644
645 #[serde(skip_serializing_if = "is_false")]
650 deny_rule_governance_on_chain: bool,
651
652 #[serde(skip_serializing_if = "is_false")]
656 deny_authenticator_packages: bool,
657
658 #[serde(skip_serializing_if = "is_false")]
661 package_metadata_with_dynamic_module_metadata: bool,
662
663 #[serde(skip_serializing_if = "is_false")]
666 report_move_authentication_error: bool,
667
668 #[serde(skip_serializing_if = "is_false")]
673 consensus_enable_sliding_window_leader_schedule: bool,
674
675 #[serde(skip_serializing_if = "is_false")]
680 consensus_enable_absolute_score_leader_schedule: bool,
681
682 #[serde(skip_serializing_if = "is_false")]
684 max_ptb_value_size_v2: bool,
685
686 #[serde(skip_serializing_if = "is_false")]
688 allow_unbounded_system_objects: bool,
689
690 #[serde(skip_serializing_if = "is_false")]
693 reject_immutable_account_objects: bool,
694
695 #[serde(skip_serializing_if = "is_false")]
698 reject_immutable_account_creation: bool,
699
700 #[serde(skip_serializing_if = "is_false")]
706 validate_input_object_versions: bool,
707
708 #[serde(skip_serializing_if = "is_false")]
710 disallow_self_identifier: bool,
711
712 #[serde(skip_serializing_if = "is_false")]
717 check_canonical_module_version_header: bool,
718
719 #[serde(skip_serializing_if = "is_false")]
724 disallow_randomness_in_move_authenticator: bool,
725
726 #[serde(skip_serializing_if = "is_false")]
730 check_cyclic_dependencies: bool,
731
732 #[serde(skip_serializing_if = "is_false")]
734 deprecate_global_storage_ops_during_deserialization: bool,
735}
736
737fn is_true(b: &bool) -> bool {
738 *b
739}
740
741fn is_false(b: &bool) -> bool {
742 !b
743}
744
745#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
747pub enum ConsensusTransactionOrdering {
748 #[default]
751 None,
752 ByGasPrice,
754}
755
756impl ConsensusTransactionOrdering {
757 pub fn is_none(&self) -> bool {
758 matches!(self, ConsensusTransactionOrdering::None)
759 }
760}
761
762#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
764pub enum PerObjectCongestionControlMode {
765 #[default]
766 None, TotalGasBudget, TotalTxCount, }
770
771impl PerObjectCongestionControlMode {
772 pub fn is_none(&self) -> bool {
773 matches!(self, PerObjectCongestionControlMode::None)
774 }
775}
776
777#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
779pub enum ConsensusChoice {
780 #[deprecated(note = "Mysticeti was replaced by Starfish")]
783 MysticetiDeprecated,
784 #[default]
785 Starfish,
786}
787
788#[expect(deprecated)]
789impl ConsensusChoice {
790 fn mysticeti_deprecated() -> Self {
797 ConsensusChoice::MysticetiDeprecated
798 }
799
800 pub fn is_mysticeti_deprecated(&self) -> bool {
801 matches!(self, ConsensusChoice::MysticetiDeprecated)
802 }
803 pub fn is_starfish(&self) -> bool {
804 matches!(self, ConsensusChoice::Starfish)
805 }
806}
807
808#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
810pub enum ConsensusNetwork {
811 #[default]
812 Tonic,
813}
814
815impl ConsensusNetwork {
816 pub fn is_tonic(&self) -> bool {
817 matches!(self, ConsensusNetwork::Tonic)
818 }
819}
820
821#[skip_serializing_none]
855#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
856pub struct ProtocolConfig {
857 pub version: ProtocolVersion,
858
859 feature_flags: FeatureFlags,
860
861 max_tx_size_bytes: Option<u64>,
866
867 max_input_objects: Option<u64>,
872
873 max_size_written_objects: Option<u64>,
878 max_size_written_objects_system_tx: Option<u64>,
882
883 max_serialized_tx_effects_size_bytes: Option<u64>,
885
886 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
888
889 max_gas_payment_objects: Option<u32>,
891
892 max_modules_in_publish: Option<u32>,
894
895 max_package_dependencies: Option<u32>,
897
898 max_arguments: Option<u32>,
901
902 max_type_arguments: Option<u32>,
904
905 max_type_argument_depth: Option<u32>,
907
908 max_pure_argument_size: Option<u32>,
910
911 max_programmable_tx_commands: Option<u32>,
913
914 move_binary_format_version: Option<u32>,
920 min_move_binary_format_version: Option<u32>,
921
922 binary_module_handles: Option<u16>,
924 binary_struct_handles: Option<u16>,
925 binary_function_handles: Option<u16>,
926 binary_function_instantiations: Option<u16>,
927 binary_signatures: Option<u16>,
928 binary_constant_pool: Option<u16>,
929 binary_identifiers: Option<u16>,
930 binary_address_identifiers: Option<u16>,
931 binary_struct_defs: Option<u16>,
932 binary_struct_def_instantiations: Option<u16>,
933 binary_function_defs: Option<u16>,
934 binary_field_handles: Option<u16>,
935 binary_field_instantiations: Option<u16>,
936 binary_friend_decls: Option<u16>,
937 binary_enum_defs: Option<u16>,
938 binary_enum_def_instantiations: Option<u16>,
939 binary_variant_handles: Option<u16>,
940 binary_variant_instantiation_handles: Option<u16>,
941
942 max_move_object_size: Option<u64>,
945
946 max_move_package_size: Option<u64>,
951
952 max_publish_or_upgrade_per_ptb: Option<u64>,
955
956 max_tx_gas: Option<u64>,
958
959 max_auth_gas: Option<u64>,
961
962 max_gas_price: Option<u64>,
965
966 max_gas_computation_bucket: Option<u64>,
969
970 gas_rounding_step: Option<u64>,
972
973 max_loop_depth: Option<u64>,
975
976 max_generic_instantiation_length: Option<u64>,
979
980 max_function_parameters: Option<u64>,
983
984 max_basic_blocks: Option<u64>,
987
988 max_value_stack_size: Option<u64>,
990
991 max_type_nodes: Option<u64>,
995
996 max_push_size: Option<u64>,
999
1000 max_struct_definitions: Option<u64>,
1003
1004 max_function_definitions: Option<u64>,
1007
1008 max_fields_in_struct: Option<u64>,
1011
1012 max_dependency_depth: Option<u64>,
1015
1016 max_num_event_emit: Option<u64>,
1019
1020 max_num_new_move_object_ids: Option<u64>,
1023
1024 max_num_new_move_object_ids_system_tx: Option<u64>,
1027
1028 max_num_deleted_move_object_ids: Option<u64>,
1031
1032 max_num_deleted_move_object_ids_system_tx: Option<u64>,
1035
1036 max_num_transferred_move_object_ids: Option<u64>,
1039
1040 max_num_transferred_move_object_ids_system_tx: Option<u64>,
1043
1044 max_event_emit_size: Option<u64>,
1046
1047 max_event_emit_size_total: Option<u64>,
1049
1050 max_move_vector_len: Option<u64>,
1053
1054 max_move_identifier_len: Option<u64>,
1057
1058 max_move_value_depth: Option<u64>,
1060
1061 max_move_enum_variants: Option<u64>,
1064
1065 max_back_edges_per_function: Option<u64>,
1074
1075 max_back_edges_per_module: Option<u64>,
1077
1078 max_verifier_meter_ticks_per_function: Option<u64>,
1080
1081 max_meter_ticks_per_module: Option<u64>,
1083
1084 max_meter_ticks_per_package: Option<u64>,
1086
1087 max_meter_ticks_regex_reference_safety: Option<u64>,
1091
1092 object_runtime_max_num_cached_objects: Option<u64>,
1099
1100 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
1103
1104 object_runtime_max_num_store_entries: Option<u64>,
1107
1108 object_runtime_max_num_store_entries_system_tx: Option<u64>,
1111
1112 base_tx_cost_fixed: Option<u64>,
1117
1118 package_publish_cost_fixed: Option<u64>,
1122
1123 base_tx_cost_per_byte: Option<u64>,
1127
1128 package_publish_cost_per_byte: Option<u64>,
1130
1131 obj_access_cost_read_per_byte: Option<u64>,
1133
1134 obj_access_cost_mutate_per_byte: Option<u64>,
1136
1137 obj_access_cost_delete_per_byte: Option<u64>,
1139
1140 obj_access_cost_verify_per_byte: Option<u64>,
1150
1151 max_type_to_layout_nodes: Option<u64>,
1153
1154 max_ptb_value_size: Option<u64>,
1156
1157 gas_model_version: Option<u64>,
1162
1163 obj_data_cost_refundable: Option<u64>,
1169
1170 obj_metadata_cost_non_refundable: Option<u64>,
1174
1175 storage_rebate_rate: Option<u64>,
1181
1182 reward_slashing_rate: Option<u64>,
1185
1186 storage_gas_price: Option<u64>,
1188
1189 base_gas_price: Option<u64>,
1191
1192 validator_target_reward: Option<u64>,
1194
1195 max_transactions_per_checkpoint: Option<u64>,
1202
1203 max_checkpoint_size_bytes: Option<u64>,
1207
1208 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
1214
1215 address_from_bytes_cost_base: Option<u64>,
1220 address_to_u256_cost_base: Option<u64>,
1222 address_from_u256_cost_base: Option<u64>,
1224
1225 config_read_setting_impl_cost_base: Option<u64>,
1230 config_read_setting_impl_cost_per_byte: Option<u64>,
1231
1232 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
1236 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
1237 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
1238 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
1239 dynamic_field_add_child_object_cost_base: Option<u64>,
1242 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
1243 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
1244 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
1245 dynamic_field_borrow_child_object_cost_base: Option<u64>,
1248 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1249 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1250 dynamic_field_remove_child_object_cost_base: Option<u64>,
1253 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1254 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1255 dynamic_field_has_child_object_cost_base: Option<u64>,
1258 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1261 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1262 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1263
1264 event_emit_cost_base: Option<u64>,
1267 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1268 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1269 event_emit_output_cost_per_byte: Option<u64>,
1270
1271 object_borrow_uid_cost_base: Option<u64>,
1274 object_delete_impl_cost_base: Option<u64>,
1276 object_record_new_uid_cost_base: Option<u64>,
1278
1279 transfer_transfer_internal_cost_base: Option<u64>,
1282 transfer_freeze_object_cost_base: Option<u64>,
1284 transfer_share_object_cost_base: Option<u64>,
1286 transfer_receive_object_cost_base: Option<u64>,
1289
1290 tx_context_derive_id_cost_base: Option<u64>,
1293 tx_context_fresh_id_cost_base: Option<u64>,
1294 tx_context_sender_cost_base: Option<u64>,
1295 tx_context_digest_cost_base: Option<u64>,
1296 tx_context_epoch_cost_base: Option<u64>,
1297 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1298 tx_context_sponsor_cost_base: Option<u64>,
1299 tx_context_rgp_cost_base: Option<u64>,
1300 tx_context_gas_price_cost_base: Option<u64>,
1301 tx_context_gas_budget_cost_base: Option<u64>,
1302 tx_context_ids_created_cost_base: Option<u64>,
1303 tx_context_replace_cost_base: Option<u64>,
1304
1305 types_is_one_time_witness_cost_base: Option<u64>,
1308 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1309 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1310
1311 validator_validate_metadata_cost_base: Option<u64>,
1314 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1315
1316 crypto_invalid_arguments_cost: Option<u64>,
1318 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1320 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1321 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1322
1323 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1325 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1326 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1327
1328 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1330 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1331 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1332 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1333 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1334 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1335
1336 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1338
1339 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1341 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1342 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1343 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1344 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1345 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1346
1347 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1349 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1350 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1351 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1352 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1353 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1354
1355 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1357 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1358 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1359 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1360 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1361 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1362
1363 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1365 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1366 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1367
1368 ed25519_ed25519_verify_cost_base: Option<u64>,
1370 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1371 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1372
1373 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1375 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1376
1377 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1379 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1380 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1381 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1382 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1383
1384 hash_blake2b256_cost_base: Option<u64>,
1386 hash_blake2b256_data_cost_per_byte: Option<u64>,
1387 hash_blake2b256_data_cost_per_block: Option<u64>,
1388
1389 hash_keccak256_cost_base: Option<u64>,
1391 hash_keccak256_data_cost_per_byte: Option<u64>,
1392 hash_keccak256_data_cost_per_block: Option<u64>,
1393
1394 poseidon_bn254_cost_base: Option<u64>,
1396 poseidon_bn254_cost_per_block: Option<u64>,
1397
1398 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1400 group_ops_bls12381_decode_g1_cost: Option<u64>,
1401 group_ops_bls12381_decode_g2_cost: Option<u64>,
1402 group_ops_bls12381_decode_gt_cost: Option<u64>,
1403 group_ops_bls12381_scalar_add_cost: Option<u64>,
1404 group_ops_bls12381_g1_add_cost: Option<u64>,
1405 group_ops_bls12381_g2_add_cost: Option<u64>,
1406 group_ops_bls12381_gt_add_cost: Option<u64>,
1407 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1408 group_ops_bls12381_g1_sub_cost: Option<u64>,
1409 group_ops_bls12381_g2_sub_cost: Option<u64>,
1410 group_ops_bls12381_gt_sub_cost: Option<u64>,
1411 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1412 group_ops_bls12381_g1_mul_cost: Option<u64>,
1413 group_ops_bls12381_g2_mul_cost: Option<u64>,
1414 group_ops_bls12381_gt_mul_cost: Option<u64>,
1415 group_ops_bls12381_scalar_div_cost: Option<u64>,
1416 group_ops_bls12381_g1_div_cost: Option<u64>,
1417 group_ops_bls12381_g2_div_cost: Option<u64>,
1418 group_ops_bls12381_gt_div_cost: Option<u64>,
1419 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1420 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1421 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1422 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1423 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1424 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1425 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1426 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1427 group_ops_bls12381_msm_max_len: Option<u32>,
1428 group_ops_bls12381_pairing_cost: Option<u64>,
1429 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1430 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1431 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1432 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1433 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1434
1435 hmac_hmac_sha3_256_cost_base: Option<u64>,
1437 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1438 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1439
1440 #[deprecated]
1442 check_zklogin_id_cost_base: Option<u64>,
1443 #[deprecated]
1445 check_zklogin_issuer_cost_base: Option<u64>,
1446
1447 vdf_verify_vdf_cost: Option<u64>,
1448 vdf_hash_to_input_cost: Option<u64>,
1449
1450 bcs_per_byte_serialized_cost: Option<u64>,
1452 bcs_legacy_min_output_size_cost: Option<u64>,
1453 bcs_failure_cost: Option<u64>,
1454
1455 hash_sha2_256_base_cost: Option<u64>,
1456 hash_sha2_256_per_byte_cost: Option<u64>,
1457 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1458 hash_sha3_256_base_cost: Option<u64>,
1459 hash_sha3_256_per_byte_cost: Option<u64>,
1460 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1461 type_name_get_base_cost: Option<u64>,
1462 type_name_get_per_byte_cost: Option<u64>,
1463
1464 string_check_utf8_base_cost: Option<u64>,
1465 string_check_utf8_per_byte_cost: Option<u64>,
1466 string_is_char_boundary_base_cost: Option<u64>,
1467 string_sub_string_base_cost: Option<u64>,
1468 string_sub_string_per_byte_cost: Option<u64>,
1469 string_index_of_base_cost: Option<u64>,
1470 string_index_of_per_byte_pattern_cost: Option<u64>,
1471 string_index_of_per_byte_searched_cost: Option<u64>,
1472
1473 vector_empty_base_cost: Option<u64>,
1474 vector_length_base_cost: Option<u64>,
1475 vector_push_back_base_cost: Option<u64>,
1476 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1477 vector_borrow_base_cost: Option<u64>,
1478 vector_pop_back_base_cost: Option<u64>,
1479 vector_destroy_empty_base_cost: Option<u64>,
1480 vector_swap_base_cost: Option<u64>,
1481 debug_print_base_cost: Option<u64>,
1482 debug_print_stack_trace_base_cost: Option<u64>,
1483
1484 execution_version: Option<u64>,
1486
1487 consensus_bad_nodes_stake_threshold: Option<u64>,
1491
1492 #[deprecated]
1493 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1494 #[deprecated]
1498 max_age_of_jwk_in_epochs: Option<u64>,
1499
1500 random_beacon_reduction_allowed_delta: Option<u16>,
1504
1505 random_beacon_reduction_lower_bound: Option<u32>,
1508
1509 random_beacon_dkg_timeout_round: Option<u32>,
1512
1513 random_beacon_min_round_interval_ms: Option<u64>,
1515
1516 random_beacon_dkg_version: Option<u64>,
1520
1521 consensus_max_transaction_size_bytes: Option<u64>,
1526 consensus_max_transactions_in_block_bytes: Option<u64>,
1528 consensus_max_num_transactions_in_block: Option<u64>,
1530
1531 max_deferral_rounds_for_congestion_control: Option<u64>,
1535
1536 min_checkpoint_interval_ms: Option<u64>,
1538
1539 checkpoint_rate_window_size: Option<u64>,
1549
1550 checkpoint_summary_version_specific_data: Option<u64>,
1552
1553 max_soft_bundle_size: Option<u64>,
1556
1557 bridge_should_try_to_finalize_committee: Option<bool>,
1562
1563 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1569
1570 max_committee_members_count: Option<u64>,
1574
1575 deny_rule_update_max_entries_per_tx: Option<u64>,
1580
1581 deny_rule_removal_grace_round_floor: Option<u64>,
1586
1587 consensus_gc_depth: Option<u32>,
1590
1591 consensus_max_acknowledgments_per_block: Option<u32>,
1597
1598 max_congestion_limit_overshoot_per_commit: Option<u64>,
1603
1604 max_concurrent_execution_workers: Option<u16>,
1611
1612 scorer_version: Option<u16>,
1621
1622 auth_context_digest_cost_base: Option<u64>,
1625 auth_context_tx_data_bytes_cost_base: Option<u64>,
1627 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1628 auth_context_tx_commands_cost_base: Option<u64>,
1630 auth_context_tx_commands_cost_per_byte: Option<u64>,
1631 auth_context_tx_inputs_cost_base: Option<u64>,
1633 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1634 auth_context_replace_cost_base: Option<u64>,
1637 auth_context_replace_cost_per_byte: Option<u64>,
1638 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1642
1643 consensus_commits_per_schedule: Option<u32>,
1646
1647 min_validator_count: Option<u64>,
1650
1651 max_validator_count: Option<u64>,
1655
1656 min_validator_joining_stake: Option<u64>,
1660
1661 validator_low_stake_threshold: Option<u64>,
1666
1667 validator_very_low_stake_threshold: Option<u64>,
1671
1672 validator_low_stake_grace_period: Option<u64>,
1676
1677 consensus_leader_schedule_window_size: Option<u32>,
1681
1682 max_move_system_package_size: Option<u64>,
1687}
1688
1689impl ProtocolConfig {
1691 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1704 self.feature_flags
1705 .disable_invariant_violation_check_in_swap_loc
1706 }
1707
1708 pub fn no_extraneous_module_bytes(&self) -> bool {
1709 self.feature_flags.no_extraneous_module_bytes
1710 }
1711
1712 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1713 self.feature_flags.consensus_transaction_ordering
1714 }
1715
1716 pub fn dkg_version(&self) -> u64 {
1717 self.random_beacon_dkg_version.unwrap_or(1)
1719 }
1720
1721 pub fn hardened_otw_check(&self) -> bool {
1722 self.feature_flags.hardened_otw_check
1723 }
1724
1725 pub fn enable_poseidon(&self) -> bool {
1726 self.feature_flags.enable_poseidon
1727 }
1728
1729 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1730 self.feature_flags.enable_group_ops_native_function_msm
1731 }
1732
1733 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1734 self.feature_flags.per_object_congestion_control_mode
1735 }
1736
1737 pub fn consensus_choice(&self) -> ConsensusChoice {
1738 self.feature_flags.consensus_choice
1739 }
1740
1741 pub fn consensus_network(&self) -> ConsensusNetwork {
1742 self.feature_flags.consensus_network
1743 }
1744
1745 pub fn enable_vdf(&self) -> bool {
1746 self.feature_flags.enable_vdf
1747 }
1748
1749 pub fn passkey_auth(&self) -> bool {
1750 self.feature_flags.passkey_auth
1751 }
1752
1753 pub fn max_transaction_size_bytes(&self) -> u64 {
1754 self.consensus_max_transaction_size_bytes
1756 .unwrap_or(256 * 1024)
1757 }
1758
1759 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1760 if cfg!(msim) {
1761 256 * 1024
1762 } else {
1763 self.consensus_max_transactions_in_block_bytes
1764 .unwrap_or(512 * 1024)
1765 }
1766 }
1767
1768 pub fn max_num_transactions_in_block(&self) -> u64 {
1769 if cfg!(msim) {
1770 8
1771 } else {
1772 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1773 }
1774 }
1775
1776 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1777 self.feature_flags.rethrow_serialization_type_layout_errors
1778 }
1779
1780 pub fn relocate_event_module(&self) -> bool {
1781 self.feature_flags.relocate_event_module
1782 }
1783
1784 pub fn protocol_defined_base_fee(&self) -> bool {
1785 self.feature_flags.protocol_defined_base_fee
1786 }
1787
1788 pub fn uncompressed_g1_group_elements(&self) -> bool {
1789 self.feature_flags.uncompressed_g1_group_elements
1790 }
1791
1792 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1793 self.feature_flags
1794 .disallow_new_modules_in_deps_only_packages
1795 }
1796
1797 pub fn native_charging_v2(&self) -> bool {
1798 self.feature_flags.native_charging_v2
1799 }
1800
1801 pub fn consensus_round_prober(&self) -> bool {
1802 self.feature_flags.consensus_round_prober
1803 }
1804
1805 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1806 self.feature_flags
1807 .consensus_distributed_vote_scoring_strategy
1808 }
1809
1810 pub fn gc_depth(&self) -> u32 {
1811 if cfg!(msim) {
1812 min(5, self.consensus_gc_depth.unwrap_or(0))
1814 } else {
1815 self.consensus_gc_depth.unwrap_or(0)
1816 }
1817 }
1818
1819 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1820 let res = self.feature_flags.consensus_linearize_subdag_v2;
1821 assert!(
1822 !res || self.gc_depth() > 0,
1823 "The consensus linearize sub dag V2 requires GC to be enabled"
1824 );
1825 res
1826 }
1827
1828 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1829 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1830 }
1831
1832 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1833 2 * committee_size
1834 }
1835
1836 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1837 committee_size
1838 }
1839
1840 pub fn variant_nodes(&self) -> bool {
1841 self.feature_flags.variant_nodes
1842 }
1843
1844 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1845 self.feature_flags.consensus_smart_ancestor_selection
1846 }
1847
1848 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1849 self.feature_flags
1850 .consensus_round_prober_probe_accepted_rounds
1851 }
1852
1853 pub fn consensus_zstd_compression(&self) -> bool {
1854 self.feature_flags.consensus_zstd_compression
1855 }
1856
1857 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1858 self.feature_flags
1859 .congestion_control_min_free_execution_slot
1860 }
1861
1862 pub fn accept_passkey_in_multisig(&self) -> bool {
1863 self.feature_flags.accept_passkey_in_multisig
1864 }
1865
1866 pub fn consensus_batched_block_sync(&self) -> bool {
1867 self.feature_flags.consensus_batched_block_sync
1868 }
1869
1870 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1873 self.feature_flags
1874 .congestion_control_gas_price_feedback_mechanism
1875 }
1876
1877 pub fn validate_identifier_inputs(&self) -> bool {
1878 self.feature_flags.validate_identifier_inputs
1879 }
1880
1881 pub fn minimize_child_object_mutations(&self) -> bool {
1882 self.feature_flags.minimize_child_object_mutations
1883 }
1884
1885 pub fn dependency_linkage_error(&self) -> bool {
1886 self.feature_flags.dependency_linkage_error
1887 }
1888
1889 pub fn additional_multisig_checks(&self) -> bool {
1890 self.feature_flags.additional_multisig_checks
1891 }
1892
1893 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1894 0
1897 }
1898
1899 pub fn normalize_ptb_arguments(&self) -> bool {
1900 self.feature_flags.normalize_ptb_arguments
1901 }
1902
1903 pub fn select_committee_from_eligible_validators(&self) -> bool {
1904 let res = self.feature_flags.select_committee_from_eligible_validators;
1905 assert!(
1906 !res || (self.protocol_defined_base_fee()
1907 && self.max_committee_members_count_as_option().is_some()),
1908 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1909 );
1910 res
1911 }
1912
1913 pub fn track_non_committee_eligible_validators(&self) -> bool {
1914 self.feature_flags.track_non_committee_eligible_validators
1915 }
1916
1917 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1918 let res = self
1919 .feature_flags
1920 .select_committee_supporting_next_epoch_version;
1921 assert!(
1922 !res || (self.track_non_committee_eligible_validators()
1923 && self.select_committee_from_eligible_validators()),
1924 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1925 );
1926 res
1927 }
1928
1929 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1930 let res = self
1931 .feature_flags
1932 .consensus_median_timestamp_with_checkpoint_enforcement;
1933 assert!(
1934 !res || self.gc_depth() > 0,
1935 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1936 );
1937 res
1938 }
1939
1940 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1941 self.feature_flags
1942 .consensus_commit_transactions_only_for_traversed_headers
1943 }
1944
1945 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1948 self.feature_flags
1949 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1950 }
1951
1952 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1955 self.feature_flags
1956 .separate_gas_price_feedback_mechanism_for_randomness
1957 }
1958
1959 pub fn metadata_in_module_bytes(&self) -> bool {
1960 self.feature_flags.metadata_in_module_bytes
1961 }
1962
1963 pub fn publish_package_metadata(&self) -> bool {
1964 self.feature_flags.publish_package_metadata
1965 }
1966
1967 pub fn enable_move_authentication(&self) -> bool {
1968 self.feature_flags.enable_move_authentication
1969 }
1970
1971 pub fn additional_borrow_checks(&self) -> bool {
1972 self.feature_flags.additional_borrow_checks
1973 }
1974
1975 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1976 let enable_move_authentication_for_sponsor =
1977 self.feature_flags.enable_move_authentication_for_sponsor;
1978 assert!(
1979 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1980 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1981 );
1982 enable_move_authentication_for_sponsor
1983 }
1984
1985 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1986 self.feature_flags.pass_validator_scores_to_advance_epoch
1987 }
1988
1989 pub fn calculate_validator_scores(&self) -> bool {
1990 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1991 assert!(
1992 !calculate_validator_scores || self.scorer_version.is_some(),
1993 "calculate_validator_scores requires scorer_version to be set"
1994 );
1995 calculate_validator_scores
1996 }
1997
1998 pub fn adjust_rewards_by_score(&self) -> bool {
1999 let adjust = self.feature_flags.adjust_rewards_by_score;
2000 assert!(
2001 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
2002 "adjust_rewards_by_score requires scorer_version to be set"
2003 );
2004 adjust
2005 }
2006
2007 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
2008 let pass = self
2009 .feature_flags
2010 .pass_calculated_validator_scores_to_advance_epoch;
2011 assert!(
2012 !pass
2013 || (self.pass_validator_scores_to_advance_epoch()
2014 && self.calculate_validator_scores()),
2015 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
2016 );
2017 pass
2018 }
2019 pub fn consensus_fast_commit_sync(&self) -> bool {
2020 let res = self.feature_flags.consensus_fast_commit_sync;
2021 assert!(
2022 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
2023 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
2024 );
2025 res
2026 }
2027
2028 pub fn consensus_block_restrictions(&self) -> bool {
2029 self.feature_flags.consensus_block_restrictions
2030 }
2031
2032 pub fn move_native_tx_context(&self) -> bool {
2033 self.feature_flags.move_native_tx_context
2034 }
2035
2036 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
2037 let pre_consensus_sponsor_only_move_authentication = self
2038 .feature_flags
2039 .pre_consensus_sponsor_only_move_authentication;
2040 if pre_consensus_sponsor_only_move_authentication {
2041 assert!(
2042 self.enable_move_authentication(),
2043 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
2044 );
2045 assert!(
2046 self.enable_move_authentication_for_sponsor(),
2047 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
2048 );
2049 }
2050 pre_consensus_sponsor_only_move_authentication
2051 }
2052
2053 pub fn consensus_starfish_speed(&self) -> bool {
2054 let res = self.feature_flags.consensus_starfish_speed;
2055 assert!(
2056 !res || self.consensus_fast_commit_sync(),
2057 "consensus_starfish_speed requires consensus_fast_commit_sync to be enabled"
2058 );
2059 res
2060 }
2061
2062 pub fn always_advance_dkg_to_resolution(&self) -> bool {
2063 self.feature_flags.always_advance_dkg_to_resolution
2064 }
2065
2066 pub fn enable_pcool_flow(&self) -> bool {
2067 self.feature_flags.enable_pcool_flow
2068 }
2069
2070 pub fn pcool_skip_immutable_object_locks(&self) -> bool {
2071 self.feature_flags.pcool_skip_immutable_object_locks
2072 }
2073
2074 pub fn pcool_verifier_limits_from_protocol_config(&self) -> bool {
2077 self.feature_flags
2078 .pcool_verifier_limits_from_protocol_config
2079 }
2080
2081 pub fn validator_metadata_verify_v2(&self) -> bool {
2082 self.feature_flags.validator_metadata_verify_v2
2083 }
2084
2085 pub fn commits_per_schedule(&self) -> u32 {
2086 let commits_per_schedule = if cfg!(msim) {
2087 min(10, self.consensus_commits_per_schedule.unwrap_or(300))
2089 } else {
2090 self.consensus_commits_per_schedule.unwrap_or(300)
2091 };
2092 assert!(
2093 commits_per_schedule > 0,
2094 "consensus_commits_per_schedule must be greater than 0"
2095 );
2096 commits_per_schedule
2097 }
2098
2099 pub fn leader_schedule_window_size(&self) -> u32 {
2100 if cfg!(msim) {
2101 min(
2104 20,
2105 self.consensus_leader_schedule_window_size.unwrap_or(600),
2106 )
2107 } else {
2108 self.consensus_leader_schedule_window_size.unwrap_or(600)
2109 }
2110 }
2111
2112 pub fn consensus_enable_sliding_window_leader_schedule(&self) -> bool {
2113 let res = self
2114 .feature_flags
2115 .consensus_enable_sliding_window_leader_schedule;
2116 assert!(
2117 !res || self.leader_schedule_window_size() >= self.commits_per_schedule(),
2118 "consensus_enable_sliding_window_leader_schedule requires window_size >= commits_per_schedule"
2119 );
2120 res
2121 }
2122
2123 pub fn consensus_enable_absolute_score_leader_schedule(&self) -> bool {
2124 self.feature_flags
2125 .consensus_enable_absolute_score_leader_schedule
2126 }
2127
2128 pub fn max_ptb_value_size_v2(&self) -> bool {
2129 self.feature_flags.max_ptb_value_size_v2
2130 }
2131
2132 pub fn deny_rule_governance(&self) -> bool {
2133 self.feature_flags.deny_rule_governance
2134 }
2135
2136 pub fn deny_rule_governance_on_chain(&self) -> bool {
2137 self.feature_flags.deny_rule_governance_on_chain
2138 }
2139
2140 pub fn deny_authenticator_packages(&self) -> bool {
2141 self.feature_flags.deny_authenticator_packages
2142 }
2143
2144 pub fn package_metadata_with_dynamic_module_metadata(&self) -> bool {
2145 let res = self
2146 .feature_flags
2147 .package_metadata_with_dynamic_module_metadata;
2148 assert!(
2149 !res || self.publish_package_metadata(),
2150 "package_metadata_with_dynamic_module_metadata requires publish_package_metadata to be enabled"
2151 );
2152 res
2153 }
2154
2155 pub fn report_move_authentication_error(&self) -> bool {
2156 let report_move_authentication_error = self.feature_flags.report_move_authentication_error;
2157 assert!(
2158 !report_move_authentication_error || self.enable_move_authentication(),
2159 "report_move_authentication_error requires enable_move_authentication to be set"
2160 );
2161 report_move_authentication_error
2162 }
2163
2164 pub fn concurrent_execution_workers(&self) -> Option<u16> {
2168 let res = self.max_concurrent_execution_workers;
2169 assert!(
2170 res.is_none() || self.enable_pcool_flow(),
2171 "max_concurrent_execution_workers requires enable_pcool_flow to be enabled"
2172 );
2173 assert!(
2174 res.is_none()
2175 || self
2176 .max_accumulated_txn_cost_per_object_in_mysticeti_commit
2177 .is_some(),
2178 "max_concurrent_execution_workers requires per-object congestion control \
2179 (max_accumulated_txn_cost_per_object_in_mysticeti_commit) to be enabled"
2180 );
2181 assert!(
2182 res.is_none() || self.congestion_control_gas_price_feedback_mechanism(),
2183 "max_concurrent_execution_workers requires the gas price feedback mechanism \
2184 (congestion_control_gas_price_feedback_mechanism), which carries the suggested \
2185 gas price of an execution-worker congestion cancellation"
2186 );
2187 assert!(
2188 res.is_none() || !self.separate_gas_price_feedback_mechanism_for_randomness(),
2189 "max_concurrent_execution_workers implies a single congestion tracker and suggested \
2190 gas price calculator for all transactions, which is incompatible with \
2191 separate_gas_price_feedback_mechanism_for_randomness"
2192 );
2193 assert!(
2194 res != Some(0),
2195 "max_concurrent_execution_workers must be positive when set"
2196 );
2197 res
2198 }
2199
2200 pub fn allow_unbounded_system_objects(&self) -> bool {
2201 self.feature_flags.allow_unbounded_system_objects
2202 }
2203
2204 pub fn reject_immutable_account_objects(&self) -> bool {
2205 let reject_immutable_account_objects = self.feature_flags.reject_immutable_account_objects;
2206 assert!(
2207 !reject_immutable_account_objects || self.enable_move_authentication(),
2208 "reject_immutable_account_objects requires enable_move_authentication to be set"
2209 );
2210 reject_immutable_account_objects
2211 }
2212
2213 pub fn reject_immutable_account_creation(&self) -> bool {
2214 let reject_immutable_account_creation =
2215 self.feature_flags.reject_immutable_account_creation;
2216 assert!(
2217 !reject_immutable_account_creation || self.reject_immutable_account_objects(),
2218 "reject_immutable_account_creation requires reject_immutable_account_objects to be set"
2219 );
2220 reject_immutable_account_creation
2221 }
2222
2223 pub fn validate_input_object_versions(&self) -> bool {
2224 self.feature_flags.validate_input_object_versions
2225 }
2226
2227 pub fn check_canonical_module_version_header(&self) -> bool {
2228 self.feature_flags.check_canonical_module_version_header
2229 }
2230
2231 pub fn disallow_randomness_in_move_authenticator(&self) -> bool {
2232 self.feature_flags.disallow_randomness_in_move_authenticator
2233 }
2234
2235 pub fn check_cyclic_dependencies(&self) -> bool {
2236 self.feature_flags.check_cyclic_dependencies
2237 }
2238
2239 pub fn deprecate_global_storage_ops_during_deserialization(&self) -> bool {
2240 self.feature_flags
2241 .deprecate_global_storage_ops_during_deserialization
2242 }
2243}
2244
2245#[cfg(not(msim))]
2246static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2247
2248#[cfg(msim)]
2250thread_local! {
2251 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2252}
2253
2254impl ProtocolConfig {
2256 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
2259 assert!(
2261 version >= ProtocolVersion::MIN,
2262 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
2263 version,
2264 ProtocolVersion::MIN.0,
2265 );
2266 assert!(
2267 version <= ProtocolVersion::MAX_ALLOWED,
2268 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
2269 version,
2270 ProtocolVersion::MAX_ALLOWED.0,
2271 );
2272
2273 let mut ret = Self::get_for_version_impl(version, chain);
2274 ret.version = version;
2275
2276 ret = CONFIG_OVERRIDE.with(|ovr| {
2277 if let Some(override_fn) = &*ovr.borrow() {
2278 warn!(
2279 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
2280 );
2281 override_fn(version, ret)
2282 } else {
2283 ret
2284 }
2285 });
2286
2287 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
2288 warn!(
2289 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
2290 );
2291
2292 let overrides: ProtocolConfigOptional =
2294 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
2295 .expect("failed to parse ProtocolConfig override env variables");
2296 overrides.apply_to(&mut ret);
2297
2298 let feature_flag_overrides: FeatureFlagsOptional =
2300 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_FEATURE_FLAGS_OVERRIDE")
2301 .expect("failed to parse ProtocolConfig feature flags override env variables");
2302
2303 feature_flag_overrides.apply_to(&mut ret.feature_flags);
2304 }
2305
2306 assert!(
2308 !ret.feature_flags.deny_rule_governance_on_chain
2309 || ret.feature_flags.deny_rule_governance,
2310 "deny_rule_governance_on_chain requires deny_rule_governance"
2311 );
2312 assert!(
2317 !ret.feature_flags.pcool_verifier_limits_from_protocol_config
2318 || ret.max_meter_ticks_regex_reference_safety.is_some(),
2319 "pcool_verifier_limits_from_protocol_config requires \
2320 max_meter_ticks_regex_reference_safety"
2321 );
2322 assert!(
2325 !ret.feature_flags.deny_rule_governance_on_chain
2326 || (ret.deny_rule_update_max_entries_per_tx.is_some()
2327 && ret.deny_rule_removal_grace_round_floor.is_some()),
2328 "deny_rule_governance_on_chain requires deny_rule_update_max_entries_per_tx and deny_rule_removal_grace_round_floor"
2329 );
2330 const DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING: u64 = 2048;
2338 assert!(
2339 ret.deny_rule_update_max_entries_per_tx
2340 .is_none_or(|max_entries| {
2341 max_entries > 0
2342 && max_entries <= DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING
2343 && [
2344 ret.max_num_new_move_object_ids_system_tx,
2345 ret.max_num_deleted_move_object_ids_system_tx,
2346 ret.object_runtime_max_num_cached_objects_system_tx,
2347 ret.object_runtime_max_num_store_entries_system_tx,
2348 ]
2349 .iter()
2350 .all(|limit| limit.is_none_or(|limit| max_entries <= limit))
2351 }),
2352 "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"
2353 );
2354
2355 ret
2356 }
2357
2358 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
2361 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
2362 let mut ret = Self::get_for_version_impl(version, chain);
2363 ret.version = version;
2364 Some(ret)
2365 } else {
2366 None
2367 }
2368 }
2369
2370 #[cfg(not(msim))]
2371 pub fn poison_get_for_min_version() {
2372 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
2373 }
2374
2375 #[cfg(not(msim))]
2376 fn load_poison_get_for_min_version() -> bool {
2377 POISON_VERSION_METHODS.load(Ordering::Relaxed)
2378 }
2379
2380 #[cfg(msim)]
2381 pub fn poison_get_for_min_version() {
2382 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
2383 }
2384
2385 #[cfg(msim)]
2386 fn load_poison_get_for_min_version() -> bool {
2387 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
2388 }
2389
2390 pub fn convert_type_argument_error(&self) -> bool {
2391 self.feature_flags.convert_type_argument_error
2392 }
2393
2394 pub fn get_for_min_version() -> Self {
2398 if Self::load_poison_get_for_min_version() {
2399 panic!("get_for_min_version called on validator");
2400 }
2401 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
2402 }
2403
2404 #[expect(non_snake_case)]
2415 pub fn get_for_max_version_UNSAFE() -> Self {
2416 if Self::load_poison_get_for_min_version() {
2417 panic!("get_for_max_version_UNSAFE called on validator");
2418 }
2419 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
2420 }
2421
2422 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
2423 #[cfg(msim)]
2424 {
2425 if version > ProtocolVersion::MAX {
2427 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
2428 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
2429 return config;
2430 }
2431 }
2432
2433 let mut cfg = Self {
2437 version,
2438
2439 feature_flags: Default::default(),
2440
2441 max_tx_size_bytes: Some(128 * 1024),
2442 max_input_objects: Some(2048),
2445 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
2446 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
2447 max_gas_payment_objects: Some(256),
2448 max_modules_in_publish: Some(64),
2449 max_package_dependencies: Some(32),
2450 max_arguments: Some(512),
2451 max_type_arguments: Some(16),
2452 max_type_argument_depth: Some(16),
2453 max_pure_argument_size: Some(16 * 1024),
2454 max_programmable_tx_commands: Some(1024),
2455 move_binary_format_version: Some(7),
2456 min_move_binary_format_version: Some(6),
2457 binary_module_handles: Some(100),
2458 binary_struct_handles: Some(300),
2459 binary_function_handles: Some(1500),
2460 binary_function_instantiations: Some(750),
2461 binary_signatures: Some(1000),
2462 binary_constant_pool: Some(4000),
2463 binary_identifiers: Some(10000),
2464 binary_address_identifiers: Some(100),
2465 binary_struct_defs: Some(200),
2466 binary_struct_def_instantiations: Some(100),
2467 binary_function_defs: Some(1000),
2468 binary_field_handles: Some(500),
2469 binary_field_instantiations: Some(250),
2470 binary_friend_decls: Some(100),
2471 binary_enum_defs: None,
2472 binary_enum_def_instantiations: None,
2473 binary_variant_handles: None,
2474 binary_variant_instantiation_handles: None,
2475 max_move_object_size: Some(250 * 1024),
2476 max_move_package_size: Some(100 * 1024),
2477 max_publish_or_upgrade_per_ptb: Some(5),
2478 max_auth_gas: None,
2480 max_tx_gas: Some(50_000_000_000),
2482 max_gas_price: Some(100_000),
2483 max_gas_computation_bucket: Some(5_000_000),
2484 max_loop_depth: Some(5),
2485 max_generic_instantiation_length: Some(32),
2486 max_function_parameters: Some(128),
2487 max_basic_blocks: Some(1024),
2488 max_value_stack_size: Some(1024),
2489 max_type_nodes: Some(256),
2490 max_push_size: Some(10000),
2491 max_struct_definitions: Some(200),
2492 max_function_definitions: Some(1000),
2493 max_fields_in_struct: Some(32),
2494 max_dependency_depth: Some(100),
2495 max_num_event_emit: Some(1024),
2496 max_num_new_move_object_ids: Some(2048),
2497 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
2498 max_num_deleted_move_object_ids: Some(2048),
2499 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
2500 max_num_transferred_move_object_ids: Some(2048),
2501 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
2502 max_event_emit_size: Some(250 * 1024),
2503 max_move_vector_len: Some(256 * 1024),
2504 max_type_to_layout_nodes: None,
2505 max_ptb_value_size: None,
2506
2507 max_back_edges_per_function: Some(10_000),
2508 max_back_edges_per_module: Some(10_000),
2509
2510 max_verifier_meter_ticks_per_function: Some(16_000_000),
2511
2512 max_meter_ticks_per_module: Some(16_000_000),
2513 max_meter_ticks_per_package: Some(16_000_000),
2514 max_meter_ticks_regex_reference_safety: None,
2515
2516 object_runtime_max_num_cached_objects: Some(1000),
2517 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2518 object_runtime_max_num_store_entries: Some(1000),
2519 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2520 base_tx_cost_fixed: Some(1_000),
2522 package_publish_cost_fixed: Some(1_000),
2523 base_tx_cost_per_byte: Some(0),
2524 package_publish_cost_per_byte: Some(80),
2525 obj_access_cost_read_per_byte: Some(15),
2526 obj_access_cost_mutate_per_byte: Some(40),
2527 obj_access_cost_delete_per_byte: Some(40),
2528 obj_access_cost_verify_per_byte: Some(200),
2529 obj_data_cost_refundable: Some(100),
2530 obj_metadata_cost_non_refundable: Some(50),
2531 gas_model_version: Some(1),
2532 storage_rebate_rate: Some(10000),
2533 reward_slashing_rate: Some(10000),
2535 storage_gas_price: Some(76),
2536 base_gas_price: None,
2537 validator_target_reward: Some(767_000 * 1_000_000_000),
2540 max_transactions_per_checkpoint: Some(10_000),
2541 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2542
2543 buffer_stake_for_protocol_upgrade_bps: Some(5000),
2545
2546 address_from_bytes_cost_base: Some(52),
2550 address_to_u256_cost_base: Some(52),
2552 address_from_u256_cost_base: Some(52),
2554
2555 config_read_setting_impl_cost_base: Some(100),
2558 config_read_setting_impl_cost_per_byte: Some(40),
2559
2560 dynamic_field_hash_type_and_key_cost_base: Some(100),
2564 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
2565 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
2566 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
2567 dynamic_field_add_child_object_cost_base: Some(100),
2570 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2571 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2572 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2573 dynamic_field_borrow_child_object_cost_base: Some(100),
2576 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2577 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2578 dynamic_field_remove_child_object_cost_base: Some(100),
2581 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2582 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2583 dynamic_field_has_child_object_cost_base: Some(100),
2586 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2589 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2590 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2591
2592 event_emit_cost_base: Some(52),
2595 event_emit_value_size_derivation_cost_per_byte: Some(2),
2596 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2597 event_emit_output_cost_per_byte: Some(10),
2598
2599 object_borrow_uid_cost_base: Some(52),
2602 object_delete_impl_cost_base: Some(52),
2604 object_record_new_uid_cost_base: Some(52),
2606
2607 transfer_transfer_internal_cost_base: Some(52),
2611 transfer_freeze_object_cost_base: Some(52),
2613 transfer_share_object_cost_base: Some(52),
2615 transfer_receive_object_cost_base: Some(52),
2616
2617 tx_context_derive_id_cost_base: Some(52),
2621 tx_context_fresh_id_cost_base: None,
2622 tx_context_sender_cost_base: None,
2623 tx_context_digest_cost_base: None,
2624 tx_context_epoch_cost_base: None,
2625 tx_context_epoch_timestamp_ms_cost_base: None,
2626 tx_context_sponsor_cost_base: None,
2627 tx_context_rgp_cost_base: None,
2628 tx_context_gas_price_cost_base: None,
2629 tx_context_gas_budget_cost_base: None,
2630 tx_context_ids_created_cost_base: None,
2631 tx_context_replace_cost_base: None,
2632
2633 types_is_one_time_witness_cost_base: Some(52),
2636 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2637 types_is_one_time_witness_type_cost_per_byte: Some(2),
2638
2639 validator_validate_metadata_cost_base: Some(52),
2643 validator_validate_metadata_data_cost_per_byte: Some(2),
2644
2645 crypto_invalid_arguments_cost: Some(100),
2647 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2649 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2650 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2651
2652 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2654 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2655 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2656
2657 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2659 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2660 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2661 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2662 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2663 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2664
2665 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2667
2668 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2670 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2671 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2672 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2673 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2674 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2675
2676 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2678 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2679 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2680 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2681 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2682 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2683
2684 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2686 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2687 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2688 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2689 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2690 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2691
2692 ecvrf_ecvrf_verify_cost_base: Some(52),
2694 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2695 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2696
2697 ed25519_ed25519_verify_cost_base: Some(52),
2699 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2700 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2701
2702 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2704 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2705
2706 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2708 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2709 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2710 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2711 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2712
2713 hash_blake2b256_cost_base: Some(52),
2715 hash_blake2b256_data_cost_per_byte: Some(2),
2716 hash_blake2b256_data_cost_per_block: Some(2),
2717 hash_keccak256_cost_base: Some(52),
2719 hash_keccak256_data_cost_per_byte: Some(2),
2720 hash_keccak256_data_cost_per_block: Some(2),
2721
2722 poseidon_bn254_cost_base: None,
2723 poseidon_bn254_cost_per_block: None,
2724
2725 hmac_hmac_sha3_256_cost_base: Some(52),
2727 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2728 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2729
2730 group_ops_bls12381_decode_scalar_cost: Some(52),
2732 group_ops_bls12381_decode_g1_cost: Some(52),
2733 group_ops_bls12381_decode_g2_cost: Some(52),
2734 group_ops_bls12381_decode_gt_cost: Some(52),
2735 group_ops_bls12381_scalar_add_cost: Some(52),
2736 group_ops_bls12381_g1_add_cost: Some(52),
2737 group_ops_bls12381_g2_add_cost: Some(52),
2738 group_ops_bls12381_gt_add_cost: Some(52),
2739 group_ops_bls12381_scalar_sub_cost: Some(52),
2740 group_ops_bls12381_g1_sub_cost: Some(52),
2741 group_ops_bls12381_g2_sub_cost: Some(52),
2742 group_ops_bls12381_gt_sub_cost: Some(52),
2743 group_ops_bls12381_scalar_mul_cost: Some(52),
2744 group_ops_bls12381_g1_mul_cost: Some(52),
2745 group_ops_bls12381_g2_mul_cost: Some(52),
2746 group_ops_bls12381_gt_mul_cost: Some(52),
2747 group_ops_bls12381_scalar_div_cost: Some(52),
2748 group_ops_bls12381_g1_div_cost: Some(52),
2749 group_ops_bls12381_g2_div_cost: Some(52),
2750 group_ops_bls12381_gt_div_cost: Some(52),
2751 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2752 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2753 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2754 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2755 group_ops_bls12381_g1_msm_base_cost: Some(52),
2756 group_ops_bls12381_g2_msm_base_cost: Some(52),
2757 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2758 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2759 group_ops_bls12381_msm_max_len: Some(32),
2760 group_ops_bls12381_pairing_cost: Some(52),
2761 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2762 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2763 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2764 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2765 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2766
2767 #[allow(deprecated)]
2769 check_zklogin_id_cost_base: Some(200),
2770 #[allow(deprecated)]
2771 check_zklogin_issuer_cost_base: Some(200),
2773
2774 vdf_verify_vdf_cost: None,
2775 vdf_hash_to_input_cost: None,
2776
2777 bcs_per_byte_serialized_cost: Some(2),
2778 bcs_legacy_min_output_size_cost: Some(1),
2779 bcs_failure_cost: Some(52),
2780 hash_sha2_256_base_cost: Some(52),
2781 hash_sha2_256_per_byte_cost: Some(2),
2782 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2783 hash_sha3_256_base_cost: Some(52),
2784 hash_sha3_256_per_byte_cost: Some(2),
2785 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2786 type_name_get_base_cost: Some(52),
2787 type_name_get_per_byte_cost: Some(2),
2788 string_check_utf8_base_cost: Some(52),
2789 string_check_utf8_per_byte_cost: Some(2),
2790 string_is_char_boundary_base_cost: Some(52),
2791 string_sub_string_base_cost: Some(52),
2792 string_sub_string_per_byte_cost: Some(2),
2793 string_index_of_base_cost: Some(52),
2794 string_index_of_per_byte_pattern_cost: Some(2),
2795 string_index_of_per_byte_searched_cost: Some(2),
2796 vector_empty_base_cost: Some(52),
2797 vector_length_base_cost: Some(52),
2798 vector_push_back_base_cost: Some(52),
2799 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2800 vector_borrow_base_cost: Some(52),
2801 vector_pop_back_base_cost: Some(52),
2802 vector_destroy_empty_base_cost: Some(52),
2803 vector_swap_base_cost: Some(52),
2804 debug_print_base_cost: Some(52),
2805 debug_print_stack_trace_base_cost: Some(52),
2806
2807 max_size_written_objects: Some(5 * 1000 * 1000),
2808 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2811
2812 max_move_identifier_len: Some(128),
2814 max_move_value_depth: Some(128),
2815 max_move_enum_variants: None,
2816
2817 gas_rounding_step: Some(1_000),
2818
2819 execution_version: Some(1),
2820
2821 max_event_emit_size_total: Some(
2824 256 * 250 * 1024, ),
2826
2827 consensus_bad_nodes_stake_threshold: Some(20),
2834
2835 #[allow(deprecated)]
2837 max_jwk_votes_per_validator_per_epoch: Some(240),
2838
2839 #[allow(deprecated)]
2840 max_age_of_jwk_in_epochs: Some(1),
2841
2842 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2846
2847 random_beacon_reduction_allowed_delta: Some(800),
2848
2849 random_beacon_reduction_lower_bound: Some(1000),
2850 random_beacon_dkg_timeout_round: Some(3000),
2851 random_beacon_min_round_interval_ms: Some(500),
2852
2853 random_beacon_dkg_version: Some(1),
2854
2855 consensus_max_num_transactions_in_block: Some(512),
2859
2860 max_deferral_rounds_for_congestion_control: Some(10),
2861
2862 min_checkpoint_interval_ms: Some(200),
2863
2864 checkpoint_rate_window_size: None,
2865
2866 checkpoint_summary_version_specific_data: Some(1),
2867
2868 max_soft_bundle_size: Some(5),
2869
2870 bridge_should_try_to_finalize_committee: None,
2871
2872 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2873
2874 max_committee_members_count: None,
2875 deny_rule_update_max_entries_per_tx: None,
2876 deny_rule_removal_grace_round_floor: None,
2877
2878 consensus_gc_depth: None,
2879
2880 consensus_max_acknowledgments_per_block: None,
2881
2882 max_congestion_limit_overshoot_per_commit: None,
2883
2884 max_concurrent_execution_workers: None,
2885
2886 scorer_version: None,
2887
2888 auth_context_digest_cost_base: None,
2890 auth_context_tx_data_bytes_cost_base: None,
2891 auth_context_tx_data_bytes_cost_per_byte: None,
2892 auth_context_tx_commands_cost_base: None,
2893 auth_context_tx_commands_cost_per_byte: None,
2894 auth_context_tx_inputs_cost_base: None,
2895 auth_context_tx_inputs_cost_per_byte: None,
2896 auth_context_replace_cost_base: None,
2897 auth_context_replace_cost_per_byte: None,
2898 auth_context_authenticator_function_info_v1_cost_base: None,
2899 consensus_commits_per_schedule: None,
2900 min_validator_count: None,
2901 max_validator_count: None,
2902 min_validator_joining_stake: None,
2903 validator_low_stake_threshold: None,
2904 validator_very_low_stake_threshold: None,
2905 validator_low_stake_grace_period: None,
2906 consensus_leader_schedule_window_size: None,
2907
2908 max_move_system_package_size: None,
2909 };
2912
2913 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2914
2915 {
2917 cfg.feature_flags
2918 .disable_invariant_violation_check_in_swap_loc = true;
2919 cfg.feature_flags.no_extraneous_module_bytes = true;
2920 cfg.feature_flags.hardened_otw_check = true;
2921 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2922 }
2923
2924 {
2926 #[allow(deprecated)]
2927 {
2928 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2929 }
2930 }
2931
2932 #[expect(deprecated)]
2936 {
2937 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2938 }
2939 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2941
2942 cfg.feature_flags.per_object_congestion_control_mode =
2943 PerObjectCongestionControlMode::TotalTxCount;
2944
2945 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2947
2948 if chain != Chain::Mainnet && chain != Chain::Testnet {
2950 cfg.feature_flags.enable_poseidon = true;
2951 cfg.poseidon_bn254_cost_base = Some(260);
2952 cfg.poseidon_bn254_cost_per_block = Some(10);
2953
2954 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2955
2956 cfg.feature_flags.enable_vdf = true;
2957 cfg.vdf_verify_vdf_cost = Some(1500);
2960 cfg.vdf_hash_to_input_cost = Some(100);
2961
2962 cfg.feature_flags.passkey_auth = true;
2963 }
2964
2965 for cur in 2..=version.0 {
2966 match cur {
2967 1 => unreachable!(),
2968 2 => {}
2970 3 => {
2971 cfg.feature_flags.relocate_event_module = true;
2972 }
2973 4 => {
2974 cfg.max_type_to_layout_nodes = Some(512);
2975 }
2976 5 => {
2977 cfg.feature_flags.protocol_defined_base_fee = true;
2978 cfg.base_gas_price = Some(1000);
2979
2980 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2981 cfg.feature_flags.convert_type_argument_error = true;
2982 cfg.feature_flags.native_charging_v2 = true;
2983
2984 if chain != Chain::Mainnet && chain != Chain::Testnet {
2985 cfg.feature_flags.uncompressed_g1_group_elements = true;
2986 }
2987
2988 cfg.gas_model_version = Some(2);
2989
2990 cfg.poseidon_bn254_cost_per_block = Some(388);
2991
2992 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2993 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2994 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2995 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2996 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2997 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2998 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2999 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
3000
3001 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
3003 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
3004 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
3005 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
3006
3007 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
3008 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
3009 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
3010 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
3011 Some(8213);
3012 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
3013 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
3014 Some(9484);
3015
3016 cfg.hash_keccak256_cost_base = Some(10);
3017 cfg.hash_blake2b256_cost_base = Some(10);
3018
3019 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
3021 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
3022 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
3023 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
3024
3025 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
3026 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
3027 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
3028 cfg.group_ops_bls12381_gt_add_cost = Some(188);
3029
3030 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
3031 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
3032 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
3033 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
3034
3035 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
3036 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
3037 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
3038 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
3039
3040 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
3041 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
3042 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
3043 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
3044
3045 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
3046 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
3047
3048 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
3049 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
3050 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
3051 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
3052
3053 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
3054 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
3055 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
3056 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
3057 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
3058
3059 cfg.group_ops_bls12381_pairing_cost = Some(26897);
3060
3061 cfg.validator_validate_metadata_cost_base = Some(20000);
3062
3063 cfg.max_committee_members_count = Some(50);
3064 }
3065 6 => {
3066 cfg.max_ptb_value_size = Some(1024 * 1024);
3067 }
3068 7 => {
3069 }
3072 8 => {
3073 cfg.feature_flags.variant_nodes = true;
3074
3075 if chain != Chain::Mainnet {
3076 cfg.feature_flags.consensus_round_prober = true;
3078 cfg.feature_flags
3080 .consensus_distributed_vote_scoring_strategy = true;
3081 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
3082 cfg.feature_flags.consensus_smart_ancestor_selection = true;
3084 cfg.feature_flags
3086 .consensus_round_prober_probe_accepted_rounds = true;
3087 cfg.feature_flags.consensus_zstd_compression = true;
3089 cfg.consensus_gc_depth = Some(60);
3093 }
3094
3095 if chain != Chain::Testnet && chain != Chain::Mainnet {
3098 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
3099 }
3100 }
3101 9 => {
3102 if chain != Chain::Mainnet {
3103 cfg.feature_flags.consensus_smart_ancestor_selection = false;
3105 }
3106
3107 cfg.feature_flags.consensus_zstd_compression = true;
3109
3110 if chain != Chain::Testnet && chain != Chain::Mainnet {
3112 cfg.feature_flags.accept_passkey_in_multisig = true;
3113 }
3114
3115 cfg.bridge_should_try_to_finalize_committee = None;
3117 }
3118 10 => {
3119 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
3122
3123 cfg.max_committee_members_count = Some(80);
3125
3126 cfg.feature_flags.consensus_round_prober = true;
3128 cfg.feature_flags
3130 .consensus_round_prober_probe_accepted_rounds = true;
3131 cfg.feature_flags
3133 .consensus_distributed_vote_scoring_strategy = true;
3134 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
3136
3137 cfg.consensus_gc_depth = Some(60);
3142
3143 cfg.feature_flags.minimize_child_object_mutations = true;
3145
3146 if chain != Chain::Mainnet {
3147 cfg.feature_flags.consensus_batched_block_sync = true;
3149 }
3150
3151 if chain != Chain::Testnet && chain != Chain::Mainnet {
3152 cfg.feature_flags
3155 .congestion_control_gas_price_feedback_mechanism = true;
3156 }
3157
3158 cfg.feature_flags.validate_identifier_inputs = true;
3159 cfg.feature_flags.dependency_linkage_error = true;
3160 cfg.feature_flags.additional_multisig_checks = true;
3161 }
3162 11 => {
3163 }
3166 12 => {
3167 cfg.feature_flags
3170 .congestion_control_gas_price_feedback_mechanism = true;
3171
3172 cfg.feature_flags.normalize_ptb_arguments = true;
3174 }
3175 13 => {
3176 cfg.feature_flags.select_committee_from_eligible_validators = true;
3179 cfg.feature_flags.track_non_committee_eligible_validators = true;
3182
3183 if chain != Chain::Testnet && chain != Chain::Mainnet {
3184 cfg.feature_flags
3187 .select_committee_supporting_next_epoch_version = true;
3188 }
3189 }
3190 14 => {
3191 cfg.feature_flags.consensus_batched_block_sync = true;
3193
3194 if chain != Chain::Mainnet {
3195 cfg.feature_flags
3198 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3199 cfg.feature_flags
3203 .select_committee_supporting_next_epoch_version = true;
3204 }
3205 if chain != Chain::Testnet && chain != Chain::Mainnet {
3206 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3208 }
3209 }
3210 15 => {
3211 if chain != Chain::Mainnet && chain != Chain::Testnet {
3212 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3216 }
3217 }
3218 16 => {
3219 cfg.feature_flags
3222 .select_committee_supporting_next_epoch_version = true;
3223 cfg.feature_flags
3225 .consensus_commit_transactions_only_for_traversed_headers = true;
3226 }
3227 17 => {
3228 cfg.max_committee_members_count = Some(100);
3230 }
3231 18 => {
3232 if chain != Chain::Mainnet {
3233 cfg.feature_flags.passkey_auth = true;
3235 }
3236 }
3237 19 => {
3238 if chain != Chain::Testnet && chain != Chain::Mainnet {
3239 cfg.feature_flags
3242 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3243 cfg.feature_flags
3246 .separate_gas_price_feedback_mechanism_for_randomness = true;
3247 cfg.feature_flags.metadata_in_module_bytes = true;
3250 cfg.feature_flags.publish_package_metadata = true;
3251 cfg.feature_flags.enable_move_authentication = true;
3253 cfg.max_auth_gas = Some(250_000_000);
3255 cfg.transfer_receive_object_cost_base = Some(100);
3258 cfg.feature_flags.adjust_rewards_by_score = true;
3260 }
3261
3262 if chain != Chain::Mainnet {
3263 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3265
3266 cfg.feature_flags.calculate_validator_scores = true;
3268 cfg.scorer_version = Some(1);
3269 }
3270
3271 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
3273
3274 cfg.feature_flags.passkey_auth = true;
3276 }
3277 20 => {
3278 if chain != Chain::Testnet && chain != Chain::Mainnet {
3279 cfg.feature_flags
3281 .pass_calculated_validator_scores_to_advance_epoch = true;
3282 }
3283 }
3284 21 => {
3285 if chain != Chain::Testnet && chain != Chain::Mainnet {
3286 cfg.feature_flags.consensus_fast_commit_sync = true;
3288 }
3289 if chain != Chain::Mainnet {
3290 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3295 cfg.feature_flags
3298 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3299 cfg.feature_flags
3302 .separate_gas_price_feedback_mechanism_for_randomness = true;
3303 }
3304
3305 cfg.auth_context_digest_cost_base = Some(30);
3306 cfg.auth_context_tx_commands_cost_base = Some(30);
3307 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
3308 cfg.auth_context_tx_inputs_cost_base = Some(30);
3309 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
3310 cfg.auth_context_replace_cost_base = Some(30);
3311 cfg.auth_context_replace_cost_per_byte = Some(2);
3312
3313 if chain != Chain::Testnet && chain != Chain::Mainnet {
3314 cfg.max_auth_gas = Some(250_000);
3316 }
3317 }
3318 22 => {
3319 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3324 cfg.feature_flags
3327 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3328 cfg.feature_flags
3331 .separate_gas_price_feedback_mechanism_for_randomness = true;
3332
3333 if chain != Chain::Mainnet {
3334 cfg.feature_flags.metadata_in_module_bytes = true;
3337 cfg.feature_flags.publish_package_metadata = true;
3338 cfg.feature_flags.enable_move_authentication = true;
3340 cfg.max_auth_gas = Some(250_000);
3342 cfg.transfer_receive_object_cost_base = Some(100);
3345 }
3346
3347 if chain != Chain::Mainnet {
3348 cfg.feature_flags.consensus_fast_commit_sync = true;
3350 }
3351 }
3352 23 => {
3353 cfg.feature_flags.move_native_tx_context = true;
3355 cfg.tx_context_fresh_id_cost_base = Some(52);
3356 cfg.tx_context_sender_cost_base = Some(30);
3357 cfg.tx_context_digest_cost_base = Some(30);
3358 cfg.tx_context_epoch_cost_base = Some(30);
3359 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
3360 cfg.tx_context_sponsor_cost_base = Some(30);
3361 cfg.tx_context_rgp_cost_base = Some(30);
3362 cfg.tx_context_gas_price_cost_base = Some(30);
3363 cfg.tx_context_gas_budget_cost_base = Some(30);
3364 cfg.tx_context_ids_created_cost_base = Some(30);
3365 cfg.tx_context_replace_cost_base = Some(30);
3366 }
3367 24 => {
3368 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3370
3371 if chain != Chain::Testnet && chain != Chain::Mainnet {
3372 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3374 }
3375
3376 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
3379 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
3380
3381 cfg.feature_flags.additional_borrow_checks = true;
3383 }
3384 #[allow(deprecated)]
3385 25 => {
3386 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
3389 cfg.check_zklogin_id_cost_base = None;
3390 cfg.check_zklogin_issuer_cost_base = None;
3391 cfg.max_jwk_votes_per_validator_per_epoch = None;
3392 cfg.max_age_of_jwk_in_epochs = None;
3393 }
3394 26 => {
3395 }
3398 27 => {
3399 if chain != Chain::Mainnet {
3400 cfg.feature_flags.consensus_block_restrictions = true;
3403 }
3404
3405 if chain != Chain::Testnet && chain != Chain::Mainnet {
3406 cfg.feature_flags
3408 .pre_consensus_sponsor_only_move_authentication = true;
3409 }
3410 }
3411 28 => {
3412 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
3417
3418 cfg.feature_flags.metadata_in_module_bytes = true;
3421 cfg.feature_flags.publish_package_metadata = true;
3422 cfg.feature_flags.enable_move_authentication = true;
3424 cfg.transfer_receive_object_cost_base = Some(100);
3427
3428 if chain != Chain::Unknown {
3429 cfg.max_auth_gas = Some(20_000);
3431 }
3432
3433 if chain != Chain::Mainnet {
3434 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3436 cfg.feature_flags
3438 .pre_consensus_sponsor_only_move_authentication = true;
3439 }
3440 }
3441 29 => {
3442 cfg.feature_flags.always_advance_dkg_to_resolution = true;
3448
3449 cfg.feature_flags
3452 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3453
3454 cfg.feature_flags.consensus_fast_commit_sync = true;
3456 cfg.feature_flags.consensus_block_restrictions = true;
3460 }
3461 30 => {
3462 }
3470 31 => {
3471 cfg.feature_flags.validator_metadata_verify_v2 = true;
3472
3473 if chain != Chain::Mainnet && chain != Chain::Testnet {
3474 cfg.checkpoint_rate_window_size = Some(20);
3477 cfg.feature_flags
3480 .package_metadata_with_dynamic_module_metadata = true;
3481 cfg.feature_flags.consensus_starfish_speed = true;
3484 }
3485
3486 cfg.feature_flags.report_move_authentication_error = true;
3487 }
3488 32 => {
3489 cfg.min_validator_count = Some(4);
3493 cfg.max_validator_count = Some(150);
3494 cfg.min_validator_joining_stake = Some(2_000_000_000_000_000);
3495 cfg.validator_low_stake_threshold = Some(1_500_000_000_000_000);
3496 cfg.validator_very_low_stake_threshold = Some(1_000_000_000_000_000);
3497 cfg.validator_low_stake_grace_period = Some(7);
3498
3499 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3501 cfg.feature_flags
3503 .pre_consensus_sponsor_only_move_authentication = true;
3504
3505 if chain != Chain::Mainnet {
3506 cfg.feature_flags.consensus_starfish_speed = true;
3509 cfg.checkpoint_rate_window_size = Some(20);
3512 cfg.feature_flags
3515 .package_metadata_with_dynamic_module_metadata = true;
3516 }
3517
3518 if chain != Chain::Mainnet && chain != Chain::Testnet {
3519 cfg.feature_flags
3523 .consensus_enable_sliding_window_leader_schedule = true;
3524 cfg.feature_flags
3525 .consensus_enable_absolute_score_leader_schedule = true;
3526 cfg.feature_flags.enable_pcool_flow = true;
3530 }
3531 }
3532 33 => {
3533 cfg.checkpoint_rate_window_size = Some(20);
3536 if chain != Chain::Mainnet {
3540 cfg.feature_flags
3541 .consensus_enable_sliding_window_leader_schedule = true;
3542 cfg.feature_flags
3543 .consensus_enable_absolute_score_leader_schedule = true;
3544 }
3545 }
3546 34 => {
3547 if chain != Chain::Testnet && chain != Chain::Mainnet {
3548 cfg.scorer_version = Some(2);
3552 }
3553 cfg.feature_flags.pcool_skip_immutable_object_locks = true;
3557
3558 if chain == Chain::Mainnet {
3559 cfg.feature_flags.enable_move_authentication_for_sponsor = false;
3561 cfg.feature_flags
3564 .pre_consensus_sponsor_only_move_authentication = false;
3565 }
3566 }
3567 35 => {
3568 cfg.feature_flags.max_ptb_value_size_v2 = true;
3570 cfg.feature_flags.allow_unbounded_system_objects = true;
3572
3573 cfg.feature_flags.consensus_starfish_speed = true;
3576
3577 cfg.max_verifier_meter_ticks_per_function = Some(2_200_000);
3584 cfg.max_meter_ticks_per_module = Some(2_200_000);
3585 cfg.max_meter_ticks_per_package = Some(2_200_000);
3586 cfg.max_meter_ticks_regex_reference_safety = Some(2_200_000);
3587 cfg.feature_flags.pcool_verifier_limits_from_protocol_config = true;
3588 cfg.feature_flags
3591 .package_metadata_with_dynamic_module_metadata = true;
3592 cfg.feature_flags
3596 .consensus_enable_sliding_window_leader_schedule = true;
3597 cfg.feature_flags
3598 .consensus_enable_absolute_score_leader_schedule = true;
3599
3600 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3603 cfg.feature_flags
3606 .pre_consensus_sponsor_only_move_authentication = false;
3607 }
3608 36 => {
3609 cfg.feature_flags.reject_immutable_account_objects = true;
3612 }
3613 37 => {
3614 cfg.feature_flags.validate_input_object_versions = true;
3618 cfg.feature_flags.disallow_self_identifier = true;
3619 cfg.max_move_enum_variants = Some(move_core_types::VARIANT_COUNT_MAX);
3620 cfg.feature_flags.deny_authenticator_packages = true;
3623 cfg.feature_flags.check_canonical_module_version_header = true;
3626 cfg.feature_flags.disallow_randomness_in_move_authenticator = true;
3631 cfg.feature_flags.check_cyclic_dependencies = true;
3634 }
3635 38 => {
3636 cfg.max_move_system_package_size = Some(200 * 1024);
3643 cfg.feature_flags.reject_immutable_account_creation = true;
3646 }
3647 _ => panic!("unsupported version {version:?}"),
3658 }
3659 }
3660 cfg
3661 }
3662
3663 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
3669 let (
3670 max_back_edges_per_function,
3671 max_back_edges_per_module,
3672 sanity_check_with_regex_reference_safety,
3673 ) = if let Some((
3674 max_back_edges_per_function,
3675 max_back_edges_per_module,
3676 sanity_check_with_regex_reference_safety,
3677 )) = signing_limits
3678 {
3679 (
3680 Some(max_back_edges_per_function),
3681 Some(max_back_edges_per_module),
3682 Some(sanity_check_with_regex_reference_safety),
3683 )
3684 } else {
3685 (None, None, None)
3686 };
3687
3688 let additional_borrow_checks = if signing_limits.is_some() {
3689 true
3692 } else {
3693 self.additional_borrow_checks()
3694 };
3695
3696 VerifierConfig {
3697 max_loop_depth: Some(self.max_loop_depth() as usize),
3698 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
3699 max_function_parameters: Some(self.max_function_parameters() as usize),
3700 max_basic_blocks: Some(self.max_basic_blocks() as usize),
3701 max_value_stack_size: self.max_value_stack_size() as usize,
3702 max_type_nodes: Some(self.max_type_nodes() as usize),
3703 max_push_size: Some(self.max_push_size() as usize),
3704 max_dependency_depth: Some(self.max_dependency_depth() as usize),
3705 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
3706 max_function_definitions: Some(self.max_function_definitions() as usize),
3707 max_data_definitions: Some(self.max_struct_definitions() as usize),
3708 max_constant_vector_len: Some(self.max_move_vector_len()),
3709 max_back_edges_per_function,
3710 max_back_edges_per_module,
3711 max_basic_blocks_in_script: None,
3712 max_identifier_len: self.max_move_identifier_len_as_option(), disallow_self_identifier: self.feature_flags.disallow_self_identifier,
3716 bytecode_version: self.move_binary_format_version(),
3717 max_variants_in_enum: self.max_move_enum_variants_as_option(),
3718 additional_borrow_checks,
3719 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
3720 .map(|limit| limit as u128),
3721 check_cyclic_dependencies: self.feature_flags.check_cyclic_dependencies,
3722 }
3723 }
3724
3725 pub fn verifier_signing_limits(&self) -> (usize, usize, usize) {
3732 (
3733 self.max_back_edges_per_function() as usize,
3734 self.max_back_edges_per_module() as usize,
3735 self.max_meter_ticks_regex_reference_safety() as usize,
3736 )
3737 }
3738
3739 pub fn meter_config(&self) -> MeterConfig {
3743 MeterConfig {
3744 max_per_fun_meter_units: Some(self.max_verifier_meter_ticks_per_function() as u128),
3745 max_per_mod_meter_units: Some(self.max_meter_ticks_per_module() as u128),
3746 max_per_pkg_meter_units: Some(self.max_meter_ticks_per_package() as u128),
3747 }
3748 }
3749
3750 pub fn apply_overrides_for_testing(
3755 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
3756 ) -> OverrideGuard {
3757 CONFIG_OVERRIDE.with(|ovr| {
3758 let mut cur = ovr.borrow_mut();
3759 assert!(cur.is_none(), "config override already present");
3760 *cur = Some(Box::new(override_fn));
3761 OverrideGuard
3762 })
3763 }
3764}
3765
3766impl ProtocolConfig {
3771 pub fn set_per_object_congestion_control_mode_for_testing(
3772 &mut self,
3773 val: PerObjectCongestionControlMode,
3774 ) {
3775 self.feature_flags.per_object_congestion_control_mode = val;
3776 }
3777
3778 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
3779 self.feature_flags.consensus_choice = val;
3780 }
3781
3782 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
3783 self.feature_flags.consensus_network = val;
3784 }
3785
3786 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
3787 self.feature_flags.passkey_auth = val
3788 }
3789
3790 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
3791 self.feature_flags
3792 .disallow_new_modules_in_deps_only_packages = val;
3793 }
3794
3795 pub fn set_check_canonical_module_version_header_for_testing(&mut self, val: bool) {
3796 self.feature_flags.check_canonical_module_version_header = val;
3797 }
3798
3799 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
3800 self.feature_flags.consensus_round_prober = val;
3801 }
3802
3803 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
3804 self.feature_flags
3805 .consensus_distributed_vote_scoring_strategy = val;
3806 }
3807
3808 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
3809 self.consensus_gc_depth = Some(val);
3810 }
3811
3812 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
3813 self.feature_flags.consensus_linearize_subdag_v2 = val;
3814 }
3815
3816 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
3817 self.feature_flags
3818 .consensus_round_prober_probe_accepted_rounds = val;
3819 }
3820
3821 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
3822 self.feature_flags.accept_passkey_in_multisig = val;
3823 }
3824
3825 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
3826 self.feature_flags.consensus_smart_ancestor_selection = val;
3827 }
3828
3829 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
3830 self.feature_flags.consensus_batched_block_sync = val;
3831 }
3832
3833 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
3834 self.feature_flags
3835 .congestion_control_min_free_execution_slot = val;
3836 }
3837
3838 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
3839 self.feature_flags
3840 .congestion_control_gas_price_feedback_mechanism = val;
3841 }
3842
3843 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
3844 self.feature_flags.select_committee_from_eligible_validators = val;
3845 }
3846
3847 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
3848 self.feature_flags.track_non_committee_eligible_validators = val;
3849 }
3850
3851 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
3852 self.feature_flags
3853 .select_committee_supporting_next_epoch_version = val;
3854 }
3855
3856 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
3857 &mut self,
3858 val: bool,
3859 ) {
3860 self.feature_flags
3861 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3862 }
3863
3864 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3865 &mut self,
3866 val: bool,
3867 ) {
3868 self.feature_flags
3869 .consensus_commit_transactions_only_for_traversed_headers = val;
3870 }
3871
3872 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3873 &mut self,
3874 val: bool,
3875 ) {
3876 self.feature_flags
3877 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3878 }
3879
3880 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3881 &mut self,
3882 val: bool,
3883 ) {
3884 self.feature_flags
3885 .separate_gas_price_feedback_mechanism_for_randomness = val;
3886 }
3887
3888 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3889 self.feature_flags.metadata_in_module_bytes = val;
3890 }
3891
3892 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3893 self.feature_flags.publish_package_metadata = val;
3894 }
3895
3896 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3897 self.feature_flags.enable_move_authentication = val;
3898 }
3899
3900 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3901 self.feature_flags.enable_move_authentication_for_sponsor = val;
3902 }
3903
3904 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3905 self.feature_flags.consensus_fast_commit_sync = val;
3906 }
3907
3908 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3909 self.feature_flags.consensus_block_restrictions = val;
3910 }
3911
3912 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3913 self.feature_flags
3914 .pre_consensus_sponsor_only_move_authentication = val;
3915 }
3916
3917 pub fn set_consensus_starfish_speed_for_testing(&mut self, val: bool) {
3918 self.feature_flags.consensus_starfish_speed = val;
3919 }
3920
3921 pub fn set_always_advance_dkg_to_resolution_for_testing(&mut self, val: bool) {
3922 self.feature_flags.always_advance_dkg_to_resolution = val;
3923 }
3924
3925 pub fn set_enable_pcool_flow_for_testing(&mut self, val: bool) {
3926 self.feature_flags.enable_pcool_flow = val;
3927 }
3928
3929 pub fn set_pcool_skip_immutable_object_locks_for_testing(&mut self, val: bool) {
3930 self.feature_flags.pcool_skip_immutable_object_locks = val;
3931 }
3932
3933 pub fn set_pcool_verifier_limits_from_protocol_config_for_testing(&mut self, val: bool) {
3934 self.feature_flags
3935 .pcool_verifier_limits_from_protocol_config = val;
3936 }
3937
3938 pub fn set_reject_immutable_account_objects_for_testing(&mut self, val: bool) {
3939 self.feature_flags.reject_immutable_account_objects = val;
3940 }
3941
3942 pub fn set_reject_immutable_account_creation_for_testing(&mut self, val: bool) {
3943 self.feature_flags.reject_immutable_account_creation = val;
3944 }
3945
3946 pub fn set_validate_input_object_versions_for_testing(&mut self, val: bool) {
3947 self.feature_flags.validate_input_object_versions = val;
3948 }
3949
3950 pub fn set_disallow_randomness_in_move_authenticator_for_testing(&mut self, val: bool) {
3951 self.feature_flags.disallow_randomness_in_move_authenticator = val;
3952 }
3953
3954 pub fn set_commits_per_schedule_for_testing(&mut self, val: u32) {
3955 self.consensus_commits_per_schedule = Some(val);
3956 }
3957
3958 pub fn set_deny_rule_governance_for_testing(&mut self, val: bool) {
3959 self.feature_flags.deny_rule_governance = val;
3960 }
3961
3962 pub fn set_deny_authenticator_packages_for_testing(&mut self, val: bool) {
3963 self.feature_flags.deny_authenticator_packages = val;
3964 }
3965
3966 pub fn set_deny_rule_governance_on_chain_for_testing(&mut self, val: bool) {
3967 self.feature_flags.deny_rule_governance_on_chain = val;
3968 }
3969
3970 pub fn set_calculate_validator_scores_for_testing(&mut self, val: bool) {
3975 self.feature_flags.calculate_validator_scores = val;
3976 if val {
3977 self.scorer_version.get_or_insert(1);
3978 } else {
3979 self.feature_flags.adjust_rewards_by_score = false;
3980 self.feature_flags
3981 .pass_calculated_validator_scores_to_advance_epoch = false;
3982 }
3983 }
3984
3985 pub fn set_package_metadata_with_dynamic_module_metadata_for_testing(&mut self, val: bool) {
3986 self.feature_flags
3987 .package_metadata_with_dynamic_module_metadata = val;
3988 }
3989
3990 pub fn set_report_move_authentication_error_for_testing(&mut self, val: bool) {
3991 self.feature_flags.report_move_authentication_error = val;
3992 }
3993
3994 pub fn set_leader_schedule_window_size_for_testing(&mut self, val: u32) {
3995 self.consensus_leader_schedule_window_size = Some(val);
3996 }
3997
3998 pub fn set_consensus_enable_sliding_window_leader_schedule_for_testing(&mut self, val: bool) {
3999 self.feature_flags
4000 .consensus_enable_sliding_window_leader_schedule = val;
4001 }
4002
4003 pub fn set_consensus_enable_absolute_score_leader_schedule_for_testing(&mut self, val: bool) {
4004 self.feature_flags
4005 .consensus_enable_absolute_score_leader_schedule = val;
4006 }
4007}
4008
4009type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
4010
4011thread_local! {
4012 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
4013}
4014
4015#[must_use]
4016pub struct OverrideGuard;
4017
4018impl Drop for OverrideGuard {
4019 fn drop(&mut self) {
4020 info!("restoring override fn");
4021 CONFIG_OVERRIDE.with(|ovr| {
4022 *ovr.borrow_mut() = None;
4023 });
4024 }
4025}
4026
4027#[derive(PartialEq, Eq)]
4031pub enum LimitThresholdCrossed {
4032 None,
4033 Soft(u128, u128),
4034 Hard(u128, u128),
4035}
4036
4037pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
4040 x: T,
4041 soft_limit: U,
4042 hard_limit: V,
4043) -> LimitThresholdCrossed {
4044 let x: V = x.into();
4045 let soft_limit: V = soft_limit.into();
4046
4047 debug_assert!(soft_limit <= hard_limit);
4048
4049 if x >= hard_limit {
4052 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
4053 } else if x < soft_limit {
4054 LimitThresholdCrossed::None
4055 } else {
4056 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
4057 }
4058}
4059
4060#[macro_export]
4061macro_rules! check_limit {
4062 ($x:expr, $hard:expr) => {
4063 check_limit!($x, $hard, $hard)
4064 };
4065 ($x:expr, $soft:expr, $hard:expr) => {
4066 check_limit_in_range($x as u64, $soft, $hard)
4067 };
4068}
4069
4070#[macro_export]
4074macro_rules! check_limit_by_meter {
4075 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
4076 let (h, metered_str) = if $is_metered {
4078 ($metered_limit, "metered")
4079 } else {
4080 ($unmetered_hard_limit, "unmetered")
4082 };
4083 use iota_protocol_config::check_limit_in_range;
4084 let result = check_limit_in_range($x as u64, $metered_limit, h);
4085 match result {
4086 LimitThresholdCrossed::None => {}
4087 LimitThresholdCrossed::Soft(_, _) => {
4088 $metric.with_label_values(&[metered_str, "soft"]).inc();
4089 }
4090 LimitThresholdCrossed::Hard(_, _) => {
4091 $metric.with_label_values(&[metered_str, "hard"]).inc();
4092 }
4093 };
4094 result
4095 }};
4096}
4097
4098#[cfg(all(test, not(msim)))]
4099mod test {
4100 use insta::assert_yaml_snapshot;
4101
4102 use super::*;
4103
4104 #[test]
4105 fn snapshot_tests() {
4106 println!("\n============================================================================");
4107 println!("! !");
4108 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
4109 println!("! !");
4110 println!("============================================================================\n");
4111 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
4112 let chain_str = match chain_id {
4117 Chain::Unknown => "".to_string(),
4118 _ => format!("{chain_id:?}_"),
4119 };
4120 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
4121 let cur = ProtocolVersion::new(i);
4122 assert_yaml_snapshot!(
4123 format!("{}version_{}", chain_str, cur.as_u64()),
4124 ProtocolConfig::get_for_version(cur, *chain_id)
4125 );
4126 }
4127 }
4128 }
4129
4130 #[test]
4131 fn test_getters() {
4132 let prot: ProtocolConfig =
4133 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4134 assert_eq!(
4135 prot.max_arguments(),
4136 prot.max_arguments_as_option().unwrap()
4137 );
4138 }
4139
4140 #[test]
4141 fn test_setters() {
4142 let mut prot: ProtocolConfig =
4143 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4144 prot.set_max_arguments_for_testing(123);
4145 assert_eq!(prot.max_arguments(), 123);
4146
4147 prot.set_max_arguments_from_str_for_testing("321".to_string());
4148 assert_eq!(prot.max_arguments(), 321);
4149
4150 prot.disable_max_arguments_for_testing();
4151 assert_eq!(prot.max_arguments_as_option(), None);
4152
4153 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
4154 assert_eq!(prot.max_arguments(), 456);
4155 }
4156
4157 #[test]
4158 fn reject_immutable_account_creation_implies_rejecting_the_objects() {
4159 for chain in [Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
4160 for version in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
4161 ProtocolConfig::get_for_version(ProtocolVersion::new(version), chain)
4164 .reject_immutable_account_creation();
4165 }
4166 }
4167 }
4168
4169 #[test]
4170 #[should_panic(expected = "unsupported version")]
4171 fn max_version_test() {
4172 let _ = ProtocolConfig::get_for_version_impl(
4175 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
4176 Chain::Unknown,
4177 );
4178 }
4179
4180 #[test]
4181 fn lookup_by_string_test() {
4182 let prot: ProtocolConfig =
4183 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
4184 assert!(prot.lookup_attr("some random string".to_string()).is_none());
4186
4187 assert!(
4188 prot.lookup_attr("max_arguments".to_string())
4189 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
4190 );
4191
4192 assert!(
4194 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
4195 .is_none()
4196 );
4197 assert!(
4198 prot.attr_map()
4199 .get("poseidon_bn254_cost_base")
4200 .unwrap()
4201 .is_none()
4202 );
4203
4204 let prot: ProtocolConfig =
4206 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4207
4208 assert!(
4209 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
4210 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
4211 );
4212 assert!(
4213 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
4214 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
4215 );
4216
4217 let prot: ProtocolConfig =
4219 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
4220 assert!(
4222 prot.feature_flags
4223 .lookup_attr("some random string".to_owned())
4224 .is_none()
4225 );
4226 assert!(
4227 !prot
4228 .feature_flags
4229 .attr_map()
4230 .contains_key("some random string")
4231 );
4232
4233 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
4235 assert!(
4236 prot.feature_flags
4237 .attr_map()
4238 .get("enable_poseidon")
4239 .unwrap()
4240 == &false
4241 );
4242 let prot: ProtocolConfig =
4243 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4244 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
4246 assert!(
4247 prot.feature_flags
4248 .attr_map()
4249 .get("enable_poseidon")
4250 .unwrap()
4251 == &true
4252 );
4253 }
4254
4255 #[test]
4259 #[should_panic(expected = "deny_rule_update_max_entries_per_tx must be positive")]
4260 fn deny_rule_chunk_limit_above_the_ceiling_is_rejected() {
4261 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
4262 config.set_deny_rule_governance_for_testing(true);
4263 config.set_deny_rule_governance_on_chain_for_testing(true);
4264 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
4265 config.set_deny_rule_update_max_entries_per_tx_for_testing(2048 + 1);
4266 config
4267 });
4268 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
4269 }
4270
4271 #[test]
4274 #[should_panic(expected = "deny_rule_update_max_entries_per_tx must be positive")]
4275 fn deny_rule_chunk_limit_of_zero_is_rejected() {
4276 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
4277 config.set_deny_rule_governance_for_testing(true);
4278 config.set_deny_rule_governance_on_chain_for_testing(true);
4279 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
4280 config.set_deny_rule_update_max_entries_per_tx_for_testing(0);
4281 config
4282 });
4283 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
4284 }
4285
4286 #[test]
4288 fn deny_rule_chunk_limit_within_system_tx_object_id_limit_is_accepted() {
4289 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
4290 config.set_deny_rule_governance_for_testing(true);
4291 config.set_deny_rule_governance_on_chain_for_testing(true);
4292 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
4293 config.set_deny_rule_update_max_entries_per_tx_for_testing(1000);
4294 config
4295 });
4296 let config = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
4297 assert_eq!(config.deny_rule_update_max_entries_per_tx(), 1000);
4298 }
4299
4300 #[test]
4301 fn limit_range_fn_test() {
4302 let low = 100u32;
4303 let high = 10000u64;
4304
4305 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
4306 assert!(matches!(
4307 check_limit!(255u16, low, high),
4308 LimitThresholdCrossed::Soft(255u128, 100)
4309 ));
4310 assert!(matches!(
4317 check_limit!(2550000u64, low, high),
4318 LimitThresholdCrossed::Hard(2550000, 10000)
4319 ));
4320
4321 assert!(matches!(
4322 check_limit!(2550000u64, high, high),
4323 LimitThresholdCrossed::Hard(2550000, 10000)
4324 ));
4325
4326 assert!(matches!(
4327 check_limit!(1u8, high),
4328 LimitThresholdCrossed::None
4329 ));
4330
4331 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
4332
4333 assert!(matches!(
4334 check_limit!(2550000u64, high),
4335 LimitThresholdCrossed::Hard(2550000, 10000)
4336 ));
4337 }
4338}