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 = 39;
23
24pub const PROTOCOL_VERSION_IIP8: u64 = 20;
26#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
257pub struct ProtocolVersion(u64);
258
259impl ProtocolVersion {
260 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
266
267 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
268
269 #[cfg(not(msim))]
270 const MAX_ALLOWED: Self = Self::MAX;
271
272 #[cfg(msim)]
275 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
276
277 pub fn new(v: u64) -> Self {
278 Self(v)
279 }
280
281 pub const fn as_u64(&self) -> u64 {
282 self.0
283 }
284
285 pub fn max() -> Self {
288 Self::MAX
289 }
290}
291
292impl From<u64> for ProtocolVersion {
293 fn from(v: u64) -> Self {
294 Self::new(v)
295 }
296}
297
298impl std::ops::Sub<u64> for ProtocolVersion {
299 type Output = Self;
300 fn sub(self, rhs: u64) -> Self::Output {
301 Self::new(self.0 - rhs)
302 }
303}
304
305impl std::ops::Add<u64> for ProtocolVersion {
306 type Output = Self;
307 fn add(self, rhs: u64) -> Self::Output {
308 Self::new(self.0 + rhs)
309 }
310}
311
312#[derive(
313 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
314)]
315pub enum Chain {
316 Mainnet,
317 Testnet,
318 #[default]
319 Unknown,
320}
321
322impl Chain {
323 pub fn as_str(self) -> &'static str {
324 match self {
325 Chain::Mainnet => "mainnet",
326 Chain::Testnet => "testnet",
327 Chain::Unknown => "unknown",
328 }
329 }
330}
331
332pub struct Error(pub String);
333
334#[derive(
338 Default,
339 Clone,
340 Serialize,
341 Deserialize,
342 Debug,
343 ProtocolConfigFeatureFlagsGetters,
344 ProtocolConfigOverride,
345)]
346struct FeatureFlags {
347 #[serde(skip_serializing_if = "is_true")]
353 disable_invariant_violation_check_in_swap_loc: bool,
354
355 #[serde(skip_serializing_if = "is_true")]
358 no_extraneous_module_bytes: bool,
359
360 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
362 consensus_transaction_ordering: ConsensusTransactionOrdering,
363
364 #[serde(skip_serializing_if = "is_true")]
367 hardened_otw_check: bool,
368
369 #[serde(skip_serializing_if = "is_false")]
371 enable_poseidon: bool,
372
373 #[serde(skip_serializing_if = "is_false")]
375 enable_group_ops_native_function_msm: bool,
376
377 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
379 per_object_congestion_control_mode: PerObjectCongestionControlMode,
380
381 #[serde(
383 default = "ConsensusChoice::mysticeti_deprecated",
384 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
385 )]
386 consensus_choice: ConsensusChoice,
387
388 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
390 consensus_network: ConsensusNetwork,
391
392 #[deprecated]
394 #[serde(skip_serializing_if = "Option::is_none")]
395 zklogin_max_epoch_upper_bound_delta: Option<u64>,
396
397 #[serde(skip_serializing_if = "is_false")]
399 enable_vdf: bool,
400
401 #[serde(skip_serializing_if = "is_false")]
403 passkey_auth: bool,
404
405 #[serde(skip_serializing_if = "is_true")]
408 rethrow_serialization_type_layout_errors: bool,
409
410 #[serde(skip_serializing_if = "is_false")]
412 relocate_event_module: bool,
413
414 #[serde(skip_serializing_if = "is_false")]
416 protocol_defined_base_fee: bool,
417
418 #[serde(skip_serializing_if = "is_false")]
420 uncompressed_g1_group_elements: bool,
421
422 #[serde(skip_serializing_if = "is_false")]
424 disallow_new_modules_in_deps_only_packages: bool,
425
426 #[serde(skip_serializing_if = "is_false")]
428 native_charging_v2: bool,
429
430 #[serde(skip_serializing_if = "is_false")]
432 convert_type_argument_error: bool,
433
434 #[serde(skip_serializing_if = "is_false")]
436 consensus_round_prober: bool,
437
438 #[serde(skip_serializing_if = "is_false")]
440 consensus_distributed_vote_scoring_strategy: bool,
441
442 #[serde(skip_serializing_if = "is_false")]
446 consensus_linearize_subdag_v2: bool,
447
448 #[serde(skip_serializing_if = "is_false")]
450 variant_nodes: bool,
451
452 #[serde(skip_serializing_if = "is_false")]
454 consensus_smart_ancestor_selection: bool,
455
456 #[serde(skip_serializing_if = "is_false")]
458 consensus_round_prober_probe_accepted_rounds: bool,
459
460 #[serde(skip_serializing_if = "is_false")]
462 consensus_zstd_compression: bool,
463
464 #[serde(skip_serializing_if = "is_false")]
467 congestion_control_min_free_execution_slot: bool,
468
469 #[serde(skip_serializing_if = "is_false")]
471 accept_passkey_in_multisig: bool,
472
473 #[serde(skip_serializing_if = "is_false")]
475 consensus_batched_block_sync: bool,
476
477 #[serde(skip_serializing_if = "is_false")]
480 congestion_control_gas_price_feedback_mechanism: bool,
481
482 #[serde(skip_serializing_if = "is_false")]
484 validate_identifier_inputs: bool,
485
486 #[serde(skip_serializing_if = "is_false")]
489 minimize_child_object_mutations: bool,
490
491 #[serde(skip_serializing_if = "is_false")]
493 dependency_linkage_error: bool,
494
495 #[serde(skip_serializing_if = "is_false")]
497 additional_multisig_checks: bool,
498
499 #[serde(skip_serializing_if = "is_false")]
502 normalize_ptb_arguments: bool,
503
504 #[serde(skip_serializing_if = "is_false")]
508 select_committee_from_eligible_validators: bool,
509
510 #[serde(skip_serializing_if = "is_false")]
517 track_non_committee_eligible_validators: bool,
518
519 #[serde(skip_serializing_if = "is_false")]
525 select_committee_supporting_next_epoch_version: bool,
526
527 #[serde(skip_serializing_if = "is_false")]
531 consensus_median_timestamp_with_checkpoint_enforcement: bool,
532
533 #[serde(skip_serializing_if = "is_false")]
535 consensus_commit_transactions_only_for_traversed_headers: bool,
536
537 #[serde(skip_serializing_if = "is_false")]
539 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
540
541 #[serde(skip_serializing_if = "is_false")]
544 separate_gas_price_feedback_mechanism_for_randomness: bool,
545
546 #[serde(skip_serializing_if = "is_false")]
549 metadata_in_module_bytes: bool,
550
551 #[serde(skip_serializing_if = "is_false")]
553 publish_package_metadata: bool,
554
555 #[serde(skip_serializing_if = "is_false")]
557 enable_move_authentication: bool,
558
559 #[serde(skip_serializing_if = "is_false")]
561 enable_move_authentication_for_sponsor: bool,
562
563 #[serde(skip_serializing_if = "is_false")]
565 pass_validator_scores_to_advance_epoch: bool,
566
567 #[serde(skip_serializing_if = "is_false")]
569 calculate_validator_scores: bool,
570
571 #[serde(skip_serializing_if = "is_false")]
573 adjust_rewards_by_score: bool,
574
575 #[serde(skip_serializing_if = "is_false")]
578 pass_calculated_validator_scores_to_advance_epoch: bool,
579
580 #[serde(skip_serializing_if = "is_false")]
585 consensus_fast_commit_sync: bool,
586
587 #[serde(skip_serializing_if = "is_false")]
590 consensus_block_restrictions: bool,
591
592 #[serde(skip_serializing_if = "is_false")]
594 move_native_tx_context: bool,
595
596 #[serde(skip_serializing_if = "is_false")]
598 additional_borrow_checks: bool,
599
600 #[serde(skip_serializing_if = "is_false")]
602 pre_consensus_sponsor_only_move_authentication: bool,
603
604 #[serde(skip_serializing_if = "is_false")]
606 consensus_starfish_speed: bool,
607
608 #[serde(skip_serializing_if = "is_false")]
615 always_advance_dkg_to_resolution: bool,
616
617 #[serde(skip_serializing_if = "is_false")]
622 enable_pcool_flow: bool,
623
624 #[serde(skip_serializing_if = "is_false")]
629 pcool_skip_immutable_object_locks: bool,
630
631 #[serde(skip_serializing_if = "is_false")]
636 pcool_verifier_limits_from_protocol_config: bool,
637
638 #[serde(skip_serializing_if = "is_false")]
640 validator_metadata_verify_v2: bool,
641
642 #[serde(skip_serializing_if = "is_false")]
646 deny_rule_governance: bool,
647
648 #[serde(skip_serializing_if = "is_false")]
653 deny_rule_governance_on_chain: bool,
654
655 #[serde(skip_serializing_if = "is_false")]
659 deny_authenticator_packages: bool,
660
661 #[serde(skip_serializing_if = "is_false")]
664 package_metadata_with_dynamic_module_metadata: bool,
665
666 #[serde(skip_serializing_if = "is_false")]
669 report_move_authentication_error: bool,
670
671 #[serde(skip_serializing_if = "is_false")]
676 consensus_enable_sliding_window_leader_schedule: bool,
677
678 #[serde(skip_serializing_if = "is_false")]
683 consensus_enable_absolute_score_leader_schedule: bool,
684
685 #[serde(skip_serializing_if = "is_false")]
687 max_ptb_value_size_v2: bool,
688
689 #[serde(skip_serializing_if = "is_false")]
691 allow_unbounded_system_objects: bool,
692
693 #[serde(skip_serializing_if = "is_false")]
696 reject_immutable_account_objects: bool,
697
698 #[serde(skip_serializing_if = "is_false")]
701 reject_immutable_account_creation: bool,
702
703 #[serde(skip_serializing_if = "is_false")]
709 validate_input_object_versions: bool,
710
711 #[serde(skip_serializing_if = "is_false")]
713 disallow_self_identifier: bool,
714
715 #[serde(skip_serializing_if = "is_false")]
720 check_canonical_module_version_header: bool,
721
722 #[serde(skip_serializing_if = "is_false")]
727 disallow_randomness_in_move_authenticator: bool,
728
729 #[serde(skip_serializing_if = "is_false")]
733 check_cyclic_dependencies: bool,
734
735 #[serde(skip_serializing_if = "is_false")]
737 deprecate_global_storage_ops_during_deserialization: bool,
738
739 #[serde(skip_serializing_if = "is_false")]
741 validate_ptb_argument_indices: bool,
742
743 #[serde(skip_serializing_if = "is_false")]
746 allow_dkg_completion_after_timeout: bool,
747}
748
749fn is_true(b: &bool) -> bool {
750 *b
751}
752
753fn is_false(b: &bool) -> bool {
754 !b
755}
756
757#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
759pub enum ConsensusTransactionOrdering {
760 #[default]
763 None,
764 ByGasPrice,
766}
767
768impl ConsensusTransactionOrdering {
769 pub fn is_none(&self) -> bool {
770 matches!(self, ConsensusTransactionOrdering::None)
771 }
772}
773
774#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
776pub enum PerObjectCongestionControlMode {
777 #[default]
778 None, TotalGasBudget, TotalTxCount, }
782
783impl PerObjectCongestionControlMode {
784 pub fn is_none(&self) -> bool {
785 matches!(self, PerObjectCongestionControlMode::None)
786 }
787}
788
789#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
791pub enum ConsensusChoice {
792 #[deprecated(note = "Mysticeti was replaced by Starfish")]
795 MysticetiDeprecated,
796 #[default]
797 Starfish,
798}
799
800#[expect(deprecated)]
801impl ConsensusChoice {
802 fn mysticeti_deprecated() -> Self {
809 ConsensusChoice::MysticetiDeprecated
810 }
811
812 pub fn is_mysticeti_deprecated(&self) -> bool {
813 matches!(self, ConsensusChoice::MysticetiDeprecated)
814 }
815 pub fn is_starfish(&self) -> bool {
816 matches!(self, ConsensusChoice::Starfish)
817 }
818}
819
820#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
822pub enum ConsensusNetwork {
823 #[default]
824 Tonic,
825}
826
827impl ConsensusNetwork {
828 pub fn is_tonic(&self) -> bool {
829 matches!(self, ConsensusNetwork::Tonic)
830 }
831}
832
833#[skip_serializing_none]
866#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
867pub struct ProtocolConfig {
868 pub version: ProtocolVersion,
869
870 feature_flags: FeatureFlags,
871
872 max_tx_size_bytes: Option<u64>,
877
878 max_input_objects: Option<u64>,
883
884 max_size_written_objects: Option<u64>,
889 max_size_written_objects_system_tx: Option<u64>,
893
894 max_serialized_tx_effects_size_bytes: Option<u64>,
896
897 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
899
900 max_gas_payment_objects: Option<u32>,
902
903 max_modules_in_publish: Option<u32>,
905
906 max_package_dependencies: Option<u32>,
908
909 max_arguments: Option<u32>,
912
913 max_type_arguments: Option<u32>,
915
916 max_type_argument_depth: Option<u32>,
918
919 max_pure_argument_size: Option<u32>,
921
922 max_programmable_tx_commands: Option<u32>,
924
925 move_binary_format_version: Option<u32>,
931 min_move_binary_format_version: Option<u32>,
932
933 binary_module_handles: Option<u16>,
935 binary_struct_handles: Option<u16>,
936 binary_function_handles: Option<u16>,
937 binary_function_instantiations: Option<u16>,
938 binary_signatures: Option<u16>,
939 binary_constant_pool: Option<u16>,
940 binary_identifiers: Option<u16>,
941 binary_address_identifiers: Option<u16>,
942 binary_struct_defs: Option<u16>,
943 binary_struct_def_instantiations: Option<u16>,
944 binary_function_defs: Option<u16>,
945 binary_field_handles: Option<u16>,
946 binary_field_instantiations: Option<u16>,
947 binary_friend_decls: Option<u16>,
948 binary_enum_defs: Option<u16>,
949 binary_enum_def_instantiations: Option<u16>,
950 binary_variant_handles: Option<u16>,
951 binary_variant_instantiation_handles: Option<u16>,
952
953 max_move_object_size: Option<u64>,
956
957 max_move_package_size: Option<u64>,
962
963 max_publish_or_upgrade_per_ptb: Option<u64>,
966
967 max_tx_gas: Option<u64>,
969
970 max_auth_gas: Option<u64>,
972
973 max_gas_price: Option<u64>,
976
977 max_gas_computation_bucket: Option<u64>,
980
981 gas_rounding_step: Option<u64>,
983
984 max_loop_depth: Option<u64>,
986
987 max_generic_instantiation_length: Option<u64>,
990
991 max_function_parameters: Option<u64>,
994
995 max_basic_blocks: Option<u64>,
998
999 max_value_stack_size: Option<u64>,
1001
1002 max_type_nodes: Option<u64>,
1006
1007 max_push_size: Option<u64>,
1010
1011 max_struct_definitions: Option<u64>,
1014
1015 max_function_definitions: Option<u64>,
1018
1019 max_fields_in_struct: Option<u64>,
1022
1023 max_dependency_depth: Option<u64>,
1026
1027 max_num_event_emit: Option<u64>,
1030
1031 max_num_new_move_object_ids: Option<u64>,
1034
1035 max_num_new_move_object_ids_system_tx: Option<u64>,
1038
1039 max_num_deleted_move_object_ids: Option<u64>,
1042
1043 max_num_deleted_move_object_ids_system_tx: Option<u64>,
1046
1047 max_num_transferred_move_object_ids: Option<u64>,
1050
1051 max_num_transferred_move_object_ids_system_tx: Option<u64>,
1054
1055 max_event_emit_size: Option<u64>,
1057
1058 max_event_emit_size_total: Option<u64>,
1060
1061 max_move_vector_len: Option<u64>,
1064
1065 max_move_identifier_len: Option<u64>,
1068
1069 max_move_value_depth: Option<u64>,
1071
1072 max_move_enum_variants: Option<u64>,
1075
1076 max_back_edges_per_function: Option<u64>,
1085
1086 max_back_edges_per_module: Option<u64>,
1088
1089 max_verifier_meter_ticks_per_function: Option<u64>,
1091
1092 max_meter_ticks_per_module: Option<u64>,
1094
1095 max_meter_ticks_per_package: Option<u64>,
1097
1098 max_meter_ticks_regex_reference_safety: Option<u64>,
1102
1103 object_runtime_max_num_cached_objects: Option<u64>,
1110
1111 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
1114
1115 object_runtime_max_num_store_entries: Option<u64>,
1118
1119 object_runtime_max_num_store_entries_system_tx: Option<u64>,
1122
1123 base_tx_cost_fixed: Option<u64>,
1128
1129 package_publish_cost_fixed: Option<u64>,
1133
1134 base_tx_cost_per_byte: Option<u64>,
1138
1139 package_publish_cost_per_byte: Option<u64>,
1141
1142 obj_access_cost_read_per_byte: Option<u64>,
1144
1145 obj_access_cost_mutate_per_byte: Option<u64>,
1147
1148 obj_access_cost_delete_per_byte: Option<u64>,
1150
1151 obj_access_cost_verify_per_byte: Option<u64>,
1161
1162 max_type_to_layout_nodes: Option<u64>,
1164
1165 max_ptb_value_size: Option<u64>,
1167
1168 gas_model_version: Option<u64>,
1173
1174 obj_data_cost_refundable: Option<u64>,
1180
1181 obj_metadata_cost_non_refundable: Option<u64>,
1185
1186 storage_rebate_rate: Option<u64>,
1192
1193 reward_slashing_rate: Option<u64>,
1196
1197 storage_gas_price: Option<u64>,
1199
1200 base_gas_price: Option<u64>,
1202
1203 validator_target_reward: Option<u64>,
1205
1206 max_transactions_per_checkpoint: Option<u64>,
1213
1214 max_checkpoint_size_bytes: Option<u64>,
1218
1219 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
1225
1226 address_from_bytes_cost_base: Option<u64>,
1231 address_to_u256_cost_base: Option<u64>,
1233 address_from_u256_cost_base: Option<u64>,
1235
1236 config_read_setting_impl_cost_base: Option<u64>,
1241 config_read_setting_impl_cost_per_byte: Option<u64>,
1242
1243 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
1247 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
1248 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
1249 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
1250 dynamic_field_add_child_object_cost_base: Option<u64>,
1253 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
1254 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
1255 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
1256 dynamic_field_borrow_child_object_cost_base: Option<u64>,
1259 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1260 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1261 dynamic_field_remove_child_object_cost_base: Option<u64>,
1264 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1265 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1266 dynamic_field_has_child_object_cost_base: Option<u64>,
1269 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1272 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1273 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1274
1275 event_emit_cost_base: Option<u64>,
1278 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1279 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1280 event_emit_output_cost_per_byte: Option<u64>,
1281
1282 object_borrow_uid_cost_base: Option<u64>,
1285 object_delete_impl_cost_base: Option<u64>,
1287 object_record_new_uid_cost_base: Option<u64>,
1289
1290 transfer_transfer_internal_cost_base: Option<u64>,
1293 transfer_freeze_object_cost_base: Option<u64>,
1295 transfer_share_object_cost_base: Option<u64>,
1297 transfer_receive_object_cost_base: Option<u64>,
1300
1301 tx_context_derive_id_cost_base: Option<u64>,
1304 tx_context_fresh_id_cost_base: Option<u64>,
1305 tx_context_sender_cost_base: Option<u64>,
1306 tx_context_digest_cost_base: Option<u64>,
1307 tx_context_epoch_cost_base: Option<u64>,
1308 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1309 tx_context_sponsor_cost_base: Option<u64>,
1310 tx_context_rgp_cost_base: Option<u64>,
1311 tx_context_gas_price_cost_base: Option<u64>,
1312 tx_context_gas_budget_cost_base: Option<u64>,
1313 tx_context_ids_created_cost_base: Option<u64>,
1314 tx_context_replace_cost_base: Option<u64>,
1315
1316 types_is_one_time_witness_cost_base: Option<u64>,
1319 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1320 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1321
1322 validator_validate_metadata_cost_base: Option<u64>,
1325 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1326
1327 crypto_invalid_arguments_cost: Option<u64>,
1329 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1331 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1332 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1333
1334 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1336 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1337 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1338
1339 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1341 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1342 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1343 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1344 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1345 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1346
1347 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1349
1350 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1352 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1353 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1354 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1355 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1356 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1357
1358 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1360 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1361 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1362 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1363 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1364 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1365
1366 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1368 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1369 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1370 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1371 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1372 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1373
1374 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1376 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1377 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1378
1379 ed25519_ed25519_verify_cost_base: Option<u64>,
1381 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1382 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1383
1384 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1386 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1387
1388 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1390 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1391 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1392 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1393 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1394
1395 hash_blake2b256_cost_base: Option<u64>,
1397 hash_blake2b256_data_cost_per_byte: Option<u64>,
1398 hash_blake2b256_data_cost_per_block: Option<u64>,
1399
1400 hash_keccak256_cost_base: Option<u64>,
1402 hash_keccak256_data_cost_per_byte: Option<u64>,
1403 hash_keccak256_data_cost_per_block: Option<u64>,
1404
1405 poseidon_bn254_cost_base: Option<u64>,
1407 poseidon_bn254_cost_per_block: Option<u64>,
1408
1409 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1411 group_ops_bls12381_decode_g1_cost: Option<u64>,
1412 group_ops_bls12381_decode_g2_cost: Option<u64>,
1413 group_ops_bls12381_decode_gt_cost: Option<u64>,
1414 group_ops_bls12381_scalar_add_cost: Option<u64>,
1415 group_ops_bls12381_g1_add_cost: Option<u64>,
1416 group_ops_bls12381_g2_add_cost: Option<u64>,
1417 group_ops_bls12381_gt_add_cost: Option<u64>,
1418 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1419 group_ops_bls12381_g1_sub_cost: Option<u64>,
1420 group_ops_bls12381_g2_sub_cost: Option<u64>,
1421 group_ops_bls12381_gt_sub_cost: Option<u64>,
1422 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1423 group_ops_bls12381_g1_mul_cost: Option<u64>,
1424 group_ops_bls12381_g2_mul_cost: Option<u64>,
1425 group_ops_bls12381_gt_mul_cost: Option<u64>,
1426 group_ops_bls12381_scalar_div_cost: Option<u64>,
1427 group_ops_bls12381_g1_div_cost: Option<u64>,
1428 group_ops_bls12381_g2_div_cost: Option<u64>,
1429 group_ops_bls12381_gt_div_cost: Option<u64>,
1430 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1431 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1432 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1433 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1434 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1435 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1436 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1437 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1438 group_ops_bls12381_msm_max_len: Option<u32>,
1439 group_ops_bls12381_pairing_cost: Option<u64>,
1440 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1441 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1442 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1443 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1444 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1445
1446 hmac_hmac_sha3_256_cost_base: Option<u64>,
1448 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1449 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1450
1451 #[deprecated]
1453 check_zklogin_id_cost_base: Option<u64>,
1454 #[deprecated]
1456 check_zklogin_issuer_cost_base: Option<u64>,
1457
1458 vdf_verify_vdf_cost: Option<u64>,
1459 vdf_hash_to_input_cost: Option<u64>,
1460
1461 bcs_per_byte_serialized_cost: Option<u64>,
1463 bcs_legacy_min_output_size_cost: Option<u64>,
1464 bcs_failure_cost: Option<u64>,
1465
1466 hash_sha2_256_base_cost: Option<u64>,
1467 hash_sha2_256_per_byte_cost: Option<u64>,
1468 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1469 hash_sha3_256_base_cost: Option<u64>,
1470 hash_sha3_256_per_byte_cost: Option<u64>,
1471 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1472 type_name_get_base_cost: Option<u64>,
1473 type_name_get_per_byte_cost: Option<u64>,
1474
1475 string_check_utf8_base_cost: Option<u64>,
1476 string_check_utf8_per_byte_cost: Option<u64>,
1477 string_is_char_boundary_base_cost: Option<u64>,
1478 string_sub_string_base_cost: Option<u64>,
1479 string_sub_string_per_byte_cost: Option<u64>,
1480 string_index_of_base_cost: Option<u64>,
1481 string_index_of_per_byte_pattern_cost: Option<u64>,
1482 string_index_of_per_byte_searched_cost: Option<u64>,
1483
1484 vector_empty_base_cost: Option<u64>,
1485 vector_length_base_cost: Option<u64>,
1486 vector_push_back_base_cost: Option<u64>,
1487 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1488 vector_borrow_base_cost: Option<u64>,
1489 vector_pop_back_base_cost: Option<u64>,
1490 vector_destroy_empty_base_cost: Option<u64>,
1491 vector_swap_base_cost: Option<u64>,
1492 debug_print_base_cost: Option<u64>,
1493 debug_print_stack_trace_base_cost: Option<u64>,
1494
1495 execution_version: Option<u64>,
1497
1498 consensus_bad_nodes_stake_threshold: Option<u64>,
1502
1503 #[deprecated]
1504 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1505 #[deprecated]
1509 max_age_of_jwk_in_epochs: Option<u64>,
1510
1511 random_beacon_reduction_allowed_delta: Option<u16>,
1515
1516 random_beacon_reduction_lower_bound: Option<u32>,
1519
1520 random_beacon_dkg_timeout_round: Option<u32>,
1523
1524 random_beacon_min_round_interval_ms: Option<u64>,
1526
1527 random_beacon_dkg_version: Option<u64>,
1531
1532 consensus_max_transaction_size_bytes: Option<u64>,
1537 consensus_max_transactions_in_block_bytes: Option<u64>,
1539 consensus_max_num_transactions_in_block: Option<u64>,
1541
1542 max_deferral_rounds_for_congestion_control: Option<u64>,
1546
1547 min_checkpoint_interval_ms: Option<u64>,
1549
1550 checkpoint_rate_window_size: Option<u64>,
1560
1561 checkpoint_summary_version_specific_data: Option<u64>,
1563
1564 max_soft_bundle_size: Option<u64>,
1567
1568 bridge_should_try_to_finalize_committee: Option<bool>,
1573
1574 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1580
1581 max_committee_members_count: Option<u64>,
1585
1586 deny_rule_update_max_entries_per_tx: Option<u64>,
1591
1592 deny_rule_removal_grace_round_floor: Option<u64>,
1597
1598 consensus_gc_depth: Option<u32>,
1601
1602 consensus_max_acknowledgments_per_block: Option<u32>,
1608
1609 max_congestion_limit_overshoot_per_commit: Option<u64>,
1614
1615 max_concurrent_execution_workers: Option<u16>,
1622
1623 scorer_version: Option<u16>,
1632
1633 auth_context_digest_cost_base: Option<u64>,
1636 auth_context_tx_data_bytes_cost_base: Option<u64>,
1638 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1639 auth_context_tx_commands_cost_base: Option<u64>,
1641 auth_context_tx_commands_cost_per_byte: Option<u64>,
1642 auth_context_tx_inputs_cost_base: Option<u64>,
1644 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1645 auth_context_replace_cost_base: Option<u64>,
1648 auth_context_replace_cost_per_byte: Option<u64>,
1649 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1653
1654 consensus_commits_per_schedule: Option<u32>,
1657
1658 min_validator_count: Option<u64>,
1661
1662 max_validator_count: Option<u64>,
1666
1667 min_validator_joining_stake: Option<u64>,
1671
1672 validator_low_stake_threshold: Option<u64>,
1677
1678 validator_very_low_stake_threshold: Option<u64>,
1682
1683 validator_low_stake_grace_period: Option<u64>,
1687
1688 consensus_leader_schedule_window_size: Option<u32>,
1692
1693 max_move_system_package_size: Option<u64>,
1698}
1699
1700impl ProtocolConfig {
1702 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1715 self.feature_flags
1716 .disable_invariant_violation_check_in_swap_loc
1717 }
1718
1719 pub fn no_extraneous_module_bytes(&self) -> bool {
1720 self.feature_flags.no_extraneous_module_bytes
1721 }
1722
1723 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1724 self.feature_flags.consensus_transaction_ordering
1725 }
1726
1727 pub fn dkg_version(&self) -> u64 {
1728 self.random_beacon_dkg_version.unwrap_or(1)
1730 }
1731
1732 pub fn hardened_otw_check(&self) -> bool {
1733 self.feature_flags.hardened_otw_check
1734 }
1735
1736 pub fn enable_poseidon(&self) -> bool {
1737 self.feature_flags.enable_poseidon
1738 }
1739
1740 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1741 self.feature_flags.enable_group_ops_native_function_msm
1742 }
1743
1744 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1745 self.feature_flags.per_object_congestion_control_mode
1746 }
1747
1748 pub fn consensus_choice(&self) -> ConsensusChoice {
1749 self.feature_flags.consensus_choice
1750 }
1751
1752 pub fn consensus_network(&self) -> ConsensusNetwork {
1753 self.feature_flags.consensus_network
1754 }
1755
1756 pub fn enable_vdf(&self) -> bool {
1757 self.feature_flags.enable_vdf
1758 }
1759
1760 pub fn passkey_auth(&self) -> bool {
1761 self.feature_flags.passkey_auth
1762 }
1763
1764 pub fn max_transaction_size_bytes(&self) -> u64 {
1765 self.consensus_max_transaction_size_bytes
1767 .unwrap_or(256 * 1024)
1768 }
1769
1770 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1771 if cfg!(msim) {
1772 256 * 1024
1773 } else {
1774 self.consensus_max_transactions_in_block_bytes
1775 .unwrap_or(512 * 1024)
1776 }
1777 }
1778
1779 pub fn max_num_transactions_in_block(&self) -> u64 {
1780 if cfg!(msim) {
1781 8
1782 } else {
1783 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1784 }
1785 }
1786
1787 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1788 self.feature_flags.rethrow_serialization_type_layout_errors
1789 }
1790
1791 pub fn relocate_event_module(&self) -> bool {
1792 self.feature_flags.relocate_event_module
1793 }
1794
1795 pub fn protocol_defined_base_fee(&self) -> bool {
1796 self.feature_flags.protocol_defined_base_fee
1797 }
1798
1799 pub fn uncompressed_g1_group_elements(&self) -> bool {
1800 self.feature_flags.uncompressed_g1_group_elements
1801 }
1802
1803 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1804 self.feature_flags
1805 .disallow_new_modules_in_deps_only_packages
1806 }
1807
1808 pub fn native_charging_v2(&self) -> bool {
1809 self.feature_flags.native_charging_v2
1810 }
1811
1812 pub fn consensus_round_prober(&self) -> bool {
1813 self.feature_flags.consensus_round_prober
1814 }
1815
1816 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1817 self.feature_flags
1818 .consensus_distributed_vote_scoring_strategy
1819 }
1820
1821 pub fn gc_depth(&self) -> u32 {
1822 if cfg!(msim) {
1823 min(5, self.consensus_gc_depth.unwrap_or(0))
1825 } else {
1826 self.consensus_gc_depth.unwrap_or(0)
1827 }
1828 }
1829
1830 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1831 let res = self.feature_flags.consensus_linearize_subdag_v2;
1832 assert!(
1833 !res || self.gc_depth() > 0,
1834 "The consensus linearize sub dag V2 requires GC to be enabled"
1835 );
1836 res
1837 }
1838
1839 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1840 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1841 }
1842
1843 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1844 2 * committee_size
1845 }
1846
1847 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1848 committee_size
1849 }
1850
1851 pub fn variant_nodes(&self) -> bool {
1852 self.feature_flags.variant_nodes
1853 }
1854
1855 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1856 self.feature_flags.consensus_smart_ancestor_selection
1857 }
1858
1859 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1860 self.feature_flags
1861 .consensus_round_prober_probe_accepted_rounds
1862 }
1863
1864 pub fn consensus_zstd_compression(&self) -> bool {
1865 self.feature_flags.consensus_zstd_compression
1866 }
1867
1868 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1869 self.feature_flags
1870 .congestion_control_min_free_execution_slot
1871 }
1872
1873 pub fn accept_passkey_in_multisig(&self) -> bool {
1874 self.feature_flags.accept_passkey_in_multisig
1875 }
1876
1877 pub fn consensus_batched_block_sync(&self) -> bool {
1878 self.feature_flags.consensus_batched_block_sync
1879 }
1880
1881 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1884 self.feature_flags
1885 .congestion_control_gas_price_feedback_mechanism
1886 }
1887
1888 pub fn validate_identifier_inputs(&self) -> bool {
1889 self.feature_flags.validate_identifier_inputs
1890 }
1891
1892 pub fn minimize_child_object_mutations(&self) -> bool {
1893 self.feature_flags.minimize_child_object_mutations
1894 }
1895
1896 pub fn dependency_linkage_error(&self) -> bool {
1897 self.feature_flags.dependency_linkage_error
1898 }
1899
1900 pub fn additional_multisig_checks(&self) -> bool {
1901 self.feature_flags.additional_multisig_checks
1902 }
1903
1904 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1905 0
1908 }
1909
1910 pub fn normalize_ptb_arguments(&self) -> bool {
1911 self.feature_flags.normalize_ptb_arguments
1912 }
1913
1914 pub fn select_committee_from_eligible_validators(&self) -> bool {
1915 let res = self.feature_flags.select_committee_from_eligible_validators;
1916 assert!(
1917 !res || (self.protocol_defined_base_fee()
1918 && self.max_committee_members_count_as_option().is_some()),
1919 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1920 );
1921 res
1922 }
1923
1924 pub fn track_non_committee_eligible_validators(&self) -> bool {
1925 self.feature_flags.track_non_committee_eligible_validators
1926 }
1927
1928 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1929 let res = self
1930 .feature_flags
1931 .select_committee_supporting_next_epoch_version;
1932 assert!(
1933 !res || (self.track_non_committee_eligible_validators()
1934 && self.select_committee_from_eligible_validators()),
1935 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1936 );
1937 res
1938 }
1939
1940 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1941 let res = self
1942 .feature_flags
1943 .consensus_median_timestamp_with_checkpoint_enforcement;
1944 assert!(
1945 !res || self.gc_depth() > 0,
1946 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1947 );
1948 res
1949 }
1950
1951 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1952 self.feature_flags
1953 .consensus_commit_transactions_only_for_traversed_headers
1954 }
1955
1956 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1959 self.feature_flags
1960 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1961 }
1962
1963 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1966 self.feature_flags
1967 .separate_gas_price_feedback_mechanism_for_randomness
1968 }
1969
1970 pub fn metadata_in_module_bytes(&self) -> bool {
1971 self.feature_flags.metadata_in_module_bytes
1972 }
1973
1974 pub fn publish_package_metadata(&self) -> bool {
1975 self.feature_flags.publish_package_metadata
1976 }
1977
1978 pub fn enable_move_authentication(&self) -> bool {
1979 self.feature_flags.enable_move_authentication
1980 }
1981
1982 pub fn additional_borrow_checks(&self) -> bool {
1983 self.feature_flags.additional_borrow_checks
1984 }
1985
1986 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1987 let enable_move_authentication_for_sponsor =
1988 self.feature_flags.enable_move_authentication_for_sponsor;
1989 assert!(
1990 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1991 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1992 );
1993 enable_move_authentication_for_sponsor
1994 }
1995
1996 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1997 self.feature_flags.pass_validator_scores_to_advance_epoch
1998 }
1999
2000 pub fn calculate_validator_scores(&self) -> bool {
2001 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
2002 assert!(
2003 !calculate_validator_scores || self.scorer_version.is_some(),
2004 "calculate_validator_scores requires scorer_version to be set"
2005 );
2006 calculate_validator_scores
2007 }
2008
2009 pub fn adjust_rewards_by_score(&self) -> bool {
2010 let adjust = self.feature_flags.adjust_rewards_by_score;
2011 assert!(
2012 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
2013 "adjust_rewards_by_score requires scorer_version to be set"
2014 );
2015 adjust
2016 }
2017
2018 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
2019 let pass = self
2020 .feature_flags
2021 .pass_calculated_validator_scores_to_advance_epoch;
2022 assert!(
2023 !pass
2024 || (self.pass_validator_scores_to_advance_epoch()
2025 && self.calculate_validator_scores()),
2026 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
2027 );
2028 pass
2029 }
2030 pub fn consensus_fast_commit_sync(&self) -> bool {
2031 let res = self.feature_flags.consensus_fast_commit_sync;
2032 assert!(
2033 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
2034 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
2035 );
2036 res
2037 }
2038
2039 pub fn consensus_block_restrictions(&self) -> bool {
2040 self.feature_flags.consensus_block_restrictions
2041 }
2042
2043 pub fn move_native_tx_context(&self) -> bool {
2044 self.feature_flags.move_native_tx_context
2045 }
2046
2047 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
2048 let pre_consensus_sponsor_only_move_authentication = self
2049 .feature_flags
2050 .pre_consensus_sponsor_only_move_authentication;
2051 if pre_consensus_sponsor_only_move_authentication {
2052 assert!(
2053 self.enable_move_authentication(),
2054 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
2055 );
2056 assert!(
2057 self.enable_move_authentication_for_sponsor(),
2058 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
2059 );
2060 }
2061 pre_consensus_sponsor_only_move_authentication
2062 }
2063
2064 pub fn consensus_starfish_speed(&self) -> bool {
2065 let res = self.feature_flags.consensus_starfish_speed;
2066 assert!(
2067 !res || self.consensus_fast_commit_sync(),
2068 "consensus_starfish_speed requires consensus_fast_commit_sync to be enabled"
2069 );
2070 res
2071 }
2072
2073 pub fn always_advance_dkg_to_resolution(&self) -> bool {
2074 self.feature_flags.always_advance_dkg_to_resolution
2075 }
2076
2077 pub fn enable_pcool_flow(&self) -> bool {
2078 self.feature_flags.enable_pcool_flow
2079 }
2080
2081 pub fn pcool_skip_immutable_object_locks(&self) -> bool {
2082 self.feature_flags.pcool_skip_immutable_object_locks
2083 }
2084
2085 pub fn pcool_verifier_limits_from_protocol_config(&self) -> bool {
2088 self.feature_flags
2089 .pcool_verifier_limits_from_protocol_config
2090 }
2091
2092 pub fn validator_metadata_verify_v2(&self) -> bool {
2093 self.feature_flags.validator_metadata_verify_v2
2094 }
2095
2096 pub fn commits_per_schedule(&self) -> u32 {
2097 let commits_per_schedule = if cfg!(msim) {
2098 min(10, self.consensus_commits_per_schedule.unwrap_or(300))
2100 } else {
2101 self.consensus_commits_per_schedule.unwrap_or(300)
2102 };
2103 assert!(
2104 commits_per_schedule > 0,
2105 "consensus_commits_per_schedule must be greater than 0"
2106 );
2107 commits_per_schedule
2108 }
2109
2110 pub fn leader_schedule_window_size(&self) -> u32 {
2111 if cfg!(msim) {
2112 min(
2115 20,
2116 self.consensus_leader_schedule_window_size.unwrap_or(600),
2117 )
2118 } else {
2119 self.consensus_leader_schedule_window_size.unwrap_or(600)
2120 }
2121 }
2122
2123 pub fn consensus_enable_sliding_window_leader_schedule(&self) -> bool {
2124 let res = self
2125 .feature_flags
2126 .consensus_enable_sliding_window_leader_schedule;
2127 assert!(
2128 !res || self.leader_schedule_window_size() >= self.commits_per_schedule(),
2129 "consensus_enable_sliding_window_leader_schedule requires window_size >= commits_per_schedule"
2130 );
2131 res
2132 }
2133
2134 pub fn consensus_enable_absolute_score_leader_schedule(&self) -> bool {
2135 self.feature_flags
2136 .consensus_enable_absolute_score_leader_schedule
2137 }
2138
2139 pub fn max_ptb_value_size_v2(&self) -> bool {
2140 self.feature_flags.max_ptb_value_size_v2
2141 }
2142
2143 pub fn deny_rule_governance(&self) -> bool {
2144 self.feature_flags.deny_rule_governance
2145 }
2146
2147 pub fn deny_rule_governance_on_chain(&self) -> bool {
2148 self.feature_flags.deny_rule_governance_on_chain
2149 }
2150
2151 pub fn deny_authenticator_packages(&self) -> bool {
2152 self.feature_flags.deny_authenticator_packages
2153 }
2154
2155 pub fn package_metadata_with_dynamic_module_metadata(&self) -> bool {
2156 let res = self
2157 .feature_flags
2158 .package_metadata_with_dynamic_module_metadata;
2159 assert!(
2160 !res || self.publish_package_metadata(),
2161 "package_metadata_with_dynamic_module_metadata requires publish_package_metadata to be enabled"
2162 );
2163 res
2164 }
2165
2166 pub fn report_move_authentication_error(&self) -> bool {
2167 let report_move_authentication_error = self.feature_flags.report_move_authentication_error;
2168 assert!(
2169 !report_move_authentication_error || self.enable_move_authentication(),
2170 "report_move_authentication_error requires enable_move_authentication to be set"
2171 );
2172 report_move_authentication_error
2173 }
2174
2175 pub fn concurrent_execution_workers(&self) -> Option<u16> {
2179 let res = self.max_concurrent_execution_workers;
2180 assert!(
2181 res.is_none() || self.enable_pcool_flow(),
2182 "max_concurrent_execution_workers requires enable_pcool_flow to be enabled"
2183 );
2184 assert!(
2185 res.is_none()
2186 || self
2187 .max_accumulated_txn_cost_per_object_in_mysticeti_commit
2188 .is_some(),
2189 "max_concurrent_execution_workers requires per-object congestion control \
2190 (max_accumulated_txn_cost_per_object_in_mysticeti_commit) to be enabled"
2191 );
2192 assert!(
2193 res.is_none() || self.congestion_control_gas_price_feedback_mechanism(),
2194 "max_concurrent_execution_workers requires the gas price feedback mechanism \
2195 (congestion_control_gas_price_feedback_mechanism), which carries the suggested \
2196 gas price of an execution-worker congestion cancellation"
2197 );
2198 assert!(
2199 res.is_none() || !self.separate_gas_price_feedback_mechanism_for_randomness(),
2200 "max_concurrent_execution_workers implies a single congestion tracker and suggested \
2201 gas price calculator for all transactions, which is incompatible with \
2202 separate_gas_price_feedback_mechanism_for_randomness"
2203 );
2204 assert!(
2205 res != Some(0),
2206 "max_concurrent_execution_workers must be positive when set"
2207 );
2208 res
2209 }
2210
2211 pub fn allow_unbounded_system_objects(&self) -> bool {
2212 self.feature_flags.allow_unbounded_system_objects
2213 }
2214
2215 pub fn reject_immutable_account_objects(&self) -> bool {
2216 let reject_immutable_account_objects = self.feature_flags.reject_immutable_account_objects;
2217 assert!(
2218 !reject_immutable_account_objects || self.enable_move_authentication(),
2219 "reject_immutable_account_objects requires enable_move_authentication to be set"
2220 );
2221 reject_immutable_account_objects
2222 }
2223
2224 pub fn reject_immutable_account_creation(&self) -> bool {
2225 let reject_immutable_account_creation =
2226 self.feature_flags.reject_immutable_account_creation;
2227 assert!(
2228 !reject_immutable_account_creation || self.reject_immutable_account_objects(),
2229 "reject_immutable_account_creation requires reject_immutable_account_objects to be set"
2230 );
2231 reject_immutable_account_creation
2232 }
2233
2234 pub fn validate_input_object_versions(&self) -> bool {
2235 self.feature_flags.validate_input_object_versions
2236 }
2237
2238 pub fn check_canonical_module_version_header(&self) -> bool {
2239 self.feature_flags.check_canonical_module_version_header
2240 }
2241
2242 pub fn disallow_randomness_in_move_authenticator(&self) -> bool {
2243 self.feature_flags.disallow_randomness_in_move_authenticator
2244 }
2245
2246 pub fn check_cyclic_dependencies(&self) -> bool {
2247 self.feature_flags.check_cyclic_dependencies
2248 }
2249
2250 pub fn deprecate_global_storage_ops_during_deserialization(&self) -> bool {
2251 self.feature_flags
2252 .deprecate_global_storage_ops_during_deserialization
2253 }
2254
2255 pub fn validate_ptb_argument_indices(&self) -> bool {
2256 self.feature_flags.validate_ptb_argument_indices
2257 }
2258
2259 pub fn allow_dkg_completion_after_timeout(&self) -> bool {
2260 self.feature_flags.allow_dkg_completion_after_timeout
2261 }
2262}
2263
2264#[cfg(not(msim))]
2265static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2266
2267#[cfg(msim)]
2269thread_local! {
2270 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2271}
2272
2273impl ProtocolConfig {
2275 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
2278 assert!(
2280 version >= ProtocolVersion::MIN,
2281 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
2282 version,
2283 ProtocolVersion::MIN.0,
2284 );
2285 assert!(
2286 version <= ProtocolVersion::MAX_ALLOWED,
2287 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
2288 version,
2289 ProtocolVersion::MAX_ALLOWED.0,
2290 );
2291
2292 let mut ret = Self::get_for_version_impl(version, chain);
2293 ret.version = version;
2294
2295 ret = CONFIG_OVERRIDE.with(|ovr| {
2296 if let Some(override_fn) = &*ovr.borrow() {
2297 warn!(
2298 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
2299 );
2300 override_fn(version, ret)
2301 } else {
2302 ret
2303 }
2304 });
2305
2306 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
2307 warn!(
2308 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
2309 );
2310
2311 let overrides: ProtocolConfigOptional =
2313 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
2314 .expect("failed to parse ProtocolConfig override env variables");
2315 overrides.apply_to(&mut ret);
2316
2317 let feature_flag_overrides: FeatureFlagsOptional =
2319 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_FEATURE_FLAGS_OVERRIDE")
2320 .expect("failed to parse ProtocolConfig feature flags override env variables");
2321
2322 feature_flag_overrides.apply_to(&mut ret.feature_flags);
2323 }
2324
2325 assert!(
2327 !ret.feature_flags.deny_rule_governance_on_chain
2328 || ret.feature_flags.deny_rule_governance,
2329 "deny_rule_governance_on_chain requires deny_rule_governance"
2330 );
2331 assert!(
2336 !ret.feature_flags.pcool_verifier_limits_from_protocol_config
2337 || ret.max_meter_ticks_regex_reference_safety.is_some(),
2338 "pcool_verifier_limits_from_protocol_config requires \
2339 max_meter_ticks_regex_reference_safety"
2340 );
2341 assert!(
2344 !ret.feature_flags.deny_rule_governance_on_chain
2345 || (ret.deny_rule_update_max_entries_per_tx.is_some()
2346 && ret.deny_rule_removal_grace_round_floor.is_some()),
2347 "deny_rule_governance_on_chain requires deny_rule_update_max_entries_per_tx and deny_rule_removal_grace_round_floor"
2348 );
2349 const DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING: u64 = 2048;
2357 assert!(
2358 ret.deny_rule_update_max_entries_per_tx
2359 .is_none_or(|max_entries| {
2360 max_entries > 0
2361 && max_entries <= DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING
2362 && [
2363 ret.max_num_new_move_object_ids_system_tx,
2364 ret.max_num_deleted_move_object_ids_system_tx,
2365 ret.object_runtime_max_num_cached_objects_system_tx,
2366 ret.object_runtime_max_num_store_entries_system_tx,
2367 ]
2368 .iter()
2369 .all(|limit| limit.is_none_or(|limit| max_entries <= limit))
2370 }),
2371 "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"
2372 );
2373
2374 ret
2375 }
2376
2377 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
2380 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
2381 let mut ret = Self::get_for_version_impl(version, chain);
2382 ret.version = version;
2383 Some(ret)
2384 } else {
2385 None
2386 }
2387 }
2388
2389 #[cfg(not(msim))]
2390 pub fn poison_get_for_min_version() {
2391 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
2392 }
2393
2394 #[cfg(not(msim))]
2395 fn load_poison_get_for_min_version() -> bool {
2396 POISON_VERSION_METHODS.load(Ordering::Relaxed)
2397 }
2398
2399 #[cfg(msim)]
2400 pub fn poison_get_for_min_version() {
2401 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
2402 }
2403
2404 #[cfg(msim)]
2405 fn load_poison_get_for_min_version() -> bool {
2406 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
2407 }
2408
2409 pub fn convert_type_argument_error(&self) -> bool {
2410 self.feature_flags.convert_type_argument_error
2411 }
2412
2413 pub fn get_for_min_version() -> Self {
2417 if Self::load_poison_get_for_min_version() {
2418 panic!("get_for_min_version called on validator");
2419 }
2420 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
2421 }
2422
2423 #[expect(non_snake_case)]
2434 pub fn get_for_max_version_UNSAFE() -> Self {
2435 if Self::load_poison_get_for_min_version() {
2436 panic!("get_for_max_version_UNSAFE called on validator");
2437 }
2438 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
2439 }
2440
2441 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
2442 #[cfg(msim)]
2443 {
2444 if version > ProtocolVersion::MAX {
2446 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
2447 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
2448 return config;
2449 }
2450 }
2451
2452 let mut cfg = Self {
2456 version,
2457
2458 feature_flags: Default::default(),
2459
2460 max_tx_size_bytes: Some(128 * 1024),
2461 max_input_objects: Some(2048),
2464 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
2465 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
2466 max_gas_payment_objects: Some(256),
2467 max_modules_in_publish: Some(64),
2468 max_package_dependencies: Some(32),
2469 max_arguments: Some(512),
2470 max_type_arguments: Some(16),
2471 max_type_argument_depth: Some(16),
2472 max_pure_argument_size: Some(16 * 1024),
2473 max_programmable_tx_commands: Some(1024),
2474 move_binary_format_version: Some(7),
2475 min_move_binary_format_version: Some(6),
2476 binary_module_handles: Some(100),
2477 binary_struct_handles: Some(300),
2478 binary_function_handles: Some(1500),
2479 binary_function_instantiations: Some(750),
2480 binary_signatures: Some(1000),
2481 binary_constant_pool: Some(4000),
2482 binary_identifiers: Some(10000),
2483 binary_address_identifiers: Some(100),
2484 binary_struct_defs: Some(200),
2485 binary_struct_def_instantiations: Some(100),
2486 binary_function_defs: Some(1000),
2487 binary_field_handles: Some(500),
2488 binary_field_instantiations: Some(250),
2489 binary_friend_decls: Some(100),
2490 binary_enum_defs: None,
2491 binary_enum_def_instantiations: None,
2492 binary_variant_handles: None,
2493 binary_variant_instantiation_handles: None,
2494 max_move_object_size: Some(250 * 1024),
2495 max_move_package_size: Some(100 * 1024),
2496 max_publish_or_upgrade_per_ptb: Some(5),
2497 max_auth_gas: None,
2499 max_tx_gas: Some(50_000_000_000),
2501 max_gas_price: Some(100_000),
2502 max_gas_computation_bucket: Some(5_000_000),
2503 max_loop_depth: Some(5),
2504 max_generic_instantiation_length: Some(32),
2505 max_function_parameters: Some(128),
2506 max_basic_blocks: Some(1024),
2507 max_value_stack_size: Some(1024),
2508 max_type_nodes: Some(256),
2509 max_push_size: Some(10000),
2510 max_struct_definitions: Some(200),
2511 max_function_definitions: Some(1000),
2512 max_fields_in_struct: Some(32),
2513 max_dependency_depth: Some(100),
2514 max_num_event_emit: Some(1024),
2515 max_num_new_move_object_ids: Some(2048),
2516 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
2517 max_num_deleted_move_object_ids: Some(2048),
2518 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
2519 max_num_transferred_move_object_ids: Some(2048),
2520 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
2521 max_event_emit_size: Some(250 * 1024),
2522 max_move_vector_len: Some(256 * 1024),
2523 max_type_to_layout_nodes: None,
2524 max_ptb_value_size: None,
2525
2526 max_back_edges_per_function: Some(10_000),
2527 max_back_edges_per_module: Some(10_000),
2528
2529 max_verifier_meter_ticks_per_function: Some(16_000_000),
2530
2531 max_meter_ticks_per_module: Some(16_000_000),
2532 max_meter_ticks_per_package: Some(16_000_000),
2533 max_meter_ticks_regex_reference_safety: None,
2534
2535 object_runtime_max_num_cached_objects: Some(1000),
2536 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2537 object_runtime_max_num_store_entries: Some(1000),
2538 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2539 base_tx_cost_fixed: Some(1_000),
2541 package_publish_cost_fixed: Some(1_000),
2542 base_tx_cost_per_byte: Some(0),
2543 package_publish_cost_per_byte: Some(80),
2544 obj_access_cost_read_per_byte: Some(15),
2545 obj_access_cost_mutate_per_byte: Some(40),
2546 obj_access_cost_delete_per_byte: Some(40),
2547 obj_access_cost_verify_per_byte: Some(200),
2548 obj_data_cost_refundable: Some(100),
2549 obj_metadata_cost_non_refundable: Some(50),
2550 gas_model_version: Some(1),
2551 storage_rebate_rate: Some(10000),
2552 reward_slashing_rate: Some(10000),
2554 storage_gas_price: Some(76),
2555 base_gas_price: None,
2556 validator_target_reward: Some(767_000 * 1_000_000_000),
2559 max_transactions_per_checkpoint: Some(10_000),
2560 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2561
2562 buffer_stake_for_protocol_upgrade_bps: Some(5000),
2564
2565 address_from_bytes_cost_base: Some(52),
2569 address_to_u256_cost_base: Some(52),
2571 address_from_u256_cost_base: Some(52),
2573
2574 config_read_setting_impl_cost_base: Some(100),
2577 config_read_setting_impl_cost_per_byte: Some(40),
2578
2579 dynamic_field_hash_type_and_key_cost_base: Some(100),
2583 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
2584 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
2585 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
2586 dynamic_field_add_child_object_cost_base: Some(100),
2589 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2590 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2591 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2592 dynamic_field_borrow_child_object_cost_base: Some(100),
2595 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2596 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2597 dynamic_field_remove_child_object_cost_base: Some(100),
2600 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2601 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2602 dynamic_field_has_child_object_cost_base: Some(100),
2605 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2608 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2609 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2610
2611 event_emit_cost_base: Some(52),
2614 event_emit_value_size_derivation_cost_per_byte: Some(2),
2615 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2616 event_emit_output_cost_per_byte: Some(10),
2617
2618 object_borrow_uid_cost_base: Some(52),
2621 object_delete_impl_cost_base: Some(52),
2623 object_record_new_uid_cost_base: Some(52),
2625
2626 transfer_transfer_internal_cost_base: Some(52),
2630 transfer_freeze_object_cost_base: Some(52),
2632 transfer_share_object_cost_base: Some(52),
2634 transfer_receive_object_cost_base: Some(52),
2635
2636 tx_context_derive_id_cost_base: Some(52),
2640 tx_context_fresh_id_cost_base: None,
2641 tx_context_sender_cost_base: None,
2642 tx_context_digest_cost_base: None,
2643 tx_context_epoch_cost_base: None,
2644 tx_context_epoch_timestamp_ms_cost_base: None,
2645 tx_context_sponsor_cost_base: None,
2646 tx_context_rgp_cost_base: None,
2647 tx_context_gas_price_cost_base: None,
2648 tx_context_gas_budget_cost_base: None,
2649 tx_context_ids_created_cost_base: None,
2650 tx_context_replace_cost_base: None,
2651
2652 types_is_one_time_witness_cost_base: Some(52),
2655 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2656 types_is_one_time_witness_type_cost_per_byte: Some(2),
2657
2658 validator_validate_metadata_cost_base: Some(52),
2662 validator_validate_metadata_data_cost_per_byte: Some(2),
2663
2664 crypto_invalid_arguments_cost: Some(100),
2666 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2668 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2669 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2670
2671 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2673 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2674 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2675
2676 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2678 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2679 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2680 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2681 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2682 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2683
2684 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2686
2687 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2689 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2690 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2691 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2692 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2693 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2694
2695 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2697 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2698 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2699 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2700 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2701 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2702
2703 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2705 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2706 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2707 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2708 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2709 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2710
2711 ecvrf_ecvrf_verify_cost_base: Some(52),
2713 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2714 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2715
2716 ed25519_ed25519_verify_cost_base: Some(52),
2718 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2719 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2720
2721 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2723 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2724
2725 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2727 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2728 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2729 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2730 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2731
2732 hash_blake2b256_cost_base: Some(52),
2734 hash_blake2b256_data_cost_per_byte: Some(2),
2735 hash_blake2b256_data_cost_per_block: Some(2),
2736 hash_keccak256_cost_base: Some(52),
2738 hash_keccak256_data_cost_per_byte: Some(2),
2739 hash_keccak256_data_cost_per_block: Some(2),
2740
2741 poseidon_bn254_cost_base: None,
2742 poseidon_bn254_cost_per_block: None,
2743
2744 hmac_hmac_sha3_256_cost_base: Some(52),
2746 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2747 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2748
2749 group_ops_bls12381_decode_scalar_cost: Some(52),
2751 group_ops_bls12381_decode_g1_cost: Some(52),
2752 group_ops_bls12381_decode_g2_cost: Some(52),
2753 group_ops_bls12381_decode_gt_cost: Some(52),
2754 group_ops_bls12381_scalar_add_cost: Some(52),
2755 group_ops_bls12381_g1_add_cost: Some(52),
2756 group_ops_bls12381_g2_add_cost: Some(52),
2757 group_ops_bls12381_gt_add_cost: Some(52),
2758 group_ops_bls12381_scalar_sub_cost: Some(52),
2759 group_ops_bls12381_g1_sub_cost: Some(52),
2760 group_ops_bls12381_g2_sub_cost: Some(52),
2761 group_ops_bls12381_gt_sub_cost: Some(52),
2762 group_ops_bls12381_scalar_mul_cost: Some(52),
2763 group_ops_bls12381_g1_mul_cost: Some(52),
2764 group_ops_bls12381_g2_mul_cost: Some(52),
2765 group_ops_bls12381_gt_mul_cost: Some(52),
2766 group_ops_bls12381_scalar_div_cost: Some(52),
2767 group_ops_bls12381_g1_div_cost: Some(52),
2768 group_ops_bls12381_g2_div_cost: Some(52),
2769 group_ops_bls12381_gt_div_cost: Some(52),
2770 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2771 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2772 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2773 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2774 group_ops_bls12381_g1_msm_base_cost: Some(52),
2775 group_ops_bls12381_g2_msm_base_cost: Some(52),
2776 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2777 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2778 group_ops_bls12381_msm_max_len: Some(32),
2779 group_ops_bls12381_pairing_cost: Some(52),
2780 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2781 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2782 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2783 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2784 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2785
2786 #[allow(deprecated)]
2788 check_zklogin_id_cost_base: Some(200),
2789 #[allow(deprecated)]
2790 check_zklogin_issuer_cost_base: Some(200),
2792
2793 vdf_verify_vdf_cost: None,
2794 vdf_hash_to_input_cost: None,
2795
2796 bcs_per_byte_serialized_cost: Some(2),
2797 bcs_legacy_min_output_size_cost: Some(1),
2798 bcs_failure_cost: Some(52),
2799 hash_sha2_256_base_cost: Some(52),
2800 hash_sha2_256_per_byte_cost: Some(2),
2801 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2802 hash_sha3_256_base_cost: Some(52),
2803 hash_sha3_256_per_byte_cost: Some(2),
2804 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2805 type_name_get_base_cost: Some(52),
2806 type_name_get_per_byte_cost: Some(2),
2807 string_check_utf8_base_cost: Some(52),
2808 string_check_utf8_per_byte_cost: Some(2),
2809 string_is_char_boundary_base_cost: Some(52),
2810 string_sub_string_base_cost: Some(52),
2811 string_sub_string_per_byte_cost: Some(2),
2812 string_index_of_base_cost: Some(52),
2813 string_index_of_per_byte_pattern_cost: Some(2),
2814 string_index_of_per_byte_searched_cost: Some(2),
2815 vector_empty_base_cost: Some(52),
2816 vector_length_base_cost: Some(52),
2817 vector_push_back_base_cost: Some(52),
2818 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2819 vector_borrow_base_cost: Some(52),
2820 vector_pop_back_base_cost: Some(52),
2821 vector_destroy_empty_base_cost: Some(52),
2822 vector_swap_base_cost: Some(52),
2823 debug_print_base_cost: Some(52),
2824 debug_print_stack_trace_base_cost: Some(52),
2825
2826 max_size_written_objects: Some(5 * 1000 * 1000),
2827 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2830
2831 max_move_identifier_len: Some(128),
2833 max_move_value_depth: Some(128),
2834 max_move_enum_variants: None,
2835
2836 gas_rounding_step: Some(1_000),
2837
2838 execution_version: Some(1),
2839
2840 max_event_emit_size_total: Some(
2843 256 * 250 * 1024, ),
2845
2846 consensus_bad_nodes_stake_threshold: Some(20),
2853
2854 #[allow(deprecated)]
2856 max_jwk_votes_per_validator_per_epoch: Some(240),
2857
2858 #[allow(deprecated)]
2859 max_age_of_jwk_in_epochs: Some(1),
2860
2861 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2865
2866 random_beacon_reduction_allowed_delta: Some(800),
2867
2868 random_beacon_reduction_lower_bound: Some(1000),
2869 random_beacon_dkg_timeout_round: Some(3000),
2870 random_beacon_min_round_interval_ms: Some(500),
2871
2872 random_beacon_dkg_version: Some(1),
2873
2874 consensus_max_num_transactions_in_block: Some(512),
2878
2879 max_deferral_rounds_for_congestion_control: Some(10),
2880
2881 min_checkpoint_interval_ms: Some(200),
2882
2883 checkpoint_rate_window_size: None,
2884
2885 checkpoint_summary_version_specific_data: Some(1),
2886
2887 max_soft_bundle_size: Some(5),
2888
2889 bridge_should_try_to_finalize_committee: None,
2890
2891 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2892
2893 max_committee_members_count: None,
2894 deny_rule_update_max_entries_per_tx: None,
2895 deny_rule_removal_grace_round_floor: None,
2896
2897 consensus_gc_depth: None,
2898
2899 consensus_max_acknowledgments_per_block: None,
2900
2901 max_congestion_limit_overshoot_per_commit: None,
2902
2903 max_concurrent_execution_workers: None,
2904
2905 scorer_version: None,
2906
2907 auth_context_digest_cost_base: None,
2909 auth_context_tx_data_bytes_cost_base: None,
2910 auth_context_tx_data_bytes_cost_per_byte: None,
2911 auth_context_tx_commands_cost_base: None,
2912 auth_context_tx_commands_cost_per_byte: None,
2913 auth_context_tx_inputs_cost_base: None,
2914 auth_context_tx_inputs_cost_per_byte: None,
2915 auth_context_replace_cost_base: None,
2916 auth_context_replace_cost_per_byte: None,
2917 auth_context_authenticator_function_info_v1_cost_base: None,
2918 consensus_commits_per_schedule: None,
2919 min_validator_count: None,
2920 max_validator_count: None,
2921 min_validator_joining_stake: None,
2922 validator_low_stake_threshold: None,
2923 validator_very_low_stake_threshold: None,
2924 validator_low_stake_grace_period: None,
2925 consensus_leader_schedule_window_size: None,
2926
2927 max_move_system_package_size: None,
2928 };
2931
2932 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2933
2934 {
2936 cfg.feature_flags
2937 .disable_invariant_violation_check_in_swap_loc = true;
2938 cfg.feature_flags.no_extraneous_module_bytes = true;
2939 cfg.feature_flags.hardened_otw_check = true;
2940 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2941 }
2942
2943 {
2945 #[allow(deprecated)]
2946 {
2947 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2948 }
2949 }
2950
2951 #[expect(deprecated)]
2955 {
2956 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2957 }
2958 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2960
2961 cfg.feature_flags.per_object_congestion_control_mode =
2962 PerObjectCongestionControlMode::TotalTxCount;
2963
2964 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2966
2967 if chain != Chain::Mainnet && chain != Chain::Testnet {
2969 cfg.feature_flags.enable_poseidon = true;
2970 cfg.poseidon_bn254_cost_base = Some(260);
2971 cfg.poseidon_bn254_cost_per_block = Some(10);
2972
2973 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2974
2975 cfg.feature_flags.enable_vdf = true;
2976 cfg.vdf_verify_vdf_cost = Some(1500);
2979 cfg.vdf_hash_to_input_cost = Some(100);
2980
2981 cfg.feature_flags.passkey_auth = true;
2982 }
2983
2984 for cur in 2..=version.0 {
2985 match cur {
2986 1 => unreachable!(),
2987 2 => {}
2989 3 => {
2990 cfg.feature_flags.relocate_event_module = true;
2991 }
2992 4 => {
2993 cfg.max_type_to_layout_nodes = Some(512);
2994 }
2995 5 => {
2996 cfg.feature_flags.protocol_defined_base_fee = true;
2997 cfg.base_gas_price = Some(1000);
2998
2999 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
3000 cfg.feature_flags.convert_type_argument_error = true;
3001 cfg.feature_flags.native_charging_v2 = true;
3002
3003 if chain != Chain::Mainnet && chain != Chain::Testnet {
3004 cfg.feature_flags.uncompressed_g1_group_elements = true;
3005 }
3006
3007 cfg.gas_model_version = Some(2);
3008
3009 cfg.poseidon_bn254_cost_per_block = Some(388);
3010
3011 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
3012 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
3013 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
3014 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
3015 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
3016 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
3017 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
3018 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
3019
3020 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
3022 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
3023 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
3024 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
3025
3026 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
3027 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
3028 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
3029 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
3030 Some(8213);
3031 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
3032 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
3033 Some(9484);
3034
3035 cfg.hash_keccak256_cost_base = Some(10);
3036 cfg.hash_blake2b256_cost_base = Some(10);
3037
3038 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
3040 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
3041 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
3042 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
3043
3044 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
3045 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
3046 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
3047 cfg.group_ops_bls12381_gt_add_cost = Some(188);
3048
3049 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
3050 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
3051 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
3052 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
3053
3054 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
3055 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
3056 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
3057 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
3058
3059 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
3060 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
3061 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
3062 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
3063
3064 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
3065 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
3066
3067 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
3068 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
3069 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
3070 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
3071
3072 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
3073 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
3074 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
3075 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
3076 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
3077
3078 cfg.group_ops_bls12381_pairing_cost = Some(26897);
3079
3080 cfg.validator_validate_metadata_cost_base = Some(20000);
3081
3082 cfg.max_committee_members_count = Some(50);
3083 }
3084 6 => {
3085 cfg.max_ptb_value_size = Some(1024 * 1024);
3086 }
3087 7 => {
3088 }
3091 8 => {
3092 cfg.feature_flags.variant_nodes = true;
3093
3094 if chain != Chain::Mainnet {
3095 cfg.feature_flags.consensus_round_prober = true;
3097 cfg.feature_flags
3099 .consensus_distributed_vote_scoring_strategy = true;
3100 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
3101 cfg.feature_flags.consensus_smart_ancestor_selection = true;
3103 cfg.feature_flags
3105 .consensus_round_prober_probe_accepted_rounds = true;
3106 cfg.feature_flags.consensus_zstd_compression = true;
3108 cfg.consensus_gc_depth = Some(60);
3112 }
3113
3114 if chain != Chain::Testnet && chain != Chain::Mainnet {
3117 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
3118 }
3119 }
3120 9 => {
3121 if chain != Chain::Mainnet {
3122 cfg.feature_flags.consensus_smart_ancestor_selection = false;
3124 }
3125
3126 cfg.feature_flags.consensus_zstd_compression = true;
3128
3129 if chain != Chain::Testnet && chain != Chain::Mainnet {
3131 cfg.feature_flags.accept_passkey_in_multisig = true;
3132 }
3133
3134 cfg.bridge_should_try_to_finalize_committee = None;
3136 }
3137 10 => {
3138 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
3141
3142 cfg.max_committee_members_count = Some(80);
3144
3145 cfg.feature_flags.consensus_round_prober = true;
3147 cfg.feature_flags
3149 .consensus_round_prober_probe_accepted_rounds = true;
3150 cfg.feature_flags
3152 .consensus_distributed_vote_scoring_strategy = true;
3153 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
3155
3156 cfg.consensus_gc_depth = Some(60);
3161
3162 cfg.feature_flags.minimize_child_object_mutations = true;
3164
3165 if chain != Chain::Mainnet {
3166 cfg.feature_flags.consensus_batched_block_sync = true;
3168 }
3169
3170 if chain != Chain::Testnet && chain != Chain::Mainnet {
3171 cfg.feature_flags
3174 .congestion_control_gas_price_feedback_mechanism = true;
3175 }
3176
3177 cfg.feature_flags.validate_identifier_inputs = true;
3178 cfg.feature_flags.dependency_linkage_error = true;
3179 cfg.feature_flags.additional_multisig_checks = true;
3180 }
3181 11 => {
3182 }
3185 12 => {
3186 cfg.feature_flags
3189 .congestion_control_gas_price_feedback_mechanism = true;
3190
3191 cfg.feature_flags.normalize_ptb_arguments = true;
3193 }
3194 13 => {
3195 cfg.feature_flags.select_committee_from_eligible_validators = true;
3198 cfg.feature_flags.track_non_committee_eligible_validators = true;
3201
3202 if chain != Chain::Testnet && chain != Chain::Mainnet {
3203 cfg.feature_flags
3206 .select_committee_supporting_next_epoch_version = true;
3207 }
3208 }
3209 14 => {
3210 cfg.feature_flags.consensus_batched_block_sync = true;
3212
3213 if chain != Chain::Mainnet {
3214 cfg.feature_flags
3217 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3218 cfg.feature_flags
3222 .select_committee_supporting_next_epoch_version = true;
3223 }
3224 if chain != Chain::Testnet && chain != Chain::Mainnet {
3225 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3227 }
3228 }
3229 15 => {
3230 if chain != Chain::Mainnet && chain != Chain::Testnet {
3231 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3235 }
3236 }
3237 16 => {
3238 cfg.feature_flags
3241 .select_committee_supporting_next_epoch_version = true;
3242 cfg.feature_flags
3244 .consensus_commit_transactions_only_for_traversed_headers = true;
3245 }
3246 17 => {
3247 cfg.max_committee_members_count = Some(100);
3249 }
3250 18 => {
3251 if chain != Chain::Mainnet {
3252 cfg.feature_flags.passkey_auth = true;
3254 }
3255 }
3256 19 => {
3257 if chain != Chain::Testnet && chain != Chain::Mainnet {
3258 cfg.feature_flags
3261 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3262 cfg.feature_flags
3265 .separate_gas_price_feedback_mechanism_for_randomness = true;
3266 cfg.feature_flags.metadata_in_module_bytes = true;
3269 cfg.feature_flags.publish_package_metadata = true;
3270 cfg.feature_flags.enable_move_authentication = true;
3272 cfg.max_auth_gas = Some(250_000_000);
3274 cfg.transfer_receive_object_cost_base = Some(100);
3277 cfg.feature_flags.adjust_rewards_by_score = true;
3279 }
3280
3281 if chain != Chain::Mainnet {
3282 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3284
3285 cfg.feature_flags.calculate_validator_scores = true;
3287 cfg.scorer_version = Some(1);
3288 }
3289
3290 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
3292
3293 cfg.feature_flags.passkey_auth = true;
3295 }
3296 20 => {
3297 if chain != Chain::Testnet && chain != Chain::Mainnet {
3298 cfg.feature_flags
3300 .pass_calculated_validator_scores_to_advance_epoch = true;
3301 }
3302 }
3303 21 => {
3304 if chain != Chain::Testnet && chain != Chain::Mainnet {
3305 cfg.feature_flags.consensus_fast_commit_sync = true;
3307 }
3308 if chain != Chain::Mainnet {
3309 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3314 cfg.feature_flags
3317 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3318 cfg.feature_flags
3321 .separate_gas_price_feedback_mechanism_for_randomness = true;
3322 }
3323
3324 cfg.auth_context_digest_cost_base = Some(30);
3325 cfg.auth_context_tx_commands_cost_base = Some(30);
3326 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
3327 cfg.auth_context_tx_inputs_cost_base = Some(30);
3328 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
3329 cfg.auth_context_replace_cost_base = Some(30);
3330 cfg.auth_context_replace_cost_per_byte = Some(2);
3331
3332 if chain != Chain::Testnet && chain != Chain::Mainnet {
3333 cfg.max_auth_gas = Some(250_000);
3335 }
3336 }
3337 22 => {
3338 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3343 cfg.feature_flags
3346 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3347 cfg.feature_flags
3350 .separate_gas_price_feedback_mechanism_for_randomness = true;
3351
3352 if chain != Chain::Mainnet {
3353 cfg.feature_flags.metadata_in_module_bytes = true;
3356 cfg.feature_flags.publish_package_metadata = true;
3357 cfg.feature_flags.enable_move_authentication = true;
3359 cfg.max_auth_gas = Some(250_000);
3361 cfg.transfer_receive_object_cost_base = Some(100);
3364 }
3365
3366 if chain != Chain::Mainnet {
3367 cfg.feature_flags.consensus_fast_commit_sync = true;
3369 }
3370 }
3371 23 => {
3372 cfg.feature_flags.move_native_tx_context = true;
3374 cfg.tx_context_fresh_id_cost_base = Some(52);
3375 cfg.tx_context_sender_cost_base = Some(30);
3376 cfg.tx_context_digest_cost_base = Some(30);
3377 cfg.tx_context_epoch_cost_base = Some(30);
3378 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
3379 cfg.tx_context_sponsor_cost_base = Some(30);
3380 cfg.tx_context_rgp_cost_base = Some(30);
3381 cfg.tx_context_gas_price_cost_base = Some(30);
3382 cfg.tx_context_gas_budget_cost_base = Some(30);
3383 cfg.tx_context_ids_created_cost_base = Some(30);
3384 cfg.tx_context_replace_cost_base = Some(30);
3385 }
3386 24 => {
3387 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3389
3390 if chain != Chain::Testnet && chain != Chain::Mainnet {
3391 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3393 }
3394
3395 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
3398 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
3399
3400 cfg.feature_flags.additional_borrow_checks = true;
3402 }
3403 #[allow(deprecated)]
3404 25 => {
3405 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
3408 cfg.check_zklogin_id_cost_base = None;
3409 cfg.check_zklogin_issuer_cost_base = None;
3410 cfg.max_jwk_votes_per_validator_per_epoch = None;
3411 cfg.max_age_of_jwk_in_epochs = None;
3412 }
3413 26 => {
3414 }
3417 27 => {
3418 if chain != Chain::Mainnet {
3419 cfg.feature_flags.consensus_block_restrictions = true;
3422 }
3423
3424 if chain != Chain::Testnet && chain != Chain::Mainnet {
3425 cfg.feature_flags
3427 .pre_consensus_sponsor_only_move_authentication = true;
3428 }
3429 }
3430 28 => {
3431 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
3436
3437 cfg.feature_flags.metadata_in_module_bytes = true;
3440 cfg.feature_flags.publish_package_metadata = true;
3441 cfg.feature_flags.enable_move_authentication = true;
3443 cfg.transfer_receive_object_cost_base = Some(100);
3446
3447 if chain != Chain::Unknown {
3448 cfg.max_auth_gas = Some(20_000);
3450 }
3451
3452 if chain != Chain::Mainnet {
3453 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3455 cfg.feature_flags
3457 .pre_consensus_sponsor_only_move_authentication = true;
3458 }
3459 }
3460 29 => {
3461 cfg.feature_flags.always_advance_dkg_to_resolution = true;
3467
3468 cfg.feature_flags
3471 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3472
3473 cfg.feature_flags.consensus_fast_commit_sync = true;
3475 cfg.feature_flags.consensus_block_restrictions = true;
3479 }
3480 30 => {
3481 }
3489 31 => {
3490 cfg.feature_flags.validator_metadata_verify_v2 = true;
3491
3492 if chain != Chain::Mainnet && chain != Chain::Testnet {
3493 cfg.checkpoint_rate_window_size = Some(20);
3496 cfg.feature_flags
3499 .package_metadata_with_dynamic_module_metadata = true;
3500 cfg.feature_flags.consensus_starfish_speed = true;
3503 }
3504
3505 cfg.feature_flags.report_move_authentication_error = true;
3506 }
3507 32 => {
3508 cfg.min_validator_count = Some(4);
3512 cfg.max_validator_count = Some(150);
3513 cfg.min_validator_joining_stake = Some(2_000_000_000_000_000);
3514 cfg.validator_low_stake_threshold = Some(1_500_000_000_000_000);
3515 cfg.validator_very_low_stake_threshold = Some(1_000_000_000_000_000);
3516 cfg.validator_low_stake_grace_period = Some(7);
3517
3518 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3520 cfg.feature_flags
3522 .pre_consensus_sponsor_only_move_authentication = true;
3523
3524 if chain != Chain::Mainnet {
3525 cfg.feature_flags.consensus_starfish_speed = true;
3528 cfg.checkpoint_rate_window_size = Some(20);
3531 cfg.feature_flags
3534 .package_metadata_with_dynamic_module_metadata = true;
3535 }
3536
3537 if chain != Chain::Mainnet && chain != Chain::Testnet {
3538 cfg.feature_flags
3542 .consensus_enable_sliding_window_leader_schedule = true;
3543 cfg.feature_flags
3544 .consensus_enable_absolute_score_leader_schedule = true;
3545 cfg.feature_flags.enable_pcool_flow = true;
3549 }
3550 }
3551 33 => {
3552 cfg.checkpoint_rate_window_size = Some(20);
3555 if chain != Chain::Mainnet {
3559 cfg.feature_flags
3560 .consensus_enable_sliding_window_leader_schedule = true;
3561 cfg.feature_flags
3562 .consensus_enable_absolute_score_leader_schedule = true;
3563 }
3564 }
3565 34 => {
3566 if chain != Chain::Testnet && chain != Chain::Mainnet {
3567 cfg.scorer_version = Some(2);
3571 }
3572 cfg.feature_flags.pcool_skip_immutable_object_locks = true;
3576
3577 if chain == Chain::Mainnet {
3578 cfg.feature_flags.enable_move_authentication_for_sponsor = false;
3580 cfg.feature_flags
3583 .pre_consensus_sponsor_only_move_authentication = false;
3584 }
3585 }
3586 35 => {
3587 cfg.feature_flags.max_ptb_value_size_v2 = true;
3589 cfg.feature_flags.allow_unbounded_system_objects = true;
3591
3592 cfg.feature_flags.consensus_starfish_speed = true;
3595
3596 cfg.max_verifier_meter_ticks_per_function = Some(2_200_000);
3603 cfg.max_meter_ticks_per_module = Some(2_200_000);
3604 cfg.max_meter_ticks_per_package = Some(2_200_000);
3605 cfg.max_meter_ticks_regex_reference_safety = Some(2_200_000);
3606 cfg.feature_flags.pcool_verifier_limits_from_protocol_config = true;
3607 cfg.feature_flags
3610 .package_metadata_with_dynamic_module_metadata = true;
3611 cfg.feature_flags
3615 .consensus_enable_sliding_window_leader_schedule = true;
3616 cfg.feature_flags
3617 .consensus_enable_absolute_score_leader_schedule = true;
3618
3619 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3622 cfg.feature_flags
3625 .pre_consensus_sponsor_only_move_authentication = false;
3626 }
3627 36 => {
3628 cfg.feature_flags.reject_immutable_account_objects = true;
3631 }
3632 37 => {
3633 cfg.feature_flags.validate_input_object_versions = true;
3637 cfg.feature_flags.disallow_self_identifier = true;
3638 cfg.max_move_enum_variants = Some(move_core_types::VARIANT_COUNT_MAX);
3639 cfg.feature_flags.deny_authenticator_packages = true;
3642 cfg.feature_flags.check_canonical_module_version_header = true;
3645 cfg.feature_flags.disallow_randomness_in_move_authenticator = true;
3650 cfg.feature_flags.check_cyclic_dependencies = true;
3653 }
3654 38 => {
3655 cfg.max_move_system_package_size = Some(200 * 1024);
3662 cfg.feature_flags.reject_immutable_account_creation = true;
3665
3666 cfg.feature_flags.validate_ptb_argument_indices = true;
3667 }
3668 39 => {
3669 if chain != Chain::Mainnet {
3672 cfg.feature_flags.allow_dkg_completion_after_timeout = true;
3673 }
3674 }
3675 _ => panic!("unsupported version {version:?}"),
3686 }
3687 }
3688 cfg
3689 }
3690
3691 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
3697 let (
3698 max_back_edges_per_function,
3699 max_back_edges_per_module,
3700 sanity_check_with_regex_reference_safety,
3701 ) = if let Some((
3702 max_back_edges_per_function,
3703 max_back_edges_per_module,
3704 sanity_check_with_regex_reference_safety,
3705 )) = signing_limits
3706 {
3707 (
3708 Some(max_back_edges_per_function),
3709 Some(max_back_edges_per_module),
3710 Some(sanity_check_with_regex_reference_safety),
3711 )
3712 } else {
3713 (None, None, None)
3714 };
3715
3716 let additional_borrow_checks = if signing_limits.is_some() {
3717 true
3720 } else {
3721 self.additional_borrow_checks()
3722 };
3723
3724 VerifierConfig {
3725 max_loop_depth: Some(self.max_loop_depth() as usize),
3726 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
3727 max_function_parameters: Some(self.max_function_parameters() as usize),
3728 max_basic_blocks: Some(self.max_basic_blocks() as usize),
3729 max_value_stack_size: self.max_value_stack_size() as usize,
3730 max_type_nodes: Some(self.max_type_nodes() as usize),
3731 max_push_size: Some(self.max_push_size() as usize),
3732 max_dependency_depth: Some(self.max_dependency_depth() as usize),
3733 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
3734 max_function_definitions: Some(self.max_function_definitions() as usize),
3735 max_data_definitions: Some(self.max_struct_definitions() as usize),
3736 max_constant_vector_len: Some(self.max_move_vector_len()),
3737 max_back_edges_per_function,
3738 max_back_edges_per_module,
3739 max_basic_blocks_in_script: None,
3740 max_identifier_len: self.max_move_identifier_len_as_option(), disallow_self_identifier: self.feature_flags.disallow_self_identifier,
3744 bytecode_version: self.move_binary_format_version(),
3745 max_variants_in_enum: self.max_move_enum_variants_as_option(),
3746 additional_borrow_checks,
3747 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
3748 .map(|limit| limit as u128),
3749 check_cyclic_dependencies: self.feature_flags.check_cyclic_dependencies,
3750 }
3751 }
3752
3753 pub fn verifier_signing_limits(&self) -> (usize, usize, usize) {
3760 (
3761 self.max_back_edges_per_function() as usize,
3762 self.max_back_edges_per_module() as usize,
3763 self.max_meter_ticks_regex_reference_safety() as usize,
3764 )
3765 }
3766
3767 pub fn meter_config(&self) -> MeterConfig {
3771 MeterConfig {
3772 max_per_fun_meter_units: Some(self.max_verifier_meter_ticks_per_function() as u128),
3773 max_per_mod_meter_units: Some(self.max_meter_ticks_per_module() as u128),
3774 max_per_pkg_meter_units: Some(self.max_meter_ticks_per_package() as u128),
3775 }
3776 }
3777
3778 pub fn apply_overrides_for_testing(
3783 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
3784 ) -> OverrideGuard {
3785 CONFIG_OVERRIDE.with(|ovr| {
3786 let mut cur = ovr.borrow_mut();
3787 assert!(cur.is_none(), "config override already present");
3788 *cur = Some(Box::new(override_fn));
3789 OverrideGuard
3790 })
3791 }
3792}
3793
3794impl ProtocolConfig {
3799 pub fn set_per_object_congestion_control_mode_for_testing(
3800 &mut self,
3801 val: PerObjectCongestionControlMode,
3802 ) {
3803 self.feature_flags.per_object_congestion_control_mode = val;
3804 }
3805
3806 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
3807 self.feature_flags.consensus_choice = val;
3808 }
3809
3810 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
3811 self.feature_flags.consensus_network = val;
3812 }
3813
3814 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
3815 self.feature_flags.passkey_auth = val
3816 }
3817
3818 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
3819 self.feature_flags
3820 .disallow_new_modules_in_deps_only_packages = val;
3821 }
3822
3823 pub fn set_check_canonical_module_version_header_for_testing(&mut self, val: bool) {
3824 self.feature_flags.check_canonical_module_version_header = val;
3825 }
3826
3827 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
3828 self.feature_flags.consensus_round_prober = val;
3829 }
3830
3831 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
3832 self.feature_flags
3833 .consensus_distributed_vote_scoring_strategy = val;
3834 }
3835
3836 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
3837 self.consensus_gc_depth = Some(val);
3838 }
3839
3840 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
3841 self.feature_flags.consensus_linearize_subdag_v2 = val;
3842 }
3843
3844 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
3845 self.feature_flags
3846 .consensus_round_prober_probe_accepted_rounds = val;
3847 }
3848
3849 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
3850 self.feature_flags.accept_passkey_in_multisig = val;
3851 }
3852
3853 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
3854 self.feature_flags.consensus_smart_ancestor_selection = val;
3855 }
3856
3857 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
3858 self.feature_flags.consensus_batched_block_sync = val;
3859 }
3860
3861 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
3862 self.feature_flags
3863 .congestion_control_min_free_execution_slot = val;
3864 }
3865
3866 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
3867 self.feature_flags
3868 .congestion_control_gas_price_feedback_mechanism = val;
3869 }
3870
3871 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
3872 self.feature_flags.select_committee_from_eligible_validators = val;
3873 }
3874
3875 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
3876 self.feature_flags.track_non_committee_eligible_validators = val;
3877 }
3878
3879 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
3880 self.feature_flags
3881 .select_committee_supporting_next_epoch_version = val;
3882 }
3883
3884 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
3885 &mut self,
3886 val: bool,
3887 ) {
3888 self.feature_flags
3889 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3890 }
3891
3892 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3893 &mut self,
3894 val: bool,
3895 ) {
3896 self.feature_flags
3897 .consensus_commit_transactions_only_for_traversed_headers = val;
3898 }
3899
3900 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3901 &mut self,
3902 val: bool,
3903 ) {
3904 self.feature_flags
3905 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3906 }
3907
3908 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3909 &mut self,
3910 val: bool,
3911 ) {
3912 self.feature_flags
3913 .separate_gas_price_feedback_mechanism_for_randomness = val;
3914 }
3915
3916 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3917 self.feature_flags.metadata_in_module_bytes = val;
3918 }
3919
3920 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3921 self.feature_flags.publish_package_metadata = val;
3922 }
3923
3924 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3925 self.feature_flags.enable_move_authentication = val;
3926 }
3927
3928 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3929 self.feature_flags.enable_move_authentication_for_sponsor = val;
3930 }
3931
3932 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3933 self.feature_flags.consensus_fast_commit_sync = val;
3934 }
3935
3936 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3937 self.feature_flags.consensus_block_restrictions = val;
3938 }
3939
3940 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3941 self.feature_flags
3942 .pre_consensus_sponsor_only_move_authentication = val;
3943 }
3944
3945 pub fn set_consensus_starfish_speed_for_testing(&mut self, val: bool) {
3946 self.feature_flags.consensus_starfish_speed = val;
3947 }
3948
3949 pub fn set_always_advance_dkg_to_resolution_for_testing(&mut self, val: bool) {
3950 self.feature_flags.always_advance_dkg_to_resolution = val;
3951 }
3952
3953 pub fn set_enable_pcool_flow_for_testing(&mut self, val: bool) {
3954 self.feature_flags.enable_pcool_flow = val;
3955 }
3956
3957 pub fn set_pcool_skip_immutable_object_locks_for_testing(&mut self, val: bool) {
3958 self.feature_flags.pcool_skip_immutable_object_locks = val;
3959 }
3960
3961 pub fn set_pcool_verifier_limits_from_protocol_config_for_testing(&mut self, val: bool) {
3962 self.feature_flags
3963 .pcool_verifier_limits_from_protocol_config = val;
3964 }
3965
3966 pub fn set_reject_immutable_account_objects_for_testing(&mut self, val: bool) {
3967 self.feature_flags.reject_immutable_account_objects = val;
3968 }
3969
3970 pub fn set_reject_immutable_account_creation_for_testing(&mut self, val: bool) {
3971 self.feature_flags.reject_immutable_account_creation = val;
3972 }
3973
3974 pub fn set_validate_input_object_versions_for_testing(&mut self, val: bool) {
3975 self.feature_flags.validate_input_object_versions = val;
3976 }
3977
3978 pub fn set_disallow_randomness_in_move_authenticator_for_testing(&mut self, val: bool) {
3979 self.feature_flags.disallow_randomness_in_move_authenticator = val;
3980 }
3981
3982 pub fn set_commits_per_schedule_for_testing(&mut self, val: u32) {
3983 self.consensus_commits_per_schedule = Some(val);
3984 }
3985
3986 pub fn set_deny_rule_governance_for_testing(&mut self, val: bool) {
3987 self.feature_flags.deny_rule_governance = val;
3988 }
3989
3990 pub fn set_deny_authenticator_packages_for_testing(&mut self, val: bool) {
3991 self.feature_flags.deny_authenticator_packages = val;
3992 }
3993
3994 pub fn set_deny_rule_governance_on_chain_for_testing(&mut self, val: bool) {
3995 self.feature_flags.deny_rule_governance_on_chain = val;
3996 }
3997
3998 pub fn set_calculate_validator_scores_for_testing(&mut self, val: bool) {
4003 self.feature_flags.calculate_validator_scores = val;
4004 if val {
4005 self.scorer_version.get_or_insert(1);
4006 } else {
4007 self.feature_flags.adjust_rewards_by_score = false;
4008 self.feature_flags
4009 .pass_calculated_validator_scores_to_advance_epoch = false;
4010 }
4011 }
4012
4013 pub fn set_package_metadata_with_dynamic_module_metadata_for_testing(&mut self, val: bool) {
4014 self.feature_flags
4015 .package_metadata_with_dynamic_module_metadata = val;
4016 }
4017
4018 pub fn set_report_move_authentication_error_for_testing(&mut self, val: bool) {
4019 self.feature_flags.report_move_authentication_error = val;
4020 }
4021
4022 pub fn set_leader_schedule_window_size_for_testing(&mut self, val: u32) {
4023 self.consensus_leader_schedule_window_size = Some(val);
4024 }
4025
4026 pub fn set_consensus_enable_sliding_window_leader_schedule_for_testing(&mut self, val: bool) {
4027 self.feature_flags
4028 .consensus_enable_sliding_window_leader_schedule = val;
4029 }
4030
4031 pub fn set_consensus_enable_absolute_score_leader_schedule_for_testing(&mut self, val: bool) {
4032 self.feature_flags
4033 .consensus_enable_absolute_score_leader_schedule = val;
4034 }
4035
4036 pub fn set_allow_dkg_completion_after_timeout_for_testing(&mut self, val: bool) {
4037 self.feature_flags.allow_dkg_completion_after_timeout = val;
4038 }
4039}
4040
4041type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
4042
4043thread_local! {
4044 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
4045}
4046
4047#[must_use]
4048pub struct OverrideGuard;
4049
4050impl Drop for OverrideGuard {
4051 fn drop(&mut self) {
4052 info!("restoring override fn");
4053 CONFIG_OVERRIDE.with(|ovr| {
4054 *ovr.borrow_mut() = None;
4055 });
4056 }
4057}
4058
4059#[derive(PartialEq, Eq)]
4063pub enum LimitThresholdCrossed {
4064 None,
4065 Soft(u128, u128),
4066 Hard(u128, u128),
4067}
4068
4069pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
4072 x: T,
4073 soft_limit: U,
4074 hard_limit: V,
4075) -> LimitThresholdCrossed {
4076 let x: V = x.into();
4077 let soft_limit: V = soft_limit.into();
4078
4079 debug_assert!(soft_limit <= hard_limit);
4080
4081 if x >= hard_limit {
4084 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
4085 } else if x < soft_limit {
4086 LimitThresholdCrossed::None
4087 } else {
4088 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
4089 }
4090}
4091
4092#[macro_export]
4093macro_rules! check_limit {
4094 ($x:expr, $hard:expr) => {
4095 check_limit!($x, $hard, $hard)
4096 };
4097 ($x:expr, $soft:expr, $hard:expr) => {
4098 check_limit_in_range($x as u64, $soft, $hard)
4099 };
4100}
4101
4102#[macro_export]
4106macro_rules! check_limit_by_meter {
4107 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
4108 let (h, metered_str) = if $is_metered {
4110 ($metered_limit, "metered")
4111 } else {
4112 ($unmetered_hard_limit, "unmetered")
4114 };
4115 use iota_protocol_config::check_limit_in_range;
4116 let result = check_limit_in_range($x as u64, $metered_limit, h);
4117 match result {
4118 LimitThresholdCrossed::None => {}
4119 LimitThresholdCrossed::Soft(_, _) => {
4120 $metric.with_label_values(&[metered_str, "soft"]).inc();
4121 }
4122 LimitThresholdCrossed::Hard(_, _) => {
4123 $metric.with_label_values(&[metered_str, "hard"]).inc();
4124 }
4125 };
4126 result
4127 }};
4128}
4129
4130#[cfg(all(test, not(msim)))]
4131mod test {
4132 use insta::assert_yaml_snapshot;
4133
4134 use super::*;
4135
4136 #[test]
4137 fn snapshot_tests() {
4138 println!("\n============================================================================");
4139 println!("! !");
4140 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
4141 println!("! !");
4142 println!("============================================================================\n");
4143 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
4144 let chain_str = match chain_id {
4149 Chain::Unknown => "".to_string(),
4150 _ => format!("{chain_id:?}_"),
4151 };
4152 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
4153 let cur = ProtocolVersion::new(i);
4154 assert_yaml_snapshot!(
4155 format!("{}version_{}", chain_str, cur.as_u64()),
4156 ProtocolConfig::get_for_version(cur, *chain_id)
4157 );
4158 }
4159 }
4160 }
4161
4162 #[test]
4163 fn test_getters() {
4164 let prot: ProtocolConfig =
4165 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4166 assert_eq!(
4167 prot.max_arguments(),
4168 prot.max_arguments_as_option().unwrap()
4169 );
4170 }
4171
4172 #[test]
4173 fn test_setters() {
4174 let mut prot: ProtocolConfig =
4175 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4176 prot.set_max_arguments_for_testing(123);
4177 assert_eq!(prot.max_arguments(), 123);
4178
4179 prot.set_max_arguments_from_str_for_testing("321".to_string());
4180 assert_eq!(prot.max_arguments(), 321);
4181
4182 prot.disable_max_arguments_for_testing();
4183 assert_eq!(prot.max_arguments_as_option(), None);
4184
4185 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
4186 assert_eq!(prot.max_arguments(), 456);
4187 }
4188
4189 #[test]
4190 fn reject_immutable_account_creation_implies_rejecting_the_objects() {
4191 for chain in [Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
4192 for version in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
4193 ProtocolConfig::get_for_version(ProtocolVersion::new(version), chain)
4196 .reject_immutable_account_creation();
4197 }
4198 }
4199 }
4200
4201 #[test]
4202 #[should_panic(expected = "unsupported version")]
4203 fn max_version_test() {
4204 let _ = ProtocolConfig::get_for_version_impl(
4207 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
4208 Chain::Unknown,
4209 );
4210 }
4211
4212 #[test]
4213 fn lookup_by_string_test() {
4214 let prot: ProtocolConfig =
4215 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
4216 assert!(prot.lookup_attr("some random string".to_string()).is_none());
4218
4219 assert!(
4220 prot.lookup_attr("max_arguments".to_string())
4221 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
4222 );
4223
4224 assert!(
4226 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
4227 .is_none()
4228 );
4229 assert!(
4230 prot.attr_map()
4231 .get("poseidon_bn254_cost_base")
4232 .unwrap()
4233 .is_none()
4234 );
4235
4236 let prot: ProtocolConfig =
4238 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4239
4240 assert!(
4241 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
4242 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
4243 );
4244 assert!(
4245 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
4246 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
4247 );
4248
4249 let prot: ProtocolConfig =
4251 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
4252 assert!(
4254 prot.feature_flags
4255 .lookup_attr("some random string".to_owned())
4256 .is_none()
4257 );
4258 assert!(
4259 !prot
4260 .feature_flags
4261 .attr_map()
4262 .contains_key("some random string")
4263 );
4264
4265 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
4267 assert!(
4268 prot.feature_flags
4269 .attr_map()
4270 .get("enable_poseidon")
4271 .unwrap()
4272 == &false
4273 );
4274 let prot: ProtocolConfig =
4275 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4276 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
4278 assert!(
4279 prot.feature_flags
4280 .attr_map()
4281 .get("enable_poseidon")
4282 .unwrap()
4283 == &true
4284 );
4285 }
4286
4287 #[test]
4291 #[should_panic(expected = "deny_rule_update_max_entries_per_tx must be positive")]
4292 fn deny_rule_chunk_limit_above_the_ceiling_is_rejected() {
4293 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
4294 config.set_deny_rule_governance_for_testing(true);
4295 config.set_deny_rule_governance_on_chain_for_testing(true);
4296 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
4297 config.set_deny_rule_update_max_entries_per_tx_for_testing(2048 + 1);
4298 config
4299 });
4300 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
4301 }
4302
4303 #[test]
4306 #[should_panic(expected = "deny_rule_update_max_entries_per_tx must be positive")]
4307 fn deny_rule_chunk_limit_of_zero_is_rejected() {
4308 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
4309 config.set_deny_rule_governance_for_testing(true);
4310 config.set_deny_rule_governance_on_chain_for_testing(true);
4311 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
4312 config.set_deny_rule_update_max_entries_per_tx_for_testing(0);
4313 config
4314 });
4315 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
4316 }
4317
4318 #[test]
4320 fn deny_rule_chunk_limit_within_system_tx_object_id_limit_is_accepted() {
4321 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
4322 config.set_deny_rule_governance_for_testing(true);
4323 config.set_deny_rule_governance_on_chain_for_testing(true);
4324 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
4325 config.set_deny_rule_update_max_entries_per_tx_for_testing(1000);
4326 config
4327 });
4328 let config = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
4329 assert_eq!(config.deny_rule_update_max_entries_per_tx(), 1000);
4330 }
4331
4332 #[test]
4333 fn limit_range_fn_test() {
4334 let low = 100u32;
4335 let high = 10000u64;
4336
4337 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
4338 assert!(matches!(
4339 check_limit!(255u16, low, high),
4340 LimitThresholdCrossed::Soft(255u128, 100)
4341 ));
4342 assert!(matches!(
4349 check_limit!(2550000u64, low, high),
4350 LimitThresholdCrossed::Hard(2550000, 10000)
4351 ));
4352
4353 assert!(matches!(
4354 check_limit!(2550000u64, high, high),
4355 LimitThresholdCrossed::Hard(2550000, 10000)
4356 ));
4357
4358 assert!(matches!(
4359 check_limit!(1u8, high),
4360 LimitThresholdCrossed::None
4361 ));
4362
4363 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
4364
4365 assert!(matches!(
4366 check_limit!(2550000u64, high),
4367 LimitThresholdCrossed::Hard(2550000, 10000)
4368 ));
4369 }
4370}