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 = 32;
23
24pub const PROTOCOL_VERSION_IIP8: u64 = 20;
26#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
195pub struct ProtocolVersion(u64);
196
197impl ProtocolVersion {
198 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
204
205 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
206
207 #[cfg(not(msim))]
208 const MAX_ALLOWED: Self = Self::MAX;
209
210 #[cfg(msim)]
213 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
214
215 pub fn new(v: u64) -> Self {
216 Self(v)
217 }
218
219 pub const fn as_u64(&self) -> u64 {
220 self.0
221 }
222
223 pub fn max() -> Self {
226 Self::MAX
227 }
228}
229
230impl From<u64> for ProtocolVersion {
231 fn from(v: u64) -> Self {
232 Self::new(v)
233 }
234}
235
236impl std::ops::Sub<u64> for ProtocolVersion {
237 type Output = Self;
238 fn sub(self, rhs: u64) -> Self::Output {
239 Self::new(self.0 - rhs)
240 }
241}
242
243impl std::ops::Add<u64> for ProtocolVersion {
244 type Output = Self;
245 fn add(self, rhs: u64) -> Self::Output {
246 Self::new(self.0 + rhs)
247 }
248}
249
250#[derive(
251 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
252)]
253pub enum Chain {
254 Mainnet,
255 Testnet,
256 #[default]
257 Unknown,
258}
259
260impl Chain {
261 pub fn as_str(self) -> &'static str {
262 match self {
263 Chain::Mainnet => "mainnet",
264 Chain::Testnet => "testnet",
265 Chain::Unknown => "unknown",
266 }
267 }
268}
269
270pub struct Error(pub String);
271
272#[derive(
276 Default,
277 Clone,
278 Serialize,
279 Deserialize,
280 Debug,
281 ProtocolConfigFeatureFlagsGetters,
282 ProtocolConfigOverride,
283)]
284struct FeatureFlags {
285 #[serde(skip_serializing_if = "is_true")]
291 disable_invariant_violation_check_in_swap_loc: bool,
292
293 #[serde(skip_serializing_if = "is_true")]
296 no_extraneous_module_bytes: bool,
297
298 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
300 consensus_transaction_ordering: ConsensusTransactionOrdering,
301
302 #[serde(skip_serializing_if = "is_true")]
305 hardened_otw_check: bool,
306
307 #[serde(skip_serializing_if = "is_false")]
309 enable_poseidon: bool,
310
311 #[serde(skip_serializing_if = "is_false")]
313 enable_group_ops_native_function_msm: bool,
314
315 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
317 per_object_congestion_control_mode: PerObjectCongestionControlMode,
318
319 #[serde(
321 default = "ConsensusChoice::mysticeti_deprecated",
322 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
323 )]
324 consensus_choice: ConsensusChoice,
325
326 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
328 consensus_network: ConsensusNetwork,
329
330 #[deprecated]
332 #[serde(skip_serializing_if = "Option::is_none")]
333 zklogin_max_epoch_upper_bound_delta: Option<u64>,
334
335 #[serde(skip_serializing_if = "is_false")]
337 enable_vdf: bool,
338
339 #[serde(skip_serializing_if = "is_false")]
341 passkey_auth: bool,
342
343 #[serde(skip_serializing_if = "is_true")]
346 rethrow_serialization_type_layout_errors: bool,
347
348 #[serde(skip_serializing_if = "is_false")]
350 relocate_event_module: bool,
351
352 #[serde(skip_serializing_if = "is_false")]
354 protocol_defined_base_fee: bool,
355
356 #[serde(skip_serializing_if = "is_false")]
358 uncompressed_g1_group_elements: bool,
359
360 #[serde(skip_serializing_if = "is_false")]
362 disallow_new_modules_in_deps_only_packages: bool,
363
364 #[serde(skip_serializing_if = "is_false")]
366 native_charging_v2: bool,
367
368 #[serde(skip_serializing_if = "is_false")]
370 convert_type_argument_error: bool,
371
372 #[serde(skip_serializing_if = "is_false")]
374 consensus_round_prober: bool,
375
376 #[serde(skip_serializing_if = "is_false")]
378 consensus_distributed_vote_scoring_strategy: bool,
379
380 #[serde(skip_serializing_if = "is_false")]
384 consensus_linearize_subdag_v2: bool,
385
386 #[serde(skip_serializing_if = "is_false")]
388 variant_nodes: bool,
389
390 #[serde(skip_serializing_if = "is_false")]
392 consensus_smart_ancestor_selection: bool,
393
394 #[serde(skip_serializing_if = "is_false")]
396 consensus_round_prober_probe_accepted_rounds: bool,
397
398 #[serde(skip_serializing_if = "is_false")]
400 consensus_zstd_compression: bool,
401
402 #[serde(skip_serializing_if = "is_false")]
405 congestion_control_min_free_execution_slot: bool,
406
407 #[serde(skip_serializing_if = "is_false")]
409 accept_passkey_in_multisig: bool,
410
411 #[serde(skip_serializing_if = "is_false")]
413 consensus_batched_block_sync: bool,
414
415 #[serde(skip_serializing_if = "is_false")]
418 congestion_control_gas_price_feedback_mechanism: bool,
419
420 #[serde(skip_serializing_if = "is_false")]
422 validate_identifier_inputs: bool,
423
424 #[serde(skip_serializing_if = "is_false")]
427 minimize_child_object_mutations: bool,
428
429 #[serde(skip_serializing_if = "is_false")]
431 dependency_linkage_error: bool,
432
433 #[serde(skip_serializing_if = "is_false")]
435 additional_multisig_checks: bool,
436
437 #[serde(skip_serializing_if = "is_false")]
440 normalize_ptb_arguments: bool,
441
442 #[serde(skip_serializing_if = "is_false")]
446 select_committee_from_eligible_validators: bool,
447
448 #[serde(skip_serializing_if = "is_false")]
455 track_non_committee_eligible_validators: bool,
456
457 #[serde(skip_serializing_if = "is_false")]
463 select_committee_supporting_next_epoch_version: bool,
464
465 #[serde(skip_serializing_if = "is_false")]
469 consensus_median_timestamp_with_checkpoint_enforcement: bool,
470
471 #[serde(skip_serializing_if = "is_false")]
473 consensus_commit_transactions_only_for_traversed_headers: bool,
474
475 #[serde(skip_serializing_if = "is_false")]
477 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
478
479 #[serde(skip_serializing_if = "is_false")]
482 separate_gas_price_feedback_mechanism_for_randomness: bool,
483
484 #[serde(skip_serializing_if = "is_false")]
487 metadata_in_module_bytes: bool,
488
489 #[serde(skip_serializing_if = "is_false")]
491 publish_package_metadata: bool,
492
493 #[serde(skip_serializing_if = "is_false")]
495 enable_move_authentication: bool,
496
497 #[serde(skip_serializing_if = "is_false")]
499 enable_move_authentication_for_sponsor: bool,
500
501 #[serde(skip_serializing_if = "is_false")]
503 pass_validator_scores_to_advance_epoch: bool,
504
505 #[serde(skip_serializing_if = "is_false")]
507 calculate_validator_scores: bool,
508
509 #[serde(skip_serializing_if = "is_false")]
511 adjust_rewards_by_score: bool,
512
513 #[serde(skip_serializing_if = "is_false")]
516 pass_calculated_validator_scores_to_advance_epoch: bool,
517
518 #[serde(skip_serializing_if = "is_false")]
523 consensus_fast_commit_sync: bool,
524
525 #[serde(skip_serializing_if = "is_false")]
528 consensus_block_restrictions: bool,
529
530 #[serde(skip_serializing_if = "is_false")]
532 move_native_tx_context: bool,
533
534 #[serde(skip_serializing_if = "is_false")]
536 additional_borrow_checks: bool,
537
538 #[serde(skip_serializing_if = "is_false")]
540 pre_consensus_sponsor_only_move_authentication: bool,
541
542 #[serde(skip_serializing_if = "is_false")]
544 consensus_starfish_speed: bool,
545
546 #[serde(skip_serializing_if = "is_false")]
553 always_advance_dkg_to_resolution: bool,
554
555 #[serde(skip_serializing_if = "is_false")]
560 enable_pcool_flow: bool,
561
562 #[serde(skip_serializing_if = "is_false")]
564 validator_metadata_verify_v2: bool,
565
566 #[serde(skip_serializing_if = "is_false")]
570 deny_rule_governance: bool,
571
572 #[serde(skip_serializing_if = "is_false")]
575 package_metadata_with_dynamic_module_metadata: bool,
576
577 #[serde(skip_serializing_if = "is_false")]
580 report_move_authentication_error: bool,
581}
582
583fn is_true(b: &bool) -> bool {
584 *b
585}
586
587fn is_false(b: &bool) -> bool {
588 !b
589}
590
591#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
593pub enum ConsensusTransactionOrdering {
594 #[default]
597 None,
598 ByGasPrice,
600}
601
602impl ConsensusTransactionOrdering {
603 pub fn is_none(&self) -> bool {
604 matches!(self, ConsensusTransactionOrdering::None)
605 }
606}
607
608#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
610pub enum PerObjectCongestionControlMode {
611 #[default]
612 None, TotalGasBudget, TotalTxCount, }
616
617impl PerObjectCongestionControlMode {
618 pub fn is_none(&self) -> bool {
619 matches!(self, PerObjectCongestionControlMode::None)
620 }
621}
622
623#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
625pub enum ConsensusChoice {
626 #[deprecated(note = "Mysticeti was replaced by Starfish")]
629 MysticetiDeprecated,
630 #[default]
631 Starfish,
632}
633
634#[expect(deprecated)]
635impl ConsensusChoice {
636 fn mysticeti_deprecated() -> Self {
643 ConsensusChoice::MysticetiDeprecated
644 }
645
646 pub fn is_mysticeti_deprecated(&self) -> bool {
647 matches!(self, ConsensusChoice::MysticetiDeprecated)
648 }
649 pub fn is_starfish(&self) -> bool {
650 matches!(self, ConsensusChoice::Starfish)
651 }
652}
653
654#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
656pub enum ConsensusNetwork {
657 #[default]
658 Tonic,
659}
660
661impl ConsensusNetwork {
662 pub fn is_tonic(&self) -> bool {
663 matches!(self, ConsensusNetwork::Tonic)
664 }
665}
666
667#[skip_serializing_none]
701#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
702pub struct ProtocolConfig {
703 pub version: ProtocolVersion,
704
705 feature_flags: FeatureFlags,
706
707 max_tx_size_bytes: Option<u64>,
712
713 max_input_objects: Option<u64>,
716
717 max_size_written_objects: Option<u64>,
722 max_size_written_objects_system_tx: Option<u64>,
726
727 max_serialized_tx_effects_size_bytes: Option<u64>,
729
730 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
732
733 max_gas_payment_objects: Option<u32>,
735
736 max_modules_in_publish: Option<u32>,
738
739 max_package_dependencies: Option<u32>,
741
742 max_arguments: Option<u32>,
745
746 max_type_arguments: Option<u32>,
748
749 max_type_argument_depth: Option<u32>,
751
752 max_pure_argument_size: Option<u32>,
754
755 max_programmable_tx_commands: Option<u32>,
757
758 move_binary_format_version: Option<u32>,
764 min_move_binary_format_version: Option<u32>,
765
766 binary_module_handles: Option<u16>,
768 binary_struct_handles: Option<u16>,
769 binary_function_handles: Option<u16>,
770 binary_function_instantiations: Option<u16>,
771 binary_signatures: Option<u16>,
772 binary_constant_pool: Option<u16>,
773 binary_identifiers: Option<u16>,
774 binary_address_identifiers: Option<u16>,
775 binary_struct_defs: Option<u16>,
776 binary_struct_def_instantiations: Option<u16>,
777 binary_function_defs: Option<u16>,
778 binary_field_handles: Option<u16>,
779 binary_field_instantiations: Option<u16>,
780 binary_friend_decls: Option<u16>,
781 binary_enum_defs: Option<u16>,
782 binary_enum_def_instantiations: Option<u16>,
783 binary_variant_handles: Option<u16>,
784 binary_variant_instantiation_handles: Option<u16>,
785
786 max_move_object_size: Option<u64>,
789
790 max_move_package_size: Option<u64>,
795
796 max_publish_or_upgrade_per_ptb: Option<u64>,
799
800 max_tx_gas: Option<u64>,
802
803 max_auth_gas: Option<u64>,
805
806 max_gas_price: Option<u64>,
809
810 max_gas_computation_bucket: Option<u64>,
813
814 gas_rounding_step: Option<u64>,
816
817 max_loop_depth: Option<u64>,
819
820 max_generic_instantiation_length: Option<u64>,
823
824 max_function_parameters: Option<u64>,
827
828 max_basic_blocks: Option<u64>,
831
832 max_value_stack_size: Option<u64>,
834
835 max_type_nodes: Option<u64>,
839
840 max_push_size: Option<u64>,
843
844 max_struct_definitions: Option<u64>,
847
848 max_function_definitions: Option<u64>,
851
852 max_fields_in_struct: Option<u64>,
855
856 max_dependency_depth: Option<u64>,
859
860 max_num_event_emit: Option<u64>,
863
864 max_num_new_move_object_ids: Option<u64>,
867
868 max_num_new_move_object_ids_system_tx: Option<u64>,
871
872 max_num_deleted_move_object_ids: Option<u64>,
875
876 max_num_deleted_move_object_ids_system_tx: Option<u64>,
879
880 max_num_transferred_move_object_ids: Option<u64>,
883
884 max_num_transferred_move_object_ids_system_tx: Option<u64>,
887
888 max_event_emit_size: Option<u64>,
890
891 max_event_emit_size_total: Option<u64>,
893
894 max_move_vector_len: Option<u64>,
897
898 max_move_identifier_len: Option<u64>,
901
902 max_move_value_depth: Option<u64>,
904
905 max_move_enum_variants: Option<u64>,
908
909 max_back_edges_per_function: Option<u64>,
912
913 max_back_edges_per_module: Option<u64>,
916
917 max_verifier_meter_ticks_per_function: Option<u64>,
920
921 max_meter_ticks_per_module: Option<u64>,
924
925 max_meter_ticks_per_package: Option<u64>,
928
929 object_runtime_max_num_cached_objects: Option<u64>,
936
937 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
940
941 object_runtime_max_num_store_entries: Option<u64>,
944
945 object_runtime_max_num_store_entries_system_tx: Option<u64>,
948
949 base_tx_cost_fixed: Option<u64>,
954
955 package_publish_cost_fixed: Option<u64>,
959
960 base_tx_cost_per_byte: Option<u64>,
964
965 package_publish_cost_per_byte: Option<u64>,
967
968 obj_access_cost_read_per_byte: Option<u64>,
970
971 obj_access_cost_mutate_per_byte: Option<u64>,
973
974 obj_access_cost_delete_per_byte: Option<u64>,
976
977 obj_access_cost_verify_per_byte: Option<u64>,
987
988 max_type_to_layout_nodes: Option<u64>,
990
991 max_ptb_value_size: Option<u64>,
993
994 gas_model_version: Option<u64>,
999
1000 obj_data_cost_refundable: Option<u64>,
1006
1007 obj_metadata_cost_non_refundable: Option<u64>,
1011
1012 storage_rebate_rate: Option<u64>,
1018
1019 reward_slashing_rate: Option<u64>,
1022
1023 storage_gas_price: Option<u64>,
1025
1026 base_gas_price: Option<u64>,
1028
1029 validator_target_reward: Option<u64>,
1031
1032 max_transactions_per_checkpoint: Option<u64>,
1039
1040 max_checkpoint_size_bytes: Option<u64>,
1044
1045 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
1051
1052 address_from_bytes_cost_base: Option<u64>,
1057 address_to_u256_cost_base: Option<u64>,
1059 address_from_u256_cost_base: Option<u64>,
1061
1062 config_read_setting_impl_cost_base: Option<u64>,
1067 config_read_setting_impl_cost_per_byte: Option<u64>,
1068
1069 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
1073 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
1074 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
1075 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
1076 dynamic_field_add_child_object_cost_base: Option<u64>,
1079 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
1080 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
1081 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
1082 dynamic_field_borrow_child_object_cost_base: Option<u64>,
1085 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1086 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1087 dynamic_field_remove_child_object_cost_base: Option<u64>,
1090 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1091 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1092 dynamic_field_has_child_object_cost_base: Option<u64>,
1095 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1098 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1099 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1100
1101 event_emit_cost_base: Option<u64>,
1104 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1105 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1106 event_emit_output_cost_per_byte: Option<u64>,
1107
1108 object_borrow_uid_cost_base: Option<u64>,
1111 object_delete_impl_cost_base: Option<u64>,
1113 object_record_new_uid_cost_base: Option<u64>,
1115
1116 transfer_transfer_internal_cost_base: Option<u64>,
1119 transfer_freeze_object_cost_base: Option<u64>,
1121 transfer_share_object_cost_base: Option<u64>,
1123 transfer_receive_object_cost_base: Option<u64>,
1126
1127 tx_context_derive_id_cost_base: Option<u64>,
1130 tx_context_fresh_id_cost_base: Option<u64>,
1131 tx_context_sender_cost_base: Option<u64>,
1132 tx_context_digest_cost_base: Option<u64>,
1133 tx_context_epoch_cost_base: Option<u64>,
1134 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1135 tx_context_sponsor_cost_base: Option<u64>,
1136 tx_context_rgp_cost_base: Option<u64>,
1137 tx_context_gas_price_cost_base: Option<u64>,
1138 tx_context_gas_budget_cost_base: Option<u64>,
1139 tx_context_ids_created_cost_base: Option<u64>,
1140 tx_context_replace_cost_base: Option<u64>,
1141
1142 types_is_one_time_witness_cost_base: Option<u64>,
1145 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1146 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1147
1148 validator_validate_metadata_cost_base: Option<u64>,
1151 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1152
1153 crypto_invalid_arguments_cost: Option<u64>,
1155 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1157 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1158 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1159
1160 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1162 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1163 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1164
1165 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1167 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1168 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1169 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1170 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1171 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1172
1173 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1175
1176 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1178 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1179 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1180 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1181 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1182 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1183
1184 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1186 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1187 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1188 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1189 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1190 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1191
1192 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1194 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1195 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1196 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1197 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1198 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1199
1200 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1202 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1203 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1204
1205 ed25519_ed25519_verify_cost_base: Option<u64>,
1207 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1208 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1209
1210 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1212 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1213
1214 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1216 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1217 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1218 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1219 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1220
1221 hash_blake2b256_cost_base: Option<u64>,
1223 hash_blake2b256_data_cost_per_byte: Option<u64>,
1224 hash_blake2b256_data_cost_per_block: Option<u64>,
1225
1226 hash_keccak256_cost_base: Option<u64>,
1228 hash_keccak256_data_cost_per_byte: Option<u64>,
1229 hash_keccak256_data_cost_per_block: Option<u64>,
1230
1231 poseidon_bn254_cost_base: Option<u64>,
1233 poseidon_bn254_cost_per_block: Option<u64>,
1234
1235 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1237 group_ops_bls12381_decode_g1_cost: Option<u64>,
1238 group_ops_bls12381_decode_g2_cost: Option<u64>,
1239 group_ops_bls12381_decode_gt_cost: Option<u64>,
1240 group_ops_bls12381_scalar_add_cost: Option<u64>,
1241 group_ops_bls12381_g1_add_cost: Option<u64>,
1242 group_ops_bls12381_g2_add_cost: Option<u64>,
1243 group_ops_bls12381_gt_add_cost: Option<u64>,
1244 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1245 group_ops_bls12381_g1_sub_cost: Option<u64>,
1246 group_ops_bls12381_g2_sub_cost: Option<u64>,
1247 group_ops_bls12381_gt_sub_cost: Option<u64>,
1248 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1249 group_ops_bls12381_g1_mul_cost: Option<u64>,
1250 group_ops_bls12381_g2_mul_cost: Option<u64>,
1251 group_ops_bls12381_gt_mul_cost: Option<u64>,
1252 group_ops_bls12381_scalar_div_cost: Option<u64>,
1253 group_ops_bls12381_g1_div_cost: Option<u64>,
1254 group_ops_bls12381_g2_div_cost: Option<u64>,
1255 group_ops_bls12381_gt_div_cost: Option<u64>,
1256 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1257 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1258 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1259 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1260 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1261 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1262 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1263 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1264 group_ops_bls12381_msm_max_len: Option<u32>,
1265 group_ops_bls12381_pairing_cost: Option<u64>,
1266 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1267 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1268 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1269 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1270 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1271
1272 hmac_hmac_sha3_256_cost_base: Option<u64>,
1274 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1275 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1276
1277 #[deprecated]
1279 check_zklogin_id_cost_base: Option<u64>,
1280 #[deprecated]
1282 check_zklogin_issuer_cost_base: Option<u64>,
1283
1284 vdf_verify_vdf_cost: Option<u64>,
1285 vdf_hash_to_input_cost: Option<u64>,
1286
1287 bcs_per_byte_serialized_cost: Option<u64>,
1289 bcs_legacy_min_output_size_cost: Option<u64>,
1290 bcs_failure_cost: Option<u64>,
1291
1292 hash_sha2_256_base_cost: Option<u64>,
1293 hash_sha2_256_per_byte_cost: Option<u64>,
1294 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1295 hash_sha3_256_base_cost: Option<u64>,
1296 hash_sha3_256_per_byte_cost: Option<u64>,
1297 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1298 type_name_get_base_cost: Option<u64>,
1299 type_name_get_per_byte_cost: Option<u64>,
1300
1301 string_check_utf8_base_cost: Option<u64>,
1302 string_check_utf8_per_byte_cost: Option<u64>,
1303 string_is_char_boundary_base_cost: Option<u64>,
1304 string_sub_string_base_cost: Option<u64>,
1305 string_sub_string_per_byte_cost: Option<u64>,
1306 string_index_of_base_cost: Option<u64>,
1307 string_index_of_per_byte_pattern_cost: Option<u64>,
1308 string_index_of_per_byte_searched_cost: Option<u64>,
1309
1310 vector_empty_base_cost: Option<u64>,
1311 vector_length_base_cost: Option<u64>,
1312 vector_push_back_base_cost: Option<u64>,
1313 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1314 vector_borrow_base_cost: Option<u64>,
1315 vector_pop_back_base_cost: Option<u64>,
1316 vector_destroy_empty_base_cost: Option<u64>,
1317 vector_swap_base_cost: Option<u64>,
1318 debug_print_base_cost: Option<u64>,
1319 debug_print_stack_trace_base_cost: Option<u64>,
1320
1321 execution_version: Option<u64>,
1323
1324 consensus_bad_nodes_stake_threshold: Option<u64>,
1328
1329 #[deprecated]
1330 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1331 #[deprecated]
1335 max_age_of_jwk_in_epochs: Option<u64>,
1336
1337 random_beacon_reduction_allowed_delta: Option<u16>,
1341
1342 random_beacon_reduction_lower_bound: Option<u32>,
1345
1346 random_beacon_dkg_timeout_round: Option<u32>,
1349
1350 random_beacon_min_round_interval_ms: Option<u64>,
1352
1353 random_beacon_dkg_version: Option<u64>,
1357
1358 consensus_max_transaction_size_bytes: Option<u64>,
1363 consensus_max_transactions_in_block_bytes: Option<u64>,
1365 consensus_max_num_transactions_in_block: Option<u64>,
1367
1368 max_deferral_rounds_for_congestion_control: Option<u64>,
1372
1373 min_checkpoint_interval_ms: Option<u64>,
1375
1376 checkpoint_rate_window_size: Option<u64>,
1386
1387 checkpoint_summary_version_specific_data: Option<u64>,
1389
1390 max_soft_bundle_size: Option<u64>,
1393
1394 bridge_should_try_to_finalize_committee: Option<bool>,
1399
1400 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1406
1407 max_committee_members_count: Option<u64>,
1411
1412 consensus_gc_depth: Option<u32>,
1415
1416 consensus_max_acknowledgments_per_block: Option<u32>,
1422
1423 max_congestion_limit_overshoot_per_commit: Option<u64>,
1428
1429 scorer_version: Option<u16>,
1438
1439 auth_context_digest_cost_base: Option<u64>,
1442 auth_context_tx_data_bytes_cost_base: Option<u64>,
1444 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1445 auth_context_tx_commands_cost_base: Option<u64>,
1447 auth_context_tx_commands_cost_per_byte: Option<u64>,
1448 auth_context_tx_inputs_cost_base: Option<u64>,
1450 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1451 auth_context_replace_cost_base: Option<u64>,
1454 auth_context_replace_cost_per_byte: Option<u64>,
1455 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1459
1460 consensus_commits_per_schedule: Option<u32>,
1463
1464 min_validator_count: Option<u64>,
1467
1468 max_validator_count: Option<u64>,
1472
1473 min_validator_joining_stake: Option<u64>,
1477
1478 validator_low_stake_threshold: Option<u64>,
1483
1484 validator_very_low_stake_threshold: Option<u64>,
1488
1489 validator_low_stake_grace_period: Option<u64>,
1493}
1494
1495impl ProtocolConfig {
1497 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1510 self.feature_flags
1511 .disable_invariant_violation_check_in_swap_loc
1512 }
1513
1514 pub fn no_extraneous_module_bytes(&self) -> bool {
1515 self.feature_flags.no_extraneous_module_bytes
1516 }
1517
1518 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1519 self.feature_flags.consensus_transaction_ordering
1520 }
1521
1522 pub fn dkg_version(&self) -> u64 {
1523 self.random_beacon_dkg_version.unwrap_or(1)
1525 }
1526
1527 pub fn hardened_otw_check(&self) -> bool {
1528 self.feature_flags.hardened_otw_check
1529 }
1530
1531 pub fn enable_poseidon(&self) -> bool {
1532 self.feature_flags.enable_poseidon
1533 }
1534
1535 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1536 self.feature_flags.enable_group_ops_native_function_msm
1537 }
1538
1539 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1540 self.feature_flags.per_object_congestion_control_mode
1541 }
1542
1543 pub fn consensus_choice(&self) -> ConsensusChoice {
1544 self.feature_flags.consensus_choice
1545 }
1546
1547 pub fn consensus_network(&self) -> ConsensusNetwork {
1548 self.feature_flags.consensus_network
1549 }
1550
1551 pub fn enable_vdf(&self) -> bool {
1552 self.feature_flags.enable_vdf
1553 }
1554
1555 pub fn passkey_auth(&self) -> bool {
1556 self.feature_flags.passkey_auth
1557 }
1558
1559 pub fn max_transaction_size_bytes(&self) -> u64 {
1560 self.consensus_max_transaction_size_bytes
1562 .unwrap_or(256 * 1024)
1563 }
1564
1565 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1566 if cfg!(msim) {
1567 256 * 1024
1568 } else {
1569 self.consensus_max_transactions_in_block_bytes
1570 .unwrap_or(512 * 1024)
1571 }
1572 }
1573
1574 pub fn max_num_transactions_in_block(&self) -> u64 {
1575 if cfg!(msim) {
1576 8
1577 } else {
1578 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1579 }
1580 }
1581
1582 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1583 self.feature_flags.rethrow_serialization_type_layout_errors
1584 }
1585
1586 pub fn relocate_event_module(&self) -> bool {
1587 self.feature_flags.relocate_event_module
1588 }
1589
1590 pub fn protocol_defined_base_fee(&self) -> bool {
1591 self.feature_flags.protocol_defined_base_fee
1592 }
1593
1594 pub fn uncompressed_g1_group_elements(&self) -> bool {
1595 self.feature_flags.uncompressed_g1_group_elements
1596 }
1597
1598 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1599 self.feature_flags
1600 .disallow_new_modules_in_deps_only_packages
1601 }
1602
1603 pub fn native_charging_v2(&self) -> bool {
1604 self.feature_flags.native_charging_v2
1605 }
1606
1607 pub fn consensus_round_prober(&self) -> bool {
1608 self.feature_flags.consensus_round_prober
1609 }
1610
1611 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1612 self.feature_flags
1613 .consensus_distributed_vote_scoring_strategy
1614 }
1615
1616 pub fn gc_depth(&self) -> u32 {
1617 if cfg!(msim) {
1618 min(5, self.consensus_gc_depth.unwrap_or(0))
1620 } else {
1621 self.consensus_gc_depth.unwrap_or(0)
1622 }
1623 }
1624
1625 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1626 let res = self.feature_flags.consensus_linearize_subdag_v2;
1627 assert!(
1628 !res || self.gc_depth() > 0,
1629 "The consensus linearize sub dag V2 requires GC to be enabled"
1630 );
1631 res
1632 }
1633
1634 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1635 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1636 }
1637
1638 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1639 2 * committee_size
1640 }
1641
1642 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1643 committee_size
1644 }
1645
1646 pub fn variant_nodes(&self) -> bool {
1647 self.feature_flags.variant_nodes
1648 }
1649
1650 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1651 self.feature_flags.consensus_smart_ancestor_selection
1652 }
1653
1654 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1655 self.feature_flags
1656 .consensus_round_prober_probe_accepted_rounds
1657 }
1658
1659 pub fn consensus_zstd_compression(&self) -> bool {
1660 self.feature_flags.consensus_zstd_compression
1661 }
1662
1663 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1664 self.feature_flags
1665 .congestion_control_min_free_execution_slot
1666 }
1667
1668 pub fn accept_passkey_in_multisig(&self) -> bool {
1669 self.feature_flags.accept_passkey_in_multisig
1670 }
1671
1672 pub fn consensus_batched_block_sync(&self) -> bool {
1673 self.feature_flags.consensus_batched_block_sync
1674 }
1675
1676 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1679 self.feature_flags
1680 .congestion_control_gas_price_feedback_mechanism
1681 }
1682
1683 pub fn validate_identifier_inputs(&self) -> bool {
1684 self.feature_flags.validate_identifier_inputs
1685 }
1686
1687 pub fn minimize_child_object_mutations(&self) -> bool {
1688 self.feature_flags.minimize_child_object_mutations
1689 }
1690
1691 pub fn dependency_linkage_error(&self) -> bool {
1692 self.feature_flags.dependency_linkage_error
1693 }
1694
1695 pub fn additional_multisig_checks(&self) -> bool {
1696 self.feature_flags.additional_multisig_checks
1697 }
1698
1699 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1700 0
1703 }
1704
1705 pub fn normalize_ptb_arguments(&self) -> bool {
1706 self.feature_flags.normalize_ptb_arguments
1707 }
1708
1709 pub fn select_committee_from_eligible_validators(&self) -> bool {
1710 let res = self.feature_flags.select_committee_from_eligible_validators;
1711 assert!(
1712 !res || (self.protocol_defined_base_fee()
1713 && self.max_committee_members_count_as_option().is_some()),
1714 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1715 );
1716 res
1717 }
1718
1719 pub fn track_non_committee_eligible_validators(&self) -> bool {
1720 self.feature_flags.track_non_committee_eligible_validators
1721 }
1722
1723 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1724 let res = self
1725 .feature_flags
1726 .select_committee_supporting_next_epoch_version;
1727 assert!(
1728 !res || (self.track_non_committee_eligible_validators()
1729 && self.select_committee_from_eligible_validators()),
1730 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1731 );
1732 res
1733 }
1734
1735 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1736 let res = self
1737 .feature_flags
1738 .consensus_median_timestamp_with_checkpoint_enforcement;
1739 assert!(
1740 !res || self.gc_depth() > 0,
1741 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1742 );
1743 res
1744 }
1745
1746 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1747 self.feature_flags
1748 .consensus_commit_transactions_only_for_traversed_headers
1749 }
1750
1751 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1754 self.feature_flags
1755 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1756 }
1757
1758 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1761 self.feature_flags
1762 .separate_gas_price_feedback_mechanism_for_randomness
1763 }
1764
1765 pub fn metadata_in_module_bytes(&self) -> bool {
1766 self.feature_flags.metadata_in_module_bytes
1767 }
1768
1769 pub fn publish_package_metadata(&self) -> bool {
1770 self.feature_flags.publish_package_metadata
1771 }
1772
1773 pub fn enable_move_authentication(&self) -> bool {
1774 self.feature_flags.enable_move_authentication
1775 }
1776
1777 pub fn additional_borrow_checks(&self) -> bool {
1778 self.feature_flags.additional_borrow_checks
1779 }
1780
1781 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1782 let enable_move_authentication_for_sponsor =
1783 self.feature_flags.enable_move_authentication_for_sponsor;
1784 assert!(
1785 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1786 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1787 );
1788 enable_move_authentication_for_sponsor
1789 }
1790
1791 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1792 self.feature_flags.pass_validator_scores_to_advance_epoch
1793 }
1794
1795 pub fn calculate_validator_scores(&self) -> bool {
1796 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1797 assert!(
1798 !calculate_validator_scores || self.scorer_version.is_some(),
1799 "calculate_validator_scores requires scorer_version to be set"
1800 );
1801 calculate_validator_scores
1802 }
1803
1804 pub fn adjust_rewards_by_score(&self) -> bool {
1805 let adjust = self.feature_flags.adjust_rewards_by_score;
1806 assert!(
1807 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1808 "adjust_rewards_by_score requires scorer_version to be set"
1809 );
1810 adjust
1811 }
1812
1813 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1814 let pass = self
1815 .feature_flags
1816 .pass_calculated_validator_scores_to_advance_epoch;
1817 assert!(
1818 !pass
1819 || (self.pass_validator_scores_to_advance_epoch()
1820 && self.calculate_validator_scores()),
1821 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
1822 );
1823 pass
1824 }
1825 pub fn consensus_fast_commit_sync(&self) -> bool {
1826 let res = self.feature_flags.consensus_fast_commit_sync;
1827 assert!(
1828 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
1829 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
1830 );
1831 res
1832 }
1833
1834 pub fn consensus_block_restrictions(&self) -> bool {
1835 self.feature_flags.consensus_block_restrictions
1836 }
1837
1838 pub fn move_native_tx_context(&self) -> bool {
1839 self.feature_flags.move_native_tx_context
1840 }
1841
1842 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
1843 let pre_consensus_sponsor_only_move_authentication = self
1844 .feature_flags
1845 .pre_consensus_sponsor_only_move_authentication;
1846 if pre_consensus_sponsor_only_move_authentication {
1847 assert!(
1848 self.enable_move_authentication(),
1849 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
1850 );
1851 assert!(
1852 self.enable_move_authentication_for_sponsor(),
1853 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
1854 );
1855 }
1856 pre_consensus_sponsor_only_move_authentication
1857 }
1858
1859 pub fn consensus_starfish_speed(&self) -> bool {
1860 let res = self.feature_flags.consensus_starfish_speed;
1861 assert!(
1862 !res || self.consensus_fast_commit_sync(),
1863 "consensus_starfish_speed requires consensus_fast_commit_sync to be enabled"
1864 );
1865 res
1866 }
1867
1868 pub fn always_advance_dkg_to_resolution(&self) -> bool {
1869 self.feature_flags.always_advance_dkg_to_resolution
1870 }
1871
1872 pub fn enable_pcool_flow(&self) -> bool {
1873 self.feature_flags.enable_pcool_flow
1874 }
1875
1876 pub fn validator_metadata_verify_v2(&self) -> bool {
1877 self.feature_flags.validator_metadata_verify_v2
1878 }
1879
1880 pub fn commits_per_schedule(&self) -> u32 {
1881 if cfg!(msim) {
1882 min(10, self.consensus_commits_per_schedule.unwrap_or(300))
1884 } else {
1885 self.consensus_commits_per_schedule.unwrap_or(300)
1886 }
1887 }
1888
1889 pub fn deny_rule_governance(&self) -> bool {
1890 self.feature_flags.deny_rule_governance
1891 }
1892
1893 pub fn package_metadata_with_dynamic_module_metadata(&self) -> bool {
1894 let res = self
1895 .feature_flags
1896 .package_metadata_with_dynamic_module_metadata;
1897 assert!(
1898 !res || self.publish_package_metadata(),
1899 "package_metadata_with_dynamic_module_metadata requires publish_package_metadata to be enabled"
1900 );
1901 res
1902 }
1903
1904 pub fn report_move_authentication_error(&self) -> bool {
1905 let report_move_authentication_error = self.feature_flags.report_move_authentication_error;
1906 assert!(
1907 !report_move_authentication_error || self.enable_move_authentication(),
1908 "report_move_authentication_error requires enable_move_authentication to be set"
1909 );
1910 report_move_authentication_error
1911 }
1912}
1913
1914#[cfg(not(msim))]
1915static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1916
1917#[cfg(msim)]
1919thread_local! {
1920 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1921}
1922
1923impl ProtocolConfig {
1925 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1928 assert!(
1930 version >= ProtocolVersion::MIN,
1931 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1932 version,
1933 ProtocolVersion::MIN.0,
1934 );
1935 assert!(
1936 version <= ProtocolVersion::MAX_ALLOWED,
1937 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1938 version,
1939 ProtocolVersion::MAX_ALLOWED.0,
1940 );
1941
1942 let mut ret = Self::get_for_version_impl(version, chain);
1943 ret.version = version;
1944
1945 ret = CONFIG_OVERRIDE.with(|ovr| {
1946 if let Some(override_fn) = &*ovr.borrow() {
1947 warn!(
1948 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1949 );
1950 override_fn(version, ret)
1951 } else {
1952 ret
1953 }
1954 });
1955
1956 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1957 warn!(
1958 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1959 );
1960
1961 let overrides: ProtocolConfigOptional =
1963 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1964 .expect("failed to parse ProtocolConfig override env variables");
1965 overrides.apply_to(&mut ret);
1966
1967 let feature_flag_overrides: FeatureFlagsOptional =
1969 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_FEATURE_FLAGS_OVERRIDE")
1970 .expect("failed to parse ProtocolConfig feature flags override env variables");
1971
1972 feature_flag_overrides.apply_to(&mut ret.feature_flags);
1973 }
1974
1975 ret
1976 }
1977
1978 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1981 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1982 let mut ret = Self::get_for_version_impl(version, chain);
1983 ret.version = version;
1984 Some(ret)
1985 } else {
1986 None
1987 }
1988 }
1989
1990 #[cfg(not(msim))]
1991 pub fn poison_get_for_min_version() {
1992 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1993 }
1994
1995 #[cfg(not(msim))]
1996 fn load_poison_get_for_min_version() -> bool {
1997 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1998 }
1999
2000 #[cfg(msim)]
2001 pub fn poison_get_for_min_version() {
2002 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
2003 }
2004
2005 #[cfg(msim)]
2006 fn load_poison_get_for_min_version() -> bool {
2007 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
2008 }
2009
2010 pub fn convert_type_argument_error(&self) -> bool {
2011 self.feature_flags.convert_type_argument_error
2012 }
2013
2014 pub fn get_for_min_version() -> Self {
2018 if Self::load_poison_get_for_min_version() {
2019 panic!("get_for_min_version called on validator");
2020 }
2021 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
2022 }
2023
2024 #[expect(non_snake_case)]
2035 pub fn get_for_max_version_UNSAFE() -> Self {
2036 if Self::load_poison_get_for_min_version() {
2037 panic!("get_for_max_version_UNSAFE called on validator");
2038 }
2039 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
2040 }
2041
2042 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
2043 #[cfg(msim)]
2044 {
2045 if version > ProtocolVersion::MAX {
2047 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
2048 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
2049 return config;
2050 }
2051 }
2052
2053 let mut cfg = Self {
2057 version,
2058
2059 feature_flags: Default::default(),
2060
2061 max_tx_size_bytes: Some(128 * 1024),
2062 max_input_objects: Some(2048),
2065 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
2066 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
2067 max_gas_payment_objects: Some(256),
2068 max_modules_in_publish: Some(64),
2069 max_package_dependencies: Some(32),
2070 max_arguments: Some(512),
2071 max_type_arguments: Some(16),
2072 max_type_argument_depth: Some(16),
2073 max_pure_argument_size: Some(16 * 1024),
2074 max_programmable_tx_commands: Some(1024),
2075 move_binary_format_version: Some(7),
2076 min_move_binary_format_version: Some(6),
2077 binary_module_handles: Some(100),
2078 binary_struct_handles: Some(300),
2079 binary_function_handles: Some(1500),
2080 binary_function_instantiations: Some(750),
2081 binary_signatures: Some(1000),
2082 binary_constant_pool: Some(4000),
2083 binary_identifiers: Some(10000),
2084 binary_address_identifiers: Some(100),
2085 binary_struct_defs: Some(200),
2086 binary_struct_def_instantiations: Some(100),
2087 binary_function_defs: Some(1000),
2088 binary_field_handles: Some(500),
2089 binary_field_instantiations: Some(250),
2090 binary_friend_decls: Some(100),
2091 binary_enum_defs: None,
2092 binary_enum_def_instantiations: None,
2093 binary_variant_handles: None,
2094 binary_variant_instantiation_handles: None,
2095 max_move_object_size: Some(250 * 1024),
2096 max_move_package_size: Some(100 * 1024),
2097 max_publish_or_upgrade_per_ptb: Some(5),
2098 max_auth_gas: None,
2100 max_tx_gas: Some(50_000_000_000),
2102 max_gas_price: Some(100_000),
2103 max_gas_computation_bucket: Some(5_000_000),
2104 max_loop_depth: Some(5),
2105 max_generic_instantiation_length: Some(32),
2106 max_function_parameters: Some(128),
2107 max_basic_blocks: Some(1024),
2108 max_value_stack_size: Some(1024),
2109 max_type_nodes: Some(256),
2110 max_push_size: Some(10000),
2111 max_struct_definitions: Some(200),
2112 max_function_definitions: Some(1000),
2113 max_fields_in_struct: Some(32),
2114 max_dependency_depth: Some(100),
2115 max_num_event_emit: Some(1024),
2116 max_num_new_move_object_ids: Some(2048),
2117 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
2118 max_num_deleted_move_object_ids: Some(2048),
2119 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
2120 max_num_transferred_move_object_ids: Some(2048),
2121 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
2122 max_event_emit_size: Some(250 * 1024),
2123 max_move_vector_len: Some(256 * 1024),
2124 max_type_to_layout_nodes: None,
2125 max_ptb_value_size: None,
2126
2127 max_back_edges_per_function: Some(10_000),
2128 max_back_edges_per_module: Some(10_000),
2129
2130 max_verifier_meter_ticks_per_function: Some(16_000_000),
2131
2132 max_meter_ticks_per_module: Some(16_000_000),
2133 max_meter_ticks_per_package: Some(16_000_000),
2134
2135 object_runtime_max_num_cached_objects: Some(1000),
2136 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2137 object_runtime_max_num_store_entries: Some(1000),
2138 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2139 base_tx_cost_fixed: Some(1_000),
2141 package_publish_cost_fixed: Some(1_000),
2142 base_tx_cost_per_byte: Some(0),
2143 package_publish_cost_per_byte: Some(80),
2144 obj_access_cost_read_per_byte: Some(15),
2145 obj_access_cost_mutate_per_byte: Some(40),
2146 obj_access_cost_delete_per_byte: Some(40),
2147 obj_access_cost_verify_per_byte: Some(200),
2148 obj_data_cost_refundable: Some(100),
2149 obj_metadata_cost_non_refundable: Some(50),
2150 gas_model_version: Some(1),
2151 storage_rebate_rate: Some(10000),
2152 reward_slashing_rate: Some(10000),
2154 storage_gas_price: Some(76),
2155 base_gas_price: None,
2156 validator_target_reward: Some(767_000 * 1_000_000_000),
2159 max_transactions_per_checkpoint: Some(10_000),
2160 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2161
2162 buffer_stake_for_protocol_upgrade_bps: Some(5000),
2164
2165 address_from_bytes_cost_base: Some(52),
2169 address_to_u256_cost_base: Some(52),
2171 address_from_u256_cost_base: Some(52),
2173
2174 config_read_setting_impl_cost_base: Some(100),
2177 config_read_setting_impl_cost_per_byte: Some(40),
2178
2179 dynamic_field_hash_type_and_key_cost_base: Some(100),
2183 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
2184 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
2185 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
2186 dynamic_field_add_child_object_cost_base: Some(100),
2189 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2190 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2191 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2192 dynamic_field_borrow_child_object_cost_base: Some(100),
2195 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2196 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2197 dynamic_field_remove_child_object_cost_base: Some(100),
2200 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2201 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2202 dynamic_field_has_child_object_cost_base: Some(100),
2205 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2208 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2209 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2210
2211 event_emit_cost_base: Some(52),
2214 event_emit_value_size_derivation_cost_per_byte: Some(2),
2215 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2216 event_emit_output_cost_per_byte: Some(10),
2217
2218 object_borrow_uid_cost_base: Some(52),
2221 object_delete_impl_cost_base: Some(52),
2223 object_record_new_uid_cost_base: Some(52),
2225
2226 transfer_transfer_internal_cost_base: Some(52),
2230 transfer_freeze_object_cost_base: Some(52),
2232 transfer_share_object_cost_base: Some(52),
2234 transfer_receive_object_cost_base: Some(52),
2235
2236 tx_context_derive_id_cost_base: Some(52),
2240 tx_context_fresh_id_cost_base: None,
2241 tx_context_sender_cost_base: None,
2242 tx_context_digest_cost_base: None,
2243 tx_context_epoch_cost_base: None,
2244 tx_context_epoch_timestamp_ms_cost_base: None,
2245 tx_context_sponsor_cost_base: None,
2246 tx_context_rgp_cost_base: None,
2247 tx_context_gas_price_cost_base: None,
2248 tx_context_gas_budget_cost_base: None,
2249 tx_context_ids_created_cost_base: None,
2250 tx_context_replace_cost_base: None,
2251
2252 types_is_one_time_witness_cost_base: Some(52),
2255 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2256 types_is_one_time_witness_type_cost_per_byte: Some(2),
2257
2258 validator_validate_metadata_cost_base: Some(52),
2262 validator_validate_metadata_data_cost_per_byte: Some(2),
2263
2264 crypto_invalid_arguments_cost: Some(100),
2266 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2268 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2269 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2270
2271 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2273 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2274 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2275
2276 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2278 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2279 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2280 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2281 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2282 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2283
2284 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2286
2287 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2289 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2290 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2291 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2292 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2293 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2294
2295 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2297 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2298 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2299 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2300 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2301 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2302
2303 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2305 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2306 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2307 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2308 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2309 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2310
2311 ecvrf_ecvrf_verify_cost_base: Some(52),
2313 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2314 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2315
2316 ed25519_ed25519_verify_cost_base: Some(52),
2318 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2319 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2320
2321 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2323 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2324
2325 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2327 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2328 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2329 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2330 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2331
2332 hash_blake2b256_cost_base: Some(52),
2334 hash_blake2b256_data_cost_per_byte: Some(2),
2335 hash_blake2b256_data_cost_per_block: Some(2),
2336 hash_keccak256_cost_base: Some(52),
2338 hash_keccak256_data_cost_per_byte: Some(2),
2339 hash_keccak256_data_cost_per_block: Some(2),
2340
2341 poseidon_bn254_cost_base: None,
2342 poseidon_bn254_cost_per_block: None,
2343
2344 hmac_hmac_sha3_256_cost_base: Some(52),
2346 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2347 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2348
2349 group_ops_bls12381_decode_scalar_cost: Some(52),
2351 group_ops_bls12381_decode_g1_cost: Some(52),
2352 group_ops_bls12381_decode_g2_cost: Some(52),
2353 group_ops_bls12381_decode_gt_cost: Some(52),
2354 group_ops_bls12381_scalar_add_cost: Some(52),
2355 group_ops_bls12381_g1_add_cost: Some(52),
2356 group_ops_bls12381_g2_add_cost: Some(52),
2357 group_ops_bls12381_gt_add_cost: Some(52),
2358 group_ops_bls12381_scalar_sub_cost: Some(52),
2359 group_ops_bls12381_g1_sub_cost: Some(52),
2360 group_ops_bls12381_g2_sub_cost: Some(52),
2361 group_ops_bls12381_gt_sub_cost: Some(52),
2362 group_ops_bls12381_scalar_mul_cost: Some(52),
2363 group_ops_bls12381_g1_mul_cost: Some(52),
2364 group_ops_bls12381_g2_mul_cost: Some(52),
2365 group_ops_bls12381_gt_mul_cost: Some(52),
2366 group_ops_bls12381_scalar_div_cost: Some(52),
2367 group_ops_bls12381_g1_div_cost: Some(52),
2368 group_ops_bls12381_g2_div_cost: Some(52),
2369 group_ops_bls12381_gt_div_cost: Some(52),
2370 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2371 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2372 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2373 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2374 group_ops_bls12381_g1_msm_base_cost: Some(52),
2375 group_ops_bls12381_g2_msm_base_cost: Some(52),
2376 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2377 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2378 group_ops_bls12381_msm_max_len: Some(32),
2379 group_ops_bls12381_pairing_cost: Some(52),
2380 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2381 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2382 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2383 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2384 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2385
2386 #[allow(deprecated)]
2388 check_zklogin_id_cost_base: Some(200),
2389 #[allow(deprecated)]
2390 check_zklogin_issuer_cost_base: Some(200),
2392
2393 vdf_verify_vdf_cost: None,
2394 vdf_hash_to_input_cost: None,
2395
2396 bcs_per_byte_serialized_cost: Some(2),
2397 bcs_legacy_min_output_size_cost: Some(1),
2398 bcs_failure_cost: Some(52),
2399 hash_sha2_256_base_cost: Some(52),
2400 hash_sha2_256_per_byte_cost: Some(2),
2401 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2402 hash_sha3_256_base_cost: Some(52),
2403 hash_sha3_256_per_byte_cost: Some(2),
2404 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2405 type_name_get_base_cost: Some(52),
2406 type_name_get_per_byte_cost: Some(2),
2407 string_check_utf8_base_cost: Some(52),
2408 string_check_utf8_per_byte_cost: Some(2),
2409 string_is_char_boundary_base_cost: Some(52),
2410 string_sub_string_base_cost: Some(52),
2411 string_sub_string_per_byte_cost: Some(2),
2412 string_index_of_base_cost: Some(52),
2413 string_index_of_per_byte_pattern_cost: Some(2),
2414 string_index_of_per_byte_searched_cost: Some(2),
2415 vector_empty_base_cost: Some(52),
2416 vector_length_base_cost: Some(52),
2417 vector_push_back_base_cost: Some(52),
2418 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2419 vector_borrow_base_cost: Some(52),
2420 vector_pop_back_base_cost: Some(52),
2421 vector_destroy_empty_base_cost: Some(52),
2422 vector_swap_base_cost: Some(52),
2423 debug_print_base_cost: Some(52),
2424 debug_print_stack_trace_base_cost: Some(52),
2425
2426 max_size_written_objects: Some(5 * 1000 * 1000),
2427 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2430
2431 max_move_identifier_len: Some(128),
2433 max_move_value_depth: Some(128),
2434 max_move_enum_variants: None,
2435
2436 gas_rounding_step: Some(1_000),
2437
2438 execution_version: Some(1),
2439
2440 max_event_emit_size_total: Some(
2443 256 * 250 * 1024, ),
2445
2446 consensus_bad_nodes_stake_threshold: Some(20),
2453
2454 #[allow(deprecated)]
2456 max_jwk_votes_per_validator_per_epoch: Some(240),
2457
2458 #[allow(deprecated)]
2459 max_age_of_jwk_in_epochs: Some(1),
2460
2461 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2465
2466 random_beacon_reduction_allowed_delta: Some(800),
2467
2468 random_beacon_reduction_lower_bound: Some(1000),
2469 random_beacon_dkg_timeout_round: Some(3000),
2470 random_beacon_min_round_interval_ms: Some(500),
2471
2472 random_beacon_dkg_version: Some(1),
2473
2474 consensus_max_num_transactions_in_block: Some(512),
2478
2479 max_deferral_rounds_for_congestion_control: Some(10),
2480
2481 min_checkpoint_interval_ms: Some(200),
2482
2483 checkpoint_rate_window_size: None,
2484
2485 checkpoint_summary_version_specific_data: Some(1),
2486
2487 max_soft_bundle_size: Some(5),
2488
2489 bridge_should_try_to_finalize_committee: None,
2490
2491 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2492
2493 max_committee_members_count: None,
2494
2495 consensus_gc_depth: None,
2496
2497 consensus_max_acknowledgments_per_block: None,
2498
2499 max_congestion_limit_overshoot_per_commit: None,
2500
2501 scorer_version: None,
2502
2503 auth_context_digest_cost_base: None,
2505 auth_context_tx_data_bytes_cost_base: None,
2506 auth_context_tx_data_bytes_cost_per_byte: None,
2507 auth_context_tx_commands_cost_base: None,
2508 auth_context_tx_commands_cost_per_byte: None,
2509 auth_context_tx_inputs_cost_base: None,
2510 auth_context_tx_inputs_cost_per_byte: None,
2511 auth_context_replace_cost_base: None,
2512 auth_context_replace_cost_per_byte: None,
2513 auth_context_authenticator_function_info_v1_cost_base: None,
2514 consensus_commits_per_schedule: None,
2515 min_validator_count: None,
2516 max_validator_count: None,
2517 min_validator_joining_stake: None,
2518 validator_low_stake_threshold: None,
2519 validator_very_low_stake_threshold: None,
2520 validator_low_stake_grace_period: None,
2521 };
2524
2525 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2526
2527 {
2529 cfg.feature_flags
2530 .disable_invariant_violation_check_in_swap_loc = true;
2531 cfg.feature_flags.no_extraneous_module_bytes = true;
2532 cfg.feature_flags.hardened_otw_check = true;
2533 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2534 }
2535
2536 {
2538 #[allow(deprecated)]
2539 {
2540 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2541 }
2542 }
2543
2544 #[expect(deprecated)]
2548 {
2549 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2550 }
2551 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2553
2554 cfg.feature_flags.per_object_congestion_control_mode =
2555 PerObjectCongestionControlMode::TotalTxCount;
2556
2557 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2559
2560 if chain != Chain::Mainnet && chain != Chain::Testnet {
2562 cfg.feature_flags.enable_poseidon = true;
2563 cfg.poseidon_bn254_cost_base = Some(260);
2564 cfg.poseidon_bn254_cost_per_block = Some(10);
2565
2566 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2567
2568 cfg.feature_flags.enable_vdf = true;
2569 cfg.vdf_verify_vdf_cost = Some(1500);
2572 cfg.vdf_hash_to_input_cost = Some(100);
2573
2574 cfg.feature_flags.passkey_auth = true;
2575 }
2576
2577 for cur in 2..=version.0 {
2578 match cur {
2579 1 => unreachable!(),
2580 2 => {}
2582 3 => {
2583 cfg.feature_flags.relocate_event_module = true;
2584 }
2585 4 => {
2586 cfg.max_type_to_layout_nodes = Some(512);
2587 }
2588 5 => {
2589 cfg.feature_flags.protocol_defined_base_fee = true;
2590 cfg.base_gas_price = Some(1000);
2591
2592 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2593 cfg.feature_flags.convert_type_argument_error = true;
2594 cfg.feature_flags.native_charging_v2 = true;
2595
2596 if chain != Chain::Mainnet && chain != Chain::Testnet {
2597 cfg.feature_flags.uncompressed_g1_group_elements = true;
2598 }
2599
2600 cfg.gas_model_version = Some(2);
2601
2602 cfg.poseidon_bn254_cost_per_block = Some(388);
2603
2604 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2605 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2606 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2607 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2608 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2609 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2610 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2611 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2612
2613 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2615 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2616 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2617 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2618
2619 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2620 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2621 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2622 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2623 Some(8213);
2624 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2625 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2626 Some(9484);
2627
2628 cfg.hash_keccak256_cost_base = Some(10);
2629 cfg.hash_blake2b256_cost_base = Some(10);
2630
2631 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2633 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2634 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2635 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2636
2637 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2638 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2639 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2640 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2641
2642 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2643 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2644 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2645 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2646
2647 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2648 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2649 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2650 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2651
2652 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2653 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2654 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2655 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2656
2657 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2658 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2659
2660 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2661 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2662 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2663 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2664
2665 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2666 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2667 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2668 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2669 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2670
2671 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2672
2673 cfg.validator_validate_metadata_cost_base = Some(20000);
2674
2675 cfg.max_committee_members_count = Some(50);
2676 }
2677 6 => {
2678 cfg.max_ptb_value_size = Some(1024 * 1024);
2679 }
2680 7 => {
2681 }
2684 8 => {
2685 cfg.feature_flags.variant_nodes = true;
2686
2687 if chain != Chain::Mainnet {
2688 cfg.feature_flags.consensus_round_prober = true;
2690 cfg.feature_flags
2692 .consensus_distributed_vote_scoring_strategy = true;
2693 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2694 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2696 cfg.feature_flags
2698 .consensus_round_prober_probe_accepted_rounds = true;
2699 cfg.feature_flags.consensus_zstd_compression = true;
2701 cfg.consensus_gc_depth = Some(60);
2705 }
2706
2707 if chain != Chain::Testnet && chain != Chain::Mainnet {
2710 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2711 }
2712 }
2713 9 => {
2714 if chain != Chain::Mainnet {
2715 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2717 }
2718
2719 cfg.feature_flags.consensus_zstd_compression = true;
2721
2722 if chain != Chain::Testnet && chain != Chain::Mainnet {
2724 cfg.feature_flags.accept_passkey_in_multisig = true;
2725 }
2726
2727 cfg.bridge_should_try_to_finalize_committee = None;
2729 }
2730 10 => {
2731 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2734
2735 cfg.max_committee_members_count = Some(80);
2737
2738 cfg.feature_flags.consensus_round_prober = true;
2740 cfg.feature_flags
2742 .consensus_round_prober_probe_accepted_rounds = true;
2743 cfg.feature_flags
2745 .consensus_distributed_vote_scoring_strategy = true;
2746 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2748
2749 cfg.consensus_gc_depth = Some(60);
2754
2755 cfg.feature_flags.minimize_child_object_mutations = true;
2757
2758 if chain != Chain::Mainnet {
2759 cfg.feature_flags.consensus_batched_block_sync = true;
2761 }
2762
2763 if chain != Chain::Testnet && chain != Chain::Mainnet {
2764 cfg.feature_flags
2767 .congestion_control_gas_price_feedback_mechanism = true;
2768 }
2769
2770 cfg.feature_flags.validate_identifier_inputs = true;
2771 cfg.feature_flags.dependency_linkage_error = true;
2772 cfg.feature_flags.additional_multisig_checks = true;
2773 }
2774 11 => {
2775 }
2778 12 => {
2779 cfg.feature_flags
2782 .congestion_control_gas_price_feedback_mechanism = true;
2783
2784 cfg.feature_flags.normalize_ptb_arguments = true;
2786 }
2787 13 => {
2788 cfg.feature_flags.select_committee_from_eligible_validators = true;
2791 cfg.feature_flags.track_non_committee_eligible_validators = true;
2794
2795 if chain != Chain::Testnet && chain != Chain::Mainnet {
2796 cfg.feature_flags
2799 .select_committee_supporting_next_epoch_version = true;
2800 }
2801 }
2802 14 => {
2803 cfg.feature_flags.consensus_batched_block_sync = true;
2805
2806 if chain != Chain::Mainnet {
2807 cfg.feature_flags
2810 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2811 cfg.feature_flags
2815 .select_committee_supporting_next_epoch_version = true;
2816 }
2817 if chain != Chain::Testnet && chain != Chain::Mainnet {
2818 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2820 }
2821 }
2822 15 => {
2823 if chain != Chain::Mainnet && chain != Chain::Testnet {
2824 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2828 }
2829 }
2830 16 => {
2831 cfg.feature_flags
2834 .select_committee_supporting_next_epoch_version = true;
2835 cfg.feature_flags
2837 .consensus_commit_transactions_only_for_traversed_headers = true;
2838 }
2839 17 => {
2840 cfg.max_committee_members_count = Some(100);
2842 }
2843 18 => {
2844 if chain != Chain::Mainnet {
2845 cfg.feature_flags.passkey_auth = true;
2847 }
2848 }
2849 19 => {
2850 if chain != Chain::Testnet && chain != Chain::Mainnet {
2851 cfg.feature_flags
2854 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2855 cfg.feature_flags
2858 .separate_gas_price_feedback_mechanism_for_randomness = true;
2859 cfg.feature_flags.metadata_in_module_bytes = true;
2862 cfg.feature_flags.publish_package_metadata = true;
2863 cfg.feature_flags.enable_move_authentication = true;
2865 cfg.max_auth_gas = Some(250_000_000);
2867 cfg.transfer_receive_object_cost_base = Some(100);
2870 cfg.feature_flags.adjust_rewards_by_score = true;
2872 }
2873
2874 if chain != Chain::Mainnet {
2875 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2877
2878 cfg.feature_flags.calculate_validator_scores = true;
2880 cfg.scorer_version = Some(1);
2881 }
2882
2883 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
2885
2886 cfg.feature_flags.passkey_auth = true;
2888 }
2889 20 => {
2890 if chain != Chain::Testnet && chain != Chain::Mainnet {
2891 cfg.feature_flags
2893 .pass_calculated_validator_scores_to_advance_epoch = true;
2894 }
2895 }
2896 21 => {
2897 if chain != Chain::Testnet && chain != Chain::Mainnet {
2898 cfg.feature_flags.consensus_fast_commit_sync = true;
2900 }
2901 if chain != Chain::Mainnet {
2902 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2907 cfg.feature_flags
2910 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2911 cfg.feature_flags
2914 .separate_gas_price_feedback_mechanism_for_randomness = true;
2915 }
2916
2917 cfg.auth_context_digest_cost_base = Some(30);
2918 cfg.auth_context_tx_commands_cost_base = Some(30);
2919 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
2920 cfg.auth_context_tx_inputs_cost_base = Some(30);
2921 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
2922 cfg.auth_context_replace_cost_base = Some(30);
2923 cfg.auth_context_replace_cost_per_byte = Some(2);
2924
2925 if chain != Chain::Testnet && chain != Chain::Mainnet {
2926 cfg.max_auth_gas = Some(250_000);
2928 }
2929 }
2930 22 => {
2931 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2936 cfg.feature_flags
2939 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2940 cfg.feature_flags
2943 .separate_gas_price_feedback_mechanism_for_randomness = true;
2944
2945 if chain != Chain::Mainnet {
2946 cfg.feature_flags.metadata_in_module_bytes = true;
2949 cfg.feature_flags.publish_package_metadata = true;
2950 cfg.feature_flags.enable_move_authentication = true;
2952 cfg.max_auth_gas = Some(250_000);
2954 cfg.transfer_receive_object_cost_base = Some(100);
2957 }
2958
2959 if chain != Chain::Mainnet {
2960 cfg.feature_flags.consensus_fast_commit_sync = true;
2962 }
2963 }
2964 23 => {
2965 cfg.feature_flags.move_native_tx_context = true;
2967 cfg.tx_context_fresh_id_cost_base = Some(52);
2968 cfg.tx_context_sender_cost_base = Some(30);
2969 cfg.tx_context_digest_cost_base = Some(30);
2970 cfg.tx_context_epoch_cost_base = Some(30);
2971 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
2972 cfg.tx_context_sponsor_cost_base = Some(30);
2973 cfg.tx_context_rgp_cost_base = Some(30);
2974 cfg.tx_context_gas_price_cost_base = Some(30);
2975 cfg.tx_context_gas_budget_cost_base = Some(30);
2976 cfg.tx_context_ids_created_cost_base = Some(30);
2977 cfg.tx_context_replace_cost_base = Some(30);
2978 }
2979 24 => {
2980 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2982
2983 if chain != Chain::Testnet && chain != Chain::Mainnet {
2984 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2986 }
2987
2988 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
2991 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
2992
2993 cfg.feature_flags.additional_borrow_checks = true;
2995 }
2996 #[allow(deprecated)]
2997 25 => {
2998 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
3001 cfg.check_zklogin_id_cost_base = None;
3002 cfg.check_zklogin_issuer_cost_base = None;
3003 cfg.max_jwk_votes_per_validator_per_epoch = None;
3004 cfg.max_age_of_jwk_in_epochs = None;
3005 }
3006 26 => {
3007 }
3010 27 => {
3011 if chain != Chain::Mainnet {
3012 cfg.feature_flags.consensus_block_restrictions = true;
3015 }
3016
3017 if chain != Chain::Testnet && chain != Chain::Mainnet {
3018 cfg.feature_flags
3020 .pre_consensus_sponsor_only_move_authentication = true;
3021 }
3022 }
3023 28 => {
3024 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
3029
3030 cfg.feature_flags.metadata_in_module_bytes = true;
3033 cfg.feature_flags.publish_package_metadata = true;
3034 cfg.feature_flags.enable_move_authentication = true;
3036 cfg.transfer_receive_object_cost_base = Some(100);
3039
3040 if chain != Chain::Unknown {
3041 cfg.max_auth_gas = Some(20_000);
3043 }
3044
3045 if chain != Chain::Mainnet {
3046 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3048 cfg.feature_flags
3050 .pre_consensus_sponsor_only_move_authentication = true;
3051 }
3052 }
3053 29 => {
3054 cfg.feature_flags.always_advance_dkg_to_resolution = true;
3060
3061 cfg.feature_flags
3064 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3065
3066 cfg.feature_flags.consensus_fast_commit_sync = true;
3068 cfg.feature_flags.consensus_block_restrictions = true;
3072 }
3073 30 => {
3074 }
3082 31 => {
3083 cfg.feature_flags.validator_metadata_verify_v2 = true;
3084
3085 if chain != Chain::Mainnet && chain != Chain::Testnet {
3086 cfg.checkpoint_rate_window_size = Some(20);
3089 cfg.feature_flags
3092 .package_metadata_with_dynamic_module_metadata = true;
3093 cfg.feature_flags.consensus_starfish_speed = true;
3096 }
3097
3098 cfg.feature_flags.report_move_authentication_error = true;
3099 }
3100 32 => {
3101 cfg.min_validator_count = Some(4);
3105 cfg.max_validator_count = Some(150);
3106 cfg.min_validator_joining_stake = Some(2_000_000_000_000_000);
3107 cfg.validator_low_stake_threshold = Some(1_500_000_000_000_000);
3108 cfg.validator_very_low_stake_threshold = Some(1_000_000_000_000_000);
3109 cfg.validator_low_stake_grace_period = Some(7);
3110
3111 if chain != Chain::Mainnet {
3112 cfg.feature_flags.consensus_starfish_speed = true;
3115 cfg.checkpoint_rate_window_size = Some(20);
3118 }
3119 }
3120 _ => panic!("unsupported version {version:?}"),
3131 }
3132 }
3133 cfg
3134 }
3135
3136 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
3142 let (
3143 max_back_edges_per_function,
3144 max_back_edges_per_module,
3145 sanity_check_with_regex_reference_safety,
3146 ) = if let Some((
3147 max_back_edges_per_function,
3148 max_back_edges_per_module,
3149 sanity_check_with_regex_reference_safety,
3150 )) = signing_limits
3151 {
3152 (
3153 Some(max_back_edges_per_function),
3154 Some(max_back_edges_per_module),
3155 Some(sanity_check_with_regex_reference_safety),
3156 )
3157 } else {
3158 (None, None, None)
3159 };
3160
3161 let additional_borrow_checks = if signing_limits.is_some() {
3162 true
3165 } else {
3166 self.additional_borrow_checks()
3167 };
3168
3169 VerifierConfig {
3170 max_loop_depth: Some(self.max_loop_depth() as usize),
3171 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
3172 max_function_parameters: Some(self.max_function_parameters() as usize),
3173 max_basic_blocks: Some(self.max_basic_blocks() as usize),
3174 max_value_stack_size: self.max_value_stack_size() as usize,
3175 max_type_nodes: Some(self.max_type_nodes() as usize),
3176 max_push_size: Some(self.max_push_size() as usize),
3177 max_dependency_depth: Some(self.max_dependency_depth() as usize),
3178 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
3179 max_function_definitions: Some(self.max_function_definitions() as usize),
3180 max_data_definitions: Some(self.max_struct_definitions() as usize),
3181 max_constant_vector_len: Some(self.max_move_vector_len()),
3182 max_back_edges_per_function,
3183 max_back_edges_per_module,
3184 max_basic_blocks_in_script: None,
3185 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
3189 max_variants_in_enum: self.max_move_enum_variants_as_option(),
3190 additional_borrow_checks,
3191 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
3192 .map(|limit| limit as u128),
3193 }
3194 }
3195
3196 pub fn apply_overrides_for_testing(
3201 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
3202 ) -> OverrideGuard {
3203 CONFIG_OVERRIDE.with(|ovr| {
3204 let mut cur = ovr.borrow_mut();
3205 assert!(cur.is_none(), "config override already present");
3206 *cur = Some(Box::new(override_fn));
3207 OverrideGuard
3208 })
3209 }
3210}
3211
3212impl ProtocolConfig {
3217 pub fn set_per_object_congestion_control_mode_for_testing(
3218 &mut self,
3219 val: PerObjectCongestionControlMode,
3220 ) {
3221 self.feature_flags.per_object_congestion_control_mode = val;
3222 }
3223
3224 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
3225 self.feature_flags.consensus_choice = val;
3226 }
3227
3228 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
3229 self.feature_flags.consensus_network = val;
3230 }
3231
3232 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
3233 self.feature_flags.passkey_auth = val
3234 }
3235
3236 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
3237 self.feature_flags
3238 .disallow_new_modules_in_deps_only_packages = val;
3239 }
3240
3241 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
3242 self.feature_flags.consensus_round_prober = val;
3243 }
3244
3245 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
3246 self.feature_flags
3247 .consensus_distributed_vote_scoring_strategy = val;
3248 }
3249
3250 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
3251 self.consensus_gc_depth = Some(val);
3252 }
3253
3254 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
3255 self.feature_flags.consensus_linearize_subdag_v2 = val;
3256 }
3257
3258 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
3259 self.feature_flags
3260 .consensus_round_prober_probe_accepted_rounds = val;
3261 }
3262
3263 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
3264 self.feature_flags.accept_passkey_in_multisig = val;
3265 }
3266
3267 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
3268 self.feature_flags.consensus_smart_ancestor_selection = val;
3269 }
3270
3271 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
3272 self.feature_flags.consensus_batched_block_sync = val;
3273 }
3274
3275 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
3276 self.feature_flags
3277 .congestion_control_min_free_execution_slot = val;
3278 }
3279
3280 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
3281 self.feature_flags
3282 .congestion_control_gas_price_feedback_mechanism = val;
3283 }
3284
3285 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
3286 self.feature_flags.select_committee_from_eligible_validators = val;
3287 }
3288
3289 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
3290 self.feature_flags.track_non_committee_eligible_validators = val;
3291 }
3292
3293 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
3294 self.feature_flags
3295 .select_committee_supporting_next_epoch_version = val;
3296 }
3297
3298 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
3299 &mut self,
3300 val: bool,
3301 ) {
3302 self.feature_flags
3303 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3304 }
3305
3306 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3307 &mut self,
3308 val: bool,
3309 ) {
3310 self.feature_flags
3311 .consensus_commit_transactions_only_for_traversed_headers = val;
3312 }
3313
3314 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3315 &mut self,
3316 val: bool,
3317 ) {
3318 self.feature_flags
3319 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3320 }
3321
3322 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3323 &mut self,
3324 val: bool,
3325 ) {
3326 self.feature_flags
3327 .separate_gas_price_feedback_mechanism_for_randomness = val;
3328 }
3329
3330 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3331 self.feature_flags.metadata_in_module_bytes = val;
3332 }
3333
3334 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3335 self.feature_flags.publish_package_metadata = val;
3336 }
3337
3338 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3339 self.feature_flags.enable_move_authentication = val;
3340 }
3341
3342 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3343 self.feature_flags.enable_move_authentication_for_sponsor = val;
3344 }
3345
3346 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3347 self.feature_flags.consensus_fast_commit_sync = val;
3348 }
3349
3350 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3351 self.feature_flags.consensus_block_restrictions = val;
3352 }
3353
3354 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3355 self.feature_flags
3356 .pre_consensus_sponsor_only_move_authentication = val;
3357 }
3358
3359 pub fn set_consensus_starfish_speed_for_testing(&mut self, val: bool) {
3360 self.feature_flags.consensus_starfish_speed = val;
3361 }
3362
3363 pub fn set_always_advance_dkg_to_resolution_for_testing(&mut self, val: bool) {
3364 self.feature_flags.always_advance_dkg_to_resolution = val;
3365 }
3366
3367 pub fn set_enable_pcool_flow_for_testing(&mut self, val: bool) {
3368 self.feature_flags.enable_pcool_flow = val;
3369 }
3370
3371 pub fn set_commits_per_schedule_for_testing(&mut self, val: u32) {
3372 self.consensus_commits_per_schedule = Some(val);
3373 }
3374
3375 pub fn set_deny_rule_governance_for_testing(&mut self, val: bool) {
3376 self.feature_flags.deny_rule_governance = val;
3377 }
3378
3379 pub fn set_package_metadata_with_dynamic_module_metadata_for_testing(&mut self, val: bool) {
3380 self.feature_flags
3381 .package_metadata_with_dynamic_module_metadata = val;
3382 }
3383
3384 pub fn set_report_move_authentication_error_for_testing(&mut self, val: bool) {
3385 self.feature_flags.report_move_authentication_error = val;
3386 }
3387}
3388
3389type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
3390
3391thread_local! {
3392 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
3393}
3394
3395#[must_use]
3396pub struct OverrideGuard;
3397
3398impl Drop for OverrideGuard {
3399 fn drop(&mut self) {
3400 info!("restoring override fn");
3401 CONFIG_OVERRIDE.with(|ovr| {
3402 *ovr.borrow_mut() = None;
3403 });
3404 }
3405}
3406
3407#[derive(PartialEq, Eq)]
3411pub enum LimitThresholdCrossed {
3412 None,
3413 Soft(u128, u128),
3414 Hard(u128, u128),
3415}
3416
3417pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
3420 x: T,
3421 soft_limit: U,
3422 hard_limit: V,
3423) -> LimitThresholdCrossed {
3424 let x: V = x.into();
3425 let soft_limit: V = soft_limit.into();
3426
3427 debug_assert!(soft_limit <= hard_limit);
3428
3429 if x >= hard_limit {
3432 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
3433 } else if x < soft_limit {
3434 LimitThresholdCrossed::None
3435 } else {
3436 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
3437 }
3438}
3439
3440#[macro_export]
3441macro_rules! check_limit {
3442 ($x:expr, $hard:expr) => {
3443 check_limit!($x, $hard, $hard)
3444 };
3445 ($x:expr, $soft:expr, $hard:expr) => {
3446 check_limit_in_range($x as u64, $soft, $hard)
3447 };
3448}
3449
3450#[macro_export]
3454macro_rules! check_limit_by_meter {
3455 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
3456 let (h, metered_str) = if $is_metered {
3458 ($metered_limit, "metered")
3459 } else {
3460 ($unmetered_hard_limit, "unmetered")
3462 };
3463 use iota_protocol_config::check_limit_in_range;
3464 let result = check_limit_in_range($x as u64, $metered_limit, h);
3465 match result {
3466 LimitThresholdCrossed::None => {}
3467 LimitThresholdCrossed::Soft(_, _) => {
3468 $metric.with_label_values(&[metered_str, "soft"]).inc();
3469 }
3470 LimitThresholdCrossed::Hard(_, _) => {
3471 $metric.with_label_values(&[metered_str, "hard"]).inc();
3472 }
3473 };
3474 result
3475 }};
3476}
3477
3478#[cfg(all(test, not(msim)))]
3479mod test {
3480 use insta::assert_yaml_snapshot;
3481
3482 use super::*;
3483
3484 #[test]
3485 fn snapshot_tests() {
3486 println!("\n============================================================================");
3487 println!("! !");
3488 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
3489 println!("! !");
3490 println!("============================================================================\n");
3491 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
3492 let chain_str = match chain_id {
3497 Chain::Unknown => "".to_string(),
3498 _ => format!("{chain_id:?}_"),
3499 };
3500 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
3501 let cur = ProtocolVersion::new(i);
3502 assert_yaml_snapshot!(
3503 format!("{}version_{}", chain_str, cur.as_u64()),
3504 ProtocolConfig::get_for_version(cur, *chain_id)
3505 );
3506 }
3507 }
3508 }
3509
3510 #[test]
3511 fn test_getters() {
3512 let prot: ProtocolConfig =
3513 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3514 assert_eq!(
3515 prot.max_arguments(),
3516 prot.max_arguments_as_option().unwrap()
3517 );
3518 }
3519
3520 #[test]
3521 fn test_setters() {
3522 let mut prot: ProtocolConfig =
3523 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3524 prot.set_max_arguments_for_testing(123);
3525 assert_eq!(prot.max_arguments(), 123);
3526
3527 prot.set_max_arguments_from_str_for_testing("321".to_string());
3528 assert_eq!(prot.max_arguments(), 321);
3529
3530 prot.disable_max_arguments_for_testing();
3531 assert_eq!(prot.max_arguments_as_option(), None);
3532
3533 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
3534 assert_eq!(prot.max_arguments(), 456);
3535 }
3536
3537 #[test]
3538 #[should_panic(expected = "unsupported version")]
3539 fn max_version_test() {
3540 let _ = ProtocolConfig::get_for_version_impl(
3543 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
3544 Chain::Unknown,
3545 );
3546 }
3547
3548 #[test]
3549 fn lookup_by_string_test() {
3550 let prot: ProtocolConfig =
3551 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3552 assert!(prot.lookup_attr("some random string".to_string()).is_none());
3554
3555 assert!(
3556 prot.lookup_attr("max_arguments".to_string())
3557 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
3558 );
3559
3560 assert!(
3562 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3563 .is_none()
3564 );
3565 assert!(
3566 prot.attr_map()
3567 .get("poseidon_bn254_cost_base")
3568 .unwrap()
3569 .is_none()
3570 );
3571
3572 let prot: ProtocolConfig =
3574 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3575
3576 assert!(
3577 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3578 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3579 );
3580 assert!(
3581 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
3582 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3583 );
3584
3585 let prot: ProtocolConfig =
3587 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3588 assert!(
3590 prot.feature_flags
3591 .lookup_attr("some random string".to_owned())
3592 .is_none()
3593 );
3594 assert!(
3595 !prot
3596 .feature_flags
3597 .attr_map()
3598 .contains_key("some random string")
3599 );
3600
3601 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
3603 assert!(
3604 prot.feature_flags
3605 .attr_map()
3606 .get("enable_poseidon")
3607 .unwrap()
3608 == &false
3609 );
3610 let prot: ProtocolConfig =
3611 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3612 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
3614 assert!(
3615 prot.feature_flags
3616 .attr_map()
3617 .get("enable_poseidon")
3618 .unwrap()
3619 == &true
3620 );
3621 }
3622
3623 #[test]
3624 fn limit_range_fn_test() {
3625 let low = 100u32;
3626 let high = 10000u64;
3627
3628 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
3629 assert!(matches!(
3630 check_limit!(255u16, low, high),
3631 LimitThresholdCrossed::Soft(255u128, 100)
3632 ));
3633 assert!(matches!(
3640 check_limit!(2550000u64, low, high),
3641 LimitThresholdCrossed::Hard(2550000, 10000)
3642 ));
3643
3644 assert!(matches!(
3645 check_limit!(2550000u64, high, high),
3646 LimitThresholdCrossed::Hard(2550000, 10000)
3647 ));
3648
3649 assert!(matches!(
3650 check_limit!(1u8, high),
3651 LimitThresholdCrossed::None
3652 ));
3653
3654 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
3655
3656 assert!(matches!(
3657 check_limit!(2550000u64, high),
3658 LimitThresholdCrossed::Hard(2550000, 10000)
3659 ));
3660 }
3661}