1use std::{
6 cell::RefCell,
7 cmp::min,
8 sync::atomic::{AtomicBool, Ordering},
9};
10
11use clap::*;
12use iota_protocol_config_macros::{
13 ProtocolConfigAccessors, ProtocolConfigFeatureFlagsGetters, ProtocolConfigOverride,
14};
15use move_vm_config::verifier::VerifierConfig;
16use serde::{Deserialize, Serialize};
17use serde_with::skip_serializing_none;
18use tracing::{info, warn};
19
20const MIN_PROTOCOL_VERSION: u64 = 1;
22pub const MAX_PROTOCOL_VERSION: u64 = 31;
23
24pub const PROTOCOL_VERSION_IIP8: u64 = 20;
26#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
180pub struct ProtocolVersion(u64);
181
182impl ProtocolVersion {
183 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
189
190 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
191
192 #[cfg(not(msim))]
193 const MAX_ALLOWED: Self = Self::MAX;
194
195 #[cfg(msim)]
198 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
199
200 pub fn new(v: u64) -> Self {
201 Self(v)
202 }
203
204 pub const fn as_u64(&self) -> u64 {
205 self.0
206 }
207
208 pub fn max() -> Self {
211 Self::MAX
212 }
213}
214
215impl From<u64> for ProtocolVersion {
216 fn from(v: u64) -> Self {
217 Self::new(v)
218 }
219}
220
221impl std::ops::Sub<u64> for ProtocolVersion {
222 type Output = Self;
223 fn sub(self, rhs: u64) -> Self::Output {
224 Self::new(self.0 - rhs)
225 }
226}
227
228impl std::ops::Add<u64> for ProtocolVersion {
229 type Output = Self;
230 fn add(self, rhs: u64) -> Self::Output {
231 Self::new(self.0 + rhs)
232 }
233}
234
235#[derive(
236 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
237)]
238pub enum Chain {
239 Mainnet,
240 Testnet,
241 #[default]
242 Unknown,
243}
244
245impl Chain {
246 pub fn as_str(self) -> &'static str {
247 match self {
248 Chain::Mainnet => "mainnet",
249 Chain::Testnet => "testnet",
250 Chain::Unknown => "unknown",
251 }
252 }
253}
254
255pub struct Error(pub String);
256
257#[derive(
261 Default,
262 Clone,
263 Serialize,
264 Deserialize,
265 Debug,
266 ProtocolConfigFeatureFlagsGetters,
267 ProtocolConfigOverride,
268)]
269struct FeatureFlags {
270 #[serde(skip_serializing_if = "is_true")]
276 disable_invariant_violation_check_in_swap_loc: bool,
277
278 #[serde(skip_serializing_if = "is_true")]
281 no_extraneous_module_bytes: bool,
282
283 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
285 consensus_transaction_ordering: ConsensusTransactionOrdering,
286
287 #[serde(skip_serializing_if = "is_true")]
290 hardened_otw_check: bool,
291
292 #[serde(skip_serializing_if = "is_false")]
294 enable_poseidon: bool,
295
296 #[serde(skip_serializing_if = "is_false")]
298 enable_group_ops_native_function_msm: bool,
299
300 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
302 per_object_congestion_control_mode: PerObjectCongestionControlMode,
303
304 #[serde(
306 default = "ConsensusChoice::mysticeti_deprecated",
307 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
308 )]
309 consensus_choice: ConsensusChoice,
310
311 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
313 consensus_network: ConsensusNetwork,
314
315 #[deprecated]
317 #[serde(skip_serializing_if = "Option::is_none")]
318 zklogin_max_epoch_upper_bound_delta: Option<u64>,
319
320 #[serde(skip_serializing_if = "is_false")]
322 enable_vdf: bool,
323
324 #[serde(skip_serializing_if = "is_false")]
326 passkey_auth: bool,
327
328 #[serde(skip_serializing_if = "is_true")]
331 rethrow_serialization_type_layout_errors: bool,
332
333 #[serde(skip_serializing_if = "is_false")]
335 relocate_event_module: bool,
336
337 #[serde(skip_serializing_if = "is_false")]
339 protocol_defined_base_fee: bool,
340
341 #[serde(skip_serializing_if = "is_false")]
343 uncompressed_g1_group_elements: bool,
344
345 #[serde(skip_serializing_if = "is_false")]
347 disallow_new_modules_in_deps_only_packages: bool,
348
349 #[serde(skip_serializing_if = "is_false")]
351 native_charging_v2: bool,
352
353 #[serde(skip_serializing_if = "is_false")]
355 convert_type_argument_error: bool,
356
357 #[serde(skip_serializing_if = "is_false")]
359 consensus_round_prober: bool,
360
361 #[serde(skip_serializing_if = "is_false")]
363 consensus_distributed_vote_scoring_strategy: bool,
364
365 #[serde(skip_serializing_if = "is_false")]
369 consensus_linearize_subdag_v2: bool,
370
371 #[serde(skip_serializing_if = "is_false")]
373 variant_nodes: bool,
374
375 #[serde(skip_serializing_if = "is_false")]
377 consensus_smart_ancestor_selection: bool,
378
379 #[serde(skip_serializing_if = "is_false")]
381 consensus_round_prober_probe_accepted_rounds: bool,
382
383 #[serde(skip_serializing_if = "is_false")]
385 consensus_zstd_compression: bool,
386
387 #[serde(skip_serializing_if = "is_false")]
390 congestion_control_min_free_execution_slot: bool,
391
392 #[serde(skip_serializing_if = "is_false")]
394 accept_passkey_in_multisig: bool,
395
396 #[serde(skip_serializing_if = "is_false")]
398 consensus_batched_block_sync: bool,
399
400 #[serde(skip_serializing_if = "is_false")]
403 congestion_control_gas_price_feedback_mechanism: bool,
404
405 #[serde(skip_serializing_if = "is_false")]
407 validate_identifier_inputs: bool,
408
409 #[serde(skip_serializing_if = "is_false")]
412 minimize_child_object_mutations: bool,
413
414 #[serde(skip_serializing_if = "is_false")]
416 dependency_linkage_error: bool,
417
418 #[serde(skip_serializing_if = "is_false")]
420 additional_multisig_checks: bool,
421
422 #[serde(skip_serializing_if = "is_false")]
425 normalize_ptb_arguments: bool,
426
427 #[serde(skip_serializing_if = "is_false")]
431 select_committee_from_eligible_validators: bool,
432
433 #[serde(skip_serializing_if = "is_false")]
440 track_non_committee_eligible_validators: bool,
441
442 #[serde(skip_serializing_if = "is_false")]
448 select_committee_supporting_next_epoch_version: bool,
449
450 #[serde(skip_serializing_if = "is_false")]
454 consensus_median_timestamp_with_checkpoint_enforcement: bool,
455
456 #[serde(skip_serializing_if = "is_false")]
458 consensus_commit_transactions_only_for_traversed_headers: bool,
459
460 #[serde(skip_serializing_if = "is_false")]
462 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
463
464 #[serde(skip_serializing_if = "is_false")]
467 separate_gas_price_feedback_mechanism_for_randomness: bool,
468
469 #[serde(skip_serializing_if = "is_false")]
472 metadata_in_module_bytes: bool,
473
474 #[serde(skip_serializing_if = "is_false")]
476 publish_package_metadata: bool,
477
478 #[serde(skip_serializing_if = "is_false")]
480 enable_move_authentication: bool,
481
482 #[serde(skip_serializing_if = "is_false")]
484 enable_move_authentication_for_sponsor: bool,
485
486 #[serde(skip_serializing_if = "is_false")]
488 pass_validator_scores_to_advance_epoch: bool,
489
490 #[serde(skip_serializing_if = "is_false")]
492 calculate_validator_scores: bool,
493
494 #[serde(skip_serializing_if = "is_false")]
496 adjust_rewards_by_score: bool,
497
498 #[serde(skip_serializing_if = "is_false")]
501 pass_calculated_validator_scores_to_advance_epoch: bool,
502
503 #[serde(skip_serializing_if = "is_false")]
508 consensus_fast_commit_sync: bool,
509
510 #[serde(skip_serializing_if = "is_false")]
513 consensus_block_restrictions: bool,
514
515 #[serde(skip_serializing_if = "is_false")]
517 move_native_tx_context: bool,
518
519 #[serde(skip_serializing_if = "is_false")]
521 additional_borrow_checks: bool,
522
523 #[serde(skip_serializing_if = "is_false")]
525 pre_consensus_sponsor_only_move_authentication: bool,
526
527 #[serde(skip_serializing_if = "is_false")]
529 consensus_starfish_speed: bool,
530
531 #[serde(skip_serializing_if = "is_false")]
538 always_advance_dkg_to_resolution: bool,
539
540 #[serde(skip_serializing_if = "is_false")]
545 enable_pcool_flow: bool,
546
547 #[serde(skip_serializing_if = "is_false")]
549 validator_metadata_verify_v2: bool,
550}
551
552fn is_true(b: &bool) -> bool {
553 *b
554}
555
556fn is_false(b: &bool) -> bool {
557 !b
558}
559
560#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
562pub enum ConsensusTransactionOrdering {
563 #[default]
566 None,
567 ByGasPrice,
569}
570
571impl ConsensusTransactionOrdering {
572 pub fn is_none(&self) -> bool {
573 matches!(self, ConsensusTransactionOrdering::None)
574 }
575}
576
577#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
579pub enum PerObjectCongestionControlMode {
580 #[default]
581 None, TotalGasBudget, TotalTxCount, }
585
586impl PerObjectCongestionControlMode {
587 pub fn is_none(&self) -> bool {
588 matches!(self, PerObjectCongestionControlMode::None)
589 }
590}
591
592#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
594pub enum ConsensusChoice {
595 #[deprecated(note = "Mysticeti was replaced by Starfish")]
598 MysticetiDeprecated,
599 #[default]
600 Starfish,
601}
602
603#[expect(deprecated)]
604impl ConsensusChoice {
605 fn mysticeti_deprecated() -> Self {
612 ConsensusChoice::MysticetiDeprecated
613 }
614
615 pub fn is_mysticeti_deprecated(&self) -> bool {
616 matches!(self, ConsensusChoice::MysticetiDeprecated)
617 }
618 pub fn is_starfish(&self) -> bool {
619 matches!(self, ConsensusChoice::Starfish)
620 }
621}
622
623#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
625pub enum ConsensusNetwork {
626 #[default]
627 Tonic,
628}
629
630impl ConsensusNetwork {
631 pub fn is_tonic(&self) -> bool {
632 matches!(self, ConsensusNetwork::Tonic)
633 }
634}
635
636#[skip_serializing_none]
670#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
671pub struct ProtocolConfig {
672 pub version: ProtocolVersion,
673
674 feature_flags: FeatureFlags,
675
676 max_tx_size_bytes: Option<u64>,
681
682 max_input_objects: Option<u64>,
685
686 max_size_written_objects: Option<u64>,
691 max_size_written_objects_system_tx: Option<u64>,
695
696 max_serialized_tx_effects_size_bytes: Option<u64>,
698
699 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
701
702 max_gas_payment_objects: Option<u32>,
704
705 max_modules_in_publish: Option<u32>,
707
708 max_package_dependencies: Option<u32>,
710
711 max_arguments: Option<u32>,
714
715 max_type_arguments: Option<u32>,
717
718 max_type_argument_depth: Option<u32>,
720
721 max_pure_argument_size: Option<u32>,
723
724 max_programmable_tx_commands: Option<u32>,
726
727 move_binary_format_version: Option<u32>,
733 min_move_binary_format_version: Option<u32>,
734
735 binary_module_handles: Option<u16>,
737 binary_struct_handles: Option<u16>,
738 binary_function_handles: Option<u16>,
739 binary_function_instantiations: Option<u16>,
740 binary_signatures: Option<u16>,
741 binary_constant_pool: Option<u16>,
742 binary_identifiers: Option<u16>,
743 binary_address_identifiers: Option<u16>,
744 binary_struct_defs: Option<u16>,
745 binary_struct_def_instantiations: Option<u16>,
746 binary_function_defs: Option<u16>,
747 binary_field_handles: Option<u16>,
748 binary_field_instantiations: Option<u16>,
749 binary_friend_decls: Option<u16>,
750 binary_enum_defs: Option<u16>,
751 binary_enum_def_instantiations: Option<u16>,
752 binary_variant_handles: Option<u16>,
753 binary_variant_instantiation_handles: Option<u16>,
754
755 max_move_object_size: Option<u64>,
758
759 max_move_package_size: Option<u64>,
764
765 max_publish_or_upgrade_per_ptb: Option<u64>,
768
769 max_tx_gas: Option<u64>,
771
772 max_auth_gas: Option<u64>,
774
775 max_gas_price: Option<u64>,
778
779 max_gas_computation_bucket: Option<u64>,
782
783 gas_rounding_step: Option<u64>,
785
786 max_loop_depth: Option<u64>,
788
789 max_generic_instantiation_length: Option<u64>,
792
793 max_function_parameters: Option<u64>,
796
797 max_basic_blocks: Option<u64>,
800
801 max_value_stack_size: Option<u64>,
803
804 max_type_nodes: Option<u64>,
808
809 max_push_size: Option<u64>,
812
813 max_struct_definitions: Option<u64>,
816
817 max_function_definitions: Option<u64>,
820
821 max_fields_in_struct: Option<u64>,
824
825 max_dependency_depth: Option<u64>,
828
829 max_num_event_emit: Option<u64>,
832
833 max_num_new_move_object_ids: Option<u64>,
836
837 max_num_new_move_object_ids_system_tx: Option<u64>,
840
841 max_num_deleted_move_object_ids: Option<u64>,
844
845 max_num_deleted_move_object_ids_system_tx: Option<u64>,
848
849 max_num_transferred_move_object_ids: Option<u64>,
852
853 max_num_transferred_move_object_ids_system_tx: Option<u64>,
856
857 max_event_emit_size: Option<u64>,
859
860 max_event_emit_size_total: Option<u64>,
862
863 max_move_vector_len: Option<u64>,
866
867 max_move_identifier_len: Option<u64>,
870
871 max_move_value_depth: Option<u64>,
873
874 max_move_enum_variants: Option<u64>,
877
878 max_back_edges_per_function: Option<u64>,
881
882 max_back_edges_per_module: Option<u64>,
885
886 max_verifier_meter_ticks_per_function: Option<u64>,
889
890 max_meter_ticks_per_module: Option<u64>,
893
894 max_meter_ticks_per_package: Option<u64>,
897
898 object_runtime_max_num_cached_objects: Option<u64>,
905
906 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
909
910 object_runtime_max_num_store_entries: Option<u64>,
913
914 object_runtime_max_num_store_entries_system_tx: Option<u64>,
917
918 base_tx_cost_fixed: Option<u64>,
923
924 package_publish_cost_fixed: Option<u64>,
928
929 base_tx_cost_per_byte: Option<u64>,
933
934 package_publish_cost_per_byte: Option<u64>,
936
937 obj_access_cost_read_per_byte: Option<u64>,
939
940 obj_access_cost_mutate_per_byte: Option<u64>,
942
943 obj_access_cost_delete_per_byte: Option<u64>,
945
946 obj_access_cost_verify_per_byte: Option<u64>,
956
957 max_type_to_layout_nodes: Option<u64>,
959
960 max_ptb_value_size: Option<u64>,
962
963 gas_model_version: Option<u64>,
968
969 obj_data_cost_refundable: Option<u64>,
975
976 obj_metadata_cost_non_refundable: Option<u64>,
980
981 storage_rebate_rate: Option<u64>,
987
988 reward_slashing_rate: Option<u64>,
991
992 storage_gas_price: Option<u64>,
994
995 base_gas_price: Option<u64>,
997
998 validator_target_reward: Option<u64>,
1000
1001 max_transactions_per_checkpoint: Option<u64>,
1008
1009 max_checkpoint_size_bytes: Option<u64>,
1013
1014 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
1020
1021 address_from_bytes_cost_base: Option<u64>,
1026 address_to_u256_cost_base: Option<u64>,
1028 address_from_u256_cost_base: Option<u64>,
1030
1031 config_read_setting_impl_cost_base: Option<u64>,
1036 config_read_setting_impl_cost_per_byte: Option<u64>,
1037
1038 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
1042 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
1043 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
1044 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
1045 dynamic_field_add_child_object_cost_base: Option<u64>,
1048 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
1049 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
1050 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
1051 dynamic_field_borrow_child_object_cost_base: Option<u64>,
1054 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1055 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1056 dynamic_field_remove_child_object_cost_base: Option<u64>,
1059 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1060 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1061 dynamic_field_has_child_object_cost_base: Option<u64>,
1064 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1067 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1068 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1069
1070 event_emit_cost_base: Option<u64>,
1073 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1074 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1075 event_emit_output_cost_per_byte: Option<u64>,
1076
1077 object_borrow_uid_cost_base: Option<u64>,
1080 object_delete_impl_cost_base: Option<u64>,
1082 object_record_new_uid_cost_base: Option<u64>,
1084
1085 transfer_transfer_internal_cost_base: Option<u64>,
1088 transfer_freeze_object_cost_base: Option<u64>,
1090 transfer_share_object_cost_base: Option<u64>,
1092 transfer_receive_object_cost_base: Option<u64>,
1095
1096 tx_context_derive_id_cost_base: Option<u64>,
1099 tx_context_fresh_id_cost_base: Option<u64>,
1100 tx_context_sender_cost_base: Option<u64>,
1101 tx_context_digest_cost_base: Option<u64>,
1102 tx_context_epoch_cost_base: Option<u64>,
1103 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1104 tx_context_sponsor_cost_base: Option<u64>,
1105 tx_context_rgp_cost_base: Option<u64>,
1106 tx_context_gas_price_cost_base: Option<u64>,
1107 tx_context_gas_budget_cost_base: Option<u64>,
1108 tx_context_ids_created_cost_base: Option<u64>,
1109 tx_context_replace_cost_base: Option<u64>,
1110
1111 types_is_one_time_witness_cost_base: Option<u64>,
1114 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1115 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1116
1117 validator_validate_metadata_cost_base: Option<u64>,
1120 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1121
1122 crypto_invalid_arguments_cost: Option<u64>,
1124 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1126 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1127 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1128
1129 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1131 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1132 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1133
1134 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1136 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1137 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1138 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1139 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1140 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1141
1142 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1144
1145 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1147 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1148 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1149 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1150 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1151 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1152
1153 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1155 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1156 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1157 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1158 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1159 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1160
1161 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1163 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1164 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1165 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1166 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1167 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1168
1169 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1171 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1172 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1173
1174 ed25519_ed25519_verify_cost_base: Option<u64>,
1176 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1177 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1178
1179 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1181 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1182
1183 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1185 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1186 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1187 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1188 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1189
1190 hash_blake2b256_cost_base: Option<u64>,
1192 hash_blake2b256_data_cost_per_byte: Option<u64>,
1193 hash_blake2b256_data_cost_per_block: Option<u64>,
1194
1195 hash_keccak256_cost_base: Option<u64>,
1197 hash_keccak256_data_cost_per_byte: Option<u64>,
1198 hash_keccak256_data_cost_per_block: Option<u64>,
1199
1200 poseidon_bn254_cost_base: Option<u64>,
1202 poseidon_bn254_cost_per_block: Option<u64>,
1203
1204 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1206 group_ops_bls12381_decode_g1_cost: Option<u64>,
1207 group_ops_bls12381_decode_g2_cost: Option<u64>,
1208 group_ops_bls12381_decode_gt_cost: Option<u64>,
1209 group_ops_bls12381_scalar_add_cost: Option<u64>,
1210 group_ops_bls12381_g1_add_cost: Option<u64>,
1211 group_ops_bls12381_g2_add_cost: Option<u64>,
1212 group_ops_bls12381_gt_add_cost: Option<u64>,
1213 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1214 group_ops_bls12381_g1_sub_cost: Option<u64>,
1215 group_ops_bls12381_g2_sub_cost: Option<u64>,
1216 group_ops_bls12381_gt_sub_cost: Option<u64>,
1217 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1218 group_ops_bls12381_g1_mul_cost: Option<u64>,
1219 group_ops_bls12381_g2_mul_cost: Option<u64>,
1220 group_ops_bls12381_gt_mul_cost: Option<u64>,
1221 group_ops_bls12381_scalar_div_cost: Option<u64>,
1222 group_ops_bls12381_g1_div_cost: Option<u64>,
1223 group_ops_bls12381_g2_div_cost: Option<u64>,
1224 group_ops_bls12381_gt_div_cost: Option<u64>,
1225 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1226 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1227 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1228 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1229 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1230 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1231 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1232 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1233 group_ops_bls12381_msm_max_len: Option<u32>,
1234 group_ops_bls12381_pairing_cost: Option<u64>,
1235 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1236 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1237 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1238 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1239 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1240
1241 hmac_hmac_sha3_256_cost_base: Option<u64>,
1243 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1244 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1245
1246 #[deprecated]
1248 check_zklogin_id_cost_base: Option<u64>,
1249 #[deprecated]
1251 check_zklogin_issuer_cost_base: Option<u64>,
1252
1253 vdf_verify_vdf_cost: Option<u64>,
1254 vdf_hash_to_input_cost: Option<u64>,
1255
1256 bcs_per_byte_serialized_cost: Option<u64>,
1258 bcs_legacy_min_output_size_cost: Option<u64>,
1259 bcs_failure_cost: Option<u64>,
1260
1261 hash_sha2_256_base_cost: Option<u64>,
1262 hash_sha2_256_per_byte_cost: Option<u64>,
1263 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1264 hash_sha3_256_base_cost: Option<u64>,
1265 hash_sha3_256_per_byte_cost: Option<u64>,
1266 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1267 type_name_get_base_cost: Option<u64>,
1268 type_name_get_per_byte_cost: Option<u64>,
1269
1270 string_check_utf8_base_cost: Option<u64>,
1271 string_check_utf8_per_byte_cost: Option<u64>,
1272 string_is_char_boundary_base_cost: Option<u64>,
1273 string_sub_string_base_cost: Option<u64>,
1274 string_sub_string_per_byte_cost: Option<u64>,
1275 string_index_of_base_cost: Option<u64>,
1276 string_index_of_per_byte_pattern_cost: Option<u64>,
1277 string_index_of_per_byte_searched_cost: Option<u64>,
1278
1279 vector_empty_base_cost: Option<u64>,
1280 vector_length_base_cost: Option<u64>,
1281 vector_push_back_base_cost: Option<u64>,
1282 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1283 vector_borrow_base_cost: Option<u64>,
1284 vector_pop_back_base_cost: Option<u64>,
1285 vector_destroy_empty_base_cost: Option<u64>,
1286 vector_swap_base_cost: Option<u64>,
1287 debug_print_base_cost: Option<u64>,
1288 debug_print_stack_trace_base_cost: Option<u64>,
1289
1290 execution_version: Option<u64>,
1292
1293 consensus_bad_nodes_stake_threshold: Option<u64>,
1297
1298 #[deprecated]
1299 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1300 #[deprecated]
1304 max_age_of_jwk_in_epochs: Option<u64>,
1305
1306 random_beacon_reduction_allowed_delta: Option<u16>,
1310
1311 random_beacon_reduction_lower_bound: Option<u32>,
1314
1315 random_beacon_dkg_timeout_round: Option<u32>,
1318
1319 random_beacon_min_round_interval_ms: Option<u64>,
1321
1322 random_beacon_dkg_version: Option<u64>,
1326
1327 consensus_max_transaction_size_bytes: Option<u64>,
1332 consensus_max_transactions_in_block_bytes: Option<u64>,
1334 consensus_max_num_transactions_in_block: Option<u64>,
1336
1337 max_deferral_rounds_for_congestion_control: Option<u64>,
1341
1342 min_checkpoint_interval_ms: Option<u64>,
1344
1345 checkpoint_summary_version_specific_data: Option<u64>,
1347
1348 max_soft_bundle_size: Option<u64>,
1351
1352 bridge_should_try_to_finalize_committee: Option<bool>,
1357
1358 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1364
1365 max_committee_members_count: Option<u64>,
1369
1370 consensus_gc_depth: Option<u32>,
1373
1374 consensus_max_acknowledgments_per_block: Option<u32>,
1380
1381 max_congestion_limit_overshoot_per_commit: Option<u64>,
1386
1387 scorer_version: Option<u16>,
1396
1397 auth_context_digest_cost_base: Option<u64>,
1400 auth_context_tx_data_bytes_cost_base: Option<u64>,
1402 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1403 auth_context_tx_commands_cost_base: Option<u64>,
1405 auth_context_tx_commands_cost_per_byte: Option<u64>,
1406 auth_context_tx_inputs_cost_base: Option<u64>,
1408 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1409 auth_context_replace_cost_base: Option<u64>,
1412 auth_context_replace_cost_per_byte: Option<u64>,
1413 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1417
1418 consensus_commits_per_schedule: Option<u32>,
1421}
1422
1423impl ProtocolConfig {
1425 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1438 self.feature_flags
1439 .disable_invariant_violation_check_in_swap_loc
1440 }
1441
1442 pub fn no_extraneous_module_bytes(&self) -> bool {
1443 self.feature_flags.no_extraneous_module_bytes
1444 }
1445
1446 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1447 self.feature_flags.consensus_transaction_ordering
1448 }
1449
1450 pub fn dkg_version(&self) -> u64 {
1451 self.random_beacon_dkg_version.unwrap_or(1)
1453 }
1454
1455 pub fn hardened_otw_check(&self) -> bool {
1456 self.feature_flags.hardened_otw_check
1457 }
1458
1459 pub fn enable_poseidon(&self) -> bool {
1460 self.feature_flags.enable_poseidon
1461 }
1462
1463 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1464 self.feature_flags.enable_group_ops_native_function_msm
1465 }
1466
1467 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1468 self.feature_flags.per_object_congestion_control_mode
1469 }
1470
1471 pub fn consensus_choice(&self) -> ConsensusChoice {
1472 self.feature_flags.consensus_choice
1473 }
1474
1475 pub fn consensus_network(&self) -> ConsensusNetwork {
1476 self.feature_flags.consensus_network
1477 }
1478
1479 pub fn enable_vdf(&self) -> bool {
1480 self.feature_flags.enable_vdf
1481 }
1482
1483 pub fn passkey_auth(&self) -> bool {
1484 self.feature_flags.passkey_auth
1485 }
1486
1487 pub fn max_transaction_size_bytes(&self) -> u64 {
1488 self.consensus_max_transaction_size_bytes
1490 .unwrap_or(256 * 1024)
1491 }
1492
1493 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1494 if cfg!(msim) {
1495 256 * 1024
1496 } else {
1497 self.consensus_max_transactions_in_block_bytes
1498 .unwrap_or(512 * 1024)
1499 }
1500 }
1501
1502 pub fn max_num_transactions_in_block(&self) -> u64 {
1503 if cfg!(msim) {
1504 8
1505 } else {
1506 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1507 }
1508 }
1509
1510 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1511 self.feature_flags.rethrow_serialization_type_layout_errors
1512 }
1513
1514 pub fn relocate_event_module(&self) -> bool {
1515 self.feature_flags.relocate_event_module
1516 }
1517
1518 pub fn protocol_defined_base_fee(&self) -> bool {
1519 self.feature_flags.protocol_defined_base_fee
1520 }
1521
1522 pub fn uncompressed_g1_group_elements(&self) -> bool {
1523 self.feature_flags.uncompressed_g1_group_elements
1524 }
1525
1526 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1527 self.feature_flags
1528 .disallow_new_modules_in_deps_only_packages
1529 }
1530
1531 pub fn native_charging_v2(&self) -> bool {
1532 self.feature_flags.native_charging_v2
1533 }
1534
1535 pub fn consensus_round_prober(&self) -> bool {
1536 self.feature_flags.consensus_round_prober
1537 }
1538
1539 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1540 self.feature_flags
1541 .consensus_distributed_vote_scoring_strategy
1542 }
1543
1544 pub fn gc_depth(&self) -> u32 {
1545 if cfg!(msim) {
1546 min(5, self.consensus_gc_depth.unwrap_or(0))
1548 } else {
1549 self.consensus_gc_depth.unwrap_or(0)
1550 }
1551 }
1552
1553 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1554 let res = self.feature_flags.consensus_linearize_subdag_v2;
1555 assert!(
1556 !res || self.gc_depth() > 0,
1557 "The consensus linearize sub dag V2 requires GC to be enabled"
1558 );
1559 res
1560 }
1561
1562 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1563 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1564 }
1565
1566 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1567 2 * committee_size
1568 }
1569
1570 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1571 committee_size
1572 }
1573
1574 pub fn variant_nodes(&self) -> bool {
1575 self.feature_flags.variant_nodes
1576 }
1577
1578 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1579 self.feature_flags.consensus_smart_ancestor_selection
1580 }
1581
1582 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1583 self.feature_flags
1584 .consensus_round_prober_probe_accepted_rounds
1585 }
1586
1587 pub fn consensus_zstd_compression(&self) -> bool {
1588 self.feature_flags.consensus_zstd_compression
1589 }
1590
1591 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1592 self.feature_flags
1593 .congestion_control_min_free_execution_slot
1594 }
1595
1596 pub fn accept_passkey_in_multisig(&self) -> bool {
1597 self.feature_flags.accept_passkey_in_multisig
1598 }
1599
1600 pub fn consensus_batched_block_sync(&self) -> bool {
1601 self.feature_flags.consensus_batched_block_sync
1602 }
1603
1604 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1607 self.feature_flags
1608 .congestion_control_gas_price_feedback_mechanism
1609 }
1610
1611 pub fn validate_identifier_inputs(&self) -> bool {
1612 self.feature_flags.validate_identifier_inputs
1613 }
1614
1615 pub fn minimize_child_object_mutations(&self) -> bool {
1616 self.feature_flags.minimize_child_object_mutations
1617 }
1618
1619 pub fn dependency_linkage_error(&self) -> bool {
1620 self.feature_flags.dependency_linkage_error
1621 }
1622
1623 pub fn additional_multisig_checks(&self) -> bool {
1624 self.feature_flags.additional_multisig_checks
1625 }
1626
1627 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1628 0
1631 }
1632
1633 pub fn normalize_ptb_arguments(&self) -> bool {
1634 self.feature_flags.normalize_ptb_arguments
1635 }
1636
1637 pub fn select_committee_from_eligible_validators(&self) -> bool {
1638 let res = self.feature_flags.select_committee_from_eligible_validators;
1639 assert!(
1640 !res || (self.protocol_defined_base_fee()
1641 && self.max_committee_members_count_as_option().is_some()),
1642 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1643 );
1644 res
1645 }
1646
1647 pub fn track_non_committee_eligible_validators(&self) -> bool {
1648 self.feature_flags.track_non_committee_eligible_validators
1649 }
1650
1651 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1652 let res = self
1653 .feature_flags
1654 .select_committee_supporting_next_epoch_version;
1655 assert!(
1656 !res || (self.track_non_committee_eligible_validators()
1657 && self.select_committee_from_eligible_validators()),
1658 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1659 );
1660 res
1661 }
1662
1663 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1664 let res = self
1665 .feature_flags
1666 .consensus_median_timestamp_with_checkpoint_enforcement;
1667 assert!(
1668 !res || self.gc_depth() > 0,
1669 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1670 );
1671 res
1672 }
1673
1674 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1675 self.feature_flags
1676 .consensus_commit_transactions_only_for_traversed_headers
1677 }
1678
1679 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1682 self.feature_flags
1683 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1684 }
1685
1686 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1689 self.feature_flags
1690 .separate_gas_price_feedback_mechanism_for_randomness
1691 }
1692
1693 pub fn metadata_in_module_bytes(&self) -> bool {
1694 self.feature_flags.metadata_in_module_bytes
1695 }
1696
1697 pub fn publish_package_metadata(&self) -> bool {
1698 self.feature_flags.publish_package_metadata
1699 }
1700
1701 pub fn enable_move_authentication(&self) -> bool {
1702 self.feature_flags.enable_move_authentication
1703 }
1704
1705 pub fn additional_borrow_checks(&self) -> bool {
1706 self.feature_flags.additional_borrow_checks
1707 }
1708
1709 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1710 let enable_move_authentication_for_sponsor =
1711 self.feature_flags.enable_move_authentication_for_sponsor;
1712 assert!(
1713 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1714 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1715 );
1716 enable_move_authentication_for_sponsor
1717 }
1718
1719 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1720 self.feature_flags.pass_validator_scores_to_advance_epoch
1721 }
1722
1723 pub fn calculate_validator_scores(&self) -> bool {
1724 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1725 assert!(
1726 !calculate_validator_scores || self.scorer_version.is_some(),
1727 "calculate_validator_scores requires scorer_version to be set"
1728 );
1729 calculate_validator_scores
1730 }
1731
1732 pub fn adjust_rewards_by_score(&self) -> bool {
1733 let adjust = self.feature_flags.adjust_rewards_by_score;
1734 assert!(
1735 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1736 "adjust_rewards_by_score requires scorer_version to be set"
1737 );
1738 adjust
1739 }
1740
1741 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1742 let pass = self
1743 .feature_flags
1744 .pass_calculated_validator_scores_to_advance_epoch;
1745 assert!(
1746 !pass
1747 || (self.pass_validator_scores_to_advance_epoch()
1748 && self.calculate_validator_scores()),
1749 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
1750 );
1751 pass
1752 }
1753 pub fn consensus_fast_commit_sync(&self) -> bool {
1754 let res = self.feature_flags.consensus_fast_commit_sync;
1755 assert!(
1756 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
1757 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
1758 );
1759 res
1760 }
1761
1762 pub fn consensus_block_restrictions(&self) -> bool {
1763 self.feature_flags.consensus_block_restrictions
1764 }
1765
1766 pub fn move_native_tx_context(&self) -> bool {
1767 self.feature_flags.move_native_tx_context
1768 }
1769
1770 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
1771 let pre_consensus_sponsor_only_move_authentication = self
1772 .feature_flags
1773 .pre_consensus_sponsor_only_move_authentication;
1774 if pre_consensus_sponsor_only_move_authentication {
1775 assert!(
1776 self.enable_move_authentication(),
1777 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
1778 );
1779 assert!(
1780 self.enable_move_authentication_for_sponsor(),
1781 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
1782 );
1783 }
1784 pre_consensus_sponsor_only_move_authentication
1785 }
1786
1787 pub fn consensus_starfish_speed(&self) -> bool {
1788 let res = self.feature_flags.consensus_starfish_speed;
1789 assert!(
1790 !res || self.consensus_fast_commit_sync(),
1791 "consensus_starfish_speed requires consensus_fast_commit_sync to be enabled"
1792 );
1793 res
1794 }
1795
1796 pub fn always_advance_dkg_to_resolution(&self) -> bool {
1797 self.feature_flags.always_advance_dkg_to_resolution
1798 }
1799
1800 pub fn enable_pcool_flow(&self) -> bool {
1801 self.feature_flags.enable_pcool_flow
1802 }
1803
1804 pub fn validator_metadata_verify_v2(&self) -> bool {
1805 self.feature_flags.validator_metadata_verify_v2
1806 }
1807
1808 pub fn commits_per_schedule(&self) -> u32 {
1809 if cfg!(msim) {
1810 min(10, self.consensus_commits_per_schedule.unwrap_or(300))
1812 } else {
1813 self.consensus_commits_per_schedule.unwrap_or(300)
1814 }
1815 }
1816}
1817
1818#[cfg(not(msim))]
1819static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1820
1821#[cfg(msim)]
1823thread_local! {
1824 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1825}
1826
1827impl ProtocolConfig {
1829 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1832 assert!(
1834 version >= ProtocolVersion::MIN,
1835 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1836 version,
1837 ProtocolVersion::MIN.0,
1838 );
1839 assert!(
1840 version <= ProtocolVersion::MAX_ALLOWED,
1841 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1842 version,
1843 ProtocolVersion::MAX_ALLOWED.0,
1844 );
1845
1846 let mut ret = Self::get_for_version_impl(version, chain);
1847 ret.version = version;
1848
1849 ret = CONFIG_OVERRIDE.with(|ovr| {
1850 if let Some(override_fn) = &*ovr.borrow() {
1851 warn!(
1852 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1853 );
1854 override_fn(version, ret)
1855 } else {
1856 ret
1857 }
1858 });
1859
1860 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1861 warn!(
1862 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1863 );
1864
1865 let overrides: ProtocolConfigOptional =
1867 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1868 .expect("failed to parse ProtocolConfig override env variables");
1869 overrides.apply_to(&mut ret);
1870
1871 let feature_flag_overrides: FeatureFlagsOptional =
1873 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_FEATURE_FLAGS_OVERRIDE")
1874 .expect("failed to parse ProtocolConfig feature flags override env variables");
1875
1876 feature_flag_overrides.apply_to(&mut ret.feature_flags);
1877 }
1878
1879 ret
1880 }
1881
1882 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1885 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1886 let mut ret = Self::get_for_version_impl(version, chain);
1887 ret.version = version;
1888 Some(ret)
1889 } else {
1890 None
1891 }
1892 }
1893
1894 #[cfg(not(msim))]
1895 pub fn poison_get_for_min_version() {
1896 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1897 }
1898
1899 #[cfg(not(msim))]
1900 fn load_poison_get_for_min_version() -> bool {
1901 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1902 }
1903
1904 #[cfg(msim)]
1905 pub fn poison_get_for_min_version() {
1906 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1907 }
1908
1909 #[cfg(msim)]
1910 fn load_poison_get_for_min_version() -> bool {
1911 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1912 }
1913
1914 pub fn convert_type_argument_error(&self) -> bool {
1915 self.feature_flags.convert_type_argument_error
1916 }
1917
1918 pub fn get_for_min_version() -> Self {
1922 if Self::load_poison_get_for_min_version() {
1923 panic!("get_for_min_version called on validator");
1924 }
1925 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1926 }
1927
1928 #[expect(non_snake_case)]
1939 pub fn get_for_max_version_UNSAFE() -> Self {
1940 if Self::load_poison_get_for_min_version() {
1941 panic!("get_for_max_version_UNSAFE called on validator");
1942 }
1943 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1944 }
1945
1946 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1947 #[cfg(msim)]
1948 {
1949 if version > ProtocolVersion::MAX {
1951 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1952 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1953 return config;
1954 }
1955 }
1956
1957 let mut cfg = Self {
1961 version,
1962
1963 feature_flags: Default::default(),
1964
1965 max_tx_size_bytes: Some(128 * 1024),
1966 max_input_objects: Some(2048),
1969 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1970 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1971 max_gas_payment_objects: Some(256),
1972 max_modules_in_publish: Some(64),
1973 max_package_dependencies: Some(32),
1974 max_arguments: Some(512),
1975 max_type_arguments: Some(16),
1976 max_type_argument_depth: Some(16),
1977 max_pure_argument_size: Some(16 * 1024),
1978 max_programmable_tx_commands: Some(1024),
1979 move_binary_format_version: Some(7),
1980 min_move_binary_format_version: Some(6),
1981 binary_module_handles: Some(100),
1982 binary_struct_handles: Some(300),
1983 binary_function_handles: Some(1500),
1984 binary_function_instantiations: Some(750),
1985 binary_signatures: Some(1000),
1986 binary_constant_pool: Some(4000),
1987 binary_identifiers: Some(10000),
1988 binary_address_identifiers: Some(100),
1989 binary_struct_defs: Some(200),
1990 binary_struct_def_instantiations: Some(100),
1991 binary_function_defs: Some(1000),
1992 binary_field_handles: Some(500),
1993 binary_field_instantiations: Some(250),
1994 binary_friend_decls: Some(100),
1995 binary_enum_defs: None,
1996 binary_enum_def_instantiations: None,
1997 binary_variant_handles: None,
1998 binary_variant_instantiation_handles: None,
1999 max_move_object_size: Some(250 * 1024),
2000 max_move_package_size: Some(100 * 1024),
2001 max_publish_or_upgrade_per_ptb: Some(5),
2002 max_auth_gas: None,
2004 max_tx_gas: Some(50_000_000_000),
2006 max_gas_price: Some(100_000),
2007 max_gas_computation_bucket: Some(5_000_000),
2008 max_loop_depth: Some(5),
2009 max_generic_instantiation_length: Some(32),
2010 max_function_parameters: Some(128),
2011 max_basic_blocks: Some(1024),
2012 max_value_stack_size: Some(1024),
2013 max_type_nodes: Some(256),
2014 max_push_size: Some(10000),
2015 max_struct_definitions: Some(200),
2016 max_function_definitions: Some(1000),
2017 max_fields_in_struct: Some(32),
2018 max_dependency_depth: Some(100),
2019 max_num_event_emit: Some(1024),
2020 max_num_new_move_object_ids: Some(2048),
2021 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
2022 max_num_deleted_move_object_ids: Some(2048),
2023 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
2024 max_num_transferred_move_object_ids: Some(2048),
2025 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
2026 max_event_emit_size: Some(250 * 1024),
2027 max_move_vector_len: Some(256 * 1024),
2028 max_type_to_layout_nodes: None,
2029 max_ptb_value_size: None,
2030
2031 max_back_edges_per_function: Some(10_000),
2032 max_back_edges_per_module: Some(10_000),
2033
2034 max_verifier_meter_ticks_per_function: Some(16_000_000),
2035
2036 max_meter_ticks_per_module: Some(16_000_000),
2037 max_meter_ticks_per_package: Some(16_000_000),
2038
2039 object_runtime_max_num_cached_objects: Some(1000),
2040 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2041 object_runtime_max_num_store_entries: Some(1000),
2042 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2043 base_tx_cost_fixed: Some(1_000),
2045 package_publish_cost_fixed: Some(1_000),
2046 base_tx_cost_per_byte: Some(0),
2047 package_publish_cost_per_byte: Some(80),
2048 obj_access_cost_read_per_byte: Some(15),
2049 obj_access_cost_mutate_per_byte: Some(40),
2050 obj_access_cost_delete_per_byte: Some(40),
2051 obj_access_cost_verify_per_byte: Some(200),
2052 obj_data_cost_refundable: Some(100),
2053 obj_metadata_cost_non_refundable: Some(50),
2054 gas_model_version: Some(1),
2055 storage_rebate_rate: Some(10000),
2056 reward_slashing_rate: Some(10000),
2058 storage_gas_price: Some(76),
2059 base_gas_price: None,
2060 validator_target_reward: Some(767_000 * 1_000_000_000),
2063 max_transactions_per_checkpoint: Some(10_000),
2064 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2065
2066 buffer_stake_for_protocol_upgrade_bps: Some(5000),
2068
2069 address_from_bytes_cost_base: Some(52),
2073 address_to_u256_cost_base: Some(52),
2075 address_from_u256_cost_base: Some(52),
2077
2078 config_read_setting_impl_cost_base: Some(100),
2081 config_read_setting_impl_cost_per_byte: Some(40),
2082
2083 dynamic_field_hash_type_and_key_cost_base: Some(100),
2087 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
2088 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
2089 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
2090 dynamic_field_add_child_object_cost_base: Some(100),
2093 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2094 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2095 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2096 dynamic_field_borrow_child_object_cost_base: Some(100),
2099 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2100 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2101 dynamic_field_remove_child_object_cost_base: Some(100),
2104 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2105 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2106 dynamic_field_has_child_object_cost_base: Some(100),
2109 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2112 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2113 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2114
2115 event_emit_cost_base: Some(52),
2118 event_emit_value_size_derivation_cost_per_byte: Some(2),
2119 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2120 event_emit_output_cost_per_byte: Some(10),
2121
2122 object_borrow_uid_cost_base: Some(52),
2125 object_delete_impl_cost_base: Some(52),
2127 object_record_new_uid_cost_base: Some(52),
2129
2130 transfer_transfer_internal_cost_base: Some(52),
2134 transfer_freeze_object_cost_base: Some(52),
2136 transfer_share_object_cost_base: Some(52),
2138 transfer_receive_object_cost_base: Some(52),
2139
2140 tx_context_derive_id_cost_base: Some(52),
2144 tx_context_fresh_id_cost_base: None,
2145 tx_context_sender_cost_base: None,
2146 tx_context_digest_cost_base: None,
2147 tx_context_epoch_cost_base: None,
2148 tx_context_epoch_timestamp_ms_cost_base: None,
2149 tx_context_sponsor_cost_base: None,
2150 tx_context_rgp_cost_base: None,
2151 tx_context_gas_price_cost_base: None,
2152 tx_context_gas_budget_cost_base: None,
2153 tx_context_ids_created_cost_base: None,
2154 tx_context_replace_cost_base: None,
2155
2156 types_is_one_time_witness_cost_base: Some(52),
2159 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2160 types_is_one_time_witness_type_cost_per_byte: Some(2),
2161
2162 validator_validate_metadata_cost_base: Some(52),
2166 validator_validate_metadata_data_cost_per_byte: Some(2),
2167
2168 crypto_invalid_arguments_cost: Some(100),
2170 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2172 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2173 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2174
2175 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2177 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2178 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2179
2180 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2182 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2183 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2184 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2185 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2186 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2187
2188 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2190
2191 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2193 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2194 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2195 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2196 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2197 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2198
2199 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2201 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2202 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2203 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2204 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2205 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2206
2207 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2209 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2210 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2211 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2212 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2213 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2214
2215 ecvrf_ecvrf_verify_cost_base: Some(52),
2217 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2218 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2219
2220 ed25519_ed25519_verify_cost_base: Some(52),
2222 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2223 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2224
2225 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2227 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2228
2229 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2231 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2232 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2233 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2234 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2235
2236 hash_blake2b256_cost_base: Some(52),
2238 hash_blake2b256_data_cost_per_byte: Some(2),
2239 hash_blake2b256_data_cost_per_block: Some(2),
2240 hash_keccak256_cost_base: Some(52),
2242 hash_keccak256_data_cost_per_byte: Some(2),
2243 hash_keccak256_data_cost_per_block: Some(2),
2244
2245 poseidon_bn254_cost_base: None,
2246 poseidon_bn254_cost_per_block: None,
2247
2248 hmac_hmac_sha3_256_cost_base: Some(52),
2250 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2251 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2252
2253 group_ops_bls12381_decode_scalar_cost: Some(52),
2255 group_ops_bls12381_decode_g1_cost: Some(52),
2256 group_ops_bls12381_decode_g2_cost: Some(52),
2257 group_ops_bls12381_decode_gt_cost: Some(52),
2258 group_ops_bls12381_scalar_add_cost: Some(52),
2259 group_ops_bls12381_g1_add_cost: Some(52),
2260 group_ops_bls12381_g2_add_cost: Some(52),
2261 group_ops_bls12381_gt_add_cost: Some(52),
2262 group_ops_bls12381_scalar_sub_cost: Some(52),
2263 group_ops_bls12381_g1_sub_cost: Some(52),
2264 group_ops_bls12381_g2_sub_cost: Some(52),
2265 group_ops_bls12381_gt_sub_cost: Some(52),
2266 group_ops_bls12381_scalar_mul_cost: Some(52),
2267 group_ops_bls12381_g1_mul_cost: Some(52),
2268 group_ops_bls12381_g2_mul_cost: Some(52),
2269 group_ops_bls12381_gt_mul_cost: Some(52),
2270 group_ops_bls12381_scalar_div_cost: Some(52),
2271 group_ops_bls12381_g1_div_cost: Some(52),
2272 group_ops_bls12381_g2_div_cost: Some(52),
2273 group_ops_bls12381_gt_div_cost: Some(52),
2274 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2275 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2276 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2277 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2278 group_ops_bls12381_g1_msm_base_cost: Some(52),
2279 group_ops_bls12381_g2_msm_base_cost: Some(52),
2280 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2281 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2282 group_ops_bls12381_msm_max_len: Some(32),
2283 group_ops_bls12381_pairing_cost: Some(52),
2284 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2285 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2286 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2287 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2288 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2289
2290 #[allow(deprecated)]
2292 check_zklogin_id_cost_base: Some(200),
2293 #[allow(deprecated)]
2294 check_zklogin_issuer_cost_base: Some(200),
2296
2297 vdf_verify_vdf_cost: None,
2298 vdf_hash_to_input_cost: None,
2299
2300 bcs_per_byte_serialized_cost: Some(2),
2301 bcs_legacy_min_output_size_cost: Some(1),
2302 bcs_failure_cost: Some(52),
2303 hash_sha2_256_base_cost: Some(52),
2304 hash_sha2_256_per_byte_cost: Some(2),
2305 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2306 hash_sha3_256_base_cost: Some(52),
2307 hash_sha3_256_per_byte_cost: Some(2),
2308 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2309 type_name_get_base_cost: Some(52),
2310 type_name_get_per_byte_cost: Some(2),
2311 string_check_utf8_base_cost: Some(52),
2312 string_check_utf8_per_byte_cost: Some(2),
2313 string_is_char_boundary_base_cost: Some(52),
2314 string_sub_string_base_cost: Some(52),
2315 string_sub_string_per_byte_cost: Some(2),
2316 string_index_of_base_cost: Some(52),
2317 string_index_of_per_byte_pattern_cost: Some(2),
2318 string_index_of_per_byte_searched_cost: Some(2),
2319 vector_empty_base_cost: Some(52),
2320 vector_length_base_cost: Some(52),
2321 vector_push_back_base_cost: Some(52),
2322 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2323 vector_borrow_base_cost: Some(52),
2324 vector_pop_back_base_cost: Some(52),
2325 vector_destroy_empty_base_cost: Some(52),
2326 vector_swap_base_cost: Some(52),
2327 debug_print_base_cost: Some(52),
2328 debug_print_stack_trace_base_cost: Some(52),
2329
2330 max_size_written_objects: Some(5 * 1000 * 1000),
2331 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2334
2335 max_move_identifier_len: Some(128),
2337 max_move_value_depth: Some(128),
2338 max_move_enum_variants: None,
2339
2340 gas_rounding_step: Some(1_000),
2341
2342 execution_version: Some(1),
2343
2344 max_event_emit_size_total: Some(
2347 256 * 250 * 1024, ),
2349
2350 consensus_bad_nodes_stake_threshold: Some(20),
2357
2358 #[allow(deprecated)]
2360 max_jwk_votes_per_validator_per_epoch: Some(240),
2361
2362 #[allow(deprecated)]
2363 max_age_of_jwk_in_epochs: Some(1),
2364
2365 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2369
2370 random_beacon_reduction_allowed_delta: Some(800),
2371
2372 random_beacon_reduction_lower_bound: Some(1000),
2373 random_beacon_dkg_timeout_round: Some(3000),
2374 random_beacon_min_round_interval_ms: Some(500),
2375
2376 random_beacon_dkg_version: Some(1),
2377
2378 consensus_max_num_transactions_in_block: Some(512),
2382
2383 max_deferral_rounds_for_congestion_control: Some(10),
2384
2385 min_checkpoint_interval_ms: Some(200),
2386
2387 checkpoint_summary_version_specific_data: Some(1),
2388
2389 max_soft_bundle_size: Some(5),
2390
2391 bridge_should_try_to_finalize_committee: None,
2392
2393 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2394
2395 max_committee_members_count: None,
2396
2397 consensus_gc_depth: None,
2398
2399 consensus_max_acknowledgments_per_block: None,
2400
2401 max_congestion_limit_overshoot_per_commit: None,
2402
2403 scorer_version: None,
2404
2405 auth_context_digest_cost_base: None,
2407 auth_context_tx_data_bytes_cost_base: None,
2408 auth_context_tx_data_bytes_cost_per_byte: None,
2409 auth_context_tx_commands_cost_base: None,
2410 auth_context_tx_commands_cost_per_byte: None,
2411 auth_context_tx_inputs_cost_base: None,
2412 auth_context_tx_inputs_cost_per_byte: None,
2413 auth_context_replace_cost_base: None,
2414 auth_context_replace_cost_per_byte: None,
2415 auth_context_authenticator_function_info_v1_cost_base: None,
2416 consensus_commits_per_schedule: None,
2417 };
2420
2421 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2422
2423 {
2425 cfg.feature_flags
2426 .disable_invariant_violation_check_in_swap_loc = true;
2427 cfg.feature_flags.no_extraneous_module_bytes = true;
2428 cfg.feature_flags.hardened_otw_check = true;
2429 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2430 }
2431
2432 {
2434 #[allow(deprecated)]
2435 {
2436 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2437 }
2438 }
2439
2440 #[expect(deprecated)]
2444 {
2445 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2446 }
2447 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2449
2450 cfg.feature_flags.per_object_congestion_control_mode =
2451 PerObjectCongestionControlMode::TotalTxCount;
2452
2453 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2455
2456 if chain != Chain::Mainnet && chain != Chain::Testnet {
2458 cfg.feature_flags.enable_poseidon = true;
2459 cfg.poseidon_bn254_cost_base = Some(260);
2460 cfg.poseidon_bn254_cost_per_block = Some(10);
2461
2462 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2463
2464 cfg.feature_flags.enable_vdf = true;
2465 cfg.vdf_verify_vdf_cost = Some(1500);
2468 cfg.vdf_hash_to_input_cost = Some(100);
2469
2470 cfg.feature_flags.passkey_auth = true;
2471 }
2472
2473 for cur in 2..=version.0 {
2474 match cur {
2475 1 => unreachable!(),
2476 2 => {}
2478 3 => {
2479 cfg.feature_flags.relocate_event_module = true;
2480 }
2481 4 => {
2482 cfg.max_type_to_layout_nodes = Some(512);
2483 }
2484 5 => {
2485 cfg.feature_flags.protocol_defined_base_fee = true;
2486 cfg.base_gas_price = Some(1000);
2487
2488 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2489 cfg.feature_flags.convert_type_argument_error = true;
2490 cfg.feature_flags.native_charging_v2 = true;
2491
2492 if chain != Chain::Mainnet && chain != Chain::Testnet {
2493 cfg.feature_flags.uncompressed_g1_group_elements = true;
2494 }
2495
2496 cfg.gas_model_version = Some(2);
2497
2498 cfg.poseidon_bn254_cost_per_block = Some(388);
2499
2500 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2501 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2502 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2503 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2504 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2505 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2506 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2507 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2508
2509 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2511 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2512 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2513 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2514
2515 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2516 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2517 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2518 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2519 Some(8213);
2520 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2521 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2522 Some(9484);
2523
2524 cfg.hash_keccak256_cost_base = Some(10);
2525 cfg.hash_blake2b256_cost_base = Some(10);
2526
2527 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2529 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2530 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2531 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2532
2533 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2534 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2535 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2536 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2537
2538 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2539 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2540 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2541 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2542
2543 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2544 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2545 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2546 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2547
2548 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2549 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2550 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2551 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2552
2553 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2554 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2555
2556 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2557 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2558 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2559 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2560
2561 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2562 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2563 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2564 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2565 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2566
2567 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2568
2569 cfg.validator_validate_metadata_cost_base = Some(20000);
2570
2571 cfg.max_committee_members_count = Some(50);
2572 }
2573 6 => {
2574 cfg.max_ptb_value_size = Some(1024 * 1024);
2575 }
2576 7 => {
2577 }
2580 8 => {
2581 cfg.feature_flags.variant_nodes = true;
2582
2583 if chain != Chain::Mainnet {
2584 cfg.feature_flags.consensus_round_prober = true;
2586 cfg.feature_flags
2588 .consensus_distributed_vote_scoring_strategy = true;
2589 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2590 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2592 cfg.feature_flags
2594 .consensus_round_prober_probe_accepted_rounds = true;
2595 cfg.feature_flags.consensus_zstd_compression = true;
2597 cfg.consensus_gc_depth = Some(60);
2601 }
2602
2603 if chain != Chain::Testnet && chain != Chain::Mainnet {
2606 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2607 }
2608 }
2609 9 => {
2610 if chain != Chain::Mainnet {
2611 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2613 }
2614
2615 cfg.feature_flags.consensus_zstd_compression = true;
2617
2618 if chain != Chain::Testnet && chain != Chain::Mainnet {
2620 cfg.feature_flags.accept_passkey_in_multisig = true;
2621 }
2622
2623 cfg.bridge_should_try_to_finalize_committee = None;
2625 }
2626 10 => {
2627 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2630
2631 cfg.max_committee_members_count = Some(80);
2633
2634 cfg.feature_flags.consensus_round_prober = true;
2636 cfg.feature_flags
2638 .consensus_round_prober_probe_accepted_rounds = true;
2639 cfg.feature_flags
2641 .consensus_distributed_vote_scoring_strategy = true;
2642 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2644
2645 cfg.consensus_gc_depth = Some(60);
2650
2651 cfg.feature_flags.minimize_child_object_mutations = true;
2653
2654 if chain != Chain::Mainnet {
2655 cfg.feature_flags.consensus_batched_block_sync = true;
2657 }
2658
2659 if chain != Chain::Testnet && chain != Chain::Mainnet {
2660 cfg.feature_flags
2663 .congestion_control_gas_price_feedback_mechanism = true;
2664 }
2665
2666 cfg.feature_flags.validate_identifier_inputs = true;
2667 cfg.feature_flags.dependency_linkage_error = true;
2668 cfg.feature_flags.additional_multisig_checks = true;
2669 }
2670 11 => {
2671 }
2674 12 => {
2675 cfg.feature_flags
2678 .congestion_control_gas_price_feedback_mechanism = true;
2679
2680 cfg.feature_flags.normalize_ptb_arguments = true;
2682 }
2683 13 => {
2684 cfg.feature_flags.select_committee_from_eligible_validators = true;
2687 cfg.feature_flags.track_non_committee_eligible_validators = true;
2690
2691 if chain != Chain::Testnet && chain != Chain::Mainnet {
2692 cfg.feature_flags
2695 .select_committee_supporting_next_epoch_version = true;
2696 }
2697 }
2698 14 => {
2699 cfg.feature_flags.consensus_batched_block_sync = true;
2701
2702 if chain != Chain::Mainnet {
2703 cfg.feature_flags
2706 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2707 cfg.feature_flags
2711 .select_committee_supporting_next_epoch_version = true;
2712 }
2713 if chain != Chain::Testnet && chain != Chain::Mainnet {
2714 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2716 }
2717 }
2718 15 => {
2719 if chain != Chain::Mainnet && chain != Chain::Testnet {
2720 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2724 }
2725 }
2726 16 => {
2727 cfg.feature_flags
2730 .select_committee_supporting_next_epoch_version = true;
2731 cfg.feature_flags
2733 .consensus_commit_transactions_only_for_traversed_headers = true;
2734 }
2735 17 => {
2736 cfg.max_committee_members_count = Some(100);
2738 }
2739 18 => {
2740 if chain != Chain::Mainnet {
2741 cfg.feature_flags.passkey_auth = true;
2743 }
2744 }
2745 19 => {
2746 if chain != Chain::Testnet && chain != Chain::Mainnet {
2747 cfg.feature_flags
2750 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2751 cfg.feature_flags
2754 .separate_gas_price_feedback_mechanism_for_randomness = true;
2755 cfg.feature_flags.metadata_in_module_bytes = true;
2758 cfg.feature_flags.publish_package_metadata = true;
2759 cfg.feature_flags.enable_move_authentication = true;
2761 cfg.max_auth_gas = Some(250_000_000);
2763 cfg.transfer_receive_object_cost_base = Some(100);
2766 cfg.feature_flags.adjust_rewards_by_score = true;
2768 }
2769
2770 if chain != Chain::Mainnet {
2771 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2773
2774 cfg.feature_flags.calculate_validator_scores = true;
2776 cfg.scorer_version = Some(1);
2777 }
2778
2779 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
2781
2782 cfg.feature_flags.passkey_auth = true;
2784 }
2785 20 => {
2786 if chain != Chain::Testnet && chain != Chain::Mainnet {
2787 cfg.feature_flags
2789 .pass_calculated_validator_scores_to_advance_epoch = true;
2790 }
2791 }
2792 21 => {
2793 if chain != Chain::Testnet && chain != Chain::Mainnet {
2794 cfg.feature_flags.consensus_fast_commit_sync = true;
2796 }
2797 if chain != Chain::Mainnet {
2798 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2803 cfg.feature_flags
2806 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2807 cfg.feature_flags
2810 .separate_gas_price_feedback_mechanism_for_randomness = true;
2811 }
2812
2813 cfg.auth_context_digest_cost_base = Some(30);
2814 cfg.auth_context_tx_commands_cost_base = Some(30);
2815 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
2816 cfg.auth_context_tx_inputs_cost_base = Some(30);
2817 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
2818 cfg.auth_context_replace_cost_base = Some(30);
2819 cfg.auth_context_replace_cost_per_byte = Some(2);
2820
2821 if chain != Chain::Testnet && chain != Chain::Mainnet {
2822 cfg.max_auth_gas = Some(250_000);
2824 }
2825 }
2826 22 => {
2827 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2832 cfg.feature_flags
2835 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2836 cfg.feature_flags
2839 .separate_gas_price_feedback_mechanism_for_randomness = true;
2840
2841 if chain != Chain::Mainnet {
2842 cfg.feature_flags.metadata_in_module_bytes = true;
2845 cfg.feature_flags.publish_package_metadata = true;
2846 cfg.feature_flags.enable_move_authentication = true;
2848 cfg.max_auth_gas = Some(250_000);
2850 cfg.transfer_receive_object_cost_base = Some(100);
2853 }
2854
2855 if chain != Chain::Mainnet {
2856 cfg.feature_flags.consensus_fast_commit_sync = true;
2858 }
2859 }
2860 23 => {
2861 cfg.feature_flags.move_native_tx_context = true;
2863 cfg.tx_context_fresh_id_cost_base = Some(52);
2864 cfg.tx_context_sender_cost_base = Some(30);
2865 cfg.tx_context_digest_cost_base = Some(30);
2866 cfg.tx_context_epoch_cost_base = Some(30);
2867 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
2868 cfg.tx_context_sponsor_cost_base = Some(30);
2869 cfg.tx_context_rgp_cost_base = Some(30);
2870 cfg.tx_context_gas_price_cost_base = Some(30);
2871 cfg.tx_context_gas_budget_cost_base = Some(30);
2872 cfg.tx_context_ids_created_cost_base = Some(30);
2873 cfg.tx_context_replace_cost_base = Some(30);
2874 }
2875 24 => {
2876 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2878
2879 if chain != Chain::Testnet && chain != Chain::Mainnet {
2880 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2882 }
2883
2884 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
2887 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
2888
2889 cfg.feature_flags.additional_borrow_checks = true;
2891 }
2892 #[allow(deprecated)]
2893 25 => {
2894 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
2897 cfg.check_zklogin_id_cost_base = None;
2898 cfg.check_zklogin_issuer_cost_base = None;
2899 cfg.max_jwk_votes_per_validator_per_epoch = None;
2900 cfg.max_age_of_jwk_in_epochs = None;
2901 }
2902 26 => {
2903 }
2906 27 => {
2907 if chain != Chain::Mainnet {
2908 cfg.feature_flags.consensus_block_restrictions = true;
2911 }
2912
2913 if chain != Chain::Testnet && chain != Chain::Mainnet {
2914 cfg.feature_flags
2916 .pre_consensus_sponsor_only_move_authentication = true;
2917 }
2918 }
2919 28 => {
2920 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
2925
2926 cfg.feature_flags.metadata_in_module_bytes = true;
2929 cfg.feature_flags.publish_package_metadata = true;
2930 cfg.feature_flags.enable_move_authentication = true;
2932 cfg.transfer_receive_object_cost_base = Some(100);
2935
2936 if chain != Chain::Unknown {
2937 cfg.max_auth_gas = Some(20_000);
2939 }
2940
2941 if chain != Chain::Mainnet {
2942 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2944 cfg.feature_flags
2946 .pre_consensus_sponsor_only_move_authentication = true;
2947 }
2948 }
2949 29 => {
2950 cfg.feature_flags.always_advance_dkg_to_resolution = true;
2956
2957 cfg.feature_flags
2960 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2961
2962 cfg.feature_flags.consensus_fast_commit_sync = true;
2964 cfg.feature_flags.consensus_block_restrictions = true;
2968 }
2969 30 => {
2970 }
2978 31 => {
2979 cfg.feature_flags.validator_metadata_verify_v2 = true;
2980 }
2981 _ => panic!("unsupported version {version:?}"),
2992 }
2993 }
2994 cfg
2995 }
2996
2997 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
3003 let (
3004 max_back_edges_per_function,
3005 max_back_edges_per_module,
3006 sanity_check_with_regex_reference_safety,
3007 ) = if let Some((
3008 max_back_edges_per_function,
3009 max_back_edges_per_module,
3010 sanity_check_with_regex_reference_safety,
3011 )) = signing_limits
3012 {
3013 (
3014 Some(max_back_edges_per_function),
3015 Some(max_back_edges_per_module),
3016 Some(sanity_check_with_regex_reference_safety),
3017 )
3018 } else {
3019 (None, None, None)
3020 };
3021
3022 let additional_borrow_checks = if signing_limits.is_some() {
3023 true
3026 } else {
3027 self.additional_borrow_checks()
3028 };
3029
3030 VerifierConfig {
3031 max_loop_depth: Some(self.max_loop_depth() as usize),
3032 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
3033 max_function_parameters: Some(self.max_function_parameters() as usize),
3034 max_basic_blocks: Some(self.max_basic_blocks() as usize),
3035 max_value_stack_size: self.max_value_stack_size() as usize,
3036 max_type_nodes: Some(self.max_type_nodes() as usize),
3037 max_push_size: Some(self.max_push_size() as usize),
3038 max_dependency_depth: Some(self.max_dependency_depth() as usize),
3039 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
3040 max_function_definitions: Some(self.max_function_definitions() as usize),
3041 max_data_definitions: Some(self.max_struct_definitions() as usize),
3042 max_constant_vector_len: Some(self.max_move_vector_len()),
3043 max_back_edges_per_function,
3044 max_back_edges_per_module,
3045 max_basic_blocks_in_script: None,
3046 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
3050 max_variants_in_enum: self.max_move_enum_variants_as_option(),
3051 additional_borrow_checks,
3052 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
3053 .map(|limit| limit as u128),
3054 }
3055 }
3056
3057 pub fn apply_overrides_for_testing(
3062 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
3063 ) -> OverrideGuard {
3064 CONFIG_OVERRIDE.with(|ovr| {
3065 let mut cur = ovr.borrow_mut();
3066 assert!(cur.is_none(), "config override already present");
3067 *cur = Some(Box::new(override_fn));
3068 OverrideGuard
3069 })
3070 }
3071}
3072
3073impl ProtocolConfig {
3078 pub fn set_per_object_congestion_control_mode_for_testing(
3079 &mut self,
3080 val: PerObjectCongestionControlMode,
3081 ) {
3082 self.feature_flags.per_object_congestion_control_mode = val;
3083 }
3084
3085 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
3086 self.feature_flags.consensus_choice = val;
3087 }
3088
3089 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
3090 self.feature_flags.consensus_network = val;
3091 }
3092
3093 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
3094 self.feature_flags.passkey_auth = val
3095 }
3096
3097 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
3098 self.feature_flags
3099 .disallow_new_modules_in_deps_only_packages = val;
3100 }
3101
3102 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
3103 self.feature_flags.consensus_round_prober = val;
3104 }
3105
3106 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
3107 self.feature_flags
3108 .consensus_distributed_vote_scoring_strategy = val;
3109 }
3110
3111 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
3112 self.consensus_gc_depth = Some(val);
3113 }
3114
3115 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
3116 self.feature_flags.consensus_linearize_subdag_v2 = val;
3117 }
3118
3119 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
3120 self.feature_flags
3121 .consensus_round_prober_probe_accepted_rounds = val;
3122 }
3123
3124 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
3125 self.feature_flags.accept_passkey_in_multisig = val;
3126 }
3127
3128 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
3129 self.feature_flags.consensus_smart_ancestor_selection = val;
3130 }
3131
3132 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
3133 self.feature_flags.consensus_batched_block_sync = val;
3134 }
3135
3136 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
3137 self.feature_flags
3138 .congestion_control_min_free_execution_slot = val;
3139 }
3140
3141 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
3142 self.feature_flags
3143 .congestion_control_gas_price_feedback_mechanism = val;
3144 }
3145
3146 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
3147 self.feature_flags.select_committee_from_eligible_validators = val;
3148 }
3149
3150 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
3151 self.feature_flags.track_non_committee_eligible_validators = val;
3152 }
3153
3154 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
3155 self.feature_flags
3156 .select_committee_supporting_next_epoch_version = val;
3157 }
3158
3159 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
3160 &mut self,
3161 val: bool,
3162 ) {
3163 self.feature_flags
3164 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3165 }
3166
3167 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3168 &mut self,
3169 val: bool,
3170 ) {
3171 self.feature_flags
3172 .consensus_commit_transactions_only_for_traversed_headers = val;
3173 }
3174
3175 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3176 &mut self,
3177 val: bool,
3178 ) {
3179 self.feature_flags
3180 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3181 }
3182
3183 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3184 &mut self,
3185 val: bool,
3186 ) {
3187 self.feature_flags
3188 .separate_gas_price_feedback_mechanism_for_randomness = val;
3189 }
3190
3191 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3192 self.feature_flags.metadata_in_module_bytes = val;
3193 }
3194
3195 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3196 self.feature_flags.publish_package_metadata = val;
3197 }
3198
3199 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3200 self.feature_flags.enable_move_authentication = val;
3201 }
3202
3203 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3204 self.feature_flags.enable_move_authentication_for_sponsor = val;
3205 }
3206
3207 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3208 self.feature_flags.consensus_fast_commit_sync = val;
3209 }
3210
3211 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3212 self.feature_flags.consensus_block_restrictions = val;
3213 }
3214
3215 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3216 self.feature_flags
3217 .pre_consensus_sponsor_only_move_authentication = val;
3218 }
3219
3220 pub fn set_consensus_starfish_speed_for_testing(&mut self, val: bool) {
3221 self.feature_flags.consensus_starfish_speed = val;
3222 }
3223
3224 pub fn set_always_advance_dkg_to_resolution_for_testing(&mut self, val: bool) {
3225 self.feature_flags.always_advance_dkg_to_resolution = val;
3226 }
3227
3228 pub fn set_enable_pcool_flow_for_testing(&mut self, val: bool) {
3229 self.feature_flags.enable_pcool_flow = val;
3230 }
3231
3232 pub fn set_commits_per_schedule_for_testing(&mut self, val: u32) {
3233 self.consensus_commits_per_schedule = Some(val);
3234 }
3235}
3236
3237type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
3238
3239thread_local! {
3240 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
3241}
3242
3243#[must_use]
3244pub struct OverrideGuard;
3245
3246impl Drop for OverrideGuard {
3247 fn drop(&mut self) {
3248 info!("restoring override fn");
3249 CONFIG_OVERRIDE.with(|ovr| {
3250 *ovr.borrow_mut() = None;
3251 });
3252 }
3253}
3254
3255#[derive(PartialEq, Eq)]
3259pub enum LimitThresholdCrossed {
3260 None,
3261 Soft(u128, u128),
3262 Hard(u128, u128),
3263}
3264
3265pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
3268 x: T,
3269 soft_limit: U,
3270 hard_limit: V,
3271) -> LimitThresholdCrossed {
3272 let x: V = x.into();
3273 let soft_limit: V = soft_limit.into();
3274
3275 debug_assert!(soft_limit <= hard_limit);
3276
3277 if x >= hard_limit {
3280 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
3281 } else if x < soft_limit {
3282 LimitThresholdCrossed::None
3283 } else {
3284 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
3285 }
3286}
3287
3288#[macro_export]
3289macro_rules! check_limit {
3290 ($x:expr, $hard:expr) => {
3291 check_limit!($x, $hard, $hard)
3292 };
3293 ($x:expr, $soft:expr, $hard:expr) => {
3294 check_limit_in_range($x as u64, $soft, $hard)
3295 };
3296}
3297
3298#[macro_export]
3302macro_rules! check_limit_by_meter {
3303 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
3304 let (h, metered_str) = if $is_metered {
3306 ($metered_limit, "metered")
3307 } else {
3308 ($unmetered_hard_limit, "unmetered")
3310 };
3311 use iota_protocol_config::check_limit_in_range;
3312 let result = check_limit_in_range($x as u64, $metered_limit, h);
3313 match result {
3314 LimitThresholdCrossed::None => {}
3315 LimitThresholdCrossed::Soft(_, _) => {
3316 $metric.with_label_values(&[metered_str, "soft"]).inc();
3317 }
3318 LimitThresholdCrossed::Hard(_, _) => {
3319 $metric.with_label_values(&[metered_str, "hard"]).inc();
3320 }
3321 };
3322 result
3323 }};
3324}
3325
3326#[cfg(all(test, not(msim)))]
3327mod test {
3328 use insta::assert_yaml_snapshot;
3329
3330 use super::*;
3331
3332 #[test]
3333 fn snapshot_tests() {
3334 println!("\n============================================================================");
3335 println!("! !");
3336 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
3337 println!("! !");
3338 println!("============================================================================\n");
3339 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
3340 let chain_str = match chain_id {
3345 Chain::Unknown => "".to_string(),
3346 _ => format!("{chain_id:?}_"),
3347 };
3348 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
3349 let cur = ProtocolVersion::new(i);
3350 assert_yaml_snapshot!(
3351 format!("{}version_{}", chain_str, cur.as_u64()),
3352 ProtocolConfig::get_for_version(cur, *chain_id)
3353 );
3354 }
3355 }
3356 }
3357
3358 #[test]
3359 fn test_getters() {
3360 let prot: ProtocolConfig =
3361 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3362 assert_eq!(
3363 prot.max_arguments(),
3364 prot.max_arguments_as_option().unwrap()
3365 );
3366 }
3367
3368 #[test]
3369 fn test_setters() {
3370 let mut prot: ProtocolConfig =
3371 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3372 prot.set_max_arguments_for_testing(123);
3373 assert_eq!(prot.max_arguments(), 123);
3374
3375 prot.set_max_arguments_from_str_for_testing("321".to_string());
3376 assert_eq!(prot.max_arguments(), 321);
3377
3378 prot.disable_max_arguments_for_testing();
3379 assert_eq!(prot.max_arguments_as_option(), None);
3380
3381 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
3382 assert_eq!(prot.max_arguments(), 456);
3383 }
3384
3385 #[test]
3386 #[should_panic(expected = "unsupported version")]
3387 fn max_version_test() {
3388 let _ = ProtocolConfig::get_for_version_impl(
3391 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
3392 Chain::Unknown,
3393 );
3394 }
3395
3396 #[test]
3397 fn lookup_by_string_test() {
3398 let prot: ProtocolConfig =
3399 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3400 assert!(prot.lookup_attr("some random string".to_string()).is_none());
3402
3403 assert!(
3404 prot.lookup_attr("max_arguments".to_string())
3405 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
3406 );
3407
3408 assert!(
3410 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3411 .is_none()
3412 );
3413 assert!(
3414 prot.attr_map()
3415 .get("poseidon_bn254_cost_base")
3416 .unwrap()
3417 .is_none()
3418 );
3419
3420 let prot: ProtocolConfig =
3422 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3423
3424 assert!(
3425 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3426 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3427 );
3428 assert!(
3429 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
3430 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3431 );
3432
3433 let prot: ProtocolConfig =
3435 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3436 assert!(
3438 prot.feature_flags
3439 .lookup_attr("some random string".to_owned())
3440 .is_none()
3441 );
3442 assert!(
3443 !prot
3444 .feature_flags
3445 .attr_map()
3446 .contains_key("some random string")
3447 );
3448
3449 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
3451 assert!(
3452 prot.feature_flags
3453 .attr_map()
3454 .get("enable_poseidon")
3455 .unwrap()
3456 == &false
3457 );
3458 let prot: ProtocolConfig =
3459 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3460 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
3462 assert!(
3463 prot.feature_flags
3464 .attr_map()
3465 .get("enable_poseidon")
3466 .unwrap()
3467 == &true
3468 );
3469 }
3470
3471 #[test]
3472 fn limit_range_fn_test() {
3473 let low = 100u32;
3474 let high = 10000u64;
3475
3476 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
3477 assert!(matches!(
3478 check_limit!(255u16, low, high),
3479 LimitThresholdCrossed::Soft(255u128, 100)
3480 ));
3481 assert!(matches!(
3488 check_limit!(2550000u64, low, high),
3489 LimitThresholdCrossed::Hard(2550000, 10000)
3490 ));
3491
3492 assert!(matches!(
3493 check_limit!(2550000u64, high, high),
3494 LimitThresholdCrossed::Hard(2550000, 10000)
3495 ));
3496
3497 assert!(matches!(
3498 check_limit!(1u8, high),
3499 LimitThresholdCrossed::None
3500 ));
3501
3502 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
3503
3504 assert!(matches!(
3505 check_limit!(2550000u64, high),
3506 LimitThresholdCrossed::Hard(2550000, 10000)
3507 ));
3508 }
3509}