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]
854#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
855pub struct ProtocolConfig {
856 pub version: ProtocolVersion,
857
858 feature_flags: FeatureFlags,
859
860 max_tx_size_bytes: Option<u64>,
865
866 max_input_objects: Option<u64>,
871
872 max_size_written_objects: Option<u64>,
877 max_size_written_objects_system_tx: Option<u64>,
881
882 max_serialized_tx_effects_size_bytes: Option<u64>,
884
885 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
887
888 max_gas_payment_objects: Option<u32>,
890
891 max_modules_in_publish: Option<u32>,
893
894 max_package_dependencies: Option<u32>,
896
897 max_arguments: Option<u32>,
900
901 max_type_arguments: Option<u32>,
903
904 max_type_argument_depth: Option<u32>,
906
907 max_pure_argument_size: Option<u32>,
909
910 max_programmable_tx_commands: Option<u32>,
912
913 move_binary_format_version: Option<u32>,
919 min_move_binary_format_version: Option<u32>,
920
921 binary_module_handles: Option<u16>,
923 binary_struct_handles: Option<u16>,
924 binary_function_handles: Option<u16>,
925 binary_function_instantiations: Option<u16>,
926 binary_signatures: Option<u16>,
927 binary_constant_pool: Option<u16>,
928 binary_identifiers: Option<u16>,
929 binary_address_identifiers: Option<u16>,
930 binary_struct_defs: Option<u16>,
931 binary_struct_def_instantiations: Option<u16>,
932 binary_function_defs: Option<u16>,
933 binary_field_handles: Option<u16>,
934 binary_field_instantiations: Option<u16>,
935 binary_friend_decls: Option<u16>,
936 binary_enum_defs: Option<u16>,
937 binary_enum_def_instantiations: Option<u16>,
938 binary_variant_handles: Option<u16>,
939 binary_variant_instantiation_handles: Option<u16>,
940
941 max_move_object_size: Option<u64>,
944
945 max_move_package_size: Option<u64>,
950
951 max_publish_or_upgrade_per_ptb: Option<u64>,
954
955 max_tx_gas: Option<u64>,
957
958 max_auth_gas: Option<u64>,
960
961 max_gas_price: Option<u64>,
964
965 max_gas_computation_bucket: Option<u64>,
968
969 gas_rounding_step: Option<u64>,
971
972 max_loop_depth: Option<u64>,
974
975 max_generic_instantiation_length: Option<u64>,
978
979 max_function_parameters: Option<u64>,
982
983 max_basic_blocks: Option<u64>,
986
987 max_value_stack_size: Option<u64>,
989
990 max_type_nodes: Option<u64>,
994
995 max_push_size: Option<u64>,
998
999 max_struct_definitions: Option<u64>,
1002
1003 max_function_definitions: Option<u64>,
1006
1007 max_fields_in_struct: Option<u64>,
1010
1011 max_dependency_depth: Option<u64>,
1014
1015 max_num_event_emit: Option<u64>,
1018
1019 max_num_new_move_object_ids: Option<u64>,
1022
1023 max_num_new_move_object_ids_system_tx: Option<u64>,
1026
1027 max_num_deleted_move_object_ids: Option<u64>,
1030
1031 max_num_deleted_move_object_ids_system_tx: Option<u64>,
1034
1035 max_num_transferred_move_object_ids: Option<u64>,
1038
1039 max_num_transferred_move_object_ids_system_tx: Option<u64>,
1042
1043 max_event_emit_size: Option<u64>,
1045
1046 max_event_emit_size_total: Option<u64>,
1048
1049 max_move_vector_len: Option<u64>,
1052
1053 max_move_identifier_len: Option<u64>,
1056
1057 max_move_value_depth: Option<u64>,
1059
1060 max_move_enum_variants: Option<u64>,
1063
1064 max_back_edges_per_function: Option<u64>,
1073
1074 max_back_edges_per_module: Option<u64>,
1076
1077 max_verifier_meter_ticks_per_function: Option<u64>,
1079
1080 max_meter_ticks_per_module: Option<u64>,
1082
1083 max_meter_ticks_per_package: Option<u64>,
1085
1086 max_meter_ticks_regex_reference_safety: Option<u64>,
1090
1091 object_runtime_max_num_cached_objects: Option<u64>,
1098
1099 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
1102
1103 object_runtime_max_num_store_entries: Option<u64>,
1106
1107 object_runtime_max_num_store_entries_system_tx: Option<u64>,
1110
1111 base_tx_cost_fixed: Option<u64>,
1116
1117 package_publish_cost_fixed: Option<u64>,
1121
1122 base_tx_cost_per_byte: Option<u64>,
1126
1127 package_publish_cost_per_byte: Option<u64>,
1129
1130 obj_access_cost_read_per_byte: Option<u64>,
1132
1133 obj_access_cost_mutate_per_byte: Option<u64>,
1135
1136 obj_access_cost_delete_per_byte: Option<u64>,
1138
1139 obj_access_cost_verify_per_byte: Option<u64>,
1149
1150 max_type_to_layout_nodes: Option<u64>,
1152
1153 max_ptb_value_size: Option<u64>,
1155
1156 gas_model_version: Option<u64>,
1161
1162 obj_data_cost_refundable: Option<u64>,
1168
1169 obj_metadata_cost_non_refundable: Option<u64>,
1173
1174 storage_rebate_rate: Option<u64>,
1180
1181 reward_slashing_rate: Option<u64>,
1184
1185 storage_gas_price: Option<u64>,
1187
1188 base_gas_price: Option<u64>,
1190
1191 validator_target_reward: Option<u64>,
1193
1194 max_transactions_per_checkpoint: Option<u64>,
1201
1202 max_checkpoint_size_bytes: Option<u64>,
1206
1207 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
1213
1214 address_from_bytes_cost_base: Option<u64>,
1219 address_to_u256_cost_base: Option<u64>,
1221 address_from_u256_cost_base: Option<u64>,
1223
1224 config_read_setting_impl_cost_base: Option<u64>,
1229 config_read_setting_impl_cost_per_byte: Option<u64>,
1230
1231 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
1235 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
1236 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
1237 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
1238 dynamic_field_add_child_object_cost_base: Option<u64>,
1241 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
1242 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
1243 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
1244 dynamic_field_borrow_child_object_cost_base: Option<u64>,
1247 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1248 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1249 dynamic_field_remove_child_object_cost_base: Option<u64>,
1252 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1253 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1254 dynamic_field_has_child_object_cost_base: Option<u64>,
1257 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1260 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1261 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1262
1263 event_emit_cost_base: Option<u64>,
1266 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1267 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1268 event_emit_output_cost_per_byte: Option<u64>,
1269
1270 object_borrow_uid_cost_base: Option<u64>,
1273 object_delete_impl_cost_base: Option<u64>,
1275 object_record_new_uid_cost_base: Option<u64>,
1277
1278 transfer_transfer_internal_cost_base: Option<u64>,
1281 transfer_freeze_object_cost_base: Option<u64>,
1283 transfer_share_object_cost_base: Option<u64>,
1285 transfer_receive_object_cost_base: Option<u64>,
1288
1289 tx_context_derive_id_cost_base: Option<u64>,
1292 tx_context_fresh_id_cost_base: Option<u64>,
1293 tx_context_sender_cost_base: Option<u64>,
1294 tx_context_digest_cost_base: Option<u64>,
1295 tx_context_epoch_cost_base: Option<u64>,
1296 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1297 tx_context_sponsor_cost_base: Option<u64>,
1298 tx_context_rgp_cost_base: Option<u64>,
1299 tx_context_gas_price_cost_base: Option<u64>,
1300 tx_context_gas_budget_cost_base: Option<u64>,
1301 tx_context_ids_created_cost_base: Option<u64>,
1302 tx_context_replace_cost_base: Option<u64>,
1303
1304 types_is_one_time_witness_cost_base: Option<u64>,
1307 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1308 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1309
1310 validator_validate_metadata_cost_base: Option<u64>,
1313 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1314
1315 crypto_invalid_arguments_cost: Option<u64>,
1317 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1319 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1320 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1321
1322 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1324 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1325 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1326
1327 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1329 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1330 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1331 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1332 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1333 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1334
1335 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1337
1338 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1340 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1341 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1342 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1343 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1344 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1345
1346 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1348 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1349 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1350 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1351 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1352 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1353
1354 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1356 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1357 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1358 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1359 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1360 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1361
1362 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1364 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1365 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1366
1367 ed25519_ed25519_verify_cost_base: Option<u64>,
1369 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1370 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1371
1372 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1374 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1375
1376 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1378 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1379 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1380 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1381 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1382
1383 hash_blake2b256_cost_base: Option<u64>,
1385 hash_blake2b256_data_cost_per_byte: Option<u64>,
1386 hash_blake2b256_data_cost_per_block: Option<u64>,
1387
1388 hash_keccak256_cost_base: Option<u64>,
1390 hash_keccak256_data_cost_per_byte: Option<u64>,
1391 hash_keccak256_data_cost_per_block: Option<u64>,
1392
1393 poseidon_bn254_cost_base: Option<u64>,
1395 poseidon_bn254_cost_per_block: Option<u64>,
1396
1397 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1399 group_ops_bls12381_decode_g1_cost: Option<u64>,
1400 group_ops_bls12381_decode_g2_cost: Option<u64>,
1401 group_ops_bls12381_decode_gt_cost: Option<u64>,
1402 group_ops_bls12381_scalar_add_cost: Option<u64>,
1403 group_ops_bls12381_g1_add_cost: Option<u64>,
1404 group_ops_bls12381_g2_add_cost: Option<u64>,
1405 group_ops_bls12381_gt_add_cost: Option<u64>,
1406 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1407 group_ops_bls12381_g1_sub_cost: Option<u64>,
1408 group_ops_bls12381_g2_sub_cost: Option<u64>,
1409 group_ops_bls12381_gt_sub_cost: Option<u64>,
1410 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1411 group_ops_bls12381_g1_mul_cost: Option<u64>,
1412 group_ops_bls12381_g2_mul_cost: Option<u64>,
1413 group_ops_bls12381_gt_mul_cost: Option<u64>,
1414 group_ops_bls12381_scalar_div_cost: Option<u64>,
1415 group_ops_bls12381_g1_div_cost: Option<u64>,
1416 group_ops_bls12381_g2_div_cost: Option<u64>,
1417 group_ops_bls12381_gt_div_cost: Option<u64>,
1418 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1419 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1420 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1421 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1422 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1423 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1424 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1425 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1426 group_ops_bls12381_msm_max_len: Option<u32>,
1427 group_ops_bls12381_pairing_cost: Option<u64>,
1428 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1429 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1430 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1431 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1432 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1433
1434 hmac_hmac_sha3_256_cost_base: Option<u64>,
1436 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1437 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1438
1439 #[deprecated]
1441 check_zklogin_id_cost_base: Option<u64>,
1442 #[deprecated]
1444 check_zklogin_issuer_cost_base: Option<u64>,
1445
1446 vdf_verify_vdf_cost: Option<u64>,
1447 vdf_hash_to_input_cost: Option<u64>,
1448
1449 bcs_per_byte_serialized_cost: Option<u64>,
1451 bcs_legacy_min_output_size_cost: Option<u64>,
1452 bcs_failure_cost: Option<u64>,
1453
1454 hash_sha2_256_base_cost: Option<u64>,
1455 hash_sha2_256_per_byte_cost: Option<u64>,
1456 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1457 hash_sha3_256_base_cost: Option<u64>,
1458 hash_sha3_256_per_byte_cost: Option<u64>,
1459 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1460 type_name_get_base_cost: Option<u64>,
1461 type_name_get_per_byte_cost: Option<u64>,
1462
1463 string_check_utf8_base_cost: Option<u64>,
1464 string_check_utf8_per_byte_cost: Option<u64>,
1465 string_is_char_boundary_base_cost: Option<u64>,
1466 string_sub_string_base_cost: Option<u64>,
1467 string_sub_string_per_byte_cost: Option<u64>,
1468 string_index_of_base_cost: Option<u64>,
1469 string_index_of_per_byte_pattern_cost: Option<u64>,
1470 string_index_of_per_byte_searched_cost: Option<u64>,
1471
1472 vector_empty_base_cost: Option<u64>,
1473 vector_length_base_cost: Option<u64>,
1474 vector_push_back_base_cost: Option<u64>,
1475 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1476 vector_borrow_base_cost: Option<u64>,
1477 vector_pop_back_base_cost: Option<u64>,
1478 vector_destroy_empty_base_cost: Option<u64>,
1479 vector_swap_base_cost: Option<u64>,
1480 debug_print_base_cost: Option<u64>,
1481 debug_print_stack_trace_base_cost: Option<u64>,
1482
1483 execution_version: Option<u64>,
1485
1486 consensus_bad_nodes_stake_threshold: Option<u64>,
1490
1491 #[deprecated]
1492 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1493 #[deprecated]
1497 max_age_of_jwk_in_epochs: Option<u64>,
1498
1499 random_beacon_reduction_allowed_delta: Option<u16>,
1503
1504 random_beacon_reduction_lower_bound: Option<u32>,
1507
1508 random_beacon_dkg_timeout_round: Option<u32>,
1511
1512 random_beacon_min_round_interval_ms: Option<u64>,
1514
1515 random_beacon_dkg_version: Option<u64>,
1519
1520 consensus_max_transaction_size_bytes: Option<u64>,
1525 consensus_max_transactions_in_block_bytes: Option<u64>,
1527 consensus_max_num_transactions_in_block: Option<u64>,
1529
1530 max_deferral_rounds_for_congestion_control: Option<u64>,
1534
1535 min_checkpoint_interval_ms: Option<u64>,
1537
1538 checkpoint_rate_window_size: Option<u64>,
1548
1549 checkpoint_summary_version_specific_data: Option<u64>,
1551
1552 max_soft_bundle_size: Option<u64>,
1555
1556 bridge_should_try_to_finalize_committee: Option<bool>,
1561
1562 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1568
1569 max_committee_members_count: Option<u64>,
1573
1574 deny_rule_update_max_entries_per_tx: Option<u64>,
1579
1580 deny_rule_removal_grace_round_floor: Option<u64>,
1585
1586 consensus_gc_depth: Option<u32>,
1589
1590 consensus_max_acknowledgments_per_block: Option<u32>,
1596
1597 max_congestion_limit_overshoot_per_commit: Option<u64>,
1602
1603 max_concurrent_execution_workers: Option<u16>,
1610
1611 scorer_version: Option<u16>,
1620
1621 auth_context_digest_cost_base: Option<u64>,
1624 auth_context_tx_data_bytes_cost_base: Option<u64>,
1626 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1627 auth_context_tx_commands_cost_base: Option<u64>,
1629 auth_context_tx_commands_cost_per_byte: Option<u64>,
1630 auth_context_tx_inputs_cost_base: Option<u64>,
1632 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1633 auth_context_replace_cost_base: Option<u64>,
1636 auth_context_replace_cost_per_byte: Option<u64>,
1637 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1641
1642 consensus_commits_per_schedule: Option<u32>,
1645
1646 min_validator_count: Option<u64>,
1649
1650 max_validator_count: Option<u64>,
1654
1655 min_validator_joining_stake: Option<u64>,
1659
1660 validator_low_stake_threshold: Option<u64>,
1665
1666 validator_very_low_stake_threshold: Option<u64>,
1670
1671 validator_low_stake_grace_period: Option<u64>,
1675
1676 consensus_leader_schedule_window_size: Option<u32>,
1680
1681 max_move_system_package_size: Option<u64>,
1686}
1687
1688impl ProtocolConfig {
1690 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1703 self.feature_flags
1704 .disable_invariant_violation_check_in_swap_loc
1705 }
1706
1707 pub fn no_extraneous_module_bytes(&self) -> bool {
1708 self.feature_flags.no_extraneous_module_bytes
1709 }
1710
1711 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1712 self.feature_flags.consensus_transaction_ordering
1713 }
1714
1715 pub fn dkg_version(&self) -> u64 {
1716 self.random_beacon_dkg_version.unwrap_or(1)
1718 }
1719
1720 pub fn hardened_otw_check(&self) -> bool {
1721 self.feature_flags.hardened_otw_check
1722 }
1723
1724 pub fn enable_poseidon(&self) -> bool {
1725 self.feature_flags.enable_poseidon
1726 }
1727
1728 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1729 self.feature_flags.enable_group_ops_native_function_msm
1730 }
1731
1732 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1733 self.feature_flags.per_object_congestion_control_mode
1734 }
1735
1736 pub fn consensus_choice(&self) -> ConsensusChoice {
1737 self.feature_flags.consensus_choice
1738 }
1739
1740 pub fn consensus_network(&self) -> ConsensusNetwork {
1741 self.feature_flags.consensus_network
1742 }
1743
1744 pub fn enable_vdf(&self) -> bool {
1745 self.feature_flags.enable_vdf
1746 }
1747
1748 pub fn passkey_auth(&self) -> bool {
1749 self.feature_flags.passkey_auth
1750 }
1751
1752 pub fn max_transaction_size_bytes(&self) -> u64 {
1753 self.consensus_max_transaction_size_bytes
1755 .unwrap_or(256 * 1024)
1756 }
1757
1758 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1759 if cfg!(msim) {
1760 256 * 1024
1761 } else {
1762 self.consensus_max_transactions_in_block_bytes
1763 .unwrap_or(512 * 1024)
1764 }
1765 }
1766
1767 pub fn max_num_transactions_in_block(&self) -> u64 {
1768 if cfg!(msim) {
1769 8
1770 } else {
1771 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1772 }
1773 }
1774
1775 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1776 self.feature_flags.rethrow_serialization_type_layout_errors
1777 }
1778
1779 pub fn relocate_event_module(&self) -> bool {
1780 self.feature_flags.relocate_event_module
1781 }
1782
1783 pub fn protocol_defined_base_fee(&self) -> bool {
1784 self.feature_flags.protocol_defined_base_fee
1785 }
1786
1787 pub fn uncompressed_g1_group_elements(&self) -> bool {
1788 self.feature_flags.uncompressed_g1_group_elements
1789 }
1790
1791 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1792 self.feature_flags
1793 .disallow_new_modules_in_deps_only_packages
1794 }
1795
1796 pub fn native_charging_v2(&self) -> bool {
1797 self.feature_flags.native_charging_v2
1798 }
1799
1800 pub fn consensus_round_prober(&self) -> bool {
1801 self.feature_flags.consensus_round_prober
1802 }
1803
1804 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1805 self.feature_flags
1806 .consensus_distributed_vote_scoring_strategy
1807 }
1808
1809 pub fn gc_depth(&self) -> u32 {
1810 if cfg!(msim) {
1811 min(5, self.consensus_gc_depth.unwrap_or(0))
1813 } else {
1814 self.consensus_gc_depth.unwrap_or(0)
1815 }
1816 }
1817
1818 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1819 let res = self.feature_flags.consensus_linearize_subdag_v2;
1820 assert!(
1821 !res || self.gc_depth() > 0,
1822 "The consensus linearize sub dag V2 requires GC to be enabled"
1823 );
1824 res
1825 }
1826
1827 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1828 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1829 }
1830
1831 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1832 2 * committee_size
1833 }
1834
1835 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1836 committee_size
1837 }
1838
1839 pub fn variant_nodes(&self) -> bool {
1840 self.feature_flags.variant_nodes
1841 }
1842
1843 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1844 self.feature_flags.consensus_smart_ancestor_selection
1845 }
1846
1847 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1848 self.feature_flags
1849 .consensus_round_prober_probe_accepted_rounds
1850 }
1851
1852 pub fn consensus_zstd_compression(&self) -> bool {
1853 self.feature_flags.consensus_zstd_compression
1854 }
1855
1856 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1857 self.feature_flags
1858 .congestion_control_min_free_execution_slot
1859 }
1860
1861 pub fn accept_passkey_in_multisig(&self) -> bool {
1862 self.feature_flags.accept_passkey_in_multisig
1863 }
1864
1865 pub fn consensus_batched_block_sync(&self) -> bool {
1866 self.feature_flags.consensus_batched_block_sync
1867 }
1868
1869 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1872 self.feature_flags
1873 .congestion_control_gas_price_feedback_mechanism
1874 }
1875
1876 pub fn validate_identifier_inputs(&self) -> bool {
1877 self.feature_flags.validate_identifier_inputs
1878 }
1879
1880 pub fn minimize_child_object_mutations(&self) -> bool {
1881 self.feature_flags.minimize_child_object_mutations
1882 }
1883
1884 pub fn dependency_linkage_error(&self) -> bool {
1885 self.feature_flags.dependency_linkage_error
1886 }
1887
1888 pub fn additional_multisig_checks(&self) -> bool {
1889 self.feature_flags.additional_multisig_checks
1890 }
1891
1892 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1893 0
1896 }
1897
1898 pub fn normalize_ptb_arguments(&self) -> bool {
1899 self.feature_flags.normalize_ptb_arguments
1900 }
1901
1902 pub fn select_committee_from_eligible_validators(&self) -> bool {
1903 let res = self.feature_flags.select_committee_from_eligible_validators;
1904 assert!(
1905 !res || (self.protocol_defined_base_fee()
1906 && self.max_committee_members_count_as_option().is_some()),
1907 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1908 );
1909 res
1910 }
1911
1912 pub fn track_non_committee_eligible_validators(&self) -> bool {
1913 self.feature_flags.track_non_committee_eligible_validators
1914 }
1915
1916 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1917 let res = self
1918 .feature_flags
1919 .select_committee_supporting_next_epoch_version;
1920 assert!(
1921 !res || (self.track_non_committee_eligible_validators()
1922 && self.select_committee_from_eligible_validators()),
1923 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1924 );
1925 res
1926 }
1927
1928 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1929 let res = self
1930 .feature_flags
1931 .consensus_median_timestamp_with_checkpoint_enforcement;
1932 assert!(
1933 !res || self.gc_depth() > 0,
1934 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1935 );
1936 res
1937 }
1938
1939 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1940 self.feature_flags
1941 .consensus_commit_transactions_only_for_traversed_headers
1942 }
1943
1944 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1947 self.feature_flags
1948 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1949 }
1950
1951 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1954 self.feature_flags
1955 .separate_gas_price_feedback_mechanism_for_randomness
1956 }
1957
1958 pub fn metadata_in_module_bytes(&self) -> bool {
1959 self.feature_flags.metadata_in_module_bytes
1960 }
1961
1962 pub fn publish_package_metadata(&self) -> bool {
1963 self.feature_flags.publish_package_metadata
1964 }
1965
1966 pub fn enable_move_authentication(&self) -> bool {
1967 self.feature_flags.enable_move_authentication
1968 }
1969
1970 pub fn additional_borrow_checks(&self) -> bool {
1971 self.feature_flags.additional_borrow_checks
1972 }
1973
1974 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1975 let enable_move_authentication_for_sponsor =
1976 self.feature_flags.enable_move_authentication_for_sponsor;
1977 assert!(
1978 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1979 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1980 );
1981 enable_move_authentication_for_sponsor
1982 }
1983
1984 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1985 self.feature_flags.pass_validator_scores_to_advance_epoch
1986 }
1987
1988 pub fn calculate_validator_scores(&self) -> bool {
1989 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1990 assert!(
1991 !calculate_validator_scores || self.scorer_version.is_some(),
1992 "calculate_validator_scores requires scorer_version to be set"
1993 );
1994 calculate_validator_scores
1995 }
1996
1997 pub fn adjust_rewards_by_score(&self) -> bool {
1998 let adjust = self.feature_flags.adjust_rewards_by_score;
1999 assert!(
2000 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
2001 "adjust_rewards_by_score requires scorer_version to be set"
2002 );
2003 adjust
2004 }
2005
2006 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
2007 let pass = self
2008 .feature_flags
2009 .pass_calculated_validator_scores_to_advance_epoch;
2010 assert!(
2011 !pass
2012 || (self.pass_validator_scores_to_advance_epoch()
2013 && self.calculate_validator_scores()),
2014 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
2015 );
2016 pass
2017 }
2018 pub fn consensus_fast_commit_sync(&self) -> bool {
2019 let res = self.feature_flags.consensus_fast_commit_sync;
2020 assert!(
2021 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
2022 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
2023 );
2024 res
2025 }
2026
2027 pub fn consensus_block_restrictions(&self) -> bool {
2028 self.feature_flags.consensus_block_restrictions
2029 }
2030
2031 pub fn move_native_tx_context(&self) -> bool {
2032 self.feature_flags.move_native_tx_context
2033 }
2034
2035 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
2036 let pre_consensus_sponsor_only_move_authentication = self
2037 .feature_flags
2038 .pre_consensus_sponsor_only_move_authentication;
2039 if pre_consensus_sponsor_only_move_authentication {
2040 assert!(
2041 self.enable_move_authentication(),
2042 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
2043 );
2044 assert!(
2045 self.enable_move_authentication_for_sponsor(),
2046 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
2047 );
2048 }
2049 pre_consensus_sponsor_only_move_authentication
2050 }
2051
2052 pub fn consensus_starfish_speed(&self) -> bool {
2053 let res = self.feature_flags.consensus_starfish_speed;
2054 assert!(
2055 !res || self.consensus_fast_commit_sync(),
2056 "consensus_starfish_speed requires consensus_fast_commit_sync to be enabled"
2057 );
2058 res
2059 }
2060
2061 pub fn always_advance_dkg_to_resolution(&self) -> bool {
2062 self.feature_flags.always_advance_dkg_to_resolution
2063 }
2064
2065 pub fn enable_pcool_flow(&self) -> bool {
2066 self.feature_flags.enable_pcool_flow
2067 }
2068
2069 pub fn pcool_skip_immutable_object_locks(&self) -> bool {
2070 self.feature_flags.pcool_skip_immutable_object_locks
2071 }
2072
2073 pub fn pcool_verifier_limits_from_protocol_config(&self) -> bool {
2076 self.feature_flags
2077 .pcool_verifier_limits_from_protocol_config
2078 }
2079
2080 pub fn validator_metadata_verify_v2(&self) -> bool {
2081 self.feature_flags.validator_metadata_verify_v2
2082 }
2083
2084 pub fn commits_per_schedule(&self) -> u32 {
2085 let commits_per_schedule = if cfg!(msim) {
2086 min(10, self.consensus_commits_per_schedule.unwrap_or(300))
2088 } else {
2089 self.consensus_commits_per_schedule.unwrap_or(300)
2090 };
2091 assert!(
2092 commits_per_schedule > 0,
2093 "consensus_commits_per_schedule must be greater than 0"
2094 );
2095 commits_per_schedule
2096 }
2097
2098 pub fn leader_schedule_window_size(&self) -> u32 {
2099 if cfg!(msim) {
2100 min(
2103 20,
2104 self.consensus_leader_schedule_window_size.unwrap_or(600),
2105 )
2106 } else {
2107 self.consensus_leader_schedule_window_size.unwrap_or(600)
2108 }
2109 }
2110
2111 pub fn consensus_enable_sliding_window_leader_schedule(&self) -> bool {
2112 let res = self
2113 .feature_flags
2114 .consensus_enable_sliding_window_leader_schedule;
2115 assert!(
2116 !res || self.leader_schedule_window_size() >= self.commits_per_schedule(),
2117 "consensus_enable_sliding_window_leader_schedule requires window_size >= commits_per_schedule"
2118 );
2119 res
2120 }
2121
2122 pub fn consensus_enable_absolute_score_leader_schedule(&self) -> bool {
2123 self.feature_flags
2124 .consensus_enable_absolute_score_leader_schedule
2125 }
2126
2127 pub fn max_ptb_value_size_v2(&self) -> bool {
2128 self.feature_flags.max_ptb_value_size_v2
2129 }
2130
2131 pub fn deny_rule_governance(&self) -> bool {
2132 self.feature_flags.deny_rule_governance
2133 }
2134
2135 pub fn deny_rule_governance_on_chain(&self) -> bool {
2136 self.feature_flags.deny_rule_governance_on_chain
2137 }
2138
2139 pub fn deny_authenticator_packages(&self) -> bool {
2140 self.feature_flags.deny_authenticator_packages
2141 }
2142
2143 pub fn package_metadata_with_dynamic_module_metadata(&self) -> bool {
2144 let res = self
2145 .feature_flags
2146 .package_metadata_with_dynamic_module_metadata;
2147 assert!(
2148 !res || self.publish_package_metadata(),
2149 "package_metadata_with_dynamic_module_metadata requires publish_package_metadata to be enabled"
2150 );
2151 res
2152 }
2153
2154 pub fn report_move_authentication_error(&self) -> bool {
2155 let report_move_authentication_error = self.feature_flags.report_move_authentication_error;
2156 assert!(
2157 !report_move_authentication_error || self.enable_move_authentication(),
2158 "report_move_authentication_error requires enable_move_authentication to be set"
2159 );
2160 report_move_authentication_error
2161 }
2162
2163 pub fn concurrent_execution_workers(&self) -> Option<u16> {
2167 let res = self.max_concurrent_execution_workers;
2168 assert!(
2169 res.is_none() || self.enable_pcool_flow(),
2170 "max_concurrent_execution_workers requires enable_pcool_flow to be enabled"
2171 );
2172 assert!(
2173 res.is_none()
2174 || self
2175 .max_accumulated_txn_cost_per_object_in_mysticeti_commit
2176 .is_some(),
2177 "max_concurrent_execution_workers requires per-object congestion control \
2178 (max_accumulated_txn_cost_per_object_in_mysticeti_commit) to be enabled"
2179 );
2180 assert!(
2181 res.is_none() || self.congestion_control_gas_price_feedback_mechanism(),
2182 "max_concurrent_execution_workers requires the gas price feedback mechanism \
2183 (congestion_control_gas_price_feedback_mechanism), which carries the suggested \
2184 gas price of an execution-worker congestion cancellation"
2185 );
2186 assert!(
2187 res.is_none() || !self.separate_gas_price_feedback_mechanism_for_randomness(),
2188 "max_concurrent_execution_workers implies a single congestion tracker and suggested \
2189 gas price calculator for all transactions, which is incompatible with \
2190 separate_gas_price_feedback_mechanism_for_randomness"
2191 );
2192 assert!(
2193 res != Some(0),
2194 "max_concurrent_execution_workers must be positive when set"
2195 );
2196 res
2197 }
2198
2199 pub fn allow_unbounded_system_objects(&self) -> bool {
2200 self.feature_flags.allow_unbounded_system_objects
2201 }
2202
2203 pub fn reject_immutable_account_objects(&self) -> bool {
2204 let reject_immutable_account_objects = self.feature_flags.reject_immutable_account_objects;
2205 assert!(
2206 !reject_immutable_account_objects || self.enable_move_authentication(),
2207 "reject_immutable_account_objects requires enable_move_authentication to be set"
2208 );
2209 reject_immutable_account_objects
2210 }
2211
2212 pub fn reject_immutable_account_creation(&self) -> bool {
2213 let reject_immutable_account_creation =
2214 self.feature_flags.reject_immutable_account_creation;
2215 assert!(
2216 !reject_immutable_account_creation || self.reject_immutable_account_objects(),
2217 "reject_immutable_account_creation requires reject_immutable_account_objects to be set"
2218 );
2219 reject_immutable_account_creation
2220 }
2221
2222 pub fn validate_input_object_versions(&self) -> bool {
2223 self.feature_flags.validate_input_object_versions
2224 }
2225
2226 pub fn check_canonical_module_version_header(&self) -> bool {
2227 self.feature_flags.check_canonical_module_version_header
2228 }
2229
2230 pub fn disallow_randomness_in_move_authenticator(&self) -> bool {
2231 self.feature_flags.disallow_randomness_in_move_authenticator
2232 }
2233
2234 pub fn check_cyclic_dependencies(&self) -> bool {
2235 self.feature_flags.check_cyclic_dependencies
2236 }
2237
2238 pub fn deprecate_global_storage_ops_during_deserialization(&self) -> bool {
2239 self.feature_flags
2240 .deprecate_global_storage_ops_during_deserialization
2241 }
2242}
2243
2244#[cfg(not(msim))]
2245static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2246
2247#[cfg(msim)]
2249thread_local! {
2250 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2251}
2252
2253impl ProtocolConfig {
2255 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
2258 assert!(
2260 version >= ProtocolVersion::MIN,
2261 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
2262 version,
2263 ProtocolVersion::MIN.0,
2264 );
2265 assert!(
2266 version <= ProtocolVersion::MAX_ALLOWED,
2267 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
2268 version,
2269 ProtocolVersion::MAX_ALLOWED.0,
2270 );
2271
2272 let mut ret = Self::get_for_version_impl(version, chain);
2273 ret.version = version;
2274
2275 ret = CONFIG_OVERRIDE.with(|ovr| {
2276 if let Some(override_fn) = &*ovr.borrow() {
2277 warn!(
2278 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
2279 );
2280 override_fn(version, ret)
2281 } else {
2282 ret
2283 }
2284 });
2285
2286 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
2287 warn!(
2288 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
2289 );
2290
2291 let overrides: ProtocolConfigOptional =
2293 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
2294 .expect("failed to parse ProtocolConfig override env variables");
2295 overrides.apply_to(&mut ret);
2296
2297 let feature_flag_overrides: FeatureFlagsOptional =
2299 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_FEATURE_FLAGS_OVERRIDE")
2300 .expect("failed to parse ProtocolConfig feature flags override env variables");
2301
2302 feature_flag_overrides.apply_to(&mut ret.feature_flags);
2303 }
2304
2305 assert!(
2307 !ret.feature_flags.deny_rule_governance_on_chain
2308 || ret.feature_flags.deny_rule_governance,
2309 "deny_rule_governance_on_chain requires deny_rule_governance"
2310 );
2311 assert!(
2316 !ret.feature_flags.pcool_verifier_limits_from_protocol_config
2317 || ret.max_meter_ticks_regex_reference_safety.is_some(),
2318 "pcool_verifier_limits_from_protocol_config requires \
2319 max_meter_ticks_regex_reference_safety"
2320 );
2321 assert!(
2324 !ret.feature_flags.deny_rule_governance_on_chain
2325 || (ret.deny_rule_update_max_entries_per_tx.is_some()
2326 && ret.deny_rule_removal_grace_round_floor.is_some()),
2327 "deny_rule_governance_on_chain requires deny_rule_update_max_entries_per_tx and deny_rule_removal_grace_round_floor"
2328 );
2329 const DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING: u64 = 2048;
2337 assert!(
2338 ret.deny_rule_update_max_entries_per_tx
2339 .is_none_or(|max_entries| {
2340 max_entries > 0
2341 && max_entries <= DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING
2342 && [
2343 ret.max_num_new_move_object_ids_system_tx,
2344 ret.max_num_deleted_move_object_ids_system_tx,
2345 ret.object_runtime_max_num_cached_objects_system_tx,
2346 ret.object_runtime_max_num_store_entries_system_tx,
2347 ]
2348 .iter()
2349 .all(|limit| limit.is_none_or(|limit| max_entries <= limit))
2350 }),
2351 "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"
2352 );
2353
2354 ret
2355 }
2356
2357 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
2360 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
2361 let mut ret = Self::get_for_version_impl(version, chain);
2362 ret.version = version;
2363 Some(ret)
2364 } else {
2365 None
2366 }
2367 }
2368
2369 #[cfg(not(msim))]
2370 pub fn poison_get_for_min_version() {
2371 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
2372 }
2373
2374 #[cfg(not(msim))]
2375 fn load_poison_get_for_min_version() -> bool {
2376 POISON_VERSION_METHODS.load(Ordering::Relaxed)
2377 }
2378
2379 #[cfg(msim)]
2380 pub fn poison_get_for_min_version() {
2381 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
2382 }
2383
2384 #[cfg(msim)]
2385 fn load_poison_get_for_min_version() -> bool {
2386 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
2387 }
2388
2389 pub fn convert_type_argument_error(&self) -> bool {
2390 self.feature_flags.convert_type_argument_error
2391 }
2392
2393 pub fn get_for_min_version() -> Self {
2397 if Self::load_poison_get_for_min_version() {
2398 panic!("get_for_min_version called on validator");
2399 }
2400 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
2401 }
2402
2403 #[expect(non_snake_case)]
2414 pub fn get_for_max_version_UNSAFE() -> Self {
2415 if Self::load_poison_get_for_min_version() {
2416 panic!("get_for_max_version_UNSAFE called on validator");
2417 }
2418 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
2419 }
2420
2421 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
2422 #[cfg(msim)]
2423 {
2424 if version > ProtocolVersion::MAX {
2426 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
2427 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
2428 return config;
2429 }
2430 }
2431
2432 let mut cfg = Self {
2436 version,
2437
2438 feature_flags: Default::default(),
2439
2440 max_tx_size_bytes: Some(128 * 1024),
2441 max_input_objects: Some(2048),
2444 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
2445 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
2446 max_gas_payment_objects: Some(256),
2447 max_modules_in_publish: Some(64),
2448 max_package_dependencies: Some(32),
2449 max_arguments: Some(512),
2450 max_type_arguments: Some(16),
2451 max_type_argument_depth: Some(16),
2452 max_pure_argument_size: Some(16 * 1024),
2453 max_programmable_tx_commands: Some(1024),
2454 move_binary_format_version: Some(7),
2455 min_move_binary_format_version: Some(6),
2456 binary_module_handles: Some(100),
2457 binary_struct_handles: Some(300),
2458 binary_function_handles: Some(1500),
2459 binary_function_instantiations: Some(750),
2460 binary_signatures: Some(1000),
2461 binary_constant_pool: Some(4000),
2462 binary_identifiers: Some(10000),
2463 binary_address_identifiers: Some(100),
2464 binary_struct_defs: Some(200),
2465 binary_struct_def_instantiations: Some(100),
2466 binary_function_defs: Some(1000),
2467 binary_field_handles: Some(500),
2468 binary_field_instantiations: Some(250),
2469 binary_friend_decls: Some(100),
2470 binary_enum_defs: None,
2471 binary_enum_def_instantiations: None,
2472 binary_variant_handles: None,
2473 binary_variant_instantiation_handles: None,
2474 max_move_object_size: Some(250 * 1024),
2475 max_move_package_size: Some(100 * 1024),
2476 max_publish_or_upgrade_per_ptb: Some(5),
2477 max_auth_gas: None,
2479 max_tx_gas: Some(50_000_000_000),
2481 max_gas_price: Some(100_000),
2482 max_gas_computation_bucket: Some(5_000_000),
2483 max_loop_depth: Some(5),
2484 max_generic_instantiation_length: Some(32),
2485 max_function_parameters: Some(128),
2486 max_basic_blocks: Some(1024),
2487 max_value_stack_size: Some(1024),
2488 max_type_nodes: Some(256),
2489 max_push_size: Some(10000),
2490 max_struct_definitions: Some(200),
2491 max_function_definitions: Some(1000),
2492 max_fields_in_struct: Some(32),
2493 max_dependency_depth: Some(100),
2494 max_num_event_emit: Some(1024),
2495 max_num_new_move_object_ids: Some(2048),
2496 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
2497 max_num_deleted_move_object_ids: Some(2048),
2498 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
2499 max_num_transferred_move_object_ids: Some(2048),
2500 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
2501 max_event_emit_size: Some(250 * 1024),
2502 max_move_vector_len: Some(256 * 1024),
2503 max_type_to_layout_nodes: None,
2504 max_ptb_value_size: None,
2505
2506 max_back_edges_per_function: Some(10_000),
2507 max_back_edges_per_module: Some(10_000),
2508
2509 max_verifier_meter_ticks_per_function: Some(16_000_000),
2510
2511 max_meter_ticks_per_module: Some(16_000_000),
2512 max_meter_ticks_per_package: Some(16_000_000),
2513 max_meter_ticks_regex_reference_safety: None,
2514
2515 object_runtime_max_num_cached_objects: Some(1000),
2516 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2517 object_runtime_max_num_store_entries: Some(1000),
2518 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2519 base_tx_cost_fixed: Some(1_000),
2521 package_publish_cost_fixed: Some(1_000),
2522 base_tx_cost_per_byte: Some(0),
2523 package_publish_cost_per_byte: Some(80),
2524 obj_access_cost_read_per_byte: Some(15),
2525 obj_access_cost_mutate_per_byte: Some(40),
2526 obj_access_cost_delete_per_byte: Some(40),
2527 obj_access_cost_verify_per_byte: Some(200),
2528 obj_data_cost_refundable: Some(100),
2529 obj_metadata_cost_non_refundable: Some(50),
2530 gas_model_version: Some(1),
2531 storage_rebate_rate: Some(10000),
2532 reward_slashing_rate: Some(10000),
2534 storage_gas_price: Some(76),
2535 base_gas_price: None,
2536 validator_target_reward: Some(767_000 * 1_000_000_000),
2539 max_transactions_per_checkpoint: Some(10_000),
2540 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2541
2542 buffer_stake_for_protocol_upgrade_bps: Some(5000),
2544
2545 address_from_bytes_cost_base: Some(52),
2549 address_to_u256_cost_base: Some(52),
2551 address_from_u256_cost_base: Some(52),
2553
2554 config_read_setting_impl_cost_base: Some(100),
2557 config_read_setting_impl_cost_per_byte: Some(40),
2558
2559 dynamic_field_hash_type_and_key_cost_base: Some(100),
2563 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
2564 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
2565 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
2566 dynamic_field_add_child_object_cost_base: Some(100),
2569 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2570 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2571 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2572 dynamic_field_borrow_child_object_cost_base: Some(100),
2575 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2576 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2577 dynamic_field_remove_child_object_cost_base: Some(100),
2580 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2581 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2582 dynamic_field_has_child_object_cost_base: Some(100),
2585 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2588 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2589 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2590
2591 event_emit_cost_base: Some(52),
2594 event_emit_value_size_derivation_cost_per_byte: Some(2),
2595 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2596 event_emit_output_cost_per_byte: Some(10),
2597
2598 object_borrow_uid_cost_base: Some(52),
2601 object_delete_impl_cost_base: Some(52),
2603 object_record_new_uid_cost_base: Some(52),
2605
2606 transfer_transfer_internal_cost_base: Some(52),
2610 transfer_freeze_object_cost_base: Some(52),
2612 transfer_share_object_cost_base: Some(52),
2614 transfer_receive_object_cost_base: Some(52),
2615
2616 tx_context_derive_id_cost_base: Some(52),
2620 tx_context_fresh_id_cost_base: None,
2621 tx_context_sender_cost_base: None,
2622 tx_context_digest_cost_base: None,
2623 tx_context_epoch_cost_base: None,
2624 tx_context_epoch_timestamp_ms_cost_base: None,
2625 tx_context_sponsor_cost_base: None,
2626 tx_context_rgp_cost_base: None,
2627 tx_context_gas_price_cost_base: None,
2628 tx_context_gas_budget_cost_base: None,
2629 tx_context_ids_created_cost_base: None,
2630 tx_context_replace_cost_base: None,
2631
2632 types_is_one_time_witness_cost_base: Some(52),
2635 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2636 types_is_one_time_witness_type_cost_per_byte: Some(2),
2637
2638 validator_validate_metadata_cost_base: Some(52),
2642 validator_validate_metadata_data_cost_per_byte: Some(2),
2643
2644 crypto_invalid_arguments_cost: Some(100),
2646 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2648 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2649 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2650
2651 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2653 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2654 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2655
2656 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2658 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2659 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2660 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2661 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2662 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2663
2664 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2666
2667 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2669 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2670 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2671 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2672 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2673 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2674
2675 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2677 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2678 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2679 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2680 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2681 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2682
2683 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2685 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2686 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2687 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2688 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2689 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2690
2691 ecvrf_ecvrf_verify_cost_base: Some(52),
2693 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2694 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2695
2696 ed25519_ed25519_verify_cost_base: Some(52),
2698 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2699 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2700
2701 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2703 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2704
2705 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2707 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2708 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2709 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2710 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2711
2712 hash_blake2b256_cost_base: Some(52),
2714 hash_blake2b256_data_cost_per_byte: Some(2),
2715 hash_blake2b256_data_cost_per_block: Some(2),
2716 hash_keccak256_cost_base: Some(52),
2718 hash_keccak256_data_cost_per_byte: Some(2),
2719 hash_keccak256_data_cost_per_block: Some(2),
2720
2721 poseidon_bn254_cost_base: None,
2722 poseidon_bn254_cost_per_block: None,
2723
2724 hmac_hmac_sha3_256_cost_base: Some(52),
2726 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2727 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2728
2729 group_ops_bls12381_decode_scalar_cost: Some(52),
2731 group_ops_bls12381_decode_g1_cost: Some(52),
2732 group_ops_bls12381_decode_g2_cost: Some(52),
2733 group_ops_bls12381_decode_gt_cost: Some(52),
2734 group_ops_bls12381_scalar_add_cost: Some(52),
2735 group_ops_bls12381_g1_add_cost: Some(52),
2736 group_ops_bls12381_g2_add_cost: Some(52),
2737 group_ops_bls12381_gt_add_cost: Some(52),
2738 group_ops_bls12381_scalar_sub_cost: Some(52),
2739 group_ops_bls12381_g1_sub_cost: Some(52),
2740 group_ops_bls12381_g2_sub_cost: Some(52),
2741 group_ops_bls12381_gt_sub_cost: Some(52),
2742 group_ops_bls12381_scalar_mul_cost: Some(52),
2743 group_ops_bls12381_g1_mul_cost: Some(52),
2744 group_ops_bls12381_g2_mul_cost: Some(52),
2745 group_ops_bls12381_gt_mul_cost: Some(52),
2746 group_ops_bls12381_scalar_div_cost: Some(52),
2747 group_ops_bls12381_g1_div_cost: Some(52),
2748 group_ops_bls12381_g2_div_cost: Some(52),
2749 group_ops_bls12381_gt_div_cost: Some(52),
2750 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2751 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2752 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2753 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2754 group_ops_bls12381_g1_msm_base_cost: Some(52),
2755 group_ops_bls12381_g2_msm_base_cost: Some(52),
2756 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2757 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2758 group_ops_bls12381_msm_max_len: Some(32),
2759 group_ops_bls12381_pairing_cost: Some(52),
2760 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2761 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2762 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2763 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2764 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2765
2766 #[allow(deprecated)]
2768 check_zklogin_id_cost_base: Some(200),
2769 #[allow(deprecated)]
2770 check_zklogin_issuer_cost_base: Some(200),
2772
2773 vdf_verify_vdf_cost: None,
2774 vdf_hash_to_input_cost: None,
2775
2776 bcs_per_byte_serialized_cost: Some(2),
2777 bcs_legacy_min_output_size_cost: Some(1),
2778 bcs_failure_cost: Some(52),
2779 hash_sha2_256_base_cost: Some(52),
2780 hash_sha2_256_per_byte_cost: Some(2),
2781 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2782 hash_sha3_256_base_cost: Some(52),
2783 hash_sha3_256_per_byte_cost: Some(2),
2784 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2785 type_name_get_base_cost: Some(52),
2786 type_name_get_per_byte_cost: Some(2),
2787 string_check_utf8_base_cost: Some(52),
2788 string_check_utf8_per_byte_cost: Some(2),
2789 string_is_char_boundary_base_cost: Some(52),
2790 string_sub_string_base_cost: Some(52),
2791 string_sub_string_per_byte_cost: Some(2),
2792 string_index_of_base_cost: Some(52),
2793 string_index_of_per_byte_pattern_cost: Some(2),
2794 string_index_of_per_byte_searched_cost: Some(2),
2795 vector_empty_base_cost: Some(52),
2796 vector_length_base_cost: Some(52),
2797 vector_push_back_base_cost: Some(52),
2798 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2799 vector_borrow_base_cost: Some(52),
2800 vector_pop_back_base_cost: Some(52),
2801 vector_destroy_empty_base_cost: Some(52),
2802 vector_swap_base_cost: Some(52),
2803 debug_print_base_cost: Some(52),
2804 debug_print_stack_trace_base_cost: Some(52),
2805
2806 max_size_written_objects: Some(5 * 1000 * 1000),
2807 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2810
2811 max_move_identifier_len: Some(128),
2813 max_move_value_depth: Some(128),
2814 max_move_enum_variants: None,
2815
2816 gas_rounding_step: Some(1_000),
2817
2818 execution_version: Some(1),
2819
2820 max_event_emit_size_total: Some(
2823 256 * 250 * 1024, ),
2825
2826 consensus_bad_nodes_stake_threshold: Some(20),
2833
2834 #[allow(deprecated)]
2836 max_jwk_votes_per_validator_per_epoch: Some(240),
2837
2838 #[allow(deprecated)]
2839 max_age_of_jwk_in_epochs: Some(1),
2840
2841 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2845
2846 random_beacon_reduction_allowed_delta: Some(800),
2847
2848 random_beacon_reduction_lower_bound: Some(1000),
2849 random_beacon_dkg_timeout_round: Some(3000),
2850 random_beacon_min_round_interval_ms: Some(500),
2851
2852 random_beacon_dkg_version: Some(1),
2853
2854 consensus_max_num_transactions_in_block: Some(512),
2858
2859 max_deferral_rounds_for_congestion_control: Some(10),
2860
2861 min_checkpoint_interval_ms: Some(200),
2862
2863 checkpoint_rate_window_size: None,
2864
2865 checkpoint_summary_version_specific_data: Some(1),
2866
2867 max_soft_bundle_size: Some(5),
2868
2869 bridge_should_try_to_finalize_committee: None,
2870
2871 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2872
2873 max_committee_members_count: None,
2874 deny_rule_update_max_entries_per_tx: None,
2875 deny_rule_removal_grace_round_floor: None,
2876
2877 consensus_gc_depth: None,
2878
2879 consensus_max_acknowledgments_per_block: None,
2880
2881 max_congestion_limit_overshoot_per_commit: None,
2882
2883 max_concurrent_execution_workers: None,
2884
2885 scorer_version: None,
2886
2887 auth_context_digest_cost_base: None,
2889 auth_context_tx_data_bytes_cost_base: None,
2890 auth_context_tx_data_bytes_cost_per_byte: None,
2891 auth_context_tx_commands_cost_base: None,
2892 auth_context_tx_commands_cost_per_byte: None,
2893 auth_context_tx_inputs_cost_base: None,
2894 auth_context_tx_inputs_cost_per_byte: None,
2895 auth_context_replace_cost_base: None,
2896 auth_context_replace_cost_per_byte: None,
2897 auth_context_authenticator_function_info_v1_cost_base: None,
2898 consensus_commits_per_schedule: None,
2899 min_validator_count: None,
2900 max_validator_count: None,
2901 min_validator_joining_stake: None,
2902 validator_low_stake_threshold: None,
2903 validator_very_low_stake_threshold: None,
2904 validator_low_stake_grace_period: None,
2905 consensus_leader_schedule_window_size: None,
2906
2907 max_move_system_package_size: None,
2908 };
2911
2912 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2913
2914 {
2916 cfg.feature_flags
2917 .disable_invariant_violation_check_in_swap_loc = true;
2918 cfg.feature_flags.no_extraneous_module_bytes = true;
2919 cfg.feature_flags.hardened_otw_check = true;
2920 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2921 }
2922
2923 {
2925 #[allow(deprecated)]
2926 {
2927 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2928 }
2929 }
2930
2931 #[expect(deprecated)]
2935 {
2936 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2937 }
2938 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2940
2941 cfg.feature_flags.per_object_congestion_control_mode =
2942 PerObjectCongestionControlMode::TotalTxCount;
2943
2944 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2946
2947 if chain != Chain::Mainnet && chain != Chain::Testnet {
2949 cfg.feature_flags.enable_poseidon = true;
2950 cfg.poseidon_bn254_cost_base = Some(260);
2951 cfg.poseidon_bn254_cost_per_block = Some(10);
2952
2953 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2954
2955 cfg.feature_flags.enable_vdf = true;
2956 cfg.vdf_verify_vdf_cost = Some(1500);
2959 cfg.vdf_hash_to_input_cost = Some(100);
2960
2961 cfg.feature_flags.passkey_auth = true;
2962 }
2963
2964 for cur in 2..=version.0 {
2965 match cur {
2966 1 => unreachable!(),
2967 2 => {}
2969 3 => {
2970 cfg.feature_flags.relocate_event_module = true;
2971 }
2972 4 => {
2973 cfg.max_type_to_layout_nodes = Some(512);
2974 }
2975 5 => {
2976 cfg.feature_flags.protocol_defined_base_fee = true;
2977 cfg.base_gas_price = Some(1000);
2978
2979 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2980 cfg.feature_flags.convert_type_argument_error = true;
2981 cfg.feature_flags.native_charging_v2 = true;
2982
2983 if chain != Chain::Mainnet && chain != Chain::Testnet {
2984 cfg.feature_flags.uncompressed_g1_group_elements = true;
2985 }
2986
2987 cfg.gas_model_version = Some(2);
2988
2989 cfg.poseidon_bn254_cost_per_block = Some(388);
2990
2991 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2992 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2993 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2994 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2995 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2996 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2997 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2998 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2999
3000 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
3002 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
3003 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
3004 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
3005
3006 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
3007 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
3008 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
3009 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
3010 Some(8213);
3011 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
3012 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
3013 Some(9484);
3014
3015 cfg.hash_keccak256_cost_base = Some(10);
3016 cfg.hash_blake2b256_cost_base = Some(10);
3017
3018 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
3020 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
3021 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
3022 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
3023
3024 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
3025 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
3026 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
3027 cfg.group_ops_bls12381_gt_add_cost = Some(188);
3028
3029 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
3030 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
3031 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
3032 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
3033
3034 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
3035 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
3036 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
3037 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
3038
3039 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
3040 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
3041 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
3042 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
3043
3044 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
3045 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
3046
3047 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
3048 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
3049 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
3050 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
3051
3052 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
3053 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
3054 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
3055 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
3056 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
3057
3058 cfg.group_ops_bls12381_pairing_cost = Some(26897);
3059
3060 cfg.validator_validate_metadata_cost_base = Some(20000);
3061
3062 cfg.max_committee_members_count = Some(50);
3063 }
3064 6 => {
3065 cfg.max_ptb_value_size = Some(1024 * 1024);
3066 }
3067 7 => {
3068 }
3071 8 => {
3072 cfg.feature_flags.variant_nodes = true;
3073
3074 if chain != Chain::Mainnet {
3075 cfg.feature_flags.consensus_round_prober = true;
3077 cfg.feature_flags
3079 .consensus_distributed_vote_scoring_strategy = true;
3080 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
3081 cfg.feature_flags.consensus_smart_ancestor_selection = true;
3083 cfg.feature_flags
3085 .consensus_round_prober_probe_accepted_rounds = true;
3086 cfg.feature_flags.consensus_zstd_compression = true;
3088 cfg.consensus_gc_depth = Some(60);
3092 }
3093
3094 if chain != Chain::Testnet && chain != Chain::Mainnet {
3097 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
3098 }
3099 }
3100 9 => {
3101 if chain != Chain::Mainnet {
3102 cfg.feature_flags.consensus_smart_ancestor_selection = false;
3104 }
3105
3106 cfg.feature_flags.consensus_zstd_compression = true;
3108
3109 if chain != Chain::Testnet && chain != Chain::Mainnet {
3111 cfg.feature_flags.accept_passkey_in_multisig = true;
3112 }
3113
3114 cfg.bridge_should_try_to_finalize_committee = None;
3116 }
3117 10 => {
3118 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
3121
3122 cfg.max_committee_members_count = Some(80);
3124
3125 cfg.feature_flags.consensus_round_prober = true;
3127 cfg.feature_flags
3129 .consensus_round_prober_probe_accepted_rounds = true;
3130 cfg.feature_flags
3132 .consensus_distributed_vote_scoring_strategy = true;
3133 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
3135
3136 cfg.consensus_gc_depth = Some(60);
3141
3142 cfg.feature_flags.minimize_child_object_mutations = true;
3144
3145 if chain != Chain::Mainnet {
3146 cfg.feature_flags.consensus_batched_block_sync = true;
3148 }
3149
3150 if chain != Chain::Testnet && chain != Chain::Mainnet {
3151 cfg.feature_flags
3154 .congestion_control_gas_price_feedback_mechanism = true;
3155 }
3156
3157 cfg.feature_flags.validate_identifier_inputs = true;
3158 cfg.feature_flags.dependency_linkage_error = true;
3159 cfg.feature_flags.additional_multisig_checks = true;
3160 }
3161 11 => {
3162 }
3165 12 => {
3166 cfg.feature_flags
3169 .congestion_control_gas_price_feedback_mechanism = true;
3170
3171 cfg.feature_flags.normalize_ptb_arguments = true;
3173 }
3174 13 => {
3175 cfg.feature_flags.select_committee_from_eligible_validators = true;
3178 cfg.feature_flags.track_non_committee_eligible_validators = true;
3181
3182 if chain != Chain::Testnet && chain != Chain::Mainnet {
3183 cfg.feature_flags
3186 .select_committee_supporting_next_epoch_version = true;
3187 }
3188 }
3189 14 => {
3190 cfg.feature_flags.consensus_batched_block_sync = true;
3192
3193 if chain != Chain::Mainnet {
3194 cfg.feature_flags
3197 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3198 cfg.feature_flags
3202 .select_committee_supporting_next_epoch_version = true;
3203 }
3204 if chain != Chain::Testnet && chain != Chain::Mainnet {
3205 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3207 }
3208 }
3209 15 => {
3210 if chain != Chain::Mainnet && chain != Chain::Testnet {
3211 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3215 }
3216 }
3217 16 => {
3218 cfg.feature_flags
3221 .select_committee_supporting_next_epoch_version = true;
3222 cfg.feature_flags
3224 .consensus_commit_transactions_only_for_traversed_headers = true;
3225 }
3226 17 => {
3227 cfg.max_committee_members_count = Some(100);
3229 }
3230 18 => {
3231 if chain != Chain::Mainnet {
3232 cfg.feature_flags.passkey_auth = true;
3234 }
3235 }
3236 19 => {
3237 if chain != Chain::Testnet && chain != Chain::Mainnet {
3238 cfg.feature_flags
3241 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3242 cfg.feature_flags
3245 .separate_gas_price_feedback_mechanism_for_randomness = true;
3246 cfg.feature_flags.metadata_in_module_bytes = true;
3249 cfg.feature_flags.publish_package_metadata = true;
3250 cfg.feature_flags.enable_move_authentication = true;
3252 cfg.max_auth_gas = Some(250_000_000);
3254 cfg.transfer_receive_object_cost_base = Some(100);
3257 cfg.feature_flags.adjust_rewards_by_score = true;
3259 }
3260
3261 if chain != Chain::Mainnet {
3262 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3264
3265 cfg.feature_flags.calculate_validator_scores = true;
3267 cfg.scorer_version = Some(1);
3268 }
3269
3270 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
3272
3273 cfg.feature_flags.passkey_auth = true;
3275 }
3276 20 => {
3277 if chain != Chain::Testnet && chain != Chain::Mainnet {
3278 cfg.feature_flags
3280 .pass_calculated_validator_scores_to_advance_epoch = true;
3281 }
3282 }
3283 21 => {
3284 if chain != Chain::Testnet && chain != Chain::Mainnet {
3285 cfg.feature_flags.consensus_fast_commit_sync = true;
3287 }
3288 if chain != Chain::Mainnet {
3289 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3294 cfg.feature_flags
3297 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3298 cfg.feature_flags
3301 .separate_gas_price_feedback_mechanism_for_randomness = true;
3302 }
3303
3304 cfg.auth_context_digest_cost_base = Some(30);
3305 cfg.auth_context_tx_commands_cost_base = Some(30);
3306 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
3307 cfg.auth_context_tx_inputs_cost_base = Some(30);
3308 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
3309 cfg.auth_context_replace_cost_base = Some(30);
3310 cfg.auth_context_replace_cost_per_byte = Some(2);
3311
3312 if chain != Chain::Testnet && chain != Chain::Mainnet {
3313 cfg.max_auth_gas = Some(250_000);
3315 }
3316 }
3317 22 => {
3318 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3323 cfg.feature_flags
3326 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3327 cfg.feature_flags
3330 .separate_gas_price_feedback_mechanism_for_randomness = true;
3331
3332 if chain != Chain::Mainnet {
3333 cfg.feature_flags.metadata_in_module_bytes = true;
3336 cfg.feature_flags.publish_package_metadata = true;
3337 cfg.feature_flags.enable_move_authentication = true;
3339 cfg.max_auth_gas = Some(250_000);
3341 cfg.transfer_receive_object_cost_base = Some(100);
3344 }
3345
3346 if chain != Chain::Mainnet {
3347 cfg.feature_flags.consensus_fast_commit_sync = true;
3349 }
3350 }
3351 23 => {
3352 cfg.feature_flags.move_native_tx_context = true;
3354 cfg.tx_context_fresh_id_cost_base = Some(52);
3355 cfg.tx_context_sender_cost_base = Some(30);
3356 cfg.tx_context_digest_cost_base = Some(30);
3357 cfg.tx_context_epoch_cost_base = Some(30);
3358 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
3359 cfg.tx_context_sponsor_cost_base = Some(30);
3360 cfg.tx_context_rgp_cost_base = Some(30);
3361 cfg.tx_context_gas_price_cost_base = Some(30);
3362 cfg.tx_context_gas_budget_cost_base = Some(30);
3363 cfg.tx_context_ids_created_cost_base = Some(30);
3364 cfg.tx_context_replace_cost_base = Some(30);
3365 }
3366 24 => {
3367 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3369
3370 if chain != Chain::Testnet && chain != Chain::Mainnet {
3371 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3373 }
3374
3375 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
3378 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
3379
3380 cfg.feature_flags.additional_borrow_checks = true;
3382 }
3383 #[allow(deprecated)]
3384 25 => {
3385 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
3388 cfg.check_zklogin_id_cost_base = None;
3389 cfg.check_zklogin_issuer_cost_base = None;
3390 cfg.max_jwk_votes_per_validator_per_epoch = None;
3391 cfg.max_age_of_jwk_in_epochs = None;
3392 }
3393 26 => {
3394 }
3397 27 => {
3398 if chain != Chain::Mainnet {
3399 cfg.feature_flags.consensus_block_restrictions = true;
3402 }
3403
3404 if chain != Chain::Testnet && chain != Chain::Mainnet {
3405 cfg.feature_flags
3407 .pre_consensus_sponsor_only_move_authentication = true;
3408 }
3409 }
3410 28 => {
3411 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
3416
3417 cfg.feature_flags.metadata_in_module_bytes = true;
3420 cfg.feature_flags.publish_package_metadata = true;
3421 cfg.feature_flags.enable_move_authentication = true;
3423 cfg.transfer_receive_object_cost_base = Some(100);
3426
3427 if chain != Chain::Unknown {
3428 cfg.max_auth_gas = Some(20_000);
3430 }
3431
3432 if chain != Chain::Mainnet {
3433 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3435 cfg.feature_flags
3437 .pre_consensus_sponsor_only_move_authentication = true;
3438 }
3439 }
3440 29 => {
3441 cfg.feature_flags.always_advance_dkg_to_resolution = true;
3447
3448 cfg.feature_flags
3451 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3452
3453 cfg.feature_flags.consensus_fast_commit_sync = true;
3455 cfg.feature_flags.consensus_block_restrictions = true;
3459 }
3460 30 => {
3461 }
3469 31 => {
3470 cfg.feature_flags.validator_metadata_verify_v2 = true;
3471
3472 if chain != Chain::Mainnet && chain != Chain::Testnet {
3473 cfg.checkpoint_rate_window_size = Some(20);
3476 cfg.feature_flags
3479 .package_metadata_with_dynamic_module_metadata = true;
3480 cfg.feature_flags.consensus_starfish_speed = true;
3483 }
3484
3485 cfg.feature_flags.report_move_authentication_error = true;
3486 }
3487 32 => {
3488 cfg.min_validator_count = Some(4);
3492 cfg.max_validator_count = Some(150);
3493 cfg.min_validator_joining_stake = Some(2_000_000_000_000_000);
3494 cfg.validator_low_stake_threshold = Some(1_500_000_000_000_000);
3495 cfg.validator_very_low_stake_threshold = Some(1_000_000_000_000_000);
3496 cfg.validator_low_stake_grace_period = Some(7);
3497
3498 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3500 cfg.feature_flags
3502 .pre_consensus_sponsor_only_move_authentication = true;
3503
3504 if chain != Chain::Mainnet {
3505 cfg.feature_flags.consensus_starfish_speed = true;
3508 cfg.checkpoint_rate_window_size = Some(20);
3511 cfg.feature_flags
3514 .package_metadata_with_dynamic_module_metadata = true;
3515 }
3516
3517 if chain != Chain::Mainnet && chain != Chain::Testnet {
3518 cfg.feature_flags
3522 .consensus_enable_sliding_window_leader_schedule = true;
3523 cfg.feature_flags
3524 .consensus_enable_absolute_score_leader_schedule = true;
3525 cfg.feature_flags.enable_pcool_flow = true;
3529 }
3530 }
3531 33 => {
3532 cfg.checkpoint_rate_window_size = Some(20);
3535 if chain != Chain::Mainnet {
3539 cfg.feature_flags
3540 .consensus_enable_sliding_window_leader_schedule = true;
3541 cfg.feature_flags
3542 .consensus_enable_absolute_score_leader_schedule = true;
3543 }
3544 }
3545 34 => {
3546 if chain != Chain::Testnet && chain != Chain::Mainnet {
3547 cfg.scorer_version = Some(2);
3551 }
3552 cfg.feature_flags.pcool_skip_immutable_object_locks = true;
3556
3557 if chain == Chain::Mainnet {
3558 cfg.feature_flags.enable_move_authentication_for_sponsor = false;
3560 cfg.feature_flags
3563 .pre_consensus_sponsor_only_move_authentication = false;
3564 }
3565 }
3566 35 => {
3567 cfg.feature_flags.max_ptb_value_size_v2 = true;
3569 cfg.feature_flags.allow_unbounded_system_objects = true;
3571
3572 cfg.feature_flags.consensus_starfish_speed = true;
3575
3576 cfg.max_verifier_meter_ticks_per_function = Some(2_200_000);
3583 cfg.max_meter_ticks_per_module = Some(2_200_000);
3584 cfg.max_meter_ticks_per_package = Some(2_200_000);
3585 cfg.max_meter_ticks_regex_reference_safety = Some(2_200_000);
3586 cfg.feature_flags.pcool_verifier_limits_from_protocol_config = true;
3587 cfg.feature_flags
3590 .package_metadata_with_dynamic_module_metadata = true;
3591 cfg.feature_flags
3595 .consensus_enable_sliding_window_leader_schedule = true;
3596 cfg.feature_flags
3597 .consensus_enable_absolute_score_leader_schedule = true;
3598
3599 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3602 cfg.feature_flags
3605 .pre_consensus_sponsor_only_move_authentication = false;
3606 }
3607 36 => {
3608 cfg.feature_flags.reject_immutable_account_objects = true;
3611 }
3612 37 => {
3613 cfg.feature_flags.validate_input_object_versions = true;
3617 cfg.feature_flags.disallow_self_identifier = true;
3618 cfg.max_move_enum_variants = Some(move_core_types::VARIANT_COUNT_MAX);
3619 cfg.feature_flags.deny_authenticator_packages = true;
3622 cfg.feature_flags.check_canonical_module_version_header = true;
3625 cfg.feature_flags.disallow_randomness_in_move_authenticator = true;
3630 cfg.feature_flags.check_cyclic_dependencies = true;
3633 }
3634 38 => {
3635 cfg.max_move_system_package_size = Some(200 * 1024);
3642 cfg.feature_flags.reject_immutable_account_creation = true;
3645 }
3646 _ => panic!("unsupported version {version:?}"),
3657 }
3658 }
3659 cfg
3660 }
3661
3662 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
3668 let (
3669 max_back_edges_per_function,
3670 max_back_edges_per_module,
3671 sanity_check_with_regex_reference_safety,
3672 ) = if let Some((
3673 max_back_edges_per_function,
3674 max_back_edges_per_module,
3675 sanity_check_with_regex_reference_safety,
3676 )) = signing_limits
3677 {
3678 (
3679 Some(max_back_edges_per_function),
3680 Some(max_back_edges_per_module),
3681 Some(sanity_check_with_regex_reference_safety),
3682 )
3683 } else {
3684 (None, None, None)
3685 };
3686
3687 let additional_borrow_checks = if signing_limits.is_some() {
3688 true
3691 } else {
3692 self.additional_borrow_checks()
3693 };
3694
3695 VerifierConfig {
3696 max_loop_depth: Some(self.max_loop_depth() as usize),
3697 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
3698 max_function_parameters: Some(self.max_function_parameters() as usize),
3699 max_basic_blocks: Some(self.max_basic_blocks() as usize),
3700 max_value_stack_size: self.max_value_stack_size() as usize,
3701 max_type_nodes: Some(self.max_type_nodes() as usize),
3702 max_push_size: Some(self.max_push_size() as usize),
3703 max_dependency_depth: Some(self.max_dependency_depth() as usize),
3704 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
3705 max_function_definitions: Some(self.max_function_definitions() as usize),
3706 max_data_definitions: Some(self.max_struct_definitions() as usize),
3707 max_constant_vector_len: Some(self.max_move_vector_len()),
3708 max_back_edges_per_function,
3709 max_back_edges_per_module,
3710 max_basic_blocks_in_script: None,
3711 max_identifier_len: self.max_move_identifier_len_as_option(), disallow_self_identifier: self.feature_flags.disallow_self_identifier,
3715 bytecode_version: self.move_binary_format_version(),
3716 max_variants_in_enum: self.max_move_enum_variants_as_option(),
3717 additional_borrow_checks,
3718 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
3719 .map(|limit| limit as u128),
3720 check_cyclic_dependencies: self.feature_flags.check_cyclic_dependencies,
3721 }
3722 }
3723
3724 pub fn verifier_signing_limits(&self) -> (usize, usize, usize) {
3731 (
3732 self.max_back_edges_per_function() as usize,
3733 self.max_back_edges_per_module() as usize,
3734 self.max_meter_ticks_regex_reference_safety() as usize,
3735 )
3736 }
3737
3738 pub fn meter_config(&self) -> MeterConfig {
3742 MeterConfig {
3743 max_per_fun_meter_units: Some(self.max_verifier_meter_ticks_per_function() as u128),
3744 max_per_mod_meter_units: Some(self.max_meter_ticks_per_module() as u128),
3745 max_per_pkg_meter_units: Some(self.max_meter_ticks_per_package() as u128),
3746 }
3747 }
3748
3749 pub fn apply_overrides_for_testing(
3754 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
3755 ) -> OverrideGuard {
3756 CONFIG_OVERRIDE.with(|ovr| {
3757 let mut cur = ovr.borrow_mut();
3758 assert!(cur.is_none(), "config override already present");
3759 *cur = Some(Box::new(override_fn));
3760 OverrideGuard
3761 })
3762 }
3763}
3764
3765impl ProtocolConfig {
3770 pub fn set_per_object_congestion_control_mode_for_testing(
3771 &mut self,
3772 val: PerObjectCongestionControlMode,
3773 ) {
3774 self.feature_flags.per_object_congestion_control_mode = val;
3775 }
3776
3777 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
3778 self.feature_flags.consensus_choice = val;
3779 }
3780
3781 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
3782 self.feature_flags.consensus_network = val;
3783 }
3784
3785 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
3786 self.feature_flags.passkey_auth = val
3787 }
3788
3789 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
3790 self.feature_flags
3791 .disallow_new_modules_in_deps_only_packages = val;
3792 }
3793
3794 pub fn set_check_canonical_module_version_header_for_testing(&mut self, val: bool) {
3795 self.feature_flags.check_canonical_module_version_header = val;
3796 }
3797
3798 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
3799 self.feature_flags.consensus_round_prober = val;
3800 }
3801
3802 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
3803 self.feature_flags
3804 .consensus_distributed_vote_scoring_strategy = val;
3805 }
3806
3807 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
3808 self.consensus_gc_depth = Some(val);
3809 }
3810
3811 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
3812 self.feature_flags.consensus_linearize_subdag_v2 = val;
3813 }
3814
3815 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
3816 self.feature_flags
3817 .consensus_round_prober_probe_accepted_rounds = val;
3818 }
3819
3820 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
3821 self.feature_flags.accept_passkey_in_multisig = val;
3822 }
3823
3824 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
3825 self.feature_flags.consensus_smart_ancestor_selection = val;
3826 }
3827
3828 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
3829 self.feature_flags.consensus_batched_block_sync = val;
3830 }
3831
3832 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
3833 self.feature_flags
3834 .congestion_control_min_free_execution_slot = val;
3835 }
3836
3837 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
3838 self.feature_flags
3839 .congestion_control_gas_price_feedback_mechanism = val;
3840 }
3841
3842 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
3843 self.feature_flags.select_committee_from_eligible_validators = val;
3844 }
3845
3846 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
3847 self.feature_flags.track_non_committee_eligible_validators = val;
3848 }
3849
3850 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
3851 self.feature_flags
3852 .select_committee_supporting_next_epoch_version = val;
3853 }
3854
3855 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
3856 &mut self,
3857 val: bool,
3858 ) {
3859 self.feature_flags
3860 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3861 }
3862
3863 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3864 &mut self,
3865 val: bool,
3866 ) {
3867 self.feature_flags
3868 .consensus_commit_transactions_only_for_traversed_headers = val;
3869 }
3870
3871 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3872 &mut self,
3873 val: bool,
3874 ) {
3875 self.feature_flags
3876 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3877 }
3878
3879 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3880 &mut self,
3881 val: bool,
3882 ) {
3883 self.feature_flags
3884 .separate_gas_price_feedback_mechanism_for_randomness = val;
3885 }
3886
3887 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3888 self.feature_flags.metadata_in_module_bytes = val;
3889 }
3890
3891 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3892 self.feature_flags.publish_package_metadata = val;
3893 }
3894
3895 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3896 self.feature_flags.enable_move_authentication = val;
3897 }
3898
3899 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3900 self.feature_flags.enable_move_authentication_for_sponsor = val;
3901 }
3902
3903 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3904 self.feature_flags.consensus_fast_commit_sync = val;
3905 }
3906
3907 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3908 self.feature_flags.consensus_block_restrictions = val;
3909 }
3910
3911 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3912 self.feature_flags
3913 .pre_consensus_sponsor_only_move_authentication = val;
3914 }
3915
3916 pub fn set_consensus_starfish_speed_for_testing(&mut self, val: bool) {
3917 self.feature_flags.consensus_starfish_speed = val;
3918 }
3919
3920 pub fn set_always_advance_dkg_to_resolution_for_testing(&mut self, val: bool) {
3921 self.feature_flags.always_advance_dkg_to_resolution = val;
3922 }
3923
3924 pub fn set_enable_pcool_flow_for_testing(&mut self, val: bool) {
3925 self.feature_flags.enable_pcool_flow = val;
3926 }
3927
3928 pub fn set_pcool_skip_immutable_object_locks_for_testing(&mut self, val: bool) {
3929 self.feature_flags.pcool_skip_immutable_object_locks = val;
3930 }
3931
3932 pub fn set_pcool_verifier_limits_from_protocol_config_for_testing(&mut self, val: bool) {
3933 self.feature_flags
3934 .pcool_verifier_limits_from_protocol_config = val;
3935 }
3936
3937 pub fn set_reject_immutable_account_objects_for_testing(&mut self, val: bool) {
3938 self.feature_flags.reject_immutable_account_objects = val;
3939 }
3940
3941 pub fn set_reject_immutable_account_creation_for_testing(&mut self, val: bool) {
3942 self.feature_flags.reject_immutable_account_creation = val;
3943 }
3944
3945 pub fn set_validate_input_object_versions_for_testing(&mut self, val: bool) {
3946 self.feature_flags.validate_input_object_versions = val;
3947 }
3948
3949 pub fn set_disallow_randomness_in_move_authenticator_for_testing(&mut self, val: bool) {
3950 self.feature_flags.disallow_randomness_in_move_authenticator = val;
3951 }
3952
3953 pub fn set_commits_per_schedule_for_testing(&mut self, val: u32) {
3954 self.consensus_commits_per_schedule = Some(val);
3955 }
3956
3957 pub fn set_deny_rule_governance_for_testing(&mut self, val: bool) {
3958 self.feature_flags.deny_rule_governance = val;
3959 }
3960
3961 pub fn set_deny_authenticator_packages_for_testing(&mut self, val: bool) {
3962 self.feature_flags.deny_authenticator_packages = val;
3963 }
3964
3965 pub fn set_deny_rule_governance_on_chain_for_testing(&mut self, val: bool) {
3966 self.feature_flags.deny_rule_governance_on_chain = val;
3967 }
3968
3969 pub fn set_calculate_validator_scores_for_testing(&mut self, val: bool) {
3974 self.feature_flags.calculate_validator_scores = val;
3975 if val {
3976 self.scorer_version.get_or_insert(1);
3977 } else {
3978 self.feature_flags.adjust_rewards_by_score = false;
3979 self.feature_flags
3980 .pass_calculated_validator_scores_to_advance_epoch = false;
3981 }
3982 }
3983
3984 pub fn set_package_metadata_with_dynamic_module_metadata_for_testing(&mut self, val: bool) {
3985 self.feature_flags
3986 .package_metadata_with_dynamic_module_metadata = val;
3987 }
3988
3989 pub fn set_report_move_authentication_error_for_testing(&mut self, val: bool) {
3990 self.feature_flags.report_move_authentication_error = val;
3991 }
3992
3993 pub fn set_leader_schedule_window_size_for_testing(&mut self, val: u32) {
3994 self.consensus_leader_schedule_window_size = Some(val);
3995 }
3996
3997 pub fn set_consensus_enable_sliding_window_leader_schedule_for_testing(&mut self, val: bool) {
3998 self.feature_flags
3999 .consensus_enable_sliding_window_leader_schedule = val;
4000 }
4001
4002 pub fn set_consensus_enable_absolute_score_leader_schedule_for_testing(&mut self, val: bool) {
4003 self.feature_flags
4004 .consensus_enable_absolute_score_leader_schedule = val;
4005 }
4006}
4007
4008type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
4009
4010thread_local! {
4011 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
4012}
4013
4014#[must_use]
4015pub struct OverrideGuard;
4016
4017impl Drop for OverrideGuard {
4018 fn drop(&mut self) {
4019 info!("restoring override fn");
4020 CONFIG_OVERRIDE.with(|ovr| {
4021 *ovr.borrow_mut() = None;
4022 });
4023 }
4024}
4025
4026#[derive(PartialEq, Eq)]
4030pub enum LimitThresholdCrossed {
4031 None,
4032 Soft(u128, u128),
4033 Hard(u128, u128),
4034}
4035
4036pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
4039 x: T,
4040 soft_limit: U,
4041 hard_limit: V,
4042) -> LimitThresholdCrossed {
4043 let x: V = x.into();
4044 let soft_limit: V = soft_limit.into();
4045
4046 debug_assert!(soft_limit <= hard_limit);
4047
4048 if x >= hard_limit {
4051 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
4052 } else if x < soft_limit {
4053 LimitThresholdCrossed::None
4054 } else {
4055 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
4056 }
4057}
4058
4059#[macro_export]
4060macro_rules! check_limit {
4061 ($x:expr, $hard:expr) => {
4062 check_limit!($x, $hard, $hard)
4063 };
4064 ($x:expr, $soft:expr, $hard:expr) => {
4065 check_limit_in_range($x as u64, $soft, $hard)
4066 };
4067}
4068
4069#[macro_export]
4073macro_rules! check_limit_by_meter {
4074 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
4075 let (h, metered_str) = if $is_metered {
4077 ($metered_limit, "metered")
4078 } else {
4079 ($unmetered_hard_limit, "unmetered")
4081 };
4082 use iota_protocol_config::check_limit_in_range;
4083 let result = check_limit_in_range($x as u64, $metered_limit, h);
4084 match result {
4085 LimitThresholdCrossed::None => {}
4086 LimitThresholdCrossed::Soft(_, _) => {
4087 $metric.with_label_values(&[metered_str, "soft"]).inc();
4088 }
4089 LimitThresholdCrossed::Hard(_, _) => {
4090 $metric.with_label_values(&[metered_str, "hard"]).inc();
4091 }
4092 };
4093 result
4094 }};
4095}
4096
4097#[cfg(all(test, not(msim)))]
4098mod test {
4099 use insta::assert_yaml_snapshot;
4100
4101 use super::*;
4102
4103 #[test]
4104 fn snapshot_tests() {
4105 println!("\n============================================================================");
4106 println!("! !");
4107 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
4108 println!("! !");
4109 println!("============================================================================\n");
4110 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
4111 let chain_str = match chain_id {
4116 Chain::Unknown => "".to_string(),
4117 _ => format!("{chain_id:?}_"),
4118 };
4119 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
4120 let cur = ProtocolVersion::new(i);
4121 assert_yaml_snapshot!(
4122 format!("{}version_{}", chain_str, cur.as_u64()),
4123 ProtocolConfig::get_for_version(cur, *chain_id)
4124 );
4125 }
4126 }
4127 }
4128
4129 #[test]
4130 fn test_getters() {
4131 let prot: ProtocolConfig =
4132 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4133 assert_eq!(
4134 prot.max_arguments(),
4135 prot.max_arguments_as_option().unwrap()
4136 );
4137 }
4138
4139 #[test]
4140 fn test_setters() {
4141 let mut prot: ProtocolConfig =
4142 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4143 prot.set_max_arguments_for_testing(123);
4144 assert_eq!(prot.max_arguments(), 123);
4145
4146 prot.set_max_arguments_from_str_for_testing("321".to_string());
4147 assert_eq!(prot.max_arguments(), 321);
4148
4149 prot.disable_max_arguments_for_testing();
4150 assert_eq!(prot.max_arguments_as_option(), None);
4151
4152 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
4153 assert_eq!(prot.max_arguments(), 456);
4154 }
4155
4156 #[test]
4157 fn reject_immutable_account_creation_implies_rejecting_the_objects() {
4158 for chain in [Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
4159 for version in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
4160 ProtocolConfig::get_for_version(ProtocolVersion::new(version), chain)
4163 .reject_immutable_account_creation();
4164 }
4165 }
4166 }
4167
4168 #[test]
4169 #[should_panic(expected = "unsupported version")]
4170 fn max_version_test() {
4171 let _ = ProtocolConfig::get_for_version_impl(
4174 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
4175 Chain::Unknown,
4176 );
4177 }
4178
4179 #[test]
4180 fn lookup_by_string_test() {
4181 let prot: ProtocolConfig =
4182 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
4183 assert!(prot.lookup_attr("some random string".to_string()).is_none());
4185
4186 assert!(
4187 prot.lookup_attr("max_arguments".to_string())
4188 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
4189 );
4190
4191 assert!(
4193 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
4194 .is_none()
4195 );
4196 assert!(
4197 prot.attr_map()
4198 .get("poseidon_bn254_cost_base")
4199 .unwrap()
4200 .is_none()
4201 );
4202
4203 let prot: ProtocolConfig =
4205 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4206
4207 assert!(
4208 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
4209 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
4210 );
4211 assert!(
4212 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
4213 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
4214 );
4215
4216 let prot: ProtocolConfig =
4218 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
4219 assert!(
4221 prot.feature_flags
4222 .lookup_attr("some random string".to_owned())
4223 .is_none()
4224 );
4225 assert!(
4226 !prot
4227 .feature_flags
4228 .attr_map()
4229 .contains_key("some random string")
4230 );
4231
4232 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
4234 assert!(
4235 prot.feature_flags
4236 .attr_map()
4237 .get("enable_poseidon")
4238 .unwrap()
4239 == &false
4240 );
4241 let prot: ProtocolConfig =
4242 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4243 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
4245 assert!(
4246 prot.feature_flags
4247 .attr_map()
4248 .get("enable_poseidon")
4249 .unwrap()
4250 == &true
4251 );
4252 }
4253
4254 #[test]
4258 #[should_panic(expected = "deny_rule_update_max_entries_per_tx must be positive")]
4259 fn deny_rule_chunk_limit_above_the_ceiling_is_rejected() {
4260 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
4261 config.set_deny_rule_governance_for_testing(true);
4262 config.set_deny_rule_governance_on_chain_for_testing(true);
4263 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
4264 config.set_deny_rule_update_max_entries_per_tx_for_testing(2048 + 1);
4265 config
4266 });
4267 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
4268 }
4269
4270 #[test]
4273 #[should_panic(expected = "deny_rule_update_max_entries_per_tx must be positive")]
4274 fn deny_rule_chunk_limit_of_zero_is_rejected() {
4275 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
4276 config.set_deny_rule_governance_for_testing(true);
4277 config.set_deny_rule_governance_on_chain_for_testing(true);
4278 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
4279 config.set_deny_rule_update_max_entries_per_tx_for_testing(0);
4280 config
4281 });
4282 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
4283 }
4284
4285 #[test]
4287 fn deny_rule_chunk_limit_within_system_tx_object_id_limit_is_accepted() {
4288 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
4289 config.set_deny_rule_governance_for_testing(true);
4290 config.set_deny_rule_governance_on_chain_for_testing(true);
4291 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
4292 config.set_deny_rule_update_max_entries_per_tx_for_testing(1000);
4293 config
4294 });
4295 let config = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
4296 assert_eq!(config.deny_rule_update_max_entries_per_tx(), 1000);
4297 }
4298
4299 #[test]
4300 fn limit_range_fn_test() {
4301 let low = 100u32;
4302 let high = 10000u64;
4303
4304 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
4305 assert!(matches!(
4306 check_limit!(255u16, low, high),
4307 LimitThresholdCrossed::Soft(255u128, 100)
4308 ));
4309 assert!(matches!(
4316 check_limit!(2550000u64, low, high),
4317 LimitThresholdCrossed::Hard(2550000, 10000)
4318 ));
4319
4320 assert!(matches!(
4321 check_limit!(2550000u64, high, high),
4322 LimitThresholdCrossed::Hard(2550000, 10000)
4323 ));
4324
4325 assert!(matches!(
4326 check_limit!(1u8, high),
4327 LimitThresholdCrossed::None
4328 ));
4329
4330 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
4331
4332 assert!(matches!(
4333 check_limit!(2550000u64, high),
4334 LimitThresholdCrossed::Hard(2550000, 10000)
4335 ));
4336 }
4337}