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)]
191pub struct ProtocolVersion(u64);
192
193impl ProtocolVersion {
194 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
200
201 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
202
203 #[cfg(not(msim))]
204 const MAX_ALLOWED: Self = Self::MAX;
205
206 #[cfg(msim)]
209 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
210
211 pub fn new(v: u64) -> Self {
212 Self(v)
213 }
214
215 pub const fn as_u64(&self) -> u64 {
216 self.0
217 }
218
219 pub fn max() -> Self {
222 Self::MAX
223 }
224}
225
226impl From<u64> for ProtocolVersion {
227 fn from(v: u64) -> Self {
228 Self::new(v)
229 }
230}
231
232impl std::ops::Sub<u64> for ProtocolVersion {
233 type Output = Self;
234 fn sub(self, rhs: u64) -> Self::Output {
235 Self::new(self.0 - rhs)
236 }
237}
238
239impl std::ops::Add<u64> for ProtocolVersion {
240 type Output = Self;
241 fn add(self, rhs: u64) -> Self::Output {
242 Self::new(self.0 + rhs)
243 }
244}
245
246#[derive(
247 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
248)]
249pub enum Chain {
250 Mainnet,
251 Testnet,
252 #[default]
253 Unknown,
254}
255
256impl Chain {
257 pub fn as_str(self) -> &'static str {
258 match self {
259 Chain::Mainnet => "mainnet",
260 Chain::Testnet => "testnet",
261 Chain::Unknown => "unknown",
262 }
263 }
264}
265
266pub struct Error(pub String);
267
268#[derive(
272 Default,
273 Clone,
274 Serialize,
275 Deserialize,
276 Debug,
277 ProtocolConfigFeatureFlagsGetters,
278 ProtocolConfigOverride,
279)]
280struct FeatureFlags {
281 #[serde(skip_serializing_if = "is_true")]
287 disable_invariant_violation_check_in_swap_loc: bool,
288
289 #[serde(skip_serializing_if = "is_true")]
292 no_extraneous_module_bytes: bool,
293
294 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
296 consensus_transaction_ordering: ConsensusTransactionOrdering,
297
298 #[serde(skip_serializing_if = "is_true")]
301 hardened_otw_check: bool,
302
303 #[serde(skip_serializing_if = "is_false")]
305 enable_poseidon: bool,
306
307 #[serde(skip_serializing_if = "is_false")]
309 enable_group_ops_native_function_msm: bool,
310
311 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
313 per_object_congestion_control_mode: PerObjectCongestionControlMode,
314
315 #[serde(
317 default = "ConsensusChoice::mysticeti_deprecated",
318 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
319 )]
320 consensus_choice: ConsensusChoice,
321
322 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
324 consensus_network: ConsensusNetwork,
325
326 #[deprecated]
328 #[serde(skip_serializing_if = "Option::is_none")]
329 zklogin_max_epoch_upper_bound_delta: Option<u64>,
330
331 #[serde(skip_serializing_if = "is_false")]
333 enable_vdf: bool,
334
335 #[serde(skip_serializing_if = "is_false")]
337 passkey_auth: bool,
338
339 #[serde(skip_serializing_if = "is_true")]
342 rethrow_serialization_type_layout_errors: bool,
343
344 #[serde(skip_serializing_if = "is_false")]
346 relocate_event_module: bool,
347
348 #[serde(skip_serializing_if = "is_false")]
350 protocol_defined_base_fee: bool,
351
352 #[serde(skip_serializing_if = "is_false")]
354 uncompressed_g1_group_elements: bool,
355
356 #[serde(skip_serializing_if = "is_false")]
358 disallow_new_modules_in_deps_only_packages: bool,
359
360 #[serde(skip_serializing_if = "is_false")]
362 native_charging_v2: bool,
363
364 #[serde(skip_serializing_if = "is_false")]
366 convert_type_argument_error: bool,
367
368 #[serde(skip_serializing_if = "is_false")]
370 consensus_round_prober: bool,
371
372 #[serde(skip_serializing_if = "is_false")]
374 consensus_distributed_vote_scoring_strategy: bool,
375
376 #[serde(skip_serializing_if = "is_false")]
380 consensus_linearize_subdag_v2: bool,
381
382 #[serde(skip_serializing_if = "is_false")]
384 variant_nodes: bool,
385
386 #[serde(skip_serializing_if = "is_false")]
388 consensus_smart_ancestor_selection: bool,
389
390 #[serde(skip_serializing_if = "is_false")]
392 consensus_round_prober_probe_accepted_rounds: bool,
393
394 #[serde(skip_serializing_if = "is_false")]
396 consensus_zstd_compression: bool,
397
398 #[serde(skip_serializing_if = "is_false")]
401 congestion_control_min_free_execution_slot: bool,
402
403 #[serde(skip_serializing_if = "is_false")]
405 accept_passkey_in_multisig: bool,
406
407 #[serde(skip_serializing_if = "is_false")]
409 consensus_batched_block_sync: bool,
410
411 #[serde(skip_serializing_if = "is_false")]
414 congestion_control_gas_price_feedback_mechanism: bool,
415
416 #[serde(skip_serializing_if = "is_false")]
418 validate_identifier_inputs: bool,
419
420 #[serde(skip_serializing_if = "is_false")]
423 minimize_child_object_mutations: bool,
424
425 #[serde(skip_serializing_if = "is_false")]
427 dependency_linkage_error: bool,
428
429 #[serde(skip_serializing_if = "is_false")]
431 additional_multisig_checks: bool,
432
433 #[serde(skip_serializing_if = "is_false")]
436 normalize_ptb_arguments: bool,
437
438 #[serde(skip_serializing_if = "is_false")]
442 select_committee_from_eligible_validators: bool,
443
444 #[serde(skip_serializing_if = "is_false")]
451 track_non_committee_eligible_validators: bool,
452
453 #[serde(skip_serializing_if = "is_false")]
459 select_committee_supporting_next_epoch_version: bool,
460
461 #[serde(skip_serializing_if = "is_false")]
465 consensus_median_timestamp_with_checkpoint_enforcement: bool,
466
467 #[serde(skip_serializing_if = "is_false")]
469 consensus_commit_transactions_only_for_traversed_headers: bool,
470
471 #[serde(skip_serializing_if = "is_false")]
473 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
474
475 #[serde(skip_serializing_if = "is_false")]
478 separate_gas_price_feedback_mechanism_for_randomness: bool,
479
480 #[serde(skip_serializing_if = "is_false")]
483 metadata_in_module_bytes: bool,
484
485 #[serde(skip_serializing_if = "is_false")]
487 publish_package_metadata: bool,
488
489 #[serde(skip_serializing_if = "is_false")]
491 enable_move_authentication: bool,
492
493 #[serde(skip_serializing_if = "is_false")]
495 enable_move_authentication_for_sponsor: bool,
496
497 #[serde(skip_serializing_if = "is_false")]
499 pass_validator_scores_to_advance_epoch: bool,
500
501 #[serde(skip_serializing_if = "is_false")]
503 calculate_validator_scores: bool,
504
505 #[serde(skip_serializing_if = "is_false")]
507 adjust_rewards_by_score: bool,
508
509 #[serde(skip_serializing_if = "is_false")]
512 pass_calculated_validator_scores_to_advance_epoch: bool,
513
514 #[serde(skip_serializing_if = "is_false")]
519 consensus_fast_commit_sync: bool,
520
521 #[serde(skip_serializing_if = "is_false")]
524 consensus_block_restrictions: bool,
525
526 #[serde(skip_serializing_if = "is_false")]
528 move_native_tx_context: bool,
529
530 #[serde(skip_serializing_if = "is_false")]
532 additional_borrow_checks: bool,
533
534 #[serde(skip_serializing_if = "is_false")]
536 pre_consensus_sponsor_only_move_authentication: bool,
537
538 #[serde(skip_serializing_if = "is_false")]
540 consensus_starfish_speed: bool,
541
542 #[serde(skip_serializing_if = "is_false")]
549 always_advance_dkg_to_resolution: bool,
550
551 #[serde(skip_serializing_if = "is_false")]
556 enable_pcool_flow: bool,
557
558 #[serde(skip_serializing_if = "is_false")]
560 validator_metadata_verify_v2: bool,
561
562 #[serde(skip_serializing_if = "is_false")]
566 deny_rule_governance: bool,
567
568 #[serde(skip_serializing_if = "is_false")]
571 package_metadata_with_dynamic_module_metadata: bool,
572
573 #[serde(skip_serializing_if = "is_false")]
576 report_move_authentication_error: bool,
577}
578
579fn is_true(b: &bool) -> bool {
580 *b
581}
582
583fn is_false(b: &bool) -> bool {
584 !b
585}
586
587#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
589pub enum ConsensusTransactionOrdering {
590 #[default]
593 None,
594 ByGasPrice,
596}
597
598impl ConsensusTransactionOrdering {
599 pub fn is_none(&self) -> bool {
600 matches!(self, ConsensusTransactionOrdering::None)
601 }
602}
603
604#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
606pub enum PerObjectCongestionControlMode {
607 #[default]
608 None, TotalGasBudget, TotalTxCount, }
612
613impl PerObjectCongestionControlMode {
614 pub fn is_none(&self) -> bool {
615 matches!(self, PerObjectCongestionControlMode::None)
616 }
617}
618
619#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
621pub enum ConsensusChoice {
622 #[deprecated(note = "Mysticeti was replaced by Starfish")]
625 MysticetiDeprecated,
626 #[default]
627 Starfish,
628}
629
630#[expect(deprecated)]
631impl ConsensusChoice {
632 fn mysticeti_deprecated() -> Self {
639 ConsensusChoice::MysticetiDeprecated
640 }
641
642 pub fn is_mysticeti_deprecated(&self) -> bool {
643 matches!(self, ConsensusChoice::MysticetiDeprecated)
644 }
645 pub fn is_starfish(&self) -> bool {
646 matches!(self, ConsensusChoice::Starfish)
647 }
648}
649
650#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
652pub enum ConsensusNetwork {
653 #[default]
654 Tonic,
655}
656
657impl ConsensusNetwork {
658 pub fn is_tonic(&self) -> bool {
659 matches!(self, ConsensusNetwork::Tonic)
660 }
661}
662
663#[skip_serializing_none]
697#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
698pub struct ProtocolConfig {
699 pub version: ProtocolVersion,
700
701 feature_flags: FeatureFlags,
702
703 max_tx_size_bytes: Option<u64>,
708
709 max_input_objects: Option<u64>,
712
713 max_size_written_objects: Option<u64>,
718 max_size_written_objects_system_tx: Option<u64>,
722
723 max_serialized_tx_effects_size_bytes: Option<u64>,
725
726 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
728
729 max_gas_payment_objects: Option<u32>,
731
732 max_modules_in_publish: Option<u32>,
734
735 max_package_dependencies: Option<u32>,
737
738 max_arguments: Option<u32>,
741
742 max_type_arguments: Option<u32>,
744
745 max_type_argument_depth: Option<u32>,
747
748 max_pure_argument_size: Option<u32>,
750
751 max_programmable_tx_commands: Option<u32>,
753
754 move_binary_format_version: Option<u32>,
760 min_move_binary_format_version: Option<u32>,
761
762 binary_module_handles: Option<u16>,
764 binary_struct_handles: Option<u16>,
765 binary_function_handles: Option<u16>,
766 binary_function_instantiations: Option<u16>,
767 binary_signatures: Option<u16>,
768 binary_constant_pool: Option<u16>,
769 binary_identifiers: Option<u16>,
770 binary_address_identifiers: Option<u16>,
771 binary_struct_defs: Option<u16>,
772 binary_struct_def_instantiations: Option<u16>,
773 binary_function_defs: Option<u16>,
774 binary_field_handles: Option<u16>,
775 binary_field_instantiations: Option<u16>,
776 binary_friend_decls: Option<u16>,
777 binary_enum_defs: Option<u16>,
778 binary_enum_def_instantiations: Option<u16>,
779 binary_variant_handles: Option<u16>,
780 binary_variant_instantiation_handles: Option<u16>,
781
782 max_move_object_size: Option<u64>,
785
786 max_move_package_size: Option<u64>,
791
792 max_publish_or_upgrade_per_ptb: Option<u64>,
795
796 max_tx_gas: Option<u64>,
798
799 max_auth_gas: Option<u64>,
801
802 max_gas_price: Option<u64>,
805
806 max_gas_computation_bucket: Option<u64>,
809
810 gas_rounding_step: Option<u64>,
812
813 max_loop_depth: Option<u64>,
815
816 max_generic_instantiation_length: Option<u64>,
819
820 max_function_parameters: Option<u64>,
823
824 max_basic_blocks: Option<u64>,
827
828 max_value_stack_size: Option<u64>,
830
831 max_type_nodes: Option<u64>,
835
836 max_push_size: Option<u64>,
839
840 max_struct_definitions: Option<u64>,
843
844 max_function_definitions: Option<u64>,
847
848 max_fields_in_struct: Option<u64>,
851
852 max_dependency_depth: Option<u64>,
855
856 max_num_event_emit: Option<u64>,
859
860 max_num_new_move_object_ids: Option<u64>,
863
864 max_num_new_move_object_ids_system_tx: Option<u64>,
867
868 max_num_deleted_move_object_ids: Option<u64>,
871
872 max_num_deleted_move_object_ids_system_tx: Option<u64>,
875
876 max_num_transferred_move_object_ids: Option<u64>,
879
880 max_num_transferred_move_object_ids_system_tx: Option<u64>,
883
884 max_event_emit_size: Option<u64>,
886
887 max_event_emit_size_total: Option<u64>,
889
890 max_move_vector_len: Option<u64>,
893
894 max_move_identifier_len: Option<u64>,
897
898 max_move_value_depth: Option<u64>,
900
901 max_move_enum_variants: Option<u64>,
904
905 max_back_edges_per_function: Option<u64>,
908
909 max_back_edges_per_module: Option<u64>,
912
913 max_verifier_meter_ticks_per_function: Option<u64>,
916
917 max_meter_ticks_per_module: Option<u64>,
920
921 max_meter_ticks_per_package: Option<u64>,
924
925 object_runtime_max_num_cached_objects: Option<u64>,
932
933 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
936
937 object_runtime_max_num_store_entries: Option<u64>,
940
941 object_runtime_max_num_store_entries_system_tx: Option<u64>,
944
945 base_tx_cost_fixed: Option<u64>,
950
951 package_publish_cost_fixed: Option<u64>,
955
956 base_tx_cost_per_byte: Option<u64>,
960
961 package_publish_cost_per_byte: Option<u64>,
963
964 obj_access_cost_read_per_byte: Option<u64>,
966
967 obj_access_cost_mutate_per_byte: Option<u64>,
969
970 obj_access_cost_delete_per_byte: Option<u64>,
972
973 obj_access_cost_verify_per_byte: Option<u64>,
983
984 max_type_to_layout_nodes: Option<u64>,
986
987 max_ptb_value_size: Option<u64>,
989
990 gas_model_version: Option<u64>,
995
996 obj_data_cost_refundable: Option<u64>,
1002
1003 obj_metadata_cost_non_refundable: Option<u64>,
1007
1008 storage_rebate_rate: Option<u64>,
1014
1015 reward_slashing_rate: Option<u64>,
1018
1019 storage_gas_price: Option<u64>,
1021
1022 base_gas_price: Option<u64>,
1024
1025 validator_target_reward: Option<u64>,
1027
1028 max_transactions_per_checkpoint: Option<u64>,
1035
1036 max_checkpoint_size_bytes: Option<u64>,
1040
1041 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
1047
1048 address_from_bytes_cost_base: Option<u64>,
1053 address_to_u256_cost_base: Option<u64>,
1055 address_from_u256_cost_base: Option<u64>,
1057
1058 config_read_setting_impl_cost_base: Option<u64>,
1063 config_read_setting_impl_cost_per_byte: Option<u64>,
1064
1065 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
1069 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
1070 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
1071 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
1072 dynamic_field_add_child_object_cost_base: Option<u64>,
1075 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
1076 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
1077 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
1078 dynamic_field_borrow_child_object_cost_base: Option<u64>,
1081 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1082 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1083 dynamic_field_remove_child_object_cost_base: Option<u64>,
1086 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1087 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1088 dynamic_field_has_child_object_cost_base: Option<u64>,
1091 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1094 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1095 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1096
1097 event_emit_cost_base: Option<u64>,
1100 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1101 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1102 event_emit_output_cost_per_byte: Option<u64>,
1103
1104 object_borrow_uid_cost_base: Option<u64>,
1107 object_delete_impl_cost_base: Option<u64>,
1109 object_record_new_uid_cost_base: Option<u64>,
1111
1112 transfer_transfer_internal_cost_base: Option<u64>,
1115 transfer_freeze_object_cost_base: Option<u64>,
1117 transfer_share_object_cost_base: Option<u64>,
1119 transfer_receive_object_cost_base: Option<u64>,
1122
1123 tx_context_derive_id_cost_base: Option<u64>,
1126 tx_context_fresh_id_cost_base: Option<u64>,
1127 tx_context_sender_cost_base: Option<u64>,
1128 tx_context_digest_cost_base: Option<u64>,
1129 tx_context_epoch_cost_base: Option<u64>,
1130 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1131 tx_context_sponsor_cost_base: Option<u64>,
1132 tx_context_rgp_cost_base: Option<u64>,
1133 tx_context_gas_price_cost_base: Option<u64>,
1134 tx_context_gas_budget_cost_base: Option<u64>,
1135 tx_context_ids_created_cost_base: Option<u64>,
1136 tx_context_replace_cost_base: Option<u64>,
1137
1138 types_is_one_time_witness_cost_base: Option<u64>,
1141 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1142 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1143
1144 validator_validate_metadata_cost_base: Option<u64>,
1147 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1148
1149 crypto_invalid_arguments_cost: Option<u64>,
1151 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1153 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1154 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1155
1156 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1158 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1159 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1160
1161 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1163 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1164 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1165 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1166 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1167 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1168
1169 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1171
1172 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1174 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1175 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1176 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1177 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1178 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1179
1180 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1182 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1183 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1184 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1185 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1186 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1187
1188 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1190 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1191 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1192 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1193 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1194 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1195
1196 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1198 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1199 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1200
1201 ed25519_ed25519_verify_cost_base: Option<u64>,
1203 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1204 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1205
1206 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1208 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1209
1210 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1212 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1213 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1214 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1215 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1216
1217 hash_blake2b256_cost_base: Option<u64>,
1219 hash_blake2b256_data_cost_per_byte: Option<u64>,
1220 hash_blake2b256_data_cost_per_block: Option<u64>,
1221
1222 hash_keccak256_cost_base: Option<u64>,
1224 hash_keccak256_data_cost_per_byte: Option<u64>,
1225 hash_keccak256_data_cost_per_block: Option<u64>,
1226
1227 poseidon_bn254_cost_base: Option<u64>,
1229 poseidon_bn254_cost_per_block: Option<u64>,
1230
1231 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1233 group_ops_bls12381_decode_g1_cost: Option<u64>,
1234 group_ops_bls12381_decode_g2_cost: Option<u64>,
1235 group_ops_bls12381_decode_gt_cost: Option<u64>,
1236 group_ops_bls12381_scalar_add_cost: Option<u64>,
1237 group_ops_bls12381_g1_add_cost: Option<u64>,
1238 group_ops_bls12381_g2_add_cost: Option<u64>,
1239 group_ops_bls12381_gt_add_cost: Option<u64>,
1240 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1241 group_ops_bls12381_g1_sub_cost: Option<u64>,
1242 group_ops_bls12381_g2_sub_cost: Option<u64>,
1243 group_ops_bls12381_gt_sub_cost: Option<u64>,
1244 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1245 group_ops_bls12381_g1_mul_cost: Option<u64>,
1246 group_ops_bls12381_g2_mul_cost: Option<u64>,
1247 group_ops_bls12381_gt_mul_cost: Option<u64>,
1248 group_ops_bls12381_scalar_div_cost: Option<u64>,
1249 group_ops_bls12381_g1_div_cost: Option<u64>,
1250 group_ops_bls12381_g2_div_cost: Option<u64>,
1251 group_ops_bls12381_gt_div_cost: Option<u64>,
1252 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1253 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1254 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1255 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1256 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1257 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1258 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1259 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1260 group_ops_bls12381_msm_max_len: Option<u32>,
1261 group_ops_bls12381_pairing_cost: Option<u64>,
1262 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1263 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1264 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1265 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1266 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1267
1268 hmac_hmac_sha3_256_cost_base: Option<u64>,
1270 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1271 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1272
1273 #[deprecated]
1275 check_zklogin_id_cost_base: Option<u64>,
1276 #[deprecated]
1278 check_zklogin_issuer_cost_base: Option<u64>,
1279
1280 vdf_verify_vdf_cost: Option<u64>,
1281 vdf_hash_to_input_cost: Option<u64>,
1282
1283 bcs_per_byte_serialized_cost: Option<u64>,
1285 bcs_legacy_min_output_size_cost: Option<u64>,
1286 bcs_failure_cost: Option<u64>,
1287
1288 hash_sha2_256_base_cost: Option<u64>,
1289 hash_sha2_256_per_byte_cost: Option<u64>,
1290 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1291 hash_sha3_256_base_cost: Option<u64>,
1292 hash_sha3_256_per_byte_cost: Option<u64>,
1293 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1294 type_name_get_base_cost: Option<u64>,
1295 type_name_get_per_byte_cost: Option<u64>,
1296
1297 string_check_utf8_base_cost: Option<u64>,
1298 string_check_utf8_per_byte_cost: Option<u64>,
1299 string_is_char_boundary_base_cost: Option<u64>,
1300 string_sub_string_base_cost: Option<u64>,
1301 string_sub_string_per_byte_cost: Option<u64>,
1302 string_index_of_base_cost: Option<u64>,
1303 string_index_of_per_byte_pattern_cost: Option<u64>,
1304 string_index_of_per_byte_searched_cost: Option<u64>,
1305
1306 vector_empty_base_cost: Option<u64>,
1307 vector_length_base_cost: Option<u64>,
1308 vector_push_back_base_cost: Option<u64>,
1309 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1310 vector_borrow_base_cost: Option<u64>,
1311 vector_pop_back_base_cost: Option<u64>,
1312 vector_destroy_empty_base_cost: Option<u64>,
1313 vector_swap_base_cost: Option<u64>,
1314 debug_print_base_cost: Option<u64>,
1315 debug_print_stack_trace_base_cost: Option<u64>,
1316
1317 execution_version: Option<u64>,
1319
1320 consensus_bad_nodes_stake_threshold: Option<u64>,
1324
1325 #[deprecated]
1326 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1327 #[deprecated]
1331 max_age_of_jwk_in_epochs: Option<u64>,
1332
1333 random_beacon_reduction_allowed_delta: Option<u16>,
1337
1338 random_beacon_reduction_lower_bound: Option<u32>,
1341
1342 random_beacon_dkg_timeout_round: Option<u32>,
1345
1346 random_beacon_min_round_interval_ms: Option<u64>,
1348
1349 random_beacon_dkg_version: Option<u64>,
1353
1354 consensus_max_transaction_size_bytes: Option<u64>,
1359 consensus_max_transactions_in_block_bytes: Option<u64>,
1361 consensus_max_num_transactions_in_block: Option<u64>,
1363
1364 max_deferral_rounds_for_congestion_control: Option<u64>,
1368
1369 min_checkpoint_interval_ms: Option<u64>,
1371
1372 checkpoint_rate_window_size: Option<u64>,
1382
1383 checkpoint_summary_version_specific_data: Option<u64>,
1385
1386 max_soft_bundle_size: Option<u64>,
1389
1390 bridge_should_try_to_finalize_committee: Option<bool>,
1395
1396 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1402
1403 max_committee_members_count: Option<u64>,
1407
1408 consensus_gc_depth: Option<u32>,
1411
1412 consensus_max_acknowledgments_per_block: Option<u32>,
1418
1419 max_congestion_limit_overshoot_per_commit: Option<u64>,
1424
1425 scorer_version: Option<u16>,
1434
1435 auth_context_digest_cost_base: Option<u64>,
1438 auth_context_tx_data_bytes_cost_base: Option<u64>,
1440 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1441 auth_context_tx_commands_cost_base: Option<u64>,
1443 auth_context_tx_commands_cost_per_byte: Option<u64>,
1444 auth_context_tx_inputs_cost_base: Option<u64>,
1446 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1447 auth_context_replace_cost_base: Option<u64>,
1450 auth_context_replace_cost_per_byte: Option<u64>,
1451 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1455
1456 consensus_commits_per_schedule: Option<u32>,
1459
1460 min_validator_count: Option<u64>,
1463
1464 max_validator_count: Option<u64>,
1468
1469 min_validator_joining_stake: Option<u64>,
1473
1474 validator_low_stake_threshold: Option<u64>,
1479
1480 validator_very_low_stake_threshold: Option<u64>,
1484
1485 validator_low_stake_grace_period: Option<u64>,
1489}
1490
1491impl ProtocolConfig {
1493 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1506 self.feature_flags
1507 .disable_invariant_violation_check_in_swap_loc
1508 }
1509
1510 pub fn no_extraneous_module_bytes(&self) -> bool {
1511 self.feature_flags.no_extraneous_module_bytes
1512 }
1513
1514 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1515 self.feature_flags.consensus_transaction_ordering
1516 }
1517
1518 pub fn dkg_version(&self) -> u64 {
1519 self.random_beacon_dkg_version.unwrap_or(1)
1521 }
1522
1523 pub fn hardened_otw_check(&self) -> bool {
1524 self.feature_flags.hardened_otw_check
1525 }
1526
1527 pub fn enable_poseidon(&self) -> bool {
1528 self.feature_flags.enable_poseidon
1529 }
1530
1531 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1532 self.feature_flags.enable_group_ops_native_function_msm
1533 }
1534
1535 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1536 self.feature_flags.per_object_congestion_control_mode
1537 }
1538
1539 pub fn consensus_choice(&self) -> ConsensusChoice {
1540 self.feature_flags.consensus_choice
1541 }
1542
1543 pub fn consensus_network(&self) -> ConsensusNetwork {
1544 self.feature_flags.consensus_network
1545 }
1546
1547 pub fn enable_vdf(&self) -> bool {
1548 self.feature_flags.enable_vdf
1549 }
1550
1551 pub fn passkey_auth(&self) -> bool {
1552 self.feature_flags.passkey_auth
1553 }
1554
1555 pub fn max_transaction_size_bytes(&self) -> u64 {
1556 self.consensus_max_transaction_size_bytes
1558 .unwrap_or(256 * 1024)
1559 }
1560
1561 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1562 if cfg!(msim) {
1563 256 * 1024
1564 } else {
1565 self.consensus_max_transactions_in_block_bytes
1566 .unwrap_or(512 * 1024)
1567 }
1568 }
1569
1570 pub fn max_num_transactions_in_block(&self) -> u64 {
1571 if cfg!(msim) {
1572 8
1573 } else {
1574 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1575 }
1576 }
1577
1578 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1579 self.feature_flags.rethrow_serialization_type_layout_errors
1580 }
1581
1582 pub fn relocate_event_module(&self) -> bool {
1583 self.feature_flags.relocate_event_module
1584 }
1585
1586 pub fn protocol_defined_base_fee(&self) -> bool {
1587 self.feature_flags.protocol_defined_base_fee
1588 }
1589
1590 pub fn uncompressed_g1_group_elements(&self) -> bool {
1591 self.feature_flags.uncompressed_g1_group_elements
1592 }
1593
1594 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1595 self.feature_flags
1596 .disallow_new_modules_in_deps_only_packages
1597 }
1598
1599 pub fn native_charging_v2(&self) -> bool {
1600 self.feature_flags.native_charging_v2
1601 }
1602
1603 pub fn consensus_round_prober(&self) -> bool {
1604 self.feature_flags.consensus_round_prober
1605 }
1606
1607 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1608 self.feature_flags
1609 .consensus_distributed_vote_scoring_strategy
1610 }
1611
1612 pub fn gc_depth(&self) -> u32 {
1613 if cfg!(msim) {
1614 min(5, self.consensus_gc_depth.unwrap_or(0))
1616 } else {
1617 self.consensus_gc_depth.unwrap_or(0)
1618 }
1619 }
1620
1621 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1622 let res = self.feature_flags.consensus_linearize_subdag_v2;
1623 assert!(
1624 !res || self.gc_depth() > 0,
1625 "The consensus linearize sub dag V2 requires GC to be enabled"
1626 );
1627 res
1628 }
1629
1630 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1631 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1632 }
1633
1634 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1635 2 * committee_size
1636 }
1637
1638 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1639 committee_size
1640 }
1641
1642 pub fn variant_nodes(&self) -> bool {
1643 self.feature_flags.variant_nodes
1644 }
1645
1646 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1647 self.feature_flags.consensus_smart_ancestor_selection
1648 }
1649
1650 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1651 self.feature_flags
1652 .consensus_round_prober_probe_accepted_rounds
1653 }
1654
1655 pub fn consensus_zstd_compression(&self) -> bool {
1656 self.feature_flags.consensus_zstd_compression
1657 }
1658
1659 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1660 self.feature_flags
1661 .congestion_control_min_free_execution_slot
1662 }
1663
1664 pub fn accept_passkey_in_multisig(&self) -> bool {
1665 self.feature_flags.accept_passkey_in_multisig
1666 }
1667
1668 pub fn consensus_batched_block_sync(&self) -> bool {
1669 self.feature_flags.consensus_batched_block_sync
1670 }
1671
1672 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1675 self.feature_flags
1676 .congestion_control_gas_price_feedback_mechanism
1677 }
1678
1679 pub fn validate_identifier_inputs(&self) -> bool {
1680 self.feature_flags.validate_identifier_inputs
1681 }
1682
1683 pub fn minimize_child_object_mutations(&self) -> bool {
1684 self.feature_flags.minimize_child_object_mutations
1685 }
1686
1687 pub fn dependency_linkage_error(&self) -> bool {
1688 self.feature_flags.dependency_linkage_error
1689 }
1690
1691 pub fn additional_multisig_checks(&self) -> bool {
1692 self.feature_flags.additional_multisig_checks
1693 }
1694
1695 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1696 0
1699 }
1700
1701 pub fn normalize_ptb_arguments(&self) -> bool {
1702 self.feature_flags.normalize_ptb_arguments
1703 }
1704
1705 pub fn select_committee_from_eligible_validators(&self) -> bool {
1706 let res = self.feature_flags.select_committee_from_eligible_validators;
1707 assert!(
1708 !res || (self.protocol_defined_base_fee()
1709 && self.max_committee_members_count_as_option().is_some()),
1710 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1711 );
1712 res
1713 }
1714
1715 pub fn track_non_committee_eligible_validators(&self) -> bool {
1716 self.feature_flags.track_non_committee_eligible_validators
1717 }
1718
1719 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1720 let res = self
1721 .feature_flags
1722 .select_committee_supporting_next_epoch_version;
1723 assert!(
1724 !res || (self.track_non_committee_eligible_validators()
1725 && self.select_committee_from_eligible_validators()),
1726 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1727 );
1728 res
1729 }
1730
1731 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1732 let res = self
1733 .feature_flags
1734 .consensus_median_timestamp_with_checkpoint_enforcement;
1735 assert!(
1736 !res || self.gc_depth() > 0,
1737 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1738 );
1739 res
1740 }
1741
1742 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1743 self.feature_flags
1744 .consensus_commit_transactions_only_for_traversed_headers
1745 }
1746
1747 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1750 self.feature_flags
1751 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1752 }
1753
1754 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1757 self.feature_flags
1758 .separate_gas_price_feedback_mechanism_for_randomness
1759 }
1760
1761 pub fn metadata_in_module_bytes(&self) -> bool {
1762 self.feature_flags.metadata_in_module_bytes
1763 }
1764
1765 pub fn publish_package_metadata(&self) -> bool {
1766 self.feature_flags.publish_package_metadata
1767 }
1768
1769 pub fn enable_move_authentication(&self) -> bool {
1770 self.feature_flags.enable_move_authentication
1771 }
1772
1773 pub fn additional_borrow_checks(&self) -> bool {
1774 self.feature_flags.additional_borrow_checks
1775 }
1776
1777 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1778 let enable_move_authentication_for_sponsor =
1779 self.feature_flags.enable_move_authentication_for_sponsor;
1780 assert!(
1781 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1782 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1783 );
1784 enable_move_authentication_for_sponsor
1785 }
1786
1787 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1788 self.feature_flags.pass_validator_scores_to_advance_epoch
1789 }
1790
1791 pub fn calculate_validator_scores(&self) -> bool {
1792 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1793 assert!(
1794 !calculate_validator_scores || self.scorer_version.is_some(),
1795 "calculate_validator_scores requires scorer_version to be set"
1796 );
1797 calculate_validator_scores
1798 }
1799
1800 pub fn adjust_rewards_by_score(&self) -> bool {
1801 let adjust = self.feature_flags.adjust_rewards_by_score;
1802 assert!(
1803 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1804 "adjust_rewards_by_score requires scorer_version to be set"
1805 );
1806 adjust
1807 }
1808
1809 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1810 let pass = self
1811 .feature_flags
1812 .pass_calculated_validator_scores_to_advance_epoch;
1813 assert!(
1814 !pass
1815 || (self.pass_validator_scores_to_advance_epoch()
1816 && self.calculate_validator_scores()),
1817 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
1818 );
1819 pass
1820 }
1821 pub fn consensus_fast_commit_sync(&self) -> bool {
1822 let res = self.feature_flags.consensus_fast_commit_sync;
1823 assert!(
1824 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
1825 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
1826 );
1827 res
1828 }
1829
1830 pub fn consensus_block_restrictions(&self) -> bool {
1831 self.feature_flags.consensus_block_restrictions
1832 }
1833
1834 pub fn move_native_tx_context(&self) -> bool {
1835 self.feature_flags.move_native_tx_context
1836 }
1837
1838 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
1839 let pre_consensus_sponsor_only_move_authentication = self
1840 .feature_flags
1841 .pre_consensus_sponsor_only_move_authentication;
1842 if pre_consensus_sponsor_only_move_authentication {
1843 assert!(
1844 self.enable_move_authentication(),
1845 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
1846 );
1847 assert!(
1848 self.enable_move_authentication_for_sponsor(),
1849 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
1850 );
1851 }
1852 pre_consensus_sponsor_only_move_authentication
1853 }
1854
1855 pub fn consensus_starfish_speed(&self) -> bool {
1856 let res = self.feature_flags.consensus_starfish_speed;
1857 assert!(
1858 !res || self.consensus_fast_commit_sync(),
1859 "consensus_starfish_speed requires consensus_fast_commit_sync to be enabled"
1860 );
1861 res
1862 }
1863
1864 pub fn always_advance_dkg_to_resolution(&self) -> bool {
1865 self.feature_flags.always_advance_dkg_to_resolution
1866 }
1867
1868 pub fn enable_pcool_flow(&self) -> bool {
1869 self.feature_flags.enable_pcool_flow
1870 }
1871
1872 pub fn validator_metadata_verify_v2(&self) -> bool {
1873 self.feature_flags.validator_metadata_verify_v2
1874 }
1875
1876 pub fn commits_per_schedule(&self) -> u32 {
1877 if cfg!(msim) {
1878 min(10, self.consensus_commits_per_schedule.unwrap_or(300))
1880 } else {
1881 self.consensus_commits_per_schedule.unwrap_or(300)
1882 }
1883 }
1884
1885 pub fn deny_rule_governance(&self) -> bool {
1886 self.feature_flags.deny_rule_governance
1887 }
1888
1889 pub fn package_metadata_with_dynamic_module_metadata(&self) -> bool {
1890 let res = self
1891 .feature_flags
1892 .package_metadata_with_dynamic_module_metadata;
1893 assert!(
1894 !res || self.publish_package_metadata(),
1895 "package_metadata_with_dynamic_module_metadata requires publish_package_metadata to be enabled"
1896 );
1897 res
1898 }
1899
1900 pub fn report_move_authentication_error(&self) -> bool {
1901 let report_move_authentication_error = self.feature_flags.report_move_authentication_error;
1902 assert!(
1903 !report_move_authentication_error || self.enable_move_authentication(),
1904 "report_move_authentication_error requires enable_move_authentication to be set"
1905 );
1906 report_move_authentication_error
1907 }
1908}
1909
1910#[cfg(not(msim))]
1911static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1912
1913#[cfg(msim)]
1915thread_local! {
1916 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1917}
1918
1919impl ProtocolConfig {
1921 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1924 assert!(
1926 version >= ProtocolVersion::MIN,
1927 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1928 version,
1929 ProtocolVersion::MIN.0,
1930 );
1931 assert!(
1932 version <= ProtocolVersion::MAX_ALLOWED,
1933 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1934 version,
1935 ProtocolVersion::MAX_ALLOWED.0,
1936 );
1937
1938 let mut ret = Self::get_for_version_impl(version, chain);
1939 ret.version = version;
1940
1941 ret = CONFIG_OVERRIDE.with(|ovr| {
1942 if let Some(override_fn) = &*ovr.borrow() {
1943 warn!(
1944 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1945 );
1946 override_fn(version, ret)
1947 } else {
1948 ret
1949 }
1950 });
1951
1952 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1953 warn!(
1954 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1955 );
1956
1957 let overrides: ProtocolConfigOptional =
1959 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1960 .expect("failed to parse ProtocolConfig override env variables");
1961 overrides.apply_to(&mut ret);
1962
1963 let feature_flag_overrides: FeatureFlagsOptional =
1965 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_FEATURE_FLAGS_OVERRIDE")
1966 .expect("failed to parse ProtocolConfig feature flags override env variables");
1967
1968 feature_flag_overrides.apply_to(&mut ret.feature_flags);
1969 }
1970
1971 ret
1972 }
1973
1974 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1977 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1978 let mut ret = Self::get_for_version_impl(version, chain);
1979 ret.version = version;
1980 Some(ret)
1981 } else {
1982 None
1983 }
1984 }
1985
1986 #[cfg(not(msim))]
1987 pub fn poison_get_for_min_version() {
1988 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1989 }
1990
1991 #[cfg(not(msim))]
1992 fn load_poison_get_for_min_version() -> bool {
1993 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1994 }
1995
1996 #[cfg(msim)]
1997 pub fn poison_get_for_min_version() {
1998 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1999 }
2000
2001 #[cfg(msim)]
2002 fn load_poison_get_for_min_version() -> bool {
2003 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
2004 }
2005
2006 pub fn convert_type_argument_error(&self) -> bool {
2007 self.feature_flags.convert_type_argument_error
2008 }
2009
2010 pub fn get_for_min_version() -> Self {
2014 if Self::load_poison_get_for_min_version() {
2015 panic!("get_for_min_version called on validator");
2016 }
2017 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
2018 }
2019
2020 #[expect(non_snake_case)]
2031 pub fn get_for_max_version_UNSAFE() -> Self {
2032 if Self::load_poison_get_for_min_version() {
2033 panic!("get_for_max_version_UNSAFE called on validator");
2034 }
2035 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
2036 }
2037
2038 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
2039 #[cfg(msim)]
2040 {
2041 if version > ProtocolVersion::MAX {
2043 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
2044 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
2045 return config;
2046 }
2047 }
2048
2049 let mut cfg = Self {
2053 version,
2054
2055 feature_flags: Default::default(),
2056
2057 max_tx_size_bytes: Some(128 * 1024),
2058 max_input_objects: Some(2048),
2061 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
2062 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
2063 max_gas_payment_objects: Some(256),
2064 max_modules_in_publish: Some(64),
2065 max_package_dependencies: Some(32),
2066 max_arguments: Some(512),
2067 max_type_arguments: Some(16),
2068 max_type_argument_depth: Some(16),
2069 max_pure_argument_size: Some(16 * 1024),
2070 max_programmable_tx_commands: Some(1024),
2071 move_binary_format_version: Some(7),
2072 min_move_binary_format_version: Some(6),
2073 binary_module_handles: Some(100),
2074 binary_struct_handles: Some(300),
2075 binary_function_handles: Some(1500),
2076 binary_function_instantiations: Some(750),
2077 binary_signatures: Some(1000),
2078 binary_constant_pool: Some(4000),
2079 binary_identifiers: Some(10000),
2080 binary_address_identifiers: Some(100),
2081 binary_struct_defs: Some(200),
2082 binary_struct_def_instantiations: Some(100),
2083 binary_function_defs: Some(1000),
2084 binary_field_handles: Some(500),
2085 binary_field_instantiations: Some(250),
2086 binary_friend_decls: Some(100),
2087 binary_enum_defs: None,
2088 binary_enum_def_instantiations: None,
2089 binary_variant_handles: None,
2090 binary_variant_instantiation_handles: None,
2091 max_move_object_size: Some(250 * 1024),
2092 max_move_package_size: Some(100 * 1024),
2093 max_publish_or_upgrade_per_ptb: Some(5),
2094 max_auth_gas: None,
2096 max_tx_gas: Some(50_000_000_000),
2098 max_gas_price: Some(100_000),
2099 max_gas_computation_bucket: Some(5_000_000),
2100 max_loop_depth: Some(5),
2101 max_generic_instantiation_length: Some(32),
2102 max_function_parameters: Some(128),
2103 max_basic_blocks: Some(1024),
2104 max_value_stack_size: Some(1024),
2105 max_type_nodes: Some(256),
2106 max_push_size: Some(10000),
2107 max_struct_definitions: Some(200),
2108 max_function_definitions: Some(1000),
2109 max_fields_in_struct: Some(32),
2110 max_dependency_depth: Some(100),
2111 max_num_event_emit: Some(1024),
2112 max_num_new_move_object_ids: Some(2048),
2113 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
2114 max_num_deleted_move_object_ids: Some(2048),
2115 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
2116 max_num_transferred_move_object_ids: Some(2048),
2117 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
2118 max_event_emit_size: Some(250 * 1024),
2119 max_move_vector_len: Some(256 * 1024),
2120 max_type_to_layout_nodes: None,
2121 max_ptb_value_size: None,
2122
2123 max_back_edges_per_function: Some(10_000),
2124 max_back_edges_per_module: Some(10_000),
2125
2126 max_verifier_meter_ticks_per_function: Some(16_000_000),
2127
2128 max_meter_ticks_per_module: Some(16_000_000),
2129 max_meter_ticks_per_package: Some(16_000_000),
2130
2131 object_runtime_max_num_cached_objects: Some(1000),
2132 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2133 object_runtime_max_num_store_entries: Some(1000),
2134 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2135 base_tx_cost_fixed: Some(1_000),
2137 package_publish_cost_fixed: Some(1_000),
2138 base_tx_cost_per_byte: Some(0),
2139 package_publish_cost_per_byte: Some(80),
2140 obj_access_cost_read_per_byte: Some(15),
2141 obj_access_cost_mutate_per_byte: Some(40),
2142 obj_access_cost_delete_per_byte: Some(40),
2143 obj_access_cost_verify_per_byte: Some(200),
2144 obj_data_cost_refundable: Some(100),
2145 obj_metadata_cost_non_refundable: Some(50),
2146 gas_model_version: Some(1),
2147 storage_rebate_rate: Some(10000),
2148 reward_slashing_rate: Some(10000),
2150 storage_gas_price: Some(76),
2151 base_gas_price: None,
2152 validator_target_reward: Some(767_000 * 1_000_000_000),
2155 max_transactions_per_checkpoint: Some(10_000),
2156 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2157
2158 buffer_stake_for_protocol_upgrade_bps: Some(5000),
2160
2161 address_from_bytes_cost_base: Some(52),
2165 address_to_u256_cost_base: Some(52),
2167 address_from_u256_cost_base: Some(52),
2169
2170 config_read_setting_impl_cost_base: Some(100),
2173 config_read_setting_impl_cost_per_byte: Some(40),
2174
2175 dynamic_field_hash_type_and_key_cost_base: Some(100),
2179 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
2180 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
2181 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
2182 dynamic_field_add_child_object_cost_base: Some(100),
2185 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2186 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2187 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2188 dynamic_field_borrow_child_object_cost_base: Some(100),
2191 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2192 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2193 dynamic_field_remove_child_object_cost_base: Some(100),
2196 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2197 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2198 dynamic_field_has_child_object_cost_base: Some(100),
2201 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2204 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2205 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2206
2207 event_emit_cost_base: Some(52),
2210 event_emit_value_size_derivation_cost_per_byte: Some(2),
2211 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2212 event_emit_output_cost_per_byte: Some(10),
2213
2214 object_borrow_uid_cost_base: Some(52),
2217 object_delete_impl_cost_base: Some(52),
2219 object_record_new_uid_cost_base: Some(52),
2221
2222 transfer_transfer_internal_cost_base: Some(52),
2226 transfer_freeze_object_cost_base: Some(52),
2228 transfer_share_object_cost_base: Some(52),
2230 transfer_receive_object_cost_base: Some(52),
2231
2232 tx_context_derive_id_cost_base: Some(52),
2236 tx_context_fresh_id_cost_base: None,
2237 tx_context_sender_cost_base: None,
2238 tx_context_digest_cost_base: None,
2239 tx_context_epoch_cost_base: None,
2240 tx_context_epoch_timestamp_ms_cost_base: None,
2241 tx_context_sponsor_cost_base: None,
2242 tx_context_rgp_cost_base: None,
2243 tx_context_gas_price_cost_base: None,
2244 tx_context_gas_budget_cost_base: None,
2245 tx_context_ids_created_cost_base: None,
2246 tx_context_replace_cost_base: None,
2247
2248 types_is_one_time_witness_cost_base: Some(52),
2251 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2252 types_is_one_time_witness_type_cost_per_byte: Some(2),
2253
2254 validator_validate_metadata_cost_base: Some(52),
2258 validator_validate_metadata_data_cost_per_byte: Some(2),
2259
2260 crypto_invalid_arguments_cost: Some(100),
2262 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2264 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2265 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2266
2267 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2269 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2270 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2271
2272 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2274 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2275 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2276 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2277 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2278 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2279
2280 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2282
2283 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2285 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2286 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2287 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2288 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2289 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2290
2291 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2293 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2294 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2295 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2296 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2297 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2298
2299 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2301 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2302 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2303 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2304 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2305 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2306
2307 ecvrf_ecvrf_verify_cost_base: Some(52),
2309 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2310 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2311
2312 ed25519_ed25519_verify_cost_base: Some(52),
2314 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2315 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2316
2317 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2319 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2320
2321 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2323 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2324 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2325 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2326 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2327
2328 hash_blake2b256_cost_base: Some(52),
2330 hash_blake2b256_data_cost_per_byte: Some(2),
2331 hash_blake2b256_data_cost_per_block: Some(2),
2332 hash_keccak256_cost_base: Some(52),
2334 hash_keccak256_data_cost_per_byte: Some(2),
2335 hash_keccak256_data_cost_per_block: Some(2),
2336
2337 poseidon_bn254_cost_base: None,
2338 poseidon_bn254_cost_per_block: None,
2339
2340 hmac_hmac_sha3_256_cost_base: Some(52),
2342 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2343 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2344
2345 group_ops_bls12381_decode_scalar_cost: Some(52),
2347 group_ops_bls12381_decode_g1_cost: Some(52),
2348 group_ops_bls12381_decode_g2_cost: Some(52),
2349 group_ops_bls12381_decode_gt_cost: Some(52),
2350 group_ops_bls12381_scalar_add_cost: Some(52),
2351 group_ops_bls12381_g1_add_cost: Some(52),
2352 group_ops_bls12381_g2_add_cost: Some(52),
2353 group_ops_bls12381_gt_add_cost: Some(52),
2354 group_ops_bls12381_scalar_sub_cost: Some(52),
2355 group_ops_bls12381_g1_sub_cost: Some(52),
2356 group_ops_bls12381_g2_sub_cost: Some(52),
2357 group_ops_bls12381_gt_sub_cost: Some(52),
2358 group_ops_bls12381_scalar_mul_cost: Some(52),
2359 group_ops_bls12381_g1_mul_cost: Some(52),
2360 group_ops_bls12381_g2_mul_cost: Some(52),
2361 group_ops_bls12381_gt_mul_cost: Some(52),
2362 group_ops_bls12381_scalar_div_cost: Some(52),
2363 group_ops_bls12381_g1_div_cost: Some(52),
2364 group_ops_bls12381_g2_div_cost: Some(52),
2365 group_ops_bls12381_gt_div_cost: Some(52),
2366 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2367 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2368 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2369 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2370 group_ops_bls12381_g1_msm_base_cost: Some(52),
2371 group_ops_bls12381_g2_msm_base_cost: Some(52),
2372 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2373 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2374 group_ops_bls12381_msm_max_len: Some(32),
2375 group_ops_bls12381_pairing_cost: Some(52),
2376 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2377 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2378 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2379 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2380 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2381
2382 #[allow(deprecated)]
2384 check_zklogin_id_cost_base: Some(200),
2385 #[allow(deprecated)]
2386 check_zklogin_issuer_cost_base: Some(200),
2388
2389 vdf_verify_vdf_cost: None,
2390 vdf_hash_to_input_cost: None,
2391
2392 bcs_per_byte_serialized_cost: Some(2),
2393 bcs_legacy_min_output_size_cost: Some(1),
2394 bcs_failure_cost: Some(52),
2395 hash_sha2_256_base_cost: Some(52),
2396 hash_sha2_256_per_byte_cost: Some(2),
2397 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2398 hash_sha3_256_base_cost: Some(52),
2399 hash_sha3_256_per_byte_cost: Some(2),
2400 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2401 type_name_get_base_cost: Some(52),
2402 type_name_get_per_byte_cost: Some(2),
2403 string_check_utf8_base_cost: Some(52),
2404 string_check_utf8_per_byte_cost: Some(2),
2405 string_is_char_boundary_base_cost: Some(52),
2406 string_sub_string_base_cost: Some(52),
2407 string_sub_string_per_byte_cost: Some(2),
2408 string_index_of_base_cost: Some(52),
2409 string_index_of_per_byte_pattern_cost: Some(2),
2410 string_index_of_per_byte_searched_cost: Some(2),
2411 vector_empty_base_cost: Some(52),
2412 vector_length_base_cost: Some(52),
2413 vector_push_back_base_cost: Some(52),
2414 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2415 vector_borrow_base_cost: Some(52),
2416 vector_pop_back_base_cost: Some(52),
2417 vector_destroy_empty_base_cost: Some(52),
2418 vector_swap_base_cost: Some(52),
2419 debug_print_base_cost: Some(52),
2420 debug_print_stack_trace_base_cost: Some(52),
2421
2422 max_size_written_objects: Some(5 * 1000 * 1000),
2423 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2426
2427 max_move_identifier_len: Some(128),
2429 max_move_value_depth: Some(128),
2430 max_move_enum_variants: None,
2431
2432 gas_rounding_step: Some(1_000),
2433
2434 execution_version: Some(1),
2435
2436 max_event_emit_size_total: Some(
2439 256 * 250 * 1024, ),
2441
2442 consensus_bad_nodes_stake_threshold: Some(20),
2449
2450 #[allow(deprecated)]
2452 max_jwk_votes_per_validator_per_epoch: Some(240),
2453
2454 #[allow(deprecated)]
2455 max_age_of_jwk_in_epochs: Some(1),
2456
2457 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2461
2462 random_beacon_reduction_allowed_delta: Some(800),
2463
2464 random_beacon_reduction_lower_bound: Some(1000),
2465 random_beacon_dkg_timeout_round: Some(3000),
2466 random_beacon_min_round_interval_ms: Some(500),
2467
2468 random_beacon_dkg_version: Some(1),
2469
2470 consensus_max_num_transactions_in_block: Some(512),
2474
2475 max_deferral_rounds_for_congestion_control: Some(10),
2476
2477 min_checkpoint_interval_ms: Some(200),
2478
2479 checkpoint_rate_window_size: None,
2480
2481 checkpoint_summary_version_specific_data: Some(1),
2482
2483 max_soft_bundle_size: Some(5),
2484
2485 bridge_should_try_to_finalize_committee: None,
2486
2487 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2488
2489 max_committee_members_count: None,
2490
2491 consensus_gc_depth: None,
2492
2493 consensus_max_acknowledgments_per_block: None,
2494
2495 max_congestion_limit_overshoot_per_commit: None,
2496
2497 scorer_version: None,
2498
2499 auth_context_digest_cost_base: None,
2501 auth_context_tx_data_bytes_cost_base: None,
2502 auth_context_tx_data_bytes_cost_per_byte: None,
2503 auth_context_tx_commands_cost_base: None,
2504 auth_context_tx_commands_cost_per_byte: None,
2505 auth_context_tx_inputs_cost_base: None,
2506 auth_context_tx_inputs_cost_per_byte: None,
2507 auth_context_replace_cost_base: None,
2508 auth_context_replace_cost_per_byte: None,
2509 auth_context_authenticator_function_info_v1_cost_base: None,
2510 consensus_commits_per_schedule: None,
2511 min_validator_count: None,
2512 max_validator_count: None,
2513 min_validator_joining_stake: None,
2514 validator_low_stake_threshold: None,
2515 validator_very_low_stake_threshold: None,
2516 validator_low_stake_grace_period: None,
2517 };
2520
2521 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2522
2523 {
2525 cfg.feature_flags
2526 .disable_invariant_violation_check_in_swap_loc = true;
2527 cfg.feature_flags.no_extraneous_module_bytes = true;
2528 cfg.feature_flags.hardened_otw_check = true;
2529 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2530 }
2531
2532 {
2534 #[allow(deprecated)]
2535 {
2536 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2537 }
2538 }
2539
2540 #[expect(deprecated)]
2544 {
2545 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2546 }
2547 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2549
2550 cfg.feature_flags.per_object_congestion_control_mode =
2551 PerObjectCongestionControlMode::TotalTxCount;
2552
2553 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2555
2556 if chain != Chain::Mainnet && chain != Chain::Testnet {
2558 cfg.feature_flags.enable_poseidon = true;
2559 cfg.poseidon_bn254_cost_base = Some(260);
2560 cfg.poseidon_bn254_cost_per_block = Some(10);
2561
2562 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2563
2564 cfg.feature_flags.enable_vdf = true;
2565 cfg.vdf_verify_vdf_cost = Some(1500);
2568 cfg.vdf_hash_to_input_cost = Some(100);
2569
2570 cfg.feature_flags.passkey_auth = true;
2571 }
2572
2573 for cur in 2..=version.0 {
2574 match cur {
2575 1 => unreachable!(),
2576 2 => {}
2578 3 => {
2579 cfg.feature_flags.relocate_event_module = true;
2580 }
2581 4 => {
2582 cfg.max_type_to_layout_nodes = Some(512);
2583 }
2584 5 => {
2585 cfg.feature_flags.protocol_defined_base_fee = true;
2586 cfg.base_gas_price = Some(1000);
2587
2588 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2589 cfg.feature_flags.convert_type_argument_error = true;
2590 cfg.feature_flags.native_charging_v2 = true;
2591
2592 if chain != Chain::Mainnet && chain != Chain::Testnet {
2593 cfg.feature_flags.uncompressed_g1_group_elements = true;
2594 }
2595
2596 cfg.gas_model_version = Some(2);
2597
2598 cfg.poseidon_bn254_cost_per_block = Some(388);
2599
2600 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2601 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2602 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2603 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2604 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2605 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2606 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2607 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2608
2609 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2611 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2612 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2613 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2614
2615 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2616 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2617 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2618 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2619 Some(8213);
2620 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2621 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2622 Some(9484);
2623
2624 cfg.hash_keccak256_cost_base = Some(10);
2625 cfg.hash_blake2b256_cost_base = Some(10);
2626
2627 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2629 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2630 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2631 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2632
2633 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2634 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2635 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2636 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2637
2638 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2639 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2640 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2641 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2642
2643 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2644 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2645 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2646 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2647
2648 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2649 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2650 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2651 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2652
2653 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2654 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2655
2656 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2657 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2658 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2659 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2660
2661 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2662 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2663 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2664 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2665 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2666
2667 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2668
2669 cfg.validator_validate_metadata_cost_base = Some(20000);
2670
2671 cfg.max_committee_members_count = Some(50);
2672 }
2673 6 => {
2674 cfg.max_ptb_value_size = Some(1024 * 1024);
2675 }
2676 7 => {
2677 }
2680 8 => {
2681 cfg.feature_flags.variant_nodes = true;
2682
2683 if chain != Chain::Mainnet {
2684 cfg.feature_flags.consensus_round_prober = true;
2686 cfg.feature_flags
2688 .consensus_distributed_vote_scoring_strategy = true;
2689 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2690 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2692 cfg.feature_flags
2694 .consensus_round_prober_probe_accepted_rounds = true;
2695 cfg.feature_flags.consensus_zstd_compression = true;
2697 cfg.consensus_gc_depth = Some(60);
2701 }
2702
2703 if chain != Chain::Testnet && chain != Chain::Mainnet {
2706 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2707 }
2708 }
2709 9 => {
2710 if chain != Chain::Mainnet {
2711 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2713 }
2714
2715 cfg.feature_flags.consensus_zstd_compression = true;
2717
2718 if chain != Chain::Testnet && chain != Chain::Mainnet {
2720 cfg.feature_flags.accept_passkey_in_multisig = true;
2721 }
2722
2723 cfg.bridge_should_try_to_finalize_committee = None;
2725 }
2726 10 => {
2727 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2730
2731 cfg.max_committee_members_count = Some(80);
2733
2734 cfg.feature_flags.consensus_round_prober = true;
2736 cfg.feature_flags
2738 .consensus_round_prober_probe_accepted_rounds = true;
2739 cfg.feature_flags
2741 .consensus_distributed_vote_scoring_strategy = true;
2742 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2744
2745 cfg.consensus_gc_depth = Some(60);
2750
2751 cfg.feature_flags.minimize_child_object_mutations = true;
2753
2754 if chain != Chain::Mainnet {
2755 cfg.feature_flags.consensus_batched_block_sync = true;
2757 }
2758
2759 if chain != Chain::Testnet && chain != Chain::Mainnet {
2760 cfg.feature_flags
2763 .congestion_control_gas_price_feedback_mechanism = true;
2764 }
2765
2766 cfg.feature_flags.validate_identifier_inputs = true;
2767 cfg.feature_flags.dependency_linkage_error = true;
2768 cfg.feature_flags.additional_multisig_checks = true;
2769 }
2770 11 => {
2771 }
2774 12 => {
2775 cfg.feature_flags
2778 .congestion_control_gas_price_feedback_mechanism = true;
2779
2780 cfg.feature_flags.normalize_ptb_arguments = true;
2782 }
2783 13 => {
2784 cfg.feature_flags.select_committee_from_eligible_validators = true;
2787 cfg.feature_flags.track_non_committee_eligible_validators = true;
2790
2791 if chain != Chain::Testnet && chain != Chain::Mainnet {
2792 cfg.feature_flags
2795 .select_committee_supporting_next_epoch_version = true;
2796 }
2797 }
2798 14 => {
2799 cfg.feature_flags.consensus_batched_block_sync = true;
2801
2802 if chain != Chain::Mainnet {
2803 cfg.feature_flags
2806 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2807 cfg.feature_flags
2811 .select_committee_supporting_next_epoch_version = true;
2812 }
2813 if chain != Chain::Testnet && chain != Chain::Mainnet {
2814 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2816 }
2817 }
2818 15 => {
2819 if chain != Chain::Mainnet && chain != Chain::Testnet {
2820 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2824 }
2825 }
2826 16 => {
2827 cfg.feature_flags
2830 .select_committee_supporting_next_epoch_version = true;
2831 cfg.feature_flags
2833 .consensus_commit_transactions_only_for_traversed_headers = true;
2834 }
2835 17 => {
2836 cfg.max_committee_members_count = Some(100);
2838 }
2839 18 => {
2840 if chain != Chain::Mainnet {
2841 cfg.feature_flags.passkey_auth = true;
2843 }
2844 }
2845 19 => {
2846 if chain != Chain::Testnet && chain != Chain::Mainnet {
2847 cfg.feature_flags
2850 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2851 cfg.feature_flags
2854 .separate_gas_price_feedback_mechanism_for_randomness = true;
2855 cfg.feature_flags.metadata_in_module_bytes = true;
2858 cfg.feature_flags.publish_package_metadata = true;
2859 cfg.feature_flags.enable_move_authentication = true;
2861 cfg.max_auth_gas = Some(250_000_000);
2863 cfg.transfer_receive_object_cost_base = Some(100);
2866 cfg.feature_flags.adjust_rewards_by_score = true;
2868 }
2869
2870 if chain != Chain::Mainnet {
2871 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2873
2874 cfg.feature_flags.calculate_validator_scores = true;
2876 cfg.scorer_version = Some(1);
2877 }
2878
2879 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
2881
2882 cfg.feature_flags.passkey_auth = true;
2884 }
2885 20 => {
2886 if chain != Chain::Testnet && chain != Chain::Mainnet {
2887 cfg.feature_flags
2889 .pass_calculated_validator_scores_to_advance_epoch = true;
2890 }
2891 }
2892 21 => {
2893 if chain != Chain::Testnet && chain != Chain::Mainnet {
2894 cfg.feature_flags.consensus_fast_commit_sync = true;
2896 }
2897 if chain != Chain::Mainnet {
2898 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2903 cfg.feature_flags
2906 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2907 cfg.feature_flags
2910 .separate_gas_price_feedback_mechanism_for_randomness = true;
2911 }
2912
2913 cfg.auth_context_digest_cost_base = Some(30);
2914 cfg.auth_context_tx_commands_cost_base = Some(30);
2915 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
2916 cfg.auth_context_tx_inputs_cost_base = Some(30);
2917 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
2918 cfg.auth_context_replace_cost_base = Some(30);
2919 cfg.auth_context_replace_cost_per_byte = Some(2);
2920
2921 if chain != Chain::Testnet && chain != Chain::Mainnet {
2922 cfg.max_auth_gas = Some(250_000);
2924 }
2925 }
2926 22 => {
2927 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2932 cfg.feature_flags
2935 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2936 cfg.feature_flags
2939 .separate_gas_price_feedback_mechanism_for_randomness = true;
2940
2941 if chain != Chain::Mainnet {
2942 cfg.feature_flags.metadata_in_module_bytes = true;
2945 cfg.feature_flags.publish_package_metadata = true;
2946 cfg.feature_flags.enable_move_authentication = true;
2948 cfg.max_auth_gas = Some(250_000);
2950 cfg.transfer_receive_object_cost_base = Some(100);
2953 }
2954
2955 if chain != Chain::Mainnet {
2956 cfg.feature_flags.consensus_fast_commit_sync = true;
2958 }
2959 }
2960 23 => {
2961 cfg.feature_flags.move_native_tx_context = true;
2963 cfg.tx_context_fresh_id_cost_base = Some(52);
2964 cfg.tx_context_sender_cost_base = Some(30);
2965 cfg.tx_context_digest_cost_base = Some(30);
2966 cfg.tx_context_epoch_cost_base = Some(30);
2967 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
2968 cfg.tx_context_sponsor_cost_base = Some(30);
2969 cfg.tx_context_rgp_cost_base = Some(30);
2970 cfg.tx_context_gas_price_cost_base = Some(30);
2971 cfg.tx_context_gas_budget_cost_base = Some(30);
2972 cfg.tx_context_ids_created_cost_base = Some(30);
2973 cfg.tx_context_replace_cost_base = Some(30);
2974 }
2975 24 => {
2976 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2978
2979 if chain != Chain::Testnet && chain != Chain::Mainnet {
2980 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2982 }
2983
2984 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
2987 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
2988
2989 cfg.feature_flags.additional_borrow_checks = true;
2991 }
2992 #[allow(deprecated)]
2993 25 => {
2994 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
2997 cfg.check_zklogin_id_cost_base = None;
2998 cfg.check_zklogin_issuer_cost_base = None;
2999 cfg.max_jwk_votes_per_validator_per_epoch = None;
3000 cfg.max_age_of_jwk_in_epochs = None;
3001 }
3002 26 => {
3003 }
3006 27 => {
3007 if chain != Chain::Mainnet {
3008 cfg.feature_flags.consensus_block_restrictions = true;
3011 }
3012
3013 if chain != Chain::Testnet && chain != Chain::Mainnet {
3014 cfg.feature_flags
3016 .pre_consensus_sponsor_only_move_authentication = true;
3017 }
3018 }
3019 28 => {
3020 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
3025
3026 cfg.feature_flags.metadata_in_module_bytes = true;
3029 cfg.feature_flags.publish_package_metadata = true;
3030 cfg.feature_flags.enable_move_authentication = true;
3032 cfg.transfer_receive_object_cost_base = Some(100);
3035
3036 if chain != Chain::Unknown {
3037 cfg.max_auth_gas = Some(20_000);
3039 }
3040
3041 if chain != Chain::Mainnet {
3042 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3044 cfg.feature_flags
3046 .pre_consensus_sponsor_only_move_authentication = true;
3047 }
3048 }
3049 29 => {
3050 cfg.feature_flags.always_advance_dkg_to_resolution = true;
3056
3057 cfg.feature_flags
3060 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3061
3062 cfg.feature_flags.consensus_fast_commit_sync = true;
3064 cfg.feature_flags.consensus_block_restrictions = true;
3068 }
3069 30 => {
3070 }
3078 31 => {
3079 cfg.feature_flags.validator_metadata_verify_v2 = true;
3080
3081 if chain != Chain::Mainnet && chain != Chain::Testnet {
3082 cfg.checkpoint_rate_window_size = Some(20);
3085 cfg.feature_flags
3088 .package_metadata_with_dynamic_module_metadata = true;
3089 cfg.feature_flags.consensus_starfish_speed = true;
3092 }
3093
3094 cfg.feature_flags.report_move_authentication_error = true;
3095 }
3096 32 => {
3097 cfg.min_validator_count = Some(4);
3101 cfg.max_validator_count = Some(150);
3102 cfg.min_validator_joining_stake = Some(2_000_000_000_000_000);
3103 cfg.validator_low_stake_threshold = Some(1_500_000_000_000_000);
3104 cfg.validator_very_low_stake_threshold = Some(1_000_000_000_000_000);
3105 cfg.validator_low_stake_grace_period = Some(7);
3106 }
3107 _ => panic!("unsupported version {version:?}"),
3118 }
3119 }
3120 cfg
3121 }
3122
3123 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
3129 let (
3130 max_back_edges_per_function,
3131 max_back_edges_per_module,
3132 sanity_check_with_regex_reference_safety,
3133 ) = if let Some((
3134 max_back_edges_per_function,
3135 max_back_edges_per_module,
3136 sanity_check_with_regex_reference_safety,
3137 )) = signing_limits
3138 {
3139 (
3140 Some(max_back_edges_per_function),
3141 Some(max_back_edges_per_module),
3142 Some(sanity_check_with_regex_reference_safety),
3143 )
3144 } else {
3145 (None, None, None)
3146 };
3147
3148 let additional_borrow_checks = if signing_limits.is_some() {
3149 true
3152 } else {
3153 self.additional_borrow_checks()
3154 };
3155
3156 VerifierConfig {
3157 max_loop_depth: Some(self.max_loop_depth() as usize),
3158 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
3159 max_function_parameters: Some(self.max_function_parameters() as usize),
3160 max_basic_blocks: Some(self.max_basic_blocks() as usize),
3161 max_value_stack_size: self.max_value_stack_size() as usize,
3162 max_type_nodes: Some(self.max_type_nodes() as usize),
3163 max_push_size: Some(self.max_push_size() as usize),
3164 max_dependency_depth: Some(self.max_dependency_depth() as usize),
3165 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
3166 max_function_definitions: Some(self.max_function_definitions() as usize),
3167 max_data_definitions: Some(self.max_struct_definitions() as usize),
3168 max_constant_vector_len: Some(self.max_move_vector_len()),
3169 max_back_edges_per_function,
3170 max_back_edges_per_module,
3171 max_basic_blocks_in_script: None,
3172 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
3176 max_variants_in_enum: self.max_move_enum_variants_as_option(),
3177 additional_borrow_checks,
3178 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
3179 .map(|limit| limit as u128),
3180 }
3181 }
3182
3183 pub fn apply_overrides_for_testing(
3188 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
3189 ) -> OverrideGuard {
3190 CONFIG_OVERRIDE.with(|ovr| {
3191 let mut cur = ovr.borrow_mut();
3192 assert!(cur.is_none(), "config override already present");
3193 *cur = Some(Box::new(override_fn));
3194 OverrideGuard
3195 })
3196 }
3197}
3198
3199impl ProtocolConfig {
3204 pub fn set_per_object_congestion_control_mode_for_testing(
3205 &mut self,
3206 val: PerObjectCongestionControlMode,
3207 ) {
3208 self.feature_flags.per_object_congestion_control_mode = val;
3209 }
3210
3211 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
3212 self.feature_flags.consensus_choice = val;
3213 }
3214
3215 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
3216 self.feature_flags.consensus_network = val;
3217 }
3218
3219 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
3220 self.feature_flags.passkey_auth = val
3221 }
3222
3223 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
3224 self.feature_flags
3225 .disallow_new_modules_in_deps_only_packages = val;
3226 }
3227
3228 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
3229 self.feature_flags.consensus_round_prober = val;
3230 }
3231
3232 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
3233 self.feature_flags
3234 .consensus_distributed_vote_scoring_strategy = val;
3235 }
3236
3237 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
3238 self.consensus_gc_depth = Some(val);
3239 }
3240
3241 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
3242 self.feature_flags.consensus_linearize_subdag_v2 = val;
3243 }
3244
3245 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
3246 self.feature_flags
3247 .consensus_round_prober_probe_accepted_rounds = val;
3248 }
3249
3250 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
3251 self.feature_flags.accept_passkey_in_multisig = val;
3252 }
3253
3254 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
3255 self.feature_flags.consensus_smart_ancestor_selection = val;
3256 }
3257
3258 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
3259 self.feature_flags.consensus_batched_block_sync = val;
3260 }
3261
3262 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
3263 self.feature_flags
3264 .congestion_control_min_free_execution_slot = val;
3265 }
3266
3267 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
3268 self.feature_flags
3269 .congestion_control_gas_price_feedback_mechanism = val;
3270 }
3271
3272 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
3273 self.feature_flags.select_committee_from_eligible_validators = val;
3274 }
3275
3276 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
3277 self.feature_flags.track_non_committee_eligible_validators = val;
3278 }
3279
3280 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
3281 self.feature_flags
3282 .select_committee_supporting_next_epoch_version = val;
3283 }
3284
3285 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
3286 &mut self,
3287 val: bool,
3288 ) {
3289 self.feature_flags
3290 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3291 }
3292
3293 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3294 &mut self,
3295 val: bool,
3296 ) {
3297 self.feature_flags
3298 .consensus_commit_transactions_only_for_traversed_headers = val;
3299 }
3300
3301 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3302 &mut self,
3303 val: bool,
3304 ) {
3305 self.feature_flags
3306 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3307 }
3308
3309 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3310 &mut self,
3311 val: bool,
3312 ) {
3313 self.feature_flags
3314 .separate_gas_price_feedback_mechanism_for_randomness = val;
3315 }
3316
3317 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3318 self.feature_flags.metadata_in_module_bytes = val;
3319 }
3320
3321 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3322 self.feature_flags.publish_package_metadata = val;
3323 }
3324
3325 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3326 self.feature_flags.enable_move_authentication = val;
3327 }
3328
3329 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3330 self.feature_flags.enable_move_authentication_for_sponsor = val;
3331 }
3332
3333 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3334 self.feature_flags.consensus_fast_commit_sync = val;
3335 }
3336
3337 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3338 self.feature_flags.consensus_block_restrictions = val;
3339 }
3340
3341 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3342 self.feature_flags
3343 .pre_consensus_sponsor_only_move_authentication = val;
3344 }
3345
3346 pub fn set_consensus_starfish_speed_for_testing(&mut self, val: bool) {
3347 self.feature_flags.consensus_starfish_speed = val;
3348 }
3349
3350 pub fn set_always_advance_dkg_to_resolution_for_testing(&mut self, val: bool) {
3351 self.feature_flags.always_advance_dkg_to_resolution = val;
3352 }
3353
3354 pub fn set_enable_pcool_flow_for_testing(&mut self, val: bool) {
3355 self.feature_flags.enable_pcool_flow = val;
3356 }
3357
3358 pub fn set_commits_per_schedule_for_testing(&mut self, val: u32) {
3359 self.consensus_commits_per_schedule = Some(val);
3360 }
3361
3362 pub fn set_deny_rule_governance_for_testing(&mut self, val: bool) {
3363 self.feature_flags.deny_rule_governance = val;
3364 }
3365
3366 pub fn set_package_metadata_with_dynamic_module_metadata_for_testing(&mut self, val: bool) {
3367 self.feature_flags
3368 .package_metadata_with_dynamic_module_metadata = val;
3369 }
3370
3371 pub fn set_report_move_authentication_error_for_testing(&mut self, val: bool) {
3372 self.feature_flags.report_move_authentication_error = val;
3373 }
3374}
3375
3376type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
3377
3378thread_local! {
3379 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
3380}
3381
3382#[must_use]
3383pub struct OverrideGuard;
3384
3385impl Drop for OverrideGuard {
3386 fn drop(&mut self) {
3387 info!("restoring override fn");
3388 CONFIG_OVERRIDE.with(|ovr| {
3389 *ovr.borrow_mut() = None;
3390 });
3391 }
3392}
3393
3394#[derive(PartialEq, Eq)]
3398pub enum LimitThresholdCrossed {
3399 None,
3400 Soft(u128, u128),
3401 Hard(u128, u128),
3402}
3403
3404pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
3407 x: T,
3408 soft_limit: U,
3409 hard_limit: V,
3410) -> LimitThresholdCrossed {
3411 let x: V = x.into();
3412 let soft_limit: V = soft_limit.into();
3413
3414 debug_assert!(soft_limit <= hard_limit);
3415
3416 if x >= hard_limit {
3419 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
3420 } else if x < soft_limit {
3421 LimitThresholdCrossed::None
3422 } else {
3423 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
3424 }
3425}
3426
3427#[macro_export]
3428macro_rules! check_limit {
3429 ($x:expr, $hard:expr) => {
3430 check_limit!($x, $hard, $hard)
3431 };
3432 ($x:expr, $soft:expr, $hard:expr) => {
3433 check_limit_in_range($x as u64, $soft, $hard)
3434 };
3435}
3436
3437#[macro_export]
3441macro_rules! check_limit_by_meter {
3442 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
3443 let (h, metered_str) = if $is_metered {
3445 ($metered_limit, "metered")
3446 } else {
3447 ($unmetered_hard_limit, "unmetered")
3449 };
3450 use iota_protocol_config::check_limit_in_range;
3451 let result = check_limit_in_range($x as u64, $metered_limit, h);
3452 match result {
3453 LimitThresholdCrossed::None => {}
3454 LimitThresholdCrossed::Soft(_, _) => {
3455 $metric.with_label_values(&[metered_str, "soft"]).inc();
3456 }
3457 LimitThresholdCrossed::Hard(_, _) => {
3458 $metric.with_label_values(&[metered_str, "hard"]).inc();
3459 }
3460 };
3461 result
3462 }};
3463}
3464
3465#[cfg(all(test, not(msim)))]
3466mod test {
3467 use insta::assert_yaml_snapshot;
3468
3469 use super::*;
3470
3471 #[test]
3472 fn snapshot_tests() {
3473 println!("\n============================================================================");
3474 println!("! !");
3475 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
3476 println!("! !");
3477 println!("============================================================================\n");
3478 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
3479 let chain_str = match chain_id {
3484 Chain::Unknown => "".to_string(),
3485 _ => format!("{chain_id:?}_"),
3486 };
3487 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
3488 let cur = ProtocolVersion::new(i);
3489 assert_yaml_snapshot!(
3490 format!("{}version_{}", chain_str, cur.as_u64()),
3491 ProtocolConfig::get_for_version(cur, *chain_id)
3492 );
3493 }
3494 }
3495 }
3496
3497 #[test]
3498 fn test_getters() {
3499 let prot: ProtocolConfig =
3500 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3501 assert_eq!(
3502 prot.max_arguments(),
3503 prot.max_arguments_as_option().unwrap()
3504 );
3505 }
3506
3507 #[test]
3508 fn test_setters() {
3509 let mut prot: ProtocolConfig =
3510 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3511 prot.set_max_arguments_for_testing(123);
3512 assert_eq!(prot.max_arguments(), 123);
3513
3514 prot.set_max_arguments_from_str_for_testing("321".to_string());
3515 assert_eq!(prot.max_arguments(), 321);
3516
3517 prot.disable_max_arguments_for_testing();
3518 assert_eq!(prot.max_arguments_as_option(), None);
3519
3520 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
3521 assert_eq!(prot.max_arguments(), 456);
3522 }
3523
3524 #[test]
3525 #[should_panic(expected = "unsupported version")]
3526 fn max_version_test() {
3527 let _ = ProtocolConfig::get_for_version_impl(
3530 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
3531 Chain::Unknown,
3532 );
3533 }
3534
3535 #[test]
3536 fn lookup_by_string_test() {
3537 let prot: ProtocolConfig =
3538 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3539 assert!(prot.lookup_attr("some random string".to_string()).is_none());
3541
3542 assert!(
3543 prot.lookup_attr("max_arguments".to_string())
3544 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
3545 );
3546
3547 assert!(
3549 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3550 .is_none()
3551 );
3552 assert!(
3553 prot.attr_map()
3554 .get("poseidon_bn254_cost_base")
3555 .unwrap()
3556 .is_none()
3557 );
3558
3559 let prot: ProtocolConfig =
3561 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3562
3563 assert!(
3564 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3565 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3566 );
3567 assert!(
3568 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
3569 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3570 );
3571
3572 let prot: ProtocolConfig =
3574 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3575 assert!(
3577 prot.feature_flags
3578 .lookup_attr("some random string".to_owned())
3579 .is_none()
3580 );
3581 assert!(
3582 !prot
3583 .feature_flags
3584 .attr_map()
3585 .contains_key("some random string")
3586 );
3587
3588 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
3590 assert!(
3591 prot.feature_flags
3592 .attr_map()
3593 .get("enable_poseidon")
3594 .unwrap()
3595 == &false
3596 );
3597 let prot: ProtocolConfig =
3598 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3599 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
3601 assert!(
3602 prot.feature_flags
3603 .attr_map()
3604 .get("enable_poseidon")
3605 .unwrap()
3606 == &true
3607 );
3608 }
3609
3610 #[test]
3611 fn limit_range_fn_test() {
3612 let low = 100u32;
3613 let high = 10000u64;
3614
3615 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
3616 assert!(matches!(
3617 check_limit!(255u16, low, high),
3618 LimitThresholdCrossed::Soft(255u128, 100)
3619 ));
3620 assert!(matches!(
3627 check_limit!(2550000u64, low, high),
3628 LimitThresholdCrossed::Hard(2550000, 10000)
3629 ));
3630
3631 assert!(matches!(
3632 check_limit!(2550000u64, high, high),
3633 LimitThresholdCrossed::Hard(2550000, 10000)
3634 ));
3635
3636 assert!(matches!(
3637 check_limit!(1u8, high),
3638 LimitThresholdCrossed::None
3639 ));
3640
3641 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
3642
3643 assert!(matches!(
3644 check_limit!(2550000u64, high),
3645 LimitThresholdCrossed::Hard(2550000, 10000)
3646 ));
3647 }
3648}