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 = 31;
23
24pub const PROTOCOL_VERSION_IIP8: u64 = 20;
26#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
188pub struct ProtocolVersion(u64);
189
190impl ProtocolVersion {
191 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
197
198 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
199
200 #[cfg(not(msim))]
201 const MAX_ALLOWED: Self = Self::MAX;
202
203 #[cfg(msim)]
206 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
207
208 pub fn new(v: u64) -> Self {
209 Self(v)
210 }
211
212 pub const fn as_u64(&self) -> u64 {
213 self.0
214 }
215
216 pub fn max() -> Self {
219 Self::MAX
220 }
221}
222
223impl From<u64> for ProtocolVersion {
224 fn from(v: u64) -> Self {
225 Self::new(v)
226 }
227}
228
229impl std::ops::Sub<u64> for ProtocolVersion {
230 type Output = Self;
231 fn sub(self, rhs: u64) -> Self::Output {
232 Self::new(self.0 - rhs)
233 }
234}
235
236impl std::ops::Add<u64> for ProtocolVersion {
237 type Output = Self;
238 fn add(self, rhs: u64) -> Self::Output {
239 Self::new(self.0 + rhs)
240 }
241}
242
243#[derive(
244 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
245)]
246pub enum Chain {
247 Mainnet,
248 Testnet,
249 #[default]
250 Unknown,
251}
252
253impl Chain {
254 pub fn as_str(self) -> &'static str {
255 match self {
256 Chain::Mainnet => "mainnet",
257 Chain::Testnet => "testnet",
258 Chain::Unknown => "unknown",
259 }
260 }
261}
262
263pub struct Error(pub String);
264
265#[derive(
269 Default,
270 Clone,
271 Serialize,
272 Deserialize,
273 Debug,
274 ProtocolConfigFeatureFlagsGetters,
275 ProtocolConfigOverride,
276)]
277struct FeatureFlags {
278 #[serde(skip_serializing_if = "is_true")]
284 disable_invariant_violation_check_in_swap_loc: bool,
285
286 #[serde(skip_serializing_if = "is_true")]
289 no_extraneous_module_bytes: bool,
290
291 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
293 consensus_transaction_ordering: ConsensusTransactionOrdering,
294
295 #[serde(skip_serializing_if = "is_true")]
298 hardened_otw_check: bool,
299
300 #[serde(skip_serializing_if = "is_false")]
302 enable_poseidon: bool,
303
304 #[serde(skip_serializing_if = "is_false")]
306 enable_group_ops_native_function_msm: bool,
307
308 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
310 per_object_congestion_control_mode: PerObjectCongestionControlMode,
311
312 #[serde(
314 default = "ConsensusChoice::mysticeti_deprecated",
315 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
316 )]
317 consensus_choice: ConsensusChoice,
318
319 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
321 consensus_network: ConsensusNetwork,
322
323 #[deprecated]
325 #[serde(skip_serializing_if = "Option::is_none")]
326 zklogin_max_epoch_upper_bound_delta: Option<u64>,
327
328 #[serde(skip_serializing_if = "is_false")]
330 enable_vdf: bool,
331
332 #[serde(skip_serializing_if = "is_false")]
334 passkey_auth: bool,
335
336 #[serde(skip_serializing_if = "is_true")]
339 rethrow_serialization_type_layout_errors: bool,
340
341 #[serde(skip_serializing_if = "is_false")]
343 relocate_event_module: bool,
344
345 #[serde(skip_serializing_if = "is_false")]
347 protocol_defined_base_fee: bool,
348
349 #[serde(skip_serializing_if = "is_false")]
351 uncompressed_g1_group_elements: bool,
352
353 #[serde(skip_serializing_if = "is_false")]
355 disallow_new_modules_in_deps_only_packages: bool,
356
357 #[serde(skip_serializing_if = "is_false")]
359 native_charging_v2: bool,
360
361 #[serde(skip_serializing_if = "is_false")]
363 convert_type_argument_error: bool,
364
365 #[serde(skip_serializing_if = "is_false")]
367 consensus_round_prober: bool,
368
369 #[serde(skip_serializing_if = "is_false")]
371 consensus_distributed_vote_scoring_strategy: bool,
372
373 #[serde(skip_serializing_if = "is_false")]
377 consensus_linearize_subdag_v2: bool,
378
379 #[serde(skip_serializing_if = "is_false")]
381 variant_nodes: bool,
382
383 #[serde(skip_serializing_if = "is_false")]
385 consensus_smart_ancestor_selection: bool,
386
387 #[serde(skip_serializing_if = "is_false")]
389 consensus_round_prober_probe_accepted_rounds: bool,
390
391 #[serde(skip_serializing_if = "is_false")]
393 consensus_zstd_compression: bool,
394
395 #[serde(skip_serializing_if = "is_false")]
398 congestion_control_min_free_execution_slot: bool,
399
400 #[serde(skip_serializing_if = "is_false")]
402 accept_passkey_in_multisig: bool,
403
404 #[serde(skip_serializing_if = "is_false")]
406 consensus_batched_block_sync: bool,
407
408 #[serde(skip_serializing_if = "is_false")]
411 congestion_control_gas_price_feedback_mechanism: bool,
412
413 #[serde(skip_serializing_if = "is_false")]
415 validate_identifier_inputs: bool,
416
417 #[serde(skip_serializing_if = "is_false")]
420 minimize_child_object_mutations: bool,
421
422 #[serde(skip_serializing_if = "is_false")]
424 dependency_linkage_error: bool,
425
426 #[serde(skip_serializing_if = "is_false")]
428 additional_multisig_checks: bool,
429
430 #[serde(skip_serializing_if = "is_false")]
433 normalize_ptb_arguments: bool,
434
435 #[serde(skip_serializing_if = "is_false")]
439 select_committee_from_eligible_validators: bool,
440
441 #[serde(skip_serializing_if = "is_false")]
448 track_non_committee_eligible_validators: bool,
449
450 #[serde(skip_serializing_if = "is_false")]
456 select_committee_supporting_next_epoch_version: bool,
457
458 #[serde(skip_serializing_if = "is_false")]
462 consensus_median_timestamp_with_checkpoint_enforcement: bool,
463
464 #[serde(skip_serializing_if = "is_false")]
466 consensus_commit_transactions_only_for_traversed_headers: bool,
467
468 #[serde(skip_serializing_if = "is_false")]
470 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
471
472 #[serde(skip_serializing_if = "is_false")]
475 separate_gas_price_feedback_mechanism_for_randomness: bool,
476
477 #[serde(skip_serializing_if = "is_false")]
480 metadata_in_module_bytes: bool,
481
482 #[serde(skip_serializing_if = "is_false")]
484 publish_package_metadata: bool,
485
486 #[serde(skip_serializing_if = "is_false")]
488 enable_move_authentication: bool,
489
490 #[serde(skip_serializing_if = "is_false")]
492 enable_move_authentication_for_sponsor: bool,
493
494 #[serde(skip_serializing_if = "is_false")]
496 pass_validator_scores_to_advance_epoch: bool,
497
498 #[serde(skip_serializing_if = "is_false")]
500 calculate_validator_scores: bool,
501
502 #[serde(skip_serializing_if = "is_false")]
504 adjust_rewards_by_score: bool,
505
506 #[serde(skip_serializing_if = "is_false")]
509 pass_calculated_validator_scores_to_advance_epoch: bool,
510
511 #[serde(skip_serializing_if = "is_false")]
516 consensus_fast_commit_sync: bool,
517
518 #[serde(skip_serializing_if = "is_false")]
521 consensus_block_restrictions: bool,
522
523 #[serde(skip_serializing_if = "is_false")]
525 move_native_tx_context: bool,
526
527 #[serde(skip_serializing_if = "is_false")]
529 additional_borrow_checks: bool,
530
531 #[serde(skip_serializing_if = "is_false")]
533 pre_consensus_sponsor_only_move_authentication: bool,
534
535 #[serde(skip_serializing_if = "is_false")]
537 consensus_starfish_speed: bool,
538
539 #[serde(skip_serializing_if = "is_false")]
546 always_advance_dkg_to_resolution: bool,
547
548 #[serde(skip_serializing_if = "is_false")]
553 enable_pcool_flow: bool,
554
555 #[serde(skip_serializing_if = "is_false")]
557 validator_metadata_verify_v2: bool,
558
559 #[serde(skip_serializing_if = "is_false")]
563 deny_rule_governance: bool,
564
565 #[serde(skip_serializing_if = "is_false")]
568 package_metadata_with_dynamic_module_metadata: bool,
569
570 #[serde(skip_serializing_if = "is_false")]
573 report_move_authentication_error: bool,
574}
575
576fn is_true(b: &bool) -> bool {
577 *b
578}
579
580fn is_false(b: &bool) -> bool {
581 !b
582}
583
584#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
586pub enum ConsensusTransactionOrdering {
587 #[default]
590 None,
591 ByGasPrice,
593}
594
595impl ConsensusTransactionOrdering {
596 pub fn is_none(&self) -> bool {
597 matches!(self, ConsensusTransactionOrdering::None)
598 }
599}
600
601#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
603pub enum PerObjectCongestionControlMode {
604 #[default]
605 None, TotalGasBudget, TotalTxCount, }
609
610impl PerObjectCongestionControlMode {
611 pub fn is_none(&self) -> bool {
612 matches!(self, PerObjectCongestionControlMode::None)
613 }
614}
615
616#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
618pub enum ConsensusChoice {
619 #[deprecated(note = "Mysticeti was replaced by Starfish")]
622 MysticetiDeprecated,
623 #[default]
624 Starfish,
625}
626
627#[expect(deprecated)]
628impl ConsensusChoice {
629 fn mysticeti_deprecated() -> Self {
636 ConsensusChoice::MysticetiDeprecated
637 }
638
639 pub fn is_mysticeti_deprecated(&self) -> bool {
640 matches!(self, ConsensusChoice::MysticetiDeprecated)
641 }
642 pub fn is_starfish(&self) -> bool {
643 matches!(self, ConsensusChoice::Starfish)
644 }
645}
646
647#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
649pub enum ConsensusNetwork {
650 #[default]
651 Tonic,
652}
653
654impl ConsensusNetwork {
655 pub fn is_tonic(&self) -> bool {
656 matches!(self, ConsensusNetwork::Tonic)
657 }
658}
659
660#[skip_serializing_none]
694#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
695pub struct ProtocolConfig {
696 pub version: ProtocolVersion,
697
698 feature_flags: FeatureFlags,
699
700 max_tx_size_bytes: Option<u64>,
705
706 max_input_objects: Option<u64>,
709
710 max_size_written_objects: Option<u64>,
715 max_size_written_objects_system_tx: Option<u64>,
719
720 max_serialized_tx_effects_size_bytes: Option<u64>,
722
723 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
725
726 max_gas_payment_objects: Option<u32>,
728
729 max_modules_in_publish: Option<u32>,
731
732 max_package_dependencies: Option<u32>,
734
735 max_arguments: Option<u32>,
738
739 max_type_arguments: Option<u32>,
741
742 max_type_argument_depth: Option<u32>,
744
745 max_pure_argument_size: Option<u32>,
747
748 max_programmable_tx_commands: Option<u32>,
750
751 move_binary_format_version: Option<u32>,
757 min_move_binary_format_version: Option<u32>,
758
759 binary_module_handles: Option<u16>,
761 binary_struct_handles: Option<u16>,
762 binary_function_handles: Option<u16>,
763 binary_function_instantiations: Option<u16>,
764 binary_signatures: Option<u16>,
765 binary_constant_pool: Option<u16>,
766 binary_identifiers: Option<u16>,
767 binary_address_identifiers: Option<u16>,
768 binary_struct_defs: Option<u16>,
769 binary_struct_def_instantiations: Option<u16>,
770 binary_function_defs: Option<u16>,
771 binary_field_handles: Option<u16>,
772 binary_field_instantiations: Option<u16>,
773 binary_friend_decls: Option<u16>,
774 binary_enum_defs: Option<u16>,
775 binary_enum_def_instantiations: Option<u16>,
776 binary_variant_handles: Option<u16>,
777 binary_variant_instantiation_handles: Option<u16>,
778
779 max_move_object_size: Option<u64>,
782
783 max_move_package_size: Option<u64>,
788
789 max_publish_or_upgrade_per_ptb: Option<u64>,
792
793 max_tx_gas: Option<u64>,
795
796 max_auth_gas: Option<u64>,
798
799 max_gas_price: Option<u64>,
802
803 max_gas_computation_bucket: Option<u64>,
806
807 gas_rounding_step: Option<u64>,
809
810 max_loop_depth: Option<u64>,
812
813 max_generic_instantiation_length: Option<u64>,
816
817 max_function_parameters: Option<u64>,
820
821 max_basic_blocks: Option<u64>,
824
825 max_value_stack_size: Option<u64>,
827
828 max_type_nodes: Option<u64>,
832
833 max_push_size: Option<u64>,
836
837 max_struct_definitions: Option<u64>,
840
841 max_function_definitions: Option<u64>,
844
845 max_fields_in_struct: Option<u64>,
848
849 max_dependency_depth: Option<u64>,
852
853 max_num_event_emit: Option<u64>,
856
857 max_num_new_move_object_ids: Option<u64>,
860
861 max_num_new_move_object_ids_system_tx: Option<u64>,
864
865 max_num_deleted_move_object_ids: Option<u64>,
868
869 max_num_deleted_move_object_ids_system_tx: Option<u64>,
872
873 max_num_transferred_move_object_ids: Option<u64>,
876
877 max_num_transferred_move_object_ids_system_tx: Option<u64>,
880
881 max_event_emit_size: Option<u64>,
883
884 max_event_emit_size_total: Option<u64>,
886
887 max_move_vector_len: Option<u64>,
890
891 max_move_identifier_len: Option<u64>,
894
895 max_move_value_depth: Option<u64>,
897
898 max_move_enum_variants: Option<u64>,
901
902 max_back_edges_per_function: Option<u64>,
905
906 max_back_edges_per_module: Option<u64>,
909
910 max_verifier_meter_ticks_per_function: Option<u64>,
913
914 max_meter_ticks_per_module: Option<u64>,
917
918 max_meter_ticks_per_package: Option<u64>,
921
922 object_runtime_max_num_cached_objects: Option<u64>,
929
930 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
933
934 object_runtime_max_num_store_entries: Option<u64>,
937
938 object_runtime_max_num_store_entries_system_tx: Option<u64>,
941
942 base_tx_cost_fixed: Option<u64>,
947
948 package_publish_cost_fixed: Option<u64>,
952
953 base_tx_cost_per_byte: Option<u64>,
957
958 package_publish_cost_per_byte: Option<u64>,
960
961 obj_access_cost_read_per_byte: Option<u64>,
963
964 obj_access_cost_mutate_per_byte: Option<u64>,
966
967 obj_access_cost_delete_per_byte: Option<u64>,
969
970 obj_access_cost_verify_per_byte: Option<u64>,
980
981 max_type_to_layout_nodes: Option<u64>,
983
984 max_ptb_value_size: Option<u64>,
986
987 gas_model_version: Option<u64>,
992
993 obj_data_cost_refundable: Option<u64>,
999
1000 obj_metadata_cost_non_refundable: Option<u64>,
1004
1005 storage_rebate_rate: Option<u64>,
1011
1012 reward_slashing_rate: Option<u64>,
1015
1016 storage_gas_price: Option<u64>,
1018
1019 base_gas_price: Option<u64>,
1021
1022 validator_target_reward: Option<u64>,
1024
1025 max_transactions_per_checkpoint: Option<u64>,
1032
1033 max_checkpoint_size_bytes: Option<u64>,
1037
1038 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
1044
1045 address_from_bytes_cost_base: Option<u64>,
1050 address_to_u256_cost_base: Option<u64>,
1052 address_from_u256_cost_base: Option<u64>,
1054
1055 config_read_setting_impl_cost_base: Option<u64>,
1060 config_read_setting_impl_cost_per_byte: Option<u64>,
1061
1062 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
1066 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
1067 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
1068 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
1069 dynamic_field_add_child_object_cost_base: Option<u64>,
1072 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
1073 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
1074 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
1075 dynamic_field_borrow_child_object_cost_base: Option<u64>,
1078 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1079 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1080 dynamic_field_remove_child_object_cost_base: Option<u64>,
1083 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1084 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1085 dynamic_field_has_child_object_cost_base: Option<u64>,
1088 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1091 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1092 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1093
1094 event_emit_cost_base: Option<u64>,
1097 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1098 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1099 event_emit_output_cost_per_byte: Option<u64>,
1100
1101 object_borrow_uid_cost_base: Option<u64>,
1104 object_delete_impl_cost_base: Option<u64>,
1106 object_record_new_uid_cost_base: Option<u64>,
1108
1109 transfer_transfer_internal_cost_base: Option<u64>,
1112 transfer_freeze_object_cost_base: Option<u64>,
1114 transfer_share_object_cost_base: Option<u64>,
1116 transfer_receive_object_cost_base: Option<u64>,
1119
1120 tx_context_derive_id_cost_base: Option<u64>,
1123 tx_context_fresh_id_cost_base: Option<u64>,
1124 tx_context_sender_cost_base: Option<u64>,
1125 tx_context_digest_cost_base: Option<u64>,
1126 tx_context_epoch_cost_base: Option<u64>,
1127 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1128 tx_context_sponsor_cost_base: Option<u64>,
1129 tx_context_rgp_cost_base: Option<u64>,
1130 tx_context_gas_price_cost_base: Option<u64>,
1131 tx_context_gas_budget_cost_base: Option<u64>,
1132 tx_context_ids_created_cost_base: Option<u64>,
1133 tx_context_replace_cost_base: Option<u64>,
1134
1135 types_is_one_time_witness_cost_base: Option<u64>,
1138 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1139 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1140
1141 validator_validate_metadata_cost_base: Option<u64>,
1144 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1145
1146 crypto_invalid_arguments_cost: Option<u64>,
1148 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1150 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1151 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1152
1153 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1155 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1156 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1157
1158 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1160 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1161 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1162 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1163 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1164 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1165
1166 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1168
1169 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1171 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1172 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1173 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1174 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1175 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1176
1177 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1179 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1180 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1181 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1182 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1183 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1184
1185 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1187 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1188 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1189 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1190 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1191 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1192
1193 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1195 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1196 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1197
1198 ed25519_ed25519_verify_cost_base: Option<u64>,
1200 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1201 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1202
1203 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1205 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1206
1207 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1209 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1210 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1211 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1212 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1213
1214 hash_blake2b256_cost_base: Option<u64>,
1216 hash_blake2b256_data_cost_per_byte: Option<u64>,
1217 hash_blake2b256_data_cost_per_block: Option<u64>,
1218
1219 hash_keccak256_cost_base: Option<u64>,
1221 hash_keccak256_data_cost_per_byte: Option<u64>,
1222 hash_keccak256_data_cost_per_block: Option<u64>,
1223
1224 poseidon_bn254_cost_base: Option<u64>,
1226 poseidon_bn254_cost_per_block: Option<u64>,
1227
1228 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1230 group_ops_bls12381_decode_g1_cost: Option<u64>,
1231 group_ops_bls12381_decode_g2_cost: Option<u64>,
1232 group_ops_bls12381_decode_gt_cost: Option<u64>,
1233 group_ops_bls12381_scalar_add_cost: Option<u64>,
1234 group_ops_bls12381_g1_add_cost: Option<u64>,
1235 group_ops_bls12381_g2_add_cost: Option<u64>,
1236 group_ops_bls12381_gt_add_cost: Option<u64>,
1237 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1238 group_ops_bls12381_g1_sub_cost: Option<u64>,
1239 group_ops_bls12381_g2_sub_cost: Option<u64>,
1240 group_ops_bls12381_gt_sub_cost: Option<u64>,
1241 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1242 group_ops_bls12381_g1_mul_cost: Option<u64>,
1243 group_ops_bls12381_g2_mul_cost: Option<u64>,
1244 group_ops_bls12381_gt_mul_cost: Option<u64>,
1245 group_ops_bls12381_scalar_div_cost: Option<u64>,
1246 group_ops_bls12381_g1_div_cost: Option<u64>,
1247 group_ops_bls12381_g2_div_cost: Option<u64>,
1248 group_ops_bls12381_gt_div_cost: Option<u64>,
1249 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1250 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1251 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1252 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1253 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1254 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1255 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1256 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1257 group_ops_bls12381_msm_max_len: Option<u32>,
1258 group_ops_bls12381_pairing_cost: Option<u64>,
1259 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1260 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1261 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1262 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1263 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1264
1265 hmac_hmac_sha3_256_cost_base: Option<u64>,
1267 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1268 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1269
1270 #[deprecated]
1272 check_zklogin_id_cost_base: Option<u64>,
1273 #[deprecated]
1275 check_zklogin_issuer_cost_base: Option<u64>,
1276
1277 vdf_verify_vdf_cost: Option<u64>,
1278 vdf_hash_to_input_cost: Option<u64>,
1279
1280 bcs_per_byte_serialized_cost: Option<u64>,
1282 bcs_legacy_min_output_size_cost: Option<u64>,
1283 bcs_failure_cost: Option<u64>,
1284
1285 hash_sha2_256_base_cost: Option<u64>,
1286 hash_sha2_256_per_byte_cost: Option<u64>,
1287 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1288 hash_sha3_256_base_cost: Option<u64>,
1289 hash_sha3_256_per_byte_cost: Option<u64>,
1290 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1291 type_name_get_base_cost: Option<u64>,
1292 type_name_get_per_byte_cost: Option<u64>,
1293
1294 string_check_utf8_base_cost: Option<u64>,
1295 string_check_utf8_per_byte_cost: Option<u64>,
1296 string_is_char_boundary_base_cost: Option<u64>,
1297 string_sub_string_base_cost: Option<u64>,
1298 string_sub_string_per_byte_cost: Option<u64>,
1299 string_index_of_base_cost: Option<u64>,
1300 string_index_of_per_byte_pattern_cost: Option<u64>,
1301 string_index_of_per_byte_searched_cost: Option<u64>,
1302
1303 vector_empty_base_cost: Option<u64>,
1304 vector_length_base_cost: Option<u64>,
1305 vector_push_back_base_cost: Option<u64>,
1306 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1307 vector_borrow_base_cost: Option<u64>,
1308 vector_pop_back_base_cost: Option<u64>,
1309 vector_destroy_empty_base_cost: Option<u64>,
1310 vector_swap_base_cost: Option<u64>,
1311 debug_print_base_cost: Option<u64>,
1312 debug_print_stack_trace_base_cost: Option<u64>,
1313
1314 execution_version: Option<u64>,
1316
1317 consensus_bad_nodes_stake_threshold: Option<u64>,
1321
1322 #[deprecated]
1323 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1324 #[deprecated]
1328 max_age_of_jwk_in_epochs: Option<u64>,
1329
1330 random_beacon_reduction_allowed_delta: Option<u16>,
1334
1335 random_beacon_reduction_lower_bound: Option<u32>,
1338
1339 random_beacon_dkg_timeout_round: Option<u32>,
1342
1343 random_beacon_min_round_interval_ms: Option<u64>,
1345
1346 random_beacon_dkg_version: Option<u64>,
1350
1351 consensus_max_transaction_size_bytes: Option<u64>,
1356 consensus_max_transactions_in_block_bytes: Option<u64>,
1358 consensus_max_num_transactions_in_block: Option<u64>,
1360
1361 max_deferral_rounds_for_congestion_control: Option<u64>,
1365
1366 min_checkpoint_interval_ms: Option<u64>,
1368
1369 checkpoint_rate_window_size: Option<u64>,
1379
1380 checkpoint_summary_version_specific_data: Option<u64>,
1382
1383 max_soft_bundle_size: Option<u64>,
1386
1387 bridge_should_try_to_finalize_committee: Option<bool>,
1392
1393 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1399
1400 max_committee_members_count: Option<u64>,
1404
1405 consensus_gc_depth: Option<u32>,
1408
1409 consensus_max_acknowledgments_per_block: Option<u32>,
1415
1416 max_congestion_limit_overshoot_per_commit: Option<u64>,
1421
1422 scorer_version: Option<u16>,
1431
1432 auth_context_digest_cost_base: Option<u64>,
1435 auth_context_tx_data_bytes_cost_base: Option<u64>,
1437 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1438 auth_context_tx_commands_cost_base: Option<u64>,
1440 auth_context_tx_commands_cost_per_byte: Option<u64>,
1441 auth_context_tx_inputs_cost_base: Option<u64>,
1443 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1444 auth_context_replace_cost_base: Option<u64>,
1447 auth_context_replace_cost_per_byte: Option<u64>,
1448 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1452
1453 consensus_commits_per_schedule: Option<u32>,
1456}
1457
1458impl ProtocolConfig {
1460 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1473 self.feature_flags
1474 .disable_invariant_violation_check_in_swap_loc
1475 }
1476
1477 pub fn no_extraneous_module_bytes(&self) -> bool {
1478 self.feature_flags.no_extraneous_module_bytes
1479 }
1480
1481 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1482 self.feature_flags.consensus_transaction_ordering
1483 }
1484
1485 pub fn dkg_version(&self) -> u64 {
1486 self.random_beacon_dkg_version.unwrap_or(1)
1488 }
1489
1490 pub fn hardened_otw_check(&self) -> bool {
1491 self.feature_flags.hardened_otw_check
1492 }
1493
1494 pub fn enable_poseidon(&self) -> bool {
1495 self.feature_flags.enable_poseidon
1496 }
1497
1498 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1499 self.feature_flags.enable_group_ops_native_function_msm
1500 }
1501
1502 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1503 self.feature_flags.per_object_congestion_control_mode
1504 }
1505
1506 pub fn consensus_choice(&self) -> ConsensusChoice {
1507 self.feature_flags.consensus_choice
1508 }
1509
1510 pub fn consensus_network(&self) -> ConsensusNetwork {
1511 self.feature_flags.consensus_network
1512 }
1513
1514 pub fn enable_vdf(&self) -> bool {
1515 self.feature_flags.enable_vdf
1516 }
1517
1518 pub fn passkey_auth(&self) -> bool {
1519 self.feature_flags.passkey_auth
1520 }
1521
1522 pub fn max_transaction_size_bytes(&self) -> u64 {
1523 self.consensus_max_transaction_size_bytes
1525 .unwrap_or(256 * 1024)
1526 }
1527
1528 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1529 if cfg!(msim) {
1530 256 * 1024
1531 } else {
1532 self.consensus_max_transactions_in_block_bytes
1533 .unwrap_or(512 * 1024)
1534 }
1535 }
1536
1537 pub fn max_num_transactions_in_block(&self) -> u64 {
1538 if cfg!(msim) {
1539 8
1540 } else {
1541 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1542 }
1543 }
1544
1545 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1546 self.feature_flags.rethrow_serialization_type_layout_errors
1547 }
1548
1549 pub fn relocate_event_module(&self) -> bool {
1550 self.feature_flags.relocate_event_module
1551 }
1552
1553 pub fn protocol_defined_base_fee(&self) -> bool {
1554 self.feature_flags.protocol_defined_base_fee
1555 }
1556
1557 pub fn uncompressed_g1_group_elements(&self) -> bool {
1558 self.feature_flags.uncompressed_g1_group_elements
1559 }
1560
1561 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1562 self.feature_flags
1563 .disallow_new_modules_in_deps_only_packages
1564 }
1565
1566 pub fn native_charging_v2(&self) -> bool {
1567 self.feature_flags.native_charging_v2
1568 }
1569
1570 pub fn consensus_round_prober(&self) -> bool {
1571 self.feature_flags.consensus_round_prober
1572 }
1573
1574 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1575 self.feature_flags
1576 .consensus_distributed_vote_scoring_strategy
1577 }
1578
1579 pub fn gc_depth(&self) -> u32 {
1580 if cfg!(msim) {
1581 min(5, self.consensus_gc_depth.unwrap_or(0))
1583 } else {
1584 self.consensus_gc_depth.unwrap_or(0)
1585 }
1586 }
1587
1588 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1589 let res = self.feature_flags.consensus_linearize_subdag_v2;
1590 assert!(
1591 !res || self.gc_depth() > 0,
1592 "The consensus linearize sub dag V2 requires GC to be enabled"
1593 );
1594 res
1595 }
1596
1597 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1598 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1599 }
1600
1601 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1602 2 * committee_size
1603 }
1604
1605 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1606 committee_size
1607 }
1608
1609 pub fn variant_nodes(&self) -> bool {
1610 self.feature_flags.variant_nodes
1611 }
1612
1613 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1614 self.feature_flags.consensus_smart_ancestor_selection
1615 }
1616
1617 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1618 self.feature_flags
1619 .consensus_round_prober_probe_accepted_rounds
1620 }
1621
1622 pub fn consensus_zstd_compression(&self) -> bool {
1623 self.feature_flags.consensus_zstd_compression
1624 }
1625
1626 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1627 self.feature_flags
1628 .congestion_control_min_free_execution_slot
1629 }
1630
1631 pub fn accept_passkey_in_multisig(&self) -> bool {
1632 self.feature_flags.accept_passkey_in_multisig
1633 }
1634
1635 pub fn consensus_batched_block_sync(&self) -> bool {
1636 self.feature_flags.consensus_batched_block_sync
1637 }
1638
1639 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1642 self.feature_flags
1643 .congestion_control_gas_price_feedback_mechanism
1644 }
1645
1646 pub fn validate_identifier_inputs(&self) -> bool {
1647 self.feature_flags.validate_identifier_inputs
1648 }
1649
1650 pub fn minimize_child_object_mutations(&self) -> bool {
1651 self.feature_flags.minimize_child_object_mutations
1652 }
1653
1654 pub fn dependency_linkage_error(&self) -> bool {
1655 self.feature_flags.dependency_linkage_error
1656 }
1657
1658 pub fn additional_multisig_checks(&self) -> bool {
1659 self.feature_flags.additional_multisig_checks
1660 }
1661
1662 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1663 0
1666 }
1667
1668 pub fn normalize_ptb_arguments(&self) -> bool {
1669 self.feature_flags.normalize_ptb_arguments
1670 }
1671
1672 pub fn select_committee_from_eligible_validators(&self) -> bool {
1673 let res = self.feature_flags.select_committee_from_eligible_validators;
1674 assert!(
1675 !res || (self.protocol_defined_base_fee()
1676 && self.max_committee_members_count_as_option().is_some()),
1677 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1678 );
1679 res
1680 }
1681
1682 pub fn track_non_committee_eligible_validators(&self) -> bool {
1683 self.feature_flags.track_non_committee_eligible_validators
1684 }
1685
1686 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1687 let res = self
1688 .feature_flags
1689 .select_committee_supporting_next_epoch_version;
1690 assert!(
1691 !res || (self.track_non_committee_eligible_validators()
1692 && self.select_committee_from_eligible_validators()),
1693 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1694 );
1695 res
1696 }
1697
1698 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1699 let res = self
1700 .feature_flags
1701 .consensus_median_timestamp_with_checkpoint_enforcement;
1702 assert!(
1703 !res || self.gc_depth() > 0,
1704 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1705 );
1706 res
1707 }
1708
1709 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1710 self.feature_flags
1711 .consensus_commit_transactions_only_for_traversed_headers
1712 }
1713
1714 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1717 self.feature_flags
1718 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1719 }
1720
1721 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1724 self.feature_flags
1725 .separate_gas_price_feedback_mechanism_for_randomness
1726 }
1727
1728 pub fn metadata_in_module_bytes(&self) -> bool {
1729 self.feature_flags.metadata_in_module_bytes
1730 }
1731
1732 pub fn publish_package_metadata(&self) -> bool {
1733 self.feature_flags.publish_package_metadata
1734 }
1735
1736 pub fn enable_move_authentication(&self) -> bool {
1737 self.feature_flags.enable_move_authentication
1738 }
1739
1740 pub fn additional_borrow_checks(&self) -> bool {
1741 self.feature_flags.additional_borrow_checks
1742 }
1743
1744 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1745 let enable_move_authentication_for_sponsor =
1746 self.feature_flags.enable_move_authentication_for_sponsor;
1747 assert!(
1748 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1749 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1750 );
1751 enable_move_authentication_for_sponsor
1752 }
1753
1754 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1755 self.feature_flags.pass_validator_scores_to_advance_epoch
1756 }
1757
1758 pub fn calculate_validator_scores(&self) -> bool {
1759 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1760 assert!(
1761 !calculate_validator_scores || self.scorer_version.is_some(),
1762 "calculate_validator_scores requires scorer_version to be set"
1763 );
1764 calculate_validator_scores
1765 }
1766
1767 pub fn adjust_rewards_by_score(&self) -> bool {
1768 let adjust = self.feature_flags.adjust_rewards_by_score;
1769 assert!(
1770 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1771 "adjust_rewards_by_score requires scorer_version to be set"
1772 );
1773 adjust
1774 }
1775
1776 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1777 let pass = self
1778 .feature_flags
1779 .pass_calculated_validator_scores_to_advance_epoch;
1780 assert!(
1781 !pass
1782 || (self.pass_validator_scores_to_advance_epoch()
1783 && self.calculate_validator_scores()),
1784 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
1785 );
1786 pass
1787 }
1788 pub fn consensus_fast_commit_sync(&self) -> bool {
1789 let res = self.feature_flags.consensus_fast_commit_sync;
1790 assert!(
1791 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
1792 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
1793 );
1794 res
1795 }
1796
1797 pub fn consensus_block_restrictions(&self) -> bool {
1798 self.feature_flags.consensus_block_restrictions
1799 }
1800
1801 pub fn move_native_tx_context(&self) -> bool {
1802 self.feature_flags.move_native_tx_context
1803 }
1804
1805 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
1806 let pre_consensus_sponsor_only_move_authentication = self
1807 .feature_flags
1808 .pre_consensus_sponsor_only_move_authentication;
1809 if pre_consensus_sponsor_only_move_authentication {
1810 assert!(
1811 self.enable_move_authentication(),
1812 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
1813 );
1814 assert!(
1815 self.enable_move_authentication_for_sponsor(),
1816 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
1817 );
1818 }
1819 pre_consensus_sponsor_only_move_authentication
1820 }
1821
1822 pub fn consensus_starfish_speed(&self) -> bool {
1823 let res = self.feature_flags.consensus_starfish_speed;
1824 assert!(
1825 !res || self.consensus_fast_commit_sync(),
1826 "consensus_starfish_speed requires consensus_fast_commit_sync to be enabled"
1827 );
1828 res
1829 }
1830
1831 pub fn always_advance_dkg_to_resolution(&self) -> bool {
1832 self.feature_flags.always_advance_dkg_to_resolution
1833 }
1834
1835 pub fn enable_pcool_flow(&self) -> bool {
1836 self.feature_flags.enable_pcool_flow
1837 }
1838
1839 pub fn validator_metadata_verify_v2(&self) -> bool {
1840 self.feature_flags.validator_metadata_verify_v2
1841 }
1842
1843 pub fn commits_per_schedule(&self) -> u32 {
1844 if cfg!(msim) {
1845 min(10, self.consensus_commits_per_schedule.unwrap_or(300))
1847 } else {
1848 self.consensus_commits_per_schedule.unwrap_or(300)
1849 }
1850 }
1851
1852 pub fn deny_rule_governance(&self) -> bool {
1853 self.feature_flags.deny_rule_governance
1854 }
1855
1856 pub fn package_metadata_with_dynamic_module_metadata(&self) -> bool {
1857 let res = self
1858 .feature_flags
1859 .package_metadata_with_dynamic_module_metadata;
1860 assert!(
1861 !res || self.publish_package_metadata(),
1862 "package_metadata_with_dynamic_module_metadata requires publish_package_metadata to be enabled"
1863 );
1864 res
1865 }
1866
1867 pub fn report_move_authentication_error(&self) -> bool {
1868 let report_move_authentication_error = self.feature_flags.report_move_authentication_error;
1869 assert!(
1870 !report_move_authentication_error || self.enable_move_authentication(),
1871 "report_move_authentication_error requires enable_move_authentication to be set"
1872 );
1873 report_move_authentication_error
1874 }
1875}
1876
1877#[cfg(not(msim))]
1878static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1879
1880#[cfg(msim)]
1882thread_local! {
1883 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1884}
1885
1886impl ProtocolConfig {
1888 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1891 assert!(
1893 version >= ProtocolVersion::MIN,
1894 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1895 version,
1896 ProtocolVersion::MIN.0,
1897 );
1898 assert!(
1899 version <= ProtocolVersion::MAX_ALLOWED,
1900 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1901 version,
1902 ProtocolVersion::MAX_ALLOWED.0,
1903 );
1904
1905 let mut ret = Self::get_for_version_impl(version, chain);
1906 ret.version = version;
1907
1908 ret = CONFIG_OVERRIDE.with(|ovr| {
1909 if let Some(override_fn) = &*ovr.borrow() {
1910 warn!(
1911 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1912 );
1913 override_fn(version, ret)
1914 } else {
1915 ret
1916 }
1917 });
1918
1919 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1920 warn!(
1921 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1922 );
1923
1924 let overrides: ProtocolConfigOptional =
1926 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1927 .expect("failed to parse ProtocolConfig override env variables");
1928 overrides.apply_to(&mut ret);
1929
1930 let feature_flag_overrides: FeatureFlagsOptional =
1932 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_FEATURE_FLAGS_OVERRIDE")
1933 .expect("failed to parse ProtocolConfig feature flags override env variables");
1934
1935 feature_flag_overrides.apply_to(&mut ret.feature_flags);
1936 }
1937
1938 ret
1939 }
1940
1941 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1944 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1945 let mut ret = Self::get_for_version_impl(version, chain);
1946 ret.version = version;
1947 Some(ret)
1948 } else {
1949 None
1950 }
1951 }
1952
1953 #[cfg(not(msim))]
1954 pub fn poison_get_for_min_version() {
1955 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1956 }
1957
1958 #[cfg(not(msim))]
1959 fn load_poison_get_for_min_version() -> bool {
1960 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1961 }
1962
1963 #[cfg(msim)]
1964 pub fn poison_get_for_min_version() {
1965 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1966 }
1967
1968 #[cfg(msim)]
1969 fn load_poison_get_for_min_version() -> bool {
1970 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1971 }
1972
1973 pub fn convert_type_argument_error(&self) -> bool {
1974 self.feature_flags.convert_type_argument_error
1975 }
1976
1977 pub fn get_for_min_version() -> Self {
1981 if Self::load_poison_get_for_min_version() {
1982 panic!("get_for_min_version called on validator");
1983 }
1984 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1985 }
1986
1987 #[expect(non_snake_case)]
1998 pub fn get_for_max_version_UNSAFE() -> Self {
1999 if Self::load_poison_get_for_min_version() {
2000 panic!("get_for_max_version_UNSAFE called on validator");
2001 }
2002 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
2003 }
2004
2005 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
2006 #[cfg(msim)]
2007 {
2008 if version > ProtocolVersion::MAX {
2010 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
2011 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
2012 return config;
2013 }
2014 }
2015
2016 let mut cfg = Self {
2020 version,
2021
2022 feature_flags: Default::default(),
2023
2024 max_tx_size_bytes: Some(128 * 1024),
2025 max_input_objects: Some(2048),
2028 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
2029 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
2030 max_gas_payment_objects: Some(256),
2031 max_modules_in_publish: Some(64),
2032 max_package_dependencies: Some(32),
2033 max_arguments: Some(512),
2034 max_type_arguments: Some(16),
2035 max_type_argument_depth: Some(16),
2036 max_pure_argument_size: Some(16 * 1024),
2037 max_programmable_tx_commands: Some(1024),
2038 move_binary_format_version: Some(7),
2039 min_move_binary_format_version: Some(6),
2040 binary_module_handles: Some(100),
2041 binary_struct_handles: Some(300),
2042 binary_function_handles: Some(1500),
2043 binary_function_instantiations: Some(750),
2044 binary_signatures: Some(1000),
2045 binary_constant_pool: Some(4000),
2046 binary_identifiers: Some(10000),
2047 binary_address_identifiers: Some(100),
2048 binary_struct_defs: Some(200),
2049 binary_struct_def_instantiations: Some(100),
2050 binary_function_defs: Some(1000),
2051 binary_field_handles: Some(500),
2052 binary_field_instantiations: Some(250),
2053 binary_friend_decls: Some(100),
2054 binary_enum_defs: None,
2055 binary_enum_def_instantiations: None,
2056 binary_variant_handles: None,
2057 binary_variant_instantiation_handles: None,
2058 max_move_object_size: Some(250 * 1024),
2059 max_move_package_size: Some(100 * 1024),
2060 max_publish_or_upgrade_per_ptb: Some(5),
2061 max_auth_gas: None,
2063 max_tx_gas: Some(50_000_000_000),
2065 max_gas_price: Some(100_000),
2066 max_gas_computation_bucket: Some(5_000_000),
2067 max_loop_depth: Some(5),
2068 max_generic_instantiation_length: Some(32),
2069 max_function_parameters: Some(128),
2070 max_basic_blocks: Some(1024),
2071 max_value_stack_size: Some(1024),
2072 max_type_nodes: Some(256),
2073 max_push_size: Some(10000),
2074 max_struct_definitions: Some(200),
2075 max_function_definitions: Some(1000),
2076 max_fields_in_struct: Some(32),
2077 max_dependency_depth: Some(100),
2078 max_num_event_emit: Some(1024),
2079 max_num_new_move_object_ids: Some(2048),
2080 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
2081 max_num_deleted_move_object_ids: Some(2048),
2082 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
2083 max_num_transferred_move_object_ids: Some(2048),
2084 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
2085 max_event_emit_size: Some(250 * 1024),
2086 max_move_vector_len: Some(256 * 1024),
2087 max_type_to_layout_nodes: None,
2088 max_ptb_value_size: None,
2089
2090 max_back_edges_per_function: Some(10_000),
2091 max_back_edges_per_module: Some(10_000),
2092
2093 max_verifier_meter_ticks_per_function: Some(16_000_000),
2094
2095 max_meter_ticks_per_module: Some(16_000_000),
2096 max_meter_ticks_per_package: Some(16_000_000),
2097
2098 object_runtime_max_num_cached_objects: Some(1000),
2099 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2100 object_runtime_max_num_store_entries: Some(1000),
2101 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2102 base_tx_cost_fixed: Some(1_000),
2104 package_publish_cost_fixed: Some(1_000),
2105 base_tx_cost_per_byte: Some(0),
2106 package_publish_cost_per_byte: Some(80),
2107 obj_access_cost_read_per_byte: Some(15),
2108 obj_access_cost_mutate_per_byte: Some(40),
2109 obj_access_cost_delete_per_byte: Some(40),
2110 obj_access_cost_verify_per_byte: Some(200),
2111 obj_data_cost_refundable: Some(100),
2112 obj_metadata_cost_non_refundable: Some(50),
2113 gas_model_version: Some(1),
2114 storage_rebate_rate: Some(10000),
2115 reward_slashing_rate: Some(10000),
2117 storage_gas_price: Some(76),
2118 base_gas_price: None,
2119 validator_target_reward: Some(767_000 * 1_000_000_000),
2122 max_transactions_per_checkpoint: Some(10_000),
2123 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2124
2125 buffer_stake_for_protocol_upgrade_bps: Some(5000),
2127
2128 address_from_bytes_cost_base: Some(52),
2132 address_to_u256_cost_base: Some(52),
2134 address_from_u256_cost_base: Some(52),
2136
2137 config_read_setting_impl_cost_base: Some(100),
2140 config_read_setting_impl_cost_per_byte: Some(40),
2141
2142 dynamic_field_hash_type_and_key_cost_base: Some(100),
2146 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
2147 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
2148 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
2149 dynamic_field_add_child_object_cost_base: Some(100),
2152 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2153 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2154 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2155 dynamic_field_borrow_child_object_cost_base: Some(100),
2158 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2159 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2160 dynamic_field_remove_child_object_cost_base: Some(100),
2163 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2164 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2165 dynamic_field_has_child_object_cost_base: Some(100),
2168 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2171 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2172 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2173
2174 event_emit_cost_base: Some(52),
2177 event_emit_value_size_derivation_cost_per_byte: Some(2),
2178 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2179 event_emit_output_cost_per_byte: Some(10),
2180
2181 object_borrow_uid_cost_base: Some(52),
2184 object_delete_impl_cost_base: Some(52),
2186 object_record_new_uid_cost_base: Some(52),
2188
2189 transfer_transfer_internal_cost_base: Some(52),
2193 transfer_freeze_object_cost_base: Some(52),
2195 transfer_share_object_cost_base: Some(52),
2197 transfer_receive_object_cost_base: Some(52),
2198
2199 tx_context_derive_id_cost_base: Some(52),
2203 tx_context_fresh_id_cost_base: None,
2204 tx_context_sender_cost_base: None,
2205 tx_context_digest_cost_base: None,
2206 tx_context_epoch_cost_base: None,
2207 tx_context_epoch_timestamp_ms_cost_base: None,
2208 tx_context_sponsor_cost_base: None,
2209 tx_context_rgp_cost_base: None,
2210 tx_context_gas_price_cost_base: None,
2211 tx_context_gas_budget_cost_base: None,
2212 tx_context_ids_created_cost_base: None,
2213 tx_context_replace_cost_base: None,
2214
2215 types_is_one_time_witness_cost_base: Some(52),
2218 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2219 types_is_one_time_witness_type_cost_per_byte: Some(2),
2220
2221 validator_validate_metadata_cost_base: Some(52),
2225 validator_validate_metadata_data_cost_per_byte: Some(2),
2226
2227 crypto_invalid_arguments_cost: Some(100),
2229 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2231 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2232 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2233
2234 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2236 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2237 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2238
2239 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2241 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2242 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2243 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2244 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2245 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2246
2247 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2249
2250 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2252 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2253 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2254 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2255 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2256 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2257
2258 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2260 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2261 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2262 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2263 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2264 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2265
2266 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2268 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2269 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2270 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2271 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2272 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2273
2274 ecvrf_ecvrf_verify_cost_base: Some(52),
2276 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2277 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2278
2279 ed25519_ed25519_verify_cost_base: Some(52),
2281 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2282 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2283
2284 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2286 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2287
2288 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2290 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2291 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2292 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2293 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2294
2295 hash_blake2b256_cost_base: Some(52),
2297 hash_blake2b256_data_cost_per_byte: Some(2),
2298 hash_blake2b256_data_cost_per_block: Some(2),
2299 hash_keccak256_cost_base: Some(52),
2301 hash_keccak256_data_cost_per_byte: Some(2),
2302 hash_keccak256_data_cost_per_block: Some(2),
2303
2304 poseidon_bn254_cost_base: None,
2305 poseidon_bn254_cost_per_block: None,
2306
2307 hmac_hmac_sha3_256_cost_base: Some(52),
2309 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2310 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2311
2312 group_ops_bls12381_decode_scalar_cost: Some(52),
2314 group_ops_bls12381_decode_g1_cost: Some(52),
2315 group_ops_bls12381_decode_g2_cost: Some(52),
2316 group_ops_bls12381_decode_gt_cost: Some(52),
2317 group_ops_bls12381_scalar_add_cost: Some(52),
2318 group_ops_bls12381_g1_add_cost: Some(52),
2319 group_ops_bls12381_g2_add_cost: Some(52),
2320 group_ops_bls12381_gt_add_cost: Some(52),
2321 group_ops_bls12381_scalar_sub_cost: Some(52),
2322 group_ops_bls12381_g1_sub_cost: Some(52),
2323 group_ops_bls12381_g2_sub_cost: Some(52),
2324 group_ops_bls12381_gt_sub_cost: Some(52),
2325 group_ops_bls12381_scalar_mul_cost: Some(52),
2326 group_ops_bls12381_g1_mul_cost: Some(52),
2327 group_ops_bls12381_g2_mul_cost: Some(52),
2328 group_ops_bls12381_gt_mul_cost: Some(52),
2329 group_ops_bls12381_scalar_div_cost: Some(52),
2330 group_ops_bls12381_g1_div_cost: Some(52),
2331 group_ops_bls12381_g2_div_cost: Some(52),
2332 group_ops_bls12381_gt_div_cost: Some(52),
2333 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2334 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2335 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2336 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2337 group_ops_bls12381_g1_msm_base_cost: Some(52),
2338 group_ops_bls12381_g2_msm_base_cost: Some(52),
2339 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2340 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2341 group_ops_bls12381_msm_max_len: Some(32),
2342 group_ops_bls12381_pairing_cost: Some(52),
2343 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2344 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2345 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2346 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2347 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2348
2349 #[allow(deprecated)]
2351 check_zklogin_id_cost_base: Some(200),
2352 #[allow(deprecated)]
2353 check_zklogin_issuer_cost_base: Some(200),
2355
2356 vdf_verify_vdf_cost: None,
2357 vdf_hash_to_input_cost: None,
2358
2359 bcs_per_byte_serialized_cost: Some(2),
2360 bcs_legacy_min_output_size_cost: Some(1),
2361 bcs_failure_cost: Some(52),
2362 hash_sha2_256_base_cost: Some(52),
2363 hash_sha2_256_per_byte_cost: Some(2),
2364 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2365 hash_sha3_256_base_cost: Some(52),
2366 hash_sha3_256_per_byte_cost: Some(2),
2367 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2368 type_name_get_base_cost: Some(52),
2369 type_name_get_per_byte_cost: Some(2),
2370 string_check_utf8_base_cost: Some(52),
2371 string_check_utf8_per_byte_cost: Some(2),
2372 string_is_char_boundary_base_cost: Some(52),
2373 string_sub_string_base_cost: Some(52),
2374 string_sub_string_per_byte_cost: Some(2),
2375 string_index_of_base_cost: Some(52),
2376 string_index_of_per_byte_pattern_cost: Some(2),
2377 string_index_of_per_byte_searched_cost: Some(2),
2378 vector_empty_base_cost: Some(52),
2379 vector_length_base_cost: Some(52),
2380 vector_push_back_base_cost: Some(52),
2381 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2382 vector_borrow_base_cost: Some(52),
2383 vector_pop_back_base_cost: Some(52),
2384 vector_destroy_empty_base_cost: Some(52),
2385 vector_swap_base_cost: Some(52),
2386 debug_print_base_cost: Some(52),
2387 debug_print_stack_trace_base_cost: Some(52),
2388
2389 max_size_written_objects: Some(5 * 1000 * 1000),
2390 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2393
2394 max_move_identifier_len: Some(128),
2396 max_move_value_depth: Some(128),
2397 max_move_enum_variants: None,
2398
2399 gas_rounding_step: Some(1_000),
2400
2401 execution_version: Some(1),
2402
2403 max_event_emit_size_total: Some(
2406 256 * 250 * 1024, ),
2408
2409 consensus_bad_nodes_stake_threshold: Some(20),
2416
2417 #[allow(deprecated)]
2419 max_jwk_votes_per_validator_per_epoch: Some(240),
2420
2421 #[allow(deprecated)]
2422 max_age_of_jwk_in_epochs: Some(1),
2423
2424 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2428
2429 random_beacon_reduction_allowed_delta: Some(800),
2430
2431 random_beacon_reduction_lower_bound: Some(1000),
2432 random_beacon_dkg_timeout_round: Some(3000),
2433 random_beacon_min_round_interval_ms: Some(500),
2434
2435 random_beacon_dkg_version: Some(1),
2436
2437 consensus_max_num_transactions_in_block: Some(512),
2441
2442 max_deferral_rounds_for_congestion_control: Some(10),
2443
2444 min_checkpoint_interval_ms: Some(200),
2445
2446 checkpoint_rate_window_size: None,
2447
2448 checkpoint_summary_version_specific_data: Some(1),
2449
2450 max_soft_bundle_size: Some(5),
2451
2452 bridge_should_try_to_finalize_committee: None,
2453
2454 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2455
2456 max_committee_members_count: None,
2457
2458 consensus_gc_depth: None,
2459
2460 consensus_max_acknowledgments_per_block: None,
2461
2462 max_congestion_limit_overshoot_per_commit: None,
2463
2464 scorer_version: None,
2465
2466 auth_context_digest_cost_base: None,
2468 auth_context_tx_data_bytes_cost_base: None,
2469 auth_context_tx_data_bytes_cost_per_byte: None,
2470 auth_context_tx_commands_cost_base: None,
2471 auth_context_tx_commands_cost_per_byte: None,
2472 auth_context_tx_inputs_cost_base: None,
2473 auth_context_tx_inputs_cost_per_byte: None,
2474 auth_context_replace_cost_base: None,
2475 auth_context_replace_cost_per_byte: None,
2476 auth_context_authenticator_function_info_v1_cost_base: None,
2477 consensus_commits_per_schedule: None,
2478 };
2481
2482 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2483
2484 {
2486 cfg.feature_flags
2487 .disable_invariant_violation_check_in_swap_loc = true;
2488 cfg.feature_flags.no_extraneous_module_bytes = true;
2489 cfg.feature_flags.hardened_otw_check = true;
2490 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2491 }
2492
2493 {
2495 #[allow(deprecated)]
2496 {
2497 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2498 }
2499 }
2500
2501 #[expect(deprecated)]
2505 {
2506 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2507 }
2508 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2510
2511 cfg.feature_flags.per_object_congestion_control_mode =
2512 PerObjectCongestionControlMode::TotalTxCount;
2513
2514 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2516
2517 if chain != Chain::Mainnet && chain != Chain::Testnet {
2519 cfg.feature_flags.enable_poseidon = true;
2520 cfg.poseidon_bn254_cost_base = Some(260);
2521 cfg.poseidon_bn254_cost_per_block = Some(10);
2522
2523 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2524
2525 cfg.feature_flags.enable_vdf = true;
2526 cfg.vdf_verify_vdf_cost = Some(1500);
2529 cfg.vdf_hash_to_input_cost = Some(100);
2530
2531 cfg.feature_flags.passkey_auth = true;
2532 }
2533
2534 for cur in 2..=version.0 {
2535 match cur {
2536 1 => unreachable!(),
2537 2 => {}
2539 3 => {
2540 cfg.feature_flags.relocate_event_module = true;
2541 }
2542 4 => {
2543 cfg.max_type_to_layout_nodes = Some(512);
2544 }
2545 5 => {
2546 cfg.feature_flags.protocol_defined_base_fee = true;
2547 cfg.base_gas_price = Some(1000);
2548
2549 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2550 cfg.feature_flags.convert_type_argument_error = true;
2551 cfg.feature_flags.native_charging_v2 = true;
2552
2553 if chain != Chain::Mainnet && chain != Chain::Testnet {
2554 cfg.feature_flags.uncompressed_g1_group_elements = true;
2555 }
2556
2557 cfg.gas_model_version = Some(2);
2558
2559 cfg.poseidon_bn254_cost_per_block = Some(388);
2560
2561 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2562 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2563 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2564 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2565 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2566 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2567 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2568 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2569
2570 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2572 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2573 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2574 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2575
2576 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2577 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2578 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2579 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2580 Some(8213);
2581 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2582 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2583 Some(9484);
2584
2585 cfg.hash_keccak256_cost_base = Some(10);
2586 cfg.hash_blake2b256_cost_base = Some(10);
2587
2588 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2590 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2591 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2592 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2593
2594 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2595 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2596 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2597 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2598
2599 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2600 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2601 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2602 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2603
2604 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2605 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2606 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2607 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2608
2609 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2610 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2611 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2612 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2613
2614 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2615 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2616
2617 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2618 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2619 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2620 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2621
2622 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2623 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2624 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2625 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2626 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2627
2628 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2629
2630 cfg.validator_validate_metadata_cost_base = Some(20000);
2631
2632 cfg.max_committee_members_count = Some(50);
2633 }
2634 6 => {
2635 cfg.max_ptb_value_size = Some(1024 * 1024);
2636 }
2637 7 => {
2638 }
2641 8 => {
2642 cfg.feature_flags.variant_nodes = true;
2643
2644 if chain != Chain::Mainnet {
2645 cfg.feature_flags.consensus_round_prober = true;
2647 cfg.feature_flags
2649 .consensus_distributed_vote_scoring_strategy = true;
2650 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2651 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2653 cfg.feature_flags
2655 .consensus_round_prober_probe_accepted_rounds = true;
2656 cfg.feature_flags.consensus_zstd_compression = true;
2658 cfg.consensus_gc_depth = Some(60);
2662 }
2663
2664 if chain != Chain::Testnet && chain != Chain::Mainnet {
2667 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2668 }
2669 }
2670 9 => {
2671 if chain != Chain::Mainnet {
2672 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2674 }
2675
2676 cfg.feature_flags.consensus_zstd_compression = true;
2678
2679 if chain != Chain::Testnet && chain != Chain::Mainnet {
2681 cfg.feature_flags.accept_passkey_in_multisig = true;
2682 }
2683
2684 cfg.bridge_should_try_to_finalize_committee = None;
2686 }
2687 10 => {
2688 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2691
2692 cfg.max_committee_members_count = Some(80);
2694
2695 cfg.feature_flags.consensus_round_prober = true;
2697 cfg.feature_flags
2699 .consensus_round_prober_probe_accepted_rounds = true;
2700 cfg.feature_flags
2702 .consensus_distributed_vote_scoring_strategy = true;
2703 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2705
2706 cfg.consensus_gc_depth = Some(60);
2711
2712 cfg.feature_flags.minimize_child_object_mutations = true;
2714
2715 if chain != Chain::Mainnet {
2716 cfg.feature_flags.consensus_batched_block_sync = true;
2718 }
2719
2720 if chain != Chain::Testnet && chain != Chain::Mainnet {
2721 cfg.feature_flags
2724 .congestion_control_gas_price_feedback_mechanism = true;
2725 }
2726
2727 cfg.feature_flags.validate_identifier_inputs = true;
2728 cfg.feature_flags.dependency_linkage_error = true;
2729 cfg.feature_flags.additional_multisig_checks = true;
2730 }
2731 11 => {
2732 }
2735 12 => {
2736 cfg.feature_flags
2739 .congestion_control_gas_price_feedback_mechanism = true;
2740
2741 cfg.feature_flags.normalize_ptb_arguments = true;
2743 }
2744 13 => {
2745 cfg.feature_flags.select_committee_from_eligible_validators = true;
2748 cfg.feature_flags.track_non_committee_eligible_validators = true;
2751
2752 if chain != Chain::Testnet && chain != Chain::Mainnet {
2753 cfg.feature_flags
2756 .select_committee_supporting_next_epoch_version = true;
2757 }
2758 }
2759 14 => {
2760 cfg.feature_flags.consensus_batched_block_sync = true;
2762
2763 if chain != Chain::Mainnet {
2764 cfg.feature_flags
2767 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2768 cfg.feature_flags
2772 .select_committee_supporting_next_epoch_version = true;
2773 }
2774 if chain != Chain::Testnet && chain != Chain::Mainnet {
2775 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2777 }
2778 }
2779 15 => {
2780 if chain != Chain::Mainnet && chain != Chain::Testnet {
2781 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2785 }
2786 }
2787 16 => {
2788 cfg.feature_flags
2791 .select_committee_supporting_next_epoch_version = true;
2792 cfg.feature_flags
2794 .consensus_commit_transactions_only_for_traversed_headers = true;
2795 }
2796 17 => {
2797 cfg.max_committee_members_count = Some(100);
2799 }
2800 18 => {
2801 if chain != Chain::Mainnet {
2802 cfg.feature_flags.passkey_auth = true;
2804 }
2805 }
2806 19 => {
2807 if chain != Chain::Testnet && chain != Chain::Mainnet {
2808 cfg.feature_flags
2811 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2812 cfg.feature_flags
2815 .separate_gas_price_feedback_mechanism_for_randomness = true;
2816 cfg.feature_flags.metadata_in_module_bytes = true;
2819 cfg.feature_flags.publish_package_metadata = true;
2820 cfg.feature_flags.enable_move_authentication = true;
2822 cfg.max_auth_gas = Some(250_000_000);
2824 cfg.transfer_receive_object_cost_base = Some(100);
2827 cfg.feature_flags.adjust_rewards_by_score = true;
2829 }
2830
2831 if chain != Chain::Mainnet {
2832 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2834
2835 cfg.feature_flags.calculate_validator_scores = true;
2837 cfg.scorer_version = Some(1);
2838 }
2839
2840 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
2842
2843 cfg.feature_flags.passkey_auth = true;
2845 }
2846 20 => {
2847 if chain != Chain::Testnet && chain != Chain::Mainnet {
2848 cfg.feature_flags
2850 .pass_calculated_validator_scores_to_advance_epoch = true;
2851 }
2852 }
2853 21 => {
2854 if chain != Chain::Testnet && chain != Chain::Mainnet {
2855 cfg.feature_flags.consensus_fast_commit_sync = true;
2857 }
2858 if chain != Chain::Mainnet {
2859 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2864 cfg.feature_flags
2867 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2868 cfg.feature_flags
2871 .separate_gas_price_feedback_mechanism_for_randomness = true;
2872 }
2873
2874 cfg.auth_context_digest_cost_base = Some(30);
2875 cfg.auth_context_tx_commands_cost_base = Some(30);
2876 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
2877 cfg.auth_context_tx_inputs_cost_base = Some(30);
2878 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
2879 cfg.auth_context_replace_cost_base = Some(30);
2880 cfg.auth_context_replace_cost_per_byte = Some(2);
2881
2882 if chain != Chain::Testnet && chain != Chain::Mainnet {
2883 cfg.max_auth_gas = Some(250_000);
2885 }
2886 }
2887 22 => {
2888 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2893 cfg.feature_flags
2896 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2897 cfg.feature_flags
2900 .separate_gas_price_feedback_mechanism_for_randomness = true;
2901
2902 if chain != Chain::Mainnet {
2903 cfg.feature_flags.metadata_in_module_bytes = true;
2906 cfg.feature_flags.publish_package_metadata = true;
2907 cfg.feature_flags.enable_move_authentication = true;
2909 cfg.max_auth_gas = Some(250_000);
2911 cfg.transfer_receive_object_cost_base = Some(100);
2914 }
2915
2916 if chain != Chain::Mainnet {
2917 cfg.feature_flags.consensus_fast_commit_sync = true;
2919 }
2920 }
2921 23 => {
2922 cfg.feature_flags.move_native_tx_context = true;
2924 cfg.tx_context_fresh_id_cost_base = Some(52);
2925 cfg.tx_context_sender_cost_base = Some(30);
2926 cfg.tx_context_digest_cost_base = Some(30);
2927 cfg.tx_context_epoch_cost_base = Some(30);
2928 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
2929 cfg.tx_context_sponsor_cost_base = Some(30);
2930 cfg.tx_context_rgp_cost_base = Some(30);
2931 cfg.tx_context_gas_price_cost_base = Some(30);
2932 cfg.tx_context_gas_budget_cost_base = Some(30);
2933 cfg.tx_context_ids_created_cost_base = Some(30);
2934 cfg.tx_context_replace_cost_base = Some(30);
2935 }
2936 24 => {
2937 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2939
2940 if chain != Chain::Testnet && chain != Chain::Mainnet {
2941 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2943 }
2944
2945 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
2948 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
2949
2950 cfg.feature_flags.additional_borrow_checks = true;
2952 }
2953 #[allow(deprecated)]
2954 25 => {
2955 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
2958 cfg.check_zklogin_id_cost_base = None;
2959 cfg.check_zklogin_issuer_cost_base = None;
2960 cfg.max_jwk_votes_per_validator_per_epoch = None;
2961 cfg.max_age_of_jwk_in_epochs = None;
2962 }
2963 26 => {
2964 }
2967 27 => {
2968 if chain != Chain::Mainnet {
2969 cfg.feature_flags.consensus_block_restrictions = true;
2972 }
2973
2974 if chain != Chain::Testnet && chain != Chain::Mainnet {
2975 cfg.feature_flags
2977 .pre_consensus_sponsor_only_move_authentication = true;
2978 }
2979 }
2980 28 => {
2981 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
2986
2987 cfg.feature_flags.metadata_in_module_bytes = true;
2990 cfg.feature_flags.publish_package_metadata = true;
2991 cfg.feature_flags.enable_move_authentication = true;
2993 cfg.transfer_receive_object_cost_base = Some(100);
2996
2997 if chain != Chain::Unknown {
2998 cfg.max_auth_gas = Some(20_000);
3000 }
3001
3002 if chain != Chain::Mainnet {
3003 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3005 cfg.feature_flags
3007 .pre_consensus_sponsor_only_move_authentication = true;
3008 }
3009 }
3010 29 => {
3011 cfg.feature_flags.always_advance_dkg_to_resolution = true;
3017
3018 cfg.feature_flags
3021 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3022
3023 cfg.feature_flags.consensus_fast_commit_sync = true;
3025 cfg.feature_flags.consensus_block_restrictions = true;
3029 }
3030 30 => {
3031 }
3039 31 => {
3040 cfg.feature_flags.validator_metadata_verify_v2 = true;
3041
3042 if chain != Chain::Mainnet && chain != Chain::Testnet {
3043 cfg.checkpoint_rate_window_size = Some(20);
3046 cfg.feature_flags
3049 .package_metadata_with_dynamic_module_metadata = true;
3050 cfg.feature_flags.consensus_starfish_speed = true;
3053 }
3054
3055 cfg.feature_flags.report_move_authentication_error = true;
3056 }
3057 _ => panic!("unsupported version {version:?}"),
3068 }
3069 }
3070 cfg
3071 }
3072
3073 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
3079 let (
3080 max_back_edges_per_function,
3081 max_back_edges_per_module,
3082 sanity_check_with_regex_reference_safety,
3083 ) = if let Some((
3084 max_back_edges_per_function,
3085 max_back_edges_per_module,
3086 sanity_check_with_regex_reference_safety,
3087 )) = signing_limits
3088 {
3089 (
3090 Some(max_back_edges_per_function),
3091 Some(max_back_edges_per_module),
3092 Some(sanity_check_with_regex_reference_safety),
3093 )
3094 } else {
3095 (None, None, None)
3096 };
3097
3098 let additional_borrow_checks = if signing_limits.is_some() {
3099 true
3102 } else {
3103 self.additional_borrow_checks()
3104 };
3105
3106 VerifierConfig {
3107 max_loop_depth: Some(self.max_loop_depth() as usize),
3108 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
3109 max_function_parameters: Some(self.max_function_parameters() as usize),
3110 max_basic_blocks: Some(self.max_basic_blocks() as usize),
3111 max_value_stack_size: self.max_value_stack_size() as usize,
3112 max_type_nodes: Some(self.max_type_nodes() as usize),
3113 max_push_size: Some(self.max_push_size() as usize),
3114 max_dependency_depth: Some(self.max_dependency_depth() as usize),
3115 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
3116 max_function_definitions: Some(self.max_function_definitions() as usize),
3117 max_data_definitions: Some(self.max_struct_definitions() as usize),
3118 max_constant_vector_len: Some(self.max_move_vector_len()),
3119 max_back_edges_per_function,
3120 max_back_edges_per_module,
3121 max_basic_blocks_in_script: None,
3122 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
3126 max_variants_in_enum: self.max_move_enum_variants_as_option(),
3127 additional_borrow_checks,
3128 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
3129 .map(|limit| limit as u128),
3130 }
3131 }
3132
3133 pub fn apply_overrides_for_testing(
3138 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
3139 ) -> OverrideGuard {
3140 CONFIG_OVERRIDE.with(|ovr| {
3141 let mut cur = ovr.borrow_mut();
3142 assert!(cur.is_none(), "config override already present");
3143 *cur = Some(Box::new(override_fn));
3144 OverrideGuard
3145 })
3146 }
3147}
3148
3149impl ProtocolConfig {
3154 pub fn set_per_object_congestion_control_mode_for_testing(
3155 &mut self,
3156 val: PerObjectCongestionControlMode,
3157 ) {
3158 self.feature_flags.per_object_congestion_control_mode = val;
3159 }
3160
3161 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
3162 self.feature_flags.consensus_choice = val;
3163 }
3164
3165 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
3166 self.feature_flags.consensus_network = val;
3167 }
3168
3169 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
3170 self.feature_flags.passkey_auth = val
3171 }
3172
3173 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
3174 self.feature_flags
3175 .disallow_new_modules_in_deps_only_packages = val;
3176 }
3177
3178 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
3179 self.feature_flags.consensus_round_prober = val;
3180 }
3181
3182 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
3183 self.feature_flags
3184 .consensus_distributed_vote_scoring_strategy = val;
3185 }
3186
3187 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
3188 self.consensus_gc_depth = Some(val);
3189 }
3190
3191 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
3192 self.feature_flags.consensus_linearize_subdag_v2 = val;
3193 }
3194
3195 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
3196 self.feature_flags
3197 .consensus_round_prober_probe_accepted_rounds = val;
3198 }
3199
3200 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
3201 self.feature_flags.accept_passkey_in_multisig = val;
3202 }
3203
3204 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
3205 self.feature_flags.consensus_smart_ancestor_selection = val;
3206 }
3207
3208 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
3209 self.feature_flags.consensus_batched_block_sync = val;
3210 }
3211
3212 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
3213 self.feature_flags
3214 .congestion_control_min_free_execution_slot = val;
3215 }
3216
3217 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
3218 self.feature_flags
3219 .congestion_control_gas_price_feedback_mechanism = val;
3220 }
3221
3222 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
3223 self.feature_flags.select_committee_from_eligible_validators = val;
3224 }
3225
3226 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
3227 self.feature_flags.track_non_committee_eligible_validators = val;
3228 }
3229
3230 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
3231 self.feature_flags
3232 .select_committee_supporting_next_epoch_version = val;
3233 }
3234
3235 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
3236 &mut self,
3237 val: bool,
3238 ) {
3239 self.feature_flags
3240 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3241 }
3242
3243 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3244 &mut self,
3245 val: bool,
3246 ) {
3247 self.feature_flags
3248 .consensus_commit_transactions_only_for_traversed_headers = val;
3249 }
3250
3251 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3252 &mut self,
3253 val: bool,
3254 ) {
3255 self.feature_flags
3256 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3257 }
3258
3259 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3260 &mut self,
3261 val: bool,
3262 ) {
3263 self.feature_flags
3264 .separate_gas_price_feedback_mechanism_for_randomness = val;
3265 }
3266
3267 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3268 self.feature_flags.metadata_in_module_bytes = val;
3269 }
3270
3271 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3272 self.feature_flags.publish_package_metadata = val;
3273 }
3274
3275 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3276 self.feature_flags.enable_move_authentication = val;
3277 }
3278
3279 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3280 self.feature_flags.enable_move_authentication_for_sponsor = val;
3281 }
3282
3283 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3284 self.feature_flags.consensus_fast_commit_sync = val;
3285 }
3286
3287 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3288 self.feature_flags.consensus_block_restrictions = val;
3289 }
3290
3291 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3292 self.feature_flags
3293 .pre_consensus_sponsor_only_move_authentication = val;
3294 }
3295
3296 pub fn set_consensus_starfish_speed_for_testing(&mut self, val: bool) {
3297 self.feature_flags.consensus_starfish_speed = val;
3298 }
3299
3300 pub fn set_always_advance_dkg_to_resolution_for_testing(&mut self, val: bool) {
3301 self.feature_flags.always_advance_dkg_to_resolution = val;
3302 }
3303
3304 pub fn set_enable_pcool_flow_for_testing(&mut self, val: bool) {
3305 self.feature_flags.enable_pcool_flow = val;
3306 }
3307
3308 pub fn set_commits_per_schedule_for_testing(&mut self, val: u32) {
3309 self.consensus_commits_per_schedule = Some(val);
3310 }
3311
3312 pub fn set_deny_rule_governance_for_testing(&mut self, val: bool) {
3313 self.feature_flags.deny_rule_governance = val;
3314 }
3315
3316 pub fn set_package_metadata_with_dynamic_module_metadata_for_testing(&mut self, val: bool) {
3317 self.feature_flags
3318 .package_metadata_with_dynamic_module_metadata = val;
3319 }
3320
3321 pub fn set_report_move_authentication_error_for_testing(&mut self, val: bool) {
3322 self.feature_flags.report_move_authentication_error = val;
3323 }
3324}
3325
3326type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
3327
3328thread_local! {
3329 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
3330}
3331
3332#[must_use]
3333pub struct OverrideGuard;
3334
3335impl Drop for OverrideGuard {
3336 fn drop(&mut self) {
3337 info!("restoring override fn");
3338 CONFIG_OVERRIDE.with(|ovr| {
3339 *ovr.borrow_mut() = None;
3340 });
3341 }
3342}
3343
3344#[derive(PartialEq, Eq)]
3348pub enum LimitThresholdCrossed {
3349 None,
3350 Soft(u128, u128),
3351 Hard(u128, u128),
3352}
3353
3354pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
3357 x: T,
3358 soft_limit: U,
3359 hard_limit: V,
3360) -> LimitThresholdCrossed {
3361 let x: V = x.into();
3362 let soft_limit: V = soft_limit.into();
3363
3364 debug_assert!(soft_limit <= hard_limit);
3365
3366 if x >= hard_limit {
3369 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
3370 } else if x < soft_limit {
3371 LimitThresholdCrossed::None
3372 } else {
3373 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
3374 }
3375}
3376
3377#[macro_export]
3378macro_rules! check_limit {
3379 ($x:expr, $hard:expr) => {
3380 check_limit!($x, $hard, $hard)
3381 };
3382 ($x:expr, $soft:expr, $hard:expr) => {
3383 check_limit_in_range($x as u64, $soft, $hard)
3384 };
3385}
3386
3387#[macro_export]
3391macro_rules! check_limit_by_meter {
3392 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
3393 let (h, metered_str) = if $is_metered {
3395 ($metered_limit, "metered")
3396 } else {
3397 ($unmetered_hard_limit, "unmetered")
3399 };
3400 use iota_protocol_config::check_limit_in_range;
3401 let result = check_limit_in_range($x as u64, $metered_limit, h);
3402 match result {
3403 LimitThresholdCrossed::None => {}
3404 LimitThresholdCrossed::Soft(_, _) => {
3405 $metric.with_label_values(&[metered_str, "soft"]).inc();
3406 }
3407 LimitThresholdCrossed::Hard(_, _) => {
3408 $metric.with_label_values(&[metered_str, "hard"]).inc();
3409 }
3410 };
3411 result
3412 }};
3413}
3414
3415#[cfg(all(test, not(msim)))]
3416mod test {
3417 use insta::assert_yaml_snapshot;
3418
3419 use super::*;
3420
3421 #[test]
3422 fn snapshot_tests() {
3423 println!("\n============================================================================");
3424 println!("! !");
3425 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
3426 println!("! !");
3427 println!("============================================================================\n");
3428 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
3429 let chain_str = match chain_id {
3434 Chain::Unknown => "".to_string(),
3435 _ => format!("{chain_id:?}_"),
3436 };
3437 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
3438 let cur = ProtocolVersion::new(i);
3439 assert_yaml_snapshot!(
3440 format!("{}version_{}", chain_str, cur.as_u64()),
3441 ProtocolConfig::get_for_version(cur, *chain_id)
3442 );
3443 }
3444 }
3445 }
3446
3447 #[test]
3448 fn test_getters() {
3449 let prot: ProtocolConfig =
3450 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3451 assert_eq!(
3452 prot.max_arguments(),
3453 prot.max_arguments_as_option().unwrap()
3454 );
3455 }
3456
3457 #[test]
3458 fn test_setters() {
3459 let mut prot: ProtocolConfig =
3460 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3461 prot.set_max_arguments_for_testing(123);
3462 assert_eq!(prot.max_arguments(), 123);
3463
3464 prot.set_max_arguments_from_str_for_testing("321".to_string());
3465 assert_eq!(prot.max_arguments(), 321);
3466
3467 prot.disable_max_arguments_for_testing();
3468 assert_eq!(prot.max_arguments_as_option(), None);
3469
3470 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
3471 assert_eq!(prot.max_arguments(), 456);
3472 }
3473
3474 #[test]
3475 #[should_panic(expected = "unsupported version")]
3476 fn max_version_test() {
3477 let _ = ProtocolConfig::get_for_version_impl(
3480 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
3481 Chain::Unknown,
3482 );
3483 }
3484
3485 #[test]
3486 fn lookup_by_string_test() {
3487 let prot: ProtocolConfig =
3488 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3489 assert!(prot.lookup_attr("some random string".to_string()).is_none());
3491
3492 assert!(
3493 prot.lookup_attr("max_arguments".to_string())
3494 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
3495 );
3496
3497 assert!(
3499 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3500 .is_none()
3501 );
3502 assert!(
3503 prot.attr_map()
3504 .get("poseidon_bn254_cost_base")
3505 .unwrap()
3506 .is_none()
3507 );
3508
3509 let prot: ProtocolConfig =
3511 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3512
3513 assert!(
3514 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3515 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3516 );
3517 assert!(
3518 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
3519 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3520 );
3521
3522 let prot: ProtocolConfig =
3524 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3525 assert!(
3527 prot.feature_flags
3528 .lookup_attr("some random string".to_owned())
3529 .is_none()
3530 );
3531 assert!(
3532 !prot
3533 .feature_flags
3534 .attr_map()
3535 .contains_key("some random string")
3536 );
3537
3538 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
3540 assert!(
3541 prot.feature_flags
3542 .attr_map()
3543 .get("enable_poseidon")
3544 .unwrap()
3545 == &false
3546 );
3547 let prot: ProtocolConfig =
3548 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3549 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
3551 assert!(
3552 prot.feature_flags
3553 .attr_map()
3554 .get("enable_poseidon")
3555 .unwrap()
3556 == &true
3557 );
3558 }
3559
3560 #[test]
3561 fn limit_range_fn_test() {
3562 let low = 100u32;
3563 let high = 10000u64;
3564
3565 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
3566 assert!(matches!(
3567 check_limit!(255u16, low, high),
3568 LimitThresholdCrossed::Soft(255u128, 100)
3569 ));
3570 assert!(matches!(
3577 check_limit!(2550000u64, low, high),
3578 LimitThresholdCrossed::Hard(2550000, 10000)
3579 ));
3580
3581 assert!(matches!(
3582 check_limit!(2550000u64, high, high),
3583 LimitThresholdCrossed::Hard(2550000, 10000)
3584 ));
3585
3586 assert!(matches!(
3587 check_limit!(1u8, high),
3588 LimitThresholdCrossed::None
3589 ));
3590
3591 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
3592
3593 assert!(matches!(
3594 check_limit!(2550000u64, high),
3595 LimitThresholdCrossed::Hard(2550000, 10000)
3596 ));
3597 }
3598}