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 = 37;
23
24pub const PROTOCOL_VERSION_IIP8: u64 = 20;
26#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
250pub struct ProtocolVersion(u64);
251
252impl ProtocolVersion {
253 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
259
260 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
261
262 #[cfg(not(msim))]
263 const MAX_ALLOWED: Self = Self::MAX;
264
265 #[cfg(msim)]
268 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
269
270 pub fn new(v: u64) -> Self {
271 Self(v)
272 }
273
274 pub const fn as_u64(&self) -> u64 {
275 self.0
276 }
277
278 pub fn max() -> Self {
281 Self::MAX
282 }
283}
284
285impl From<u64> for ProtocolVersion {
286 fn from(v: u64) -> Self {
287 Self::new(v)
288 }
289}
290
291impl std::ops::Sub<u64> for ProtocolVersion {
292 type Output = Self;
293 fn sub(self, rhs: u64) -> Self::Output {
294 Self::new(self.0 - rhs)
295 }
296}
297
298impl std::ops::Add<u64> for ProtocolVersion {
299 type Output = Self;
300 fn add(self, rhs: u64) -> Self::Output {
301 Self::new(self.0 + rhs)
302 }
303}
304
305#[derive(
306 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
307)]
308pub enum Chain {
309 Mainnet,
310 Testnet,
311 #[default]
312 Unknown,
313}
314
315impl Chain {
316 pub fn as_str(self) -> &'static str {
317 match self {
318 Chain::Mainnet => "mainnet",
319 Chain::Testnet => "testnet",
320 Chain::Unknown => "unknown",
321 }
322 }
323}
324
325pub struct Error(pub String);
326
327#[derive(
331 Default,
332 Clone,
333 Serialize,
334 Deserialize,
335 Debug,
336 ProtocolConfigFeatureFlagsGetters,
337 ProtocolConfigOverride,
338)]
339struct FeatureFlags {
340 #[serde(skip_serializing_if = "is_true")]
346 disable_invariant_violation_check_in_swap_loc: bool,
347
348 #[serde(skip_serializing_if = "is_true")]
351 no_extraneous_module_bytes: bool,
352
353 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
355 consensus_transaction_ordering: ConsensusTransactionOrdering,
356
357 #[serde(skip_serializing_if = "is_true")]
360 hardened_otw_check: bool,
361
362 #[serde(skip_serializing_if = "is_false")]
364 enable_poseidon: bool,
365
366 #[serde(skip_serializing_if = "is_false")]
368 enable_group_ops_native_function_msm: bool,
369
370 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
372 per_object_congestion_control_mode: PerObjectCongestionControlMode,
373
374 #[serde(
376 default = "ConsensusChoice::mysticeti_deprecated",
377 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
378 )]
379 consensus_choice: ConsensusChoice,
380
381 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
383 consensus_network: ConsensusNetwork,
384
385 #[deprecated]
387 #[serde(skip_serializing_if = "Option::is_none")]
388 zklogin_max_epoch_upper_bound_delta: Option<u64>,
389
390 #[serde(skip_serializing_if = "is_false")]
392 enable_vdf: bool,
393
394 #[serde(skip_serializing_if = "is_false")]
396 passkey_auth: bool,
397
398 #[serde(skip_serializing_if = "is_true")]
401 rethrow_serialization_type_layout_errors: bool,
402
403 #[serde(skip_serializing_if = "is_false")]
405 relocate_event_module: bool,
406
407 #[serde(skip_serializing_if = "is_false")]
409 protocol_defined_base_fee: bool,
410
411 #[serde(skip_serializing_if = "is_false")]
413 uncompressed_g1_group_elements: bool,
414
415 #[serde(skip_serializing_if = "is_false")]
417 disallow_new_modules_in_deps_only_packages: bool,
418
419 #[serde(skip_serializing_if = "is_false")]
421 native_charging_v2: bool,
422
423 #[serde(skip_serializing_if = "is_false")]
425 convert_type_argument_error: bool,
426
427 #[serde(skip_serializing_if = "is_false")]
429 consensus_round_prober: bool,
430
431 #[serde(skip_serializing_if = "is_false")]
433 consensus_distributed_vote_scoring_strategy: bool,
434
435 #[serde(skip_serializing_if = "is_false")]
439 consensus_linearize_subdag_v2: bool,
440
441 #[serde(skip_serializing_if = "is_false")]
443 variant_nodes: bool,
444
445 #[serde(skip_serializing_if = "is_false")]
447 consensus_smart_ancestor_selection: bool,
448
449 #[serde(skip_serializing_if = "is_false")]
451 consensus_round_prober_probe_accepted_rounds: bool,
452
453 #[serde(skip_serializing_if = "is_false")]
455 consensus_zstd_compression: bool,
456
457 #[serde(skip_serializing_if = "is_false")]
460 congestion_control_min_free_execution_slot: bool,
461
462 #[serde(skip_serializing_if = "is_false")]
464 accept_passkey_in_multisig: bool,
465
466 #[serde(skip_serializing_if = "is_false")]
468 consensus_batched_block_sync: bool,
469
470 #[serde(skip_serializing_if = "is_false")]
473 congestion_control_gas_price_feedback_mechanism: bool,
474
475 #[serde(skip_serializing_if = "is_false")]
477 validate_identifier_inputs: bool,
478
479 #[serde(skip_serializing_if = "is_false")]
482 minimize_child_object_mutations: bool,
483
484 #[serde(skip_serializing_if = "is_false")]
486 dependency_linkage_error: bool,
487
488 #[serde(skip_serializing_if = "is_false")]
490 additional_multisig_checks: bool,
491
492 #[serde(skip_serializing_if = "is_false")]
495 normalize_ptb_arguments: bool,
496
497 #[serde(skip_serializing_if = "is_false")]
501 select_committee_from_eligible_validators: bool,
502
503 #[serde(skip_serializing_if = "is_false")]
510 track_non_committee_eligible_validators: bool,
511
512 #[serde(skip_serializing_if = "is_false")]
518 select_committee_supporting_next_epoch_version: bool,
519
520 #[serde(skip_serializing_if = "is_false")]
524 consensus_median_timestamp_with_checkpoint_enforcement: bool,
525
526 #[serde(skip_serializing_if = "is_false")]
528 consensus_commit_transactions_only_for_traversed_headers: bool,
529
530 #[serde(skip_serializing_if = "is_false")]
532 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
533
534 #[serde(skip_serializing_if = "is_false")]
537 separate_gas_price_feedback_mechanism_for_randomness: bool,
538
539 #[serde(skip_serializing_if = "is_false")]
542 metadata_in_module_bytes: bool,
543
544 #[serde(skip_serializing_if = "is_false")]
546 publish_package_metadata: bool,
547
548 #[serde(skip_serializing_if = "is_false")]
550 enable_move_authentication: bool,
551
552 #[serde(skip_serializing_if = "is_false")]
554 enable_move_authentication_for_sponsor: bool,
555
556 #[serde(skip_serializing_if = "is_false")]
558 pass_validator_scores_to_advance_epoch: bool,
559
560 #[serde(skip_serializing_if = "is_false")]
562 calculate_validator_scores: bool,
563
564 #[serde(skip_serializing_if = "is_false")]
566 adjust_rewards_by_score: bool,
567
568 #[serde(skip_serializing_if = "is_false")]
571 pass_calculated_validator_scores_to_advance_epoch: bool,
572
573 #[serde(skip_serializing_if = "is_false")]
578 consensus_fast_commit_sync: bool,
579
580 #[serde(skip_serializing_if = "is_false")]
583 consensus_block_restrictions: bool,
584
585 #[serde(skip_serializing_if = "is_false")]
587 move_native_tx_context: bool,
588
589 #[serde(skip_serializing_if = "is_false")]
591 additional_borrow_checks: bool,
592
593 #[serde(skip_serializing_if = "is_false")]
595 pre_consensus_sponsor_only_move_authentication: bool,
596
597 #[serde(skip_serializing_if = "is_false")]
599 consensus_starfish_speed: bool,
600
601 #[serde(skip_serializing_if = "is_false")]
608 always_advance_dkg_to_resolution: bool,
609
610 #[serde(skip_serializing_if = "is_false")]
615 enable_pcool_flow: bool,
616
617 #[serde(skip_serializing_if = "is_false")]
622 pcool_skip_immutable_object_locks: bool,
623
624 #[serde(skip_serializing_if = "is_false")]
629 pcool_verifier_limits_from_protocol_config: bool,
630
631 #[serde(skip_serializing_if = "is_false")]
633 validator_metadata_verify_v2: bool,
634
635 #[serde(skip_serializing_if = "is_false")]
639 deny_rule_governance: bool,
640
641 #[serde(skip_serializing_if = "is_false")]
646 deny_rule_governance_on_chain: bool,
647
648 #[serde(skip_serializing_if = "is_false")]
652 deny_authenticator_packages: bool,
653
654 #[serde(skip_serializing_if = "is_false")]
657 package_metadata_with_dynamic_module_metadata: bool,
658
659 #[serde(skip_serializing_if = "is_false")]
662 report_move_authentication_error: bool,
663
664 #[serde(skip_serializing_if = "is_false")]
669 consensus_enable_sliding_window_leader_schedule: bool,
670
671 #[serde(skip_serializing_if = "is_false")]
676 consensus_enable_absolute_score_leader_schedule: bool,
677
678 #[serde(skip_serializing_if = "is_false")]
680 max_ptb_value_size_v2: bool,
681
682 #[serde(skip_serializing_if = "is_false")]
684 allow_unbounded_system_objects: bool,
685
686 #[serde(skip_serializing_if = "is_false")]
689 reject_immutable_account_objects: bool,
690
691 #[serde(skip_serializing_if = "is_false")]
697 validate_input_object_versions: bool,
698
699 #[serde(skip_serializing_if = "is_false")]
701 disallow_self_identifier: bool,
702
703 #[serde(skip_serializing_if = "is_false")]
708 check_canonical_module_version_header: bool,
709
710 #[serde(skip_serializing_if = "is_false")]
715 disallow_randomness_in_move_authenticator: bool,
716
717 #[serde(skip_serializing_if = "is_false")]
721 check_cyclic_dependencies: bool,
722
723 #[serde(skip_serializing_if = "is_false")]
725 deprecate_global_storage_ops_during_deserialization: bool,
726}
727
728fn is_true(b: &bool) -> bool {
729 *b
730}
731
732fn is_false(b: &bool) -> bool {
733 !b
734}
735
736#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
738pub enum ConsensusTransactionOrdering {
739 #[default]
742 None,
743 ByGasPrice,
745}
746
747impl ConsensusTransactionOrdering {
748 pub fn is_none(&self) -> bool {
749 matches!(self, ConsensusTransactionOrdering::None)
750 }
751}
752
753#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
755pub enum PerObjectCongestionControlMode {
756 #[default]
757 None, TotalGasBudget, TotalTxCount, }
761
762impl PerObjectCongestionControlMode {
763 pub fn is_none(&self) -> bool {
764 matches!(self, PerObjectCongestionControlMode::None)
765 }
766}
767
768#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
770pub enum ConsensusChoice {
771 #[deprecated(note = "Mysticeti was replaced by Starfish")]
774 MysticetiDeprecated,
775 #[default]
776 Starfish,
777}
778
779#[expect(deprecated)]
780impl ConsensusChoice {
781 fn mysticeti_deprecated() -> Self {
788 ConsensusChoice::MysticetiDeprecated
789 }
790
791 pub fn is_mysticeti_deprecated(&self) -> bool {
792 matches!(self, ConsensusChoice::MysticetiDeprecated)
793 }
794 pub fn is_starfish(&self) -> bool {
795 matches!(self, ConsensusChoice::Starfish)
796 }
797}
798
799#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
801pub enum ConsensusNetwork {
802 #[default]
803 Tonic,
804}
805
806impl ConsensusNetwork {
807 pub fn is_tonic(&self) -> bool {
808 matches!(self, ConsensusNetwork::Tonic)
809 }
810}
811
812#[skip_serializing_none]
846#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
847pub struct ProtocolConfig {
848 pub version: ProtocolVersion,
849
850 feature_flags: FeatureFlags,
851
852 max_tx_size_bytes: Option<u64>,
857
858 max_input_objects: Option<u64>,
863
864 max_size_written_objects: Option<u64>,
869 max_size_written_objects_system_tx: Option<u64>,
873
874 max_serialized_tx_effects_size_bytes: Option<u64>,
876
877 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
879
880 max_gas_payment_objects: Option<u32>,
882
883 max_modules_in_publish: Option<u32>,
885
886 max_package_dependencies: Option<u32>,
888
889 max_arguments: Option<u32>,
892
893 max_type_arguments: Option<u32>,
895
896 max_type_argument_depth: Option<u32>,
898
899 max_pure_argument_size: Option<u32>,
901
902 max_programmable_tx_commands: Option<u32>,
904
905 move_binary_format_version: Option<u32>,
911 min_move_binary_format_version: Option<u32>,
912
913 binary_module_handles: Option<u16>,
915 binary_struct_handles: Option<u16>,
916 binary_function_handles: Option<u16>,
917 binary_function_instantiations: Option<u16>,
918 binary_signatures: Option<u16>,
919 binary_constant_pool: Option<u16>,
920 binary_identifiers: Option<u16>,
921 binary_address_identifiers: Option<u16>,
922 binary_struct_defs: Option<u16>,
923 binary_struct_def_instantiations: Option<u16>,
924 binary_function_defs: Option<u16>,
925 binary_field_handles: Option<u16>,
926 binary_field_instantiations: Option<u16>,
927 binary_friend_decls: Option<u16>,
928 binary_enum_defs: Option<u16>,
929 binary_enum_def_instantiations: Option<u16>,
930 binary_variant_handles: Option<u16>,
931 binary_variant_instantiation_handles: Option<u16>,
932
933 max_move_object_size: Option<u64>,
936
937 max_move_package_size: Option<u64>,
942
943 max_publish_or_upgrade_per_ptb: Option<u64>,
946
947 max_tx_gas: Option<u64>,
949
950 max_auth_gas: Option<u64>,
952
953 max_gas_price: Option<u64>,
956
957 max_gas_computation_bucket: Option<u64>,
960
961 gas_rounding_step: Option<u64>,
963
964 max_loop_depth: Option<u64>,
966
967 max_generic_instantiation_length: Option<u64>,
970
971 max_function_parameters: Option<u64>,
974
975 max_basic_blocks: Option<u64>,
978
979 max_value_stack_size: Option<u64>,
981
982 max_type_nodes: Option<u64>,
986
987 max_push_size: Option<u64>,
990
991 max_struct_definitions: Option<u64>,
994
995 max_function_definitions: Option<u64>,
998
999 max_fields_in_struct: Option<u64>,
1002
1003 max_dependency_depth: Option<u64>,
1006
1007 max_num_event_emit: Option<u64>,
1010
1011 max_num_new_move_object_ids: Option<u64>,
1014
1015 max_num_new_move_object_ids_system_tx: Option<u64>,
1018
1019 max_num_deleted_move_object_ids: Option<u64>,
1022
1023 max_num_deleted_move_object_ids_system_tx: Option<u64>,
1026
1027 max_num_transferred_move_object_ids: Option<u64>,
1030
1031 max_num_transferred_move_object_ids_system_tx: Option<u64>,
1034
1035 max_event_emit_size: Option<u64>,
1037
1038 max_event_emit_size_total: Option<u64>,
1040
1041 max_move_vector_len: Option<u64>,
1044
1045 max_move_identifier_len: Option<u64>,
1048
1049 max_move_value_depth: Option<u64>,
1051
1052 max_move_enum_variants: Option<u64>,
1055
1056 max_back_edges_per_function: Option<u64>,
1065
1066 max_back_edges_per_module: Option<u64>,
1068
1069 max_verifier_meter_ticks_per_function: Option<u64>,
1071
1072 max_meter_ticks_per_module: Option<u64>,
1074
1075 max_meter_ticks_per_package: Option<u64>,
1077
1078 max_meter_ticks_regex_reference_safety: Option<u64>,
1082
1083 object_runtime_max_num_cached_objects: Option<u64>,
1090
1091 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
1094
1095 object_runtime_max_num_store_entries: Option<u64>,
1098
1099 object_runtime_max_num_store_entries_system_tx: Option<u64>,
1102
1103 base_tx_cost_fixed: Option<u64>,
1108
1109 package_publish_cost_fixed: Option<u64>,
1113
1114 base_tx_cost_per_byte: Option<u64>,
1118
1119 package_publish_cost_per_byte: Option<u64>,
1121
1122 obj_access_cost_read_per_byte: Option<u64>,
1124
1125 obj_access_cost_mutate_per_byte: Option<u64>,
1127
1128 obj_access_cost_delete_per_byte: Option<u64>,
1130
1131 obj_access_cost_verify_per_byte: Option<u64>,
1141
1142 max_type_to_layout_nodes: Option<u64>,
1144
1145 max_ptb_value_size: Option<u64>,
1147
1148 gas_model_version: Option<u64>,
1153
1154 obj_data_cost_refundable: Option<u64>,
1160
1161 obj_metadata_cost_non_refundable: Option<u64>,
1165
1166 storage_rebate_rate: Option<u64>,
1172
1173 reward_slashing_rate: Option<u64>,
1176
1177 storage_gas_price: Option<u64>,
1179
1180 base_gas_price: Option<u64>,
1182
1183 validator_target_reward: Option<u64>,
1185
1186 max_transactions_per_checkpoint: Option<u64>,
1193
1194 max_checkpoint_size_bytes: Option<u64>,
1198
1199 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
1205
1206 address_from_bytes_cost_base: Option<u64>,
1211 address_to_u256_cost_base: Option<u64>,
1213 address_from_u256_cost_base: Option<u64>,
1215
1216 config_read_setting_impl_cost_base: Option<u64>,
1221 config_read_setting_impl_cost_per_byte: Option<u64>,
1222
1223 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
1227 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
1228 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
1229 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
1230 dynamic_field_add_child_object_cost_base: Option<u64>,
1233 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
1234 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
1235 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
1236 dynamic_field_borrow_child_object_cost_base: Option<u64>,
1239 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1240 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1241 dynamic_field_remove_child_object_cost_base: Option<u64>,
1244 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1245 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1246 dynamic_field_has_child_object_cost_base: Option<u64>,
1249 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1252 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1253 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1254
1255 event_emit_cost_base: Option<u64>,
1258 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1259 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1260 event_emit_output_cost_per_byte: Option<u64>,
1261
1262 object_borrow_uid_cost_base: Option<u64>,
1265 object_delete_impl_cost_base: Option<u64>,
1267 object_record_new_uid_cost_base: Option<u64>,
1269
1270 transfer_transfer_internal_cost_base: Option<u64>,
1273 transfer_freeze_object_cost_base: Option<u64>,
1275 transfer_share_object_cost_base: Option<u64>,
1277 transfer_receive_object_cost_base: Option<u64>,
1280
1281 tx_context_derive_id_cost_base: Option<u64>,
1284 tx_context_fresh_id_cost_base: Option<u64>,
1285 tx_context_sender_cost_base: Option<u64>,
1286 tx_context_digest_cost_base: Option<u64>,
1287 tx_context_epoch_cost_base: Option<u64>,
1288 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1289 tx_context_sponsor_cost_base: Option<u64>,
1290 tx_context_rgp_cost_base: Option<u64>,
1291 tx_context_gas_price_cost_base: Option<u64>,
1292 tx_context_gas_budget_cost_base: Option<u64>,
1293 tx_context_ids_created_cost_base: Option<u64>,
1294 tx_context_replace_cost_base: Option<u64>,
1295
1296 types_is_one_time_witness_cost_base: Option<u64>,
1299 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1300 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1301
1302 validator_validate_metadata_cost_base: Option<u64>,
1305 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1306
1307 crypto_invalid_arguments_cost: Option<u64>,
1309 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1311 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1312 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1313
1314 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1316 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1317 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1318
1319 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1321 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1322 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1323 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1324 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1325 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1326
1327 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1329
1330 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1332 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1333 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1334 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1335 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1336 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1337
1338 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1340 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1341 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1342 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1343 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1344 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1345
1346 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1348 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1349 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1350 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1351 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1352 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1353
1354 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1356 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1357 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1358
1359 ed25519_ed25519_verify_cost_base: Option<u64>,
1361 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1362 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1363
1364 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1366 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1367
1368 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1370 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1371 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1372 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1373 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1374
1375 hash_blake2b256_cost_base: Option<u64>,
1377 hash_blake2b256_data_cost_per_byte: Option<u64>,
1378 hash_blake2b256_data_cost_per_block: Option<u64>,
1379
1380 hash_keccak256_cost_base: Option<u64>,
1382 hash_keccak256_data_cost_per_byte: Option<u64>,
1383 hash_keccak256_data_cost_per_block: Option<u64>,
1384
1385 poseidon_bn254_cost_base: Option<u64>,
1387 poseidon_bn254_cost_per_block: Option<u64>,
1388
1389 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1391 group_ops_bls12381_decode_g1_cost: Option<u64>,
1392 group_ops_bls12381_decode_g2_cost: Option<u64>,
1393 group_ops_bls12381_decode_gt_cost: Option<u64>,
1394 group_ops_bls12381_scalar_add_cost: Option<u64>,
1395 group_ops_bls12381_g1_add_cost: Option<u64>,
1396 group_ops_bls12381_g2_add_cost: Option<u64>,
1397 group_ops_bls12381_gt_add_cost: Option<u64>,
1398 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1399 group_ops_bls12381_g1_sub_cost: Option<u64>,
1400 group_ops_bls12381_g2_sub_cost: Option<u64>,
1401 group_ops_bls12381_gt_sub_cost: Option<u64>,
1402 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1403 group_ops_bls12381_g1_mul_cost: Option<u64>,
1404 group_ops_bls12381_g2_mul_cost: Option<u64>,
1405 group_ops_bls12381_gt_mul_cost: Option<u64>,
1406 group_ops_bls12381_scalar_div_cost: Option<u64>,
1407 group_ops_bls12381_g1_div_cost: Option<u64>,
1408 group_ops_bls12381_g2_div_cost: Option<u64>,
1409 group_ops_bls12381_gt_div_cost: Option<u64>,
1410 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1411 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1412 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1413 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1414 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1415 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1416 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1417 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1418 group_ops_bls12381_msm_max_len: Option<u32>,
1419 group_ops_bls12381_pairing_cost: Option<u64>,
1420 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1421 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1422 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1423 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1424 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1425
1426 hmac_hmac_sha3_256_cost_base: Option<u64>,
1428 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1429 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1430
1431 #[deprecated]
1433 check_zklogin_id_cost_base: Option<u64>,
1434 #[deprecated]
1436 check_zklogin_issuer_cost_base: Option<u64>,
1437
1438 vdf_verify_vdf_cost: Option<u64>,
1439 vdf_hash_to_input_cost: Option<u64>,
1440
1441 bcs_per_byte_serialized_cost: Option<u64>,
1443 bcs_legacy_min_output_size_cost: Option<u64>,
1444 bcs_failure_cost: Option<u64>,
1445
1446 hash_sha2_256_base_cost: Option<u64>,
1447 hash_sha2_256_per_byte_cost: Option<u64>,
1448 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1449 hash_sha3_256_base_cost: Option<u64>,
1450 hash_sha3_256_per_byte_cost: Option<u64>,
1451 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1452 type_name_get_base_cost: Option<u64>,
1453 type_name_get_per_byte_cost: Option<u64>,
1454
1455 string_check_utf8_base_cost: Option<u64>,
1456 string_check_utf8_per_byte_cost: Option<u64>,
1457 string_is_char_boundary_base_cost: Option<u64>,
1458 string_sub_string_base_cost: Option<u64>,
1459 string_sub_string_per_byte_cost: Option<u64>,
1460 string_index_of_base_cost: Option<u64>,
1461 string_index_of_per_byte_pattern_cost: Option<u64>,
1462 string_index_of_per_byte_searched_cost: Option<u64>,
1463
1464 vector_empty_base_cost: Option<u64>,
1465 vector_length_base_cost: Option<u64>,
1466 vector_push_back_base_cost: Option<u64>,
1467 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1468 vector_borrow_base_cost: Option<u64>,
1469 vector_pop_back_base_cost: Option<u64>,
1470 vector_destroy_empty_base_cost: Option<u64>,
1471 vector_swap_base_cost: Option<u64>,
1472 debug_print_base_cost: Option<u64>,
1473 debug_print_stack_trace_base_cost: Option<u64>,
1474
1475 execution_version: Option<u64>,
1477
1478 consensus_bad_nodes_stake_threshold: Option<u64>,
1482
1483 #[deprecated]
1484 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1485 #[deprecated]
1489 max_age_of_jwk_in_epochs: Option<u64>,
1490
1491 random_beacon_reduction_allowed_delta: Option<u16>,
1495
1496 random_beacon_reduction_lower_bound: Option<u32>,
1499
1500 random_beacon_dkg_timeout_round: Option<u32>,
1503
1504 random_beacon_min_round_interval_ms: Option<u64>,
1506
1507 random_beacon_dkg_version: Option<u64>,
1511
1512 consensus_max_transaction_size_bytes: Option<u64>,
1517 consensus_max_transactions_in_block_bytes: Option<u64>,
1519 consensus_max_num_transactions_in_block: Option<u64>,
1521
1522 max_deferral_rounds_for_congestion_control: Option<u64>,
1526
1527 min_checkpoint_interval_ms: Option<u64>,
1529
1530 checkpoint_rate_window_size: Option<u64>,
1540
1541 checkpoint_summary_version_specific_data: Option<u64>,
1543
1544 max_soft_bundle_size: Option<u64>,
1547
1548 bridge_should_try_to_finalize_committee: Option<bool>,
1553
1554 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1560
1561 max_committee_members_count: Option<u64>,
1565
1566 deny_rule_update_max_entries_per_tx: Option<u64>,
1571
1572 deny_rule_removal_grace_round_floor: Option<u64>,
1577
1578 consensus_gc_depth: Option<u32>,
1581
1582 consensus_max_acknowledgments_per_block: Option<u32>,
1588
1589 max_congestion_limit_overshoot_per_commit: Option<u64>,
1594
1595 max_concurrent_execution_workers: Option<u16>,
1602
1603 scorer_version: Option<u16>,
1612
1613 auth_context_digest_cost_base: Option<u64>,
1616 auth_context_tx_data_bytes_cost_base: Option<u64>,
1618 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1619 auth_context_tx_commands_cost_base: Option<u64>,
1621 auth_context_tx_commands_cost_per_byte: Option<u64>,
1622 auth_context_tx_inputs_cost_base: Option<u64>,
1624 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1625 auth_context_replace_cost_base: Option<u64>,
1628 auth_context_replace_cost_per_byte: Option<u64>,
1629 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1633
1634 consensus_commits_per_schedule: Option<u32>,
1637
1638 min_validator_count: Option<u64>,
1641
1642 max_validator_count: Option<u64>,
1646
1647 min_validator_joining_stake: Option<u64>,
1651
1652 validator_low_stake_threshold: Option<u64>,
1657
1658 validator_very_low_stake_threshold: Option<u64>,
1662
1663 validator_low_stake_grace_period: Option<u64>,
1667
1668 consensus_leader_schedule_window_size: Option<u32>,
1672}
1673
1674impl ProtocolConfig {
1676 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1689 self.feature_flags
1690 .disable_invariant_violation_check_in_swap_loc
1691 }
1692
1693 pub fn no_extraneous_module_bytes(&self) -> bool {
1694 self.feature_flags.no_extraneous_module_bytes
1695 }
1696
1697 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1698 self.feature_flags.consensus_transaction_ordering
1699 }
1700
1701 pub fn dkg_version(&self) -> u64 {
1702 self.random_beacon_dkg_version.unwrap_or(1)
1704 }
1705
1706 pub fn hardened_otw_check(&self) -> bool {
1707 self.feature_flags.hardened_otw_check
1708 }
1709
1710 pub fn enable_poseidon(&self) -> bool {
1711 self.feature_flags.enable_poseidon
1712 }
1713
1714 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1715 self.feature_flags.enable_group_ops_native_function_msm
1716 }
1717
1718 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1719 self.feature_flags.per_object_congestion_control_mode
1720 }
1721
1722 pub fn consensus_choice(&self) -> ConsensusChoice {
1723 self.feature_flags.consensus_choice
1724 }
1725
1726 pub fn consensus_network(&self) -> ConsensusNetwork {
1727 self.feature_flags.consensus_network
1728 }
1729
1730 pub fn enable_vdf(&self) -> bool {
1731 self.feature_flags.enable_vdf
1732 }
1733
1734 pub fn passkey_auth(&self) -> bool {
1735 self.feature_flags.passkey_auth
1736 }
1737
1738 pub fn max_transaction_size_bytes(&self) -> u64 {
1739 self.consensus_max_transaction_size_bytes
1741 .unwrap_or(256 * 1024)
1742 }
1743
1744 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1745 if cfg!(msim) {
1746 256 * 1024
1747 } else {
1748 self.consensus_max_transactions_in_block_bytes
1749 .unwrap_or(512 * 1024)
1750 }
1751 }
1752
1753 pub fn max_num_transactions_in_block(&self) -> u64 {
1754 if cfg!(msim) {
1755 8
1756 } else {
1757 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1758 }
1759 }
1760
1761 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1762 self.feature_flags.rethrow_serialization_type_layout_errors
1763 }
1764
1765 pub fn relocate_event_module(&self) -> bool {
1766 self.feature_flags.relocate_event_module
1767 }
1768
1769 pub fn protocol_defined_base_fee(&self) -> bool {
1770 self.feature_flags.protocol_defined_base_fee
1771 }
1772
1773 pub fn uncompressed_g1_group_elements(&self) -> bool {
1774 self.feature_flags.uncompressed_g1_group_elements
1775 }
1776
1777 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1778 self.feature_flags
1779 .disallow_new_modules_in_deps_only_packages
1780 }
1781
1782 pub fn native_charging_v2(&self) -> bool {
1783 self.feature_flags.native_charging_v2
1784 }
1785
1786 pub fn consensus_round_prober(&self) -> bool {
1787 self.feature_flags.consensus_round_prober
1788 }
1789
1790 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1791 self.feature_flags
1792 .consensus_distributed_vote_scoring_strategy
1793 }
1794
1795 pub fn gc_depth(&self) -> u32 {
1796 if cfg!(msim) {
1797 min(5, self.consensus_gc_depth.unwrap_or(0))
1799 } else {
1800 self.consensus_gc_depth.unwrap_or(0)
1801 }
1802 }
1803
1804 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1805 let res = self.feature_flags.consensus_linearize_subdag_v2;
1806 assert!(
1807 !res || self.gc_depth() > 0,
1808 "The consensus linearize sub dag V2 requires GC to be enabled"
1809 );
1810 res
1811 }
1812
1813 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1814 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1815 }
1816
1817 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1818 2 * committee_size
1819 }
1820
1821 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1822 committee_size
1823 }
1824
1825 pub fn variant_nodes(&self) -> bool {
1826 self.feature_flags.variant_nodes
1827 }
1828
1829 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1830 self.feature_flags.consensus_smart_ancestor_selection
1831 }
1832
1833 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1834 self.feature_flags
1835 .consensus_round_prober_probe_accepted_rounds
1836 }
1837
1838 pub fn consensus_zstd_compression(&self) -> bool {
1839 self.feature_flags.consensus_zstd_compression
1840 }
1841
1842 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1843 self.feature_flags
1844 .congestion_control_min_free_execution_slot
1845 }
1846
1847 pub fn accept_passkey_in_multisig(&self) -> bool {
1848 self.feature_flags.accept_passkey_in_multisig
1849 }
1850
1851 pub fn consensus_batched_block_sync(&self) -> bool {
1852 self.feature_flags.consensus_batched_block_sync
1853 }
1854
1855 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1858 self.feature_flags
1859 .congestion_control_gas_price_feedback_mechanism
1860 }
1861
1862 pub fn validate_identifier_inputs(&self) -> bool {
1863 self.feature_flags.validate_identifier_inputs
1864 }
1865
1866 pub fn minimize_child_object_mutations(&self) -> bool {
1867 self.feature_flags.minimize_child_object_mutations
1868 }
1869
1870 pub fn dependency_linkage_error(&self) -> bool {
1871 self.feature_flags.dependency_linkage_error
1872 }
1873
1874 pub fn additional_multisig_checks(&self) -> bool {
1875 self.feature_flags.additional_multisig_checks
1876 }
1877
1878 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1879 0
1882 }
1883
1884 pub fn normalize_ptb_arguments(&self) -> bool {
1885 self.feature_flags.normalize_ptb_arguments
1886 }
1887
1888 pub fn select_committee_from_eligible_validators(&self) -> bool {
1889 let res = self.feature_flags.select_committee_from_eligible_validators;
1890 assert!(
1891 !res || (self.protocol_defined_base_fee()
1892 && self.max_committee_members_count_as_option().is_some()),
1893 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1894 );
1895 res
1896 }
1897
1898 pub fn track_non_committee_eligible_validators(&self) -> bool {
1899 self.feature_flags.track_non_committee_eligible_validators
1900 }
1901
1902 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1903 let res = self
1904 .feature_flags
1905 .select_committee_supporting_next_epoch_version;
1906 assert!(
1907 !res || (self.track_non_committee_eligible_validators()
1908 && self.select_committee_from_eligible_validators()),
1909 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1910 );
1911 res
1912 }
1913
1914 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1915 let res = self
1916 .feature_flags
1917 .consensus_median_timestamp_with_checkpoint_enforcement;
1918 assert!(
1919 !res || self.gc_depth() > 0,
1920 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1921 );
1922 res
1923 }
1924
1925 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1926 self.feature_flags
1927 .consensus_commit_transactions_only_for_traversed_headers
1928 }
1929
1930 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1933 self.feature_flags
1934 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1935 }
1936
1937 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1940 self.feature_flags
1941 .separate_gas_price_feedback_mechanism_for_randomness
1942 }
1943
1944 pub fn metadata_in_module_bytes(&self) -> bool {
1945 self.feature_flags.metadata_in_module_bytes
1946 }
1947
1948 pub fn publish_package_metadata(&self) -> bool {
1949 self.feature_flags.publish_package_metadata
1950 }
1951
1952 pub fn enable_move_authentication(&self) -> bool {
1953 self.feature_flags.enable_move_authentication
1954 }
1955
1956 pub fn additional_borrow_checks(&self) -> bool {
1957 self.feature_flags.additional_borrow_checks
1958 }
1959
1960 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1961 let enable_move_authentication_for_sponsor =
1962 self.feature_flags.enable_move_authentication_for_sponsor;
1963 assert!(
1964 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1965 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1966 );
1967 enable_move_authentication_for_sponsor
1968 }
1969
1970 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1971 self.feature_flags.pass_validator_scores_to_advance_epoch
1972 }
1973
1974 pub fn calculate_validator_scores(&self) -> bool {
1975 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1976 assert!(
1977 !calculate_validator_scores || self.scorer_version.is_some(),
1978 "calculate_validator_scores requires scorer_version to be set"
1979 );
1980 calculate_validator_scores
1981 }
1982
1983 pub fn adjust_rewards_by_score(&self) -> bool {
1984 let adjust = self.feature_flags.adjust_rewards_by_score;
1985 assert!(
1986 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1987 "adjust_rewards_by_score requires scorer_version to be set"
1988 );
1989 adjust
1990 }
1991
1992 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1993 let pass = self
1994 .feature_flags
1995 .pass_calculated_validator_scores_to_advance_epoch;
1996 assert!(
1997 !pass
1998 || (self.pass_validator_scores_to_advance_epoch()
1999 && self.calculate_validator_scores()),
2000 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
2001 );
2002 pass
2003 }
2004 pub fn consensus_fast_commit_sync(&self) -> bool {
2005 let res = self.feature_flags.consensus_fast_commit_sync;
2006 assert!(
2007 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
2008 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
2009 );
2010 res
2011 }
2012
2013 pub fn consensus_block_restrictions(&self) -> bool {
2014 self.feature_flags.consensus_block_restrictions
2015 }
2016
2017 pub fn move_native_tx_context(&self) -> bool {
2018 self.feature_flags.move_native_tx_context
2019 }
2020
2021 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
2022 let pre_consensus_sponsor_only_move_authentication = self
2023 .feature_flags
2024 .pre_consensus_sponsor_only_move_authentication;
2025 if pre_consensus_sponsor_only_move_authentication {
2026 assert!(
2027 self.enable_move_authentication(),
2028 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
2029 );
2030 assert!(
2031 self.enable_move_authentication_for_sponsor(),
2032 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
2033 );
2034 }
2035 pre_consensus_sponsor_only_move_authentication
2036 }
2037
2038 pub fn consensus_starfish_speed(&self) -> bool {
2039 let res = self.feature_flags.consensus_starfish_speed;
2040 assert!(
2041 !res || self.consensus_fast_commit_sync(),
2042 "consensus_starfish_speed requires consensus_fast_commit_sync to be enabled"
2043 );
2044 res
2045 }
2046
2047 pub fn always_advance_dkg_to_resolution(&self) -> bool {
2048 self.feature_flags.always_advance_dkg_to_resolution
2049 }
2050
2051 pub fn enable_pcool_flow(&self) -> bool {
2052 self.feature_flags.enable_pcool_flow
2053 }
2054
2055 pub fn pcool_skip_immutable_object_locks(&self) -> bool {
2056 self.feature_flags.pcool_skip_immutable_object_locks
2057 }
2058
2059 pub fn pcool_verifier_limits_from_protocol_config(&self) -> bool {
2062 self.feature_flags
2063 .pcool_verifier_limits_from_protocol_config
2064 }
2065
2066 pub fn validator_metadata_verify_v2(&self) -> bool {
2067 self.feature_flags.validator_metadata_verify_v2
2068 }
2069
2070 pub fn commits_per_schedule(&self) -> u32 {
2071 let commits_per_schedule = if cfg!(msim) {
2072 min(10, self.consensus_commits_per_schedule.unwrap_or(300))
2074 } else {
2075 self.consensus_commits_per_schedule.unwrap_or(300)
2076 };
2077 assert!(
2078 commits_per_schedule > 0,
2079 "consensus_commits_per_schedule must be greater than 0"
2080 );
2081 commits_per_schedule
2082 }
2083
2084 pub fn leader_schedule_window_size(&self) -> u32 {
2085 if cfg!(msim) {
2086 min(
2089 20,
2090 self.consensus_leader_schedule_window_size.unwrap_or(600),
2091 )
2092 } else {
2093 self.consensus_leader_schedule_window_size.unwrap_or(600)
2094 }
2095 }
2096
2097 pub fn consensus_enable_sliding_window_leader_schedule(&self) -> bool {
2098 let res = self
2099 .feature_flags
2100 .consensus_enable_sliding_window_leader_schedule;
2101 assert!(
2102 !res || self.leader_schedule_window_size() >= self.commits_per_schedule(),
2103 "consensus_enable_sliding_window_leader_schedule requires window_size >= commits_per_schedule"
2104 );
2105 res
2106 }
2107
2108 pub fn consensus_enable_absolute_score_leader_schedule(&self) -> bool {
2109 self.feature_flags
2110 .consensus_enable_absolute_score_leader_schedule
2111 }
2112
2113 pub fn max_ptb_value_size_v2(&self) -> bool {
2114 self.feature_flags.max_ptb_value_size_v2
2115 }
2116
2117 pub fn deny_rule_governance(&self) -> bool {
2118 self.feature_flags.deny_rule_governance
2119 }
2120
2121 pub fn deny_rule_governance_on_chain(&self) -> bool {
2122 self.feature_flags.deny_rule_governance_on_chain
2123 }
2124
2125 pub fn deny_authenticator_packages(&self) -> bool {
2126 self.feature_flags.deny_authenticator_packages
2127 }
2128
2129 pub fn package_metadata_with_dynamic_module_metadata(&self) -> bool {
2130 let res = self
2131 .feature_flags
2132 .package_metadata_with_dynamic_module_metadata;
2133 assert!(
2134 !res || self.publish_package_metadata(),
2135 "package_metadata_with_dynamic_module_metadata requires publish_package_metadata to be enabled"
2136 );
2137 res
2138 }
2139
2140 pub fn report_move_authentication_error(&self) -> bool {
2141 let report_move_authentication_error = self.feature_flags.report_move_authentication_error;
2142 assert!(
2143 !report_move_authentication_error || self.enable_move_authentication(),
2144 "report_move_authentication_error requires enable_move_authentication to be set"
2145 );
2146 report_move_authentication_error
2147 }
2148
2149 pub fn concurrent_execution_workers(&self) -> Option<u16> {
2153 let res = self.max_concurrent_execution_workers;
2154 assert!(
2155 res.is_none() || self.enable_pcool_flow(),
2156 "max_concurrent_execution_workers requires enable_pcool_flow to be enabled"
2157 );
2158 assert!(
2159 res.is_none()
2160 || self
2161 .max_accumulated_txn_cost_per_object_in_mysticeti_commit
2162 .is_some(),
2163 "max_concurrent_execution_workers requires per-object congestion control \
2164 (max_accumulated_txn_cost_per_object_in_mysticeti_commit) to be enabled"
2165 );
2166 assert!(
2167 res.is_none() || self.congestion_control_gas_price_feedback_mechanism(),
2168 "max_concurrent_execution_workers requires the gas price feedback mechanism \
2169 (congestion_control_gas_price_feedback_mechanism), which carries the suggested \
2170 gas price of an execution-worker congestion cancellation"
2171 );
2172 assert!(
2173 res.is_none() || !self.separate_gas_price_feedback_mechanism_for_randomness(),
2174 "max_concurrent_execution_workers implies a single congestion tracker and suggested \
2175 gas price calculator for all transactions, which is incompatible with \
2176 separate_gas_price_feedback_mechanism_for_randomness"
2177 );
2178 assert!(
2179 res != Some(0),
2180 "max_concurrent_execution_workers must be positive when set"
2181 );
2182 res
2183 }
2184
2185 pub fn allow_unbounded_system_objects(&self) -> bool {
2186 self.feature_flags.allow_unbounded_system_objects
2187 }
2188
2189 pub fn reject_immutable_account_objects(&self) -> bool {
2190 let reject_immutable_account_objects = self.feature_flags.reject_immutable_account_objects;
2191 assert!(
2192 !reject_immutable_account_objects || self.enable_move_authentication(),
2193 "reject_immutable_account_objects requires enable_move_authentication to be set"
2194 );
2195 reject_immutable_account_objects
2196 }
2197
2198 pub fn validate_input_object_versions(&self) -> bool {
2199 self.feature_flags.validate_input_object_versions
2200 }
2201
2202 pub fn check_canonical_module_version_header(&self) -> bool {
2203 self.feature_flags.check_canonical_module_version_header
2204 }
2205
2206 pub fn disallow_randomness_in_move_authenticator(&self) -> bool {
2207 self.feature_flags.disallow_randomness_in_move_authenticator
2208 }
2209
2210 pub fn check_cyclic_dependencies(&self) -> bool {
2211 self.feature_flags.check_cyclic_dependencies
2212 }
2213
2214 pub fn deprecate_global_storage_ops_during_deserialization(&self) -> bool {
2215 self.feature_flags
2216 .deprecate_global_storage_ops_during_deserialization
2217 }
2218}
2219
2220#[cfg(not(msim))]
2221static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2222
2223#[cfg(msim)]
2225thread_local! {
2226 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2227}
2228
2229impl ProtocolConfig {
2231 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
2234 assert!(
2236 version >= ProtocolVersion::MIN,
2237 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
2238 version,
2239 ProtocolVersion::MIN.0,
2240 );
2241 assert!(
2242 version <= ProtocolVersion::MAX_ALLOWED,
2243 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
2244 version,
2245 ProtocolVersion::MAX_ALLOWED.0,
2246 );
2247
2248 let mut ret = Self::get_for_version_impl(version, chain);
2249 ret.version = version;
2250
2251 ret = CONFIG_OVERRIDE.with(|ovr| {
2252 if let Some(override_fn) = &*ovr.borrow() {
2253 warn!(
2254 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
2255 );
2256 override_fn(version, ret)
2257 } else {
2258 ret
2259 }
2260 });
2261
2262 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
2263 warn!(
2264 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
2265 );
2266
2267 let overrides: ProtocolConfigOptional =
2269 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
2270 .expect("failed to parse ProtocolConfig override env variables");
2271 overrides.apply_to(&mut ret);
2272
2273 let feature_flag_overrides: FeatureFlagsOptional =
2275 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_FEATURE_FLAGS_OVERRIDE")
2276 .expect("failed to parse ProtocolConfig feature flags override env variables");
2277
2278 feature_flag_overrides.apply_to(&mut ret.feature_flags);
2279 }
2280
2281 assert!(
2283 !ret.feature_flags.deny_rule_governance_on_chain
2284 || ret.feature_flags.deny_rule_governance,
2285 "deny_rule_governance_on_chain requires deny_rule_governance"
2286 );
2287 assert!(
2292 !ret.feature_flags.pcool_verifier_limits_from_protocol_config
2293 || ret.max_meter_ticks_regex_reference_safety.is_some(),
2294 "pcool_verifier_limits_from_protocol_config requires \
2295 max_meter_ticks_regex_reference_safety"
2296 );
2297 assert!(
2300 !ret.feature_flags.deny_rule_governance_on_chain
2301 || (ret.deny_rule_update_max_entries_per_tx.is_some()
2302 && ret.deny_rule_removal_grace_round_floor.is_some()),
2303 "deny_rule_governance_on_chain requires deny_rule_update_max_entries_per_tx and deny_rule_removal_grace_round_floor"
2304 );
2305 const DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING: u64 = 2048;
2313 assert!(
2314 ret.deny_rule_update_max_entries_per_tx
2315 .is_none_or(|max_entries| {
2316 max_entries > 0
2317 && max_entries <= DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING
2318 && [
2319 ret.max_num_new_move_object_ids_system_tx,
2320 ret.max_num_deleted_move_object_ids_system_tx,
2321 ret.object_runtime_max_num_cached_objects_system_tx,
2322 ret.object_runtime_max_num_store_entries_system_tx,
2323 ]
2324 .iter()
2325 .all(|limit| limit.is_none_or(|limit| max_entries <= limit))
2326 }),
2327 "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"
2328 );
2329
2330 ret
2331 }
2332
2333 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
2336 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
2337 let mut ret = Self::get_for_version_impl(version, chain);
2338 ret.version = version;
2339 Some(ret)
2340 } else {
2341 None
2342 }
2343 }
2344
2345 #[cfg(not(msim))]
2346 pub fn poison_get_for_min_version() {
2347 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
2348 }
2349
2350 #[cfg(not(msim))]
2351 fn load_poison_get_for_min_version() -> bool {
2352 POISON_VERSION_METHODS.load(Ordering::Relaxed)
2353 }
2354
2355 #[cfg(msim)]
2356 pub fn poison_get_for_min_version() {
2357 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
2358 }
2359
2360 #[cfg(msim)]
2361 fn load_poison_get_for_min_version() -> bool {
2362 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
2363 }
2364
2365 pub fn convert_type_argument_error(&self) -> bool {
2366 self.feature_flags.convert_type_argument_error
2367 }
2368
2369 pub fn get_for_min_version() -> Self {
2373 if Self::load_poison_get_for_min_version() {
2374 panic!("get_for_min_version called on validator");
2375 }
2376 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
2377 }
2378
2379 #[expect(non_snake_case)]
2390 pub fn get_for_max_version_UNSAFE() -> Self {
2391 if Self::load_poison_get_for_min_version() {
2392 panic!("get_for_max_version_UNSAFE called on validator");
2393 }
2394 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
2395 }
2396
2397 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
2398 #[cfg(msim)]
2399 {
2400 if version > ProtocolVersion::MAX {
2402 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
2403 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
2404 return config;
2405 }
2406 }
2407
2408 let mut cfg = Self {
2412 version,
2413
2414 feature_flags: Default::default(),
2415
2416 max_tx_size_bytes: Some(128 * 1024),
2417 max_input_objects: Some(2048),
2420 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
2421 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
2422 max_gas_payment_objects: Some(256),
2423 max_modules_in_publish: Some(64),
2424 max_package_dependencies: Some(32),
2425 max_arguments: Some(512),
2426 max_type_arguments: Some(16),
2427 max_type_argument_depth: Some(16),
2428 max_pure_argument_size: Some(16 * 1024),
2429 max_programmable_tx_commands: Some(1024),
2430 move_binary_format_version: Some(7),
2431 min_move_binary_format_version: Some(6),
2432 binary_module_handles: Some(100),
2433 binary_struct_handles: Some(300),
2434 binary_function_handles: Some(1500),
2435 binary_function_instantiations: Some(750),
2436 binary_signatures: Some(1000),
2437 binary_constant_pool: Some(4000),
2438 binary_identifiers: Some(10000),
2439 binary_address_identifiers: Some(100),
2440 binary_struct_defs: Some(200),
2441 binary_struct_def_instantiations: Some(100),
2442 binary_function_defs: Some(1000),
2443 binary_field_handles: Some(500),
2444 binary_field_instantiations: Some(250),
2445 binary_friend_decls: Some(100),
2446 binary_enum_defs: None,
2447 binary_enum_def_instantiations: None,
2448 binary_variant_handles: None,
2449 binary_variant_instantiation_handles: None,
2450 max_move_object_size: Some(250 * 1024),
2451 max_move_package_size: Some(100 * 1024),
2452 max_publish_or_upgrade_per_ptb: Some(5),
2453 max_auth_gas: None,
2455 max_tx_gas: Some(50_000_000_000),
2457 max_gas_price: Some(100_000),
2458 max_gas_computation_bucket: Some(5_000_000),
2459 max_loop_depth: Some(5),
2460 max_generic_instantiation_length: Some(32),
2461 max_function_parameters: Some(128),
2462 max_basic_blocks: Some(1024),
2463 max_value_stack_size: Some(1024),
2464 max_type_nodes: Some(256),
2465 max_push_size: Some(10000),
2466 max_struct_definitions: Some(200),
2467 max_function_definitions: Some(1000),
2468 max_fields_in_struct: Some(32),
2469 max_dependency_depth: Some(100),
2470 max_num_event_emit: Some(1024),
2471 max_num_new_move_object_ids: Some(2048),
2472 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
2473 max_num_deleted_move_object_ids: Some(2048),
2474 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
2475 max_num_transferred_move_object_ids: Some(2048),
2476 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
2477 max_event_emit_size: Some(250 * 1024),
2478 max_move_vector_len: Some(256 * 1024),
2479 max_type_to_layout_nodes: None,
2480 max_ptb_value_size: None,
2481
2482 max_back_edges_per_function: Some(10_000),
2483 max_back_edges_per_module: Some(10_000),
2484
2485 max_verifier_meter_ticks_per_function: Some(16_000_000),
2486
2487 max_meter_ticks_per_module: Some(16_000_000),
2488 max_meter_ticks_per_package: Some(16_000_000),
2489 max_meter_ticks_regex_reference_safety: None,
2490
2491 object_runtime_max_num_cached_objects: Some(1000),
2492 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2493 object_runtime_max_num_store_entries: Some(1000),
2494 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2495 base_tx_cost_fixed: Some(1_000),
2497 package_publish_cost_fixed: Some(1_000),
2498 base_tx_cost_per_byte: Some(0),
2499 package_publish_cost_per_byte: Some(80),
2500 obj_access_cost_read_per_byte: Some(15),
2501 obj_access_cost_mutate_per_byte: Some(40),
2502 obj_access_cost_delete_per_byte: Some(40),
2503 obj_access_cost_verify_per_byte: Some(200),
2504 obj_data_cost_refundable: Some(100),
2505 obj_metadata_cost_non_refundable: Some(50),
2506 gas_model_version: Some(1),
2507 storage_rebate_rate: Some(10000),
2508 reward_slashing_rate: Some(10000),
2510 storage_gas_price: Some(76),
2511 base_gas_price: None,
2512 validator_target_reward: Some(767_000 * 1_000_000_000),
2515 max_transactions_per_checkpoint: Some(10_000),
2516 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2517
2518 buffer_stake_for_protocol_upgrade_bps: Some(5000),
2520
2521 address_from_bytes_cost_base: Some(52),
2525 address_to_u256_cost_base: Some(52),
2527 address_from_u256_cost_base: Some(52),
2529
2530 config_read_setting_impl_cost_base: Some(100),
2533 config_read_setting_impl_cost_per_byte: Some(40),
2534
2535 dynamic_field_hash_type_and_key_cost_base: Some(100),
2539 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
2540 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
2541 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
2542 dynamic_field_add_child_object_cost_base: Some(100),
2545 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2546 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2547 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2548 dynamic_field_borrow_child_object_cost_base: Some(100),
2551 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2552 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2553 dynamic_field_remove_child_object_cost_base: Some(100),
2556 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2557 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2558 dynamic_field_has_child_object_cost_base: Some(100),
2561 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2564 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2565 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2566
2567 event_emit_cost_base: Some(52),
2570 event_emit_value_size_derivation_cost_per_byte: Some(2),
2571 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2572 event_emit_output_cost_per_byte: Some(10),
2573
2574 object_borrow_uid_cost_base: Some(52),
2577 object_delete_impl_cost_base: Some(52),
2579 object_record_new_uid_cost_base: Some(52),
2581
2582 transfer_transfer_internal_cost_base: Some(52),
2586 transfer_freeze_object_cost_base: Some(52),
2588 transfer_share_object_cost_base: Some(52),
2590 transfer_receive_object_cost_base: Some(52),
2591
2592 tx_context_derive_id_cost_base: Some(52),
2596 tx_context_fresh_id_cost_base: None,
2597 tx_context_sender_cost_base: None,
2598 tx_context_digest_cost_base: None,
2599 tx_context_epoch_cost_base: None,
2600 tx_context_epoch_timestamp_ms_cost_base: None,
2601 tx_context_sponsor_cost_base: None,
2602 tx_context_rgp_cost_base: None,
2603 tx_context_gas_price_cost_base: None,
2604 tx_context_gas_budget_cost_base: None,
2605 tx_context_ids_created_cost_base: None,
2606 tx_context_replace_cost_base: None,
2607
2608 types_is_one_time_witness_cost_base: Some(52),
2611 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2612 types_is_one_time_witness_type_cost_per_byte: Some(2),
2613
2614 validator_validate_metadata_cost_base: Some(52),
2618 validator_validate_metadata_data_cost_per_byte: Some(2),
2619
2620 crypto_invalid_arguments_cost: Some(100),
2622 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2624 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2625 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2626
2627 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2629 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2630 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2631
2632 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2634 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2635 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2636 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2637 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2638 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2639
2640 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2642
2643 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2645 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2646 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2647 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2648 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2649 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2650
2651 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2653 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2654 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2655 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2656 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2657 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2658
2659 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2661 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2662 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2663 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2664 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2665 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2666
2667 ecvrf_ecvrf_verify_cost_base: Some(52),
2669 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2670 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2671
2672 ed25519_ed25519_verify_cost_base: Some(52),
2674 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2675 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2676
2677 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2679 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2680
2681 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2683 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2684 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2685 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2686 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2687
2688 hash_blake2b256_cost_base: Some(52),
2690 hash_blake2b256_data_cost_per_byte: Some(2),
2691 hash_blake2b256_data_cost_per_block: Some(2),
2692 hash_keccak256_cost_base: Some(52),
2694 hash_keccak256_data_cost_per_byte: Some(2),
2695 hash_keccak256_data_cost_per_block: Some(2),
2696
2697 poseidon_bn254_cost_base: None,
2698 poseidon_bn254_cost_per_block: None,
2699
2700 hmac_hmac_sha3_256_cost_base: Some(52),
2702 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2703 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2704
2705 group_ops_bls12381_decode_scalar_cost: Some(52),
2707 group_ops_bls12381_decode_g1_cost: Some(52),
2708 group_ops_bls12381_decode_g2_cost: Some(52),
2709 group_ops_bls12381_decode_gt_cost: Some(52),
2710 group_ops_bls12381_scalar_add_cost: Some(52),
2711 group_ops_bls12381_g1_add_cost: Some(52),
2712 group_ops_bls12381_g2_add_cost: Some(52),
2713 group_ops_bls12381_gt_add_cost: Some(52),
2714 group_ops_bls12381_scalar_sub_cost: Some(52),
2715 group_ops_bls12381_g1_sub_cost: Some(52),
2716 group_ops_bls12381_g2_sub_cost: Some(52),
2717 group_ops_bls12381_gt_sub_cost: Some(52),
2718 group_ops_bls12381_scalar_mul_cost: Some(52),
2719 group_ops_bls12381_g1_mul_cost: Some(52),
2720 group_ops_bls12381_g2_mul_cost: Some(52),
2721 group_ops_bls12381_gt_mul_cost: Some(52),
2722 group_ops_bls12381_scalar_div_cost: Some(52),
2723 group_ops_bls12381_g1_div_cost: Some(52),
2724 group_ops_bls12381_g2_div_cost: Some(52),
2725 group_ops_bls12381_gt_div_cost: Some(52),
2726 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2727 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2728 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2729 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2730 group_ops_bls12381_g1_msm_base_cost: Some(52),
2731 group_ops_bls12381_g2_msm_base_cost: Some(52),
2732 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2733 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2734 group_ops_bls12381_msm_max_len: Some(32),
2735 group_ops_bls12381_pairing_cost: Some(52),
2736 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2737 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2738 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2739 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2740 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2741
2742 #[allow(deprecated)]
2744 check_zklogin_id_cost_base: Some(200),
2745 #[allow(deprecated)]
2746 check_zklogin_issuer_cost_base: Some(200),
2748
2749 vdf_verify_vdf_cost: None,
2750 vdf_hash_to_input_cost: None,
2751
2752 bcs_per_byte_serialized_cost: Some(2),
2753 bcs_legacy_min_output_size_cost: Some(1),
2754 bcs_failure_cost: Some(52),
2755 hash_sha2_256_base_cost: Some(52),
2756 hash_sha2_256_per_byte_cost: Some(2),
2757 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2758 hash_sha3_256_base_cost: Some(52),
2759 hash_sha3_256_per_byte_cost: Some(2),
2760 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2761 type_name_get_base_cost: Some(52),
2762 type_name_get_per_byte_cost: Some(2),
2763 string_check_utf8_base_cost: Some(52),
2764 string_check_utf8_per_byte_cost: Some(2),
2765 string_is_char_boundary_base_cost: Some(52),
2766 string_sub_string_base_cost: Some(52),
2767 string_sub_string_per_byte_cost: Some(2),
2768 string_index_of_base_cost: Some(52),
2769 string_index_of_per_byte_pattern_cost: Some(2),
2770 string_index_of_per_byte_searched_cost: Some(2),
2771 vector_empty_base_cost: Some(52),
2772 vector_length_base_cost: Some(52),
2773 vector_push_back_base_cost: Some(52),
2774 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2775 vector_borrow_base_cost: Some(52),
2776 vector_pop_back_base_cost: Some(52),
2777 vector_destroy_empty_base_cost: Some(52),
2778 vector_swap_base_cost: Some(52),
2779 debug_print_base_cost: Some(52),
2780 debug_print_stack_trace_base_cost: Some(52),
2781
2782 max_size_written_objects: Some(5 * 1000 * 1000),
2783 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2786
2787 max_move_identifier_len: Some(128),
2789 max_move_value_depth: Some(128),
2790 max_move_enum_variants: None,
2791
2792 gas_rounding_step: Some(1_000),
2793
2794 execution_version: Some(1),
2795
2796 max_event_emit_size_total: Some(
2799 256 * 250 * 1024, ),
2801
2802 consensus_bad_nodes_stake_threshold: Some(20),
2809
2810 #[allow(deprecated)]
2812 max_jwk_votes_per_validator_per_epoch: Some(240),
2813
2814 #[allow(deprecated)]
2815 max_age_of_jwk_in_epochs: Some(1),
2816
2817 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2821
2822 random_beacon_reduction_allowed_delta: Some(800),
2823
2824 random_beacon_reduction_lower_bound: Some(1000),
2825 random_beacon_dkg_timeout_round: Some(3000),
2826 random_beacon_min_round_interval_ms: Some(500),
2827
2828 random_beacon_dkg_version: Some(1),
2829
2830 consensus_max_num_transactions_in_block: Some(512),
2834
2835 max_deferral_rounds_for_congestion_control: Some(10),
2836
2837 min_checkpoint_interval_ms: Some(200),
2838
2839 checkpoint_rate_window_size: None,
2840
2841 checkpoint_summary_version_specific_data: Some(1),
2842
2843 max_soft_bundle_size: Some(5),
2844
2845 bridge_should_try_to_finalize_committee: None,
2846
2847 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2848
2849 max_committee_members_count: None,
2850 deny_rule_update_max_entries_per_tx: None,
2851 deny_rule_removal_grace_round_floor: None,
2852
2853 consensus_gc_depth: None,
2854
2855 consensus_max_acknowledgments_per_block: None,
2856
2857 max_congestion_limit_overshoot_per_commit: None,
2858
2859 max_concurrent_execution_workers: None,
2860
2861 scorer_version: None,
2862
2863 auth_context_digest_cost_base: None,
2865 auth_context_tx_data_bytes_cost_base: None,
2866 auth_context_tx_data_bytes_cost_per_byte: None,
2867 auth_context_tx_commands_cost_base: None,
2868 auth_context_tx_commands_cost_per_byte: None,
2869 auth_context_tx_inputs_cost_base: None,
2870 auth_context_tx_inputs_cost_per_byte: None,
2871 auth_context_replace_cost_base: None,
2872 auth_context_replace_cost_per_byte: None,
2873 auth_context_authenticator_function_info_v1_cost_base: None,
2874 consensus_commits_per_schedule: None,
2875 min_validator_count: None,
2876 max_validator_count: None,
2877 min_validator_joining_stake: None,
2878 validator_low_stake_threshold: None,
2879 validator_very_low_stake_threshold: None,
2880 validator_low_stake_grace_period: None,
2881 consensus_leader_schedule_window_size: None,
2882 };
2885
2886 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2887
2888 {
2890 cfg.feature_flags
2891 .disable_invariant_violation_check_in_swap_loc = true;
2892 cfg.feature_flags.no_extraneous_module_bytes = true;
2893 cfg.feature_flags.hardened_otw_check = true;
2894 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2895 }
2896
2897 {
2899 #[allow(deprecated)]
2900 {
2901 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2902 }
2903 }
2904
2905 #[expect(deprecated)]
2909 {
2910 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2911 }
2912 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2914
2915 cfg.feature_flags.per_object_congestion_control_mode =
2916 PerObjectCongestionControlMode::TotalTxCount;
2917
2918 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2920
2921 if chain != Chain::Mainnet && chain != Chain::Testnet {
2923 cfg.feature_flags.enable_poseidon = true;
2924 cfg.poseidon_bn254_cost_base = Some(260);
2925 cfg.poseidon_bn254_cost_per_block = Some(10);
2926
2927 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2928
2929 cfg.feature_flags.enable_vdf = true;
2930 cfg.vdf_verify_vdf_cost = Some(1500);
2933 cfg.vdf_hash_to_input_cost = Some(100);
2934
2935 cfg.feature_flags.passkey_auth = true;
2936 }
2937
2938 for cur in 2..=version.0 {
2939 match cur {
2940 1 => unreachable!(),
2941 2 => {}
2943 3 => {
2944 cfg.feature_flags.relocate_event_module = true;
2945 }
2946 4 => {
2947 cfg.max_type_to_layout_nodes = Some(512);
2948 }
2949 5 => {
2950 cfg.feature_flags.protocol_defined_base_fee = true;
2951 cfg.base_gas_price = Some(1000);
2952
2953 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2954 cfg.feature_flags.convert_type_argument_error = true;
2955 cfg.feature_flags.native_charging_v2 = true;
2956
2957 if chain != Chain::Mainnet && chain != Chain::Testnet {
2958 cfg.feature_flags.uncompressed_g1_group_elements = true;
2959 }
2960
2961 cfg.gas_model_version = Some(2);
2962
2963 cfg.poseidon_bn254_cost_per_block = Some(388);
2964
2965 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2966 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2967 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2968 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2969 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2970 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2971 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2972 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2973
2974 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2976 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2977 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2978 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2979
2980 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2981 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2982 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2983 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2984 Some(8213);
2985 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2986 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2987 Some(9484);
2988
2989 cfg.hash_keccak256_cost_base = Some(10);
2990 cfg.hash_blake2b256_cost_base = Some(10);
2991
2992 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2994 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2995 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2996 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2997
2998 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2999 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
3000 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
3001 cfg.group_ops_bls12381_gt_add_cost = Some(188);
3002
3003 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
3004 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
3005 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
3006 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
3007
3008 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
3009 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
3010 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
3011 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
3012
3013 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
3014 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
3015 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
3016 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
3017
3018 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
3019 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
3020
3021 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
3022 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
3023 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
3024 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
3025
3026 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
3027 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
3028 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
3029 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
3030 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
3031
3032 cfg.group_ops_bls12381_pairing_cost = Some(26897);
3033
3034 cfg.validator_validate_metadata_cost_base = Some(20000);
3035
3036 cfg.max_committee_members_count = Some(50);
3037 }
3038 6 => {
3039 cfg.max_ptb_value_size = Some(1024 * 1024);
3040 }
3041 7 => {
3042 }
3045 8 => {
3046 cfg.feature_flags.variant_nodes = true;
3047
3048 if chain != Chain::Mainnet {
3049 cfg.feature_flags.consensus_round_prober = true;
3051 cfg.feature_flags
3053 .consensus_distributed_vote_scoring_strategy = true;
3054 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
3055 cfg.feature_flags.consensus_smart_ancestor_selection = true;
3057 cfg.feature_flags
3059 .consensus_round_prober_probe_accepted_rounds = true;
3060 cfg.feature_flags.consensus_zstd_compression = true;
3062 cfg.consensus_gc_depth = Some(60);
3066 }
3067
3068 if chain != Chain::Testnet && chain != Chain::Mainnet {
3071 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
3072 }
3073 }
3074 9 => {
3075 if chain != Chain::Mainnet {
3076 cfg.feature_flags.consensus_smart_ancestor_selection = false;
3078 }
3079
3080 cfg.feature_flags.consensus_zstd_compression = true;
3082
3083 if chain != Chain::Testnet && chain != Chain::Mainnet {
3085 cfg.feature_flags.accept_passkey_in_multisig = true;
3086 }
3087
3088 cfg.bridge_should_try_to_finalize_committee = None;
3090 }
3091 10 => {
3092 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
3095
3096 cfg.max_committee_members_count = Some(80);
3098
3099 cfg.feature_flags.consensus_round_prober = true;
3101 cfg.feature_flags
3103 .consensus_round_prober_probe_accepted_rounds = true;
3104 cfg.feature_flags
3106 .consensus_distributed_vote_scoring_strategy = true;
3107 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
3109
3110 cfg.consensus_gc_depth = Some(60);
3115
3116 cfg.feature_flags.minimize_child_object_mutations = true;
3118
3119 if chain != Chain::Mainnet {
3120 cfg.feature_flags.consensus_batched_block_sync = true;
3122 }
3123
3124 if chain != Chain::Testnet && chain != Chain::Mainnet {
3125 cfg.feature_flags
3128 .congestion_control_gas_price_feedback_mechanism = true;
3129 }
3130
3131 cfg.feature_flags.validate_identifier_inputs = true;
3132 cfg.feature_flags.dependency_linkage_error = true;
3133 cfg.feature_flags.additional_multisig_checks = true;
3134 }
3135 11 => {
3136 }
3139 12 => {
3140 cfg.feature_flags
3143 .congestion_control_gas_price_feedback_mechanism = true;
3144
3145 cfg.feature_flags.normalize_ptb_arguments = true;
3147 }
3148 13 => {
3149 cfg.feature_flags.select_committee_from_eligible_validators = true;
3152 cfg.feature_flags.track_non_committee_eligible_validators = true;
3155
3156 if chain != Chain::Testnet && chain != Chain::Mainnet {
3157 cfg.feature_flags
3160 .select_committee_supporting_next_epoch_version = true;
3161 }
3162 }
3163 14 => {
3164 cfg.feature_flags.consensus_batched_block_sync = true;
3166
3167 if chain != Chain::Mainnet {
3168 cfg.feature_flags
3171 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3172 cfg.feature_flags
3176 .select_committee_supporting_next_epoch_version = true;
3177 }
3178 if chain != Chain::Testnet && chain != Chain::Mainnet {
3179 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3181 }
3182 }
3183 15 => {
3184 if chain != Chain::Mainnet && chain != Chain::Testnet {
3185 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3189 }
3190 }
3191 16 => {
3192 cfg.feature_flags
3195 .select_committee_supporting_next_epoch_version = true;
3196 cfg.feature_flags
3198 .consensus_commit_transactions_only_for_traversed_headers = true;
3199 }
3200 17 => {
3201 cfg.max_committee_members_count = Some(100);
3203 }
3204 18 => {
3205 if chain != Chain::Mainnet {
3206 cfg.feature_flags.passkey_auth = true;
3208 }
3209 }
3210 19 => {
3211 if chain != Chain::Testnet && chain != Chain::Mainnet {
3212 cfg.feature_flags
3215 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3216 cfg.feature_flags
3219 .separate_gas_price_feedback_mechanism_for_randomness = true;
3220 cfg.feature_flags.metadata_in_module_bytes = true;
3223 cfg.feature_flags.publish_package_metadata = true;
3224 cfg.feature_flags.enable_move_authentication = true;
3226 cfg.max_auth_gas = Some(250_000_000);
3228 cfg.transfer_receive_object_cost_base = Some(100);
3231 cfg.feature_flags.adjust_rewards_by_score = true;
3233 }
3234
3235 if chain != Chain::Mainnet {
3236 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3238
3239 cfg.feature_flags.calculate_validator_scores = true;
3241 cfg.scorer_version = Some(1);
3242 }
3243
3244 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
3246
3247 cfg.feature_flags.passkey_auth = true;
3249 }
3250 20 => {
3251 if chain != Chain::Testnet && chain != Chain::Mainnet {
3252 cfg.feature_flags
3254 .pass_calculated_validator_scores_to_advance_epoch = true;
3255 }
3256 }
3257 21 => {
3258 if chain != Chain::Testnet && chain != Chain::Mainnet {
3259 cfg.feature_flags.consensus_fast_commit_sync = true;
3261 }
3262 if chain != Chain::Mainnet {
3263 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3268 cfg.feature_flags
3271 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3272 cfg.feature_flags
3275 .separate_gas_price_feedback_mechanism_for_randomness = true;
3276 }
3277
3278 cfg.auth_context_digest_cost_base = Some(30);
3279 cfg.auth_context_tx_commands_cost_base = Some(30);
3280 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
3281 cfg.auth_context_tx_inputs_cost_base = Some(30);
3282 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
3283 cfg.auth_context_replace_cost_base = Some(30);
3284 cfg.auth_context_replace_cost_per_byte = Some(2);
3285
3286 if chain != Chain::Testnet && chain != Chain::Mainnet {
3287 cfg.max_auth_gas = Some(250_000);
3289 }
3290 }
3291 22 => {
3292 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3297 cfg.feature_flags
3300 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3301 cfg.feature_flags
3304 .separate_gas_price_feedback_mechanism_for_randomness = true;
3305
3306 if chain != Chain::Mainnet {
3307 cfg.feature_flags.metadata_in_module_bytes = true;
3310 cfg.feature_flags.publish_package_metadata = true;
3311 cfg.feature_flags.enable_move_authentication = true;
3313 cfg.max_auth_gas = Some(250_000);
3315 cfg.transfer_receive_object_cost_base = Some(100);
3318 }
3319
3320 if chain != Chain::Mainnet {
3321 cfg.feature_flags.consensus_fast_commit_sync = true;
3323 }
3324 }
3325 23 => {
3326 cfg.feature_flags.move_native_tx_context = true;
3328 cfg.tx_context_fresh_id_cost_base = Some(52);
3329 cfg.tx_context_sender_cost_base = Some(30);
3330 cfg.tx_context_digest_cost_base = Some(30);
3331 cfg.tx_context_epoch_cost_base = Some(30);
3332 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
3333 cfg.tx_context_sponsor_cost_base = Some(30);
3334 cfg.tx_context_rgp_cost_base = Some(30);
3335 cfg.tx_context_gas_price_cost_base = Some(30);
3336 cfg.tx_context_gas_budget_cost_base = Some(30);
3337 cfg.tx_context_ids_created_cost_base = Some(30);
3338 cfg.tx_context_replace_cost_base = Some(30);
3339 }
3340 24 => {
3341 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3343
3344 if chain != Chain::Testnet && chain != Chain::Mainnet {
3345 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3347 }
3348
3349 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
3352 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
3353
3354 cfg.feature_flags.additional_borrow_checks = true;
3356 }
3357 #[allow(deprecated)]
3358 25 => {
3359 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
3362 cfg.check_zklogin_id_cost_base = None;
3363 cfg.check_zklogin_issuer_cost_base = None;
3364 cfg.max_jwk_votes_per_validator_per_epoch = None;
3365 cfg.max_age_of_jwk_in_epochs = None;
3366 }
3367 26 => {
3368 }
3371 27 => {
3372 if chain != Chain::Mainnet {
3373 cfg.feature_flags.consensus_block_restrictions = true;
3376 }
3377
3378 if chain != Chain::Testnet && chain != Chain::Mainnet {
3379 cfg.feature_flags
3381 .pre_consensus_sponsor_only_move_authentication = true;
3382 }
3383 }
3384 28 => {
3385 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
3390
3391 cfg.feature_flags.metadata_in_module_bytes = true;
3394 cfg.feature_flags.publish_package_metadata = true;
3395 cfg.feature_flags.enable_move_authentication = true;
3397 cfg.transfer_receive_object_cost_base = Some(100);
3400
3401 if chain != Chain::Unknown {
3402 cfg.max_auth_gas = Some(20_000);
3404 }
3405
3406 if chain != Chain::Mainnet {
3407 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3409 cfg.feature_flags
3411 .pre_consensus_sponsor_only_move_authentication = true;
3412 }
3413 }
3414 29 => {
3415 cfg.feature_flags.always_advance_dkg_to_resolution = true;
3421
3422 cfg.feature_flags
3425 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3426
3427 cfg.feature_flags.consensus_fast_commit_sync = true;
3429 cfg.feature_flags.consensus_block_restrictions = true;
3433 }
3434 30 => {
3435 }
3443 31 => {
3444 cfg.feature_flags.validator_metadata_verify_v2 = true;
3445
3446 if chain != Chain::Mainnet && chain != Chain::Testnet {
3447 cfg.checkpoint_rate_window_size = Some(20);
3450 cfg.feature_flags
3453 .package_metadata_with_dynamic_module_metadata = true;
3454 cfg.feature_flags.consensus_starfish_speed = true;
3457 }
3458
3459 cfg.feature_flags.report_move_authentication_error = true;
3460 }
3461 32 => {
3462 cfg.min_validator_count = Some(4);
3466 cfg.max_validator_count = Some(150);
3467 cfg.min_validator_joining_stake = Some(2_000_000_000_000_000);
3468 cfg.validator_low_stake_threshold = Some(1_500_000_000_000_000);
3469 cfg.validator_very_low_stake_threshold = Some(1_000_000_000_000_000);
3470 cfg.validator_low_stake_grace_period = Some(7);
3471
3472 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3474 cfg.feature_flags
3476 .pre_consensus_sponsor_only_move_authentication = true;
3477
3478 if chain != Chain::Mainnet {
3479 cfg.feature_flags.consensus_starfish_speed = true;
3482 cfg.checkpoint_rate_window_size = Some(20);
3485 cfg.feature_flags
3488 .package_metadata_with_dynamic_module_metadata = true;
3489 }
3490
3491 if chain != Chain::Mainnet && chain != Chain::Testnet {
3492 cfg.feature_flags
3496 .consensus_enable_sliding_window_leader_schedule = true;
3497 cfg.feature_flags
3498 .consensus_enable_absolute_score_leader_schedule = true;
3499 cfg.feature_flags.enable_pcool_flow = true;
3503 }
3504 }
3505 33 => {
3506 cfg.checkpoint_rate_window_size = Some(20);
3509 if chain != Chain::Mainnet {
3513 cfg.feature_flags
3514 .consensus_enable_sliding_window_leader_schedule = true;
3515 cfg.feature_flags
3516 .consensus_enable_absolute_score_leader_schedule = true;
3517 }
3518 }
3519 34 => {
3520 if chain != Chain::Testnet && chain != Chain::Mainnet {
3521 cfg.scorer_version = Some(2);
3525 }
3526 cfg.feature_flags.pcool_skip_immutable_object_locks = true;
3530
3531 if chain == Chain::Mainnet {
3532 cfg.feature_flags.enable_move_authentication_for_sponsor = false;
3534 cfg.feature_flags
3537 .pre_consensus_sponsor_only_move_authentication = false;
3538 }
3539 }
3540 35 => {
3541 cfg.feature_flags.max_ptb_value_size_v2 = true;
3543 cfg.feature_flags.allow_unbounded_system_objects = true;
3545
3546 cfg.feature_flags.consensus_starfish_speed = true;
3549
3550 cfg.max_verifier_meter_ticks_per_function = Some(2_200_000);
3557 cfg.max_meter_ticks_per_module = Some(2_200_000);
3558 cfg.max_meter_ticks_per_package = Some(2_200_000);
3559 cfg.max_meter_ticks_regex_reference_safety = Some(2_200_000);
3560 cfg.feature_flags.pcool_verifier_limits_from_protocol_config = true;
3561 cfg.feature_flags
3564 .package_metadata_with_dynamic_module_metadata = true;
3565 cfg.feature_flags
3569 .consensus_enable_sliding_window_leader_schedule = true;
3570 cfg.feature_flags
3571 .consensus_enable_absolute_score_leader_schedule = true;
3572
3573 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3576 cfg.feature_flags
3579 .pre_consensus_sponsor_only_move_authentication = false;
3580 }
3581 36 => {
3582 cfg.feature_flags.reject_immutable_account_objects = true;
3585 }
3586 37 => {
3587 cfg.feature_flags.validate_input_object_versions = true;
3591 cfg.feature_flags.disallow_self_identifier = true;
3592 cfg.max_move_enum_variants = Some(move_core_types::VARIANT_COUNT_MAX);
3593 cfg.feature_flags.deny_authenticator_packages = true;
3596 cfg.feature_flags.check_canonical_module_version_header = true;
3599 cfg.feature_flags.disallow_randomness_in_move_authenticator = true;
3604 cfg.feature_flags.check_cyclic_dependencies = true;
3607 }
3608 _ => panic!("unsupported version {version:?}"),
3619 }
3620 }
3621 cfg
3622 }
3623
3624 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
3630 let (
3631 max_back_edges_per_function,
3632 max_back_edges_per_module,
3633 sanity_check_with_regex_reference_safety,
3634 ) = if let Some((
3635 max_back_edges_per_function,
3636 max_back_edges_per_module,
3637 sanity_check_with_regex_reference_safety,
3638 )) = signing_limits
3639 {
3640 (
3641 Some(max_back_edges_per_function),
3642 Some(max_back_edges_per_module),
3643 Some(sanity_check_with_regex_reference_safety),
3644 )
3645 } else {
3646 (None, None, None)
3647 };
3648
3649 let additional_borrow_checks = if signing_limits.is_some() {
3650 true
3653 } else {
3654 self.additional_borrow_checks()
3655 };
3656
3657 VerifierConfig {
3658 max_loop_depth: Some(self.max_loop_depth() as usize),
3659 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
3660 max_function_parameters: Some(self.max_function_parameters() as usize),
3661 max_basic_blocks: Some(self.max_basic_blocks() as usize),
3662 max_value_stack_size: self.max_value_stack_size() as usize,
3663 max_type_nodes: Some(self.max_type_nodes() as usize),
3664 max_push_size: Some(self.max_push_size() as usize),
3665 max_dependency_depth: Some(self.max_dependency_depth() as usize),
3666 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
3667 max_function_definitions: Some(self.max_function_definitions() as usize),
3668 max_data_definitions: Some(self.max_struct_definitions() as usize),
3669 max_constant_vector_len: Some(self.max_move_vector_len()),
3670 max_back_edges_per_function,
3671 max_back_edges_per_module,
3672 max_basic_blocks_in_script: None,
3673 max_identifier_len: self.max_move_identifier_len_as_option(), disallow_self_identifier: self.feature_flags.disallow_self_identifier,
3677 bytecode_version: self.move_binary_format_version(),
3678 max_variants_in_enum: self.max_move_enum_variants_as_option(),
3679 additional_borrow_checks,
3680 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
3681 .map(|limit| limit as u128),
3682 check_cyclic_dependencies: self.feature_flags.check_cyclic_dependencies,
3683 }
3684 }
3685
3686 pub fn verifier_signing_limits(&self) -> (usize, usize, usize) {
3693 (
3694 self.max_back_edges_per_function() as usize,
3695 self.max_back_edges_per_module() as usize,
3696 self.max_meter_ticks_regex_reference_safety() as usize,
3697 )
3698 }
3699
3700 pub fn meter_config(&self) -> MeterConfig {
3704 MeterConfig {
3705 max_per_fun_meter_units: Some(self.max_verifier_meter_ticks_per_function() as u128),
3706 max_per_mod_meter_units: Some(self.max_meter_ticks_per_module() as u128),
3707 max_per_pkg_meter_units: Some(self.max_meter_ticks_per_package() as u128),
3708 }
3709 }
3710
3711 pub fn apply_overrides_for_testing(
3716 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
3717 ) -> OverrideGuard {
3718 CONFIG_OVERRIDE.with(|ovr| {
3719 let mut cur = ovr.borrow_mut();
3720 assert!(cur.is_none(), "config override already present");
3721 *cur = Some(Box::new(override_fn));
3722 OverrideGuard
3723 })
3724 }
3725}
3726
3727impl ProtocolConfig {
3732 pub fn set_per_object_congestion_control_mode_for_testing(
3733 &mut self,
3734 val: PerObjectCongestionControlMode,
3735 ) {
3736 self.feature_flags.per_object_congestion_control_mode = val;
3737 }
3738
3739 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
3740 self.feature_flags.consensus_choice = val;
3741 }
3742
3743 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
3744 self.feature_flags.consensus_network = val;
3745 }
3746
3747 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
3748 self.feature_flags.passkey_auth = val
3749 }
3750
3751 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
3752 self.feature_flags
3753 .disallow_new_modules_in_deps_only_packages = val;
3754 }
3755
3756 pub fn set_check_canonical_module_version_header_for_testing(&mut self, val: bool) {
3757 self.feature_flags.check_canonical_module_version_header = val;
3758 }
3759
3760 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
3761 self.feature_flags.consensus_round_prober = val;
3762 }
3763
3764 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
3765 self.feature_flags
3766 .consensus_distributed_vote_scoring_strategy = val;
3767 }
3768
3769 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
3770 self.consensus_gc_depth = Some(val);
3771 }
3772
3773 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
3774 self.feature_flags.consensus_linearize_subdag_v2 = val;
3775 }
3776
3777 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
3778 self.feature_flags
3779 .consensus_round_prober_probe_accepted_rounds = val;
3780 }
3781
3782 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
3783 self.feature_flags.accept_passkey_in_multisig = val;
3784 }
3785
3786 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
3787 self.feature_flags.consensus_smart_ancestor_selection = val;
3788 }
3789
3790 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
3791 self.feature_flags.consensus_batched_block_sync = val;
3792 }
3793
3794 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
3795 self.feature_flags
3796 .congestion_control_min_free_execution_slot = val;
3797 }
3798
3799 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
3800 self.feature_flags
3801 .congestion_control_gas_price_feedback_mechanism = val;
3802 }
3803
3804 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
3805 self.feature_flags.select_committee_from_eligible_validators = val;
3806 }
3807
3808 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
3809 self.feature_flags.track_non_committee_eligible_validators = val;
3810 }
3811
3812 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
3813 self.feature_flags
3814 .select_committee_supporting_next_epoch_version = val;
3815 }
3816
3817 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
3818 &mut self,
3819 val: bool,
3820 ) {
3821 self.feature_flags
3822 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3823 }
3824
3825 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3826 &mut self,
3827 val: bool,
3828 ) {
3829 self.feature_flags
3830 .consensus_commit_transactions_only_for_traversed_headers = val;
3831 }
3832
3833 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3834 &mut self,
3835 val: bool,
3836 ) {
3837 self.feature_flags
3838 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3839 }
3840
3841 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3842 &mut self,
3843 val: bool,
3844 ) {
3845 self.feature_flags
3846 .separate_gas_price_feedback_mechanism_for_randomness = val;
3847 }
3848
3849 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3850 self.feature_flags.metadata_in_module_bytes = val;
3851 }
3852
3853 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3854 self.feature_flags.publish_package_metadata = val;
3855 }
3856
3857 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3858 self.feature_flags.enable_move_authentication = val;
3859 }
3860
3861 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3862 self.feature_flags.enable_move_authentication_for_sponsor = val;
3863 }
3864
3865 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3866 self.feature_flags.consensus_fast_commit_sync = val;
3867 }
3868
3869 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3870 self.feature_flags.consensus_block_restrictions = val;
3871 }
3872
3873 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3874 self.feature_flags
3875 .pre_consensus_sponsor_only_move_authentication = val;
3876 }
3877
3878 pub fn set_consensus_starfish_speed_for_testing(&mut self, val: bool) {
3879 self.feature_flags.consensus_starfish_speed = val;
3880 }
3881
3882 pub fn set_always_advance_dkg_to_resolution_for_testing(&mut self, val: bool) {
3883 self.feature_flags.always_advance_dkg_to_resolution = val;
3884 }
3885
3886 pub fn set_enable_pcool_flow_for_testing(&mut self, val: bool) {
3887 self.feature_flags.enable_pcool_flow = val;
3888 }
3889
3890 pub fn set_pcool_skip_immutable_object_locks_for_testing(&mut self, val: bool) {
3891 self.feature_flags.pcool_skip_immutable_object_locks = val;
3892 }
3893
3894 pub fn set_pcool_verifier_limits_from_protocol_config_for_testing(&mut self, val: bool) {
3895 self.feature_flags
3896 .pcool_verifier_limits_from_protocol_config = val;
3897 }
3898
3899 pub fn set_reject_immutable_account_objects_for_testing(&mut self, val: bool) {
3900 self.feature_flags.reject_immutable_account_objects = val;
3901 }
3902
3903 pub fn set_validate_input_object_versions_for_testing(&mut self, val: bool) {
3904 self.feature_flags.validate_input_object_versions = val;
3905 }
3906
3907 pub fn set_disallow_randomness_in_move_authenticator_for_testing(&mut self, val: bool) {
3908 self.feature_flags.disallow_randomness_in_move_authenticator = val;
3909 }
3910
3911 pub fn set_commits_per_schedule_for_testing(&mut self, val: u32) {
3912 self.consensus_commits_per_schedule = Some(val);
3913 }
3914
3915 pub fn set_deny_rule_governance_for_testing(&mut self, val: bool) {
3916 self.feature_flags.deny_rule_governance = val;
3917 }
3918
3919 pub fn set_deny_authenticator_packages_for_testing(&mut self, val: bool) {
3920 self.feature_flags.deny_authenticator_packages = val;
3921 }
3922
3923 pub fn set_deny_rule_governance_on_chain_for_testing(&mut self, val: bool) {
3924 self.feature_flags.deny_rule_governance_on_chain = val;
3925 }
3926
3927 pub fn set_calculate_validator_scores_for_testing(&mut self, val: bool) {
3932 self.feature_flags.calculate_validator_scores = val;
3933 if val {
3934 self.scorer_version.get_or_insert(1);
3935 } else {
3936 self.feature_flags.adjust_rewards_by_score = false;
3937 self.feature_flags
3938 .pass_calculated_validator_scores_to_advance_epoch = false;
3939 }
3940 }
3941
3942 pub fn set_package_metadata_with_dynamic_module_metadata_for_testing(&mut self, val: bool) {
3943 self.feature_flags
3944 .package_metadata_with_dynamic_module_metadata = val;
3945 }
3946
3947 pub fn set_report_move_authentication_error_for_testing(&mut self, val: bool) {
3948 self.feature_flags.report_move_authentication_error = val;
3949 }
3950
3951 pub fn set_leader_schedule_window_size_for_testing(&mut self, val: u32) {
3952 self.consensus_leader_schedule_window_size = Some(val);
3953 }
3954
3955 pub fn set_consensus_enable_sliding_window_leader_schedule_for_testing(&mut self, val: bool) {
3956 self.feature_flags
3957 .consensus_enable_sliding_window_leader_schedule = val;
3958 }
3959
3960 pub fn set_consensus_enable_absolute_score_leader_schedule_for_testing(&mut self, val: bool) {
3961 self.feature_flags
3962 .consensus_enable_absolute_score_leader_schedule = val;
3963 }
3964}
3965
3966type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
3967
3968thread_local! {
3969 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
3970}
3971
3972#[must_use]
3973pub struct OverrideGuard;
3974
3975impl Drop for OverrideGuard {
3976 fn drop(&mut self) {
3977 info!("restoring override fn");
3978 CONFIG_OVERRIDE.with(|ovr| {
3979 *ovr.borrow_mut() = None;
3980 });
3981 }
3982}
3983
3984#[derive(PartialEq, Eq)]
3988pub enum LimitThresholdCrossed {
3989 None,
3990 Soft(u128, u128),
3991 Hard(u128, u128),
3992}
3993
3994pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
3997 x: T,
3998 soft_limit: U,
3999 hard_limit: V,
4000) -> LimitThresholdCrossed {
4001 let x: V = x.into();
4002 let soft_limit: V = soft_limit.into();
4003
4004 debug_assert!(soft_limit <= hard_limit);
4005
4006 if x >= hard_limit {
4009 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
4010 } else if x < soft_limit {
4011 LimitThresholdCrossed::None
4012 } else {
4013 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
4014 }
4015}
4016
4017#[macro_export]
4018macro_rules! check_limit {
4019 ($x:expr, $hard:expr) => {
4020 check_limit!($x, $hard, $hard)
4021 };
4022 ($x:expr, $soft:expr, $hard:expr) => {
4023 check_limit_in_range($x as u64, $soft, $hard)
4024 };
4025}
4026
4027#[macro_export]
4031macro_rules! check_limit_by_meter {
4032 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
4033 let (h, metered_str) = if $is_metered {
4035 ($metered_limit, "metered")
4036 } else {
4037 ($unmetered_hard_limit, "unmetered")
4039 };
4040 use iota_protocol_config::check_limit_in_range;
4041 let result = check_limit_in_range($x as u64, $metered_limit, h);
4042 match result {
4043 LimitThresholdCrossed::None => {}
4044 LimitThresholdCrossed::Soft(_, _) => {
4045 $metric.with_label_values(&[metered_str, "soft"]).inc();
4046 }
4047 LimitThresholdCrossed::Hard(_, _) => {
4048 $metric.with_label_values(&[metered_str, "hard"]).inc();
4049 }
4050 };
4051 result
4052 }};
4053}
4054
4055#[cfg(all(test, not(msim)))]
4056mod test {
4057 use insta::assert_yaml_snapshot;
4058
4059 use super::*;
4060
4061 #[test]
4062 fn snapshot_tests() {
4063 println!("\n============================================================================");
4064 println!("! !");
4065 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
4066 println!("! !");
4067 println!("============================================================================\n");
4068 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
4069 let chain_str = match chain_id {
4074 Chain::Unknown => "".to_string(),
4075 _ => format!("{chain_id:?}_"),
4076 };
4077 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
4078 let cur = ProtocolVersion::new(i);
4079 assert_yaml_snapshot!(
4080 format!("{}version_{}", chain_str, cur.as_u64()),
4081 ProtocolConfig::get_for_version(cur, *chain_id)
4082 );
4083 }
4084 }
4085 }
4086
4087 #[test]
4088 fn test_getters() {
4089 let prot: ProtocolConfig =
4090 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4091 assert_eq!(
4092 prot.max_arguments(),
4093 prot.max_arguments_as_option().unwrap()
4094 );
4095 }
4096
4097 #[test]
4098 fn test_setters() {
4099 let mut prot: ProtocolConfig =
4100 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4101 prot.set_max_arguments_for_testing(123);
4102 assert_eq!(prot.max_arguments(), 123);
4103
4104 prot.set_max_arguments_from_str_for_testing("321".to_string());
4105 assert_eq!(prot.max_arguments(), 321);
4106
4107 prot.disable_max_arguments_for_testing();
4108 assert_eq!(prot.max_arguments_as_option(), None);
4109
4110 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
4111 assert_eq!(prot.max_arguments(), 456);
4112 }
4113
4114 #[test]
4115 #[should_panic(expected = "unsupported version")]
4116 fn max_version_test() {
4117 let _ = ProtocolConfig::get_for_version_impl(
4120 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
4121 Chain::Unknown,
4122 );
4123 }
4124
4125 #[test]
4126 fn lookup_by_string_test() {
4127 let prot: ProtocolConfig =
4128 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
4129 assert!(prot.lookup_attr("some random string".to_string()).is_none());
4131
4132 assert!(
4133 prot.lookup_attr("max_arguments".to_string())
4134 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
4135 );
4136
4137 assert!(
4139 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
4140 .is_none()
4141 );
4142 assert!(
4143 prot.attr_map()
4144 .get("poseidon_bn254_cost_base")
4145 .unwrap()
4146 .is_none()
4147 );
4148
4149 let prot: ProtocolConfig =
4151 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4152
4153 assert!(
4154 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
4155 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
4156 );
4157 assert!(
4158 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
4159 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
4160 );
4161
4162 let prot: ProtocolConfig =
4164 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
4165 assert!(
4167 prot.feature_flags
4168 .lookup_attr("some random string".to_owned())
4169 .is_none()
4170 );
4171 assert!(
4172 !prot
4173 .feature_flags
4174 .attr_map()
4175 .contains_key("some random string")
4176 );
4177
4178 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
4180 assert!(
4181 prot.feature_flags
4182 .attr_map()
4183 .get("enable_poseidon")
4184 .unwrap()
4185 == &false
4186 );
4187 let prot: ProtocolConfig =
4188 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4189 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
4191 assert!(
4192 prot.feature_flags
4193 .attr_map()
4194 .get("enable_poseidon")
4195 .unwrap()
4196 == &true
4197 );
4198 }
4199
4200 #[test]
4204 #[should_panic(expected = "deny_rule_update_max_entries_per_tx must be positive")]
4205 fn deny_rule_chunk_limit_above_the_ceiling_is_rejected() {
4206 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
4207 config.set_deny_rule_governance_for_testing(true);
4208 config.set_deny_rule_governance_on_chain_for_testing(true);
4209 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
4210 config.set_deny_rule_update_max_entries_per_tx_for_testing(2048 + 1);
4211 config
4212 });
4213 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
4214 }
4215
4216 #[test]
4219 #[should_panic(expected = "deny_rule_update_max_entries_per_tx must be positive")]
4220 fn deny_rule_chunk_limit_of_zero_is_rejected() {
4221 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
4222 config.set_deny_rule_governance_for_testing(true);
4223 config.set_deny_rule_governance_on_chain_for_testing(true);
4224 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
4225 config.set_deny_rule_update_max_entries_per_tx_for_testing(0);
4226 config
4227 });
4228 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
4229 }
4230
4231 #[test]
4233 fn deny_rule_chunk_limit_within_system_tx_object_id_limit_is_accepted() {
4234 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
4235 config.set_deny_rule_governance_for_testing(true);
4236 config.set_deny_rule_governance_on_chain_for_testing(true);
4237 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
4238 config.set_deny_rule_update_max_entries_per_tx_for_testing(1000);
4239 config
4240 });
4241 let config = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
4242 assert_eq!(config.deny_rule_update_max_entries_per_tx(), 1000);
4243 }
4244
4245 #[test]
4246 fn limit_range_fn_test() {
4247 let low = 100u32;
4248 let high = 10000u64;
4249
4250 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
4251 assert!(matches!(
4252 check_limit!(255u16, low, high),
4253 LimitThresholdCrossed::Soft(255u128, 100)
4254 ));
4255 assert!(matches!(
4262 check_limit!(2550000u64, low, high),
4263 LimitThresholdCrossed::Hard(2550000, 10000)
4264 ));
4265
4266 assert!(matches!(
4267 check_limit!(2550000u64, high, high),
4268 LimitThresholdCrossed::Hard(2550000, 10000)
4269 ));
4270
4271 assert!(matches!(
4272 check_limit!(1u8, high),
4273 LimitThresholdCrossed::None
4274 ));
4275
4276 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
4277
4278 assert!(matches!(
4279 check_limit!(2550000u64, high),
4280 LimitThresholdCrossed::Hard(2550000, 10000)
4281 ));
4282 }
4283}