1use std::{
6 cell::RefCell,
7 cmp::min,
8 sync::atomic::{AtomicBool, Ordering},
9};
10
11use clap::*;
12use iota_protocol_config_macros::{
13 ProtocolConfigAccessors, ProtocolConfigFeatureFlagsGetters, ProtocolConfigOverride,
14};
15use move_vm_config::verifier::VerifierConfig;
16use serde::{Deserialize, Serialize};
17use serde_with::skip_serializing_none;
18use tracing::{info, warn};
19
20const MIN_PROTOCOL_VERSION: u64 = 1;
22pub const MAX_PROTOCOL_VERSION: u64 = 30;
23
24pub const PROTOCOL_VERSION_IIP8: u64 = 20;
26#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
173pub struct ProtocolVersion(u64);
174
175impl ProtocolVersion {
176 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
182
183 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
184
185 #[cfg(not(msim))]
186 const MAX_ALLOWED: Self = Self::MAX;
187
188 #[cfg(msim)]
191 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
192
193 pub fn new(v: u64) -> Self {
194 Self(v)
195 }
196
197 pub const fn as_u64(&self) -> u64 {
198 self.0
199 }
200
201 pub fn max() -> Self {
204 Self::MAX
205 }
206}
207
208impl From<u64> for ProtocolVersion {
209 fn from(v: u64) -> Self {
210 Self::new(v)
211 }
212}
213
214impl std::ops::Sub<u64> for ProtocolVersion {
215 type Output = Self;
216 fn sub(self, rhs: u64) -> Self::Output {
217 Self::new(self.0 - rhs)
218 }
219}
220
221impl std::ops::Add<u64> for ProtocolVersion {
222 type Output = Self;
223 fn add(self, rhs: u64) -> Self::Output {
224 Self::new(self.0 + rhs)
225 }
226}
227
228#[derive(
229 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
230)]
231pub enum Chain {
232 Mainnet,
233 Testnet,
234 #[default]
235 Unknown,
236}
237
238impl Chain {
239 pub fn as_str(self) -> &'static str {
240 match self {
241 Chain::Mainnet => "mainnet",
242 Chain::Testnet => "testnet",
243 Chain::Unknown => "unknown",
244 }
245 }
246}
247
248pub struct Error(pub String);
249
250#[derive(
254 Default,
255 Clone,
256 Serialize,
257 Deserialize,
258 Debug,
259 ProtocolConfigFeatureFlagsGetters,
260 ProtocolConfigOverride,
261)]
262struct FeatureFlags {
263 #[serde(skip_serializing_if = "is_true")]
269 disable_invariant_violation_check_in_swap_loc: bool,
270
271 #[serde(skip_serializing_if = "is_true")]
274 no_extraneous_module_bytes: bool,
275
276 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
278 consensus_transaction_ordering: ConsensusTransactionOrdering,
279
280 #[serde(skip_serializing_if = "is_true")]
283 hardened_otw_check: bool,
284
285 #[serde(skip_serializing_if = "is_false")]
287 enable_poseidon: bool,
288
289 #[serde(skip_serializing_if = "is_false")]
291 enable_group_ops_native_function_msm: bool,
292
293 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
295 per_object_congestion_control_mode: PerObjectCongestionControlMode,
296
297 #[serde(
299 default = "ConsensusChoice::mysticeti_deprecated",
300 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
301 )]
302 consensus_choice: ConsensusChoice,
303
304 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
306 consensus_network: ConsensusNetwork,
307
308 #[deprecated]
310 #[serde(skip_serializing_if = "Option::is_none")]
311 zklogin_max_epoch_upper_bound_delta: Option<u64>,
312
313 #[serde(skip_serializing_if = "is_false")]
315 enable_vdf: bool,
316
317 #[serde(skip_serializing_if = "is_false")]
319 passkey_auth: bool,
320
321 #[serde(skip_serializing_if = "is_true")]
324 rethrow_serialization_type_layout_errors: bool,
325
326 #[serde(skip_serializing_if = "is_false")]
328 relocate_event_module: bool,
329
330 #[serde(skip_serializing_if = "is_false")]
332 protocol_defined_base_fee: bool,
333
334 #[serde(skip_serializing_if = "is_false")]
336 uncompressed_g1_group_elements: bool,
337
338 #[serde(skip_serializing_if = "is_false")]
340 disallow_new_modules_in_deps_only_packages: bool,
341
342 #[serde(skip_serializing_if = "is_false")]
344 native_charging_v2: bool,
345
346 #[serde(skip_serializing_if = "is_false")]
348 convert_type_argument_error: bool,
349
350 #[serde(skip_serializing_if = "is_false")]
352 consensus_round_prober: bool,
353
354 #[serde(skip_serializing_if = "is_false")]
356 consensus_distributed_vote_scoring_strategy: bool,
357
358 #[serde(skip_serializing_if = "is_false")]
362 consensus_linearize_subdag_v2: bool,
363
364 #[serde(skip_serializing_if = "is_false")]
366 variant_nodes: bool,
367
368 #[serde(skip_serializing_if = "is_false")]
370 consensus_smart_ancestor_selection: bool,
371
372 #[serde(skip_serializing_if = "is_false")]
374 consensus_round_prober_probe_accepted_rounds: bool,
375
376 #[serde(skip_serializing_if = "is_false")]
378 consensus_zstd_compression: bool,
379
380 #[serde(skip_serializing_if = "is_false")]
383 congestion_control_min_free_execution_slot: bool,
384
385 #[serde(skip_serializing_if = "is_false")]
387 accept_passkey_in_multisig: bool,
388
389 #[serde(skip_serializing_if = "is_false")]
391 consensus_batched_block_sync: bool,
392
393 #[serde(skip_serializing_if = "is_false")]
396 congestion_control_gas_price_feedback_mechanism: bool,
397
398 #[serde(skip_serializing_if = "is_false")]
400 validate_identifier_inputs: bool,
401
402 #[serde(skip_serializing_if = "is_false")]
405 minimize_child_object_mutations: bool,
406
407 #[serde(skip_serializing_if = "is_false")]
409 dependency_linkage_error: bool,
410
411 #[serde(skip_serializing_if = "is_false")]
413 additional_multisig_checks: bool,
414
415 #[serde(skip_serializing_if = "is_false")]
418 normalize_ptb_arguments: bool,
419
420 #[serde(skip_serializing_if = "is_false")]
424 select_committee_from_eligible_validators: bool,
425
426 #[serde(skip_serializing_if = "is_false")]
433 track_non_committee_eligible_validators: bool,
434
435 #[serde(skip_serializing_if = "is_false")]
441 select_committee_supporting_next_epoch_version: bool,
442
443 #[serde(skip_serializing_if = "is_false")]
447 consensus_median_timestamp_with_checkpoint_enforcement: bool,
448
449 #[serde(skip_serializing_if = "is_false")]
451 consensus_commit_transactions_only_for_traversed_headers: bool,
452
453 #[serde(skip_serializing_if = "is_false")]
455 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
456
457 #[serde(skip_serializing_if = "is_false")]
460 separate_gas_price_feedback_mechanism_for_randomness: bool,
461
462 #[serde(skip_serializing_if = "is_false")]
465 metadata_in_module_bytes: bool,
466
467 #[serde(skip_serializing_if = "is_false")]
469 publish_package_metadata: bool,
470
471 #[serde(skip_serializing_if = "is_false")]
473 enable_move_authentication: bool,
474
475 #[serde(skip_serializing_if = "is_false")]
477 enable_move_authentication_for_sponsor: bool,
478
479 #[serde(skip_serializing_if = "is_false")]
481 pass_validator_scores_to_advance_epoch: bool,
482
483 #[serde(skip_serializing_if = "is_false")]
485 calculate_validator_scores: bool,
486
487 #[serde(skip_serializing_if = "is_false")]
489 adjust_rewards_by_score: bool,
490
491 #[serde(skip_serializing_if = "is_false")]
494 pass_calculated_validator_scores_to_advance_epoch: bool,
495
496 #[serde(skip_serializing_if = "is_false")]
501 consensus_fast_commit_sync: bool,
502
503 #[serde(skip_serializing_if = "is_false")]
506 consensus_block_restrictions: bool,
507
508 #[serde(skip_serializing_if = "is_false")]
510 move_native_tx_context: bool,
511
512 #[serde(skip_serializing_if = "is_false")]
514 additional_borrow_checks: bool,
515
516 #[serde(skip_serializing_if = "is_false")]
518 pre_consensus_sponsor_only_move_authentication: bool,
519
520 #[serde(skip_serializing_if = "is_false")]
522 consensus_starfish_speed: bool,
523
524 #[serde(skip_serializing_if = "is_false")]
531 always_advance_dkg_to_resolution: bool,
532
533 #[serde(skip_serializing_if = "is_false")]
538 enable_pcool_flow: bool,
539}
540
541fn is_true(b: &bool) -> bool {
542 *b
543}
544
545fn is_false(b: &bool) -> bool {
546 !b
547}
548
549#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
551pub enum ConsensusTransactionOrdering {
552 #[default]
555 None,
556 ByGasPrice,
558}
559
560impl ConsensusTransactionOrdering {
561 pub fn is_none(&self) -> bool {
562 matches!(self, ConsensusTransactionOrdering::None)
563 }
564}
565
566#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
568pub enum PerObjectCongestionControlMode {
569 #[default]
570 None, TotalGasBudget, TotalTxCount, }
574
575impl PerObjectCongestionControlMode {
576 pub fn is_none(&self) -> bool {
577 matches!(self, PerObjectCongestionControlMode::None)
578 }
579}
580
581#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
583pub enum ConsensusChoice {
584 #[deprecated(note = "Mysticeti was replaced by Starfish")]
587 MysticetiDeprecated,
588 #[default]
589 Starfish,
590}
591
592#[expect(deprecated)]
593impl ConsensusChoice {
594 fn mysticeti_deprecated() -> Self {
601 ConsensusChoice::MysticetiDeprecated
602 }
603
604 pub fn is_mysticeti_deprecated(&self) -> bool {
605 matches!(self, ConsensusChoice::MysticetiDeprecated)
606 }
607 pub fn is_starfish(&self) -> bool {
608 matches!(self, ConsensusChoice::Starfish)
609 }
610}
611
612#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
614pub enum ConsensusNetwork {
615 #[default]
616 Tonic,
617}
618
619impl ConsensusNetwork {
620 pub fn is_tonic(&self) -> bool {
621 matches!(self, ConsensusNetwork::Tonic)
622 }
623}
624
625#[skip_serializing_none]
659#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
660pub struct ProtocolConfig {
661 pub version: ProtocolVersion,
662
663 feature_flags: FeatureFlags,
664
665 max_tx_size_bytes: Option<u64>,
670
671 max_input_objects: Option<u64>,
674
675 max_size_written_objects: Option<u64>,
680 max_size_written_objects_system_tx: Option<u64>,
684
685 max_serialized_tx_effects_size_bytes: Option<u64>,
687
688 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
690
691 max_gas_payment_objects: Option<u32>,
693
694 max_modules_in_publish: Option<u32>,
696
697 max_package_dependencies: Option<u32>,
699
700 max_arguments: Option<u32>,
703
704 max_type_arguments: Option<u32>,
706
707 max_type_argument_depth: Option<u32>,
709
710 max_pure_argument_size: Option<u32>,
712
713 max_programmable_tx_commands: Option<u32>,
715
716 move_binary_format_version: Option<u32>,
722 min_move_binary_format_version: Option<u32>,
723
724 binary_module_handles: Option<u16>,
726 binary_struct_handles: Option<u16>,
727 binary_function_handles: Option<u16>,
728 binary_function_instantiations: Option<u16>,
729 binary_signatures: Option<u16>,
730 binary_constant_pool: Option<u16>,
731 binary_identifiers: Option<u16>,
732 binary_address_identifiers: Option<u16>,
733 binary_struct_defs: Option<u16>,
734 binary_struct_def_instantiations: Option<u16>,
735 binary_function_defs: Option<u16>,
736 binary_field_handles: Option<u16>,
737 binary_field_instantiations: Option<u16>,
738 binary_friend_decls: Option<u16>,
739 binary_enum_defs: Option<u16>,
740 binary_enum_def_instantiations: Option<u16>,
741 binary_variant_handles: Option<u16>,
742 binary_variant_instantiation_handles: Option<u16>,
743
744 max_move_object_size: Option<u64>,
747
748 max_move_package_size: Option<u64>,
753
754 max_publish_or_upgrade_per_ptb: Option<u64>,
757
758 max_tx_gas: Option<u64>,
760
761 max_auth_gas: Option<u64>,
763
764 max_gas_price: Option<u64>,
767
768 max_gas_computation_bucket: Option<u64>,
771
772 gas_rounding_step: Option<u64>,
774
775 max_loop_depth: Option<u64>,
777
778 max_generic_instantiation_length: Option<u64>,
781
782 max_function_parameters: Option<u64>,
785
786 max_basic_blocks: Option<u64>,
789
790 max_value_stack_size: Option<u64>,
792
793 max_type_nodes: Option<u64>,
797
798 max_push_size: Option<u64>,
801
802 max_struct_definitions: Option<u64>,
805
806 max_function_definitions: Option<u64>,
809
810 max_fields_in_struct: Option<u64>,
813
814 max_dependency_depth: Option<u64>,
817
818 max_num_event_emit: Option<u64>,
821
822 max_num_new_move_object_ids: Option<u64>,
825
826 max_num_new_move_object_ids_system_tx: Option<u64>,
829
830 max_num_deleted_move_object_ids: Option<u64>,
833
834 max_num_deleted_move_object_ids_system_tx: Option<u64>,
837
838 max_num_transferred_move_object_ids: Option<u64>,
841
842 max_num_transferred_move_object_ids_system_tx: Option<u64>,
845
846 max_event_emit_size: Option<u64>,
848
849 max_event_emit_size_total: Option<u64>,
851
852 max_move_vector_len: Option<u64>,
855
856 max_move_identifier_len: Option<u64>,
859
860 max_move_value_depth: Option<u64>,
862
863 max_move_enum_variants: Option<u64>,
866
867 max_back_edges_per_function: Option<u64>,
870
871 max_back_edges_per_module: Option<u64>,
874
875 max_verifier_meter_ticks_per_function: Option<u64>,
878
879 max_meter_ticks_per_module: Option<u64>,
882
883 max_meter_ticks_per_package: Option<u64>,
886
887 object_runtime_max_num_cached_objects: Option<u64>,
894
895 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
898
899 object_runtime_max_num_store_entries: Option<u64>,
902
903 object_runtime_max_num_store_entries_system_tx: Option<u64>,
906
907 base_tx_cost_fixed: Option<u64>,
912
913 package_publish_cost_fixed: Option<u64>,
917
918 base_tx_cost_per_byte: Option<u64>,
922
923 package_publish_cost_per_byte: Option<u64>,
925
926 obj_access_cost_read_per_byte: Option<u64>,
928
929 obj_access_cost_mutate_per_byte: Option<u64>,
931
932 obj_access_cost_delete_per_byte: Option<u64>,
934
935 obj_access_cost_verify_per_byte: Option<u64>,
945
946 max_type_to_layout_nodes: Option<u64>,
948
949 max_ptb_value_size: Option<u64>,
951
952 gas_model_version: Option<u64>,
957
958 obj_data_cost_refundable: Option<u64>,
964
965 obj_metadata_cost_non_refundable: Option<u64>,
969
970 storage_rebate_rate: Option<u64>,
976
977 reward_slashing_rate: Option<u64>,
980
981 storage_gas_price: Option<u64>,
983
984 base_gas_price: Option<u64>,
986
987 validator_target_reward: Option<u64>,
989
990 max_transactions_per_checkpoint: Option<u64>,
997
998 max_checkpoint_size_bytes: Option<u64>,
1002
1003 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
1009
1010 address_from_bytes_cost_base: Option<u64>,
1015 address_to_u256_cost_base: Option<u64>,
1017 address_from_u256_cost_base: Option<u64>,
1019
1020 config_read_setting_impl_cost_base: Option<u64>,
1025 config_read_setting_impl_cost_per_byte: Option<u64>,
1026
1027 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
1031 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
1032 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
1033 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
1034 dynamic_field_add_child_object_cost_base: Option<u64>,
1037 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
1038 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
1039 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
1040 dynamic_field_borrow_child_object_cost_base: Option<u64>,
1043 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1044 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1045 dynamic_field_remove_child_object_cost_base: Option<u64>,
1048 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1049 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1050 dynamic_field_has_child_object_cost_base: Option<u64>,
1053 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1056 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1057 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1058
1059 event_emit_cost_base: Option<u64>,
1062 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1063 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1064 event_emit_output_cost_per_byte: Option<u64>,
1065
1066 object_borrow_uid_cost_base: Option<u64>,
1069 object_delete_impl_cost_base: Option<u64>,
1071 object_record_new_uid_cost_base: Option<u64>,
1073
1074 transfer_transfer_internal_cost_base: Option<u64>,
1077 transfer_freeze_object_cost_base: Option<u64>,
1079 transfer_share_object_cost_base: Option<u64>,
1081 transfer_receive_object_cost_base: Option<u64>,
1084
1085 tx_context_derive_id_cost_base: Option<u64>,
1088 tx_context_fresh_id_cost_base: Option<u64>,
1089 tx_context_sender_cost_base: Option<u64>,
1090 tx_context_digest_cost_base: Option<u64>,
1091 tx_context_epoch_cost_base: Option<u64>,
1092 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1093 tx_context_sponsor_cost_base: Option<u64>,
1094 tx_context_rgp_cost_base: Option<u64>,
1095 tx_context_gas_price_cost_base: Option<u64>,
1096 tx_context_gas_budget_cost_base: Option<u64>,
1097 tx_context_ids_created_cost_base: Option<u64>,
1098 tx_context_replace_cost_base: Option<u64>,
1099
1100 types_is_one_time_witness_cost_base: Option<u64>,
1103 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1104 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1105
1106 validator_validate_metadata_cost_base: Option<u64>,
1109 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1110
1111 crypto_invalid_arguments_cost: Option<u64>,
1113 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1115 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1116 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1117
1118 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1120 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1121 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1122
1123 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1125 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1126 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1127 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1128 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1129 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1130
1131 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1133
1134 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1136 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1137 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1138 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1139 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1140 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1141
1142 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1144 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1145 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1146 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1147 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1148 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1149
1150 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1152 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1153 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1154 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1155 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1156 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1157
1158 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1160 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1161 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1162
1163 ed25519_ed25519_verify_cost_base: Option<u64>,
1165 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1166 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1167
1168 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1170 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1171
1172 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1174 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1175 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1176 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1177 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1178
1179 hash_blake2b256_cost_base: Option<u64>,
1181 hash_blake2b256_data_cost_per_byte: Option<u64>,
1182 hash_blake2b256_data_cost_per_block: Option<u64>,
1183
1184 hash_keccak256_cost_base: Option<u64>,
1186 hash_keccak256_data_cost_per_byte: Option<u64>,
1187 hash_keccak256_data_cost_per_block: Option<u64>,
1188
1189 poseidon_bn254_cost_base: Option<u64>,
1191 poseidon_bn254_cost_per_block: Option<u64>,
1192
1193 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1195 group_ops_bls12381_decode_g1_cost: Option<u64>,
1196 group_ops_bls12381_decode_g2_cost: Option<u64>,
1197 group_ops_bls12381_decode_gt_cost: Option<u64>,
1198 group_ops_bls12381_scalar_add_cost: Option<u64>,
1199 group_ops_bls12381_g1_add_cost: Option<u64>,
1200 group_ops_bls12381_g2_add_cost: Option<u64>,
1201 group_ops_bls12381_gt_add_cost: Option<u64>,
1202 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1203 group_ops_bls12381_g1_sub_cost: Option<u64>,
1204 group_ops_bls12381_g2_sub_cost: Option<u64>,
1205 group_ops_bls12381_gt_sub_cost: Option<u64>,
1206 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1207 group_ops_bls12381_g1_mul_cost: Option<u64>,
1208 group_ops_bls12381_g2_mul_cost: Option<u64>,
1209 group_ops_bls12381_gt_mul_cost: Option<u64>,
1210 group_ops_bls12381_scalar_div_cost: Option<u64>,
1211 group_ops_bls12381_g1_div_cost: Option<u64>,
1212 group_ops_bls12381_g2_div_cost: Option<u64>,
1213 group_ops_bls12381_gt_div_cost: Option<u64>,
1214 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1215 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1216 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1217 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1218 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1219 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1220 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1221 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1222 group_ops_bls12381_msm_max_len: Option<u32>,
1223 group_ops_bls12381_pairing_cost: Option<u64>,
1224 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1225 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1226 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1227 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1228 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1229
1230 hmac_hmac_sha3_256_cost_base: Option<u64>,
1232 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1233 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1234
1235 #[deprecated]
1237 check_zklogin_id_cost_base: Option<u64>,
1238 #[deprecated]
1240 check_zklogin_issuer_cost_base: Option<u64>,
1241
1242 vdf_verify_vdf_cost: Option<u64>,
1243 vdf_hash_to_input_cost: Option<u64>,
1244
1245 bcs_per_byte_serialized_cost: Option<u64>,
1247 bcs_legacy_min_output_size_cost: Option<u64>,
1248 bcs_failure_cost: Option<u64>,
1249
1250 hash_sha2_256_base_cost: Option<u64>,
1251 hash_sha2_256_per_byte_cost: Option<u64>,
1252 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1253 hash_sha3_256_base_cost: Option<u64>,
1254 hash_sha3_256_per_byte_cost: Option<u64>,
1255 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1256 type_name_get_base_cost: Option<u64>,
1257 type_name_get_per_byte_cost: Option<u64>,
1258
1259 string_check_utf8_base_cost: Option<u64>,
1260 string_check_utf8_per_byte_cost: Option<u64>,
1261 string_is_char_boundary_base_cost: Option<u64>,
1262 string_sub_string_base_cost: Option<u64>,
1263 string_sub_string_per_byte_cost: Option<u64>,
1264 string_index_of_base_cost: Option<u64>,
1265 string_index_of_per_byte_pattern_cost: Option<u64>,
1266 string_index_of_per_byte_searched_cost: Option<u64>,
1267
1268 vector_empty_base_cost: Option<u64>,
1269 vector_length_base_cost: Option<u64>,
1270 vector_push_back_base_cost: Option<u64>,
1271 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1272 vector_borrow_base_cost: Option<u64>,
1273 vector_pop_back_base_cost: Option<u64>,
1274 vector_destroy_empty_base_cost: Option<u64>,
1275 vector_swap_base_cost: Option<u64>,
1276 debug_print_base_cost: Option<u64>,
1277 debug_print_stack_trace_base_cost: Option<u64>,
1278
1279 execution_version: Option<u64>,
1281
1282 consensus_bad_nodes_stake_threshold: Option<u64>,
1286
1287 #[deprecated]
1288 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1289 #[deprecated]
1293 max_age_of_jwk_in_epochs: Option<u64>,
1294
1295 random_beacon_reduction_allowed_delta: Option<u16>,
1299
1300 random_beacon_reduction_lower_bound: Option<u32>,
1303
1304 random_beacon_dkg_timeout_round: Option<u32>,
1307
1308 random_beacon_min_round_interval_ms: Option<u64>,
1310
1311 random_beacon_dkg_version: Option<u64>,
1315
1316 consensus_max_transaction_size_bytes: Option<u64>,
1321 consensus_max_transactions_in_block_bytes: Option<u64>,
1323 consensus_max_num_transactions_in_block: Option<u64>,
1325
1326 max_deferral_rounds_for_congestion_control: Option<u64>,
1330
1331 min_checkpoint_interval_ms: Option<u64>,
1333
1334 checkpoint_summary_version_specific_data: Option<u64>,
1336
1337 max_soft_bundle_size: Option<u64>,
1340
1341 bridge_should_try_to_finalize_committee: Option<bool>,
1346
1347 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1353
1354 max_committee_members_count: Option<u64>,
1358
1359 consensus_gc_depth: Option<u32>,
1362
1363 consensus_max_acknowledgments_per_block: Option<u32>,
1369
1370 max_congestion_limit_overshoot_per_commit: Option<u64>,
1375
1376 scorer_version: Option<u16>,
1385
1386 auth_context_digest_cost_base: Option<u64>,
1389 auth_context_tx_data_bytes_cost_base: Option<u64>,
1391 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1392 auth_context_tx_commands_cost_base: Option<u64>,
1394 auth_context_tx_commands_cost_per_byte: Option<u64>,
1395 auth_context_tx_inputs_cost_base: Option<u64>,
1397 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1398 auth_context_replace_cost_base: Option<u64>,
1401 auth_context_replace_cost_per_byte: Option<u64>,
1402 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1406}
1407
1408impl ProtocolConfig {
1410 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1423 self.feature_flags
1424 .disable_invariant_violation_check_in_swap_loc
1425 }
1426
1427 pub fn no_extraneous_module_bytes(&self) -> bool {
1428 self.feature_flags.no_extraneous_module_bytes
1429 }
1430
1431 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1432 self.feature_flags.consensus_transaction_ordering
1433 }
1434
1435 pub fn dkg_version(&self) -> u64 {
1436 self.random_beacon_dkg_version.unwrap_or(1)
1438 }
1439
1440 pub fn hardened_otw_check(&self) -> bool {
1441 self.feature_flags.hardened_otw_check
1442 }
1443
1444 pub fn enable_poseidon(&self) -> bool {
1445 self.feature_flags.enable_poseidon
1446 }
1447
1448 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1449 self.feature_flags.enable_group_ops_native_function_msm
1450 }
1451
1452 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1453 self.feature_flags.per_object_congestion_control_mode
1454 }
1455
1456 pub fn consensus_choice(&self) -> ConsensusChoice {
1457 self.feature_flags.consensus_choice
1458 }
1459
1460 pub fn consensus_network(&self) -> ConsensusNetwork {
1461 self.feature_flags.consensus_network
1462 }
1463
1464 pub fn enable_vdf(&self) -> bool {
1465 self.feature_flags.enable_vdf
1466 }
1467
1468 pub fn passkey_auth(&self) -> bool {
1469 self.feature_flags.passkey_auth
1470 }
1471
1472 pub fn max_transaction_size_bytes(&self) -> u64 {
1473 self.consensus_max_transaction_size_bytes
1475 .unwrap_or(256 * 1024)
1476 }
1477
1478 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1479 if cfg!(msim) {
1480 256 * 1024
1481 } else {
1482 self.consensus_max_transactions_in_block_bytes
1483 .unwrap_or(512 * 1024)
1484 }
1485 }
1486
1487 pub fn max_num_transactions_in_block(&self) -> u64 {
1488 if cfg!(msim) {
1489 8
1490 } else {
1491 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1492 }
1493 }
1494
1495 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1496 self.feature_flags.rethrow_serialization_type_layout_errors
1497 }
1498
1499 pub fn relocate_event_module(&self) -> bool {
1500 self.feature_flags.relocate_event_module
1501 }
1502
1503 pub fn protocol_defined_base_fee(&self) -> bool {
1504 self.feature_flags.protocol_defined_base_fee
1505 }
1506
1507 pub fn uncompressed_g1_group_elements(&self) -> bool {
1508 self.feature_flags.uncompressed_g1_group_elements
1509 }
1510
1511 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1512 self.feature_flags
1513 .disallow_new_modules_in_deps_only_packages
1514 }
1515
1516 pub fn native_charging_v2(&self) -> bool {
1517 self.feature_flags.native_charging_v2
1518 }
1519
1520 pub fn consensus_round_prober(&self) -> bool {
1521 self.feature_flags.consensus_round_prober
1522 }
1523
1524 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1525 self.feature_flags
1526 .consensus_distributed_vote_scoring_strategy
1527 }
1528
1529 pub fn gc_depth(&self) -> u32 {
1530 if cfg!(msim) {
1531 min(5, self.consensus_gc_depth.unwrap_or(0))
1533 } else {
1534 self.consensus_gc_depth.unwrap_or(0)
1535 }
1536 }
1537
1538 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1539 let res = self.feature_flags.consensus_linearize_subdag_v2;
1540 assert!(
1541 !res || self.gc_depth() > 0,
1542 "The consensus linearize sub dag V2 requires GC to be enabled"
1543 );
1544 res
1545 }
1546
1547 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1548 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1549 }
1550
1551 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1552 if self.consensus_block_restrictions() {
1553 2 * committee_size
1554 } else {
1555 self.consensus_max_acknowledgments_per_block_or_default() as usize
1556 }
1557 }
1558
1559 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1560 if self.consensus_block_restrictions() {
1561 committee_size
1562 } else {
1563 100
1564 }
1565 }
1566
1567 pub fn variant_nodes(&self) -> bool {
1568 self.feature_flags.variant_nodes
1569 }
1570
1571 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1572 self.feature_flags.consensus_smart_ancestor_selection
1573 }
1574
1575 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1576 self.feature_flags
1577 .consensus_round_prober_probe_accepted_rounds
1578 }
1579
1580 pub fn consensus_zstd_compression(&self) -> bool {
1581 self.feature_flags.consensus_zstd_compression
1582 }
1583
1584 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1585 self.feature_flags
1586 .congestion_control_min_free_execution_slot
1587 }
1588
1589 pub fn accept_passkey_in_multisig(&self) -> bool {
1590 self.feature_flags.accept_passkey_in_multisig
1591 }
1592
1593 pub fn consensus_batched_block_sync(&self) -> bool {
1594 self.feature_flags.consensus_batched_block_sync
1595 }
1596
1597 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1600 self.feature_flags
1601 .congestion_control_gas_price_feedback_mechanism
1602 }
1603
1604 pub fn validate_identifier_inputs(&self) -> bool {
1605 self.feature_flags.validate_identifier_inputs
1606 }
1607
1608 pub fn minimize_child_object_mutations(&self) -> bool {
1609 self.feature_flags.minimize_child_object_mutations
1610 }
1611
1612 pub fn dependency_linkage_error(&self) -> bool {
1613 self.feature_flags.dependency_linkage_error
1614 }
1615
1616 pub fn additional_multisig_checks(&self) -> bool {
1617 self.feature_flags.additional_multisig_checks
1618 }
1619
1620 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1621 0
1624 }
1625
1626 pub fn normalize_ptb_arguments(&self) -> bool {
1627 self.feature_flags.normalize_ptb_arguments
1628 }
1629
1630 pub fn select_committee_from_eligible_validators(&self) -> bool {
1631 let res = self.feature_flags.select_committee_from_eligible_validators;
1632 assert!(
1633 !res || (self.protocol_defined_base_fee()
1634 && self.max_committee_members_count_as_option().is_some()),
1635 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1636 );
1637 res
1638 }
1639
1640 pub fn track_non_committee_eligible_validators(&self) -> bool {
1641 self.feature_flags.track_non_committee_eligible_validators
1642 }
1643
1644 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1645 let res = self
1646 .feature_flags
1647 .select_committee_supporting_next_epoch_version;
1648 assert!(
1649 !res || (self.track_non_committee_eligible_validators()
1650 && self.select_committee_from_eligible_validators()),
1651 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1652 );
1653 res
1654 }
1655
1656 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1657 let res = self
1658 .feature_flags
1659 .consensus_median_timestamp_with_checkpoint_enforcement;
1660 assert!(
1661 !res || self.gc_depth() > 0,
1662 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1663 );
1664 res
1665 }
1666
1667 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1668 self.feature_flags
1669 .consensus_commit_transactions_only_for_traversed_headers
1670 }
1671
1672 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1675 self.feature_flags
1676 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1677 }
1678
1679 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1682 self.feature_flags
1683 .separate_gas_price_feedback_mechanism_for_randomness
1684 }
1685
1686 pub fn metadata_in_module_bytes(&self) -> bool {
1687 self.feature_flags.metadata_in_module_bytes
1688 }
1689
1690 pub fn publish_package_metadata(&self) -> bool {
1691 self.feature_flags.publish_package_metadata
1692 }
1693
1694 pub fn enable_move_authentication(&self) -> bool {
1695 self.feature_flags.enable_move_authentication
1696 }
1697
1698 pub fn additional_borrow_checks(&self) -> bool {
1699 self.feature_flags.additional_borrow_checks
1700 }
1701
1702 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1703 let enable_move_authentication_for_sponsor =
1704 self.feature_flags.enable_move_authentication_for_sponsor;
1705 assert!(
1706 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1707 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1708 );
1709 enable_move_authentication_for_sponsor
1710 }
1711
1712 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1713 self.feature_flags.pass_validator_scores_to_advance_epoch
1714 }
1715
1716 pub fn calculate_validator_scores(&self) -> bool {
1717 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1718 assert!(
1719 !calculate_validator_scores || self.scorer_version.is_some(),
1720 "calculate_validator_scores requires scorer_version to be set"
1721 );
1722 calculate_validator_scores
1723 }
1724
1725 pub fn adjust_rewards_by_score(&self) -> bool {
1726 let adjust = self.feature_flags.adjust_rewards_by_score;
1727 assert!(
1728 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1729 "adjust_rewards_by_score requires scorer_version to be set"
1730 );
1731 adjust
1732 }
1733
1734 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1735 let pass = self
1736 .feature_flags
1737 .pass_calculated_validator_scores_to_advance_epoch;
1738 assert!(
1739 !pass
1740 || (self.pass_validator_scores_to_advance_epoch()
1741 && self.calculate_validator_scores()),
1742 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
1743 );
1744 pass
1745 }
1746 pub fn consensus_fast_commit_sync(&self) -> bool {
1747 let res = self.feature_flags.consensus_fast_commit_sync;
1748 assert!(
1749 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
1750 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
1751 );
1752 res
1753 }
1754
1755 pub fn consensus_block_restrictions(&self) -> bool {
1756 self.feature_flags.consensus_block_restrictions
1757 }
1758
1759 pub fn move_native_tx_context(&self) -> bool {
1760 self.feature_flags.move_native_tx_context
1761 }
1762
1763 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
1764 let pre_consensus_sponsor_only_move_authentication = self
1765 .feature_flags
1766 .pre_consensus_sponsor_only_move_authentication;
1767 if pre_consensus_sponsor_only_move_authentication {
1768 assert!(
1769 self.enable_move_authentication(),
1770 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
1771 );
1772 assert!(
1773 self.enable_move_authentication_for_sponsor(),
1774 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
1775 );
1776 }
1777 pre_consensus_sponsor_only_move_authentication
1778 }
1779
1780 pub fn consensus_starfish_speed(&self) -> bool {
1781 let res = self.feature_flags.consensus_starfish_speed;
1782 assert!(
1783 !res || self.consensus_fast_commit_sync(),
1784 "consensus_starfish_speed requires consensus_fast_commit_sync to be enabled"
1785 );
1786 res
1787 }
1788
1789 pub fn always_advance_dkg_to_resolution(&self) -> bool {
1790 self.feature_flags.always_advance_dkg_to_resolution
1791 }
1792
1793 pub fn enable_pcool_flow(&self) -> bool {
1794 self.feature_flags.enable_pcool_flow
1795 }
1796}
1797
1798#[cfg(not(msim))]
1799static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1800
1801#[cfg(msim)]
1803thread_local! {
1804 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1805}
1806
1807impl ProtocolConfig {
1809 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1812 assert!(
1814 version >= ProtocolVersion::MIN,
1815 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1816 version,
1817 ProtocolVersion::MIN.0,
1818 );
1819 assert!(
1820 version <= ProtocolVersion::MAX_ALLOWED,
1821 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1822 version,
1823 ProtocolVersion::MAX_ALLOWED.0,
1824 );
1825
1826 let mut ret = Self::get_for_version_impl(version, chain);
1827 ret.version = version;
1828
1829 ret = CONFIG_OVERRIDE.with(|ovr| {
1830 if let Some(override_fn) = &*ovr.borrow() {
1831 warn!(
1832 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1833 );
1834 override_fn(version, ret)
1835 } else {
1836 ret
1837 }
1838 });
1839
1840 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1841 warn!(
1842 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1843 );
1844
1845 let overrides: ProtocolConfigOptional =
1847 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1848 .expect("failed to parse ProtocolConfig override env variables");
1849 overrides.apply_to(&mut ret);
1850
1851 let feature_flag_overrides: FeatureFlagsOptional =
1853 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_FEATURE_FLAGS_OVERRIDE")
1854 .expect("failed to parse ProtocolConfig feature flags override env variables");
1855
1856 feature_flag_overrides.apply_to(&mut ret.feature_flags);
1857 }
1858
1859 ret
1860 }
1861
1862 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1865 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1866 let mut ret = Self::get_for_version_impl(version, chain);
1867 ret.version = version;
1868 Some(ret)
1869 } else {
1870 None
1871 }
1872 }
1873
1874 #[cfg(not(msim))]
1875 pub fn poison_get_for_min_version() {
1876 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1877 }
1878
1879 #[cfg(not(msim))]
1880 fn load_poison_get_for_min_version() -> bool {
1881 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1882 }
1883
1884 #[cfg(msim)]
1885 pub fn poison_get_for_min_version() {
1886 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1887 }
1888
1889 #[cfg(msim)]
1890 fn load_poison_get_for_min_version() -> bool {
1891 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1892 }
1893
1894 pub fn convert_type_argument_error(&self) -> bool {
1895 self.feature_flags.convert_type_argument_error
1896 }
1897
1898 pub fn get_for_min_version() -> Self {
1902 if Self::load_poison_get_for_min_version() {
1903 panic!("get_for_min_version called on validator");
1904 }
1905 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1906 }
1907
1908 #[expect(non_snake_case)]
1919 pub fn get_for_max_version_UNSAFE() -> Self {
1920 if Self::load_poison_get_for_min_version() {
1921 panic!("get_for_max_version_UNSAFE called on validator");
1922 }
1923 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1924 }
1925
1926 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1927 #[cfg(msim)]
1928 {
1929 if version > ProtocolVersion::MAX {
1931 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1932 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1933 return config;
1934 }
1935 }
1936
1937 let mut cfg = Self {
1941 version,
1942
1943 feature_flags: Default::default(),
1944
1945 max_tx_size_bytes: Some(128 * 1024),
1946 max_input_objects: Some(2048),
1949 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1950 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1951 max_gas_payment_objects: Some(256),
1952 max_modules_in_publish: Some(64),
1953 max_package_dependencies: Some(32),
1954 max_arguments: Some(512),
1955 max_type_arguments: Some(16),
1956 max_type_argument_depth: Some(16),
1957 max_pure_argument_size: Some(16 * 1024),
1958 max_programmable_tx_commands: Some(1024),
1959 move_binary_format_version: Some(7),
1960 min_move_binary_format_version: Some(6),
1961 binary_module_handles: Some(100),
1962 binary_struct_handles: Some(300),
1963 binary_function_handles: Some(1500),
1964 binary_function_instantiations: Some(750),
1965 binary_signatures: Some(1000),
1966 binary_constant_pool: Some(4000),
1967 binary_identifiers: Some(10000),
1968 binary_address_identifiers: Some(100),
1969 binary_struct_defs: Some(200),
1970 binary_struct_def_instantiations: Some(100),
1971 binary_function_defs: Some(1000),
1972 binary_field_handles: Some(500),
1973 binary_field_instantiations: Some(250),
1974 binary_friend_decls: Some(100),
1975 binary_enum_defs: None,
1976 binary_enum_def_instantiations: None,
1977 binary_variant_handles: None,
1978 binary_variant_instantiation_handles: None,
1979 max_move_object_size: Some(250 * 1024),
1980 max_move_package_size: Some(100 * 1024),
1981 max_publish_or_upgrade_per_ptb: Some(5),
1982 max_auth_gas: None,
1984 max_tx_gas: Some(50_000_000_000),
1986 max_gas_price: Some(100_000),
1987 max_gas_computation_bucket: Some(5_000_000),
1988 max_loop_depth: Some(5),
1989 max_generic_instantiation_length: Some(32),
1990 max_function_parameters: Some(128),
1991 max_basic_blocks: Some(1024),
1992 max_value_stack_size: Some(1024),
1993 max_type_nodes: Some(256),
1994 max_push_size: Some(10000),
1995 max_struct_definitions: Some(200),
1996 max_function_definitions: Some(1000),
1997 max_fields_in_struct: Some(32),
1998 max_dependency_depth: Some(100),
1999 max_num_event_emit: Some(1024),
2000 max_num_new_move_object_ids: Some(2048),
2001 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
2002 max_num_deleted_move_object_ids: Some(2048),
2003 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
2004 max_num_transferred_move_object_ids: Some(2048),
2005 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
2006 max_event_emit_size: Some(250 * 1024),
2007 max_move_vector_len: Some(256 * 1024),
2008 max_type_to_layout_nodes: None,
2009 max_ptb_value_size: None,
2010
2011 max_back_edges_per_function: Some(10_000),
2012 max_back_edges_per_module: Some(10_000),
2013
2014 max_verifier_meter_ticks_per_function: Some(16_000_000),
2015
2016 max_meter_ticks_per_module: Some(16_000_000),
2017 max_meter_ticks_per_package: Some(16_000_000),
2018
2019 object_runtime_max_num_cached_objects: Some(1000),
2020 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2021 object_runtime_max_num_store_entries: Some(1000),
2022 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2023 base_tx_cost_fixed: Some(1_000),
2025 package_publish_cost_fixed: Some(1_000),
2026 base_tx_cost_per_byte: Some(0),
2027 package_publish_cost_per_byte: Some(80),
2028 obj_access_cost_read_per_byte: Some(15),
2029 obj_access_cost_mutate_per_byte: Some(40),
2030 obj_access_cost_delete_per_byte: Some(40),
2031 obj_access_cost_verify_per_byte: Some(200),
2032 obj_data_cost_refundable: Some(100),
2033 obj_metadata_cost_non_refundable: Some(50),
2034 gas_model_version: Some(1),
2035 storage_rebate_rate: Some(10000),
2036 reward_slashing_rate: Some(10000),
2038 storage_gas_price: Some(76),
2039 base_gas_price: None,
2040 validator_target_reward: Some(767_000 * 1_000_000_000),
2043 max_transactions_per_checkpoint: Some(10_000),
2044 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2045
2046 buffer_stake_for_protocol_upgrade_bps: Some(5000),
2048
2049 address_from_bytes_cost_base: Some(52),
2053 address_to_u256_cost_base: Some(52),
2055 address_from_u256_cost_base: Some(52),
2057
2058 config_read_setting_impl_cost_base: Some(100),
2061 config_read_setting_impl_cost_per_byte: Some(40),
2062
2063 dynamic_field_hash_type_and_key_cost_base: Some(100),
2067 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
2068 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
2069 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
2070 dynamic_field_add_child_object_cost_base: Some(100),
2073 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2074 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2075 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2076 dynamic_field_borrow_child_object_cost_base: Some(100),
2079 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2080 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2081 dynamic_field_remove_child_object_cost_base: Some(100),
2084 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2085 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2086 dynamic_field_has_child_object_cost_base: Some(100),
2089 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2092 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2093 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2094
2095 event_emit_cost_base: Some(52),
2098 event_emit_value_size_derivation_cost_per_byte: Some(2),
2099 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2100 event_emit_output_cost_per_byte: Some(10),
2101
2102 object_borrow_uid_cost_base: Some(52),
2105 object_delete_impl_cost_base: Some(52),
2107 object_record_new_uid_cost_base: Some(52),
2109
2110 transfer_transfer_internal_cost_base: Some(52),
2114 transfer_freeze_object_cost_base: Some(52),
2116 transfer_share_object_cost_base: Some(52),
2118 transfer_receive_object_cost_base: Some(52),
2119
2120 tx_context_derive_id_cost_base: Some(52),
2124 tx_context_fresh_id_cost_base: None,
2125 tx_context_sender_cost_base: None,
2126 tx_context_digest_cost_base: None,
2127 tx_context_epoch_cost_base: None,
2128 tx_context_epoch_timestamp_ms_cost_base: None,
2129 tx_context_sponsor_cost_base: None,
2130 tx_context_rgp_cost_base: None,
2131 tx_context_gas_price_cost_base: None,
2132 tx_context_gas_budget_cost_base: None,
2133 tx_context_ids_created_cost_base: None,
2134 tx_context_replace_cost_base: None,
2135
2136 types_is_one_time_witness_cost_base: Some(52),
2139 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2140 types_is_one_time_witness_type_cost_per_byte: Some(2),
2141
2142 validator_validate_metadata_cost_base: Some(52),
2146 validator_validate_metadata_data_cost_per_byte: Some(2),
2147
2148 crypto_invalid_arguments_cost: Some(100),
2150 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2152 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2153 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2154
2155 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2157 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2158 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2159
2160 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2162 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2163 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2164 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2165 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2166 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2167
2168 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2170
2171 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2173 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2174 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2175 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2176 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2177 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2178
2179 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2181 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2182 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2183 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2184 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2185 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2186
2187 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2189 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2190 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2191 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2192 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2193 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2194
2195 ecvrf_ecvrf_verify_cost_base: Some(52),
2197 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2198 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2199
2200 ed25519_ed25519_verify_cost_base: Some(52),
2202 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2203 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2204
2205 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2207 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2208
2209 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2211 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2212 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2213 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2214 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2215
2216 hash_blake2b256_cost_base: Some(52),
2218 hash_blake2b256_data_cost_per_byte: Some(2),
2219 hash_blake2b256_data_cost_per_block: Some(2),
2220 hash_keccak256_cost_base: Some(52),
2222 hash_keccak256_data_cost_per_byte: Some(2),
2223 hash_keccak256_data_cost_per_block: Some(2),
2224
2225 poseidon_bn254_cost_base: None,
2226 poseidon_bn254_cost_per_block: None,
2227
2228 hmac_hmac_sha3_256_cost_base: Some(52),
2230 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2231 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2232
2233 group_ops_bls12381_decode_scalar_cost: Some(52),
2235 group_ops_bls12381_decode_g1_cost: Some(52),
2236 group_ops_bls12381_decode_g2_cost: Some(52),
2237 group_ops_bls12381_decode_gt_cost: Some(52),
2238 group_ops_bls12381_scalar_add_cost: Some(52),
2239 group_ops_bls12381_g1_add_cost: Some(52),
2240 group_ops_bls12381_g2_add_cost: Some(52),
2241 group_ops_bls12381_gt_add_cost: Some(52),
2242 group_ops_bls12381_scalar_sub_cost: Some(52),
2243 group_ops_bls12381_g1_sub_cost: Some(52),
2244 group_ops_bls12381_g2_sub_cost: Some(52),
2245 group_ops_bls12381_gt_sub_cost: Some(52),
2246 group_ops_bls12381_scalar_mul_cost: Some(52),
2247 group_ops_bls12381_g1_mul_cost: Some(52),
2248 group_ops_bls12381_g2_mul_cost: Some(52),
2249 group_ops_bls12381_gt_mul_cost: Some(52),
2250 group_ops_bls12381_scalar_div_cost: Some(52),
2251 group_ops_bls12381_g1_div_cost: Some(52),
2252 group_ops_bls12381_g2_div_cost: Some(52),
2253 group_ops_bls12381_gt_div_cost: Some(52),
2254 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2255 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2256 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2257 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2258 group_ops_bls12381_g1_msm_base_cost: Some(52),
2259 group_ops_bls12381_g2_msm_base_cost: Some(52),
2260 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2261 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2262 group_ops_bls12381_msm_max_len: Some(32),
2263 group_ops_bls12381_pairing_cost: Some(52),
2264 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2265 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2266 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2267 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2268 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2269
2270 #[allow(deprecated)]
2272 check_zklogin_id_cost_base: Some(200),
2273 #[allow(deprecated)]
2274 check_zklogin_issuer_cost_base: Some(200),
2276
2277 vdf_verify_vdf_cost: None,
2278 vdf_hash_to_input_cost: None,
2279
2280 bcs_per_byte_serialized_cost: Some(2),
2281 bcs_legacy_min_output_size_cost: Some(1),
2282 bcs_failure_cost: Some(52),
2283 hash_sha2_256_base_cost: Some(52),
2284 hash_sha2_256_per_byte_cost: Some(2),
2285 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2286 hash_sha3_256_base_cost: Some(52),
2287 hash_sha3_256_per_byte_cost: Some(2),
2288 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2289 type_name_get_base_cost: Some(52),
2290 type_name_get_per_byte_cost: Some(2),
2291 string_check_utf8_base_cost: Some(52),
2292 string_check_utf8_per_byte_cost: Some(2),
2293 string_is_char_boundary_base_cost: Some(52),
2294 string_sub_string_base_cost: Some(52),
2295 string_sub_string_per_byte_cost: Some(2),
2296 string_index_of_base_cost: Some(52),
2297 string_index_of_per_byte_pattern_cost: Some(2),
2298 string_index_of_per_byte_searched_cost: Some(2),
2299 vector_empty_base_cost: Some(52),
2300 vector_length_base_cost: Some(52),
2301 vector_push_back_base_cost: Some(52),
2302 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2303 vector_borrow_base_cost: Some(52),
2304 vector_pop_back_base_cost: Some(52),
2305 vector_destroy_empty_base_cost: Some(52),
2306 vector_swap_base_cost: Some(52),
2307 debug_print_base_cost: Some(52),
2308 debug_print_stack_trace_base_cost: Some(52),
2309
2310 max_size_written_objects: Some(5 * 1000 * 1000),
2311 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2314
2315 max_move_identifier_len: Some(128),
2317 max_move_value_depth: Some(128),
2318 max_move_enum_variants: None,
2319
2320 gas_rounding_step: Some(1_000),
2321
2322 execution_version: Some(1),
2323
2324 max_event_emit_size_total: Some(
2327 256 * 250 * 1024, ),
2329
2330 consensus_bad_nodes_stake_threshold: Some(20),
2337
2338 #[allow(deprecated)]
2340 max_jwk_votes_per_validator_per_epoch: Some(240),
2341
2342 #[allow(deprecated)]
2343 max_age_of_jwk_in_epochs: Some(1),
2344
2345 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2349
2350 random_beacon_reduction_allowed_delta: Some(800),
2351
2352 random_beacon_reduction_lower_bound: Some(1000),
2353 random_beacon_dkg_timeout_round: Some(3000),
2354 random_beacon_min_round_interval_ms: Some(500),
2355
2356 random_beacon_dkg_version: Some(1),
2357
2358 consensus_max_num_transactions_in_block: Some(512),
2362
2363 max_deferral_rounds_for_congestion_control: Some(10),
2364
2365 min_checkpoint_interval_ms: Some(200),
2366
2367 checkpoint_summary_version_specific_data: Some(1),
2368
2369 max_soft_bundle_size: Some(5),
2370
2371 bridge_should_try_to_finalize_committee: None,
2372
2373 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2374
2375 max_committee_members_count: None,
2376
2377 consensus_gc_depth: None,
2378
2379 consensus_max_acknowledgments_per_block: None,
2380
2381 max_congestion_limit_overshoot_per_commit: None,
2382
2383 scorer_version: None,
2384
2385 auth_context_digest_cost_base: None,
2387 auth_context_tx_data_bytes_cost_base: None,
2388 auth_context_tx_data_bytes_cost_per_byte: None,
2389 auth_context_tx_commands_cost_base: None,
2390 auth_context_tx_commands_cost_per_byte: None,
2391 auth_context_tx_inputs_cost_base: None,
2392 auth_context_tx_inputs_cost_per_byte: None,
2393 auth_context_replace_cost_base: None,
2394 auth_context_replace_cost_per_byte: None,
2395 auth_context_authenticator_function_info_v1_cost_base: None,
2396 };
2399
2400 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2401
2402 {
2404 cfg.feature_flags
2405 .disable_invariant_violation_check_in_swap_loc = true;
2406 cfg.feature_flags.no_extraneous_module_bytes = true;
2407 cfg.feature_flags.hardened_otw_check = true;
2408 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2409 }
2410
2411 {
2413 #[allow(deprecated)]
2414 {
2415 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2416 }
2417 }
2418
2419 #[expect(deprecated)]
2423 {
2424 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2425 }
2426 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2428
2429 cfg.feature_flags.per_object_congestion_control_mode =
2430 PerObjectCongestionControlMode::TotalTxCount;
2431
2432 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2434
2435 if chain != Chain::Mainnet && chain != Chain::Testnet {
2437 cfg.feature_flags.enable_poseidon = true;
2438 cfg.poseidon_bn254_cost_base = Some(260);
2439 cfg.poseidon_bn254_cost_per_block = Some(10);
2440
2441 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2442
2443 cfg.feature_flags.enable_vdf = true;
2444 cfg.vdf_verify_vdf_cost = Some(1500);
2447 cfg.vdf_hash_to_input_cost = Some(100);
2448
2449 cfg.feature_flags.passkey_auth = true;
2450 }
2451
2452 for cur in 2..=version.0 {
2453 match cur {
2454 1 => unreachable!(),
2455 2 => {}
2457 3 => {
2458 cfg.feature_flags.relocate_event_module = true;
2459 }
2460 4 => {
2461 cfg.max_type_to_layout_nodes = Some(512);
2462 }
2463 5 => {
2464 cfg.feature_flags.protocol_defined_base_fee = true;
2465 cfg.base_gas_price = Some(1000);
2466
2467 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2468 cfg.feature_flags.convert_type_argument_error = true;
2469 cfg.feature_flags.native_charging_v2 = true;
2470
2471 if chain != Chain::Mainnet && chain != Chain::Testnet {
2472 cfg.feature_flags.uncompressed_g1_group_elements = true;
2473 }
2474
2475 cfg.gas_model_version = Some(2);
2476
2477 cfg.poseidon_bn254_cost_per_block = Some(388);
2478
2479 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2480 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2481 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2482 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2483 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2484 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2485 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2486 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2487
2488 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2490 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2491 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2492 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2493
2494 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2495 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2496 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2497 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2498 Some(8213);
2499 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2500 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2501 Some(9484);
2502
2503 cfg.hash_keccak256_cost_base = Some(10);
2504 cfg.hash_blake2b256_cost_base = Some(10);
2505
2506 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2508 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2509 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2510 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2511
2512 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2513 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2514 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2515 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2516
2517 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2518 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2519 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2520 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2521
2522 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2523 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2524 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2525 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2526
2527 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2528 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2529 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2530 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2531
2532 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2533 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2534
2535 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2536 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2537 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2538 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2539
2540 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2541 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2542 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2543 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2544 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2545
2546 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2547
2548 cfg.validator_validate_metadata_cost_base = Some(20000);
2549
2550 cfg.max_committee_members_count = Some(50);
2551 }
2552 6 => {
2553 cfg.max_ptb_value_size = Some(1024 * 1024);
2554 }
2555 7 => {
2556 }
2559 8 => {
2560 cfg.feature_flags.variant_nodes = true;
2561
2562 if chain != Chain::Mainnet {
2563 cfg.feature_flags.consensus_round_prober = true;
2565 cfg.feature_flags
2567 .consensus_distributed_vote_scoring_strategy = true;
2568 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2569 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2571 cfg.feature_flags
2573 .consensus_round_prober_probe_accepted_rounds = true;
2574 cfg.feature_flags.consensus_zstd_compression = true;
2576 cfg.consensus_gc_depth = Some(60);
2580 }
2581
2582 if chain != Chain::Testnet && chain != Chain::Mainnet {
2585 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2586 }
2587 }
2588 9 => {
2589 if chain != Chain::Mainnet {
2590 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2592 }
2593
2594 cfg.feature_flags.consensus_zstd_compression = true;
2596
2597 if chain != Chain::Testnet && chain != Chain::Mainnet {
2599 cfg.feature_flags.accept_passkey_in_multisig = true;
2600 }
2601
2602 cfg.bridge_should_try_to_finalize_committee = None;
2604 }
2605 10 => {
2606 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2609
2610 cfg.max_committee_members_count = Some(80);
2612
2613 cfg.feature_flags.consensus_round_prober = true;
2615 cfg.feature_flags
2617 .consensus_round_prober_probe_accepted_rounds = true;
2618 cfg.feature_flags
2620 .consensus_distributed_vote_scoring_strategy = true;
2621 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2623
2624 cfg.consensus_gc_depth = Some(60);
2629
2630 cfg.feature_flags.minimize_child_object_mutations = true;
2632
2633 if chain != Chain::Mainnet {
2634 cfg.feature_flags.consensus_batched_block_sync = true;
2636 }
2637
2638 if chain != Chain::Testnet && chain != Chain::Mainnet {
2639 cfg.feature_flags
2642 .congestion_control_gas_price_feedback_mechanism = true;
2643 }
2644
2645 cfg.feature_flags.validate_identifier_inputs = true;
2646 cfg.feature_flags.dependency_linkage_error = true;
2647 cfg.feature_flags.additional_multisig_checks = true;
2648 }
2649 11 => {
2650 }
2653 12 => {
2654 cfg.feature_flags
2657 .congestion_control_gas_price_feedback_mechanism = true;
2658
2659 cfg.feature_flags.normalize_ptb_arguments = true;
2661 }
2662 13 => {
2663 cfg.feature_flags.select_committee_from_eligible_validators = true;
2666 cfg.feature_flags.track_non_committee_eligible_validators = true;
2669
2670 if chain != Chain::Testnet && chain != Chain::Mainnet {
2671 cfg.feature_flags
2674 .select_committee_supporting_next_epoch_version = true;
2675 }
2676 }
2677 14 => {
2678 cfg.feature_flags.consensus_batched_block_sync = true;
2680
2681 if chain != Chain::Mainnet {
2682 cfg.feature_flags
2685 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2686 cfg.feature_flags
2690 .select_committee_supporting_next_epoch_version = true;
2691 }
2692 if chain != Chain::Testnet && chain != Chain::Mainnet {
2693 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2695 }
2696 }
2697 15 => {
2698 if chain != Chain::Mainnet && chain != Chain::Testnet {
2699 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2703 }
2704 }
2705 16 => {
2706 cfg.feature_flags
2709 .select_committee_supporting_next_epoch_version = true;
2710 cfg.feature_flags
2712 .consensus_commit_transactions_only_for_traversed_headers = true;
2713 }
2714 17 => {
2715 cfg.max_committee_members_count = Some(100);
2717 }
2718 18 => {
2719 if chain != Chain::Mainnet {
2720 cfg.feature_flags.passkey_auth = true;
2722 }
2723 }
2724 19 => {
2725 if chain != Chain::Testnet && chain != Chain::Mainnet {
2726 cfg.feature_flags
2729 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2730 cfg.feature_flags
2733 .separate_gas_price_feedback_mechanism_for_randomness = true;
2734 cfg.feature_flags.metadata_in_module_bytes = true;
2737 cfg.feature_flags.publish_package_metadata = true;
2738 cfg.feature_flags.enable_move_authentication = true;
2740 cfg.max_auth_gas = Some(250_000_000);
2742 cfg.transfer_receive_object_cost_base = Some(100);
2745 cfg.feature_flags.adjust_rewards_by_score = true;
2747 }
2748
2749 if chain != Chain::Mainnet {
2750 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2752
2753 cfg.feature_flags.calculate_validator_scores = true;
2755 cfg.scorer_version = Some(1);
2756 }
2757
2758 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
2760
2761 cfg.feature_flags.passkey_auth = true;
2763 }
2764 20 => {
2765 if chain != Chain::Testnet && chain != Chain::Mainnet {
2766 cfg.feature_flags
2768 .pass_calculated_validator_scores_to_advance_epoch = true;
2769 }
2770 }
2771 21 => {
2772 if chain != Chain::Testnet && chain != Chain::Mainnet {
2773 cfg.feature_flags.consensus_fast_commit_sync = true;
2775 }
2776 if chain != Chain::Mainnet {
2777 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2782 cfg.feature_flags
2785 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2786 cfg.feature_flags
2789 .separate_gas_price_feedback_mechanism_for_randomness = true;
2790 }
2791
2792 cfg.auth_context_digest_cost_base = Some(30);
2793 cfg.auth_context_tx_commands_cost_base = Some(30);
2794 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
2795 cfg.auth_context_tx_inputs_cost_base = Some(30);
2796 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
2797 cfg.auth_context_replace_cost_base = Some(30);
2798 cfg.auth_context_replace_cost_per_byte = Some(2);
2799
2800 if chain != Chain::Testnet && chain != Chain::Mainnet {
2801 cfg.max_auth_gas = Some(250_000);
2803 }
2804 }
2805 22 => {
2806 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2811 cfg.feature_flags
2814 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2815 cfg.feature_flags
2818 .separate_gas_price_feedback_mechanism_for_randomness = true;
2819
2820 if chain != Chain::Mainnet {
2821 cfg.feature_flags.metadata_in_module_bytes = true;
2824 cfg.feature_flags.publish_package_metadata = true;
2825 cfg.feature_flags.enable_move_authentication = true;
2827 cfg.max_auth_gas = Some(250_000);
2829 cfg.transfer_receive_object_cost_base = Some(100);
2832 }
2833
2834 if chain != Chain::Mainnet {
2835 cfg.feature_flags.consensus_fast_commit_sync = true;
2837 }
2838 }
2839 23 => {
2840 cfg.feature_flags.move_native_tx_context = true;
2842 cfg.tx_context_fresh_id_cost_base = Some(52);
2843 cfg.tx_context_sender_cost_base = Some(30);
2844 cfg.tx_context_digest_cost_base = Some(30);
2845 cfg.tx_context_epoch_cost_base = Some(30);
2846 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
2847 cfg.tx_context_sponsor_cost_base = Some(30);
2848 cfg.tx_context_rgp_cost_base = Some(30);
2849 cfg.tx_context_gas_price_cost_base = Some(30);
2850 cfg.tx_context_gas_budget_cost_base = Some(30);
2851 cfg.tx_context_ids_created_cost_base = Some(30);
2852 cfg.tx_context_replace_cost_base = Some(30);
2853 }
2854 24 => {
2855 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2857
2858 if chain != Chain::Testnet && chain != Chain::Mainnet {
2859 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2861 }
2862
2863 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
2866 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
2867
2868 cfg.feature_flags.additional_borrow_checks = true;
2870 }
2871 #[allow(deprecated)]
2872 25 => {
2873 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
2876 cfg.check_zklogin_id_cost_base = None;
2877 cfg.check_zklogin_issuer_cost_base = None;
2878 cfg.max_jwk_votes_per_validator_per_epoch = None;
2879 cfg.max_age_of_jwk_in_epochs = None;
2880 }
2881 26 => {
2882 }
2885 27 => {
2886 if chain != Chain::Mainnet {
2887 cfg.feature_flags.consensus_block_restrictions = true;
2890 }
2891
2892 if chain != Chain::Testnet && chain != Chain::Mainnet {
2893 cfg.feature_flags
2895 .pre_consensus_sponsor_only_move_authentication = true;
2896 }
2897 }
2898 28 => {
2899 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
2904
2905 cfg.feature_flags.metadata_in_module_bytes = true;
2908 cfg.feature_flags.publish_package_metadata = true;
2909 cfg.feature_flags.enable_move_authentication = true;
2911 cfg.transfer_receive_object_cost_base = Some(100);
2914
2915 if chain != Chain::Unknown {
2916 cfg.max_auth_gas = Some(20_000);
2918 }
2919
2920 if chain != Chain::Mainnet {
2921 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2923 cfg.feature_flags
2925 .pre_consensus_sponsor_only_move_authentication = true;
2926 }
2927 }
2928 29 => {
2929 cfg.feature_flags.always_advance_dkg_to_resolution = true;
2935
2936 cfg.feature_flags
2939 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2940
2941 cfg.feature_flags.consensus_fast_commit_sync = true;
2943 cfg.feature_flags.consensus_block_restrictions = true;
2947 }
2948 30 => {
2949 }
2954 _ => panic!("unsupported version {version:?}"),
2965 }
2966 }
2967 cfg
2968 }
2969
2970 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
2976 let (
2977 max_back_edges_per_function,
2978 max_back_edges_per_module,
2979 sanity_check_with_regex_reference_safety,
2980 ) = if let Some((
2981 max_back_edges_per_function,
2982 max_back_edges_per_module,
2983 sanity_check_with_regex_reference_safety,
2984 )) = signing_limits
2985 {
2986 (
2987 Some(max_back_edges_per_function),
2988 Some(max_back_edges_per_module),
2989 Some(sanity_check_with_regex_reference_safety),
2990 )
2991 } else {
2992 (None, None, None)
2993 };
2994
2995 let additional_borrow_checks = if signing_limits.is_some() {
2996 true
2999 } else {
3000 self.additional_borrow_checks()
3001 };
3002
3003 VerifierConfig {
3004 max_loop_depth: Some(self.max_loop_depth() as usize),
3005 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
3006 max_function_parameters: Some(self.max_function_parameters() as usize),
3007 max_basic_blocks: Some(self.max_basic_blocks() as usize),
3008 max_value_stack_size: self.max_value_stack_size() as usize,
3009 max_type_nodes: Some(self.max_type_nodes() as usize),
3010 max_push_size: Some(self.max_push_size() as usize),
3011 max_dependency_depth: Some(self.max_dependency_depth() as usize),
3012 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
3013 max_function_definitions: Some(self.max_function_definitions() as usize),
3014 max_data_definitions: Some(self.max_struct_definitions() as usize),
3015 max_constant_vector_len: Some(self.max_move_vector_len()),
3016 max_back_edges_per_function,
3017 max_back_edges_per_module,
3018 max_basic_blocks_in_script: None,
3019 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
3023 max_variants_in_enum: self.max_move_enum_variants_as_option(),
3024 additional_borrow_checks,
3025 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
3026 .map(|limit| limit as u128),
3027 }
3028 }
3029
3030 pub fn apply_overrides_for_testing(
3035 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
3036 ) -> OverrideGuard {
3037 CONFIG_OVERRIDE.with(|ovr| {
3038 let mut cur = ovr.borrow_mut();
3039 assert!(cur.is_none(), "config override already present");
3040 *cur = Some(Box::new(override_fn));
3041 OverrideGuard
3042 })
3043 }
3044}
3045
3046impl ProtocolConfig {
3051 pub fn set_per_object_congestion_control_mode_for_testing(
3052 &mut self,
3053 val: PerObjectCongestionControlMode,
3054 ) {
3055 self.feature_flags.per_object_congestion_control_mode = val;
3056 }
3057
3058 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
3059 self.feature_flags.consensus_choice = val;
3060 }
3061
3062 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
3063 self.feature_flags.consensus_network = val;
3064 }
3065
3066 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
3067 self.feature_flags.passkey_auth = val
3068 }
3069
3070 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
3071 self.feature_flags
3072 .disallow_new_modules_in_deps_only_packages = val;
3073 }
3074
3075 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
3076 self.feature_flags.consensus_round_prober = val;
3077 }
3078
3079 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
3080 self.feature_flags
3081 .consensus_distributed_vote_scoring_strategy = val;
3082 }
3083
3084 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
3085 self.consensus_gc_depth = Some(val);
3086 }
3087
3088 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
3089 self.feature_flags.consensus_linearize_subdag_v2 = val;
3090 }
3091
3092 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
3093 self.feature_flags
3094 .consensus_round_prober_probe_accepted_rounds = val;
3095 }
3096
3097 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
3098 self.feature_flags.accept_passkey_in_multisig = val;
3099 }
3100
3101 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
3102 self.feature_flags.consensus_smart_ancestor_selection = val;
3103 }
3104
3105 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
3106 self.feature_flags.consensus_batched_block_sync = val;
3107 }
3108
3109 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
3110 self.feature_flags
3111 .congestion_control_min_free_execution_slot = val;
3112 }
3113
3114 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
3115 self.feature_flags
3116 .congestion_control_gas_price_feedback_mechanism = val;
3117 }
3118
3119 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
3120 self.feature_flags.select_committee_from_eligible_validators = val;
3121 }
3122
3123 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
3124 self.feature_flags.track_non_committee_eligible_validators = val;
3125 }
3126
3127 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
3128 self.feature_flags
3129 .select_committee_supporting_next_epoch_version = val;
3130 }
3131
3132 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
3133 &mut self,
3134 val: bool,
3135 ) {
3136 self.feature_flags
3137 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3138 }
3139
3140 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3141 &mut self,
3142 val: bool,
3143 ) {
3144 self.feature_flags
3145 .consensus_commit_transactions_only_for_traversed_headers = val;
3146 }
3147
3148 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3149 &mut self,
3150 val: bool,
3151 ) {
3152 self.feature_flags
3153 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3154 }
3155
3156 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3157 &mut self,
3158 val: bool,
3159 ) {
3160 self.feature_flags
3161 .separate_gas_price_feedback_mechanism_for_randomness = val;
3162 }
3163
3164 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3165 self.feature_flags.metadata_in_module_bytes = val;
3166 }
3167
3168 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3169 self.feature_flags.publish_package_metadata = val;
3170 }
3171
3172 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3173 self.feature_flags.enable_move_authentication = val;
3174 }
3175
3176 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3177 self.feature_flags.enable_move_authentication_for_sponsor = val;
3178 }
3179
3180 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3181 self.feature_flags.consensus_fast_commit_sync = val;
3182 }
3183
3184 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3185 self.feature_flags.consensus_block_restrictions = val;
3186 }
3187
3188 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3189 self.feature_flags
3190 .pre_consensus_sponsor_only_move_authentication = val;
3191 }
3192
3193 pub fn set_consensus_starfish_speed_for_testing(&mut self, val: bool) {
3194 self.feature_flags.consensus_starfish_speed = val;
3195 }
3196
3197 pub fn set_always_advance_dkg_to_resolution_for_testing(&mut self, val: bool) {
3198 self.feature_flags.always_advance_dkg_to_resolution = val;
3199 }
3200
3201 pub fn set_enable_pcool_flow_for_testing(&mut self, val: bool) {
3202 self.feature_flags.enable_pcool_flow = val;
3203 }
3204}
3205
3206type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
3207
3208thread_local! {
3209 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
3210}
3211
3212#[must_use]
3213pub struct OverrideGuard;
3214
3215impl Drop for OverrideGuard {
3216 fn drop(&mut self) {
3217 info!("restoring override fn");
3218 CONFIG_OVERRIDE.with(|ovr| {
3219 *ovr.borrow_mut() = None;
3220 });
3221 }
3222}
3223
3224#[derive(PartialEq, Eq)]
3228pub enum LimitThresholdCrossed {
3229 None,
3230 Soft(u128, u128),
3231 Hard(u128, u128),
3232}
3233
3234pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
3237 x: T,
3238 soft_limit: U,
3239 hard_limit: V,
3240) -> LimitThresholdCrossed {
3241 let x: V = x.into();
3242 let soft_limit: V = soft_limit.into();
3243
3244 debug_assert!(soft_limit <= hard_limit);
3245
3246 if x >= hard_limit {
3249 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
3250 } else if x < soft_limit {
3251 LimitThresholdCrossed::None
3252 } else {
3253 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
3254 }
3255}
3256
3257#[macro_export]
3258macro_rules! check_limit {
3259 ($x:expr, $hard:expr) => {
3260 check_limit!($x, $hard, $hard)
3261 };
3262 ($x:expr, $soft:expr, $hard:expr) => {
3263 check_limit_in_range($x as u64, $soft, $hard)
3264 };
3265}
3266
3267#[macro_export]
3271macro_rules! check_limit_by_meter {
3272 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
3273 let (h, metered_str) = if $is_metered {
3275 ($metered_limit, "metered")
3276 } else {
3277 ($unmetered_hard_limit, "unmetered")
3279 };
3280 use iota_protocol_config::check_limit_in_range;
3281 let result = check_limit_in_range($x as u64, $metered_limit, h);
3282 match result {
3283 LimitThresholdCrossed::None => {}
3284 LimitThresholdCrossed::Soft(_, _) => {
3285 $metric.with_label_values(&[metered_str, "soft"]).inc();
3286 }
3287 LimitThresholdCrossed::Hard(_, _) => {
3288 $metric.with_label_values(&[metered_str, "hard"]).inc();
3289 }
3290 };
3291 result
3292 }};
3293}
3294
3295#[cfg(all(test, not(msim)))]
3296mod test {
3297 use insta::assert_yaml_snapshot;
3298
3299 use super::*;
3300
3301 #[test]
3302 fn snapshot_tests() {
3303 println!("\n============================================================================");
3304 println!("! !");
3305 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
3306 println!("! !");
3307 println!("============================================================================\n");
3308 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
3309 let chain_str = match chain_id {
3314 Chain::Unknown => "".to_string(),
3315 _ => format!("{chain_id:?}_"),
3316 };
3317 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
3318 let cur = ProtocolVersion::new(i);
3319 assert_yaml_snapshot!(
3320 format!("{}version_{}", chain_str, cur.as_u64()),
3321 ProtocolConfig::get_for_version(cur, *chain_id)
3322 );
3323 }
3324 }
3325 }
3326
3327 #[test]
3328 fn test_getters() {
3329 let prot: ProtocolConfig =
3330 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3331 assert_eq!(
3332 prot.max_arguments(),
3333 prot.max_arguments_as_option().unwrap()
3334 );
3335 }
3336
3337 #[test]
3338 fn test_setters() {
3339 let mut prot: ProtocolConfig =
3340 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3341 prot.set_max_arguments_for_testing(123);
3342 assert_eq!(prot.max_arguments(), 123);
3343
3344 prot.set_max_arguments_from_str_for_testing("321".to_string());
3345 assert_eq!(prot.max_arguments(), 321);
3346
3347 prot.disable_max_arguments_for_testing();
3348 assert_eq!(prot.max_arguments_as_option(), None);
3349
3350 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
3351 assert_eq!(prot.max_arguments(), 456);
3352 }
3353
3354 #[test]
3355 #[should_panic(expected = "unsupported version")]
3356 fn max_version_test() {
3357 let _ = ProtocolConfig::get_for_version_impl(
3360 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
3361 Chain::Unknown,
3362 );
3363 }
3364
3365 #[test]
3366 fn lookup_by_string_test() {
3367 let prot: ProtocolConfig =
3368 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3369 assert!(prot.lookup_attr("some random string".to_string()).is_none());
3371
3372 assert!(
3373 prot.lookup_attr("max_arguments".to_string())
3374 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
3375 );
3376
3377 assert!(
3379 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3380 .is_none()
3381 );
3382 assert!(
3383 prot.attr_map()
3384 .get("poseidon_bn254_cost_base")
3385 .unwrap()
3386 .is_none()
3387 );
3388
3389 let prot: ProtocolConfig =
3391 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3392
3393 assert!(
3394 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3395 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3396 );
3397 assert!(
3398 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
3399 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3400 );
3401
3402 let prot: ProtocolConfig =
3404 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3405 assert!(
3407 prot.feature_flags
3408 .lookup_attr("some random string".to_owned())
3409 .is_none()
3410 );
3411 assert!(
3412 !prot
3413 .feature_flags
3414 .attr_map()
3415 .contains_key("some random string")
3416 );
3417
3418 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
3420 assert!(
3421 prot.feature_flags
3422 .attr_map()
3423 .get("enable_poseidon")
3424 .unwrap()
3425 == &false
3426 );
3427 let prot: ProtocolConfig =
3428 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3429 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
3431 assert!(
3432 prot.feature_flags
3433 .attr_map()
3434 .get("enable_poseidon")
3435 .unwrap()
3436 == &true
3437 );
3438 }
3439
3440 #[test]
3441 fn limit_range_fn_test() {
3442 let low = 100u32;
3443 let high = 10000u64;
3444
3445 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
3446 assert!(matches!(
3447 check_limit!(255u16, low, high),
3448 LimitThresholdCrossed::Soft(255u128, 100)
3449 ));
3450 assert!(matches!(
3457 check_limit!(2550000u64, low, high),
3458 LimitThresholdCrossed::Hard(2550000, 10000)
3459 ));
3460
3461 assert!(matches!(
3462 check_limit!(2550000u64, high, high),
3463 LimitThresholdCrossed::Hard(2550000, 10000)
3464 ));
3465
3466 assert!(matches!(
3467 check_limit!(1u8, high),
3468 LimitThresholdCrossed::None
3469 ));
3470
3471 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
3472
3473 assert!(matches!(
3474 check_limit!(2550000u64, high),
3475 LimitThresholdCrossed::Hard(2550000, 10000)
3476 ));
3477 }
3478}