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::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 = 30;
23
24pub const PROTOCOL_VERSION_IIP8: u64 = 20;
26#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
177pub struct ProtocolVersion(u64);
178
179impl ProtocolVersion {
180 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
186
187 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
188
189 #[cfg(not(msim))]
190 const MAX_ALLOWED: Self = Self::MAX;
191
192 #[cfg(msim)]
195 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
196
197 pub fn new(v: u64) -> Self {
198 Self(v)
199 }
200
201 pub const fn as_u64(&self) -> u64 {
202 self.0
203 }
204
205 pub fn max() -> Self {
208 Self::MAX
209 }
210}
211
212impl From<u64> for ProtocolVersion {
213 fn from(v: u64) -> Self {
214 Self::new(v)
215 }
216}
217
218impl std::ops::Sub<u64> for ProtocolVersion {
219 type Output = Self;
220 fn sub(self, rhs: u64) -> Self::Output {
221 Self::new(self.0 - rhs)
222 }
223}
224
225impl std::ops::Add<u64> for ProtocolVersion {
226 type Output = Self;
227 fn add(self, rhs: u64) -> Self::Output {
228 Self::new(self.0 + rhs)
229 }
230}
231
232#[derive(
233 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
234)]
235pub enum Chain {
236 Mainnet,
237 Testnet,
238 #[default]
239 Unknown,
240}
241
242impl Chain {
243 pub fn as_str(self) -> &'static str {
244 match self {
245 Chain::Mainnet => "mainnet",
246 Chain::Testnet => "testnet",
247 Chain::Unknown => "unknown",
248 }
249 }
250}
251
252pub struct Error(pub String);
253
254#[derive(
258 Default,
259 Clone,
260 Serialize,
261 Deserialize,
262 Debug,
263 ProtocolConfigFeatureFlagsGetters,
264 ProtocolConfigOverride,
265)]
266struct FeatureFlags {
267 #[serde(skip_serializing_if = "is_true")]
273 disable_invariant_violation_check_in_swap_loc: bool,
274
275 #[serde(skip_serializing_if = "is_true")]
278 no_extraneous_module_bytes: bool,
279
280 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
282 consensus_transaction_ordering: ConsensusTransactionOrdering,
283
284 #[serde(skip_serializing_if = "is_true")]
287 hardened_otw_check: bool,
288
289 #[serde(skip_serializing_if = "is_false")]
291 enable_poseidon: bool,
292
293 #[serde(skip_serializing_if = "is_false")]
295 enable_group_ops_native_function_msm: bool,
296
297 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
299 per_object_congestion_control_mode: PerObjectCongestionControlMode,
300
301 #[serde(
303 default = "ConsensusChoice::mysticeti_deprecated",
304 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
305 )]
306 consensus_choice: ConsensusChoice,
307
308 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
310 consensus_network: ConsensusNetwork,
311
312 #[deprecated]
314 #[serde(skip_serializing_if = "Option::is_none")]
315 zklogin_max_epoch_upper_bound_delta: Option<u64>,
316
317 #[serde(skip_serializing_if = "is_false")]
319 enable_vdf: bool,
320
321 #[serde(skip_serializing_if = "is_false")]
323 passkey_auth: bool,
324
325 #[serde(skip_serializing_if = "is_true")]
328 rethrow_serialization_type_layout_errors: bool,
329
330 #[serde(skip_serializing_if = "is_false")]
332 relocate_event_module: bool,
333
334 #[serde(skip_serializing_if = "is_false")]
336 protocol_defined_base_fee: bool,
337
338 #[serde(skip_serializing_if = "is_false")]
340 uncompressed_g1_group_elements: bool,
341
342 #[serde(skip_serializing_if = "is_false")]
344 disallow_new_modules_in_deps_only_packages: bool,
345
346 #[serde(skip_serializing_if = "is_false")]
348 native_charging_v2: bool,
349
350 #[serde(skip_serializing_if = "is_false")]
352 convert_type_argument_error: bool,
353
354 #[serde(skip_serializing_if = "is_false")]
356 consensus_round_prober: bool,
357
358 #[serde(skip_serializing_if = "is_false")]
360 consensus_distributed_vote_scoring_strategy: bool,
361
362 #[serde(skip_serializing_if = "is_false")]
366 consensus_linearize_subdag_v2: bool,
367
368 #[serde(skip_serializing_if = "is_false")]
370 variant_nodes: bool,
371
372 #[serde(skip_serializing_if = "is_false")]
374 consensus_smart_ancestor_selection: bool,
375
376 #[serde(skip_serializing_if = "is_false")]
378 consensus_round_prober_probe_accepted_rounds: bool,
379
380 #[serde(skip_serializing_if = "is_false")]
382 consensus_zstd_compression: bool,
383
384 #[serde(skip_serializing_if = "is_false")]
387 congestion_control_min_free_execution_slot: bool,
388
389 #[serde(skip_serializing_if = "is_false")]
391 accept_passkey_in_multisig: bool,
392
393 #[serde(skip_serializing_if = "is_false")]
395 consensus_batched_block_sync: bool,
396
397 #[serde(skip_serializing_if = "is_false")]
400 congestion_control_gas_price_feedback_mechanism: bool,
401
402 #[serde(skip_serializing_if = "is_false")]
404 validate_identifier_inputs: bool,
405
406 #[serde(skip_serializing_if = "is_false")]
409 minimize_child_object_mutations: bool,
410
411 #[serde(skip_serializing_if = "is_false")]
413 dependency_linkage_error: bool,
414
415 #[serde(skip_serializing_if = "is_false")]
417 additional_multisig_checks: bool,
418
419 #[serde(skip_serializing_if = "is_false")]
422 normalize_ptb_arguments: bool,
423
424 #[serde(skip_serializing_if = "is_false")]
428 select_committee_from_eligible_validators: bool,
429
430 #[serde(skip_serializing_if = "is_false")]
437 track_non_committee_eligible_validators: bool,
438
439 #[serde(skip_serializing_if = "is_false")]
445 select_committee_supporting_next_epoch_version: bool,
446
447 #[serde(skip_serializing_if = "is_false")]
451 consensus_median_timestamp_with_checkpoint_enforcement: bool,
452
453 #[serde(skip_serializing_if = "is_false")]
455 consensus_commit_transactions_only_for_traversed_headers: bool,
456
457 #[serde(skip_serializing_if = "is_false")]
459 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
460
461 #[serde(skip_serializing_if = "is_false")]
464 separate_gas_price_feedback_mechanism_for_randomness: bool,
465
466 #[serde(skip_serializing_if = "is_false")]
469 metadata_in_module_bytes: bool,
470
471 #[serde(skip_serializing_if = "is_false")]
473 publish_package_metadata: bool,
474
475 #[serde(skip_serializing_if = "is_false")]
477 enable_move_authentication: bool,
478
479 #[serde(skip_serializing_if = "is_false")]
481 enable_move_authentication_for_sponsor: bool,
482
483 #[serde(skip_serializing_if = "is_false")]
485 pass_validator_scores_to_advance_epoch: bool,
486
487 #[serde(skip_serializing_if = "is_false")]
489 calculate_validator_scores: bool,
490
491 #[serde(skip_serializing_if = "is_false")]
493 adjust_rewards_by_score: bool,
494
495 #[serde(skip_serializing_if = "is_false")]
498 pass_calculated_validator_scores_to_advance_epoch: bool,
499
500 #[serde(skip_serializing_if = "is_false")]
505 consensus_fast_commit_sync: bool,
506
507 #[serde(skip_serializing_if = "is_false")]
510 consensus_block_restrictions: bool,
511
512 #[serde(skip_serializing_if = "is_false")]
514 move_native_tx_context: bool,
515
516 #[serde(skip_serializing_if = "is_false")]
518 additional_borrow_checks: bool,
519
520 #[serde(skip_serializing_if = "is_false")]
522 pre_consensus_sponsor_only_move_authentication: bool,
523
524 #[serde(skip_serializing_if = "is_false")]
526 consensus_starfish_speed: bool,
527
528 #[serde(skip_serializing_if = "is_false")]
535 always_advance_dkg_to_resolution: bool,
536
537 #[serde(skip_serializing_if = "is_false")]
542 enable_pcool_flow: bool,
543}
544
545fn is_true(b: &bool) -> bool {
546 *b
547}
548
549fn is_false(b: &bool) -> bool {
550 !b
551}
552
553#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
555pub enum ConsensusTransactionOrdering {
556 #[default]
559 None,
560 ByGasPrice,
562}
563
564impl ConsensusTransactionOrdering {
565 pub fn is_none(&self) -> bool {
566 matches!(self, ConsensusTransactionOrdering::None)
567 }
568}
569
570#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
572pub enum PerObjectCongestionControlMode {
573 #[default]
574 None, TotalGasBudget, TotalTxCount, }
578
579impl PerObjectCongestionControlMode {
580 pub fn is_none(&self) -> bool {
581 matches!(self, PerObjectCongestionControlMode::None)
582 }
583}
584
585#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
587pub enum ConsensusChoice {
588 #[deprecated(note = "Mysticeti was replaced by Starfish")]
591 MysticetiDeprecated,
592 #[default]
593 Starfish,
594}
595
596#[expect(deprecated)]
597impl ConsensusChoice {
598 fn mysticeti_deprecated() -> Self {
605 ConsensusChoice::MysticetiDeprecated
606 }
607
608 pub fn is_mysticeti_deprecated(&self) -> bool {
609 matches!(self, ConsensusChoice::MysticetiDeprecated)
610 }
611 pub fn is_starfish(&self) -> bool {
612 matches!(self, ConsensusChoice::Starfish)
613 }
614}
615
616#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
618pub enum ConsensusNetwork {
619 #[default]
620 Tonic,
621}
622
623impl ConsensusNetwork {
624 pub fn is_tonic(&self) -> bool {
625 matches!(self, ConsensusNetwork::Tonic)
626 }
627}
628
629#[skip_serializing_none]
663#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
664pub struct ProtocolConfig {
665 pub version: ProtocolVersion,
666
667 feature_flags: FeatureFlags,
668
669 max_tx_size_bytes: Option<u64>,
674
675 max_input_objects: Option<u64>,
678
679 max_size_written_objects: Option<u64>,
684 max_size_written_objects_system_tx: Option<u64>,
688
689 max_serialized_tx_effects_size_bytes: Option<u64>,
691
692 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
694
695 max_gas_payment_objects: Option<u32>,
697
698 max_modules_in_publish: Option<u32>,
700
701 max_package_dependencies: Option<u32>,
703
704 max_arguments: Option<u32>,
707
708 max_type_arguments: Option<u32>,
710
711 max_type_argument_depth: Option<u32>,
713
714 max_pure_argument_size: Option<u32>,
716
717 max_programmable_tx_commands: Option<u32>,
719
720 move_binary_format_version: Option<u32>,
726 min_move_binary_format_version: Option<u32>,
727
728 binary_module_handles: Option<u16>,
730 binary_struct_handles: Option<u16>,
731 binary_function_handles: Option<u16>,
732 binary_function_instantiations: Option<u16>,
733 binary_signatures: Option<u16>,
734 binary_constant_pool: Option<u16>,
735 binary_identifiers: Option<u16>,
736 binary_address_identifiers: Option<u16>,
737 binary_struct_defs: Option<u16>,
738 binary_struct_def_instantiations: Option<u16>,
739 binary_function_defs: Option<u16>,
740 binary_field_handles: Option<u16>,
741 binary_field_instantiations: Option<u16>,
742 binary_friend_decls: Option<u16>,
743 binary_enum_defs: Option<u16>,
744 binary_enum_def_instantiations: Option<u16>,
745 binary_variant_handles: Option<u16>,
746 binary_variant_instantiation_handles: Option<u16>,
747
748 max_move_object_size: Option<u64>,
751
752 max_move_package_size: Option<u64>,
757
758 max_publish_or_upgrade_per_ptb: Option<u64>,
761
762 max_tx_gas: Option<u64>,
764
765 max_auth_gas: Option<u64>,
767
768 max_gas_price: Option<u64>,
771
772 max_gas_computation_bucket: Option<u64>,
775
776 gas_rounding_step: Option<u64>,
778
779 max_loop_depth: Option<u64>,
781
782 max_generic_instantiation_length: Option<u64>,
785
786 max_function_parameters: Option<u64>,
789
790 max_basic_blocks: Option<u64>,
793
794 max_value_stack_size: Option<u64>,
796
797 max_type_nodes: Option<u64>,
801
802 max_push_size: Option<u64>,
805
806 max_struct_definitions: Option<u64>,
809
810 max_function_definitions: Option<u64>,
813
814 max_fields_in_struct: Option<u64>,
817
818 max_dependency_depth: Option<u64>,
821
822 max_num_event_emit: Option<u64>,
825
826 max_num_new_move_object_ids: Option<u64>,
829
830 max_num_new_move_object_ids_system_tx: Option<u64>,
833
834 max_num_deleted_move_object_ids: Option<u64>,
837
838 max_num_deleted_move_object_ids_system_tx: Option<u64>,
841
842 max_num_transferred_move_object_ids: Option<u64>,
845
846 max_num_transferred_move_object_ids_system_tx: Option<u64>,
849
850 max_event_emit_size: Option<u64>,
852
853 max_event_emit_size_total: Option<u64>,
855
856 max_move_vector_len: Option<u64>,
859
860 max_move_identifier_len: Option<u64>,
863
864 max_move_value_depth: Option<u64>,
866
867 max_move_enum_variants: Option<u64>,
870
871 max_back_edges_per_function: Option<u64>,
874
875 max_back_edges_per_module: Option<u64>,
878
879 max_verifier_meter_ticks_per_function: Option<u64>,
882
883 max_meter_ticks_per_module: Option<u64>,
886
887 max_meter_ticks_per_package: Option<u64>,
890
891 object_runtime_max_num_cached_objects: Option<u64>,
898
899 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
902
903 object_runtime_max_num_store_entries: Option<u64>,
906
907 object_runtime_max_num_store_entries_system_tx: Option<u64>,
910
911 base_tx_cost_fixed: Option<u64>,
916
917 package_publish_cost_fixed: Option<u64>,
921
922 base_tx_cost_per_byte: Option<u64>,
926
927 package_publish_cost_per_byte: Option<u64>,
929
930 obj_access_cost_read_per_byte: Option<u64>,
932
933 obj_access_cost_mutate_per_byte: Option<u64>,
935
936 obj_access_cost_delete_per_byte: Option<u64>,
938
939 obj_access_cost_verify_per_byte: Option<u64>,
949
950 max_type_to_layout_nodes: Option<u64>,
952
953 max_ptb_value_size: Option<u64>,
955
956 gas_model_version: Option<u64>,
961
962 obj_data_cost_refundable: Option<u64>,
968
969 obj_metadata_cost_non_refundable: Option<u64>,
973
974 storage_rebate_rate: Option<u64>,
980
981 reward_slashing_rate: Option<u64>,
984
985 storage_gas_price: Option<u64>,
987
988 base_gas_price: Option<u64>,
990
991 validator_target_reward: Option<u64>,
993
994 max_transactions_per_checkpoint: Option<u64>,
1001
1002 max_checkpoint_size_bytes: Option<u64>,
1006
1007 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
1013
1014 address_from_bytes_cost_base: Option<u64>,
1019 address_to_u256_cost_base: Option<u64>,
1021 address_from_u256_cost_base: Option<u64>,
1023
1024 config_read_setting_impl_cost_base: Option<u64>,
1029 config_read_setting_impl_cost_per_byte: Option<u64>,
1030
1031 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
1035 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
1036 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
1037 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
1038 dynamic_field_add_child_object_cost_base: Option<u64>,
1041 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
1042 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
1043 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
1044 dynamic_field_borrow_child_object_cost_base: Option<u64>,
1047 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1048 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1049 dynamic_field_remove_child_object_cost_base: Option<u64>,
1052 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1053 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1054 dynamic_field_has_child_object_cost_base: Option<u64>,
1057 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1060 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1061 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1062
1063 event_emit_cost_base: Option<u64>,
1066 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1067 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1068 event_emit_output_cost_per_byte: Option<u64>,
1069
1070 object_borrow_uid_cost_base: Option<u64>,
1073 object_delete_impl_cost_base: Option<u64>,
1075 object_record_new_uid_cost_base: Option<u64>,
1077
1078 transfer_transfer_internal_cost_base: Option<u64>,
1081 transfer_freeze_object_cost_base: Option<u64>,
1083 transfer_share_object_cost_base: Option<u64>,
1085 transfer_receive_object_cost_base: Option<u64>,
1088
1089 tx_context_derive_id_cost_base: Option<u64>,
1092 tx_context_fresh_id_cost_base: Option<u64>,
1093 tx_context_sender_cost_base: Option<u64>,
1094 tx_context_digest_cost_base: Option<u64>,
1095 tx_context_epoch_cost_base: Option<u64>,
1096 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1097 tx_context_sponsor_cost_base: Option<u64>,
1098 tx_context_rgp_cost_base: Option<u64>,
1099 tx_context_gas_price_cost_base: Option<u64>,
1100 tx_context_gas_budget_cost_base: Option<u64>,
1101 tx_context_ids_created_cost_base: Option<u64>,
1102 tx_context_replace_cost_base: Option<u64>,
1103
1104 types_is_one_time_witness_cost_base: Option<u64>,
1107 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1108 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1109
1110 validator_validate_metadata_cost_base: Option<u64>,
1113 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1114
1115 crypto_invalid_arguments_cost: Option<u64>,
1117 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1119 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1120 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1121
1122 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1124 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1125 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1126
1127 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1129 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1130 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1131 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1132 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1133 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1134
1135 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1137
1138 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1140 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1141 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1142 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1143 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1144 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1145
1146 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1148 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1149 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1150 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1151 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1152 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1153
1154 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1156 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1157 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1158 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1159 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1160 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1161
1162 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1164 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1165 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1166
1167 ed25519_ed25519_verify_cost_base: Option<u64>,
1169 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1170 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1171
1172 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1174 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1175
1176 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1178 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1179 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1180 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1181 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1182
1183 hash_blake2b256_cost_base: Option<u64>,
1185 hash_blake2b256_data_cost_per_byte: Option<u64>,
1186 hash_blake2b256_data_cost_per_block: Option<u64>,
1187
1188 hash_keccak256_cost_base: Option<u64>,
1190 hash_keccak256_data_cost_per_byte: Option<u64>,
1191 hash_keccak256_data_cost_per_block: Option<u64>,
1192
1193 poseidon_bn254_cost_base: Option<u64>,
1195 poseidon_bn254_cost_per_block: Option<u64>,
1196
1197 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1199 group_ops_bls12381_decode_g1_cost: Option<u64>,
1200 group_ops_bls12381_decode_g2_cost: Option<u64>,
1201 group_ops_bls12381_decode_gt_cost: Option<u64>,
1202 group_ops_bls12381_scalar_add_cost: Option<u64>,
1203 group_ops_bls12381_g1_add_cost: Option<u64>,
1204 group_ops_bls12381_g2_add_cost: Option<u64>,
1205 group_ops_bls12381_gt_add_cost: Option<u64>,
1206 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1207 group_ops_bls12381_g1_sub_cost: Option<u64>,
1208 group_ops_bls12381_g2_sub_cost: Option<u64>,
1209 group_ops_bls12381_gt_sub_cost: Option<u64>,
1210 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1211 group_ops_bls12381_g1_mul_cost: Option<u64>,
1212 group_ops_bls12381_g2_mul_cost: Option<u64>,
1213 group_ops_bls12381_gt_mul_cost: Option<u64>,
1214 group_ops_bls12381_scalar_div_cost: Option<u64>,
1215 group_ops_bls12381_g1_div_cost: Option<u64>,
1216 group_ops_bls12381_g2_div_cost: Option<u64>,
1217 group_ops_bls12381_gt_div_cost: Option<u64>,
1218 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1219 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1220 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1221 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1222 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1223 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1224 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1225 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1226 group_ops_bls12381_msm_max_len: Option<u32>,
1227 group_ops_bls12381_pairing_cost: Option<u64>,
1228 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1229 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1230 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1231 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1232 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1233
1234 hmac_hmac_sha3_256_cost_base: Option<u64>,
1236 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1237 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1238
1239 #[deprecated]
1241 check_zklogin_id_cost_base: Option<u64>,
1242 #[deprecated]
1244 check_zklogin_issuer_cost_base: Option<u64>,
1245
1246 vdf_verify_vdf_cost: Option<u64>,
1247 vdf_hash_to_input_cost: Option<u64>,
1248
1249 bcs_per_byte_serialized_cost: Option<u64>,
1251 bcs_legacy_min_output_size_cost: Option<u64>,
1252 bcs_failure_cost: Option<u64>,
1253
1254 hash_sha2_256_base_cost: Option<u64>,
1255 hash_sha2_256_per_byte_cost: Option<u64>,
1256 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1257 hash_sha3_256_base_cost: Option<u64>,
1258 hash_sha3_256_per_byte_cost: Option<u64>,
1259 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1260 type_name_get_base_cost: Option<u64>,
1261 type_name_get_per_byte_cost: Option<u64>,
1262
1263 string_check_utf8_base_cost: Option<u64>,
1264 string_check_utf8_per_byte_cost: Option<u64>,
1265 string_is_char_boundary_base_cost: Option<u64>,
1266 string_sub_string_base_cost: Option<u64>,
1267 string_sub_string_per_byte_cost: Option<u64>,
1268 string_index_of_base_cost: Option<u64>,
1269 string_index_of_per_byte_pattern_cost: Option<u64>,
1270 string_index_of_per_byte_searched_cost: Option<u64>,
1271
1272 vector_empty_base_cost: Option<u64>,
1273 vector_length_base_cost: Option<u64>,
1274 vector_push_back_base_cost: Option<u64>,
1275 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1276 vector_borrow_base_cost: Option<u64>,
1277 vector_pop_back_base_cost: Option<u64>,
1278 vector_destroy_empty_base_cost: Option<u64>,
1279 vector_swap_base_cost: Option<u64>,
1280 debug_print_base_cost: Option<u64>,
1281 debug_print_stack_trace_base_cost: Option<u64>,
1282
1283 execution_version: Option<u64>,
1285
1286 consensus_bad_nodes_stake_threshold: Option<u64>,
1290
1291 #[deprecated]
1292 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1293 #[deprecated]
1297 max_age_of_jwk_in_epochs: Option<u64>,
1298
1299 random_beacon_reduction_allowed_delta: Option<u16>,
1303
1304 random_beacon_reduction_lower_bound: Option<u32>,
1307
1308 random_beacon_dkg_timeout_round: Option<u32>,
1311
1312 random_beacon_min_round_interval_ms: Option<u64>,
1314
1315 random_beacon_dkg_version: Option<u64>,
1319
1320 consensus_max_transaction_size_bytes: Option<u64>,
1325 consensus_max_transactions_in_block_bytes: Option<u64>,
1327 consensus_max_num_transactions_in_block: Option<u64>,
1329
1330 max_deferral_rounds_for_congestion_control: Option<u64>,
1334
1335 min_checkpoint_interval_ms: Option<u64>,
1337
1338 checkpoint_summary_version_specific_data: Option<u64>,
1340
1341 max_soft_bundle_size: Option<u64>,
1344
1345 bridge_should_try_to_finalize_committee: Option<bool>,
1350
1351 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1357
1358 max_committee_members_count: Option<u64>,
1362
1363 consensus_gc_depth: Option<u32>,
1366
1367 consensus_max_acknowledgments_per_block: Option<u32>,
1373
1374 max_congestion_limit_overshoot_per_commit: Option<u64>,
1379
1380 scorer_version: Option<u16>,
1389
1390 auth_context_digest_cost_base: Option<u64>,
1393 auth_context_tx_data_bytes_cost_base: Option<u64>,
1395 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1396 auth_context_tx_commands_cost_base: Option<u64>,
1398 auth_context_tx_commands_cost_per_byte: Option<u64>,
1399 auth_context_tx_inputs_cost_base: Option<u64>,
1401 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1402 auth_context_replace_cost_base: Option<u64>,
1405 auth_context_replace_cost_per_byte: Option<u64>,
1406 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1410
1411 consensus_commits_per_schedule: Option<u32>,
1414}
1415
1416impl ProtocolConfig {
1418 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1431 self.feature_flags
1432 .disable_invariant_violation_check_in_swap_loc
1433 }
1434
1435 pub fn no_extraneous_module_bytes(&self) -> bool {
1436 self.feature_flags.no_extraneous_module_bytes
1437 }
1438
1439 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1440 self.feature_flags.consensus_transaction_ordering
1441 }
1442
1443 pub fn dkg_version(&self) -> u64 {
1444 self.random_beacon_dkg_version.unwrap_or(1)
1446 }
1447
1448 pub fn hardened_otw_check(&self) -> bool {
1449 self.feature_flags.hardened_otw_check
1450 }
1451
1452 pub fn enable_poseidon(&self) -> bool {
1453 self.feature_flags.enable_poseidon
1454 }
1455
1456 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1457 self.feature_flags.enable_group_ops_native_function_msm
1458 }
1459
1460 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1461 self.feature_flags.per_object_congestion_control_mode
1462 }
1463
1464 pub fn consensus_choice(&self) -> ConsensusChoice {
1465 self.feature_flags.consensus_choice
1466 }
1467
1468 pub fn consensus_network(&self) -> ConsensusNetwork {
1469 self.feature_flags.consensus_network
1470 }
1471
1472 pub fn enable_vdf(&self) -> bool {
1473 self.feature_flags.enable_vdf
1474 }
1475
1476 pub fn passkey_auth(&self) -> bool {
1477 self.feature_flags.passkey_auth
1478 }
1479
1480 pub fn max_transaction_size_bytes(&self) -> u64 {
1481 self.consensus_max_transaction_size_bytes
1483 .unwrap_or(256 * 1024)
1484 }
1485
1486 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1487 if cfg!(msim) {
1488 256 * 1024
1489 } else {
1490 self.consensus_max_transactions_in_block_bytes
1491 .unwrap_or(512 * 1024)
1492 }
1493 }
1494
1495 pub fn max_num_transactions_in_block(&self) -> u64 {
1496 if cfg!(msim) {
1497 8
1498 } else {
1499 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1500 }
1501 }
1502
1503 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1504 self.feature_flags.rethrow_serialization_type_layout_errors
1505 }
1506
1507 pub fn relocate_event_module(&self) -> bool {
1508 self.feature_flags.relocate_event_module
1509 }
1510
1511 pub fn protocol_defined_base_fee(&self) -> bool {
1512 self.feature_flags.protocol_defined_base_fee
1513 }
1514
1515 pub fn uncompressed_g1_group_elements(&self) -> bool {
1516 self.feature_flags.uncompressed_g1_group_elements
1517 }
1518
1519 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1520 self.feature_flags
1521 .disallow_new_modules_in_deps_only_packages
1522 }
1523
1524 pub fn native_charging_v2(&self) -> bool {
1525 self.feature_flags.native_charging_v2
1526 }
1527
1528 pub fn consensus_round_prober(&self) -> bool {
1529 self.feature_flags.consensus_round_prober
1530 }
1531
1532 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1533 self.feature_flags
1534 .consensus_distributed_vote_scoring_strategy
1535 }
1536
1537 pub fn gc_depth(&self) -> u32 {
1538 if cfg!(msim) {
1539 min(5, self.consensus_gc_depth.unwrap_or(0))
1541 } else {
1542 self.consensus_gc_depth.unwrap_or(0)
1543 }
1544 }
1545
1546 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1547 let res = self.feature_flags.consensus_linearize_subdag_v2;
1548 assert!(
1549 !res || self.gc_depth() > 0,
1550 "The consensus linearize sub dag V2 requires GC to be enabled"
1551 );
1552 res
1553 }
1554
1555 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1556 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1557 }
1558
1559 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1560 2 * committee_size
1561 }
1562
1563 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1564 committee_size
1565 }
1566
1567 pub fn variant_nodes(&self) -> bool {
1568 self.feature_flags.variant_nodes
1569 }
1570
1571 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1572 self.feature_flags.consensus_smart_ancestor_selection
1573 }
1574
1575 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1576 self.feature_flags
1577 .consensus_round_prober_probe_accepted_rounds
1578 }
1579
1580 pub fn consensus_zstd_compression(&self) -> bool {
1581 self.feature_flags.consensus_zstd_compression
1582 }
1583
1584 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1585 self.feature_flags
1586 .congestion_control_min_free_execution_slot
1587 }
1588
1589 pub fn accept_passkey_in_multisig(&self) -> bool {
1590 self.feature_flags.accept_passkey_in_multisig
1591 }
1592
1593 pub fn consensus_batched_block_sync(&self) -> bool {
1594 self.feature_flags.consensus_batched_block_sync
1595 }
1596
1597 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1600 self.feature_flags
1601 .congestion_control_gas_price_feedback_mechanism
1602 }
1603
1604 pub fn validate_identifier_inputs(&self) -> bool {
1605 self.feature_flags.validate_identifier_inputs
1606 }
1607
1608 pub fn minimize_child_object_mutations(&self) -> bool {
1609 self.feature_flags.minimize_child_object_mutations
1610 }
1611
1612 pub fn dependency_linkage_error(&self) -> bool {
1613 self.feature_flags.dependency_linkage_error
1614 }
1615
1616 pub fn additional_multisig_checks(&self) -> bool {
1617 self.feature_flags.additional_multisig_checks
1618 }
1619
1620 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1621 0
1624 }
1625
1626 pub fn normalize_ptb_arguments(&self) -> bool {
1627 self.feature_flags.normalize_ptb_arguments
1628 }
1629
1630 pub fn select_committee_from_eligible_validators(&self) -> bool {
1631 let res = self.feature_flags.select_committee_from_eligible_validators;
1632 assert!(
1633 !res || (self.protocol_defined_base_fee()
1634 && self.max_committee_members_count_as_option().is_some()),
1635 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1636 );
1637 res
1638 }
1639
1640 pub fn track_non_committee_eligible_validators(&self) -> bool {
1641 self.feature_flags.track_non_committee_eligible_validators
1642 }
1643
1644 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1645 let res = self
1646 .feature_flags
1647 .select_committee_supporting_next_epoch_version;
1648 assert!(
1649 !res || (self.track_non_committee_eligible_validators()
1650 && self.select_committee_from_eligible_validators()),
1651 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1652 );
1653 res
1654 }
1655
1656 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1657 let res = self
1658 .feature_flags
1659 .consensus_median_timestamp_with_checkpoint_enforcement;
1660 assert!(
1661 !res || self.gc_depth() > 0,
1662 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1663 );
1664 res
1665 }
1666
1667 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1668 self.feature_flags
1669 .consensus_commit_transactions_only_for_traversed_headers
1670 }
1671
1672 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1675 self.feature_flags
1676 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1677 }
1678
1679 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1682 self.feature_flags
1683 .separate_gas_price_feedback_mechanism_for_randomness
1684 }
1685
1686 pub fn metadata_in_module_bytes(&self) -> bool {
1687 self.feature_flags.metadata_in_module_bytes
1688 }
1689
1690 pub fn publish_package_metadata(&self) -> bool {
1691 self.feature_flags.publish_package_metadata
1692 }
1693
1694 pub fn enable_move_authentication(&self) -> bool {
1695 self.feature_flags.enable_move_authentication
1696 }
1697
1698 pub fn additional_borrow_checks(&self) -> bool {
1699 self.feature_flags.additional_borrow_checks
1700 }
1701
1702 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1703 let enable_move_authentication_for_sponsor =
1704 self.feature_flags.enable_move_authentication_for_sponsor;
1705 assert!(
1706 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1707 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1708 );
1709 enable_move_authentication_for_sponsor
1710 }
1711
1712 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1713 self.feature_flags.pass_validator_scores_to_advance_epoch
1714 }
1715
1716 pub fn calculate_validator_scores(&self) -> bool {
1717 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1718 assert!(
1719 !calculate_validator_scores || self.scorer_version.is_some(),
1720 "calculate_validator_scores requires scorer_version to be set"
1721 );
1722 calculate_validator_scores
1723 }
1724
1725 pub fn adjust_rewards_by_score(&self) -> bool {
1726 let adjust = self.feature_flags.adjust_rewards_by_score;
1727 assert!(
1728 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1729 "adjust_rewards_by_score requires scorer_version to be set"
1730 );
1731 adjust
1732 }
1733
1734 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1735 let pass = self
1736 .feature_flags
1737 .pass_calculated_validator_scores_to_advance_epoch;
1738 assert!(
1739 !pass
1740 || (self.pass_validator_scores_to_advance_epoch()
1741 && self.calculate_validator_scores()),
1742 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
1743 );
1744 pass
1745 }
1746 pub fn consensus_fast_commit_sync(&self) -> bool {
1747 let res = self.feature_flags.consensus_fast_commit_sync;
1748 assert!(
1749 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
1750 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
1751 );
1752 res
1753 }
1754
1755 pub fn consensus_block_restrictions(&self) -> bool {
1756 self.feature_flags.consensus_block_restrictions
1757 }
1758
1759 pub fn move_native_tx_context(&self) -> bool {
1760 self.feature_flags.move_native_tx_context
1761 }
1762
1763 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
1764 let pre_consensus_sponsor_only_move_authentication = self
1765 .feature_flags
1766 .pre_consensus_sponsor_only_move_authentication;
1767 if pre_consensus_sponsor_only_move_authentication {
1768 assert!(
1769 self.enable_move_authentication(),
1770 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
1771 );
1772 assert!(
1773 self.enable_move_authentication_for_sponsor(),
1774 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
1775 );
1776 }
1777 pre_consensus_sponsor_only_move_authentication
1778 }
1779
1780 pub fn consensus_starfish_speed(&self) -> bool {
1781 let res = self.feature_flags.consensus_starfish_speed;
1782 assert!(
1783 !res || self.consensus_fast_commit_sync(),
1784 "consensus_starfish_speed requires consensus_fast_commit_sync to be enabled"
1785 );
1786 res
1787 }
1788
1789 pub fn always_advance_dkg_to_resolution(&self) -> bool {
1790 self.feature_flags.always_advance_dkg_to_resolution
1791 }
1792
1793 pub fn enable_pcool_flow(&self) -> bool {
1794 self.feature_flags.enable_pcool_flow
1795 }
1796
1797 pub fn commits_per_schedule(&self) -> u32 {
1798 if cfg!(msim) {
1799 min(10, self.consensus_commits_per_schedule.unwrap_or(300))
1801 } else {
1802 self.consensus_commits_per_schedule.unwrap_or(300)
1803 }
1804 }
1805}
1806
1807#[cfg(not(msim))]
1808static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1809
1810#[cfg(msim)]
1812thread_local! {
1813 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1814}
1815
1816impl ProtocolConfig {
1818 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1821 assert!(
1823 version >= ProtocolVersion::MIN,
1824 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1825 version,
1826 ProtocolVersion::MIN.0,
1827 );
1828 assert!(
1829 version <= ProtocolVersion::MAX_ALLOWED,
1830 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1831 version,
1832 ProtocolVersion::MAX_ALLOWED.0,
1833 );
1834
1835 let mut ret = Self::get_for_version_impl(version, chain);
1836 ret.version = version;
1837
1838 ret = CONFIG_OVERRIDE.with(|ovr| {
1839 if let Some(override_fn) = &*ovr.borrow() {
1840 warn!(
1841 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1842 );
1843 override_fn(version, ret)
1844 } else {
1845 ret
1846 }
1847 });
1848
1849 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1850 warn!(
1851 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1852 );
1853
1854 let overrides: ProtocolConfigOptional =
1856 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1857 .expect("failed to parse ProtocolConfig override env variables");
1858 overrides.apply_to(&mut ret);
1859
1860 let feature_flag_overrides: FeatureFlagsOptional =
1862 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_FEATURE_FLAGS_OVERRIDE")
1863 .expect("failed to parse ProtocolConfig feature flags override env variables");
1864
1865 feature_flag_overrides.apply_to(&mut ret.feature_flags);
1866 }
1867
1868 ret
1869 }
1870
1871 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1874 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1875 let mut ret = Self::get_for_version_impl(version, chain);
1876 ret.version = version;
1877 Some(ret)
1878 } else {
1879 None
1880 }
1881 }
1882
1883 #[cfg(not(msim))]
1884 pub fn poison_get_for_min_version() {
1885 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1886 }
1887
1888 #[cfg(not(msim))]
1889 fn load_poison_get_for_min_version() -> bool {
1890 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1891 }
1892
1893 #[cfg(msim)]
1894 pub fn poison_get_for_min_version() {
1895 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1896 }
1897
1898 #[cfg(msim)]
1899 fn load_poison_get_for_min_version() -> bool {
1900 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1901 }
1902
1903 pub fn convert_type_argument_error(&self) -> bool {
1904 self.feature_flags.convert_type_argument_error
1905 }
1906
1907 pub fn get_for_min_version() -> Self {
1911 if Self::load_poison_get_for_min_version() {
1912 panic!("get_for_min_version called on validator");
1913 }
1914 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1915 }
1916
1917 #[expect(non_snake_case)]
1928 pub fn get_for_max_version_UNSAFE() -> Self {
1929 if Self::load_poison_get_for_min_version() {
1930 panic!("get_for_max_version_UNSAFE called on validator");
1931 }
1932 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1933 }
1934
1935 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1936 #[cfg(msim)]
1937 {
1938 if version > ProtocolVersion::MAX {
1940 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1941 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1942 return config;
1943 }
1944 }
1945
1946 let mut cfg = Self {
1950 version,
1951
1952 feature_flags: Default::default(),
1953
1954 max_tx_size_bytes: Some(128 * 1024),
1955 max_input_objects: Some(2048),
1958 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1959 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1960 max_gas_payment_objects: Some(256),
1961 max_modules_in_publish: Some(64),
1962 max_package_dependencies: Some(32),
1963 max_arguments: Some(512),
1964 max_type_arguments: Some(16),
1965 max_type_argument_depth: Some(16),
1966 max_pure_argument_size: Some(16 * 1024),
1967 max_programmable_tx_commands: Some(1024),
1968 move_binary_format_version: Some(7),
1969 min_move_binary_format_version: Some(6),
1970 binary_module_handles: Some(100),
1971 binary_struct_handles: Some(300),
1972 binary_function_handles: Some(1500),
1973 binary_function_instantiations: Some(750),
1974 binary_signatures: Some(1000),
1975 binary_constant_pool: Some(4000),
1976 binary_identifiers: Some(10000),
1977 binary_address_identifiers: Some(100),
1978 binary_struct_defs: Some(200),
1979 binary_struct_def_instantiations: Some(100),
1980 binary_function_defs: Some(1000),
1981 binary_field_handles: Some(500),
1982 binary_field_instantiations: Some(250),
1983 binary_friend_decls: Some(100),
1984 binary_enum_defs: None,
1985 binary_enum_def_instantiations: None,
1986 binary_variant_handles: None,
1987 binary_variant_instantiation_handles: None,
1988 max_move_object_size: Some(250 * 1024),
1989 max_move_package_size: Some(100 * 1024),
1990 max_publish_or_upgrade_per_ptb: Some(5),
1991 max_auth_gas: None,
1993 max_tx_gas: Some(50_000_000_000),
1995 max_gas_price: Some(100_000),
1996 max_gas_computation_bucket: Some(5_000_000),
1997 max_loop_depth: Some(5),
1998 max_generic_instantiation_length: Some(32),
1999 max_function_parameters: Some(128),
2000 max_basic_blocks: Some(1024),
2001 max_value_stack_size: Some(1024),
2002 max_type_nodes: Some(256),
2003 max_push_size: Some(10000),
2004 max_struct_definitions: Some(200),
2005 max_function_definitions: Some(1000),
2006 max_fields_in_struct: Some(32),
2007 max_dependency_depth: Some(100),
2008 max_num_event_emit: Some(1024),
2009 max_num_new_move_object_ids: Some(2048),
2010 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
2011 max_num_deleted_move_object_ids: Some(2048),
2012 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
2013 max_num_transferred_move_object_ids: Some(2048),
2014 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
2015 max_event_emit_size: Some(250 * 1024),
2016 max_move_vector_len: Some(256 * 1024),
2017 max_type_to_layout_nodes: None,
2018 max_ptb_value_size: None,
2019
2020 max_back_edges_per_function: Some(10_000),
2021 max_back_edges_per_module: Some(10_000),
2022
2023 max_verifier_meter_ticks_per_function: Some(16_000_000),
2024
2025 max_meter_ticks_per_module: Some(16_000_000),
2026 max_meter_ticks_per_package: Some(16_000_000),
2027
2028 object_runtime_max_num_cached_objects: Some(1000),
2029 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2030 object_runtime_max_num_store_entries: Some(1000),
2031 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2032 base_tx_cost_fixed: Some(1_000),
2034 package_publish_cost_fixed: Some(1_000),
2035 base_tx_cost_per_byte: Some(0),
2036 package_publish_cost_per_byte: Some(80),
2037 obj_access_cost_read_per_byte: Some(15),
2038 obj_access_cost_mutate_per_byte: Some(40),
2039 obj_access_cost_delete_per_byte: Some(40),
2040 obj_access_cost_verify_per_byte: Some(200),
2041 obj_data_cost_refundable: Some(100),
2042 obj_metadata_cost_non_refundable: Some(50),
2043 gas_model_version: Some(1),
2044 storage_rebate_rate: Some(10000),
2045 reward_slashing_rate: Some(10000),
2047 storage_gas_price: Some(76),
2048 base_gas_price: None,
2049 validator_target_reward: Some(767_000 * 1_000_000_000),
2052 max_transactions_per_checkpoint: Some(10_000),
2053 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2054
2055 buffer_stake_for_protocol_upgrade_bps: Some(5000),
2057
2058 address_from_bytes_cost_base: Some(52),
2062 address_to_u256_cost_base: Some(52),
2064 address_from_u256_cost_base: Some(52),
2066
2067 config_read_setting_impl_cost_base: Some(100),
2070 config_read_setting_impl_cost_per_byte: Some(40),
2071
2072 dynamic_field_hash_type_and_key_cost_base: Some(100),
2076 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
2077 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
2078 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
2079 dynamic_field_add_child_object_cost_base: Some(100),
2082 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2083 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2084 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2085 dynamic_field_borrow_child_object_cost_base: Some(100),
2088 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2089 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2090 dynamic_field_remove_child_object_cost_base: Some(100),
2093 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2094 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2095 dynamic_field_has_child_object_cost_base: Some(100),
2098 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2101 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2102 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2103
2104 event_emit_cost_base: Some(52),
2107 event_emit_value_size_derivation_cost_per_byte: Some(2),
2108 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2109 event_emit_output_cost_per_byte: Some(10),
2110
2111 object_borrow_uid_cost_base: Some(52),
2114 object_delete_impl_cost_base: Some(52),
2116 object_record_new_uid_cost_base: Some(52),
2118
2119 transfer_transfer_internal_cost_base: Some(52),
2123 transfer_freeze_object_cost_base: Some(52),
2125 transfer_share_object_cost_base: Some(52),
2127 transfer_receive_object_cost_base: Some(52),
2128
2129 tx_context_derive_id_cost_base: Some(52),
2133 tx_context_fresh_id_cost_base: None,
2134 tx_context_sender_cost_base: None,
2135 tx_context_digest_cost_base: None,
2136 tx_context_epoch_cost_base: None,
2137 tx_context_epoch_timestamp_ms_cost_base: None,
2138 tx_context_sponsor_cost_base: None,
2139 tx_context_rgp_cost_base: None,
2140 tx_context_gas_price_cost_base: None,
2141 tx_context_gas_budget_cost_base: None,
2142 tx_context_ids_created_cost_base: None,
2143 tx_context_replace_cost_base: None,
2144
2145 types_is_one_time_witness_cost_base: Some(52),
2148 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2149 types_is_one_time_witness_type_cost_per_byte: Some(2),
2150
2151 validator_validate_metadata_cost_base: Some(52),
2155 validator_validate_metadata_data_cost_per_byte: Some(2),
2156
2157 crypto_invalid_arguments_cost: Some(100),
2159 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2161 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2162 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2163
2164 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2166 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2167 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2168
2169 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2171 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2172 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2173 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2174 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2175 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2176
2177 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2179
2180 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2182 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2183 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2184 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2185 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2186 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2187
2188 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2190 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2191 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2192 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2193 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2194 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2195
2196 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2198 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2199 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2200 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2201 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2202 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2203
2204 ecvrf_ecvrf_verify_cost_base: Some(52),
2206 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2207 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2208
2209 ed25519_ed25519_verify_cost_base: Some(52),
2211 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2212 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2213
2214 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2216 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2217
2218 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2220 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2221 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2222 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2223 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2224
2225 hash_blake2b256_cost_base: Some(52),
2227 hash_blake2b256_data_cost_per_byte: Some(2),
2228 hash_blake2b256_data_cost_per_block: Some(2),
2229 hash_keccak256_cost_base: Some(52),
2231 hash_keccak256_data_cost_per_byte: Some(2),
2232 hash_keccak256_data_cost_per_block: Some(2),
2233
2234 poseidon_bn254_cost_base: None,
2235 poseidon_bn254_cost_per_block: None,
2236
2237 hmac_hmac_sha3_256_cost_base: Some(52),
2239 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2240 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2241
2242 group_ops_bls12381_decode_scalar_cost: Some(52),
2244 group_ops_bls12381_decode_g1_cost: Some(52),
2245 group_ops_bls12381_decode_g2_cost: Some(52),
2246 group_ops_bls12381_decode_gt_cost: Some(52),
2247 group_ops_bls12381_scalar_add_cost: Some(52),
2248 group_ops_bls12381_g1_add_cost: Some(52),
2249 group_ops_bls12381_g2_add_cost: Some(52),
2250 group_ops_bls12381_gt_add_cost: Some(52),
2251 group_ops_bls12381_scalar_sub_cost: Some(52),
2252 group_ops_bls12381_g1_sub_cost: Some(52),
2253 group_ops_bls12381_g2_sub_cost: Some(52),
2254 group_ops_bls12381_gt_sub_cost: Some(52),
2255 group_ops_bls12381_scalar_mul_cost: Some(52),
2256 group_ops_bls12381_g1_mul_cost: Some(52),
2257 group_ops_bls12381_g2_mul_cost: Some(52),
2258 group_ops_bls12381_gt_mul_cost: Some(52),
2259 group_ops_bls12381_scalar_div_cost: Some(52),
2260 group_ops_bls12381_g1_div_cost: Some(52),
2261 group_ops_bls12381_g2_div_cost: Some(52),
2262 group_ops_bls12381_gt_div_cost: Some(52),
2263 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2264 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2265 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2266 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2267 group_ops_bls12381_g1_msm_base_cost: Some(52),
2268 group_ops_bls12381_g2_msm_base_cost: Some(52),
2269 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2270 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2271 group_ops_bls12381_msm_max_len: Some(32),
2272 group_ops_bls12381_pairing_cost: Some(52),
2273 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2274 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2275 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2276 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2277 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2278
2279 #[allow(deprecated)]
2281 check_zklogin_id_cost_base: Some(200),
2282 #[allow(deprecated)]
2283 check_zklogin_issuer_cost_base: Some(200),
2285
2286 vdf_verify_vdf_cost: None,
2287 vdf_hash_to_input_cost: None,
2288
2289 bcs_per_byte_serialized_cost: Some(2),
2290 bcs_legacy_min_output_size_cost: Some(1),
2291 bcs_failure_cost: Some(52),
2292 hash_sha2_256_base_cost: Some(52),
2293 hash_sha2_256_per_byte_cost: Some(2),
2294 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2295 hash_sha3_256_base_cost: Some(52),
2296 hash_sha3_256_per_byte_cost: Some(2),
2297 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2298 type_name_get_base_cost: Some(52),
2299 type_name_get_per_byte_cost: Some(2),
2300 string_check_utf8_base_cost: Some(52),
2301 string_check_utf8_per_byte_cost: Some(2),
2302 string_is_char_boundary_base_cost: Some(52),
2303 string_sub_string_base_cost: Some(52),
2304 string_sub_string_per_byte_cost: Some(2),
2305 string_index_of_base_cost: Some(52),
2306 string_index_of_per_byte_pattern_cost: Some(2),
2307 string_index_of_per_byte_searched_cost: Some(2),
2308 vector_empty_base_cost: Some(52),
2309 vector_length_base_cost: Some(52),
2310 vector_push_back_base_cost: Some(52),
2311 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2312 vector_borrow_base_cost: Some(52),
2313 vector_pop_back_base_cost: Some(52),
2314 vector_destroy_empty_base_cost: Some(52),
2315 vector_swap_base_cost: Some(52),
2316 debug_print_base_cost: Some(52),
2317 debug_print_stack_trace_base_cost: Some(52),
2318
2319 max_size_written_objects: Some(5 * 1000 * 1000),
2320 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2323
2324 max_move_identifier_len: Some(128),
2326 max_move_value_depth: Some(128),
2327 max_move_enum_variants: None,
2328
2329 gas_rounding_step: Some(1_000),
2330
2331 execution_version: Some(1),
2332
2333 max_event_emit_size_total: Some(
2336 256 * 250 * 1024, ),
2338
2339 consensus_bad_nodes_stake_threshold: Some(20),
2346
2347 #[allow(deprecated)]
2349 max_jwk_votes_per_validator_per_epoch: Some(240),
2350
2351 #[allow(deprecated)]
2352 max_age_of_jwk_in_epochs: Some(1),
2353
2354 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2358
2359 random_beacon_reduction_allowed_delta: Some(800),
2360
2361 random_beacon_reduction_lower_bound: Some(1000),
2362 random_beacon_dkg_timeout_round: Some(3000),
2363 random_beacon_min_round_interval_ms: Some(500),
2364
2365 random_beacon_dkg_version: Some(1),
2366
2367 consensus_max_num_transactions_in_block: Some(512),
2371
2372 max_deferral_rounds_for_congestion_control: Some(10),
2373
2374 min_checkpoint_interval_ms: Some(200),
2375
2376 checkpoint_summary_version_specific_data: Some(1),
2377
2378 max_soft_bundle_size: Some(5),
2379
2380 bridge_should_try_to_finalize_committee: None,
2381
2382 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2383
2384 max_committee_members_count: None,
2385
2386 consensus_gc_depth: None,
2387
2388 consensus_max_acknowledgments_per_block: None,
2389
2390 max_congestion_limit_overshoot_per_commit: None,
2391
2392 scorer_version: None,
2393
2394 auth_context_digest_cost_base: None,
2396 auth_context_tx_data_bytes_cost_base: None,
2397 auth_context_tx_data_bytes_cost_per_byte: None,
2398 auth_context_tx_commands_cost_base: None,
2399 auth_context_tx_commands_cost_per_byte: None,
2400 auth_context_tx_inputs_cost_base: None,
2401 auth_context_tx_inputs_cost_per_byte: None,
2402 auth_context_replace_cost_base: None,
2403 auth_context_replace_cost_per_byte: None,
2404 auth_context_authenticator_function_info_v1_cost_base: None,
2405 consensus_commits_per_schedule: None,
2406 };
2409
2410 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2411
2412 {
2414 cfg.feature_flags
2415 .disable_invariant_violation_check_in_swap_loc = true;
2416 cfg.feature_flags.no_extraneous_module_bytes = true;
2417 cfg.feature_flags.hardened_otw_check = true;
2418 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2419 }
2420
2421 {
2423 #[allow(deprecated)]
2424 {
2425 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2426 }
2427 }
2428
2429 #[expect(deprecated)]
2433 {
2434 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2435 }
2436 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2438
2439 cfg.feature_flags.per_object_congestion_control_mode =
2440 PerObjectCongestionControlMode::TotalTxCount;
2441
2442 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2444
2445 if chain != Chain::Mainnet && chain != Chain::Testnet {
2447 cfg.feature_flags.enable_poseidon = true;
2448 cfg.poseidon_bn254_cost_base = Some(260);
2449 cfg.poseidon_bn254_cost_per_block = Some(10);
2450
2451 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2452
2453 cfg.feature_flags.enable_vdf = true;
2454 cfg.vdf_verify_vdf_cost = Some(1500);
2457 cfg.vdf_hash_to_input_cost = Some(100);
2458
2459 cfg.feature_flags.passkey_auth = true;
2460 }
2461
2462 for cur in 2..=version.0 {
2463 match cur {
2464 1 => unreachable!(),
2465 2 => {}
2467 3 => {
2468 cfg.feature_flags.relocate_event_module = true;
2469 }
2470 4 => {
2471 cfg.max_type_to_layout_nodes = Some(512);
2472 }
2473 5 => {
2474 cfg.feature_flags.protocol_defined_base_fee = true;
2475 cfg.base_gas_price = Some(1000);
2476
2477 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2478 cfg.feature_flags.convert_type_argument_error = true;
2479 cfg.feature_flags.native_charging_v2 = true;
2480
2481 if chain != Chain::Mainnet && chain != Chain::Testnet {
2482 cfg.feature_flags.uncompressed_g1_group_elements = true;
2483 }
2484
2485 cfg.gas_model_version = Some(2);
2486
2487 cfg.poseidon_bn254_cost_per_block = Some(388);
2488
2489 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2490 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2491 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2492 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2493 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2494 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2495 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2496 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2497
2498 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2500 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2501 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2502 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2503
2504 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2505 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2506 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2507 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2508 Some(8213);
2509 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2510 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2511 Some(9484);
2512
2513 cfg.hash_keccak256_cost_base = Some(10);
2514 cfg.hash_blake2b256_cost_base = Some(10);
2515
2516 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2518 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2519 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2520 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2521
2522 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2523 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2524 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2525 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2526
2527 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2528 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2529 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2530 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2531
2532 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2533 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2534 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2535 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2536
2537 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2538 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2539 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2540 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2541
2542 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2543 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2544
2545 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2546 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2547 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2548 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2549
2550 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2551 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2552 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2553 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2554 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2555
2556 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2557
2558 cfg.validator_validate_metadata_cost_base = Some(20000);
2559
2560 cfg.max_committee_members_count = Some(50);
2561 }
2562 6 => {
2563 cfg.max_ptb_value_size = Some(1024 * 1024);
2564 }
2565 7 => {
2566 }
2569 8 => {
2570 cfg.feature_flags.variant_nodes = true;
2571
2572 if chain != Chain::Mainnet {
2573 cfg.feature_flags.consensus_round_prober = true;
2575 cfg.feature_flags
2577 .consensus_distributed_vote_scoring_strategy = true;
2578 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2579 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2581 cfg.feature_flags
2583 .consensus_round_prober_probe_accepted_rounds = true;
2584 cfg.feature_flags.consensus_zstd_compression = true;
2586 cfg.consensus_gc_depth = Some(60);
2590 }
2591
2592 if chain != Chain::Testnet && chain != Chain::Mainnet {
2595 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2596 }
2597 }
2598 9 => {
2599 if chain != Chain::Mainnet {
2600 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2602 }
2603
2604 cfg.feature_flags.consensus_zstd_compression = true;
2606
2607 if chain != Chain::Testnet && chain != Chain::Mainnet {
2609 cfg.feature_flags.accept_passkey_in_multisig = true;
2610 }
2611
2612 cfg.bridge_should_try_to_finalize_committee = None;
2614 }
2615 10 => {
2616 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2619
2620 cfg.max_committee_members_count = Some(80);
2622
2623 cfg.feature_flags.consensus_round_prober = true;
2625 cfg.feature_flags
2627 .consensus_round_prober_probe_accepted_rounds = true;
2628 cfg.feature_flags
2630 .consensus_distributed_vote_scoring_strategy = true;
2631 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2633
2634 cfg.consensus_gc_depth = Some(60);
2639
2640 cfg.feature_flags.minimize_child_object_mutations = true;
2642
2643 if chain != Chain::Mainnet {
2644 cfg.feature_flags.consensus_batched_block_sync = true;
2646 }
2647
2648 if chain != Chain::Testnet && chain != Chain::Mainnet {
2649 cfg.feature_flags
2652 .congestion_control_gas_price_feedback_mechanism = true;
2653 }
2654
2655 cfg.feature_flags.validate_identifier_inputs = true;
2656 cfg.feature_flags.dependency_linkage_error = true;
2657 cfg.feature_flags.additional_multisig_checks = true;
2658 }
2659 11 => {
2660 }
2663 12 => {
2664 cfg.feature_flags
2667 .congestion_control_gas_price_feedback_mechanism = true;
2668
2669 cfg.feature_flags.normalize_ptb_arguments = true;
2671 }
2672 13 => {
2673 cfg.feature_flags.select_committee_from_eligible_validators = true;
2676 cfg.feature_flags.track_non_committee_eligible_validators = true;
2679
2680 if chain != Chain::Testnet && chain != Chain::Mainnet {
2681 cfg.feature_flags
2684 .select_committee_supporting_next_epoch_version = true;
2685 }
2686 }
2687 14 => {
2688 cfg.feature_flags.consensus_batched_block_sync = true;
2690
2691 if chain != Chain::Mainnet {
2692 cfg.feature_flags
2695 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2696 cfg.feature_flags
2700 .select_committee_supporting_next_epoch_version = true;
2701 }
2702 if chain != Chain::Testnet && chain != Chain::Mainnet {
2703 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2705 }
2706 }
2707 15 => {
2708 if chain != Chain::Mainnet && chain != Chain::Testnet {
2709 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2713 }
2714 }
2715 16 => {
2716 cfg.feature_flags
2719 .select_committee_supporting_next_epoch_version = true;
2720 cfg.feature_flags
2722 .consensus_commit_transactions_only_for_traversed_headers = true;
2723 }
2724 17 => {
2725 cfg.max_committee_members_count = Some(100);
2727 }
2728 18 => {
2729 if chain != Chain::Mainnet {
2730 cfg.feature_flags.passkey_auth = true;
2732 }
2733 }
2734 19 => {
2735 if chain != Chain::Testnet && chain != Chain::Mainnet {
2736 cfg.feature_flags
2739 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2740 cfg.feature_flags
2743 .separate_gas_price_feedback_mechanism_for_randomness = true;
2744 cfg.feature_flags.metadata_in_module_bytes = true;
2747 cfg.feature_flags.publish_package_metadata = true;
2748 cfg.feature_flags.enable_move_authentication = true;
2750 cfg.max_auth_gas = Some(250_000_000);
2752 cfg.transfer_receive_object_cost_base = Some(100);
2755 cfg.feature_flags.adjust_rewards_by_score = true;
2757 }
2758
2759 if chain != Chain::Mainnet {
2760 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2762
2763 cfg.feature_flags.calculate_validator_scores = true;
2765 cfg.scorer_version = Some(1);
2766 }
2767
2768 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
2770
2771 cfg.feature_flags.passkey_auth = true;
2773 }
2774 20 => {
2775 if chain != Chain::Testnet && chain != Chain::Mainnet {
2776 cfg.feature_flags
2778 .pass_calculated_validator_scores_to_advance_epoch = true;
2779 }
2780 }
2781 21 => {
2782 if chain != Chain::Testnet && chain != Chain::Mainnet {
2783 cfg.feature_flags.consensus_fast_commit_sync = true;
2785 }
2786 if chain != Chain::Mainnet {
2787 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2792 cfg.feature_flags
2795 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2796 cfg.feature_flags
2799 .separate_gas_price_feedback_mechanism_for_randomness = true;
2800 }
2801
2802 cfg.auth_context_digest_cost_base = Some(30);
2803 cfg.auth_context_tx_commands_cost_base = Some(30);
2804 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
2805 cfg.auth_context_tx_inputs_cost_base = Some(30);
2806 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
2807 cfg.auth_context_replace_cost_base = Some(30);
2808 cfg.auth_context_replace_cost_per_byte = Some(2);
2809
2810 if chain != Chain::Testnet && chain != Chain::Mainnet {
2811 cfg.max_auth_gas = Some(250_000);
2813 }
2814 }
2815 22 => {
2816 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2821 cfg.feature_flags
2824 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2825 cfg.feature_flags
2828 .separate_gas_price_feedback_mechanism_for_randomness = true;
2829
2830 if chain != Chain::Mainnet {
2831 cfg.feature_flags.metadata_in_module_bytes = true;
2834 cfg.feature_flags.publish_package_metadata = true;
2835 cfg.feature_flags.enable_move_authentication = true;
2837 cfg.max_auth_gas = Some(250_000);
2839 cfg.transfer_receive_object_cost_base = Some(100);
2842 }
2843
2844 if chain != Chain::Mainnet {
2845 cfg.feature_flags.consensus_fast_commit_sync = true;
2847 }
2848 }
2849 23 => {
2850 cfg.feature_flags.move_native_tx_context = true;
2852 cfg.tx_context_fresh_id_cost_base = Some(52);
2853 cfg.tx_context_sender_cost_base = Some(30);
2854 cfg.tx_context_digest_cost_base = Some(30);
2855 cfg.tx_context_epoch_cost_base = Some(30);
2856 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
2857 cfg.tx_context_sponsor_cost_base = Some(30);
2858 cfg.tx_context_rgp_cost_base = Some(30);
2859 cfg.tx_context_gas_price_cost_base = Some(30);
2860 cfg.tx_context_gas_budget_cost_base = Some(30);
2861 cfg.tx_context_ids_created_cost_base = Some(30);
2862 cfg.tx_context_replace_cost_base = Some(30);
2863 }
2864 24 => {
2865 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2867
2868 if chain != Chain::Testnet && chain != Chain::Mainnet {
2869 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2871 }
2872
2873 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
2876 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
2877
2878 cfg.feature_flags.additional_borrow_checks = true;
2880 }
2881 #[allow(deprecated)]
2882 25 => {
2883 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
2886 cfg.check_zklogin_id_cost_base = None;
2887 cfg.check_zklogin_issuer_cost_base = None;
2888 cfg.max_jwk_votes_per_validator_per_epoch = None;
2889 cfg.max_age_of_jwk_in_epochs = None;
2890 }
2891 26 => {
2892 }
2895 27 => {
2896 if chain != Chain::Mainnet {
2897 cfg.feature_flags.consensus_block_restrictions = true;
2900 }
2901
2902 if chain != Chain::Testnet && chain != Chain::Mainnet {
2903 cfg.feature_flags
2905 .pre_consensus_sponsor_only_move_authentication = true;
2906 }
2907 }
2908 28 => {
2909 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
2914
2915 cfg.feature_flags.metadata_in_module_bytes = true;
2918 cfg.feature_flags.publish_package_metadata = true;
2919 cfg.feature_flags.enable_move_authentication = true;
2921 cfg.transfer_receive_object_cost_base = Some(100);
2924
2925 if chain != Chain::Unknown {
2926 cfg.max_auth_gas = Some(20_000);
2928 }
2929
2930 if chain != Chain::Mainnet {
2931 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2933 cfg.feature_flags
2935 .pre_consensus_sponsor_only_move_authentication = true;
2936 }
2937 }
2938 29 => {
2939 cfg.feature_flags.always_advance_dkg_to_resolution = true;
2945
2946 cfg.feature_flags
2949 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2950
2951 cfg.feature_flags.consensus_fast_commit_sync = true;
2953 cfg.feature_flags.consensus_block_restrictions = true;
2957 }
2958 30 => {
2959 }
2967 _ => panic!("unsupported version {version:?}"),
2978 }
2979 }
2980 cfg
2981 }
2982
2983 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
2989 let (
2990 max_back_edges_per_function,
2991 max_back_edges_per_module,
2992 sanity_check_with_regex_reference_safety,
2993 ) = if let Some((
2994 max_back_edges_per_function,
2995 max_back_edges_per_module,
2996 sanity_check_with_regex_reference_safety,
2997 )) = signing_limits
2998 {
2999 (
3000 Some(max_back_edges_per_function),
3001 Some(max_back_edges_per_module),
3002 Some(sanity_check_with_regex_reference_safety),
3003 )
3004 } else {
3005 (None, None, None)
3006 };
3007
3008 let additional_borrow_checks = if signing_limits.is_some() {
3009 true
3012 } else {
3013 self.additional_borrow_checks()
3014 };
3015
3016 VerifierConfig {
3017 max_loop_depth: Some(self.max_loop_depth() as usize),
3018 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
3019 max_function_parameters: Some(self.max_function_parameters() as usize),
3020 max_basic_blocks: Some(self.max_basic_blocks() as usize),
3021 max_value_stack_size: self.max_value_stack_size() as usize,
3022 max_type_nodes: Some(self.max_type_nodes() as usize),
3023 max_push_size: Some(self.max_push_size() as usize),
3024 max_dependency_depth: Some(self.max_dependency_depth() as usize),
3025 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
3026 max_function_definitions: Some(self.max_function_definitions() as usize),
3027 max_data_definitions: Some(self.max_struct_definitions() as usize),
3028 max_constant_vector_len: Some(self.max_move_vector_len()),
3029 max_back_edges_per_function,
3030 max_back_edges_per_module,
3031 max_basic_blocks_in_script: None,
3032 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
3036 max_variants_in_enum: self.max_move_enum_variants_as_option(),
3037 additional_borrow_checks,
3038 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
3039 .map(|limit| limit as u128),
3040 }
3041 }
3042
3043 pub fn apply_overrides_for_testing(
3048 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
3049 ) -> OverrideGuard {
3050 CONFIG_OVERRIDE.with(|ovr| {
3051 let mut cur = ovr.borrow_mut();
3052 assert!(cur.is_none(), "config override already present");
3053 *cur = Some(Box::new(override_fn));
3054 OverrideGuard
3055 })
3056 }
3057}
3058
3059impl ProtocolConfig {
3064 pub fn set_per_object_congestion_control_mode_for_testing(
3065 &mut self,
3066 val: PerObjectCongestionControlMode,
3067 ) {
3068 self.feature_flags.per_object_congestion_control_mode = val;
3069 }
3070
3071 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
3072 self.feature_flags.consensus_choice = val;
3073 }
3074
3075 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
3076 self.feature_flags.consensus_network = val;
3077 }
3078
3079 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
3080 self.feature_flags.passkey_auth = val
3081 }
3082
3083 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
3084 self.feature_flags
3085 .disallow_new_modules_in_deps_only_packages = val;
3086 }
3087
3088 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
3089 self.feature_flags.consensus_round_prober = val;
3090 }
3091
3092 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
3093 self.feature_flags
3094 .consensus_distributed_vote_scoring_strategy = val;
3095 }
3096
3097 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
3098 self.consensus_gc_depth = Some(val);
3099 }
3100
3101 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
3102 self.feature_flags.consensus_linearize_subdag_v2 = val;
3103 }
3104
3105 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
3106 self.feature_flags
3107 .consensus_round_prober_probe_accepted_rounds = val;
3108 }
3109
3110 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
3111 self.feature_flags.accept_passkey_in_multisig = val;
3112 }
3113
3114 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
3115 self.feature_flags.consensus_smart_ancestor_selection = val;
3116 }
3117
3118 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
3119 self.feature_flags.consensus_batched_block_sync = val;
3120 }
3121
3122 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
3123 self.feature_flags
3124 .congestion_control_min_free_execution_slot = val;
3125 }
3126
3127 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
3128 self.feature_flags
3129 .congestion_control_gas_price_feedback_mechanism = val;
3130 }
3131
3132 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
3133 self.feature_flags.select_committee_from_eligible_validators = val;
3134 }
3135
3136 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
3137 self.feature_flags.track_non_committee_eligible_validators = val;
3138 }
3139
3140 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
3141 self.feature_flags
3142 .select_committee_supporting_next_epoch_version = val;
3143 }
3144
3145 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
3146 &mut self,
3147 val: bool,
3148 ) {
3149 self.feature_flags
3150 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3151 }
3152
3153 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3154 &mut self,
3155 val: bool,
3156 ) {
3157 self.feature_flags
3158 .consensus_commit_transactions_only_for_traversed_headers = val;
3159 }
3160
3161 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3162 &mut self,
3163 val: bool,
3164 ) {
3165 self.feature_flags
3166 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3167 }
3168
3169 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3170 &mut self,
3171 val: bool,
3172 ) {
3173 self.feature_flags
3174 .separate_gas_price_feedback_mechanism_for_randomness = val;
3175 }
3176
3177 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3178 self.feature_flags.metadata_in_module_bytes = val;
3179 }
3180
3181 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3182 self.feature_flags.publish_package_metadata = val;
3183 }
3184
3185 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3186 self.feature_flags.enable_move_authentication = val;
3187 }
3188
3189 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3190 self.feature_flags.enable_move_authentication_for_sponsor = val;
3191 }
3192
3193 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3194 self.feature_flags.consensus_fast_commit_sync = val;
3195 }
3196
3197 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3198 self.feature_flags.consensus_block_restrictions = val;
3199 }
3200
3201 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3202 self.feature_flags
3203 .pre_consensus_sponsor_only_move_authentication = val;
3204 }
3205
3206 pub fn set_consensus_starfish_speed_for_testing(&mut self, val: bool) {
3207 self.feature_flags.consensus_starfish_speed = val;
3208 }
3209
3210 pub fn set_always_advance_dkg_to_resolution_for_testing(&mut self, val: bool) {
3211 self.feature_flags.always_advance_dkg_to_resolution = val;
3212 }
3213
3214 pub fn set_enable_pcool_flow_for_testing(&mut self, val: bool) {
3215 self.feature_flags.enable_pcool_flow = val;
3216 }
3217
3218 pub fn set_commits_per_schedule_for_testing(&mut self, val: u32) {
3219 self.consensus_commits_per_schedule = Some(val);
3220 }
3221}
3222
3223type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
3224
3225thread_local! {
3226 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
3227}
3228
3229#[must_use]
3230pub struct OverrideGuard;
3231
3232impl Drop for OverrideGuard {
3233 fn drop(&mut self) {
3234 info!("restoring override fn");
3235 CONFIG_OVERRIDE.with(|ovr| {
3236 *ovr.borrow_mut() = None;
3237 });
3238 }
3239}
3240
3241#[derive(PartialEq, Eq)]
3245pub enum LimitThresholdCrossed {
3246 None,
3247 Soft(u128, u128),
3248 Hard(u128, u128),
3249}
3250
3251pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
3254 x: T,
3255 soft_limit: U,
3256 hard_limit: V,
3257) -> LimitThresholdCrossed {
3258 let x: V = x.into();
3259 let soft_limit: V = soft_limit.into();
3260
3261 debug_assert!(soft_limit <= hard_limit);
3262
3263 if x >= hard_limit {
3266 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
3267 } else if x < soft_limit {
3268 LimitThresholdCrossed::None
3269 } else {
3270 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
3271 }
3272}
3273
3274#[macro_export]
3275macro_rules! check_limit {
3276 ($x:expr, $hard:expr) => {
3277 check_limit!($x, $hard, $hard)
3278 };
3279 ($x:expr, $soft:expr, $hard:expr) => {
3280 check_limit_in_range($x as u64, $soft, $hard)
3281 };
3282}
3283
3284#[macro_export]
3288macro_rules! check_limit_by_meter {
3289 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
3290 let (h, metered_str) = if $is_metered {
3292 ($metered_limit, "metered")
3293 } else {
3294 ($unmetered_hard_limit, "unmetered")
3296 };
3297 use iota_protocol_config::check_limit_in_range;
3298 let result = check_limit_in_range($x as u64, $metered_limit, h);
3299 match result {
3300 LimitThresholdCrossed::None => {}
3301 LimitThresholdCrossed::Soft(_, _) => {
3302 $metric.with_label_values(&[metered_str, "soft"]).inc();
3303 }
3304 LimitThresholdCrossed::Hard(_, _) => {
3305 $metric.with_label_values(&[metered_str, "hard"]).inc();
3306 }
3307 };
3308 result
3309 }};
3310}
3311
3312#[cfg(all(test, not(msim)))]
3313mod test {
3314 use insta::assert_yaml_snapshot;
3315
3316 use super::*;
3317
3318 #[test]
3319 fn snapshot_tests() {
3320 println!("\n============================================================================");
3321 println!("! !");
3322 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
3323 println!("! !");
3324 println!("============================================================================\n");
3325 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
3326 let chain_str = match chain_id {
3331 Chain::Unknown => "".to_string(),
3332 _ => format!("{chain_id:?}_"),
3333 };
3334 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
3335 let cur = ProtocolVersion::new(i);
3336 assert_yaml_snapshot!(
3337 format!("{}version_{}", chain_str, cur.as_u64()),
3338 ProtocolConfig::get_for_version(cur, *chain_id)
3339 );
3340 }
3341 }
3342 }
3343
3344 #[test]
3345 fn test_getters() {
3346 let prot: ProtocolConfig =
3347 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3348 assert_eq!(
3349 prot.max_arguments(),
3350 prot.max_arguments_as_option().unwrap()
3351 );
3352 }
3353
3354 #[test]
3355 fn test_setters() {
3356 let mut prot: ProtocolConfig =
3357 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3358 prot.set_max_arguments_for_testing(123);
3359 assert_eq!(prot.max_arguments(), 123);
3360
3361 prot.set_max_arguments_from_str_for_testing("321".to_string());
3362 assert_eq!(prot.max_arguments(), 321);
3363
3364 prot.disable_max_arguments_for_testing();
3365 assert_eq!(prot.max_arguments_as_option(), None);
3366
3367 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
3368 assert_eq!(prot.max_arguments(), 456);
3369 }
3370
3371 #[test]
3372 #[should_panic(expected = "unsupported version")]
3373 fn max_version_test() {
3374 let _ = ProtocolConfig::get_for_version_impl(
3377 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
3378 Chain::Unknown,
3379 );
3380 }
3381
3382 #[test]
3383 fn lookup_by_string_test() {
3384 let prot: ProtocolConfig =
3385 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3386 assert!(prot.lookup_attr("some random string".to_string()).is_none());
3388
3389 assert!(
3390 prot.lookup_attr("max_arguments".to_string())
3391 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
3392 );
3393
3394 assert!(
3396 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3397 .is_none()
3398 );
3399 assert!(
3400 prot.attr_map()
3401 .get("poseidon_bn254_cost_base")
3402 .unwrap()
3403 .is_none()
3404 );
3405
3406 let prot: ProtocolConfig =
3408 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3409
3410 assert!(
3411 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3412 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3413 );
3414 assert!(
3415 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
3416 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3417 );
3418
3419 let prot: ProtocolConfig =
3421 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3422 assert!(
3424 prot.feature_flags
3425 .lookup_attr("some random string".to_owned())
3426 .is_none()
3427 );
3428 assert!(
3429 !prot
3430 .feature_flags
3431 .attr_map()
3432 .contains_key("some random string")
3433 );
3434
3435 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
3437 assert!(
3438 prot.feature_flags
3439 .attr_map()
3440 .get("enable_poseidon")
3441 .unwrap()
3442 == &false
3443 );
3444 let prot: ProtocolConfig =
3445 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3446 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
3448 assert!(
3449 prot.feature_flags
3450 .attr_map()
3451 .get("enable_poseidon")
3452 .unwrap()
3453 == &true
3454 );
3455 }
3456
3457 #[test]
3458 fn limit_range_fn_test() {
3459 let low = 100u32;
3460 let high = 10000u64;
3461
3462 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
3463 assert!(matches!(
3464 check_limit!(255u16, low, high),
3465 LimitThresholdCrossed::Soft(255u128, 100)
3466 ));
3467 assert!(matches!(
3474 check_limit!(2550000u64, low, high),
3475 LimitThresholdCrossed::Hard(2550000, 10000)
3476 ));
3477
3478 assert!(matches!(
3479 check_limit!(2550000u64, high, high),
3480 LimitThresholdCrossed::Hard(2550000, 10000)
3481 ));
3482
3483 assert!(matches!(
3484 check_limit!(1u8, high),
3485 LimitThresholdCrossed::None
3486 ));
3487
3488 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
3489
3490 assert!(matches!(
3491 check_limit!(2550000u64, high),
3492 LimitThresholdCrossed::Hard(2550000, 10000)
3493 ));
3494 }
3495}