1use std::{
6 cell::RefCell,
7 cmp::min,
8 sync::atomic::{AtomicBool, Ordering},
9};
10
11use clap::*;
12use iota_protocol_config_macros::{
13 ProtocolConfigAccessors, ProtocolConfigFeatureFlagsGetters, ProtocolConfigOverride,
14};
15use move_vm_config::verifier::{MeterConfig, VerifierConfig};
16use serde::{Deserialize, Serialize};
17use serde_with::skip_serializing_none;
18use tracing::{info, warn};
19
20const MIN_PROTOCOL_VERSION: u64 = 1;
22pub const MAX_PROTOCOL_VERSION: u64 = 38;
23
24pub const PROTOCOL_VERSION_IIP8: u64 = 20;
26#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
255pub struct ProtocolVersion(u64);
256
257impl ProtocolVersion {
258 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
264
265 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
266
267 #[cfg(not(msim))]
268 const MAX_ALLOWED: Self = Self::MAX;
269
270 #[cfg(msim)]
273 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
274
275 pub fn new(v: u64) -> Self {
276 Self(v)
277 }
278
279 pub const fn as_u64(&self) -> u64 {
280 self.0
281 }
282
283 pub fn max() -> Self {
286 Self::MAX
287 }
288}
289
290impl From<u64> for ProtocolVersion {
291 fn from(v: u64) -> Self {
292 Self::new(v)
293 }
294}
295
296impl std::ops::Sub<u64> for ProtocolVersion {
297 type Output = Self;
298 fn sub(self, rhs: u64) -> Self::Output {
299 Self::new(self.0 - rhs)
300 }
301}
302
303impl std::ops::Add<u64> for ProtocolVersion {
304 type Output = Self;
305 fn add(self, rhs: u64) -> Self::Output {
306 Self::new(self.0 + rhs)
307 }
308}
309
310#[derive(
311 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
312)]
313pub enum Chain {
314 Mainnet,
315 Testnet,
316 #[default]
317 Unknown,
318}
319
320impl Chain {
321 pub fn as_str(self) -> &'static str {
322 match self {
323 Chain::Mainnet => "mainnet",
324 Chain::Testnet => "testnet",
325 Chain::Unknown => "unknown",
326 }
327 }
328}
329
330pub struct Error(pub String);
331
332#[derive(
336 Default,
337 Clone,
338 Serialize,
339 Deserialize,
340 Debug,
341 ProtocolConfigFeatureFlagsGetters,
342 ProtocolConfigOverride,
343)]
344struct FeatureFlags {
345 #[serde(skip_serializing_if = "is_true")]
351 disable_invariant_violation_check_in_swap_loc: bool,
352
353 #[serde(skip_serializing_if = "is_true")]
356 no_extraneous_module_bytes: bool,
357
358 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
360 consensus_transaction_ordering: ConsensusTransactionOrdering,
361
362 #[serde(skip_serializing_if = "is_true")]
365 hardened_otw_check: bool,
366
367 #[serde(skip_serializing_if = "is_false")]
369 enable_poseidon: bool,
370
371 #[serde(skip_serializing_if = "is_false")]
373 enable_group_ops_native_function_msm: bool,
374
375 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
377 per_object_congestion_control_mode: PerObjectCongestionControlMode,
378
379 #[serde(
381 default = "ConsensusChoice::mysticeti_deprecated",
382 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
383 )]
384 consensus_choice: ConsensusChoice,
385
386 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
388 consensus_network: ConsensusNetwork,
389
390 #[deprecated]
392 #[serde(skip_serializing_if = "Option::is_none")]
393 zklogin_max_epoch_upper_bound_delta: Option<u64>,
394
395 #[serde(skip_serializing_if = "is_false")]
397 enable_vdf: bool,
398
399 #[serde(skip_serializing_if = "is_false")]
401 passkey_auth: bool,
402
403 #[serde(skip_serializing_if = "is_true")]
406 rethrow_serialization_type_layout_errors: bool,
407
408 #[serde(skip_serializing_if = "is_false")]
410 relocate_event_module: bool,
411
412 #[serde(skip_serializing_if = "is_false")]
414 protocol_defined_base_fee: bool,
415
416 #[serde(skip_serializing_if = "is_false")]
418 uncompressed_g1_group_elements: bool,
419
420 #[serde(skip_serializing_if = "is_false")]
422 disallow_new_modules_in_deps_only_packages: bool,
423
424 #[serde(skip_serializing_if = "is_false")]
426 native_charging_v2: bool,
427
428 #[serde(skip_serializing_if = "is_false")]
430 convert_type_argument_error: bool,
431
432 #[serde(skip_serializing_if = "is_false")]
434 consensus_round_prober: bool,
435
436 #[serde(skip_serializing_if = "is_false")]
438 consensus_distributed_vote_scoring_strategy: bool,
439
440 #[serde(skip_serializing_if = "is_false")]
444 consensus_linearize_subdag_v2: bool,
445
446 #[serde(skip_serializing_if = "is_false")]
448 variant_nodes: bool,
449
450 #[serde(skip_serializing_if = "is_false")]
452 consensus_smart_ancestor_selection: bool,
453
454 #[serde(skip_serializing_if = "is_false")]
456 consensus_round_prober_probe_accepted_rounds: bool,
457
458 #[serde(skip_serializing_if = "is_false")]
460 consensus_zstd_compression: bool,
461
462 #[serde(skip_serializing_if = "is_false")]
465 congestion_control_min_free_execution_slot: bool,
466
467 #[serde(skip_serializing_if = "is_false")]
469 accept_passkey_in_multisig: bool,
470
471 #[serde(skip_serializing_if = "is_false")]
473 consensus_batched_block_sync: bool,
474
475 #[serde(skip_serializing_if = "is_false")]
478 congestion_control_gas_price_feedback_mechanism: bool,
479
480 #[serde(skip_serializing_if = "is_false")]
482 validate_identifier_inputs: bool,
483
484 #[serde(skip_serializing_if = "is_false")]
487 minimize_child_object_mutations: bool,
488
489 #[serde(skip_serializing_if = "is_false")]
491 dependency_linkage_error: bool,
492
493 #[serde(skip_serializing_if = "is_false")]
495 additional_multisig_checks: bool,
496
497 #[serde(skip_serializing_if = "is_false")]
500 normalize_ptb_arguments: bool,
501
502 #[serde(skip_serializing_if = "is_false")]
506 select_committee_from_eligible_validators: bool,
507
508 #[serde(skip_serializing_if = "is_false")]
515 track_non_committee_eligible_validators: bool,
516
517 #[serde(skip_serializing_if = "is_false")]
523 select_committee_supporting_next_epoch_version: bool,
524
525 #[serde(skip_serializing_if = "is_false")]
529 consensus_median_timestamp_with_checkpoint_enforcement: bool,
530
531 #[serde(skip_serializing_if = "is_false")]
533 consensus_commit_transactions_only_for_traversed_headers: bool,
534
535 #[serde(skip_serializing_if = "is_false")]
537 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
538
539 #[serde(skip_serializing_if = "is_false")]
542 separate_gas_price_feedback_mechanism_for_randomness: bool,
543
544 #[serde(skip_serializing_if = "is_false")]
547 metadata_in_module_bytes: bool,
548
549 #[serde(skip_serializing_if = "is_false")]
551 publish_package_metadata: bool,
552
553 #[serde(skip_serializing_if = "is_false")]
555 enable_move_authentication: bool,
556
557 #[serde(skip_serializing_if = "is_false")]
559 enable_move_authentication_for_sponsor: bool,
560
561 #[serde(skip_serializing_if = "is_false")]
563 pass_validator_scores_to_advance_epoch: bool,
564
565 #[serde(skip_serializing_if = "is_false")]
567 calculate_validator_scores: bool,
568
569 #[serde(skip_serializing_if = "is_false")]
571 adjust_rewards_by_score: bool,
572
573 #[serde(skip_serializing_if = "is_false")]
576 pass_calculated_validator_scores_to_advance_epoch: bool,
577
578 #[serde(skip_serializing_if = "is_false")]
583 consensus_fast_commit_sync: bool,
584
585 #[serde(skip_serializing_if = "is_false")]
588 consensus_block_restrictions: bool,
589
590 #[serde(skip_serializing_if = "is_false")]
592 move_native_tx_context: bool,
593
594 #[serde(skip_serializing_if = "is_false")]
596 additional_borrow_checks: bool,
597
598 #[serde(skip_serializing_if = "is_false")]
600 pre_consensus_sponsor_only_move_authentication: bool,
601
602 #[serde(skip_serializing_if = "is_false")]
604 consensus_starfish_speed: bool,
605
606 #[serde(skip_serializing_if = "is_false")]
613 always_advance_dkg_to_resolution: bool,
614
615 #[serde(skip_serializing_if = "is_false")]
620 enable_pcool_flow: bool,
621
622 #[serde(skip_serializing_if = "is_false")]
627 pcool_skip_immutable_object_locks: bool,
628
629 #[serde(skip_serializing_if = "is_false")]
634 pcool_verifier_limits_from_protocol_config: bool,
635
636 #[serde(skip_serializing_if = "is_false")]
638 validator_metadata_verify_v2: bool,
639
640 #[serde(skip_serializing_if = "is_false")]
644 deny_rule_governance: bool,
645
646 #[serde(skip_serializing_if = "is_false")]
651 deny_rule_governance_on_chain: bool,
652
653 #[serde(skip_serializing_if = "is_false")]
657 deny_authenticator_packages: bool,
658
659 #[serde(skip_serializing_if = "is_false")]
662 package_metadata_with_dynamic_module_metadata: bool,
663
664 #[serde(skip_serializing_if = "is_false")]
667 report_move_authentication_error: bool,
668
669 #[serde(skip_serializing_if = "is_false")]
674 consensus_enable_sliding_window_leader_schedule: bool,
675
676 #[serde(skip_serializing_if = "is_false")]
681 consensus_enable_absolute_score_leader_schedule: bool,
682
683 #[serde(skip_serializing_if = "is_false")]
685 max_ptb_value_size_v2: bool,
686
687 #[serde(skip_serializing_if = "is_false")]
689 allow_unbounded_system_objects: bool,
690
691 #[serde(skip_serializing_if = "is_false")]
694 reject_immutable_account_objects: bool,
695
696 #[serde(skip_serializing_if = "is_false")]
699 reject_immutable_account_creation: bool,
700
701 #[serde(skip_serializing_if = "is_false")]
707 validate_input_object_versions: bool,
708
709 #[serde(skip_serializing_if = "is_false")]
711 disallow_self_identifier: bool,
712
713 #[serde(skip_serializing_if = "is_false")]
718 check_canonical_module_version_header: bool,
719
720 #[serde(skip_serializing_if = "is_false")]
725 disallow_randomness_in_move_authenticator: bool,
726
727 #[serde(skip_serializing_if = "is_false")]
731 check_cyclic_dependencies: bool,
732
733 #[serde(skip_serializing_if = "is_false")]
735 deprecate_global_storage_ops_during_deserialization: bool,
736
737 #[serde(skip_serializing_if = "is_false")]
739 validate_ptb_argument_indices: bool,
740}
741
742fn is_true(b: &bool) -> bool {
743 *b
744}
745
746fn is_false(b: &bool) -> bool {
747 !b
748}
749
750#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
752pub enum ConsensusTransactionOrdering {
753 #[default]
756 None,
757 ByGasPrice,
759}
760
761impl ConsensusTransactionOrdering {
762 pub fn is_none(&self) -> bool {
763 matches!(self, ConsensusTransactionOrdering::None)
764 }
765}
766
767#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
769pub enum PerObjectCongestionControlMode {
770 #[default]
771 None, TotalGasBudget, TotalTxCount, }
775
776impl PerObjectCongestionControlMode {
777 pub fn is_none(&self) -> bool {
778 matches!(self, PerObjectCongestionControlMode::None)
779 }
780}
781
782#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
784pub enum ConsensusChoice {
785 #[deprecated(note = "Mysticeti was replaced by Starfish")]
788 MysticetiDeprecated,
789 #[default]
790 Starfish,
791}
792
793#[expect(deprecated)]
794impl ConsensusChoice {
795 fn mysticeti_deprecated() -> Self {
802 ConsensusChoice::MysticetiDeprecated
803 }
804
805 pub fn is_mysticeti_deprecated(&self) -> bool {
806 matches!(self, ConsensusChoice::MysticetiDeprecated)
807 }
808 pub fn is_starfish(&self) -> bool {
809 matches!(self, ConsensusChoice::Starfish)
810 }
811}
812
813#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
815pub enum ConsensusNetwork {
816 #[default]
817 Tonic,
818}
819
820impl ConsensusNetwork {
821 pub fn is_tonic(&self) -> bool {
822 matches!(self, ConsensusNetwork::Tonic)
823 }
824}
825
826#[skip_serializing_none]
859#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
860pub struct ProtocolConfig {
861 pub version: ProtocolVersion,
862
863 feature_flags: FeatureFlags,
864
865 max_tx_size_bytes: Option<u64>,
870
871 max_input_objects: Option<u64>,
876
877 max_size_written_objects: Option<u64>,
882 max_size_written_objects_system_tx: Option<u64>,
886
887 max_serialized_tx_effects_size_bytes: Option<u64>,
889
890 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
892
893 max_gas_payment_objects: Option<u32>,
895
896 max_modules_in_publish: Option<u32>,
898
899 max_package_dependencies: Option<u32>,
901
902 max_arguments: Option<u32>,
905
906 max_type_arguments: Option<u32>,
908
909 max_type_argument_depth: Option<u32>,
911
912 max_pure_argument_size: Option<u32>,
914
915 max_programmable_tx_commands: Option<u32>,
917
918 move_binary_format_version: Option<u32>,
924 min_move_binary_format_version: Option<u32>,
925
926 binary_module_handles: Option<u16>,
928 binary_struct_handles: Option<u16>,
929 binary_function_handles: Option<u16>,
930 binary_function_instantiations: Option<u16>,
931 binary_signatures: Option<u16>,
932 binary_constant_pool: Option<u16>,
933 binary_identifiers: Option<u16>,
934 binary_address_identifiers: Option<u16>,
935 binary_struct_defs: Option<u16>,
936 binary_struct_def_instantiations: Option<u16>,
937 binary_function_defs: Option<u16>,
938 binary_field_handles: Option<u16>,
939 binary_field_instantiations: Option<u16>,
940 binary_friend_decls: Option<u16>,
941 binary_enum_defs: Option<u16>,
942 binary_enum_def_instantiations: Option<u16>,
943 binary_variant_handles: Option<u16>,
944 binary_variant_instantiation_handles: Option<u16>,
945
946 max_move_object_size: Option<u64>,
949
950 max_move_package_size: Option<u64>,
955
956 max_publish_or_upgrade_per_ptb: Option<u64>,
959
960 max_tx_gas: Option<u64>,
962
963 max_auth_gas: Option<u64>,
965
966 max_gas_price: Option<u64>,
969
970 max_gas_computation_bucket: Option<u64>,
973
974 gas_rounding_step: Option<u64>,
976
977 max_loop_depth: Option<u64>,
979
980 max_generic_instantiation_length: Option<u64>,
983
984 max_function_parameters: Option<u64>,
987
988 max_basic_blocks: Option<u64>,
991
992 max_value_stack_size: Option<u64>,
994
995 max_type_nodes: Option<u64>,
999
1000 max_push_size: Option<u64>,
1003
1004 max_struct_definitions: Option<u64>,
1007
1008 max_function_definitions: Option<u64>,
1011
1012 max_fields_in_struct: Option<u64>,
1015
1016 max_dependency_depth: Option<u64>,
1019
1020 max_num_event_emit: Option<u64>,
1023
1024 max_num_new_move_object_ids: Option<u64>,
1027
1028 max_num_new_move_object_ids_system_tx: Option<u64>,
1031
1032 max_num_deleted_move_object_ids: Option<u64>,
1035
1036 max_num_deleted_move_object_ids_system_tx: Option<u64>,
1039
1040 max_num_transferred_move_object_ids: Option<u64>,
1043
1044 max_num_transferred_move_object_ids_system_tx: Option<u64>,
1047
1048 max_event_emit_size: Option<u64>,
1050
1051 max_event_emit_size_total: Option<u64>,
1053
1054 max_move_vector_len: Option<u64>,
1057
1058 max_move_identifier_len: Option<u64>,
1061
1062 max_move_value_depth: Option<u64>,
1064
1065 max_move_enum_variants: Option<u64>,
1068
1069 max_back_edges_per_function: Option<u64>,
1078
1079 max_back_edges_per_module: Option<u64>,
1081
1082 max_verifier_meter_ticks_per_function: Option<u64>,
1084
1085 max_meter_ticks_per_module: Option<u64>,
1087
1088 max_meter_ticks_per_package: Option<u64>,
1090
1091 max_meter_ticks_regex_reference_safety: Option<u64>,
1095
1096 object_runtime_max_num_cached_objects: Option<u64>,
1103
1104 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
1107
1108 object_runtime_max_num_store_entries: Option<u64>,
1111
1112 object_runtime_max_num_store_entries_system_tx: Option<u64>,
1115
1116 base_tx_cost_fixed: Option<u64>,
1121
1122 package_publish_cost_fixed: Option<u64>,
1126
1127 base_tx_cost_per_byte: Option<u64>,
1131
1132 package_publish_cost_per_byte: Option<u64>,
1134
1135 obj_access_cost_read_per_byte: Option<u64>,
1137
1138 obj_access_cost_mutate_per_byte: Option<u64>,
1140
1141 obj_access_cost_delete_per_byte: Option<u64>,
1143
1144 obj_access_cost_verify_per_byte: Option<u64>,
1154
1155 max_type_to_layout_nodes: Option<u64>,
1157
1158 max_ptb_value_size: Option<u64>,
1160
1161 gas_model_version: Option<u64>,
1166
1167 obj_data_cost_refundable: Option<u64>,
1173
1174 obj_metadata_cost_non_refundable: Option<u64>,
1178
1179 storage_rebate_rate: Option<u64>,
1185
1186 reward_slashing_rate: Option<u64>,
1189
1190 storage_gas_price: Option<u64>,
1192
1193 base_gas_price: Option<u64>,
1195
1196 validator_target_reward: Option<u64>,
1198
1199 max_transactions_per_checkpoint: Option<u64>,
1206
1207 max_checkpoint_size_bytes: Option<u64>,
1211
1212 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
1218
1219 address_from_bytes_cost_base: Option<u64>,
1224 address_to_u256_cost_base: Option<u64>,
1226 address_from_u256_cost_base: Option<u64>,
1228
1229 config_read_setting_impl_cost_base: Option<u64>,
1234 config_read_setting_impl_cost_per_byte: Option<u64>,
1235
1236 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
1240 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
1241 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
1242 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
1243 dynamic_field_add_child_object_cost_base: Option<u64>,
1246 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
1247 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
1248 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
1249 dynamic_field_borrow_child_object_cost_base: Option<u64>,
1252 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1253 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1254 dynamic_field_remove_child_object_cost_base: Option<u64>,
1257 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1258 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1259 dynamic_field_has_child_object_cost_base: Option<u64>,
1262 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1265 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1266 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1267
1268 event_emit_cost_base: Option<u64>,
1271 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1272 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1273 event_emit_output_cost_per_byte: Option<u64>,
1274
1275 object_borrow_uid_cost_base: Option<u64>,
1278 object_delete_impl_cost_base: Option<u64>,
1280 object_record_new_uid_cost_base: Option<u64>,
1282
1283 transfer_transfer_internal_cost_base: Option<u64>,
1286 transfer_freeze_object_cost_base: Option<u64>,
1288 transfer_share_object_cost_base: Option<u64>,
1290 transfer_receive_object_cost_base: Option<u64>,
1293
1294 tx_context_derive_id_cost_base: Option<u64>,
1297 tx_context_fresh_id_cost_base: Option<u64>,
1298 tx_context_sender_cost_base: Option<u64>,
1299 tx_context_digest_cost_base: Option<u64>,
1300 tx_context_epoch_cost_base: Option<u64>,
1301 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1302 tx_context_sponsor_cost_base: Option<u64>,
1303 tx_context_rgp_cost_base: Option<u64>,
1304 tx_context_gas_price_cost_base: Option<u64>,
1305 tx_context_gas_budget_cost_base: Option<u64>,
1306 tx_context_ids_created_cost_base: Option<u64>,
1307 tx_context_replace_cost_base: Option<u64>,
1308
1309 types_is_one_time_witness_cost_base: Option<u64>,
1312 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1313 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1314
1315 validator_validate_metadata_cost_base: Option<u64>,
1318 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1319
1320 crypto_invalid_arguments_cost: Option<u64>,
1322 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1324 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1325 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1326
1327 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1329 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1330 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1331
1332 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1334 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1335 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1336 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1337 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1338 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1339
1340 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1342
1343 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1345 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1346 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1347 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1348 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1349 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1350
1351 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1353 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1354 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1355 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1356 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1357 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1358
1359 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1361 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1362 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1363 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1364 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1365 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1366
1367 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1369 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1370 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1371
1372 ed25519_ed25519_verify_cost_base: Option<u64>,
1374 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1375 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1376
1377 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1379 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1380
1381 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1383 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1384 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1385 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1386 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1387
1388 hash_blake2b256_cost_base: Option<u64>,
1390 hash_blake2b256_data_cost_per_byte: Option<u64>,
1391 hash_blake2b256_data_cost_per_block: Option<u64>,
1392
1393 hash_keccak256_cost_base: Option<u64>,
1395 hash_keccak256_data_cost_per_byte: Option<u64>,
1396 hash_keccak256_data_cost_per_block: Option<u64>,
1397
1398 poseidon_bn254_cost_base: Option<u64>,
1400 poseidon_bn254_cost_per_block: Option<u64>,
1401
1402 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1404 group_ops_bls12381_decode_g1_cost: Option<u64>,
1405 group_ops_bls12381_decode_g2_cost: Option<u64>,
1406 group_ops_bls12381_decode_gt_cost: Option<u64>,
1407 group_ops_bls12381_scalar_add_cost: Option<u64>,
1408 group_ops_bls12381_g1_add_cost: Option<u64>,
1409 group_ops_bls12381_g2_add_cost: Option<u64>,
1410 group_ops_bls12381_gt_add_cost: Option<u64>,
1411 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1412 group_ops_bls12381_g1_sub_cost: Option<u64>,
1413 group_ops_bls12381_g2_sub_cost: Option<u64>,
1414 group_ops_bls12381_gt_sub_cost: Option<u64>,
1415 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1416 group_ops_bls12381_g1_mul_cost: Option<u64>,
1417 group_ops_bls12381_g2_mul_cost: Option<u64>,
1418 group_ops_bls12381_gt_mul_cost: Option<u64>,
1419 group_ops_bls12381_scalar_div_cost: Option<u64>,
1420 group_ops_bls12381_g1_div_cost: Option<u64>,
1421 group_ops_bls12381_g2_div_cost: Option<u64>,
1422 group_ops_bls12381_gt_div_cost: Option<u64>,
1423 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1424 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1425 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1426 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1427 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1428 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1429 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1430 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1431 group_ops_bls12381_msm_max_len: Option<u32>,
1432 group_ops_bls12381_pairing_cost: Option<u64>,
1433 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1434 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1435 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1436 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1437 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1438
1439 hmac_hmac_sha3_256_cost_base: Option<u64>,
1441 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1442 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1443
1444 #[deprecated]
1446 check_zklogin_id_cost_base: Option<u64>,
1447 #[deprecated]
1449 check_zklogin_issuer_cost_base: Option<u64>,
1450
1451 vdf_verify_vdf_cost: Option<u64>,
1452 vdf_hash_to_input_cost: Option<u64>,
1453
1454 bcs_per_byte_serialized_cost: Option<u64>,
1456 bcs_legacy_min_output_size_cost: Option<u64>,
1457 bcs_failure_cost: Option<u64>,
1458
1459 hash_sha2_256_base_cost: Option<u64>,
1460 hash_sha2_256_per_byte_cost: Option<u64>,
1461 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1462 hash_sha3_256_base_cost: Option<u64>,
1463 hash_sha3_256_per_byte_cost: Option<u64>,
1464 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1465 type_name_get_base_cost: Option<u64>,
1466 type_name_get_per_byte_cost: Option<u64>,
1467
1468 string_check_utf8_base_cost: Option<u64>,
1469 string_check_utf8_per_byte_cost: Option<u64>,
1470 string_is_char_boundary_base_cost: Option<u64>,
1471 string_sub_string_base_cost: Option<u64>,
1472 string_sub_string_per_byte_cost: Option<u64>,
1473 string_index_of_base_cost: Option<u64>,
1474 string_index_of_per_byte_pattern_cost: Option<u64>,
1475 string_index_of_per_byte_searched_cost: Option<u64>,
1476
1477 vector_empty_base_cost: Option<u64>,
1478 vector_length_base_cost: Option<u64>,
1479 vector_push_back_base_cost: Option<u64>,
1480 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1481 vector_borrow_base_cost: Option<u64>,
1482 vector_pop_back_base_cost: Option<u64>,
1483 vector_destroy_empty_base_cost: Option<u64>,
1484 vector_swap_base_cost: Option<u64>,
1485 debug_print_base_cost: Option<u64>,
1486 debug_print_stack_trace_base_cost: Option<u64>,
1487
1488 execution_version: Option<u64>,
1490
1491 consensus_bad_nodes_stake_threshold: Option<u64>,
1495
1496 #[deprecated]
1497 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1498 #[deprecated]
1502 max_age_of_jwk_in_epochs: Option<u64>,
1503
1504 random_beacon_reduction_allowed_delta: Option<u16>,
1508
1509 random_beacon_reduction_lower_bound: Option<u32>,
1512
1513 random_beacon_dkg_timeout_round: Option<u32>,
1516
1517 random_beacon_min_round_interval_ms: Option<u64>,
1519
1520 random_beacon_dkg_version: Option<u64>,
1524
1525 consensus_max_transaction_size_bytes: Option<u64>,
1530 consensus_max_transactions_in_block_bytes: Option<u64>,
1532 consensus_max_num_transactions_in_block: Option<u64>,
1534
1535 max_deferral_rounds_for_congestion_control: Option<u64>,
1539
1540 min_checkpoint_interval_ms: Option<u64>,
1542
1543 checkpoint_rate_window_size: Option<u64>,
1553
1554 checkpoint_summary_version_specific_data: Option<u64>,
1556
1557 max_soft_bundle_size: Option<u64>,
1560
1561 bridge_should_try_to_finalize_committee: Option<bool>,
1566
1567 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1573
1574 max_committee_members_count: Option<u64>,
1578
1579 deny_rule_update_max_entries_per_tx: Option<u64>,
1584
1585 deny_rule_removal_grace_round_floor: Option<u64>,
1590
1591 consensus_gc_depth: Option<u32>,
1594
1595 consensus_max_acknowledgments_per_block: Option<u32>,
1601
1602 max_congestion_limit_overshoot_per_commit: Option<u64>,
1607
1608 max_concurrent_execution_workers: Option<u16>,
1615
1616 scorer_version: Option<u16>,
1625
1626 auth_context_digest_cost_base: Option<u64>,
1629 auth_context_tx_data_bytes_cost_base: Option<u64>,
1631 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1632 auth_context_tx_commands_cost_base: Option<u64>,
1634 auth_context_tx_commands_cost_per_byte: Option<u64>,
1635 auth_context_tx_inputs_cost_base: Option<u64>,
1637 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1638 auth_context_replace_cost_base: Option<u64>,
1641 auth_context_replace_cost_per_byte: Option<u64>,
1642 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1646
1647 consensus_commits_per_schedule: Option<u32>,
1650
1651 min_validator_count: Option<u64>,
1654
1655 max_validator_count: Option<u64>,
1659
1660 min_validator_joining_stake: Option<u64>,
1664
1665 validator_low_stake_threshold: Option<u64>,
1670
1671 validator_very_low_stake_threshold: Option<u64>,
1675
1676 validator_low_stake_grace_period: Option<u64>,
1680
1681 consensus_leader_schedule_window_size: Option<u32>,
1685
1686 max_move_system_package_size: Option<u64>,
1691}
1692
1693impl ProtocolConfig {
1695 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1708 self.feature_flags
1709 .disable_invariant_violation_check_in_swap_loc
1710 }
1711
1712 pub fn no_extraneous_module_bytes(&self) -> bool {
1713 self.feature_flags.no_extraneous_module_bytes
1714 }
1715
1716 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1717 self.feature_flags.consensus_transaction_ordering
1718 }
1719
1720 pub fn dkg_version(&self) -> u64 {
1721 self.random_beacon_dkg_version.unwrap_or(1)
1723 }
1724
1725 pub fn hardened_otw_check(&self) -> bool {
1726 self.feature_flags.hardened_otw_check
1727 }
1728
1729 pub fn enable_poseidon(&self) -> bool {
1730 self.feature_flags.enable_poseidon
1731 }
1732
1733 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1734 self.feature_flags.enable_group_ops_native_function_msm
1735 }
1736
1737 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1738 self.feature_flags.per_object_congestion_control_mode
1739 }
1740
1741 pub fn consensus_choice(&self) -> ConsensusChoice {
1742 self.feature_flags.consensus_choice
1743 }
1744
1745 pub fn consensus_network(&self) -> ConsensusNetwork {
1746 self.feature_flags.consensus_network
1747 }
1748
1749 pub fn enable_vdf(&self) -> bool {
1750 self.feature_flags.enable_vdf
1751 }
1752
1753 pub fn passkey_auth(&self) -> bool {
1754 self.feature_flags.passkey_auth
1755 }
1756
1757 pub fn max_transaction_size_bytes(&self) -> u64 {
1758 self.consensus_max_transaction_size_bytes
1760 .unwrap_or(256 * 1024)
1761 }
1762
1763 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1764 if cfg!(msim) {
1765 256 * 1024
1766 } else {
1767 self.consensus_max_transactions_in_block_bytes
1768 .unwrap_or(512 * 1024)
1769 }
1770 }
1771
1772 pub fn max_num_transactions_in_block(&self) -> u64 {
1773 if cfg!(msim) {
1774 8
1775 } else {
1776 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1777 }
1778 }
1779
1780 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1781 self.feature_flags.rethrow_serialization_type_layout_errors
1782 }
1783
1784 pub fn relocate_event_module(&self) -> bool {
1785 self.feature_flags.relocate_event_module
1786 }
1787
1788 pub fn protocol_defined_base_fee(&self) -> bool {
1789 self.feature_flags.protocol_defined_base_fee
1790 }
1791
1792 pub fn uncompressed_g1_group_elements(&self) -> bool {
1793 self.feature_flags.uncompressed_g1_group_elements
1794 }
1795
1796 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1797 self.feature_flags
1798 .disallow_new_modules_in_deps_only_packages
1799 }
1800
1801 pub fn native_charging_v2(&self) -> bool {
1802 self.feature_flags.native_charging_v2
1803 }
1804
1805 pub fn consensus_round_prober(&self) -> bool {
1806 self.feature_flags.consensus_round_prober
1807 }
1808
1809 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1810 self.feature_flags
1811 .consensus_distributed_vote_scoring_strategy
1812 }
1813
1814 pub fn gc_depth(&self) -> u32 {
1815 if cfg!(msim) {
1816 min(5, self.consensus_gc_depth.unwrap_or(0))
1818 } else {
1819 self.consensus_gc_depth.unwrap_or(0)
1820 }
1821 }
1822
1823 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1824 let res = self.feature_flags.consensus_linearize_subdag_v2;
1825 assert!(
1826 !res || self.gc_depth() > 0,
1827 "The consensus linearize sub dag V2 requires GC to be enabled"
1828 );
1829 res
1830 }
1831
1832 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1833 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1834 }
1835
1836 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1837 2 * committee_size
1838 }
1839
1840 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1841 committee_size
1842 }
1843
1844 pub fn variant_nodes(&self) -> bool {
1845 self.feature_flags.variant_nodes
1846 }
1847
1848 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1849 self.feature_flags.consensus_smart_ancestor_selection
1850 }
1851
1852 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1853 self.feature_flags
1854 .consensus_round_prober_probe_accepted_rounds
1855 }
1856
1857 pub fn consensus_zstd_compression(&self) -> bool {
1858 self.feature_flags.consensus_zstd_compression
1859 }
1860
1861 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1862 self.feature_flags
1863 .congestion_control_min_free_execution_slot
1864 }
1865
1866 pub fn accept_passkey_in_multisig(&self) -> bool {
1867 self.feature_flags.accept_passkey_in_multisig
1868 }
1869
1870 pub fn consensus_batched_block_sync(&self) -> bool {
1871 self.feature_flags.consensus_batched_block_sync
1872 }
1873
1874 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1877 self.feature_flags
1878 .congestion_control_gas_price_feedback_mechanism
1879 }
1880
1881 pub fn validate_identifier_inputs(&self) -> bool {
1882 self.feature_flags.validate_identifier_inputs
1883 }
1884
1885 pub fn minimize_child_object_mutations(&self) -> bool {
1886 self.feature_flags.minimize_child_object_mutations
1887 }
1888
1889 pub fn dependency_linkage_error(&self) -> bool {
1890 self.feature_flags.dependency_linkage_error
1891 }
1892
1893 pub fn additional_multisig_checks(&self) -> bool {
1894 self.feature_flags.additional_multisig_checks
1895 }
1896
1897 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1898 0
1901 }
1902
1903 pub fn normalize_ptb_arguments(&self) -> bool {
1904 self.feature_flags.normalize_ptb_arguments
1905 }
1906
1907 pub fn select_committee_from_eligible_validators(&self) -> bool {
1908 let res = self.feature_flags.select_committee_from_eligible_validators;
1909 assert!(
1910 !res || (self.protocol_defined_base_fee()
1911 && self.max_committee_members_count_as_option().is_some()),
1912 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1913 );
1914 res
1915 }
1916
1917 pub fn track_non_committee_eligible_validators(&self) -> bool {
1918 self.feature_flags.track_non_committee_eligible_validators
1919 }
1920
1921 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1922 let res = self
1923 .feature_flags
1924 .select_committee_supporting_next_epoch_version;
1925 assert!(
1926 !res || (self.track_non_committee_eligible_validators()
1927 && self.select_committee_from_eligible_validators()),
1928 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1929 );
1930 res
1931 }
1932
1933 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1934 let res = self
1935 .feature_flags
1936 .consensus_median_timestamp_with_checkpoint_enforcement;
1937 assert!(
1938 !res || self.gc_depth() > 0,
1939 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1940 );
1941 res
1942 }
1943
1944 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1945 self.feature_flags
1946 .consensus_commit_transactions_only_for_traversed_headers
1947 }
1948
1949 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1952 self.feature_flags
1953 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1954 }
1955
1956 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1959 self.feature_flags
1960 .separate_gas_price_feedback_mechanism_for_randomness
1961 }
1962
1963 pub fn metadata_in_module_bytes(&self) -> bool {
1964 self.feature_flags.metadata_in_module_bytes
1965 }
1966
1967 pub fn publish_package_metadata(&self) -> bool {
1968 self.feature_flags.publish_package_metadata
1969 }
1970
1971 pub fn enable_move_authentication(&self) -> bool {
1972 self.feature_flags.enable_move_authentication
1973 }
1974
1975 pub fn additional_borrow_checks(&self) -> bool {
1976 self.feature_flags.additional_borrow_checks
1977 }
1978
1979 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1980 let enable_move_authentication_for_sponsor =
1981 self.feature_flags.enable_move_authentication_for_sponsor;
1982 assert!(
1983 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1984 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1985 );
1986 enable_move_authentication_for_sponsor
1987 }
1988
1989 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1990 self.feature_flags.pass_validator_scores_to_advance_epoch
1991 }
1992
1993 pub fn calculate_validator_scores(&self) -> bool {
1994 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1995 assert!(
1996 !calculate_validator_scores || self.scorer_version.is_some(),
1997 "calculate_validator_scores requires scorer_version to be set"
1998 );
1999 calculate_validator_scores
2000 }
2001
2002 pub fn adjust_rewards_by_score(&self) -> bool {
2003 let adjust = self.feature_flags.adjust_rewards_by_score;
2004 assert!(
2005 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
2006 "adjust_rewards_by_score requires scorer_version to be set"
2007 );
2008 adjust
2009 }
2010
2011 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
2012 let pass = self
2013 .feature_flags
2014 .pass_calculated_validator_scores_to_advance_epoch;
2015 assert!(
2016 !pass
2017 || (self.pass_validator_scores_to_advance_epoch()
2018 && self.calculate_validator_scores()),
2019 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
2020 );
2021 pass
2022 }
2023 pub fn consensus_fast_commit_sync(&self) -> bool {
2024 let res = self.feature_flags.consensus_fast_commit_sync;
2025 assert!(
2026 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
2027 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
2028 );
2029 res
2030 }
2031
2032 pub fn consensus_block_restrictions(&self) -> bool {
2033 self.feature_flags.consensus_block_restrictions
2034 }
2035
2036 pub fn move_native_tx_context(&self) -> bool {
2037 self.feature_flags.move_native_tx_context
2038 }
2039
2040 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
2041 let pre_consensus_sponsor_only_move_authentication = self
2042 .feature_flags
2043 .pre_consensus_sponsor_only_move_authentication;
2044 if pre_consensus_sponsor_only_move_authentication {
2045 assert!(
2046 self.enable_move_authentication(),
2047 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
2048 );
2049 assert!(
2050 self.enable_move_authentication_for_sponsor(),
2051 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
2052 );
2053 }
2054 pre_consensus_sponsor_only_move_authentication
2055 }
2056
2057 pub fn consensus_starfish_speed(&self) -> bool {
2058 let res = self.feature_flags.consensus_starfish_speed;
2059 assert!(
2060 !res || self.consensus_fast_commit_sync(),
2061 "consensus_starfish_speed requires consensus_fast_commit_sync to be enabled"
2062 );
2063 res
2064 }
2065
2066 pub fn always_advance_dkg_to_resolution(&self) -> bool {
2067 self.feature_flags.always_advance_dkg_to_resolution
2068 }
2069
2070 pub fn enable_pcool_flow(&self) -> bool {
2071 self.feature_flags.enable_pcool_flow
2072 }
2073
2074 pub fn pcool_skip_immutable_object_locks(&self) -> bool {
2075 self.feature_flags.pcool_skip_immutable_object_locks
2076 }
2077
2078 pub fn pcool_verifier_limits_from_protocol_config(&self) -> bool {
2081 self.feature_flags
2082 .pcool_verifier_limits_from_protocol_config
2083 }
2084
2085 pub fn validator_metadata_verify_v2(&self) -> bool {
2086 self.feature_flags.validator_metadata_verify_v2
2087 }
2088
2089 pub fn commits_per_schedule(&self) -> u32 {
2090 let commits_per_schedule = if cfg!(msim) {
2091 min(10, self.consensus_commits_per_schedule.unwrap_or(300))
2093 } else {
2094 self.consensus_commits_per_schedule.unwrap_or(300)
2095 };
2096 assert!(
2097 commits_per_schedule > 0,
2098 "consensus_commits_per_schedule must be greater than 0"
2099 );
2100 commits_per_schedule
2101 }
2102
2103 pub fn leader_schedule_window_size(&self) -> u32 {
2104 if cfg!(msim) {
2105 min(
2108 20,
2109 self.consensus_leader_schedule_window_size.unwrap_or(600),
2110 )
2111 } else {
2112 self.consensus_leader_schedule_window_size.unwrap_or(600)
2113 }
2114 }
2115
2116 pub fn consensus_enable_sliding_window_leader_schedule(&self) -> bool {
2117 let res = self
2118 .feature_flags
2119 .consensus_enable_sliding_window_leader_schedule;
2120 assert!(
2121 !res || self.leader_schedule_window_size() >= self.commits_per_schedule(),
2122 "consensus_enable_sliding_window_leader_schedule requires window_size >= commits_per_schedule"
2123 );
2124 res
2125 }
2126
2127 pub fn consensus_enable_absolute_score_leader_schedule(&self) -> bool {
2128 self.feature_flags
2129 .consensus_enable_absolute_score_leader_schedule
2130 }
2131
2132 pub fn max_ptb_value_size_v2(&self) -> bool {
2133 self.feature_flags.max_ptb_value_size_v2
2134 }
2135
2136 pub fn deny_rule_governance(&self) -> bool {
2137 self.feature_flags.deny_rule_governance
2138 }
2139
2140 pub fn deny_rule_governance_on_chain(&self) -> bool {
2141 self.feature_flags.deny_rule_governance_on_chain
2142 }
2143
2144 pub fn deny_authenticator_packages(&self) -> bool {
2145 self.feature_flags.deny_authenticator_packages
2146 }
2147
2148 pub fn package_metadata_with_dynamic_module_metadata(&self) -> bool {
2149 let res = self
2150 .feature_flags
2151 .package_metadata_with_dynamic_module_metadata;
2152 assert!(
2153 !res || self.publish_package_metadata(),
2154 "package_metadata_with_dynamic_module_metadata requires publish_package_metadata to be enabled"
2155 );
2156 res
2157 }
2158
2159 pub fn report_move_authentication_error(&self) -> bool {
2160 let report_move_authentication_error = self.feature_flags.report_move_authentication_error;
2161 assert!(
2162 !report_move_authentication_error || self.enable_move_authentication(),
2163 "report_move_authentication_error requires enable_move_authentication to be set"
2164 );
2165 report_move_authentication_error
2166 }
2167
2168 pub fn concurrent_execution_workers(&self) -> Option<u16> {
2172 let res = self.max_concurrent_execution_workers;
2173 assert!(
2174 res.is_none() || self.enable_pcool_flow(),
2175 "max_concurrent_execution_workers requires enable_pcool_flow to be enabled"
2176 );
2177 assert!(
2178 res.is_none()
2179 || self
2180 .max_accumulated_txn_cost_per_object_in_mysticeti_commit
2181 .is_some(),
2182 "max_concurrent_execution_workers requires per-object congestion control \
2183 (max_accumulated_txn_cost_per_object_in_mysticeti_commit) to be enabled"
2184 );
2185 assert!(
2186 res.is_none() || self.congestion_control_gas_price_feedback_mechanism(),
2187 "max_concurrent_execution_workers requires the gas price feedback mechanism \
2188 (congestion_control_gas_price_feedback_mechanism), which carries the suggested \
2189 gas price of an execution-worker congestion cancellation"
2190 );
2191 assert!(
2192 res.is_none() || !self.separate_gas_price_feedback_mechanism_for_randomness(),
2193 "max_concurrent_execution_workers implies a single congestion tracker and suggested \
2194 gas price calculator for all transactions, which is incompatible with \
2195 separate_gas_price_feedback_mechanism_for_randomness"
2196 );
2197 assert!(
2198 res != Some(0),
2199 "max_concurrent_execution_workers must be positive when set"
2200 );
2201 res
2202 }
2203
2204 pub fn allow_unbounded_system_objects(&self) -> bool {
2205 self.feature_flags.allow_unbounded_system_objects
2206 }
2207
2208 pub fn reject_immutable_account_objects(&self) -> bool {
2209 let reject_immutable_account_objects = self.feature_flags.reject_immutable_account_objects;
2210 assert!(
2211 !reject_immutable_account_objects || self.enable_move_authentication(),
2212 "reject_immutable_account_objects requires enable_move_authentication to be set"
2213 );
2214 reject_immutable_account_objects
2215 }
2216
2217 pub fn reject_immutable_account_creation(&self) -> bool {
2218 let reject_immutable_account_creation =
2219 self.feature_flags.reject_immutable_account_creation;
2220 assert!(
2221 !reject_immutable_account_creation || self.reject_immutable_account_objects(),
2222 "reject_immutable_account_creation requires reject_immutable_account_objects to be set"
2223 );
2224 reject_immutable_account_creation
2225 }
2226
2227 pub fn validate_input_object_versions(&self) -> bool {
2228 self.feature_flags.validate_input_object_versions
2229 }
2230
2231 pub fn check_canonical_module_version_header(&self) -> bool {
2232 self.feature_flags.check_canonical_module_version_header
2233 }
2234
2235 pub fn disallow_randomness_in_move_authenticator(&self) -> bool {
2236 self.feature_flags.disallow_randomness_in_move_authenticator
2237 }
2238
2239 pub fn check_cyclic_dependencies(&self) -> bool {
2240 self.feature_flags.check_cyclic_dependencies
2241 }
2242
2243 pub fn deprecate_global_storage_ops_during_deserialization(&self) -> bool {
2244 self.feature_flags
2245 .deprecate_global_storage_ops_during_deserialization
2246 }
2247
2248 pub fn validate_ptb_argument_indices(&self) -> bool {
2249 self.feature_flags.validate_ptb_argument_indices
2250 }
2251}
2252
2253#[cfg(not(msim))]
2254static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2255
2256#[cfg(msim)]
2258thread_local! {
2259 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2260}
2261
2262impl ProtocolConfig {
2264 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
2267 assert!(
2269 version >= ProtocolVersion::MIN,
2270 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
2271 version,
2272 ProtocolVersion::MIN.0,
2273 );
2274 assert!(
2275 version <= ProtocolVersion::MAX_ALLOWED,
2276 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
2277 version,
2278 ProtocolVersion::MAX_ALLOWED.0,
2279 );
2280
2281 let mut ret = Self::get_for_version_impl(version, chain);
2282 ret.version = version;
2283
2284 ret = CONFIG_OVERRIDE.with(|ovr| {
2285 if let Some(override_fn) = &*ovr.borrow() {
2286 warn!(
2287 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
2288 );
2289 override_fn(version, ret)
2290 } else {
2291 ret
2292 }
2293 });
2294
2295 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
2296 warn!(
2297 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
2298 );
2299
2300 let overrides: ProtocolConfigOptional =
2302 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
2303 .expect("failed to parse ProtocolConfig override env variables");
2304 overrides.apply_to(&mut ret);
2305
2306 let feature_flag_overrides: FeatureFlagsOptional =
2308 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_FEATURE_FLAGS_OVERRIDE")
2309 .expect("failed to parse ProtocolConfig feature flags override env variables");
2310
2311 feature_flag_overrides.apply_to(&mut ret.feature_flags);
2312 }
2313
2314 assert!(
2316 !ret.feature_flags.deny_rule_governance_on_chain
2317 || ret.feature_flags.deny_rule_governance,
2318 "deny_rule_governance_on_chain requires deny_rule_governance"
2319 );
2320 assert!(
2325 !ret.feature_flags.pcool_verifier_limits_from_protocol_config
2326 || ret.max_meter_ticks_regex_reference_safety.is_some(),
2327 "pcool_verifier_limits_from_protocol_config requires \
2328 max_meter_ticks_regex_reference_safety"
2329 );
2330 assert!(
2333 !ret.feature_flags.deny_rule_governance_on_chain
2334 || (ret.deny_rule_update_max_entries_per_tx.is_some()
2335 && ret.deny_rule_removal_grace_round_floor.is_some()),
2336 "deny_rule_governance_on_chain requires deny_rule_update_max_entries_per_tx and deny_rule_removal_grace_round_floor"
2337 );
2338 const DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING: u64 = 2048;
2346 assert!(
2347 ret.deny_rule_update_max_entries_per_tx
2348 .is_none_or(|max_entries| {
2349 max_entries > 0
2350 && max_entries <= DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING
2351 && [
2352 ret.max_num_new_move_object_ids_system_tx,
2353 ret.max_num_deleted_move_object_ids_system_tx,
2354 ret.object_runtime_max_num_cached_objects_system_tx,
2355 ret.object_runtime_max_num_store_entries_system_tx,
2356 ]
2357 .iter()
2358 .all(|limit| limit.is_none_or(|limit| max_entries <= limit))
2359 }),
2360 "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"
2361 );
2362
2363 ret
2364 }
2365
2366 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
2369 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
2370 let mut ret = Self::get_for_version_impl(version, chain);
2371 ret.version = version;
2372 Some(ret)
2373 } else {
2374 None
2375 }
2376 }
2377
2378 #[cfg(not(msim))]
2379 pub fn poison_get_for_min_version() {
2380 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
2381 }
2382
2383 #[cfg(not(msim))]
2384 fn load_poison_get_for_min_version() -> bool {
2385 POISON_VERSION_METHODS.load(Ordering::Relaxed)
2386 }
2387
2388 #[cfg(msim)]
2389 pub fn poison_get_for_min_version() {
2390 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
2391 }
2392
2393 #[cfg(msim)]
2394 fn load_poison_get_for_min_version() -> bool {
2395 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
2396 }
2397
2398 pub fn convert_type_argument_error(&self) -> bool {
2399 self.feature_flags.convert_type_argument_error
2400 }
2401
2402 pub fn get_for_min_version() -> Self {
2406 if Self::load_poison_get_for_min_version() {
2407 panic!("get_for_min_version called on validator");
2408 }
2409 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
2410 }
2411
2412 #[expect(non_snake_case)]
2423 pub fn get_for_max_version_UNSAFE() -> Self {
2424 if Self::load_poison_get_for_min_version() {
2425 panic!("get_for_max_version_UNSAFE called on validator");
2426 }
2427 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
2428 }
2429
2430 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
2431 #[cfg(msim)]
2432 {
2433 if version > ProtocolVersion::MAX {
2435 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
2436 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
2437 return config;
2438 }
2439 }
2440
2441 let mut cfg = Self {
2445 version,
2446
2447 feature_flags: Default::default(),
2448
2449 max_tx_size_bytes: Some(128 * 1024),
2450 max_input_objects: Some(2048),
2453 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
2454 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
2455 max_gas_payment_objects: Some(256),
2456 max_modules_in_publish: Some(64),
2457 max_package_dependencies: Some(32),
2458 max_arguments: Some(512),
2459 max_type_arguments: Some(16),
2460 max_type_argument_depth: Some(16),
2461 max_pure_argument_size: Some(16 * 1024),
2462 max_programmable_tx_commands: Some(1024),
2463 move_binary_format_version: Some(7),
2464 min_move_binary_format_version: Some(6),
2465 binary_module_handles: Some(100),
2466 binary_struct_handles: Some(300),
2467 binary_function_handles: Some(1500),
2468 binary_function_instantiations: Some(750),
2469 binary_signatures: Some(1000),
2470 binary_constant_pool: Some(4000),
2471 binary_identifiers: Some(10000),
2472 binary_address_identifiers: Some(100),
2473 binary_struct_defs: Some(200),
2474 binary_struct_def_instantiations: Some(100),
2475 binary_function_defs: Some(1000),
2476 binary_field_handles: Some(500),
2477 binary_field_instantiations: Some(250),
2478 binary_friend_decls: Some(100),
2479 binary_enum_defs: None,
2480 binary_enum_def_instantiations: None,
2481 binary_variant_handles: None,
2482 binary_variant_instantiation_handles: None,
2483 max_move_object_size: Some(250 * 1024),
2484 max_move_package_size: Some(100 * 1024),
2485 max_publish_or_upgrade_per_ptb: Some(5),
2486 max_auth_gas: None,
2488 max_tx_gas: Some(50_000_000_000),
2490 max_gas_price: Some(100_000),
2491 max_gas_computation_bucket: Some(5_000_000),
2492 max_loop_depth: Some(5),
2493 max_generic_instantiation_length: Some(32),
2494 max_function_parameters: Some(128),
2495 max_basic_blocks: Some(1024),
2496 max_value_stack_size: Some(1024),
2497 max_type_nodes: Some(256),
2498 max_push_size: Some(10000),
2499 max_struct_definitions: Some(200),
2500 max_function_definitions: Some(1000),
2501 max_fields_in_struct: Some(32),
2502 max_dependency_depth: Some(100),
2503 max_num_event_emit: Some(1024),
2504 max_num_new_move_object_ids: Some(2048),
2505 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
2506 max_num_deleted_move_object_ids: Some(2048),
2507 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
2508 max_num_transferred_move_object_ids: Some(2048),
2509 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
2510 max_event_emit_size: Some(250 * 1024),
2511 max_move_vector_len: Some(256 * 1024),
2512 max_type_to_layout_nodes: None,
2513 max_ptb_value_size: None,
2514
2515 max_back_edges_per_function: Some(10_000),
2516 max_back_edges_per_module: Some(10_000),
2517
2518 max_verifier_meter_ticks_per_function: Some(16_000_000),
2519
2520 max_meter_ticks_per_module: Some(16_000_000),
2521 max_meter_ticks_per_package: Some(16_000_000),
2522 max_meter_ticks_regex_reference_safety: None,
2523
2524 object_runtime_max_num_cached_objects: Some(1000),
2525 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2526 object_runtime_max_num_store_entries: Some(1000),
2527 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2528 base_tx_cost_fixed: Some(1_000),
2530 package_publish_cost_fixed: Some(1_000),
2531 base_tx_cost_per_byte: Some(0),
2532 package_publish_cost_per_byte: Some(80),
2533 obj_access_cost_read_per_byte: Some(15),
2534 obj_access_cost_mutate_per_byte: Some(40),
2535 obj_access_cost_delete_per_byte: Some(40),
2536 obj_access_cost_verify_per_byte: Some(200),
2537 obj_data_cost_refundable: Some(100),
2538 obj_metadata_cost_non_refundable: Some(50),
2539 gas_model_version: Some(1),
2540 storage_rebate_rate: Some(10000),
2541 reward_slashing_rate: Some(10000),
2543 storage_gas_price: Some(76),
2544 base_gas_price: None,
2545 validator_target_reward: Some(767_000 * 1_000_000_000),
2548 max_transactions_per_checkpoint: Some(10_000),
2549 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2550
2551 buffer_stake_for_protocol_upgrade_bps: Some(5000),
2553
2554 address_from_bytes_cost_base: Some(52),
2558 address_to_u256_cost_base: Some(52),
2560 address_from_u256_cost_base: Some(52),
2562
2563 config_read_setting_impl_cost_base: Some(100),
2566 config_read_setting_impl_cost_per_byte: Some(40),
2567
2568 dynamic_field_hash_type_and_key_cost_base: Some(100),
2572 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
2573 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
2574 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
2575 dynamic_field_add_child_object_cost_base: Some(100),
2578 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2579 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2580 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2581 dynamic_field_borrow_child_object_cost_base: Some(100),
2584 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2585 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2586 dynamic_field_remove_child_object_cost_base: Some(100),
2589 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2590 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2591 dynamic_field_has_child_object_cost_base: Some(100),
2594 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2597 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2598 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2599
2600 event_emit_cost_base: Some(52),
2603 event_emit_value_size_derivation_cost_per_byte: Some(2),
2604 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2605 event_emit_output_cost_per_byte: Some(10),
2606
2607 object_borrow_uid_cost_base: Some(52),
2610 object_delete_impl_cost_base: Some(52),
2612 object_record_new_uid_cost_base: Some(52),
2614
2615 transfer_transfer_internal_cost_base: Some(52),
2619 transfer_freeze_object_cost_base: Some(52),
2621 transfer_share_object_cost_base: Some(52),
2623 transfer_receive_object_cost_base: Some(52),
2624
2625 tx_context_derive_id_cost_base: Some(52),
2629 tx_context_fresh_id_cost_base: None,
2630 tx_context_sender_cost_base: None,
2631 tx_context_digest_cost_base: None,
2632 tx_context_epoch_cost_base: None,
2633 tx_context_epoch_timestamp_ms_cost_base: None,
2634 tx_context_sponsor_cost_base: None,
2635 tx_context_rgp_cost_base: None,
2636 tx_context_gas_price_cost_base: None,
2637 tx_context_gas_budget_cost_base: None,
2638 tx_context_ids_created_cost_base: None,
2639 tx_context_replace_cost_base: None,
2640
2641 types_is_one_time_witness_cost_base: Some(52),
2644 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2645 types_is_one_time_witness_type_cost_per_byte: Some(2),
2646
2647 validator_validate_metadata_cost_base: Some(52),
2651 validator_validate_metadata_data_cost_per_byte: Some(2),
2652
2653 crypto_invalid_arguments_cost: Some(100),
2655 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2657 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2658 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2659
2660 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2662 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2663 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2664
2665 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2667 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2668 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2669 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2670 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2671 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2672
2673 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2675
2676 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2678 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2679 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2680 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2681 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2682 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2683
2684 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2686 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2687 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2688 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2689 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2690 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2691
2692 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2694 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2695 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2696 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2697 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2698 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2699
2700 ecvrf_ecvrf_verify_cost_base: Some(52),
2702 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2703 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2704
2705 ed25519_ed25519_verify_cost_base: Some(52),
2707 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2708 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2709
2710 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2712 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2713
2714 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2716 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2717 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2718 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2719 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2720
2721 hash_blake2b256_cost_base: Some(52),
2723 hash_blake2b256_data_cost_per_byte: Some(2),
2724 hash_blake2b256_data_cost_per_block: Some(2),
2725 hash_keccak256_cost_base: Some(52),
2727 hash_keccak256_data_cost_per_byte: Some(2),
2728 hash_keccak256_data_cost_per_block: Some(2),
2729
2730 poseidon_bn254_cost_base: None,
2731 poseidon_bn254_cost_per_block: None,
2732
2733 hmac_hmac_sha3_256_cost_base: Some(52),
2735 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2736 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2737
2738 group_ops_bls12381_decode_scalar_cost: Some(52),
2740 group_ops_bls12381_decode_g1_cost: Some(52),
2741 group_ops_bls12381_decode_g2_cost: Some(52),
2742 group_ops_bls12381_decode_gt_cost: Some(52),
2743 group_ops_bls12381_scalar_add_cost: Some(52),
2744 group_ops_bls12381_g1_add_cost: Some(52),
2745 group_ops_bls12381_g2_add_cost: Some(52),
2746 group_ops_bls12381_gt_add_cost: Some(52),
2747 group_ops_bls12381_scalar_sub_cost: Some(52),
2748 group_ops_bls12381_g1_sub_cost: Some(52),
2749 group_ops_bls12381_g2_sub_cost: Some(52),
2750 group_ops_bls12381_gt_sub_cost: Some(52),
2751 group_ops_bls12381_scalar_mul_cost: Some(52),
2752 group_ops_bls12381_g1_mul_cost: Some(52),
2753 group_ops_bls12381_g2_mul_cost: Some(52),
2754 group_ops_bls12381_gt_mul_cost: Some(52),
2755 group_ops_bls12381_scalar_div_cost: Some(52),
2756 group_ops_bls12381_g1_div_cost: Some(52),
2757 group_ops_bls12381_g2_div_cost: Some(52),
2758 group_ops_bls12381_gt_div_cost: Some(52),
2759 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2760 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2761 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2762 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2763 group_ops_bls12381_g1_msm_base_cost: Some(52),
2764 group_ops_bls12381_g2_msm_base_cost: Some(52),
2765 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2766 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2767 group_ops_bls12381_msm_max_len: Some(32),
2768 group_ops_bls12381_pairing_cost: Some(52),
2769 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2770 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2771 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2772 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2773 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2774
2775 #[allow(deprecated)]
2777 check_zklogin_id_cost_base: Some(200),
2778 #[allow(deprecated)]
2779 check_zklogin_issuer_cost_base: Some(200),
2781
2782 vdf_verify_vdf_cost: None,
2783 vdf_hash_to_input_cost: None,
2784
2785 bcs_per_byte_serialized_cost: Some(2),
2786 bcs_legacy_min_output_size_cost: Some(1),
2787 bcs_failure_cost: Some(52),
2788 hash_sha2_256_base_cost: Some(52),
2789 hash_sha2_256_per_byte_cost: Some(2),
2790 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2791 hash_sha3_256_base_cost: Some(52),
2792 hash_sha3_256_per_byte_cost: Some(2),
2793 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2794 type_name_get_base_cost: Some(52),
2795 type_name_get_per_byte_cost: Some(2),
2796 string_check_utf8_base_cost: Some(52),
2797 string_check_utf8_per_byte_cost: Some(2),
2798 string_is_char_boundary_base_cost: Some(52),
2799 string_sub_string_base_cost: Some(52),
2800 string_sub_string_per_byte_cost: Some(2),
2801 string_index_of_base_cost: Some(52),
2802 string_index_of_per_byte_pattern_cost: Some(2),
2803 string_index_of_per_byte_searched_cost: Some(2),
2804 vector_empty_base_cost: Some(52),
2805 vector_length_base_cost: Some(52),
2806 vector_push_back_base_cost: Some(52),
2807 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2808 vector_borrow_base_cost: Some(52),
2809 vector_pop_back_base_cost: Some(52),
2810 vector_destroy_empty_base_cost: Some(52),
2811 vector_swap_base_cost: Some(52),
2812 debug_print_base_cost: Some(52),
2813 debug_print_stack_trace_base_cost: Some(52),
2814
2815 max_size_written_objects: Some(5 * 1000 * 1000),
2816 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2819
2820 max_move_identifier_len: Some(128),
2822 max_move_value_depth: Some(128),
2823 max_move_enum_variants: None,
2824
2825 gas_rounding_step: Some(1_000),
2826
2827 execution_version: Some(1),
2828
2829 max_event_emit_size_total: Some(
2832 256 * 250 * 1024, ),
2834
2835 consensus_bad_nodes_stake_threshold: Some(20),
2842
2843 #[allow(deprecated)]
2845 max_jwk_votes_per_validator_per_epoch: Some(240),
2846
2847 #[allow(deprecated)]
2848 max_age_of_jwk_in_epochs: Some(1),
2849
2850 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2854
2855 random_beacon_reduction_allowed_delta: Some(800),
2856
2857 random_beacon_reduction_lower_bound: Some(1000),
2858 random_beacon_dkg_timeout_round: Some(3000),
2859 random_beacon_min_round_interval_ms: Some(500),
2860
2861 random_beacon_dkg_version: Some(1),
2862
2863 consensus_max_num_transactions_in_block: Some(512),
2867
2868 max_deferral_rounds_for_congestion_control: Some(10),
2869
2870 min_checkpoint_interval_ms: Some(200),
2871
2872 checkpoint_rate_window_size: None,
2873
2874 checkpoint_summary_version_specific_data: Some(1),
2875
2876 max_soft_bundle_size: Some(5),
2877
2878 bridge_should_try_to_finalize_committee: None,
2879
2880 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2881
2882 max_committee_members_count: None,
2883 deny_rule_update_max_entries_per_tx: None,
2884 deny_rule_removal_grace_round_floor: None,
2885
2886 consensus_gc_depth: None,
2887
2888 consensus_max_acknowledgments_per_block: None,
2889
2890 max_congestion_limit_overshoot_per_commit: None,
2891
2892 max_concurrent_execution_workers: None,
2893
2894 scorer_version: None,
2895
2896 auth_context_digest_cost_base: None,
2898 auth_context_tx_data_bytes_cost_base: None,
2899 auth_context_tx_data_bytes_cost_per_byte: None,
2900 auth_context_tx_commands_cost_base: None,
2901 auth_context_tx_commands_cost_per_byte: None,
2902 auth_context_tx_inputs_cost_base: None,
2903 auth_context_tx_inputs_cost_per_byte: None,
2904 auth_context_replace_cost_base: None,
2905 auth_context_replace_cost_per_byte: None,
2906 auth_context_authenticator_function_info_v1_cost_base: None,
2907 consensus_commits_per_schedule: None,
2908 min_validator_count: None,
2909 max_validator_count: None,
2910 min_validator_joining_stake: None,
2911 validator_low_stake_threshold: None,
2912 validator_very_low_stake_threshold: None,
2913 validator_low_stake_grace_period: None,
2914 consensus_leader_schedule_window_size: None,
2915
2916 max_move_system_package_size: None,
2917 };
2920
2921 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2922
2923 {
2925 cfg.feature_flags
2926 .disable_invariant_violation_check_in_swap_loc = true;
2927 cfg.feature_flags.no_extraneous_module_bytes = true;
2928 cfg.feature_flags.hardened_otw_check = true;
2929 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2930 }
2931
2932 {
2934 #[allow(deprecated)]
2935 {
2936 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2937 }
2938 }
2939
2940 #[expect(deprecated)]
2944 {
2945 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2946 }
2947 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2949
2950 cfg.feature_flags.per_object_congestion_control_mode =
2951 PerObjectCongestionControlMode::TotalTxCount;
2952
2953 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2955
2956 if chain != Chain::Mainnet && chain != Chain::Testnet {
2958 cfg.feature_flags.enable_poseidon = true;
2959 cfg.poseidon_bn254_cost_base = Some(260);
2960 cfg.poseidon_bn254_cost_per_block = Some(10);
2961
2962 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2963
2964 cfg.feature_flags.enable_vdf = true;
2965 cfg.vdf_verify_vdf_cost = Some(1500);
2968 cfg.vdf_hash_to_input_cost = Some(100);
2969
2970 cfg.feature_flags.passkey_auth = true;
2971 }
2972
2973 for cur in 2..=version.0 {
2974 match cur {
2975 1 => unreachable!(),
2976 2 => {}
2978 3 => {
2979 cfg.feature_flags.relocate_event_module = true;
2980 }
2981 4 => {
2982 cfg.max_type_to_layout_nodes = Some(512);
2983 }
2984 5 => {
2985 cfg.feature_flags.protocol_defined_base_fee = true;
2986 cfg.base_gas_price = Some(1000);
2987
2988 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2989 cfg.feature_flags.convert_type_argument_error = true;
2990 cfg.feature_flags.native_charging_v2 = true;
2991
2992 if chain != Chain::Mainnet && chain != Chain::Testnet {
2993 cfg.feature_flags.uncompressed_g1_group_elements = true;
2994 }
2995
2996 cfg.gas_model_version = Some(2);
2997
2998 cfg.poseidon_bn254_cost_per_block = Some(388);
2999
3000 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
3001 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
3002 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
3003 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
3004 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
3005 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
3006 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
3007 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
3008
3009 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
3011 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
3012 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
3013 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
3014
3015 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
3016 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
3017 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
3018 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
3019 Some(8213);
3020 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
3021 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
3022 Some(9484);
3023
3024 cfg.hash_keccak256_cost_base = Some(10);
3025 cfg.hash_blake2b256_cost_base = Some(10);
3026
3027 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
3029 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
3030 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
3031 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
3032
3033 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
3034 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
3035 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
3036 cfg.group_ops_bls12381_gt_add_cost = Some(188);
3037
3038 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
3039 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
3040 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
3041 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
3042
3043 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
3044 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
3045 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
3046 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
3047
3048 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
3049 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
3050 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
3051 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
3052
3053 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
3054 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
3055
3056 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
3057 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
3058 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
3059 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
3060
3061 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
3062 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
3063 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
3064 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
3065 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
3066
3067 cfg.group_ops_bls12381_pairing_cost = Some(26897);
3068
3069 cfg.validator_validate_metadata_cost_base = Some(20000);
3070
3071 cfg.max_committee_members_count = Some(50);
3072 }
3073 6 => {
3074 cfg.max_ptb_value_size = Some(1024 * 1024);
3075 }
3076 7 => {
3077 }
3080 8 => {
3081 cfg.feature_flags.variant_nodes = true;
3082
3083 if chain != Chain::Mainnet {
3084 cfg.feature_flags.consensus_round_prober = true;
3086 cfg.feature_flags
3088 .consensus_distributed_vote_scoring_strategy = true;
3089 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
3090 cfg.feature_flags.consensus_smart_ancestor_selection = true;
3092 cfg.feature_flags
3094 .consensus_round_prober_probe_accepted_rounds = true;
3095 cfg.feature_flags.consensus_zstd_compression = true;
3097 cfg.consensus_gc_depth = Some(60);
3101 }
3102
3103 if chain != Chain::Testnet && chain != Chain::Mainnet {
3106 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
3107 }
3108 }
3109 9 => {
3110 if chain != Chain::Mainnet {
3111 cfg.feature_flags.consensus_smart_ancestor_selection = false;
3113 }
3114
3115 cfg.feature_flags.consensus_zstd_compression = true;
3117
3118 if chain != Chain::Testnet && chain != Chain::Mainnet {
3120 cfg.feature_flags.accept_passkey_in_multisig = true;
3121 }
3122
3123 cfg.bridge_should_try_to_finalize_committee = None;
3125 }
3126 10 => {
3127 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
3130
3131 cfg.max_committee_members_count = Some(80);
3133
3134 cfg.feature_flags.consensus_round_prober = true;
3136 cfg.feature_flags
3138 .consensus_round_prober_probe_accepted_rounds = true;
3139 cfg.feature_flags
3141 .consensus_distributed_vote_scoring_strategy = true;
3142 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
3144
3145 cfg.consensus_gc_depth = Some(60);
3150
3151 cfg.feature_flags.minimize_child_object_mutations = true;
3153
3154 if chain != Chain::Mainnet {
3155 cfg.feature_flags.consensus_batched_block_sync = true;
3157 }
3158
3159 if chain != Chain::Testnet && chain != Chain::Mainnet {
3160 cfg.feature_flags
3163 .congestion_control_gas_price_feedback_mechanism = true;
3164 }
3165
3166 cfg.feature_flags.validate_identifier_inputs = true;
3167 cfg.feature_flags.dependency_linkage_error = true;
3168 cfg.feature_flags.additional_multisig_checks = true;
3169 }
3170 11 => {
3171 }
3174 12 => {
3175 cfg.feature_flags
3178 .congestion_control_gas_price_feedback_mechanism = true;
3179
3180 cfg.feature_flags.normalize_ptb_arguments = true;
3182 }
3183 13 => {
3184 cfg.feature_flags.select_committee_from_eligible_validators = true;
3187 cfg.feature_flags.track_non_committee_eligible_validators = true;
3190
3191 if chain != Chain::Testnet && chain != Chain::Mainnet {
3192 cfg.feature_flags
3195 .select_committee_supporting_next_epoch_version = true;
3196 }
3197 }
3198 14 => {
3199 cfg.feature_flags.consensus_batched_block_sync = true;
3201
3202 if chain != Chain::Mainnet {
3203 cfg.feature_flags
3206 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3207 cfg.feature_flags
3211 .select_committee_supporting_next_epoch_version = true;
3212 }
3213 if chain != Chain::Testnet && chain != Chain::Mainnet {
3214 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3216 }
3217 }
3218 15 => {
3219 if chain != Chain::Mainnet && chain != Chain::Testnet {
3220 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3224 }
3225 }
3226 16 => {
3227 cfg.feature_flags
3230 .select_committee_supporting_next_epoch_version = true;
3231 cfg.feature_flags
3233 .consensus_commit_transactions_only_for_traversed_headers = true;
3234 }
3235 17 => {
3236 cfg.max_committee_members_count = Some(100);
3238 }
3239 18 => {
3240 if chain != Chain::Mainnet {
3241 cfg.feature_flags.passkey_auth = true;
3243 }
3244 }
3245 19 => {
3246 if chain != Chain::Testnet && chain != Chain::Mainnet {
3247 cfg.feature_flags
3250 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3251 cfg.feature_flags
3254 .separate_gas_price_feedback_mechanism_for_randomness = true;
3255 cfg.feature_flags.metadata_in_module_bytes = true;
3258 cfg.feature_flags.publish_package_metadata = true;
3259 cfg.feature_flags.enable_move_authentication = true;
3261 cfg.max_auth_gas = Some(250_000_000);
3263 cfg.transfer_receive_object_cost_base = Some(100);
3266 cfg.feature_flags.adjust_rewards_by_score = true;
3268 }
3269
3270 if chain != Chain::Mainnet {
3271 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3273
3274 cfg.feature_flags.calculate_validator_scores = true;
3276 cfg.scorer_version = Some(1);
3277 }
3278
3279 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
3281
3282 cfg.feature_flags.passkey_auth = true;
3284 }
3285 20 => {
3286 if chain != Chain::Testnet && chain != Chain::Mainnet {
3287 cfg.feature_flags
3289 .pass_calculated_validator_scores_to_advance_epoch = true;
3290 }
3291 }
3292 21 => {
3293 if chain != Chain::Testnet && chain != Chain::Mainnet {
3294 cfg.feature_flags.consensus_fast_commit_sync = true;
3296 }
3297 if chain != Chain::Mainnet {
3298 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3303 cfg.feature_flags
3306 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3307 cfg.feature_flags
3310 .separate_gas_price_feedback_mechanism_for_randomness = true;
3311 }
3312
3313 cfg.auth_context_digest_cost_base = Some(30);
3314 cfg.auth_context_tx_commands_cost_base = Some(30);
3315 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
3316 cfg.auth_context_tx_inputs_cost_base = Some(30);
3317 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
3318 cfg.auth_context_replace_cost_base = Some(30);
3319 cfg.auth_context_replace_cost_per_byte = Some(2);
3320
3321 if chain != Chain::Testnet && chain != Chain::Mainnet {
3322 cfg.max_auth_gas = Some(250_000);
3324 }
3325 }
3326 22 => {
3327 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3332 cfg.feature_flags
3335 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3336 cfg.feature_flags
3339 .separate_gas_price_feedback_mechanism_for_randomness = true;
3340
3341 if chain != Chain::Mainnet {
3342 cfg.feature_flags.metadata_in_module_bytes = true;
3345 cfg.feature_flags.publish_package_metadata = true;
3346 cfg.feature_flags.enable_move_authentication = true;
3348 cfg.max_auth_gas = Some(250_000);
3350 cfg.transfer_receive_object_cost_base = Some(100);
3353 }
3354
3355 if chain != Chain::Mainnet {
3356 cfg.feature_flags.consensus_fast_commit_sync = true;
3358 }
3359 }
3360 23 => {
3361 cfg.feature_flags.move_native_tx_context = true;
3363 cfg.tx_context_fresh_id_cost_base = Some(52);
3364 cfg.tx_context_sender_cost_base = Some(30);
3365 cfg.tx_context_digest_cost_base = Some(30);
3366 cfg.tx_context_epoch_cost_base = Some(30);
3367 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
3368 cfg.tx_context_sponsor_cost_base = Some(30);
3369 cfg.tx_context_rgp_cost_base = Some(30);
3370 cfg.tx_context_gas_price_cost_base = Some(30);
3371 cfg.tx_context_gas_budget_cost_base = Some(30);
3372 cfg.tx_context_ids_created_cost_base = Some(30);
3373 cfg.tx_context_replace_cost_base = Some(30);
3374 }
3375 24 => {
3376 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3378
3379 if chain != Chain::Testnet && chain != Chain::Mainnet {
3380 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3382 }
3383
3384 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
3387 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
3388
3389 cfg.feature_flags.additional_borrow_checks = true;
3391 }
3392 #[allow(deprecated)]
3393 25 => {
3394 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
3397 cfg.check_zklogin_id_cost_base = None;
3398 cfg.check_zklogin_issuer_cost_base = None;
3399 cfg.max_jwk_votes_per_validator_per_epoch = None;
3400 cfg.max_age_of_jwk_in_epochs = None;
3401 }
3402 26 => {
3403 }
3406 27 => {
3407 if chain != Chain::Mainnet {
3408 cfg.feature_flags.consensus_block_restrictions = true;
3411 }
3412
3413 if chain != Chain::Testnet && chain != Chain::Mainnet {
3414 cfg.feature_flags
3416 .pre_consensus_sponsor_only_move_authentication = true;
3417 }
3418 }
3419 28 => {
3420 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
3425
3426 cfg.feature_flags.metadata_in_module_bytes = true;
3429 cfg.feature_flags.publish_package_metadata = true;
3430 cfg.feature_flags.enable_move_authentication = true;
3432 cfg.transfer_receive_object_cost_base = Some(100);
3435
3436 if chain != Chain::Unknown {
3437 cfg.max_auth_gas = Some(20_000);
3439 }
3440
3441 if chain != Chain::Mainnet {
3442 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3444 cfg.feature_flags
3446 .pre_consensus_sponsor_only_move_authentication = true;
3447 }
3448 }
3449 29 => {
3450 cfg.feature_flags.always_advance_dkg_to_resolution = true;
3456
3457 cfg.feature_flags
3460 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3461
3462 cfg.feature_flags.consensus_fast_commit_sync = true;
3464 cfg.feature_flags.consensus_block_restrictions = true;
3468 }
3469 30 => {
3470 }
3478 31 => {
3479 cfg.feature_flags.validator_metadata_verify_v2 = true;
3480
3481 if chain != Chain::Mainnet && chain != Chain::Testnet {
3482 cfg.checkpoint_rate_window_size = Some(20);
3485 cfg.feature_flags
3488 .package_metadata_with_dynamic_module_metadata = true;
3489 cfg.feature_flags.consensus_starfish_speed = true;
3492 }
3493
3494 cfg.feature_flags.report_move_authentication_error = true;
3495 }
3496 32 => {
3497 cfg.min_validator_count = Some(4);
3501 cfg.max_validator_count = Some(150);
3502 cfg.min_validator_joining_stake = Some(2_000_000_000_000_000);
3503 cfg.validator_low_stake_threshold = Some(1_500_000_000_000_000);
3504 cfg.validator_very_low_stake_threshold = Some(1_000_000_000_000_000);
3505 cfg.validator_low_stake_grace_period = Some(7);
3506
3507 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3509 cfg.feature_flags
3511 .pre_consensus_sponsor_only_move_authentication = true;
3512
3513 if chain != Chain::Mainnet {
3514 cfg.feature_flags.consensus_starfish_speed = true;
3517 cfg.checkpoint_rate_window_size = Some(20);
3520 cfg.feature_flags
3523 .package_metadata_with_dynamic_module_metadata = true;
3524 }
3525
3526 if chain != Chain::Mainnet && chain != Chain::Testnet {
3527 cfg.feature_flags
3531 .consensus_enable_sliding_window_leader_schedule = true;
3532 cfg.feature_flags
3533 .consensus_enable_absolute_score_leader_schedule = true;
3534 cfg.feature_flags.enable_pcool_flow = true;
3538 }
3539 }
3540 33 => {
3541 cfg.checkpoint_rate_window_size = Some(20);
3544 if chain != Chain::Mainnet {
3548 cfg.feature_flags
3549 .consensus_enable_sliding_window_leader_schedule = true;
3550 cfg.feature_flags
3551 .consensus_enable_absolute_score_leader_schedule = true;
3552 }
3553 }
3554 34 => {
3555 if chain != Chain::Testnet && chain != Chain::Mainnet {
3556 cfg.scorer_version = Some(2);
3560 }
3561 cfg.feature_flags.pcool_skip_immutable_object_locks = true;
3565
3566 if chain == Chain::Mainnet {
3567 cfg.feature_flags.enable_move_authentication_for_sponsor = false;
3569 cfg.feature_flags
3572 .pre_consensus_sponsor_only_move_authentication = false;
3573 }
3574 }
3575 35 => {
3576 cfg.feature_flags.max_ptb_value_size_v2 = true;
3578 cfg.feature_flags.allow_unbounded_system_objects = true;
3580
3581 cfg.feature_flags.consensus_starfish_speed = true;
3584
3585 cfg.max_verifier_meter_ticks_per_function = Some(2_200_000);
3592 cfg.max_meter_ticks_per_module = Some(2_200_000);
3593 cfg.max_meter_ticks_per_package = Some(2_200_000);
3594 cfg.max_meter_ticks_regex_reference_safety = Some(2_200_000);
3595 cfg.feature_flags.pcool_verifier_limits_from_protocol_config = true;
3596 cfg.feature_flags
3599 .package_metadata_with_dynamic_module_metadata = true;
3600 cfg.feature_flags
3604 .consensus_enable_sliding_window_leader_schedule = true;
3605 cfg.feature_flags
3606 .consensus_enable_absolute_score_leader_schedule = true;
3607
3608 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3611 cfg.feature_flags
3614 .pre_consensus_sponsor_only_move_authentication = false;
3615 }
3616 36 => {
3617 cfg.feature_flags.reject_immutable_account_objects = true;
3620 }
3621 37 => {
3622 cfg.feature_flags.validate_input_object_versions = true;
3626 cfg.feature_flags.disallow_self_identifier = true;
3627 cfg.max_move_enum_variants = Some(move_core_types::VARIANT_COUNT_MAX);
3628 cfg.feature_flags.deny_authenticator_packages = true;
3631 cfg.feature_flags.check_canonical_module_version_header = true;
3634 cfg.feature_flags.disallow_randomness_in_move_authenticator = true;
3639 cfg.feature_flags.check_cyclic_dependencies = true;
3642 }
3643 38 => {
3644 cfg.max_move_system_package_size = Some(200 * 1024);
3651 cfg.feature_flags.reject_immutable_account_creation = true;
3654
3655 cfg.feature_flags.validate_ptb_argument_indices = true;
3656 }
3657 _ => panic!("unsupported version {version:?}"),
3668 }
3669 }
3670 cfg
3671 }
3672
3673 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
3679 let (
3680 max_back_edges_per_function,
3681 max_back_edges_per_module,
3682 sanity_check_with_regex_reference_safety,
3683 ) = if let Some((
3684 max_back_edges_per_function,
3685 max_back_edges_per_module,
3686 sanity_check_with_regex_reference_safety,
3687 )) = signing_limits
3688 {
3689 (
3690 Some(max_back_edges_per_function),
3691 Some(max_back_edges_per_module),
3692 Some(sanity_check_with_regex_reference_safety),
3693 )
3694 } else {
3695 (None, None, None)
3696 };
3697
3698 let additional_borrow_checks = if signing_limits.is_some() {
3699 true
3702 } else {
3703 self.additional_borrow_checks()
3704 };
3705
3706 VerifierConfig {
3707 max_loop_depth: Some(self.max_loop_depth() as usize),
3708 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
3709 max_function_parameters: Some(self.max_function_parameters() as usize),
3710 max_basic_blocks: Some(self.max_basic_blocks() as usize),
3711 max_value_stack_size: self.max_value_stack_size() as usize,
3712 max_type_nodes: Some(self.max_type_nodes() as usize),
3713 max_push_size: Some(self.max_push_size() as usize),
3714 max_dependency_depth: Some(self.max_dependency_depth() as usize),
3715 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
3716 max_function_definitions: Some(self.max_function_definitions() as usize),
3717 max_data_definitions: Some(self.max_struct_definitions() as usize),
3718 max_constant_vector_len: Some(self.max_move_vector_len()),
3719 max_back_edges_per_function,
3720 max_back_edges_per_module,
3721 max_basic_blocks_in_script: None,
3722 max_identifier_len: self.max_move_identifier_len_as_option(), disallow_self_identifier: self.feature_flags.disallow_self_identifier,
3726 bytecode_version: self.move_binary_format_version(),
3727 max_variants_in_enum: self.max_move_enum_variants_as_option(),
3728 additional_borrow_checks,
3729 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
3730 .map(|limit| limit as u128),
3731 check_cyclic_dependencies: self.feature_flags.check_cyclic_dependencies,
3732 }
3733 }
3734
3735 pub fn verifier_signing_limits(&self) -> (usize, usize, usize) {
3742 (
3743 self.max_back_edges_per_function() as usize,
3744 self.max_back_edges_per_module() as usize,
3745 self.max_meter_ticks_regex_reference_safety() as usize,
3746 )
3747 }
3748
3749 pub fn meter_config(&self) -> MeterConfig {
3753 MeterConfig {
3754 max_per_fun_meter_units: Some(self.max_verifier_meter_ticks_per_function() as u128),
3755 max_per_mod_meter_units: Some(self.max_meter_ticks_per_module() as u128),
3756 max_per_pkg_meter_units: Some(self.max_meter_ticks_per_package() as u128),
3757 }
3758 }
3759
3760 pub fn apply_overrides_for_testing(
3765 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
3766 ) -> OverrideGuard {
3767 CONFIG_OVERRIDE.with(|ovr| {
3768 let mut cur = ovr.borrow_mut();
3769 assert!(cur.is_none(), "config override already present");
3770 *cur = Some(Box::new(override_fn));
3771 OverrideGuard
3772 })
3773 }
3774}
3775
3776impl ProtocolConfig {
3781 pub fn set_per_object_congestion_control_mode_for_testing(
3782 &mut self,
3783 val: PerObjectCongestionControlMode,
3784 ) {
3785 self.feature_flags.per_object_congestion_control_mode = val;
3786 }
3787
3788 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
3789 self.feature_flags.consensus_choice = val;
3790 }
3791
3792 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
3793 self.feature_flags.consensus_network = val;
3794 }
3795
3796 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
3797 self.feature_flags.passkey_auth = val
3798 }
3799
3800 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
3801 self.feature_flags
3802 .disallow_new_modules_in_deps_only_packages = val;
3803 }
3804
3805 pub fn set_check_canonical_module_version_header_for_testing(&mut self, val: bool) {
3806 self.feature_flags.check_canonical_module_version_header = val;
3807 }
3808
3809 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
3810 self.feature_flags.consensus_round_prober = val;
3811 }
3812
3813 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
3814 self.feature_flags
3815 .consensus_distributed_vote_scoring_strategy = val;
3816 }
3817
3818 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
3819 self.consensus_gc_depth = Some(val);
3820 }
3821
3822 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
3823 self.feature_flags.consensus_linearize_subdag_v2 = val;
3824 }
3825
3826 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
3827 self.feature_flags
3828 .consensus_round_prober_probe_accepted_rounds = val;
3829 }
3830
3831 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
3832 self.feature_flags.accept_passkey_in_multisig = val;
3833 }
3834
3835 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
3836 self.feature_flags.consensus_smart_ancestor_selection = val;
3837 }
3838
3839 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
3840 self.feature_flags.consensus_batched_block_sync = val;
3841 }
3842
3843 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
3844 self.feature_flags
3845 .congestion_control_min_free_execution_slot = val;
3846 }
3847
3848 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
3849 self.feature_flags
3850 .congestion_control_gas_price_feedback_mechanism = val;
3851 }
3852
3853 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
3854 self.feature_flags.select_committee_from_eligible_validators = val;
3855 }
3856
3857 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
3858 self.feature_flags.track_non_committee_eligible_validators = val;
3859 }
3860
3861 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
3862 self.feature_flags
3863 .select_committee_supporting_next_epoch_version = val;
3864 }
3865
3866 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
3867 &mut self,
3868 val: bool,
3869 ) {
3870 self.feature_flags
3871 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3872 }
3873
3874 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3875 &mut self,
3876 val: bool,
3877 ) {
3878 self.feature_flags
3879 .consensus_commit_transactions_only_for_traversed_headers = val;
3880 }
3881
3882 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3883 &mut self,
3884 val: bool,
3885 ) {
3886 self.feature_flags
3887 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3888 }
3889
3890 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3891 &mut self,
3892 val: bool,
3893 ) {
3894 self.feature_flags
3895 .separate_gas_price_feedback_mechanism_for_randomness = val;
3896 }
3897
3898 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3899 self.feature_flags.metadata_in_module_bytes = val;
3900 }
3901
3902 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3903 self.feature_flags.publish_package_metadata = val;
3904 }
3905
3906 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3907 self.feature_flags.enable_move_authentication = val;
3908 }
3909
3910 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3911 self.feature_flags.enable_move_authentication_for_sponsor = val;
3912 }
3913
3914 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3915 self.feature_flags.consensus_fast_commit_sync = val;
3916 }
3917
3918 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3919 self.feature_flags.consensus_block_restrictions = val;
3920 }
3921
3922 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3923 self.feature_flags
3924 .pre_consensus_sponsor_only_move_authentication = val;
3925 }
3926
3927 pub fn set_consensus_starfish_speed_for_testing(&mut self, val: bool) {
3928 self.feature_flags.consensus_starfish_speed = val;
3929 }
3930
3931 pub fn set_always_advance_dkg_to_resolution_for_testing(&mut self, val: bool) {
3932 self.feature_flags.always_advance_dkg_to_resolution = val;
3933 }
3934
3935 pub fn set_enable_pcool_flow_for_testing(&mut self, val: bool) {
3936 self.feature_flags.enable_pcool_flow = val;
3937 }
3938
3939 pub fn set_pcool_skip_immutable_object_locks_for_testing(&mut self, val: bool) {
3940 self.feature_flags.pcool_skip_immutable_object_locks = val;
3941 }
3942
3943 pub fn set_pcool_verifier_limits_from_protocol_config_for_testing(&mut self, val: bool) {
3944 self.feature_flags
3945 .pcool_verifier_limits_from_protocol_config = val;
3946 }
3947
3948 pub fn set_reject_immutable_account_objects_for_testing(&mut self, val: bool) {
3949 self.feature_flags.reject_immutable_account_objects = val;
3950 }
3951
3952 pub fn set_reject_immutable_account_creation_for_testing(&mut self, val: bool) {
3953 self.feature_flags.reject_immutable_account_creation = val;
3954 }
3955
3956 pub fn set_validate_input_object_versions_for_testing(&mut self, val: bool) {
3957 self.feature_flags.validate_input_object_versions = val;
3958 }
3959
3960 pub fn set_disallow_randomness_in_move_authenticator_for_testing(&mut self, val: bool) {
3961 self.feature_flags.disallow_randomness_in_move_authenticator = val;
3962 }
3963
3964 pub fn set_commits_per_schedule_for_testing(&mut self, val: u32) {
3965 self.consensus_commits_per_schedule = Some(val);
3966 }
3967
3968 pub fn set_deny_rule_governance_for_testing(&mut self, val: bool) {
3969 self.feature_flags.deny_rule_governance = val;
3970 }
3971
3972 pub fn set_deny_authenticator_packages_for_testing(&mut self, val: bool) {
3973 self.feature_flags.deny_authenticator_packages = val;
3974 }
3975
3976 pub fn set_deny_rule_governance_on_chain_for_testing(&mut self, val: bool) {
3977 self.feature_flags.deny_rule_governance_on_chain = val;
3978 }
3979
3980 pub fn set_calculate_validator_scores_for_testing(&mut self, val: bool) {
3985 self.feature_flags.calculate_validator_scores = val;
3986 if val {
3987 self.scorer_version.get_or_insert(1);
3988 } else {
3989 self.feature_flags.adjust_rewards_by_score = false;
3990 self.feature_flags
3991 .pass_calculated_validator_scores_to_advance_epoch = false;
3992 }
3993 }
3994
3995 pub fn set_package_metadata_with_dynamic_module_metadata_for_testing(&mut self, val: bool) {
3996 self.feature_flags
3997 .package_metadata_with_dynamic_module_metadata = val;
3998 }
3999
4000 pub fn set_report_move_authentication_error_for_testing(&mut self, val: bool) {
4001 self.feature_flags.report_move_authentication_error = val;
4002 }
4003
4004 pub fn set_leader_schedule_window_size_for_testing(&mut self, val: u32) {
4005 self.consensus_leader_schedule_window_size = Some(val);
4006 }
4007
4008 pub fn set_consensus_enable_sliding_window_leader_schedule_for_testing(&mut self, val: bool) {
4009 self.feature_flags
4010 .consensus_enable_sliding_window_leader_schedule = val;
4011 }
4012
4013 pub fn set_consensus_enable_absolute_score_leader_schedule_for_testing(&mut self, val: bool) {
4014 self.feature_flags
4015 .consensus_enable_absolute_score_leader_schedule = val;
4016 }
4017}
4018
4019type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
4020
4021thread_local! {
4022 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
4023}
4024
4025#[must_use]
4026pub struct OverrideGuard;
4027
4028impl Drop for OverrideGuard {
4029 fn drop(&mut self) {
4030 info!("restoring override fn");
4031 CONFIG_OVERRIDE.with(|ovr| {
4032 *ovr.borrow_mut() = None;
4033 });
4034 }
4035}
4036
4037#[derive(PartialEq, Eq)]
4041pub enum LimitThresholdCrossed {
4042 None,
4043 Soft(u128, u128),
4044 Hard(u128, u128),
4045}
4046
4047pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
4050 x: T,
4051 soft_limit: U,
4052 hard_limit: V,
4053) -> LimitThresholdCrossed {
4054 let x: V = x.into();
4055 let soft_limit: V = soft_limit.into();
4056
4057 debug_assert!(soft_limit <= hard_limit);
4058
4059 if x >= hard_limit {
4062 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
4063 } else if x < soft_limit {
4064 LimitThresholdCrossed::None
4065 } else {
4066 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
4067 }
4068}
4069
4070#[macro_export]
4071macro_rules! check_limit {
4072 ($x:expr, $hard:expr) => {
4073 check_limit!($x, $hard, $hard)
4074 };
4075 ($x:expr, $soft:expr, $hard:expr) => {
4076 check_limit_in_range($x as u64, $soft, $hard)
4077 };
4078}
4079
4080#[macro_export]
4084macro_rules! check_limit_by_meter {
4085 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
4086 let (h, metered_str) = if $is_metered {
4088 ($metered_limit, "metered")
4089 } else {
4090 ($unmetered_hard_limit, "unmetered")
4092 };
4093 use iota_protocol_config::check_limit_in_range;
4094 let result = check_limit_in_range($x as u64, $metered_limit, h);
4095 match result {
4096 LimitThresholdCrossed::None => {}
4097 LimitThresholdCrossed::Soft(_, _) => {
4098 $metric.with_label_values(&[metered_str, "soft"]).inc();
4099 }
4100 LimitThresholdCrossed::Hard(_, _) => {
4101 $metric.with_label_values(&[metered_str, "hard"]).inc();
4102 }
4103 };
4104 result
4105 }};
4106}
4107
4108#[cfg(all(test, not(msim)))]
4109mod test {
4110 use insta::assert_yaml_snapshot;
4111
4112 use super::*;
4113
4114 #[test]
4115 fn snapshot_tests() {
4116 println!("\n============================================================================");
4117 println!("! !");
4118 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
4119 println!("! !");
4120 println!("============================================================================\n");
4121 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
4122 let chain_str = match chain_id {
4127 Chain::Unknown => "".to_string(),
4128 _ => format!("{chain_id:?}_"),
4129 };
4130 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
4131 let cur = ProtocolVersion::new(i);
4132 assert_yaml_snapshot!(
4133 format!("{}version_{}", chain_str, cur.as_u64()),
4134 ProtocolConfig::get_for_version(cur, *chain_id)
4135 );
4136 }
4137 }
4138 }
4139
4140 #[test]
4141 fn test_getters() {
4142 let prot: ProtocolConfig =
4143 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4144 assert_eq!(
4145 prot.max_arguments(),
4146 prot.max_arguments_as_option().unwrap()
4147 );
4148 }
4149
4150 #[test]
4151 fn test_setters() {
4152 let mut prot: ProtocolConfig =
4153 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4154 prot.set_max_arguments_for_testing(123);
4155 assert_eq!(prot.max_arguments(), 123);
4156
4157 prot.set_max_arguments_from_str_for_testing("321".to_string());
4158 assert_eq!(prot.max_arguments(), 321);
4159
4160 prot.disable_max_arguments_for_testing();
4161 assert_eq!(prot.max_arguments_as_option(), None);
4162
4163 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
4164 assert_eq!(prot.max_arguments(), 456);
4165 }
4166
4167 #[test]
4168 fn reject_immutable_account_creation_implies_rejecting_the_objects() {
4169 for chain in [Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
4170 for version in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
4171 ProtocolConfig::get_for_version(ProtocolVersion::new(version), chain)
4174 .reject_immutable_account_creation();
4175 }
4176 }
4177 }
4178
4179 #[test]
4180 #[should_panic(expected = "unsupported version")]
4181 fn max_version_test() {
4182 let _ = ProtocolConfig::get_for_version_impl(
4185 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
4186 Chain::Unknown,
4187 );
4188 }
4189
4190 #[test]
4191 fn lookup_by_string_test() {
4192 let prot: ProtocolConfig =
4193 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
4194 assert!(prot.lookup_attr("some random string".to_string()).is_none());
4196
4197 assert!(
4198 prot.lookup_attr("max_arguments".to_string())
4199 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
4200 );
4201
4202 assert!(
4204 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
4205 .is_none()
4206 );
4207 assert!(
4208 prot.attr_map()
4209 .get("poseidon_bn254_cost_base")
4210 .unwrap()
4211 .is_none()
4212 );
4213
4214 let prot: ProtocolConfig =
4216 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4217
4218 assert!(
4219 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
4220 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
4221 );
4222 assert!(
4223 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
4224 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
4225 );
4226
4227 let prot: ProtocolConfig =
4229 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
4230 assert!(
4232 prot.feature_flags
4233 .lookup_attr("some random string".to_owned())
4234 .is_none()
4235 );
4236 assert!(
4237 !prot
4238 .feature_flags
4239 .attr_map()
4240 .contains_key("some random string")
4241 );
4242
4243 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
4245 assert!(
4246 prot.feature_flags
4247 .attr_map()
4248 .get("enable_poseidon")
4249 .unwrap()
4250 == &false
4251 );
4252 let prot: ProtocolConfig =
4253 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
4254 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
4256 assert!(
4257 prot.feature_flags
4258 .attr_map()
4259 .get("enable_poseidon")
4260 .unwrap()
4261 == &true
4262 );
4263 }
4264
4265 #[test]
4269 #[should_panic(expected = "deny_rule_update_max_entries_per_tx must be positive")]
4270 fn deny_rule_chunk_limit_above_the_ceiling_is_rejected() {
4271 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
4272 config.set_deny_rule_governance_for_testing(true);
4273 config.set_deny_rule_governance_on_chain_for_testing(true);
4274 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
4275 config.set_deny_rule_update_max_entries_per_tx_for_testing(2048 + 1);
4276 config
4277 });
4278 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
4279 }
4280
4281 #[test]
4284 #[should_panic(expected = "deny_rule_update_max_entries_per_tx must be positive")]
4285 fn deny_rule_chunk_limit_of_zero_is_rejected() {
4286 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
4287 config.set_deny_rule_governance_for_testing(true);
4288 config.set_deny_rule_governance_on_chain_for_testing(true);
4289 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
4290 config.set_deny_rule_update_max_entries_per_tx_for_testing(0);
4291 config
4292 });
4293 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
4294 }
4295
4296 #[test]
4298 fn deny_rule_chunk_limit_within_system_tx_object_id_limit_is_accepted() {
4299 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
4300 config.set_deny_rule_governance_for_testing(true);
4301 config.set_deny_rule_governance_on_chain_for_testing(true);
4302 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
4303 config.set_deny_rule_update_max_entries_per_tx_for_testing(1000);
4304 config
4305 });
4306 let config = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
4307 assert_eq!(config.deny_rule_update_max_entries_per_tx(), 1000);
4308 }
4309
4310 #[test]
4311 fn limit_range_fn_test() {
4312 let low = 100u32;
4313 let high = 10000u64;
4314
4315 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
4316 assert!(matches!(
4317 check_limit!(255u16, low, high),
4318 LimitThresholdCrossed::Soft(255u128, 100)
4319 ));
4320 assert!(matches!(
4327 check_limit!(2550000u64, low, high),
4328 LimitThresholdCrossed::Hard(2550000, 10000)
4329 ));
4330
4331 assert!(matches!(
4332 check_limit!(2550000u64, high, high),
4333 LimitThresholdCrossed::Hard(2550000, 10000)
4334 ));
4335
4336 assert!(matches!(
4337 check_limit!(1u8, high),
4338 LimitThresholdCrossed::None
4339 ));
4340
4341 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
4342
4343 assert!(matches!(
4344 check_limit!(2550000u64, high),
4345 LimitThresholdCrossed::Hard(2550000, 10000)
4346 ));
4347 }
4348}