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 = 29;
23
24pub const PROTOCOL_VERSION_IIP8: u64 = 20;
26#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
164pub struct ProtocolVersion(u64);
165
166impl ProtocolVersion {
167 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
173
174 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
175
176 #[cfg(not(msim))]
177 const MAX_ALLOWED: Self = Self::MAX;
178
179 #[cfg(msim)]
182 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
183
184 pub fn new(v: u64) -> Self {
185 Self(v)
186 }
187
188 pub const fn as_u64(&self) -> u64 {
189 self.0
190 }
191
192 pub fn max() -> Self {
195 Self::MAX
196 }
197}
198
199impl From<u64> for ProtocolVersion {
200 fn from(v: u64) -> Self {
201 Self::new(v)
202 }
203}
204
205impl std::ops::Sub<u64> for ProtocolVersion {
206 type Output = Self;
207 fn sub(self, rhs: u64) -> Self::Output {
208 Self::new(self.0 - rhs)
209 }
210}
211
212impl std::ops::Add<u64> for ProtocolVersion {
213 type Output = Self;
214 fn add(self, rhs: u64) -> Self::Output {
215 Self::new(self.0 + rhs)
216 }
217}
218
219#[derive(
220 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
221)]
222pub enum Chain {
223 Mainnet,
224 Testnet,
225 #[default]
226 Unknown,
227}
228
229impl Chain {
230 pub fn as_str(self) -> &'static str {
231 match self {
232 Chain::Mainnet => "mainnet",
233 Chain::Testnet => "testnet",
234 Chain::Unknown => "unknown",
235 }
236 }
237}
238
239pub struct Error(pub String);
240
241#[derive(
245 Default,
246 Clone,
247 Serialize,
248 Deserialize,
249 Debug,
250 ProtocolConfigFeatureFlagsGetters,
251 ProtocolConfigOverride,
252)]
253struct FeatureFlags {
254 #[serde(skip_serializing_if = "is_true")]
260 disable_invariant_violation_check_in_swap_loc: bool,
261
262 #[serde(skip_serializing_if = "is_true")]
265 no_extraneous_module_bytes: bool,
266
267 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
269 consensus_transaction_ordering: ConsensusTransactionOrdering,
270
271 #[serde(skip_serializing_if = "is_true")]
274 hardened_otw_check: bool,
275
276 #[serde(skip_serializing_if = "is_false")]
278 enable_poseidon: bool,
279
280 #[serde(skip_serializing_if = "is_false")]
282 enable_group_ops_native_function_msm: bool,
283
284 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
286 per_object_congestion_control_mode: PerObjectCongestionControlMode,
287
288 #[serde(
290 default = "ConsensusChoice::mysticeti_deprecated",
291 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
292 )]
293 consensus_choice: ConsensusChoice,
294
295 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
297 consensus_network: ConsensusNetwork,
298
299 #[deprecated]
301 #[serde(skip_serializing_if = "Option::is_none")]
302 zklogin_max_epoch_upper_bound_delta: Option<u64>,
303
304 #[serde(skip_serializing_if = "is_false")]
306 enable_vdf: bool,
307
308 #[serde(skip_serializing_if = "is_false")]
310 passkey_auth: bool,
311
312 #[serde(skip_serializing_if = "is_true")]
315 rethrow_serialization_type_layout_errors: bool,
316
317 #[serde(skip_serializing_if = "is_false")]
319 relocate_event_module: bool,
320
321 #[serde(skip_serializing_if = "is_false")]
323 protocol_defined_base_fee: bool,
324
325 #[serde(skip_serializing_if = "is_false")]
327 uncompressed_g1_group_elements: bool,
328
329 #[serde(skip_serializing_if = "is_false")]
331 disallow_new_modules_in_deps_only_packages: bool,
332
333 #[serde(skip_serializing_if = "is_false")]
335 native_charging_v2: bool,
336
337 #[serde(skip_serializing_if = "is_false")]
339 convert_type_argument_error: bool,
340
341 #[serde(skip_serializing_if = "is_false")]
343 consensus_round_prober: bool,
344
345 #[serde(skip_serializing_if = "is_false")]
347 consensus_distributed_vote_scoring_strategy: bool,
348
349 #[serde(skip_serializing_if = "is_false")]
353 consensus_linearize_subdag_v2: bool,
354
355 #[serde(skip_serializing_if = "is_false")]
357 variant_nodes: bool,
358
359 #[serde(skip_serializing_if = "is_false")]
361 consensus_smart_ancestor_selection: bool,
362
363 #[serde(skip_serializing_if = "is_false")]
365 consensus_round_prober_probe_accepted_rounds: bool,
366
367 #[serde(skip_serializing_if = "is_false")]
369 consensus_zstd_compression: bool,
370
371 #[serde(skip_serializing_if = "is_false")]
374 congestion_control_min_free_execution_slot: bool,
375
376 #[serde(skip_serializing_if = "is_false")]
378 accept_passkey_in_multisig: bool,
379
380 #[serde(skip_serializing_if = "is_false")]
382 consensus_batched_block_sync: bool,
383
384 #[serde(skip_serializing_if = "is_false")]
387 congestion_control_gas_price_feedback_mechanism: bool,
388
389 #[serde(skip_serializing_if = "is_false")]
391 validate_identifier_inputs: bool,
392
393 #[serde(skip_serializing_if = "is_false")]
396 minimize_child_object_mutations: bool,
397
398 #[serde(skip_serializing_if = "is_false")]
400 dependency_linkage_error: bool,
401
402 #[serde(skip_serializing_if = "is_false")]
404 additional_multisig_checks: bool,
405
406 #[serde(skip_serializing_if = "is_false")]
409 normalize_ptb_arguments: bool,
410
411 #[serde(skip_serializing_if = "is_false")]
415 select_committee_from_eligible_validators: bool,
416
417 #[serde(skip_serializing_if = "is_false")]
424 track_non_committee_eligible_validators: bool,
425
426 #[serde(skip_serializing_if = "is_false")]
432 select_committee_supporting_next_epoch_version: bool,
433
434 #[serde(skip_serializing_if = "is_false")]
438 consensus_median_timestamp_with_checkpoint_enforcement: bool,
439
440 #[serde(skip_serializing_if = "is_false")]
442 consensus_commit_transactions_only_for_traversed_headers: bool,
443
444 #[serde(skip_serializing_if = "is_false")]
446 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
447
448 #[serde(skip_serializing_if = "is_false")]
451 separate_gas_price_feedback_mechanism_for_randomness: bool,
452
453 #[serde(skip_serializing_if = "is_false")]
456 metadata_in_module_bytes: bool,
457
458 #[serde(skip_serializing_if = "is_false")]
460 publish_package_metadata: bool,
461
462 #[serde(skip_serializing_if = "is_false")]
464 enable_move_authentication: bool,
465
466 #[serde(skip_serializing_if = "is_false")]
468 enable_move_authentication_for_sponsor: bool,
469
470 #[serde(skip_serializing_if = "is_false")]
472 pass_validator_scores_to_advance_epoch: bool,
473
474 #[serde(skip_serializing_if = "is_false")]
476 calculate_validator_scores: bool,
477
478 #[serde(skip_serializing_if = "is_false")]
480 adjust_rewards_by_score: bool,
481
482 #[serde(skip_serializing_if = "is_false")]
485 pass_calculated_validator_scores_to_advance_epoch: bool,
486
487 #[serde(skip_serializing_if = "is_false")]
492 consensus_fast_commit_sync: bool,
493
494 #[serde(skip_serializing_if = "is_false")]
497 consensus_block_restrictions: bool,
498
499 #[serde(skip_serializing_if = "is_false")]
501 move_native_tx_context: bool,
502
503 #[serde(skip_serializing_if = "is_false")]
505 additional_borrow_checks: bool,
506
507 #[serde(skip_serializing_if = "is_false")]
509 pre_consensus_sponsor_only_move_authentication: bool,
510
511 #[serde(skip_serializing_if = "is_false")]
513 consensus_starfish_speed: bool,
514
515 #[serde(skip_serializing_if = "is_false")]
522 always_advance_dkg_to_resolution: bool,
523
524 #[serde(skip_serializing_if = "is_false")]
528 enable_white_flag_flow: bool,
529}
530
531fn is_true(b: &bool) -> bool {
532 *b
533}
534
535fn is_false(b: &bool) -> bool {
536 !b
537}
538
539#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
541pub enum ConsensusTransactionOrdering {
542 #[default]
545 None,
546 ByGasPrice,
548}
549
550impl ConsensusTransactionOrdering {
551 pub fn is_none(&self) -> bool {
552 matches!(self, ConsensusTransactionOrdering::None)
553 }
554}
555
556#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
558pub enum PerObjectCongestionControlMode {
559 #[default]
560 None, TotalGasBudget, TotalTxCount, }
564
565impl PerObjectCongestionControlMode {
566 pub fn is_none(&self) -> bool {
567 matches!(self, PerObjectCongestionControlMode::None)
568 }
569}
570
571#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
573pub enum ConsensusChoice {
574 #[deprecated(note = "Mysticeti was replaced by Starfish")]
577 MysticetiDeprecated,
578 #[default]
579 Starfish,
580}
581
582#[expect(deprecated)]
583impl ConsensusChoice {
584 fn mysticeti_deprecated() -> Self {
591 ConsensusChoice::MysticetiDeprecated
592 }
593
594 pub fn is_mysticeti_deprecated(&self) -> bool {
595 matches!(self, ConsensusChoice::MysticetiDeprecated)
596 }
597 pub fn is_starfish(&self) -> bool {
598 matches!(self, ConsensusChoice::Starfish)
599 }
600}
601
602#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
604pub enum ConsensusNetwork {
605 #[default]
606 Tonic,
607}
608
609impl ConsensusNetwork {
610 pub fn is_tonic(&self) -> bool {
611 matches!(self, ConsensusNetwork::Tonic)
612 }
613}
614
615#[skip_serializing_none]
649#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
650pub struct ProtocolConfig {
651 pub version: ProtocolVersion,
652
653 feature_flags: FeatureFlags,
654
655 max_tx_size_bytes: Option<u64>,
660
661 max_input_objects: Option<u64>,
664
665 max_size_written_objects: Option<u64>,
670 max_size_written_objects_system_tx: Option<u64>,
674
675 max_serialized_tx_effects_size_bytes: Option<u64>,
677
678 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
680
681 max_gas_payment_objects: Option<u32>,
683
684 max_modules_in_publish: Option<u32>,
686
687 max_package_dependencies: Option<u32>,
689
690 max_arguments: Option<u32>,
693
694 max_type_arguments: Option<u32>,
696
697 max_type_argument_depth: Option<u32>,
699
700 max_pure_argument_size: Option<u32>,
702
703 max_programmable_tx_commands: Option<u32>,
705
706 move_binary_format_version: Option<u32>,
712 min_move_binary_format_version: Option<u32>,
713
714 binary_module_handles: Option<u16>,
716 binary_struct_handles: Option<u16>,
717 binary_function_handles: Option<u16>,
718 binary_function_instantiations: Option<u16>,
719 binary_signatures: Option<u16>,
720 binary_constant_pool: Option<u16>,
721 binary_identifiers: Option<u16>,
722 binary_address_identifiers: Option<u16>,
723 binary_struct_defs: Option<u16>,
724 binary_struct_def_instantiations: Option<u16>,
725 binary_function_defs: Option<u16>,
726 binary_field_handles: Option<u16>,
727 binary_field_instantiations: Option<u16>,
728 binary_friend_decls: Option<u16>,
729 binary_enum_defs: Option<u16>,
730 binary_enum_def_instantiations: Option<u16>,
731 binary_variant_handles: Option<u16>,
732 binary_variant_instantiation_handles: Option<u16>,
733
734 max_move_object_size: Option<u64>,
737
738 max_move_package_size: Option<u64>,
743
744 max_publish_or_upgrade_per_ptb: Option<u64>,
747
748 max_tx_gas: Option<u64>,
750
751 max_auth_gas: Option<u64>,
753
754 max_gas_price: Option<u64>,
757
758 max_gas_computation_bucket: Option<u64>,
761
762 gas_rounding_step: Option<u64>,
764
765 max_loop_depth: Option<u64>,
767
768 max_generic_instantiation_length: Option<u64>,
771
772 max_function_parameters: Option<u64>,
775
776 max_basic_blocks: Option<u64>,
779
780 max_value_stack_size: Option<u64>,
782
783 max_type_nodes: Option<u64>,
787
788 max_push_size: Option<u64>,
791
792 max_struct_definitions: Option<u64>,
795
796 max_function_definitions: Option<u64>,
799
800 max_fields_in_struct: Option<u64>,
803
804 max_dependency_depth: Option<u64>,
807
808 max_num_event_emit: Option<u64>,
811
812 max_num_new_move_object_ids: Option<u64>,
815
816 max_num_new_move_object_ids_system_tx: Option<u64>,
819
820 max_num_deleted_move_object_ids: Option<u64>,
823
824 max_num_deleted_move_object_ids_system_tx: Option<u64>,
827
828 max_num_transferred_move_object_ids: Option<u64>,
831
832 max_num_transferred_move_object_ids_system_tx: Option<u64>,
835
836 max_event_emit_size: Option<u64>,
838
839 max_event_emit_size_total: Option<u64>,
841
842 max_move_vector_len: Option<u64>,
845
846 max_move_identifier_len: Option<u64>,
849
850 max_move_value_depth: Option<u64>,
852
853 max_move_enum_variants: Option<u64>,
856
857 max_back_edges_per_function: Option<u64>,
860
861 max_back_edges_per_module: Option<u64>,
864
865 max_verifier_meter_ticks_per_function: Option<u64>,
868
869 max_meter_ticks_per_module: Option<u64>,
872
873 max_meter_ticks_per_package: Option<u64>,
876
877 object_runtime_max_num_cached_objects: Option<u64>,
884
885 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
888
889 object_runtime_max_num_store_entries: Option<u64>,
892
893 object_runtime_max_num_store_entries_system_tx: Option<u64>,
896
897 base_tx_cost_fixed: Option<u64>,
902
903 package_publish_cost_fixed: Option<u64>,
907
908 base_tx_cost_per_byte: Option<u64>,
912
913 package_publish_cost_per_byte: Option<u64>,
915
916 obj_access_cost_read_per_byte: Option<u64>,
918
919 obj_access_cost_mutate_per_byte: Option<u64>,
921
922 obj_access_cost_delete_per_byte: Option<u64>,
924
925 obj_access_cost_verify_per_byte: Option<u64>,
935
936 max_type_to_layout_nodes: Option<u64>,
938
939 max_ptb_value_size: Option<u64>,
941
942 gas_model_version: Option<u64>,
947
948 obj_data_cost_refundable: Option<u64>,
954
955 obj_metadata_cost_non_refundable: Option<u64>,
959
960 storage_rebate_rate: Option<u64>,
966
967 reward_slashing_rate: Option<u64>,
970
971 storage_gas_price: Option<u64>,
973
974 base_gas_price: Option<u64>,
976
977 validator_target_reward: Option<u64>,
979
980 max_transactions_per_checkpoint: Option<u64>,
987
988 max_checkpoint_size_bytes: Option<u64>,
992
993 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
999
1000 address_from_bytes_cost_base: Option<u64>,
1005 address_to_u256_cost_base: Option<u64>,
1007 address_from_u256_cost_base: Option<u64>,
1009
1010 config_read_setting_impl_cost_base: Option<u64>,
1015 config_read_setting_impl_cost_per_byte: Option<u64>,
1016
1017 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
1021 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
1022 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
1023 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
1024 dynamic_field_add_child_object_cost_base: Option<u64>,
1027 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
1028 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
1029 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
1030 dynamic_field_borrow_child_object_cost_base: Option<u64>,
1033 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1034 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1035 dynamic_field_remove_child_object_cost_base: Option<u64>,
1038 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1039 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1040 dynamic_field_has_child_object_cost_base: Option<u64>,
1043 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1046 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1047 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1048
1049 event_emit_cost_base: Option<u64>,
1052 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1053 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1054 event_emit_output_cost_per_byte: Option<u64>,
1055
1056 object_borrow_uid_cost_base: Option<u64>,
1059 object_delete_impl_cost_base: Option<u64>,
1061 object_record_new_uid_cost_base: Option<u64>,
1063
1064 transfer_transfer_internal_cost_base: Option<u64>,
1067 transfer_freeze_object_cost_base: Option<u64>,
1069 transfer_share_object_cost_base: Option<u64>,
1071 transfer_receive_object_cost_base: Option<u64>,
1074
1075 tx_context_derive_id_cost_base: Option<u64>,
1078 tx_context_fresh_id_cost_base: Option<u64>,
1079 tx_context_sender_cost_base: Option<u64>,
1080 tx_context_digest_cost_base: Option<u64>,
1081 tx_context_epoch_cost_base: Option<u64>,
1082 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1083 tx_context_sponsor_cost_base: Option<u64>,
1084 tx_context_rgp_cost_base: Option<u64>,
1085 tx_context_gas_price_cost_base: Option<u64>,
1086 tx_context_gas_budget_cost_base: Option<u64>,
1087 tx_context_ids_created_cost_base: Option<u64>,
1088 tx_context_replace_cost_base: Option<u64>,
1089
1090 types_is_one_time_witness_cost_base: Option<u64>,
1093 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1094 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1095
1096 validator_validate_metadata_cost_base: Option<u64>,
1099 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1100
1101 crypto_invalid_arguments_cost: Option<u64>,
1103 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1105 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1106 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1107
1108 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1110 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1111 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1112
1113 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1115 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1116 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1117 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1118 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1119 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1120
1121 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1123
1124 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1126 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1127 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1128 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1129 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1130 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1131
1132 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1134 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1135 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1136 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1137 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1138 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1139
1140 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1142 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1143 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1144 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1145 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1146 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1147
1148 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1150 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1151 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1152
1153 ed25519_ed25519_verify_cost_base: Option<u64>,
1155 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1156 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1157
1158 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1160 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1161
1162 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1164 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1165 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1166 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1167 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1168
1169 hash_blake2b256_cost_base: Option<u64>,
1171 hash_blake2b256_data_cost_per_byte: Option<u64>,
1172 hash_blake2b256_data_cost_per_block: Option<u64>,
1173
1174 hash_keccak256_cost_base: Option<u64>,
1176 hash_keccak256_data_cost_per_byte: Option<u64>,
1177 hash_keccak256_data_cost_per_block: Option<u64>,
1178
1179 poseidon_bn254_cost_base: Option<u64>,
1181 poseidon_bn254_cost_per_block: Option<u64>,
1182
1183 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1185 group_ops_bls12381_decode_g1_cost: Option<u64>,
1186 group_ops_bls12381_decode_g2_cost: Option<u64>,
1187 group_ops_bls12381_decode_gt_cost: Option<u64>,
1188 group_ops_bls12381_scalar_add_cost: Option<u64>,
1189 group_ops_bls12381_g1_add_cost: Option<u64>,
1190 group_ops_bls12381_g2_add_cost: Option<u64>,
1191 group_ops_bls12381_gt_add_cost: Option<u64>,
1192 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1193 group_ops_bls12381_g1_sub_cost: Option<u64>,
1194 group_ops_bls12381_g2_sub_cost: Option<u64>,
1195 group_ops_bls12381_gt_sub_cost: Option<u64>,
1196 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1197 group_ops_bls12381_g1_mul_cost: Option<u64>,
1198 group_ops_bls12381_g2_mul_cost: Option<u64>,
1199 group_ops_bls12381_gt_mul_cost: Option<u64>,
1200 group_ops_bls12381_scalar_div_cost: Option<u64>,
1201 group_ops_bls12381_g1_div_cost: Option<u64>,
1202 group_ops_bls12381_g2_div_cost: Option<u64>,
1203 group_ops_bls12381_gt_div_cost: Option<u64>,
1204 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1205 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1206 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1207 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1208 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1209 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1210 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1211 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1212 group_ops_bls12381_msm_max_len: Option<u32>,
1213 group_ops_bls12381_pairing_cost: Option<u64>,
1214 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1215 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1216 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1217 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1218 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1219
1220 hmac_hmac_sha3_256_cost_base: Option<u64>,
1222 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1223 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1224
1225 #[deprecated]
1227 check_zklogin_id_cost_base: Option<u64>,
1228 #[deprecated]
1230 check_zklogin_issuer_cost_base: Option<u64>,
1231
1232 vdf_verify_vdf_cost: Option<u64>,
1233 vdf_hash_to_input_cost: Option<u64>,
1234
1235 bcs_per_byte_serialized_cost: Option<u64>,
1237 bcs_legacy_min_output_size_cost: Option<u64>,
1238 bcs_failure_cost: Option<u64>,
1239
1240 hash_sha2_256_base_cost: Option<u64>,
1241 hash_sha2_256_per_byte_cost: Option<u64>,
1242 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1243 hash_sha3_256_base_cost: Option<u64>,
1244 hash_sha3_256_per_byte_cost: Option<u64>,
1245 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1246 type_name_get_base_cost: Option<u64>,
1247 type_name_get_per_byte_cost: Option<u64>,
1248
1249 string_check_utf8_base_cost: Option<u64>,
1250 string_check_utf8_per_byte_cost: Option<u64>,
1251 string_is_char_boundary_base_cost: Option<u64>,
1252 string_sub_string_base_cost: Option<u64>,
1253 string_sub_string_per_byte_cost: Option<u64>,
1254 string_index_of_base_cost: Option<u64>,
1255 string_index_of_per_byte_pattern_cost: Option<u64>,
1256 string_index_of_per_byte_searched_cost: Option<u64>,
1257
1258 vector_empty_base_cost: Option<u64>,
1259 vector_length_base_cost: Option<u64>,
1260 vector_push_back_base_cost: Option<u64>,
1261 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1262 vector_borrow_base_cost: Option<u64>,
1263 vector_pop_back_base_cost: Option<u64>,
1264 vector_destroy_empty_base_cost: Option<u64>,
1265 vector_swap_base_cost: Option<u64>,
1266 debug_print_base_cost: Option<u64>,
1267 debug_print_stack_trace_base_cost: Option<u64>,
1268
1269 execution_version: Option<u64>,
1271
1272 consensus_bad_nodes_stake_threshold: Option<u64>,
1276
1277 #[deprecated]
1278 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1279 #[deprecated]
1283 max_age_of_jwk_in_epochs: Option<u64>,
1284
1285 random_beacon_reduction_allowed_delta: Option<u16>,
1289
1290 random_beacon_reduction_lower_bound: Option<u32>,
1293
1294 random_beacon_dkg_timeout_round: Option<u32>,
1297
1298 random_beacon_min_round_interval_ms: Option<u64>,
1300
1301 random_beacon_dkg_version: Option<u64>,
1305
1306 consensus_max_transaction_size_bytes: Option<u64>,
1311 consensus_max_transactions_in_block_bytes: Option<u64>,
1313 consensus_max_num_transactions_in_block: Option<u64>,
1315
1316 max_deferral_rounds_for_congestion_control: Option<u64>,
1320
1321 min_checkpoint_interval_ms: Option<u64>,
1323
1324 checkpoint_summary_version_specific_data: Option<u64>,
1326
1327 max_soft_bundle_size: Option<u64>,
1330
1331 bridge_should_try_to_finalize_committee: Option<bool>,
1336
1337 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1343
1344 max_committee_members_count: Option<u64>,
1348
1349 consensus_gc_depth: Option<u32>,
1352
1353 consensus_max_acknowledgments_per_block: Option<u32>,
1359
1360 max_congestion_limit_overshoot_per_commit: Option<u64>,
1365
1366 scorer_version: Option<u16>,
1375
1376 auth_context_digest_cost_base: Option<u64>,
1379 auth_context_tx_data_bytes_cost_base: Option<u64>,
1381 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1382 auth_context_tx_commands_cost_base: Option<u64>,
1384 auth_context_tx_commands_cost_per_byte: Option<u64>,
1385 auth_context_tx_inputs_cost_base: Option<u64>,
1387 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1388 auth_context_replace_cost_base: Option<u64>,
1391 auth_context_replace_cost_per_byte: Option<u64>,
1392 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1396}
1397
1398impl ProtocolConfig {
1400 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1413 self.feature_flags
1414 .disable_invariant_violation_check_in_swap_loc
1415 }
1416
1417 pub fn no_extraneous_module_bytes(&self) -> bool {
1418 self.feature_flags.no_extraneous_module_bytes
1419 }
1420
1421 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1422 self.feature_flags.consensus_transaction_ordering
1423 }
1424
1425 pub fn dkg_version(&self) -> u64 {
1426 self.random_beacon_dkg_version.unwrap_or(1)
1428 }
1429
1430 pub fn hardened_otw_check(&self) -> bool {
1431 self.feature_flags.hardened_otw_check
1432 }
1433
1434 pub fn enable_poseidon(&self) -> bool {
1435 self.feature_flags.enable_poseidon
1436 }
1437
1438 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1439 self.feature_flags.enable_group_ops_native_function_msm
1440 }
1441
1442 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1443 self.feature_flags.per_object_congestion_control_mode
1444 }
1445
1446 pub fn consensus_choice(&self) -> ConsensusChoice {
1447 self.feature_flags.consensus_choice
1448 }
1449
1450 pub fn consensus_network(&self) -> ConsensusNetwork {
1451 self.feature_flags.consensus_network
1452 }
1453
1454 pub fn enable_vdf(&self) -> bool {
1455 self.feature_flags.enable_vdf
1456 }
1457
1458 pub fn passkey_auth(&self) -> bool {
1459 self.feature_flags.passkey_auth
1460 }
1461
1462 pub fn max_transaction_size_bytes(&self) -> u64 {
1463 self.consensus_max_transaction_size_bytes
1465 .unwrap_or(256 * 1024)
1466 }
1467
1468 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1469 if cfg!(msim) {
1470 256 * 1024
1471 } else {
1472 self.consensus_max_transactions_in_block_bytes
1473 .unwrap_or(512 * 1024)
1474 }
1475 }
1476
1477 pub fn max_num_transactions_in_block(&self) -> u64 {
1478 if cfg!(msim) {
1479 8
1480 } else {
1481 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1482 }
1483 }
1484
1485 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1486 self.feature_flags.rethrow_serialization_type_layout_errors
1487 }
1488
1489 pub fn relocate_event_module(&self) -> bool {
1490 self.feature_flags.relocate_event_module
1491 }
1492
1493 pub fn protocol_defined_base_fee(&self) -> bool {
1494 self.feature_flags.protocol_defined_base_fee
1495 }
1496
1497 pub fn uncompressed_g1_group_elements(&self) -> bool {
1498 self.feature_flags.uncompressed_g1_group_elements
1499 }
1500
1501 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1502 self.feature_flags
1503 .disallow_new_modules_in_deps_only_packages
1504 }
1505
1506 pub fn native_charging_v2(&self) -> bool {
1507 self.feature_flags.native_charging_v2
1508 }
1509
1510 pub fn consensus_round_prober(&self) -> bool {
1511 self.feature_flags.consensus_round_prober
1512 }
1513
1514 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1515 self.feature_flags
1516 .consensus_distributed_vote_scoring_strategy
1517 }
1518
1519 pub fn gc_depth(&self) -> u32 {
1520 if cfg!(msim) {
1521 min(5, self.consensus_gc_depth.unwrap_or(0))
1523 } else {
1524 self.consensus_gc_depth.unwrap_or(0)
1525 }
1526 }
1527
1528 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1529 let res = self.feature_flags.consensus_linearize_subdag_v2;
1530 assert!(
1531 !res || self.gc_depth() > 0,
1532 "The consensus linearize sub dag V2 requires GC to be enabled"
1533 );
1534 res
1535 }
1536
1537 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1538 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1539 }
1540
1541 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1542 if self.consensus_block_restrictions() {
1543 2 * committee_size
1544 } else {
1545 self.consensus_max_acknowledgments_per_block_or_default() as usize
1546 }
1547 }
1548
1549 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1550 if self.consensus_block_restrictions() {
1551 committee_size
1552 } else {
1553 100
1554 }
1555 }
1556
1557 pub fn variant_nodes(&self) -> bool {
1558 self.feature_flags.variant_nodes
1559 }
1560
1561 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1562 self.feature_flags.consensus_smart_ancestor_selection
1563 }
1564
1565 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1566 self.feature_flags
1567 .consensus_round_prober_probe_accepted_rounds
1568 }
1569
1570 pub fn consensus_zstd_compression(&self) -> bool {
1571 self.feature_flags.consensus_zstd_compression
1572 }
1573
1574 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1575 self.feature_flags
1576 .congestion_control_min_free_execution_slot
1577 }
1578
1579 pub fn accept_passkey_in_multisig(&self) -> bool {
1580 self.feature_flags.accept_passkey_in_multisig
1581 }
1582
1583 pub fn consensus_batched_block_sync(&self) -> bool {
1584 self.feature_flags.consensus_batched_block_sync
1585 }
1586
1587 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1590 self.feature_flags
1591 .congestion_control_gas_price_feedback_mechanism
1592 }
1593
1594 pub fn validate_identifier_inputs(&self) -> bool {
1595 self.feature_flags.validate_identifier_inputs
1596 }
1597
1598 pub fn minimize_child_object_mutations(&self) -> bool {
1599 self.feature_flags.minimize_child_object_mutations
1600 }
1601
1602 pub fn dependency_linkage_error(&self) -> bool {
1603 self.feature_flags.dependency_linkage_error
1604 }
1605
1606 pub fn additional_multisig_checks(&self) -> bool {
1607 self.feature_flags.additional_multisig_checks
1608 }
1609
1610 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1611 0
1614 }
1615
1616 pub fn normalize_ptb_arguments(&self) -> bool {
1617 self.feature_flags.normalize_ptb_arguments
1618 }
1619
1620 pub fn select_committee_from_eligible_validators(&self) -> bool {
1621 let res = self.feature_flags.select_committee_from_eligible_validators;
1622 assert!(
1623 !res || (self.protocol_defined_base_fee()
1624 && self.max_committee_members_count_as_option().is_some()),
1625 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1626 );
1627 res
1628 }
1629
1630 pub fn track_non_committee_eligible_validators(&self) -> bool {
1631 self.feature_flags.track_non_committee_eligible_validators
1632 }
1633
1634 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1635 let res = self
1636 .feature_flags
1637 .select_committee_supporting_next_epoch_version;
1638 assert!(
1639 !res || (self.track_non_committee_eligible_validators()
1640 && self.select_committee_from_eligible_validators()),
1641 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1642 );
1643 res
1644 }
1645
1646 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1647 let res = self
1648 .feature_flags
1649 .consensus_median_timestamp_with_checkpoint_enforcement;
1650 assert!(
1651 !res || self.gc_depth() > 0,
1652 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1653 );
1654 res
1655 }
1656
1657 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1658 self.feature_flags
1659 .consensus_commit_transactions_only_for_traversed_headers
1660 }
1661
1662 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1665 self.feature_flags
1666 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1667 }
1668
1669 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1672 self.feature_flags
1673 .separate_gas_price_feedback_mechanism_for_randomness
1674 }
1675
1676 pub fn metadata_in_module_bytes(&self) -> bool {
1677 self.feature_flags.metadata_in_module_bytes
1678 }
1679
1680 pub fn publish_package_metadata(&self) -> bool {
1681 self.feature_flags.publish_package_metadata
1682 }
1683
1684 pub fn enable_move_authentication(&self) -> bool {
1685 self.feature_flags.enable_move_authentication
1686 }
1687
1688 pub fn additional_borrow_checks(&self) -> bool {
1689 self.feature_flags.additional_borrow_checks
1690 }
1691
1692 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1693 let enable_move_authentication_for_sponsor =
1694 self.feature_flags.enable_move_authentication_for_sponsor;
1695 assert!(
1696 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1697 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1698 );
1699 enable_move_authentication_for_sponsor
1700 }
1701
1702 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1703 self.feature_flags.pass_validator_scores_to_advance_epoch
1704 }
1705
1706 pub fn calculate_validator_scores(&self) -> bool {
1707 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1708 assert!(
1709 !calculate_validator_scores || self.scorer_version.is_some(),
1710 "calculate_validator_scores requires scorer_version to be set"
1711 );
1712 calculate_validator_scores
1713 }
1714
1715 pub fn adjust_rewards_by_score(&self) -> bool {
1716 let adjust = self.feature_flags.adjust_rewards_by_score;
1717 assert!(
1718 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1719 "adjust_rewards_by_score requires scorer_version to be set"
1720 );
1721 adjust
1722 }
1723
1724 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1725 let pass = self
1726 .feature_flags
1727 .pass_calculated_validator_scores_to_advance_epoch;
1728 assert!(
1729 !pass
1730 || (self.pass_validator_scores_to_advance_epoch()
1731 && self.calculate_validator_scores()),
1732 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
1733 );
1734 pass
1735 }
1736 pub fn consensus_fast_commit_sync(&self) -> bool {
1737 let res = self.feature_flags.consensus_fast_commit_sync;
1738 assert!(
1739 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
1740 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
1741 );
1742 res
1743 }
1744
1745 pub fn consensus_block_restrictions(&self) -> bool {
1746 self.feature_flags.consensus_block_restrictions
1747 }
1748
1749 pub fn move_native_tx_context(&self) -> bool {
1750 self.feature_flags.move_native_tx_context
1751 }
1752
1753 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
1754 let pre_consensus_sponsor_only_move_authentication = self
1755 .feature_flags
1756 .pre_consensus_sponsor_only_move_authentication;
1757 if pre_consensus_sponsor_only_move_authentication {
1758 assert!(
1759 self.enable_move_authentication(),
1760 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
1761 );
1762 assert!(
1763 self.enable_move_authentication_for_sponsor(),
1764 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
1765 );
1766 }
1767 pre_consensus_sponsor_only_move_authentication
1768 }
1769
1770 pub fn consensus_starfish_speed(&self) -> bool {
1771 let res = self.feature_flags.consensus_starfish_speed;
1772 assert!(
1773 !res || self.consensus_fast_commit_sync(),
1774 "consensus_starfish_speed requires consensus_fast_commit_sync to be enabled"
1775 );
1776 res
1777 }
1778
1779 pub fn always_advance_dkg_to_resolution(&self) -> bool {
1780 self.feature_flags.always_advance_dkg_to_resolution
1781 }
1782
1783 pub fn enable_white_flag_flow(&self) -> bool {
1784 self.feature_flags.enable_white_flag_flow
1785 }
1786}
1787
1788#[cfg(not(msim))]
1789static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1790
1791#[cfg(msim)]
1793thread_local! {
1794 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1795}
1796
1797impl ProtocolConfig {
1799 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1802 assert!(
1804 version >= ProtocolVersion::MIN,
1805 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1806 version,
1807 ProtocolVersion::MIN.0,
1808 );
1809 assert!(
1810 version <= ProtocolVersion::MAX_ALLOWED,
1811 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1812 version,
1813 ProtocolVersion::MAX_ALLOWED.0,
1814 );
1815
1816 let mut ret = Self::get_for_version_impl(version, chain);
1817 ret.version = version;
1818
1819 ret = CONFIG_OVERRIDE.with(|ovr| {
1820 if let Some(override_fn) = &*ovr.borrow() {
1821 warn!(
1822 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1823 );
1824 override_fn(version, ret)
1825 } else {
1826 ret
1827 }
1828 });
1829
1830 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1831 warn!(
1832 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1833 );
1834
1835 let overrides: ProtocolConfigOptional =
1837 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1838 .expect("failed to parse ProtocolConfig override env variables");
1839 overrides.apply_to(&mut ret);
1840
1841 let feature_flag_overrides: FeatureFlagsOptional =
1843 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_FEATURE_FLAGS_OVERRIDE")
1844 .expect("failed to parse ProtocolConfig feature flags override env variables");
1845
1846 feature_flag_overrides.apply_to(&mut ret.feature_flags);
1847 }
1848
1849 ret
1850 }
1851
1852 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1855 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1856 let mut ret = Self::get_for_version_impl(version, chain);
1857 ret.version = version;
1858 Some(ret)
1859 } else {
1860 None
1861 }
1862 }
1863
1864 #[cfg(not(msim))]
1865 pub fn poison_get_for_min_version() {
1866 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1867 }
1868
1869 #[cfg(not(msim))]
1870 fn load_poison_get_for_min_version() -> bool {
1871 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1872 }
1873
1874 #[cfg(msim)]
1875 pub fn poison_get_for_min_version() {
1876 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1877 }
1878
1879 #[cfg(msim)]
1880 fn load_poison_get_for_min_version() -> bool {
1881 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1882 }
1883
1884 pub fn convert_type_argument_error(&self) -> bool {
1885 self.feature_flags.convert_type_argument_error
1886 }
1887
1888 pub fn get_for_min_version() -> Self {
1892 if Self::load_poison_get_for_min_version() {
1893 panic!("get_for_min_version called on validator");
1894 }
1895 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1896 }
1897
1898 #[expect(non_snake_case)]
1909 pub fn get_for_max_version_UNSAFE() -> Self {
1910 if Self::load_poison_get_for_min_version() {
1911 panic!("get_for_max_version_UNSAFE called on validator");
1912 }
1913 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1914 }
1915
1916 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1917 #[cfg(msim)]
1918 {
1919 if version > ProtocolVersion::MAX {
1921 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1922 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1923 return config;
1924 }
1925 }
1926
1927 let mut cfg = Self {
1931 version,
1932
1933 feature_flags: Default::default(),
1934
1935 max_tx_size_bytes: Some(128 * 1024),
1936 max_input_objects: Some(2048),
1939 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1940 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1941 max_gas_payment_objects: Some(256),
1942 max_modules_in_publish: Some(64),
1943 max_package_dependencies: Some(32),
1944 max_arguments: Some(512),
1945 max_type_arguments: Some(16),
1946 max_type_argument_depth: Some(16),
1947 max_pure_argument_size: Some(16 * 1024),
1948 max_programmable_tx_commands: Some(1024),
1949 move_binary_format_version: Some(7),
1950 min_move_binary_format_version: Some(6),
1951 binary_module_handles: Some(100),
1952 binary_struct_handles: Some(300),
1953 binary_function_handles: Some(1500),
1954 binary_function_instantiations: Some(750),
1955 binary_signatures: Some(1000),
1956 binary_constant_pool: Some(4000),
1957 binary_identifiers: Some(10000),
1958 binary_address_identifiers: Some(100),
1959 binary_struct_defs: Some(200),
1960 binary_struct_def_instantiations: Some(100),
1961 binary_function_defs: Some(1000),
1962 binary_field_handles: Some(500),
1963 binary_field_instantiations: Some(250),
1964 binary_friend_decls: Some(100),
1965 binary_enum_defs: None,
1966 binary_enum_def_instantiations: None,
1967 binary_variant_handles: None,
1968 binary_variant_instantiation_handles: None,
1969 max_move_object_size: Some(250 * 1024),
1970 max_move_package_size: Some(100 * 1024),
1971 max_publish_or_upgrade_per_ptb: Some(5),
1972 max_auth_gas: None,
1974 max_tx_gas: Some(50_000_000_000),
1976 max_gas_price: Some(100_000),
1977 max_gas_computation_bucket: Some(5_000_000),
1978 max_loop_depth: Some(5),
1979 max_generic_instantiation_length: Some(32),
1980 max_function_parameters: Some(128),
1981 max_basic_blocks: Some(1024),
1982 max_value_stack_size: Some(1024),
1983 max_type_nodes: Some(256),
1984 max_push_size: Some(10000),
1985 max_struct_definitions: Some(200),
1986 max_function_definitions: Some(1000),
1987 max_fields_in_struct: Some(32),
1988 max_dependency_depth: Some(100),
1989 max_num_event_emit: Some(1024),
1990 max_num_new_move_object_ids: Some(2048),
1991 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1992 max_num_deleted_move_object_ids: Some(2048),
1993 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1994 max_num_transferred_move_object_ids: Some(2048),
1995 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1996 max_event_emit_size: Some(250 * 1024),
1997 max_move_vector_len: Some(256 * 1024),
1998 max_type_to_layout_nodes: None,
1999 max_ptb_value_size: None,
2000
2001 max_back_edges_per_function: Some(10_000),
2002 max_back_edges_per_module: Some(10_000),
2003
2004 max_verifier_meter_ticks_per_function: Some(16_000_000),
2005
2006 max_meter_ticks_per_module: Some(16_000_000),
2007 max_meter_ticks_per_package: Some(16_000_000),
2008
2009 object_runtime_max_num_cached_objects: Some(1000),
2010 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2011 object_runtime_max_num_store_entries: Some(1000),
2012 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2013 base_tx_cost_fixed: Some(1_000),
2015 package_publish_cost_fixed: Some(1_000),
2016 base_tx_cost_per_byte: Some(0),
2017 package_publish_cost_per_byte: Some(80),
2018 obj_access_cost_read_per_byte: Some(15),
2019 obj_access_cost_mutate_per_byte: Some(40),
2020 obj_access_cost_delete_per_byte: Some(40),
2021 obj_access_cost_verify_per_byte: Some(200),
2022 obj_data_cost_refundable: Some(100),
2023 obj_metadata_cost_non_refundable: Some(50),
2024 gas_model_version: Some(1),
2025 storage_rebate_rate: Some(10000),
2026 reward_slashing_rate: Some(10000),
2028 storage_gas_price: Some(76),
2029 base_gas_price: None,
2030 validator_target_reward: Some(767_000 * 1_000_000_000),
2033 max_transactions_per_checkpoint: Some(10_000),
2034 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2035
2036 buffer_stake_for_protocol_upgrade_bps: Some(5000),
2038
2039 address_from_bytes_cost_base: Some(52),
2043 address_to_u256_cost_base: Some(52),
2045 address_from_u256_cost_base: Some(52),
2047
2048 config_read_setting_impl_cost_base: Some(100),
2051 config_read_setting_impl_cost_per_byte: Some(40),
2052
2053 dynamic_field_hash_type_and_key_cost_base: Some(100),
2057 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
2058 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
2059 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
2060 dynamic_field_add_child_object_cost_base: Some(100),
2063 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2064 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2065 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2066 dynamic_field_borrow_child_object_cost_base: Some(100),
2069 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2070 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2071 dynamic_field_remove_child_object_cost_base: Some(100),
2074 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2075 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2076 dynamic_field_has_child_object_cost_base: Some(100),
2079 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2082 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2083 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2084
2085 event_emit_cost_base: Some(52),
2088 event_emit_value_size_derivation_cost_per_byte: Some(2),
2089 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2090 event_emit_output_cost_per_byte: Some(10),
2091
2092 object_borrow_uid_cost_base: Some(52),
2095 object_delete_impl_cost_base: Some(52),
2097 object_record_new_uid_cost_base: Some(52),
2099
2100 transfer_transfer_internal_cost_base: Some(52),
2104 transfer_freeze_object_cost_base: Some(52),
2106 transfer_share_object_cost_base: Some(52),
2108 transfer_receive_object_cost_base: Some(52),
2109
2110 tx_context_derive_id_cost_base: Some(52),
2114 tx_context_fresh_id_cost_base: None,
2115 tx_context_sender_cost_base: None,
2116 tx_context_digest_cost_base: None,
2117 tx_context_epoch_cost_base: None,
2118 tx_context_epoch_timestamp_ms_cost_base: None,
2119 tx_context_sponsor_cost_base: None,
2120 tx_context_rgp_cost_base: None,
2121 tx_context_gas_price_cost_base: None,
2122 tx_context_gas_budget_cost_base: None,
2123 tx_context_ids_created_cost_base: None,
2124 tx_context_replace_cost_base: None,
2125
2126 types_is_one_time_witness_cost_base: Some(52),
2129 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2130 types_is_one_time_witness_type_cost_per_byte: Some(2),
2131
2132 validator_validate_metadata_cost_base: Some(52),
2136 validator_validate_metadata_data_cost_per_byte: Some(2),
2137
2138 crypto_invalid_arguments_cost: Some(100),
2140 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2142 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2143 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2144
2145 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2147 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2148 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2149
2150 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2152 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2153 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2154 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2155 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2156 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2157
2158 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2160
2161 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2163 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2164 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2165 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2166 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2167 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2168
2169 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2171 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2172 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2173 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2174 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2175 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2176
2177 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2179 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2180 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2181 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2182 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2183 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2184
2185 ecvrf_ecvrf_verify_cost_base: Some(52),
2187 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2188 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2189
2190 ed25519_ed25519_verify_cost_base: Some(52),
2192 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2193 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2194
2195 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2197 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2198
2199 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2201 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2202 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2203 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2204 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2205
2206 hash_blake2b256_cost_base: Some(52),
2208 hash_blake2b256_data_cost_per_byte: Some(2),
2209 hash_blake2b256_data_cost_per_block: Some(2),
2210 hash_keccak256_cost_base: Some(52),
2212 hash_keccak256_data_cost_per_byte: Some(2),
2213 hash_keccak256_data_cost_per_block: Some(2),
2214
2215 poseidon_bn254_cost_base: None,
2216 poseidon_bn254_cost_per_block: None,
2217
2218 hmac_hmac_sha3_256_cost_base: Some(52),
2220 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2221 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2222
2223 group_ops_bls12381_decode_scalar_cost: Some(52),
2225 group_ops_bls12381_decode_g1_cost: Some(52),
2226 group_ops_bls12381_decode_g2_cost: Some(52),
2227 group_ops_bls12381_decode_gt_cost: Some(52),
2228 group_ops_bls12381_scalar_add_cost: Some(52),
2229 group_ops_bls12381_g1_add_cost: Some(52),
2230 group_ops_bls12381_g2_add_cost: Some(52),
2231 group_ops_bls12381_gt_add_cost: Some(52),
2232 group_ops_bls12381_scalar_sub_cost: Some(52),
2233 group_ops_bls12381_g1_sub_cost: Some(52),
2234 group_ops_bls12381_g2_sub_cost: Some(52),
2235 group_ops_bls12381_gt_sub_cost: Some(52),
2236 group_ops_bls12381_scalar_mul_cost: Some(52),
2237 group_ops_bls12381_g1_mul_cost: Some(52),
2238 group_ops_bls12381_g2_mul_cost: Some(52),
2239 group_ops_bls12381_gt_mul_cost: Some(52),
2240 group_ops_bls12381_scalar_div_cost: Some(52),
2241 group_ops_bls12381_g1_div_cost: Some(52),
2242 group_ops_bls12381_g2_div_cost: Some(52),
2243 group_ops_bls12381_gt_div_cost: Some(52),
2244 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2245 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2246 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2247 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2248 group_ops_bls12381_g1_msm_base_cost: Some(52),
2249 group_ops_bls12381_g2_msm_base_cost: Some(52),
2250 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2251 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2252 group_ops_bls12381_msm_max_len: Some(32),
2253 group_ops_bls12381_pairing_cost: Some(52),
2254 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2255 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2256 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2257 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2258 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2259
2260 #[allow(deprecated)]
2262 check_zklogin_id_cost_base: Some(200),
2263 #[allow(deprecated)]
2264 check_zklogin_issuer_cost_base: Some(200),
2266
2267 vdf_verify_vdf_cost: None,
2268 vdf_hash_to_input_cost: None,
2269
2270 bcs_per_byte_serialized_cost: Some(2),
2271 bcs_legacy_min_output_size_cost: Some(1),
2272 bcs_failure_cost: Some(52),
2273 hash_sha2_256_base_cost: Some(52),
2274 hash_sha2_256_per_byte_cost: Some(2),
2275 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2276 hash_sha3_256_base_cost: Some(52),
2277 hash_sha3_256_per_byte_cost: Some(2),
2278 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2279 type_name_get_base_cost: Some(52),
2280 type_name_get_per_byte_cost: Some(2),
2281 string_check_utf8_base_cost: Some(52),
2282 string_check_utf8_per_byte_cost: Some(2),
2283 string_is_char_boundary_base_cost: Some(52),
2284 string_sub_string_base_cost: Some(52),
2285 string_sub_string_per_byte_cost: Some(2),
2286 string_index_of_base_cost: Some(52),
2287 string_index_of_per_byte_pattern_cost: Some(2),
2288 string_index_of_per_byte_searched_cost: Some(2),
2289 vector_empty_base_cost: Some(52),
2290 vector_length_base_cost: Some(52),
2291 vector_push_back_base_cost: Some(52),
2292 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2293 vector_borrow_base_cost: Some(52),
2294 vector_pop_back_base_cost: Some(52),
2295 vector_destroy_empty_base_cost: Some(52),
2296 vector_swap_base_cost: Some(52),
2297 debug_print_base_cost: Some(52),
2298 debug_print_stack_trace_base_cost: Some(52),
2299
2300 max_size_written_objects: Some(5 * 1000 * 1000),
2301 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2304
2305 max_move_identifier_len: Some(128),
2307 max_move_value_depth: Some(128),
2308 max_move_enum_variants: None,
2309
2310 gas_rounding_step: Some(1_000),
2311
2312 execution_version: Some(1),
2313
2314 max_event_emit_size_total: Some(
2317 256 * 250 * 1024, ),
2319
2320 consensus_bad_nodes_stake_threshold: Some(20),
2327
2328 #[allow(deprecated)]
2330 max_jwk_votes_per_validator_per_epoch: Some(240),
2331
2332 #[allow(deprecated)]
2333 max_age_of_jwk_in_epochs: Some(1),
2334
2335 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2339
2340 random_beacon_reduction_allowed_delta: Some(800),
2341
2342 random_beacon_reduction_lower_bound: Some(1000),
2343 random_beacon_dkg_timeout_round: Some(3000),
2344 random_beacon_min_round_interval_ms: Some(500),
2345
2346 random_beacon_dkg_version: Some(1),
2347
2348 consensus_max_num_transactions_in_block: Some(512),
2352
2353 max_deferral_rounds_for_congestion_control: Some(10),
2354
2355 min_checkpoint_interval_ms: Some(200),
2356
2357 checkpoint_summary_version_specific_data: Some(1),
2358
2359 max_soft_bundle_size: Some(5),
2360
2361 bridge_should_try_to_finalize_committee: None,
2362
2363 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2364
2365 max_committee_members_count: None,
2366
2367 consensus_gc_depth: None,
2368
2369 consensus_max_acknowledgments_per_block: None,
2370
2371 max_congestion_limit_overshoot_per_commit: None,
2372
2373 scorer_version: None,
2374
2375 auth_context_digest_cost_base: None,
2377 auth_context_tx_data_bytes_cost_base: None,
2378 auth_context_tx_data_bytes_cost_per_byte: None,
2379 auth_context_tx_commands_cost_base: None,
2380 auth_context_tx_commands_cost_per_byte: None,
2381 auth_context_tx_inputs_cost_base: None,
2382 auth_context_tx_inputs_cost_per_byte: None,
2383 auth_context_replace_cost_base: None,
2384 auth_context_replace_cost_per_byte: None,
2385 auth_context_authenticator_function_info_v1_cost_base: None,
2386 };
2389
2390 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2391
2392 {
2394 cfg.feature_flags
2395 .disable_invariant_violation_check_in_swap_loc = true;
2396 cfg.feature_flags.no_extraneous_module_bytes = true;
2397 cfg.feature_flags.hardened_otw_check = true;
2398 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2399 }
2400
2401 {
2403 #[allow(deprecated)]
2404 {
2405 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2406 }
2407 }
2408
2409 #[expect(deprecated)]
2413 {
2414 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2415 }
2416 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2418
2419 cfg.feature_flags.per_object_congestion_control_mode =
2420 PerObjectCongestionControlMode::TotalTxCount;
2421
2422 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2424
2425 if chain != Chain::Mainnet && chain != Chain::Testnet {
2427 cfg.feature_flags.enable_poseidon = true;
2428 cfg.poseidon_bn254_cost_base = Some(260);
2429 cfg.poseidon_bn254_cost_per_block = Some(10);
2430
2431 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2432
2433 cfg.feature_flags.enable_vdf = true;
2434 cfg.vdf_verify_vdf_cost = Some(1500);
2437 cfg.vdf_hash_to_input_cost = Some(100);
2438
2439 cfg.feature_flags.passkey_auth = true;
2440 }
2441
2442 for cur in 2..=version.0 {
2443 match cur {
2444 1 => unreachable!(),
2445 2 => {}
2447 3 => {
2448 cfg.feature_flags.relocate_event_module = true;
2449 }
2450 4 => {
2451 cfg.max_type_to_layout_nodes = Some(512);
2452 }
2453 5 => {
2454 cfg.feature_flags.protocol_defined_base_fee = true;
2455 cfg.base_gas_price = Some(1000);
2456
2457 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2458 cfg.feature_flags.convert_type_argument_error = true;
2459 cfg.feature_flags.native_charging_v2 = true;
2460
2461 if chain != Chain::Mainnet && chain != Chain::Testnet {
2462 cfg.feature_flags.uncompressed_g1_group_elements = true;
2463 }
2464
2465 cfg.gas_model_version = Some(2);
2466
2467 cfg.poseidon_bn254_cost_per_block = Some(388);
2468
2469 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2470 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2471 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2472 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2473 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2474 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2475 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2476 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2477
2478 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2480 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2481 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2482 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2483
2484 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2485 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2486 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2487 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2488 Some(8213);
2489 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2490 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2491 Some(9484);
2492
2493 cfg.hash_keccak256_cost_base = Some(10);
2494 cfg.hash_blake2b256_cost_base = Some(10);
2495
2496 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2498 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2499 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2500 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2501
2502 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2503 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2504 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2505 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2506
2507 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2508 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2509 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2510 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2511
2512 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2513 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2514 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2515 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2516
2517 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2518 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2519 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2520 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2521
2522 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2523 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2524
2525 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2526 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2527 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2528 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2529
2530 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2531 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2532 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2533 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2534 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2535
2536 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2537
2538 cfg.validator_validate_metadata_cost_base = Some(20000);
2539
2540 cfg.max_committee_members_count = Some(50);
2541 }
2542 6 => {
2543 cfg.max_ptb_value_size = Some(1024 * 1024);
2544 }
2545 7 => {
2546 }
2549 8 => {
2550 cfg.feature_flags.variant_nodes = true;
2551
2552 if chain != Chain::Mainnet {
2553 cfg.feature_flags.consensus_round_prober = true;
2555 cfg.feature_flags
2557 .consensus_distributed_vote_scoring_strategy = true;
2558 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2559 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2561 cfg.feature_flags
2563 .consensus_round_prober_probe_accepted_rounds = true;
2564 cfg.feature_flags.consensus_zstd_compression = true;
2566 cfg.consensus_gc_depth = Some(60);
2570 }
2571
2572 if chain != Chain::Testnet && chain != Chain::Mainnet {
2575 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2576 }
2577 }
2578 9 => {
2579 if chain != Chain::Mainnet {
2580 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2582 }
2583
2584 cfg.feature_flags.consensus_zstd_compression = true;
2586
2587 if chain != Chain::Testnet && chain != Chain::Mainnet {
2589 cfg.feature_flags.accept_passkey_in_multisig = true;
2590 }
2591
2592 cfg.bridge_should_try_to_finalize_committee = None;
2594 }
2595 10 => {
2596 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2599
2600 cfg.max_committee_members_count = Some(80);
2602
2603 cfg.feature_flags.consensus_round_prober = true;
2605 cfg.feature_flags
2607 .consensus_round_prober_probe_accepted_rounds = true;
2608 cfg.feature_flags
2610 .consensus_distributed_vote_scoring_strategy = true;
2611 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2613
2614 cfg.consensus_gc_depth = Some(60);
2619
2620 cfg.feature_flags.minimize_child_object_mutations = true;
2622
2623 if chain != Chain::Mainnet {
2624 cfg.feature_flags.consensus_batched_block_sync = true;
2626 }
2627
2628 if chain != Chain::Testnet && chain != Chain::Mainnet {
2629 cfg.feature_flags
2632 .congestion_control_gas_price_feedback_mechanism = true;
2633 }
2634
2635 cfg.feature_flags.validate_identifier_inputs = true;
2636 cfg.feature_flags.dependency_linkage_error = true;
2637 cfg.feature_flags.additional_multisig_checks = true;
2638 }
2639 11 => {
2640 }
2643 12 => {
2644 cfg.feature_flags
2647 .congestion_control_gas_price_feedback_mechanism = true;
2648
2649 cfg.feature_flags.normalize_ptb_arguments = true;
2651 }
2652 13 => {
2653 cfg.feature_flags.select_committee_from_eligible_validators = true;
2656 cfg.feature_flags.track_non_committee_eligible_validators = true;
2659
2660 if chain != Chain::Testnet && chain != Chain::Mainnet {
2661 cfg.feature_flags
2664 .select_committee_supporting_next_epoch_version = true;
2665 }
2666 }
2667 14 => {
2668 cfg.feature_flags.consensus_batched_block_sync = true;
2670
2671 if chain != Chain::Mainnet {
2672 cfg.feature_flags
2675 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2676 cfg.feature_flags
2680 .select_committee_supporting_next_epoch_version = true;
2681 }
2682 if chain != Chain::Testnet && chain != Chain::Mainnet {
2683 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2685 }
2686 }
2687 15 => {
2688 if chain != Chain::Mainnet && chain != Chain::Testnet {
2689 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2693 }
2694 }
2695 16 => {
2696 cfg.feature_flags
2699 .select_committee_supporting_next_epoch_version = true;
2700 cfg.feature_flags
2702 .consensus_commit_transactions_only_for_traversed_headers = true;
2703 }
2704 17 => {
2705 cfg.max_committee_members_count = Some(100);
2707 }
2708 18 => {
2709 if chain != Chain::Mainnet {
2710 cfg.feature_flags.passkey_auth = true;
2712 }
2713 }
2714 19 => {
2715 if chain != Chain::Testnet && chain != Chain::Mainnet {
2716 cfg.feature_flags
2719 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2720 cfg.feature_flags
2723 .separate_gas_price_feedback_mechanism_for_randomness = true;
2724 cfg.feature_flags.metadata_in_module_bytes = true;
2727 cfg.feature_flags.publish_package_metadata = true;
2728 cfg.feature_flags.enable_move_authentication = true;
2730 cfg.max_auth_gas = Some(250_000_000);
2732 cfg.transfer_receive_object_cost_base = Some(100);
2735 cfg.feature_flags.adjust_rewards_by_score = true;
2737 }
2738
2739 if chain != Chain::Mainnet {
2740 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2742
2743 cfg.feature_flags.calculate_validator_scores = true;
2745 cfg.scorer_version = Some(1);
2746 }
2747
2748 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
2750
2751 cfg.feature_flags.passkey_auth = true;
2753 }
2754 20 => {
2755 if chain != Chain::Testnet && chain != Chain::Mainnet {
2756 cfg.feature_flags
2758 .pass_calculated_validator_scores_to_advance_epoch = true;
2759 }
2760 }
2761 21 => {
2762 if chain != Chain::Testnet && chain != Chain::Mainnet {
2763 cfg.feature_flags.consensus_fast_commit_sync = true;
2765 }
2766 if chain != Chain::Mainnet {
2767 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2772 cfg.feature_flags
2775 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2776 cfg.feature_flags
2779 .separate_gas_price_feedback_mechanism_for_randomness = true;
2780 }
2781
2782 cfg.auth_context_digest_cost_base = Some(30);
2783 cfg.auth_context_tx_commands_cost_base = Some(30);
2784 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
2785 cfg.auth_context_tx_inputs_cost_base = Some(30);
2786 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
2787 cfg.auth_context_replace_cost_base = Some(30);
2788 cfg.auth_context_replace_cost_per_byte = Some(2);
2789
2790 if chain != Chain::Testnet && chain != Chain::Mainnet {
2791 cfg.max_auth_gas = Some(250_000);
2793 }
2794 }
2795 22 => {
2796 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2801 cfg.feature_flags
2804 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2805 cfg.feature_flags
2808 .separate_gas_price_feedback_mechanism_for_randomness = true;
2809
2810 if chain != Chain::Mainnet {
2811 cfg.feature_flags.metadata_in_module_bytes = true;
2814 cfg.feature_flags.publish_package_metadata = true;
2815 cfg.feature_flags.enable_move_authentication = true;
2817 cfg.max_auth_gas = Some(250_000);
2819 cfg.transfer_receive_object_cost_base = Some(100);
2822 }
2823
2824 if chain != Chain::Mainnet {
2825 cfg.feature_flags.consensus_fast_commit_sync = true;
2827 }
2828 }
2829 23 => {
2830 cfg.feature_flags.move_native_tx_context = true;
2832 cfg.tx_context_fresh_id_cost_base = Some(52);
2833 cfg.tx_context_sender_cost_base = Some(30);
2834 cfg.tx_context_digest_cost_base = Some(30);
2835 cfg.tx_context_epoch_cost_base = Some(30);
2836 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
2837 cfg.tx_context_sponsor_cost_base = Some(30);
2838 cfg.tx_context_rgp_cost_base = Some(30);
2839 cfg.tx_context_gas_price_cost_base = Some(30);
2840 cfg.tx_context_gas_budget_cost_base = Some(30);
2841 cfg.tx_context_ids_created_cost_base = Some(30);
2842 cfg.tx_context_replace_cost_base = Some(30);
2843 }
2844 24 => {
2845 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2847
2848 if chain != Chain::Testnet && chain != Chain::Mainnet {
2849 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2851 }
2852
2853 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
2856 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
2857
2858 cfg.feature_flags.additional_borrow_checks = true;
2860 }
2861 #[allow(deprecated)]
2862 25 => {
2863 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
2866 cfg.check_zklogin_id_cost_base = None;
2867 cfg.check_zklogin_issuer_cost_base = None;
2868 cfg.max_jwk_votes_per_validator_per_epoch = None;
2869 cfg.max_age_of_jwk_in_epochs = None;
2870 }
2871 26 => {
2872 }
2875 27 => {
2876 if chain != Chain::Mainnet {
2877 cfg.feature_flags.consensus_block_restrictions = true;
2880 }
2881
2882 if chain != Chain::Testnet && chain != Chain::Mainnet {
2883 cfg.feature_flags
2885 .pre_consensus_sponsor_only_move_authentication = true;
2886 }
2887 }
2888 28 => {
2889 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
2894
2895 cfg.feature_flags.metadata_in_module_bytes = true;
2898 cfg.feature_flags.publish_package_metadata = true;
2899 cfg.feature_flags.enable_move_authentication = true;
2901 cfg.transfer_receive_object_cost_base = Some(100);
2904
2905 if chain != Chain::Unknown {
2906 cfg.max_auth_gas = Some(20_000);
2908 }
2909
2910 if chain != Chain::Mainnet {
2911 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2913 cfg.feature_flags
2915 .pre_consensus_sponsor_only_move_authentication = true;
2916 }
2917 }
2918 29 => {
2919 cfg.feature_flags.always_advance_dkg_to_resolution = true;
2925 }
2926 _ => panic!("unsupported version {version:?}"),
2937 }
2938 }
2939 cfg
2940 }
2941
2942 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
2948 let (
2949 max_back_edges_per_function,
2950 max_back_edges_per_module,
2951 sanity_check_with_regex_reference_safety,
2952 ) = if let Some((
2953 max_back_edges_per_function,
2954 max_back_edges_per_module,
2955 sanity_check_with_regex_reference_safety,
2956 )) = signing_limits
2957 {
2958 (
2959 Some(max_back_edges_per_function),
2960 Some(max_back_edges_per_module),
2961 Some(sanity_check_with_regex_reference_safety),
2962 )
2963 } else {
2964 (None, None, None)
2965 };
2966
2967 let additional_borrow_checks = if signing_limits.is_some() {
2968 true
2971 } else {
2972 self.additional_borrow_checks()
2973 };
2974
2975 VerifierConfig {
2976 max_loop_depth: Some(self.max_loop_depth() as usize),
2977 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2978 max_function_parameters: Some(self.max_function_parameters() as usize),
2979 max_basic_blocks: Some(self.max_basic_blocks() as usize),
2980 max_value_stack_size: self.max_value_stack_size() as usize,
2981 max_type_nodes: Some(self.max_type_nodes() as usize),
2982 max_push_size: Some(self.max_push_size() as usize),
2983 max_dependency_depth: Some(self.max_dependency_depth() as usize),
2984 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2985 max_function_definitions: Some(self.max_function_definitions() as usize),
2986 max_data_definitions: Some(self.max_struct_definitions() as usize),
2987 max_constant_vector_len: Some(self.max_move_vector_len()),
2988 max_back_edges_per_function,
2989 max_back_edges_per_module,
2990 max_basic_blocks_in_script: None,
2991 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
2995 max_variants_in_enum: self.max_move_enum_variants_as_option(),
2996 additional_borrow_checks,
2997 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
2998 .map(|limit| limit as u128),
2999 }
3000 }
3001
3002 pub fn apply_overrides_for_testing(
3007 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
3008 ) -> OverrideGuard {
3009 CONFIG_OVERRIDE.with(|ovr| {
3010 let mut cur = ovr.borrow_mut();
3011 assert!(cur.is_none(), "config override already present");
3012 *cur = Some(Box::new(override_fn));
3013 OverrideGuard
3014 })
3015 }
3016}
3017
3018impl ProtocolConfig {
3023 pub fn set_per_object_congestion_control_mode_for_testing(
3024 &mut self,
3025 val: PerObjectCongestionControlMode,
3026 ) {
3027 self.feature_flags.per_object_congestion_control_mode = val;
3028 }
3029
3030 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
3031 self.feature_flags.consensus_choice = val;
3032 }
3033
3034 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
3035 self.feature_flags.consensus_network = val;
3036 }
3037
3038 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
3039 self.feature_flags.passkey_auth = val
3040 }
3041
3042 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
3043 self.feature_flags
3044 .disallow_new_modules_in_deps_only_packages = val;
3045 }
3046
3047 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
3048 self.feature_flags.consensus_round_prober = val;
3049 }
3050
3051 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
3052 self.feature_flags
3053 .consensus_distributed_vote_scoring_strategy = val;
3054 }
3055
3056 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
3057 self.consensus_gc_depth = Some(val);
3058 }
3059
3060 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
3061 self.feature_flags.consensus_linearize_subdag_v2 = val;
3062 }
3063
3064 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
3065 self.feature_flags
3066 .consensus_round_prober_probe_accepted_rounds = val;
3067 }
3068
3069 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
3070 self.feature_flags.accept_passkey_in_multisig = val;
3071 }
3072
3073 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
3074 self.feature_flags.consensus_smart_ancestor_selection = val;
3075 }
3076
3077 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
3078 self.feature_flags.consensus_batched_block_sync = val;
3079 }
3080
3081 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
3082 self.feature_flags
3083 .congestion_control_min_free_execution_slot = val;
3084 }
3085
3086 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
3087 self.feature_flags
3088 .congestion_control_gas_price_feedback_mechanism = val;
3089 }
3090
3091 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
3092 self.feature_flags.select_committee_from_eligible_validators = val;
3093 }
3094
3095 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
3096 self.feature_flags.track_non_committee_eligible_validators = val;
3097 }
3098
3099 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
3100 self.feature_flags
3101 .select_committee_supporting_next_epoch_version = val;
3102 }
3103
3104 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
3105 &mut self,
3106 val: bool,
3107 ) {
3108 self.feature_flags
3109 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3110 }
3111
3112 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3113 &mut self,
3114 val: bool,
3115 ) {
3116 self.feature_flags
3117 .consensus_commit_transactions_only_for_traversed_headers = val;
3118 }
3119
3120 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3121 &mut self,
3122 val: bool,
3123 ) {
3124 self.feature_flags
3125 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3126 }
3127
3128 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3129 &mut self,
3130 val: bool,
3131 ) {
3132 self.feature_flags
3133 .separate_gas_price_feedback_mechanism_for_randomness = val;
3134 }
3135
3136 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3137 self.feature_flags.metadata_in_module_bytes = val;
3138 }
3139
3140 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3141 self.feature_flags.publish_package_metadata = val;
3142 }
3143
3144 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3145 self.feature_flags.enable_move_authentication = val;
3146 }
3147
3148 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3149 self.feature_flags.enable_move_authentication_for_sponsor = val;
3150 }
3151
3152 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3153 self.feature_flags.consensus_fast_commit_sync = val;
3154 }
3155
3156 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3157 self.feature_flags.consensus_block_restrictions = val;
3158 }
3159
3160 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3161 self.feature_flags
3162 .pre_consensus_sponsor_only_move_authentication = val;
3163 }
3164
3165 pub fn set_consensus_starfish_speed_for_testing(&mut self, val: bool) {
3166 self.feature_flags.consensus_starfish_speed = val;
3167 }
3168
3169 pub fn set_always_advance_dkg_to_resolution_for_testing(&mut self, val: bool) {
3170 self.feature_flags.always_advance_dkg_to_resolution = val;
3171 }
3172
3173 pub fn set_enable_white_flag_flow_for_testing(&mut self, val: bool) {
3174 self.feature_flags.enable_white_flag_flow = val;
3175 }
3176}
3177
3178type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
3179
3180thread_local! {
3181 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
3182}
3183
3184#[must_use]
3185pub struct OverrideGuard;
3186
3187impl Drop for OverrideGuard {
3188 fn drop(&mut self) {
3189 info!("restoring override fn");
3190 CONFIG_OVERRIDE.with(|ovr| {
3191 *ovr.borrow_mut() = None;
3192 });
3193 }
3194}
3195
3196#[derive(PartialEq, Eq)]
3200pub enum LimitThresholdCrossed {
3201 None,
3202 Soft(u128, u128),
3203 Hard(u128, u128),
3204}
3205
3206pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
3209 x: T,
3210 soft_limit: U,
3211 hard_limit: V,
3212) -> LimitThresholdCrossed {
3213 let x: V = x.into();
3214 let soft_limit: V = soft_limit.into();
3215
3216 debug_assert!(soft_limit <= hard_limit);
3217
3218 if x >= hard_limit {
3221 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
3222 } else if x < soft_limit {
3223 LimitThresholdCrossed::None
3224 } else {
3225 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
3226 }
3227}
3228
3229#[macro_export]
3230macro_rules! check_limit {
3231 ($x:expr, $hard:expr) => {
3232 check_limit!($x, $hard, $hard)
3233 };
3234 ($x:expr, $soft:expr, $hard:expr) => {
3235 check_limit_in_range($x as u64, $soft, $hard)
3236 };
3237}
3238
3239#[macro_export]
3243macro_rules! check_limit_by_meter {
3244 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
3245 let (h, metered_str) = if $is_metered {
3247 ($metered_limit, "metered")
3248 } else {
3249 ($unmetered_hard_limit, "unmetered")
3251 };
3252 use iota_protocol_config::check_limit_in_range;
3253 let result = check_limit_in_range($x as u64, $metered_limit, h);
3254 match result {
3255 LimitThresholdCrossed::None => {}
3256 LimitThresholdCrossed::Soft(_, _) => {
3257 $metric.with_label_values(&[metered_str, "soft"]).inc();
3258 }
3259 LimitThresholdCrossed::Hard(_, _) => {
3260 $metric.with_label_values(&[metered_str, "hard"]).inc();
3261 }
3262 };
3263 result
3264 }};
3265}
3266
3267#[cfg(all(test, not(msim)))]
3268mod test {
3269 use insta::assert_yaml_snapshot;
3270
3271 use super::*;
3272
3273 #[test]
3274 fn snapshot_tests() {
3275 println!("\n============================================================================");
3276 println!("! !");
3277 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
3278 println!("! !");
3279 println!("============================================================================\n");
3280 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
3281 let chain_str = match chain_id {
3286 Chain::Unknown => "".to_string(),
3287 _ => format!("{chain_id:?}_"),
3288 };
3289 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
3290 let cur = ProtocolVersion::new(i);
3291 assert_yaml_snapshot!(
3292 format!("{}version_{}", chain_str, cur.as_u64()),
3293 ProtocolConfig::get_for_version(cur, *chain_id)
3294 );
3295 }
3296 }
3297 }
3298
3299 #[test]
3300 fn test_getters() {
3301 let prot: ProtocolConfig =
3302 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3303 assert_eq!(
3304 prot.max_arguments(),
3305 prot.max_arguments_as_option().unwrap()
3306 );
3307 }
3308
3309 #[test]
3310 fn test_setters() {
3311 let mut prot: ProtocolConfig =
3312 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3313 prot.set_max_arguments_for_testing(123);
3314 assert_eq!(prot.max_arguments(), 123);
3315
3316 prot.set_max_arguments_from_str_for_testing("321".to_string());
3317 assert_eq!(prot.max_arguments(), 321);
3318
3319 prot.disable_max_arguments_for_testing();
3320 assert_eq!(prot.max_arguments_as_option(), None);
3321
3322 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
3323 assert_eq!(prot.max_arguments(), 456);
3324 }
3325
3326 #[test]
3327 #[should_panic(expected = "unsupported version")]
3328 fn max_version_test() {
3329 let _ = ProtocolConfig::get_for_version_impl(
3332 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
3333 Chain::Unknown,
3334 );
3335 }
3336
3337 #[test]
3338 fn lookup_by_string_test() {
3339 let prot: ProtocolConfig =
3340 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3341 assert!(prot.lookup_attr("some random string".to_string()).is_none());
3343
3344 assert!(
3345 prot.lookup_attr("max_arguments".to_string())
3346 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
3347 );
3348
3349 assert!(
3351 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3352 .is_none()
3353 );
3354 assert!(
3355 prot.attr_map()
3356 .get("poseidon_bn254_cost_base")
3357 .unwrap()
3358 .is_none()
3359 );
3360
3361 let prot: ProtocolConfig =
3363 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3364
3365 assert!(
3366 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3367 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3368 );
3369 assert!(
3370 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
3371 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3372 );
3373
3374 let prot: ProtocolConfig =
3376 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3377 assert!(
3379 prot.feature_flags
3380 .lookup_attr("some random string".to_owned())
3381 .is_none()
3382 );
3383 assert!(
3384 !prot
3385 .feature_flags
3386 .attr_map()
3387 .contains_key("some random string")
3388 );
3389
3390 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
3392 assert!(
3393 prot.feature_flags
3394 .attr_map()
3395 .get("enable_poseidon")
3396 .unwrap()
3397 == &false
3398 );
3399 let prot: ProtocolConfig =
3400 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3401 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
3403 assert!(
3404 prot.feature_flags
3405 .attr_map()
3406 .get("enable_poseidon")
3407 .unwrap()
3408 == &true
3409 );
3410 }
3411
3412 #[test]
3413 fn limit_range_fn_test() {
3414 let low = 100u32;
3415 let high = 10000u64;
3416
3417 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
3418 assert!(matches!(
3419 check_limit!(255u16, low, high),
3420 LimitThresholdCrossed::Soft(255u128, 100)
3421 ));
3422 assert!(matches!(
3429 check_limit!(2550000u64, low, high),
3430 LimitThresholdCrossed::Hard(2550000, 10000)
3431 ));
3432
3433 assert!(matches!(
3434 check_limit!(2550000u64, high, high),
3435 LimitThresholdCrossed::Hard(2550000, 10000)
3436 ));
3437
3438 assert!(matches!(
3439 check_limit!(1u8, high),
3440 LimitThresholdCrossed::None
3441 ));
3442
3443 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
3444
3445 assert!(matches!(
3446 check_limit!(2550000u64, high),
3447 LimitThresholdCrossed::Hard(2550000, 10000)
3448 ));
3449 }
3450}