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)]
166pub struct ProtocolVersion(u64);
167
168impl ProtocolVersion {
169 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
175
176 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
177
178 #[cfg(not(msim))]
179 const MAX_ALLOWED: Self = Self::MAX;
180
181 #[cfg(msim)]
184 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
185
186 pub fn new(v: u64) -> Self {
187 Self(v)
188 }
189
190 pub const fn as_u64(&self) -> u64 {
191 self.0
192 }
193
194 pub fn max() -> Self {
197 Self::MAX
198 }
199}
200
201impl From<u64> for ProtocolVersion {
202 fn from(v: u64) -> Self {
203 Self::new(v)
204 }
205}
206
207impl std::ops::Sub<u64> for ProtocolVersion {
208 type Output = Self;
209 fn sub(self, rhs: u64) -> Self::Output {
210 Self::new(self.0 - rhs)
211 }
212}
213
214impl std::ops::Add<u64> for ProtocolVersion {
215 type Output = Self;
216 fn add(self, rhs: u64) -> Self::Output {
217 Self::new(self.0 + rhs)
218 }
219}
220
221#[derive(
222 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
223)]
224pub enum Chain {
225 Mainnet,
226 Testnet,
227 #[default]
228 Unknown,
229}
230
231impl Chain {
232 pub fn as_str(self) -> &'static str {
233 match self {
234 Chain::Mainnet => "mainnet",
235 Chain::Testnet => "testnet",
236 Chain::Unknown => "unknown",
237 }
238 }
239}
240
241pub struct Error(pub String);
242
243#[derive(
247 Default,
248 Clone,
249 Serialize,
250 Deserialize,
251 Debug,
252 ProtocolConfigFeatureFlagsGetters,
253 ProtocolConfigOverride,
254)]
255struct FeatureFlags {
256 #[serde(skip_serializing_if = "is_true")]
262 disable_invariant_violation_check_in_swap_loc: bool,
263
264 #[serde(skip_serializing_if = "is_true")]
267 no_extraneous_module_bytes: bool,
268
269 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
271 consensus_transaction_ordering: ConsensusTransactionOrdering,
272
273 #[serde(skip_serializing_if = "is_true")]
276 hardened_otw_check: bool,
277
278 #[serde(skip_serializing_if = "is_false")]
280 enable_poseidon: bool,
281
282 #[serde(skip_serializing_if = "is_false")]
284 enable_group_ops_native_function_msm: bool,
285
286 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
288 per_object_congestion_control_mode: PerObjectCongestionControlMode,
289
290 #[serde(
292 default = "ConsensusChoice::mysticeti_deprecated",
293 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
294 )]
295 consensus_choice: ConsensusChoice,
296
297 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
299 consensus_network: ConsensusNetwork,
300
301 #[deprecated]
303 #[serde(skip_serializing_if = "Option::is_none")]
304 zklogin_max_epoch_upper_bound_delta: Option<u64>,
305
306 #[serde(skip_serializing_if = "is_false")]
308 enable_vdf: bool,
309
310 #[serde(skip_serializing_if = "is_false")]
312 passkey_auth: bool,
313
314 #[serde(skip_serializing_if = "is_true")]
317 rethrow_serialization_type_layout_errors: bool,
318
319 #[serde(skip_serializing_if = "is_false")]
321 relocate_event_module: bool,
322
323 #[serde(skip_serializing_if = "is_false")]
325 protocol_defined_base_fee: bool,
326
327 #[serde(skip_serializing_if = "is_false")]
329 uncompressed_g1_group_elements: bool,
330
331 #[serde(skip_serializing_if = "is_false")]
333 disallow_new_modules_in_deps_only_packages: bool,
334
335 #[serde(skip_serializing_if = "is_false")]
337 native_charging_v2: bool,
338
339 #[serde(skip_serializing_if = "is_false")]
341 convert_type_argument_error: bool,
342
343 #[serde(skip_serializing_if = "is_false")]
345 consensus_round_prober: bool,
346
347 #[serde(skip_serializing_if = "is_false")]
349 consensus_distributed_vote_scoring_strategy: bool,
350
351 #[serde(skip_serializing_if = "is_false")]
355 consensus_linearize_subdag_v2: bool,
356
357 #[serde(skip_serializing_if = "is_false")]
359 variant_nodes: bool,
360
361 #[serde(skip_serializing_if = "is_false")]
363 consensus_smart_ancestor_selection: bool,
364
365 #[serde(skip_serializing_if = "is_false")]
367 consensus_round_prober_probe_accepted_rounds: bool,
368
369 #[serde(skip_serializing_if = "is_false")]
371 consensus_zstd_compression: bool,
372
373 #[serde(skip_serializing_if = "is_false")]
376 congestion_control_min_free_execution_slot: bool,
377
378 #[serde(skip_serializing_if = "is_false")]
380 accept_passkey_in_multisig: bool,
381
382 #[serde(skip_serializing_if = "is_false")]
384 consensus_batched_block_sync: bool,
385
386 #[serde(skip_serializing_if = "is_false")]
389 congestion_control_gas_price_feedback_mechanism: bool,
390
391 #[serde(skip_serializing_if = "is_false")]
393 validate_identifier_inputs: bool,
394
395 #[serde(skip_serializing_if = "is_false")]
398 minimize_child_object_mutations: bool,
399
400 #[serde(skip_serializing_if = "is_false")]
402 dependency_linkage_error: bool,
403
404 #[serde(skip_serializing_if = "is_false")]
406 additional_multisig_checks: bool,
407
408 #[serde(skip_serializing_if = "is_false")]
411 normalize_ptb_arguments: bool,
412
413 #[serde(skip_serializing_if = "is_false")]
417 select_committee_from_eligible_validators: bool,
418
419 #[serde(skip_serializing_if = "is_false")]
426 track_non_committee_eligible_validators: bool,
427
428 #[serde(skip_serializing_if = "is_false")]
434 select_committee_supporting_next_epoch_version: bool,
435
436 #[serde(skip_serializing_if = "is_false")]
440 consensus_median_timestamp_with_checkpoint_enforcement: bool,
441
442 #[serde(skip_serializing_if = "is_false")]
444 consensus_commit_transactions_only_for_traversed_headers: bool,
445
446 #[serde(skip_serializing_if = "is_false")]
448 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
449
450 #[serde(skip_serializing_if = "is_false")]
453 separate_gas_price_feedback_mechanism_for_randomness: bool,
454
455 #[serde(skip_serializing_if = "is_false")]
458 metadata_in_module_bytes: bool,
459
460 #[serde(skip_serializing_if = "is_false")]
462 publish_package_metadata: bool,
463
464 #[serde(skip_serializing_if = "is_false")]
466 enable_move_authentication: bool,
467
468 #[serde(skip_serializing_if = "is_false")]
470 enable_move_authentication_for_sponsor: bool,
471
472 #[serde(skip_serializing_if = "is_false")]
474 pass_validator_scores_to_advance_epoch: bool,
475
476 #[serde(skip_serializing_if = "is_false")]
478 calculate_validator_scores: bool,
479
480 #[serde(skip_serializing_if = "is_false")]
482 adjust_rewards_by_score: bool,
483
484 #[serde(skip_serializing_if = "is_false")]
487 pass_calculated_validator_scores_to_advance_epoch: bool,
488
489 #[serde(skip_serializing_if = "is_false")]
494 consensus_fast_commit_sync: bool,
495
496 #[serde(skip_serializing_if = "is_false")]
499 consensus_block_restrictions: bool,
500
501 #[serde(skip_serializing_if = "is_false")]
503 move_native_tx_context: bool,
504
505 #[serde(skip_serializing_if = "is_false")]
507 additional_borrow_checks: bool,
508
509 #[serde(skip_serializing_if = "is_false")]
511 pre_consensus_sponsor_only_move_authentication: bool,
512
513 #[serde(skip_serializing_if = "is_false")]
515 consensus_starfish_speed: bool,
516
517 #[serde(skip_serializing_if = "is_false")]
524 always_advance_dkg_to_resolution: bool,
525
526 #[serde(skip_serializing_if = "is_false")]
530 enable_white_flag_flow: bool,
531}
532
533fn is_true(b: &bool) -> bool {
534 *b
535}
536
537fn is_false(b: &bool) -> bool {
538 !b
539}
540
541#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
543pub enum ConsensusTransactionOrdering {
544 #[default]
547 None,
548 ByGasPrice,
550}
551
552impl ConsensusTransactionOrdering {
553 pub fn is_none(&self) -> bool {
554 matches!(self, ConsensusTransactionOrdering::None)
555 }
556}
557
558#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
560pub enum PerObjectCongestionControlMode {
561 #[default]
562 None, TotalGasBudget, TotalTxCount, }
566
567impl PerObjectCongestionControlMode {
568 pub fn is_none(&self) -> bool {
569 matches!(self, PerObjectCongestionControlMode::None)
570 }
571}
572
573#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
575pub enum ConsensusChoice {
576 #[deprecated(note = "Mysticeti was replaced by Starfish")]
579 MysticetiDeprecated,
580 #[default]
581 Starfish,
582}
583
584#[expect(deprecated)]
585impl ConsensusChoice {
586 fn mysticeti_deprecated() -> Self {
593 ConsensusChoice::MysticetiDeprecated
594 }
595
596 pub fn is_mysticeti_deprecated(&self) -> bool {
597 matches!(self, ConsensusChoice::MysticetiDeprecated)
598 }
599 pub fn is_starfish(&self) -> bool {
600 matches!(self, ConsensusChoice::Starfish)
601 }
602}
603
604#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
606pub enum ConsensusNetwork {
607 #[default]
608 Tonic,
609}
610
611impl ConsensusNetwork {
612 pub fn is_tonic(&self) -> bool {
613 matches!(self, ConsensusNetwork::Tonic)
614 }
615}
616
617#[skip_serializing_none]
651#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
652pub struct ProtocolConfig {
653 pub version: ProtocolVersion,
654
655 feature_flags: FeatureFlags,
656
657 max_tx_size_bytes: Option<u64>,
662
663 max_input_objects: Option<u64>,
666
667 max_size_written_objects: Option<u64>,
672 max_size_written_objects_system_tx: Option<u64>,
676
677 max_serialized_tx_effects_size_bytes: Option<u64>,
679
680 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
682
683 max_gas_payment_objects: Option<u32>,
685
686 max_modules_in_publish: Option<u32>,
688
689 max_package_dependencies: Option<u32>,
691
692 max_arguments: Option<u32>,
695
696 max_type_arguments: Option<u32>,
698
699 max_type_argument_depth: Option<u32>,
701
702 max_pure_argument_size: Option<u32>,
704
705 max_programmable_tx_commands: Option<u32>,
707
708 move_binary_format_version: Option<u32>,
714 min_move_binary_format_version: Option<u32>,
715
716 binary_module_handles: Option<u16>,
718 binary_struct_handles: Option<u16>,
719 binary_function_handles: Option<u16>,
720 binary_function_instantiations: Option<u16>,
721 binary_signatures: Option<u16>,
722 binary_constant_pool: Option<u16>,
723 binary_identifiers: Option<u16>,
724 binary_address_identifiers: Option<u16>,
725 binary_struct_defs: Option<u16>,
726 binary_struct_def_instantiations: Option<u16>,
727 binary_function_defs: Option<u16>,
728 binary_field_handles: Option<u16>,
729 binary_field_instantiations: Option<u16>,
730 binary_friend_decls: Option<u16>,
731 binary_enum_defs: Option<u16>,
732 binary_enum_def_instantiations: Option<u16>,
733 binary_variant_handles: Option<u16>,
734 binary_variant_instantiation_handles: Option<u16>,
735
736 max_move_object_size: Option<u64>,
739
740 max_move_package_size: Option<u64>,
745
746 max_publish_or_upgrade_per_ptb: Option<u64>,
749
750 max_tx_gas: Option<u64>,
752
753 max_auth_gas: Option<u64>,
755
756 max_gas_price: Option<u64>,
759
760 max_gas_computation_bucket: Option<u64>,
763
764 gas_rounding_step: Option<u64>,
766
767 max_loop_depth: Option<u64>,
769
770 max_generic_instantiation_length: Option<u64>,
773
774 max_function_parameters: Option<u64>,
777
778 max_basic_blocks: Option<u64>,
781
782 max_value_stack_size: Option<u64>,
784
785 max_type_nodes: Option<u64>,
789
790 max_push_size: Option<u64>,
793
794 max_struct_definitions: Option<u64>,
797
798 max_function_definitions: Option<u64>,
801
802 max_fields_in_struct: Option<u64>,
805
806 max_dependency_depth: Option<u64>,
809
810 max_num_event_emit: Option<u64>,
813
814 max_num_new_move_object_ids: Option<u64>,
817
818 max_num_new_move_object_ids_system_tx: Option<u64>,
821
822 max_num_deleted_move_object_ids: Option<u64>,
825
826 max_num_deleted_move_object_ids_system_tx: Option<u64>,
829
830 max_num_transferred_move_object_ids: Option<u64>,
833
834 max_num_transferred_move_object_ids_system_tx: Option<u64>,
837
838 max_event_emit_size: Option<u64>,
840
841 max_event_emit_size_total: Option<u64>,
843
844 max_move_vector_len: Option<u64>,
847
848 max_move_identifier_len: Option<u64>,
851
852 max_move_value_depth: Option<u64>,
854
855 max_move_enum_variants: Option<u64>,
858
859 max_back_edges_per_function: Option<u64>,
862
863 max_back_edges_per_module: Option<u64>,
866
867 max_verifier_meter_ticks_per_function: Option<u64>,
870
871 max_meter_ticks_per_module: Option<u64>,
874
875 max_meter_ticks_per_package: Option<u64>,
878
879 object_runtime_max_num_cached_objects: Option<u64>,
886
887 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
890
891 object_runtime_max_num_store_entries: Option<u64>,
894
895 object_runtime_max_num_store_entries_system_tx: Option<u64>,
898
899 base_tx_cost_fixed: Option<u64>,
904
905 package_publish_cost_fixed: Option<u64>,
909
910 base_tx_cost_per_byte: Option<u64>,
914
915 package_publish_cost_per_byte: Option<u64>,
917
918 obj_access_cost_read_per_byte: Option<u64>,
920
921 obj_access_cost_mutate_per_byte: Option<u64>,
923
924 obj_access_cost_delete_per_byte: Option<u64>,
926
927 obj_access_cost_verify_per_byte: Option<u64>,
937
938 max_type_to_layout_nodes: Option<u64>,
940
941 max_ptb_value_size: Option<u64>,
943
944 gas_model_version: Option<u64>,
949
950 obj_data_cost_refundable: Option<u64>,
956
957 obj_metadata_cost_non_refundable: Option<u64>,
961
962 storage_rebate_rate: Option<u64>,
968
969 reward_slashing_rate: Option<u64>,
972
973 storage_gas_price: Option<u64>,
975
976 base_gas_price: Option<u64>,
978
979 validator_target_reward: Option<u64>,
981
982 max_transactions_per_checkpoint: Option<u64>,
989
990 max_checkpoint_size_bytes: Option<u64>,
994
995 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
1001
1002 address_from_bytes_cost_base: Option<u64>,
1007 address_to_u256_cost_base: Option<u64>,
1009 address_from_u256_cost_base: Option<u64>,
1011
1012 config_read_setting_impl_cost_base: Option<u64>,
1017 config_read_setting_impl_cost_per_byte: Option<u64>,
1018
1019 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
1023 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
1024 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
1025 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
1026 dynamic_field_add_child_object_cost_base: Option<u64>,
1029 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
1030 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
1031 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
1032 dynamic_field_borrow_child_object_cost_base: Option<u64>,
1035 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1036 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1037 dynamic_field_remove_child_object_cost_base: Option<u64>,
1040 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1041 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1042 dynamic_field_has_child_object_cost_base: Option<u64>,
1045 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1048 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1049 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1050
1051 event_emit_cost_base: Option<u64>,
1054 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1055 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1056 event_emit_output_cost_per_byte: Option<u64>,
1057
1058 object_borrow_uid_cost_base: Option<u64>,
1061 object_delete_impl_cost_base: Option<u64>,
1063 object_record_new_uid_cost_base: Option<u64>,
1065
1066 transfer_transfer_internal_cost_base: Option<u64>,
1069 transfer_freeze_object_cost_base: Option<u64>,
1071 transfer_share_object_cost_base: Option<u64>,
1073 transfer_receive_object_cost_base: Option<u64>,
1076
1077 tx_context_derive_id_cost_base: Option<u64>,
1080 tx_context_fresh_id_cost_base: Option<u64>,
1081 tx_context_sender_cost_base: Option<u64>,
1082 tx_context_digest_cost_base: Option<u64>,
1083 tx_context_epoch_cost_base: Option<u64>,
1084 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1085 tx_context_sponsor_cost_base: Option<u64>,
1086 tx_context_rgp_cost_base: Option<u64>,
1087 tx_context_gas_price_cost_base: Option<u64>,
1088 tx_context_gas_budget_cost_base: Option<u64>,
1089 tx_context_ids_created_cost_base: Option<u64>,
1090 tx_context_replace_cost_base: Option<u64>,
1091
1092 types_is_one_time_witness_cost_base: Option<u64>,
1095 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1096 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1097
1098 validator_validate_metadata_cost_base: Option<u64>,
1101 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1102
1103 crypto_invalid_arguments_cost: Option<u64>,
1105 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1107 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1108 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1109
1110 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1112 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1113 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1114
1115 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1117 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1118 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1119 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1120 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1121 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1122
1123 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1125
1126 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1128 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1129 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1130 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1131 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1132 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1133
1134 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1136 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1137 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1138 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1139 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1140 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1141
1142 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1144 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1145 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1146 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1147 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1148 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1149
1150 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1152 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1153 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1154
1155 ed25519_ed25519_verify_cost_base: Option<u64>,
1157 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1158 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1159
1160 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1162 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1163
1164 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1166 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1167 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1168 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1169 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1170
1171 hash_blake2b256_cost_base: Option<u64>,
1173 hash_blake2b256_data_cost_per_byte: Option<u64>,
1174 hash_blake2b256_data_cost_per_block: Option<u64>,
1175
1176 hash_keccak256_cost_base: Option<u64>,
1178 hash_keccak256_data_cost_per_byte: Option<u64>,
1179 hash_keccak256_data_cost_per_block: Option<u64>,
1180
1181 poseidon_bn254_cost_base: Option<u64>,
1183 poseidon_bn254_cost_per_block: Option<u64>,
1184
1185 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1187 group_ops_bls12381_decode_g1_cost: Option<u64>,
1188 group_ops_bls12381_decode_g2_cost: Option<u64>,
1189 group_ops_bls12381_decode_gt_cost: Option<u64>,
1190 group_ops_bls12381_scalar_add_cost: Option<u64>,
1191 group_ops_bls12381_g1_add_cost: Option<u64>,
1192 group_ops_bls12381_g2_add_cost: Option<u64>,
1193 group_ops_bls12381_gt_add_cost: Option<u64>,
1194 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1195 group_ops_bls12381_g1_sub_cost: Option<u64>,
1196 group_ops_bls12381_g2_sub_cost: Option<u64>,
1197 group_ops_bls12381_gt_sub_cost: Option<u64>,
1198 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1199 group_ops_bls12381_g1_mul_cost: Option<u64>,
1200 group_ops_bls12381_g2_mul_cost: Option<u64>,
1201 group_ops_bls12381_gt_mul_cost: Option<u64>,
1202 group_ops_bls12381_scalar_div_cost: Option<u64>,
1203 group_ops_bls12381_g1_div_cost: Option<u64>,
1204 group_ops_bls12381_g2_div_cost: Option<u64>,
1205 group_ops_bls12381_gt_div_cost: Option<u64>,
1206 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1207 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1208 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1209 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1210 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1211 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1212 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1213 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1214 group_ops_bls12381_msm_max_len: Option<u32>,
1215 group_ops_bls12381_pairing_cost: Option<u64>,
1216 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1217 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1218 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1219 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1220 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1221
1222 hmac_hmac_sha3_256_cost_base: Option<u64>,
1224 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1225 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1226
1227 #[deprecated]
1229 check_zklogin_id_cost_base: Option<u64>,
1230 #[deprecated]
1232 check_zklogin_issuer_cost_base: Option<u64>,
1233
1234 vdf_verify_vdf_cost: Option<u64>,
1235 vdf_hash_to_input_cost: Option<u64>,
1236
1237 bcs_per_byte_serialized_cost: Option<u64>,
1239 bcs_legacy_min_output_size_cost: Option<u64>,
1240 bcs_failure_cost: Option<u64>,
1241
1242 hash_sha2_256_base_cost: Option<u64>,
1243 hash_sha2_256_per_byte_cost: Option<u64>,
1244 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1245 hash_sha3_256_base_cost: Option<u64>,
1246 hash_sha3_256_per_byte_cost: Option<u64>,
1247 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1248 type_name_get_base_cost: Option<u64>,
1249 type_name_get_per_byte_cost: Option<u64>,
1250
1251 string_check_utf8_base_cost: Option<u64>,
1252 string_check_utf8_per_byte_cost: Option<u64>,
1253 string_is_char_boundary_base_cost: Option<u64>,
1254 string_sub_string_base_cost: Option<u64>,
1255 string_sub_string_per_byte_cost: Option<u64>,
1256 string_index_of_base_cost: Option<u64>,
1257 string_index_of_per_byte_pattern_cost: Option<u64>,
1258 string_index_of_per_byte_searched_cost: Option<u64>,
1259
1260 vector_empty_base_cost: Option<u64>,
1261 vector_length_base_cost: Option<u64>,
1262 vector_push_back_base_cost: Option<u64>,
1263 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1264 vector_borrow_base_cost: Option<u64>,
1265 vector_pop_back_base_cost: Option<u64>,
1266 vector_destroy_empty_base_cost: Option<u64>,
1267 vector_swap_base_cost: Option<u64>,
1268 debug_print_base_cost: Option<u64>,
1269 debug_print_stack_trace_base_cost: Option<u64>,
1270
1271 execution_version: Option<u64>,
1273
1274 consensus_bad_nodes_stake_threshold: Option<u64>,
1278
1279 #[deprecated]
1280 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1281 #[deprecated]
1285 max_age_of_jwk_in_epochs: Option<u64>,
1286
1287 random_beacon_reduction_allowed_delta: Option<u16>,
1291
1292 random_beacon_reduction_lower_bound: Option<u32>,
1295
1296 random_beacon_dkg_timeout_round: Option<u32>,
1299
1300 random_beacon_min_round_interval_ms: Option<u64>,
1302
1303 random_beacon_dkg_version: Option<u64>,
1307
1308 consensus_max_transaction_size_bytes: Option<u64>,
1313 consensus_max_transactions_in_block_bytes: Option<u64>,
1315 consensus_max_num_transactions_in_block: Option<u64>,
1317
1318 max_deferral_rounds_for_congestion_control: Option<u64>,
1322
1323 min_checkpoint_interval_ms: Option<u64>,
1325
1326 checkpoint_summary_version_specific_data: Option<u64>,
1328
1329 max_soft_bundle_size: Option<u64>,
1332
1333 bridge_should_try_to_finalize_committee: Option<bool>,
1338
1339 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1345
1346 max_committee_members_count: Option<u64>,
1350
1351 consensus_gc_depth: Option<u32>,
1354
1355 consensus_max_acknowledgments_per_block: Option<u32>,
1361
1362 max_congestion_limit_overshoot_per_commit: Option<u64>,
1367
1368 scorer_version: Option<u16>,
1377
1378 auth_context_digest_cost_base: Option<u64>,
1381 auth_context_tx_data_bytes_cost_base: Option<u64>,
1383 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1384 auth_context_tx_commands_cost_base: Option<u64>,
1386 auth_context_tx_commands_cost_per_byte: Option<u64>,
1387 auth_context_tx_inputs_cost_base: Option<u64>,
1389 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1390 auth_context_replace_cost_base: Option<u64>,
1393 auth_context_replace_cost_per_byte: Option<u64>,
1394 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1398}
1399
1400impl ProtocolConfig {
1402 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1415 self.feature_flags
1416 .disable_invariant_violation_check_in_swap_loc
1417 }
1418
1419 pub fn no_extraneous_module_bytes(&self) -> bool {
1420 self.feature_flags.no_extraneous_module_bytes
1421 }
1422
1423 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1424 self.feature_flags.consensus_transaction_ordering
1425 }
1426
1427 pub fn dkg_version(&self) -> u64 {
1428 self.random_beacon_dkg_version.unwrap_or(1)
1430 }
1431
1432 pub fn hardened_otw_check(&self) -> bool {
1433 self.feature_flags.hardened_otw_check
1434 }
1435
1436 pub fn enable_poseidon(&self) -> bool {
1437 self.feature_flags.enable_poseidon
1438 }
1439
1440 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1441 self.feature_flags.enable_group_ops_native_function_msm
1442 }
1443
1444 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1445 self.feature_flags.per_object_congestion_control_mode
1446 }
1447
1448 pub fn consensus_choice(&self) -> ConsensusChoice {
1449 self.feature_flags.consensus_choice
1450 }
1451
1452 pub fn consensus_network(&self) -> ConsensusNetwork {
1453 self.feature_flags.consensus_network
1454 }
1455
1456 pub fn enable_vdf(&self) -> bool {
1457 self.feature_flags.enable_vdf
1458 }
1459
1460 pub fn passkey_auth(&self) -> bool {
1461 self.feature_flags.passkey_auth
1462 }
1463
1464 pub fn max_transaction_size_bytes(&self) -> u64 {
1465 self.consensus_max_transaction_size_bytes
1467 .unwrap_or(256 * 1024)
1468 }
1469
1470 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1471 if cfg!(msim) {
1472 256 * 1024
1473 } else {
1474 self.consensus_max_transactions_in_block_bytes
1475 .unwrap_or(512 * 1024)
1476 }
1477 }
1478
1479 pub fn max_num_transactions_in_block(&self) -> u64 {
1480 if cfg!(msim) {
1481 8
1482 } else {
1483 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1484 }
1485 }
1486
1487 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1488 self.feature_flags.rethrow_serialization_type_layout_errors
1489 }
1490
1491 pub fn relocate_event_module(&self) -> bool {
1492 self.feature_flags.relocate_event_module
1493 }
1494
1495 pub fn protocol_defined_base_fee(&self) -> bool {
1496 self.feature_flags.protocol_defined_base_fee
1497 }
1498
1499 pub fn uncompressed_g1_group_elements(&self) -> bool {
1500 self.feature_flags.uncompressed_g1_group_elements
1501 }
1502
1503 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1504 self.feature_flags
1505 .disallow_new_modules_in_deps_only_packages
1506 }
1507
1508 pub fn native_charging_v2(&self) -> bool {
1509 self.feature_flags.native_charging_v2
1510 }
1511
1512 pub fn consensus_round_prober(&self) -> bool {
1513 self.feature_flags.consensus_round_prober
1514 }
1515
1516 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1517 self.feature_flags
1518 .consensus_distributed_vote_scoring_strategy
1519 }
1520
1521 pub fn gc_depth(&self) -> u32 {
1522 if cfg!(msim) {
1523 min(5, self.consensus_gc_depth.unwrap_or(0))
1525 } else {
1526 self.consensus_gc_depth.unwrap_or(0)
1527 }
1528 }
1529
1530 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1531 let res = self.feature_flags.consensus_linearize_subdag_v2;
1532 assert!(
1533 !res || self.gc_depth() > 0,
1534 "The consensus linearize sub dag V2 requires GC to be enabled"
1535 );
1536 res
1537 }
1538
1539 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1540 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1541 }
1542
1543 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1544 if self.consensus_block_restrictions() {
1545 2 * committee_size
1546 } else {
1547 self.consensus_max_acknowledgments_per_block_or_default() as usize
1548 }
1549 }
1550
1551 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1552 if self.consensus_block_restrictions() {
1553 committee_size
1554 } else {
1555 100
1556 }
1557 }
1558
1559 pub fn variant_nodes(&self) -> bool {
1560 self.feature_flags.variant_nodes
1561 }
1562
1563 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1564 self.feature_flags.consensus_smart_ancestor_selection
1565 }
1566
1567 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1568 self.feature_flags
1569 .consensus_round_prober_probe_accepted_rounds
1570 }
1571
1572 pub fn consensus_zstd_compression(&self) -> bool {
1573 self.feature_flags.consensus_zstd_compression
1574 }
1575
1576 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1577 self.feature_flags
1578 .congestion_control_min_free_execution_slot
1579 }
1580
1581 pub fn accept_passkey_in_multisig(&self) -> bool {
1582 self.feature_flags.accept_passkey_in_multisig
1583 }
1584
1585 pub fn consensus_batched_block_sync(&self) -> bool {
1586 self.feature_flags.consensus_batched_block_sync
1587 }
1588
1589 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1592 self.feature_flags
1593 .congestion_control_gas_price_feedback_mechanism
1594 }
1595
1596 pub fn validate_identifier_inputs(&self) -> bool {
1597 self.feature_flags.validate_identifier_inputs
1598 }
1599
1600 pub fn minimize_child_object_mutations(&self) -> bool {
1601 self.feature_flags.minimize_child_object_mutations
1602 }
1603
1604 pub fn dependency_linkage_error(&self) -> bool {
1605 self.feature_flags.dependency_linkage_error
1606 }
1607
1608 pub fn additional_multisig_checks(&self) -> bool {
1609 self.feature_flags.additional_multisig_checks
1610 }
1611
1612 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1613 0
1616 }
1617
1618 pub fn normalize_ptb_arguments(&self) -> bool {
1619 self.feature_flags.normalize_ptb_arguments
1620 }
1621
1622 pub fn select_committee_from_eligible_validators(&self) -> bool {
1623 let res = self.feature_flags.select_committee_from_eligible_validators;
1624 assert!(
1625 !res || (self.protocol_defined_base_fee()
1626 && self.max_committee_members_count_as_option().is_some()),
1627 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1628 );
1629 res
1630 }
1631
1632 pub fn track_non_committee_eligible_validators(&self) -> bool {
1633 self.feature_flags.track_non_committee_eligible_validators
1634 }
1635
1636 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1637 let res = self
1638 .feature_flags
1639 .select_committee_supporting_next_epoch_version;
1640 assert!(
1641 !res || (self.track_non_committee_eligible_validators()
1642 && self.select_committee_from_eligible_validators()),
1643 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1644 );
1645 res
1646 }
1647
1648 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1649 let res = self
1650 .feature_flags
1651 .consensus_median_timestamp_with_checkpoint_enforcement;
1652 assert!(
1653 !res || self.gc_depth() > 0,
1654 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1655 );
1656 res
1657 }
1658
1659 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1660 self.feature_flags
1661 .consensus_commit_transactions_only_for_traversed_headers
1662 }
1663
1664 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1667 self.feature_flags
1668 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1669 }
1670
1671 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1674 self.feature_flags
1675 .separate_gas_price_feedback_mechanism_for_randomness
1676 }
1677
1678 pub fn metadata_in_module_bytes(&self) -> bool {
1679 self.feature_flags.metadata_in_module_bytes
1680 }
1681
1682 pub fn publish_package_metadata(&self) -> bool {
1683 self.feature_flags.publish_package_metadata
1684 }
1685
1686 pub fn enable_move_authentication(&self) -> bool {
1687 self.feature_flags.enable_move_authentication
1688 }
1689
1690 pub fn additional_borrow_checks(&self) -> bool {
1691 self.feature_flags.additional_borrow_checks
1692 }
1693
1694 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1695 let enable_move_authentication_for_sponsor =
1696 self.feature_flags.enable_move_authentication_for_sponsor;
1697 assert!(
1698 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1699 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1700 );
1701 enable_move_authentication_for_sponsor
1702 }
1703
1704 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1705 self.feature_flags.pass_validator_scores_to_advance_epoch
1706 }
1707
1708 pub fn calculate_validator_scores(&self) -> bool {
1709 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1710 assert!(
1711 !calculate_validator_scores || self.scorer_version.is_some(),
1712 "calculate_validator_scores requires scorer_version to be set"
1713 );
1714 calculate_validator_scores
1715 }
1716
1717 pub fn adjust_rewards_by_score(&self) -> bool {
1718 let adjust = self.feature_flags.adjust_rewards_by_score;
1719 assert!(
1720 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1721 "adjust_rewards_by_score requires scorer_version to be set"
1722 );
1723 adjust
1724 }
1725
1726 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1727 let pass = self
1728 .feature_flags
1729 .pass_calculated_validator_scores_to_advance_epoch;
1730 assert!(
1731 !pass
1732 || (self.pass_validator_scores_to_advance_epoch()
1733 && self.calculate_validator_scores()),
1734 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
1735 );
1736 pass
1737 }
1738 pub fn consensus_fast_commit_sync(&self) -> bool {
1739 let res = self.feature_flags.consensus_fast_commit_sync;
1740 assert!(
1741 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
1742 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
1743 );
1744 res
1745 }
1746
1747 pub fn consensus_block_restrictions(&self) -> bool {
1748 self.feature_flags.consensus_block_restrictions
1749 }
1750
1751 pub fn move_native_tx_context(&self) -> bool {
1752 self.feature_flags.move_native_tx_context
1753 }
1754
1755 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
1756 let pre_consensus_sponsor_only_move_authentication = self
1757 .feature_flags
1758 .pre_consensus_sponsor_only_move_authentication;
1759 if pre_consensus_sponsor_only_move_authentication {
1760 assert!(
1761 self.enable_move_authentication(),
1762 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
1763 );
1764 assert!(
1765 self.enable_move_authentication_for_sponsor(),
1766 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
1767 );
1768 }
1769 pre_consensus_sponsor_only_move_authentication
1770 }
1771
1772 pub fn consensus_starfish_speed(&self) -> bool {
1773 let res = self.feature_flags.consensus_starfish_speed;
1774 assert!(
1775 !res || self.consensus_fast_commit_sync(),
1776 "consensus_starfish_speed requires consensus_fast_commit_sync to be enabled"
1777 );
1778 res
1779 }
1780
1781 pub fn always_advance_dkg_to_resolution(&self) -> bool {
1782 self.feature_flags.always_advance_dkg_to_resolution
1783 }
1784
1785 pub fn enable_white_flag_flow(&self) -> bool {
1786 self.feature_flags.enable_white_flag_flow
1787 }
1788}
1789
1790#[cfg(not(msim))]
1791static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1792
1793#[cfg(msim)]
1795thread_local! {
1796 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1797}
1798
1799impl ProtocolConfig {
1801 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1804 assert!(
1806 version >= ProtocolVersion::MIN,
1807 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1808 version,
1809 ProtocolVersion::MIN.0,
1810 );
1811 assert!(
1812 version <= ProtocolVersion::MAX_ALLOWED,
1813 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1814 version,
1815 ProtocolVersion::MAX_ALLOWED.0,
1816 );
1817
1818 let mut ret = Self::get_for_version_impl(version, chain);
1819 ret.version = version;
1820
1821 ret = CONFIG_OVERRIDE.with(|ovr| {
1822 if let Some(override_fn) = &*ovr.borrow() {
1823 warn!(
1824 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1825 );
1826 override_fn(version, ret)
1827 } else {
1828 ret
1829 }
1830 });
1831
1832 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1833 warn!(
1834 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1835 );
1836
1837 let overrides: ProtocolConfigOptional =
1839 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1840 .expect("failed to parse ProtocolConfig override env variables");
1841 overrides.apply_to(&mut ret);
1842
1843 let feature_flag_overrides: FeatureFlagsOptional =
1845 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_FEATURE_FLAGS_OVERRIDE")
1846 .expect("failed to parse ProtocolConfig feature flags override env variables");
1847
1848 feature_flag_overrides.apply_to(&mut ret.feature_flags);
1849 }
1850
1851 ret
1852 }
1853
1854 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1857 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1858 let mut ret = Self::get_for_version_impl(version, chain);
1859 ret.version = version;
1860 Some(ret)
1861 } else {
1862 None
1863 }
1864 }
1865
1866 #[cfg(not(msim))]
1867 pub fn poison_get_for_min_version() {
1868 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1869 }
1870
1871 #[cfg(not(msim))]
1872 fn load_poison_get_for_min_version() -> bool {
1873 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1874 }
1875
1876 #[cfg(msim)]
1877 pub fn poison_get_for_min_version() {
1878 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1879 }
1880
1881 #[cfg(msim)]
1882 fn load_poison_get_for_min_version() -> bool {
1883 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1884 }
1885
1886 pub fn convert_type_argument_error(&self) -> bool {
1887 self.feature_flags.convert_type_argument_error
1888 }
1889
1890 pub fn get_for_min_version() -> Self {
1894 if Self::load_poison_get_for_min_version() {
1895 panic!("get_for_min_version called on validator");
1896 }
1897 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1898 }
1899
1900 #[expect(non_snake_case)]
1911 pub fn get_for_max_version_UNSAFE() -> Self {
1912 if Self::load_poison_get_for_min_version() {
1913 panic!("get_for_max_version_UNSAFE called on validator");
1914 }
1915 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1916 }
1917
1918 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1919 #[cfg(msim)]
1920 {
1921 if version > ProtocolVersion::MAX {
1923 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1924 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1925 return config;
1926 }
1927 }
1928
1929 let mut cfg = Self {
1933 version,
1934
1935 feature_flags: Default::default(),
1936
1937 max_tx_size_bytes: Some(128 * 1024),
1938 max_input_objects: Some(2048),
1941 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1942 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1943 max_gas_payment_objects: Some(256),
1944 max_modules_in_publish: Some(64),
1945 max_package_dependencies: Some(32),
1946 max_arguments: Some(512),
1947 max_type_arguments: Some(16),
1948 max_type_argument_depth: Some(16),
1949 max_pure_argument_size: Some(16 * 1024),
1950 max_programmable_tx_commands: Some(1024),
1951 move_binary_format_version: Some(7),
1952 min_move_binary_format_version: Some(6),
1953 binary_module_handles: Some(100),
1954 binary_struct_handles: Some(300),
1955 binary_function_handles: Some(1500),
1956 binary_function_instantiations: Some(750),
1957 binary_signatures: Some(1000),
1958 binary_constant_pool: Some(4000),
1959 binary_identifiers: Some(10000),
1960 binary_address_identifiers: Some(100),
1961 binary_struct_defs: Some(200),
1962 binary_struct_def_instantiations: Some(100),
1963 binary_function_defs: Some(1000),
1964 binary_field_handles: Some(500),
1965 binary_field_instantiations: Some(250),
1966 binary_friend_decls: Some(100),
1967 binary_enum_defs: None,
1968 binary_enum_def_instantiations: None,
1969 binary_variant_handles: None,
1970 binary_variant_instantiation_handles: None,
1971 max_move_object_size: Some(250 * 1024),
1972 max_move_package_size: Some(100 * 1024),
1973 max_publish_or_upgrade_per_ptb: Some(5),
1974 max_auth_gas: None,
1976 max_tx_gas: Some(50_000_000_000),
1978 max_gas_price: Some(100_000),
1979 max_gas_computation_bucket: Some(5_000_000),
1980 max_loop_depth: Some(5),
1981 max_generic_instantiation_length: Some(32),
1982 max_function_parameters: Some(128),
1983 max_basic_blocks: Some(1024),
1984 max_value_stack_size: Some(1024),
1985 max_type_nodes: Some(256),
1986 max_push_size: Some(10000),
1987 max_struct_definitions: Some(200),
1988 max_function_definitions: Some(1000),
1989 max_fields_in_struct: Some(32),
1990 max_dependency_depth: Some(100),
1991 max_num_event_emit: Some(1024),
1992 max_num_new_move_object_ids: Some(2048),
1993 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1994 max_num_deleted_move_object_ids: Some(2048),
1995 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1996 max_num_transferred_move_object_ids: Some(2048),
1997 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1998 max_event_emit_size: Some(250 * 1024),
1999 max_move_vector_len: Some(256 * 1024),
2000 max_type_to_layout_nodes: None,
2001 max_ptb_value_size: None,
2002
2003 max_back_edges_per_function: Some(10_000),
2004 max_back_edges_per_module: Some(10_000),
2005
2006 max_verifier_meter_ticks_per_function: Some(16_000_000),
2007
2008 max_meter_ticks_per_module: Some(16_000_000),
2009 max_meter_ticks_per_package: Some(16_000_000),
2010
2011 object_runtime_max_num_cached_objects: Some(1000),
2012 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2013 object_runtime_max_num_store_entries: Some(1000),
2014 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2015 base_tx_cost_fixed: Some(1_000),
2017 package_publish_cost_fixed: Some(1_000),
2018 base_tx_cost_per_byte: Some(0),
2019 package_publish_cost_per_byte: Some(80),
2020 obj_access_cost_read_per_byte: Some(15),
2021 obj_access_cost_mutate_per_byte: Some(40),
2022 obj_access_cost_delete_per_byte: Some(40),
2023 obj_access_cost_verify_per_byte: Some(200),
2024 obj_data_cost_refundable: Some(100),
2025 obj_metadata_cost_non_refundable: Some(50),
2026 gas_model_version: Some(1),
2027 storage_rebate_rate: Some(10000),
2028 reward_slashing_rate: Some(10000),
2030 storage_gas_price: Some(76),
2031 base_gas_price: None,
2032 validator_target_reward: Some(767_000 * 1_000_000_000),
2035 max_transactions_per_checkpoint: Some(10_000),
2036 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2037
2038 buffer_stake_for_protocol_upgrade_bps: Some(5000),
2040
2041 address_from_bytes_cost_base: Some(52),
2045 address_to_u256_cost_base: Some(52),
2047 address_from_u256_cost_base: Some(52),
2049
2050 config_read_setting_impl_cost_base: Some(100),
2053 config_read_setting_impl_cost_per_byte: Some(40),
2054
2055 dynamic_field_hash_type_and_key_cost_base: Some(100),
2059 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
2060 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
2061 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
2062 dynamic_field_add_child_object_cost_base: Some(100),
2065 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2066 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2067 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2068 dynamic_field_borrow_child_object_cost_base: Some(100),
2071 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2072 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2073 dynamic_field_remove_child_object_cost_base: Some(100),
2076 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2077 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2078 dynamic_field_has_child_object_cost_base: Some(100),
2081 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2084 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2085 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2086
2087 event_emit_cost_base: Some(52),
2090 event_emit_value_size_derivation_cost_per_byte: Some(2),
2091 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2092 event_emit_output_cost_per_byte: Some(10),
2093
2094 object_borrow_uid_cost_base: Some(52),
2097 object_delete_impl_cost_base: Some(52),
2099 object_record_new_uid_cost_base: Some(52),
2101
2102 transfer_transfer_internal_cost_base: Some(52),
2106 transfer_freeze_object_cost_base: Some(52),
2108 transfer_share_object_cost_base: Some(52),
2110 transfer_receive_object_cost_base: Some(52),
2111
2112 tx_context_derive_id_cost_base: Some(52),
2116 tx_context_fresh_id_cost_base: None,
2117 tx_context_sender_cost_base: None,
2118 tx_context_digest_cost_base: None,
2119 tx_context_epoch_cost_base: None,
2120 tx_context_epoch_timestamp_ms_cost_base: None,
2121 tx_context_sponsor_cost_base: None,
2122 tx_context_rgp_cost_base: None,
2123 tx_context_gas_price_cost_base: None,
2124 tx_context_gas_budget_cost_base: None,
2125 tx_context_ids_created_cost_base: None,
2126 tx_context_replace_cost_base: None,
2127
2128 types_is_one_time_witness_cost_base: Some(52),
2131 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2132 types_is_one_time_witness_type_cost_per_byte: Some(2),
2133
2134 validator_validate_metadata_cost_base: Some(52),
2138 validator_validate_metadata_data_cost_per_byte: Some(2),
2139
2140 crypto_invalid_arguments_cost: Some(100),
2142 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2144 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2145 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2146
2147 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2149 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2150 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2151
2152 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2154 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2155 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2156 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2157 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2158 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2159
2160 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2162
2163 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2165 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2166 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2167 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2168 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2169 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2170
2171 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2173 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2174 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2175 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2176 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2177 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2178
2179 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2181 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2182 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2183 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2184 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2185 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2186
2187 ecvrf_ecvrf_verify_cost_base: Some(52),
2189 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2190 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2191
2192 ed25519_ed25519_verify_cost_base: Some(52),
2194 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2195 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2196
2197 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2199 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2200
2201 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2203 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2204 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2205 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2206 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2207
2208 hash_blake2b256_cost_base: Some(52),
2210 hash_blake2b256_data_cost_per_byte: Some(2),
2211 hash_blake2b256_data_cost_per_block: Some(2),
2212 hash_keccak256_cost_base: Some(52),
2214 hash_keccak256_data_cost_per_byte: Some(2),
2215 hash_keccak256_data_cost_per_block: Some(2),
2216
2217 poseidon_bn254_cost_base: None,
2218 poseidon_bn254_cost_per_block: None,
2219
2220 hmac_hmac_sha3_256_cost_base: Some(52),
2222 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2223 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2224
2225 group_ops_bls12381_decode_scalar_cost: Some(52),
2227 group_ops_bls12381_decode_g1_cost: Some(52),
2228 group_ops_bls12381_decode_g2_cost: Some(52),
2229 group_ops_bls12381_decode_gt_cost: Some(52),
2230 group_ops_bls12381_scalar_add_cost: Some(52),
2231 group_ops_bls12381_g1_add_cost: Some(52),
2232 group_ops_bls12381_g2_add_cost: Some(52),
2233 group_ops_bls12381_gt_add_cost: Some(52),
2234 group_ops_bls12381_scalar_sub_cost: Some(52),
2235 group_ops_bls12381_g1_sub_cost: Some(52),
2236 group_ops_bls12381_g2_sub_cost: Some(52),
2237 group_ops_bls12381_gt_sub_cost: Some(52),
2238 group_ops_bls12381_scalar_mul_cost: Some(52),
2239 group_ops_bls12381_g1_mul_cost: Some(52),
2240 group_ops_bls12381_g2_mul_cost: Some(52),
2241 group_ops_bls12381_gt_mul_cost: Some(52),
2242 group_ops_bls12381_scalar_div_cost: Some(52),
2243 group_ops_bls12381_g1_div_cost: Some(52),
2244 group_ops_bls12381_g2_div_cost: Some(52),
2245 group_ops_bls12381_gt_div_cost: Some(52),
2246 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2247 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2248 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2249 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2250 group_ops_bls12381_g1_msm_base_cost: Some(52),
2251 group_ops_bls12381_g2_msm_base_cost: Some(52),
2252 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2253 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2254 group_ops_bls12381_msm_max_len: Some(32),
2255 group_ops_bls12381_pairing_cost: Some(52),
2256 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2257 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2258 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2259 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2260 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2261
2262 #[allow(deprecated)]
2264 check_zklogin_id_cost_base: Some(200),
2265 #[allow(deprecated)]
2266 check_zklogin_issuer_cost_base: Some(200),
2268
2269 vdf_verify_vdf_cost: None,
2270 vdf_hash_to_input_cost: None,
2271
2272 bcs_per_byte_serialized_cost: Some(2),
2273 bcs_legacy_min_output_size_cost: Some(1),
2274 bcs_failure_cost: Some(52),
2275 hash_sha2_256_base_cost: Some(52),
2276 hash_sha2_256_per_byte_cost: Some(2),
2277 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2278 hash_sha3_256_base_cost: Some(52),
2279 hash_sha3_256_per_byte_cost: Some(2),
2280 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2281 type_name_get_base_cost: Some(52),
2282 type_name_get_per_byte_cost: Some(2),
2283 string_check_utf8_base_cost: Some(52),
2284 string_check_utf8_per_byte_cost: Some(2),
2285 string_is_char_boundary_base_cost: Some(52),
2286 string_sub_string_base_cost: Some(52),
2287 string_sub_string_per_byte_cost: Some(2),
2288 string_index_of_base_cost: Some(52),
2289 string_index_of_per_byte_pattern_cost: Some(2),
2290 string_index_of_per_byte_searched_cost: Some(2),
2291 vector_empty_base_cost: Some(52),
2292 vector_length_base_cost: Some(52),
2293 vector_push_back_base_cost: Some(52),
2294 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2295 vector_borrow_base_cost: Some(52),
2296 vector_pop_back_base_cost: Some(52),
2297 vector_destroy_empty_base_cost: Some(52),
2298 vector_swap_base_cost: Some(52),
2299 debug_print_base_cost: Some(52),
2300 debug_print_stack_trace_base_cost: Some(52),
2301
2302 max_size_written_objects: Some(5 * 1000 * 1000),
2303 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2306
2307 max_move_identifier_len: Some(128),
2309 max_move_value_depth: Some(128),
2310 max_move_enum_variants: None,
2311
2312 gas_rounding_step: Some(1_000),
2313
2314 execution_version: Some(1),
2315
2316 max_event_emit_size_total: Some(
2319 256 * 250 * 1024, ),
2321
2322 consensus_bad_nodes_stake_threshold: Some(20),
2329
2330 #[allow(deprecated)]
2332 max_jwk_votes_per_validator_per_epoch: Some(240),
2333
2334 #[allow(deprecated)]
2335 max_age_of_jwk_in_epochs: Some(1),
2336
2337 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2341
2342 random_beacon_reduction_allowed_delta: Some(800),
2343
2344 random_beacon_reduction_lower_bound: Some(1000),
2345 random_beacon_dkg_timeout_round: Some(3000),
2346 random_beacon_min_round_interval_ms: Some(500),
2347
2348 random_beacon_dkg_version: Some(1),
2349
2350 consensus_max_num_transactions_in_block: Some(512),
2354
2355 max_deferral_rounds_for_congestion_control: Some(10),
2356
2357 min_checkpoint_interval_ms: Some(200),
2358
2359 checkpoint_summary_version_specific_data: Some(1),
2360
2361 max_soft_bundle_size: Some(5),
2362
2363 bridge_should_try_to_finalize_committee: None,
2364
2365 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2366
2367 max_committee_members_count: None,
2368
2369 consensus_gc_depth: None,
2370
2371 consensus_max_acknowledgments_per_block: None,
2372
2373 max_congestion_limit_overshoot_per_commit: None,
2374
2375 scorer_version: None,
2376
2377 auth_context_digest_cost_base: None,
2379 auth_context_tx_data_bytes_cost_base: None,
2380 auth_context_tx_data_bytes_cost_per_byte: None,
2381 auth_context_tx_commands_cost_base: None,
2382 auth_context_tx_commands_cost_per_byte: None,
2383 auth_context_tx_inputs_cost_base: None,
2384 auth_context_tx_inputs_cost_per_byte: None,
2385 auth_context_replace_cost_base: None,
2386 auth_context_replace_cost_per_byte: None,
2387 auth_context_authenticator_function_info_v1_cost_base: None,
2388 };
2391
2392 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2393
2394 {
2396 cfg.feature_flags
2397 .disable_invariant_violation_check_in_swap_loc = true;
2398 cfg.feature_flags.no_extraneous_module_bytes = true;
2399 cfg.feature_flags.hardened_otw_check = true;
2400 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2401 }
2402
2403 {
2405 #[allow(deprecated)]
2406 {
2407 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2408 }
2409 }
2410
2411 #[expect(deprecated)]
2415 {
2416 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2417 }
2418 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2420
2421 cfg.feature_flags.per_object_congestion_control_mode =
2422 PerObjectCongestionControlMode::TotalTxCount;
2423
2424 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2426
2427 if chain != Chain::Mainnet && chain != Chain::Testnet {
2429 cfg.feature_flags.enable_poseidon = true;
2430 cfg.poseidon_bn254_cost_base = Some(260);
2431 cfg.poseidon_bn254_cost_per_block = Some(10);
2432
2433 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2434
2435 cfg.feature_flags.enable_vdf = true;
2436 cfg.vdf_verify_vdf_cost = Some(1500);
2439 cfg.vdf_hash_to_input_cost = Some(100);
2440
2441 cfg.feature_flags.passkey_auth = true;
2442 }
2443
2444 for cur in 2..=version.0 {
2445 match cur {
2446 1 => unreachable!(),
2447 2 => {}
2449 3 => {
2450 cfg.feature_flags.relocate_event_module = true;
2451 }
2452 4 => {
2453 cfg.max_type_to_layout_nodes = Some(512);
2454 }
2455 5 => {
2456 cfg.feature_flags.protocol_defined_base_fee = true;
2457 cfg.base_gas_price = Some(1000);
2458
2459 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2460 cfg.feature_flags.convert_type_argument_error = true;
2461 cfg.feature_flags.native_charging_v2 = true;
2462
2463 if chain != Chain::Mainnet && chain != Chain::Testnet {
2464 cfg.feature_flags.uncompressed_g1_group_elements = true;
2465 }
2466
2467 cfg.gas_model_version = Some(2);
2468
2469 cfg.poseidon_bn254_cost_per_block = Some(388);
2470
2471 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2472 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2473 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2474 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2475 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2476 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2477 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2478 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2479
2480 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2482 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2483 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2484 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2485
2486 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2487 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2488 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2489 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2490 Some(8213);
2491 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2492 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2493 Some(9484);
2494
2495 cfg.hash_keccak256_cost_base = Some(10);
2496 cfg.hash_blake2b256_cost_base = Some(10);
2497
2498 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2500 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2501 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2502 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2503
2504 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2505 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2506 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2507 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2508
2509 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2510 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2511 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2512 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2513
2514 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2515 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2516 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2517 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2518
2519 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2520 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2521 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2522 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2523
2524 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2525 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2526
2527 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2528 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2529 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2530 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2531
2532 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2533 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2534 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2535 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2536 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2537
2538 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2539
2540 cfg.validator_validate_metadata_cost_base = Some(20000);
2541
2542 cfg.max_committee_members_count = Some(50);
2543 }
2544 6 => {
2545 cfg.max_ptb_value_size = Some(1024 * 1024);
2546 }
2547 7 => {
2548 }
2551 8 => {
2552 cfg.feature_flags.variant_nodes = true;
2553
2554 if chain != Chain::Mainnet {
2555 cfg.feature_flags.consensus_round_prober = true;
2557 cfg.feature_flags
2559 .consensus_distributed_vote_scoring_strategy = true;
2560 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2561 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2563 cfg.feature_flags
2565 .consensus_round_prober_probe_accepted_rounds = true;
2566 cfg.feature_flags.consensus_zstd_compression = true;
2568 cfg.consensus_gc_depth = Some(60);
2572 }
2573
2574 if chain != Chain::Testnet && chain != Chain::Mainnet {
2577 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2578 }
2579 }
2580 9 => {
2581 if chain != Chain::Mainnet {
2582 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2584 }
2585
2586 cfg.feature_flags.consensus_zstd_compression = true;
2588
2589 if chain != Chain::Testnet && chain != Chain::Mainnet {
2591 cfg.feature_flags.accept_passkey_in_multisig = true;
2592 }
2593
2594 cfg.bridge_should_try_to_finalize_committee = None;
2596 }
2597 10 => {
2598 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2601
2602 cfg.max_committee_members_count = Some(80);
2604
2605 cfg.feature_flags.consensus_round_prober = true;
2607 cfg.feature_flags
2609 .consensus_round_prober_probe_accepted_rounds = true;
2610 cfg.feature_flags
2612 .consensus_distributed_vote_scoring_strategy = true;
2613 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2615
2616 cfg.consensus_gc_depth = Some(60);
2621
2622 cfg.feature_flags.minimize_child_object_mutations = true;
2624
2625 if chain != Chain::Mainnet {
2626 cfg.feature_flags.consensus_batched_block_sync = true;
2628 }
2629
2630 if chain != Chain::Testnet && chain != Chain::Mainnet {
2631 cfg.feature_flags
2634 .congestion_control_gas_price_feedback_mechanism = true;
2635 }
2636
2637 cfg.feature_flags.validate_identifier_inputs = true;
2638 cfg.feature_flags.dependency_linkage_error = true;
2639 cfg.feature_flags.additional_multisig_checks = true;
2640 }
2641 11 => {
2642 }
2645 12 => {
2646 cfg.feature_flags
2649 .congestion_control_gas_price_feedback_mechanism = true;
2650
2651 cfg.feature_flags.normalize_ptb_arguments = true;
2653 }
2654 13 => {
2655 cfg.feature_flags.select_committee_from_eligible_validators = true;
2658 cfg.feature_flags.track_non_committee_eligible_validators = true;
2661
2662 if chain != Chain::Testnet && chain != Chain::Mainnet {
2663 cfg.feature_flags
2666 .select_committee_supporting_next_epoch_version = true;
2667 }
2668 }
2669 14 => {
2670 cfg.feature_flags.consensus_batched_block_sync = true;
2672
2673 if chain != Chain::Mainnet {
2674 cfg.feature_flags
2677 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2678 cfg.feature_flags
2682 .select_committee_supporting_next_epoch_version = true;
2683 }
2684 if chain != Chain::Testnet && chain != Chain::Mainnet {
2685 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2687 }
2688 }
2689 15 => {
2690 if chain != Chain::Mainnet && chain != Chain::Testnet {
2691 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2695 }
2696 }
2697 16 => {
2698 cfg.feature_flags
2701 .select_committee_supporting_next_epoch_version = true;
2702 cfg.feature_flags
2704 .consensus_commit_transactions_only_for_traversed_headers = true;
2705 }
2706 17 => {
2707 cfg.max_committee_members_count = Some(100);
2709 }
2710 18 => {
2711 if chain != Chain::Mainnet {
2712 cfg.feature_flags.passkey_auth = true;
2714 }
2715 }
2716 19 => {
2717 if chain != Chain::Testnet && chain != Chain::Mainnet {
2718 cfg.feature_flags
2721 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2722 cfg.feature_flags
2725 .separate_gas_price_feedback_mechanism_for_randomness = true;
2726 cfg.feature_flags.metadata_in_module_bytes = true;
2729 cfg.feature_flags.publish_package_metadata = true;
2730 cfg.feature_flags.enable_move_authentication = true;
2732 cfg.max_auth_gas = Some(250_000_000);
2734 cfg.transfer_receive_object_cost_base = Some(100);
2737 cfg.feature_flags.adjust_rewards_by_score = true;
2739 }
2740
2741 if chain != Chain::Mainnet {
2742 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2744
2745 cfg.feature_flags.calculate_validator_scores = true;
2747 cfg.scorer_version = Some(1);
2748 }
2749
2750 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
2752
2753 cfg.feature_flags.passkey_auth = true;
2755 }
2756 20 => {
2757 if chain != Chain::Testnet && chain != Chain::Mainnet {
2758 cfg.feature_flags
2760 .pass_calculated_validator_scores_to_advance_epoch = true;
2761 }
2762 }
2763 21 => {
2764 if chain != Chain::Testnet && chain != Chain::Mainnet {
2765 cfg.feature_flags.consensus_fast_commit_sync = true;
2767 }
2768 if chain != Chain::Mainnet {
2769 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2774 cfg.feature_flags
2777 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2778 cfg.feature_flags
2781 .separate_gas_price_feedback_mechanism_for_randomness = true;
2782 }
2783
2784 cfg.auth_context_digest_cost_base = Some(30);
2785 cfg.auth_context_tx_commands_cost_base = Some(30);
2786 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
2787 cfg.auth_context_tx_inputs_cost_base = Some(30);
2788 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
2789 cfg.auth_context_replace_cost_base = Some(30);
2790 cfg.auth_context_replace_cost_per_byte = Some(2);
2791
2792 if chain != Chain::Testnet && chain != Chain::Mainnet {
2793 cfg.max_auth_gas = Some(250_000);
2795 }
2796 }
2797 22 => {
2798 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2803 cfg.feature_flags
2806 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2807 cfg.feature_flags
2810 .separate_gas_price_feedback_mechanism_for_randomness = true;
2811
2812 if chain != Chain::Mainnet {
2813 cfg.feature_flags.metadata_in_module_bytes = true;
2816 cfg.feature_flags.publish_package_metadata = true;
2817 cfg.feature_flags.enable_move_authentication = true;
2819 cfg.max_auth_gas = Some(250_000);
2821 cfg.transfer_receive_object_cost_base = Some(100);
2824 }
2825
2826 if chain != Chain::Mainnet {
2827 cfg.feature_flags.consensus_fast_commit_sync = true;
2829 }
2830 }
2831 23 => {
2832 cfg.feature_flags.move_native_tx_context = true;
2834 cfg.tx_context_fresh_id_cost_base = Some(52);
2835 cfg.tx_context_sender_cost_base = Some(30);
2836 cfg.tx_context_digest_cost_base = Some(30);
2837 cfg.tx_context_epoch_cost_base = Some(30);
2838 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
2839 cfg.tx_context_sponsor_cost_base = Some(30);
2840 cfg.tx_context_rgp_cost_base = Some(30);
2841 cfg.tx_context_gas_price_cost_base = Some(30);
2842 cfg.tx_context_gas_budget_cost_base = Some(30);
2843 cfg.tx_context_ids_created_cost_base = Some(30);
2844 cfg.tx_context_replace_cost_base = Some(30);
2845 }
2846 24 => {
2847 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2849
2850 if chain != Chain::Testnet && chain != Chain::Mainnet {
2851 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2853 }
2854
2855 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
2858 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
2859
2860 cfg.feature_flags.additional_borrow_checks = true;
2862 }
2863 #[allow(deprecated)]
2864 25 => {
2865 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
2868 cfg.check_zklogin_id_cost_base = None;
2869 cfg.check_zklogin_issuer_cost_base = None;
2870 cfg.max_jwk_votes_per_validator_per_epoch = None;
2871 cfg.max_age_of_jwk_in_epochs = None;
2872 }
2873 26 => {
2874 }
2877 27 => {
2878 if chain != Chain::Mainnet {
2879 cfg.feature_flags.consensus_block_restrictions = true;
2882 }
2883
2884 if chain != Chain::Testnet && chain != Chain::Mainnet {
2885 cfg.feature_flags
2887 .pre_consensus_sponsor_only_move_authentication = true;
2888 }
2889 }
2890 28 => {
2891 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
2896
2897 cfg.feature_flags.metadata_in_module_bytes = true;
2900 cfg.feature_flags.publish_package_metadata = true;
2901 cfg.feature_flags.enable_move_authentication = true;
2903 cfg.transfer_receive_object_cost_base = Some(100);
2906
2907 if chain != Chain::Unknown {
2908 cfg.max_auth_gas = Some(20_000);
2910 }
2911
2912 if chain != Chain::Mainnet {
2913 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2915 cfg.feature_flags
2917 .pre_consensus_sponsor_only_move_authentication = true;
2918 }
2919 }
2920 29 => {
2921 cfg.feature_flags.always_advance_dkg_to_resolution = true;
2927
2928 cfg.feature_flags
2931 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2932 }
2933 _ => panic!("unsupported version {version:?}"),
2944 }
2945 }
2946 cfg
2947 }
2948
2949 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
2955 let (
2956 max_back_edges_per_function,
2957 max_back_edges_per_module,
2958 sanity_check_with_regex_reference_safety,
2959 ) = if let Some((
2960 max_back_edges_per_function,
2961 max_back_edges_per_module,
2962 sanity_check_with_regex_reference_safety,
2963 )) = signing_limits
2964 {
2965 (
2966 Some(max_back_edges_per_function),
2967 Some(max_back_edges_per_module),
2968 Some(sanity_check_with_regex_reference_safety),
2969 )
2970 } else {
2971 (None, None, None)
2972 };
2973
2974 let additional_borrow_checks = if signing_limits.is_some() {
2975 true
2978 } else {
2979 self.additional_borrow_checks()
2980 };
2981
2982 VerifierConfig {
2983 max_loop_depth: Some(self.max_loop_depth() as usize),
2984 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2985 max_function_parameters: Some(self.max_function_parameters() as usize),
2986 max_basic_blocks: Some(self.max_basic_blocks() as usize),
2987 max_value_stack_size: self.max_value_stack_size() as usize,
2988 max_type_nodes: Some(self.max_type_nodes() as usize),
2989 max_push_size: Some(self.max_push_size() as usize),
2990 max_dependency_depth: Some(self.max_dependency_depth() as usize),
2991 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2992 max_function_definitions: Some(self.max_function_definitions() as usize),
2993 max_data_definitions: Some(self.max_struct_definitions() as usize),
2994 max_constant_vector_len: Some(self.max_move_vector_len()),
2995 max_back_edges_per_function,
2996 max_back_edges_per_module,
2997 max_basic_blocks_in_script: None,
2998 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
3002 max_variants_in_enum: self.max_move_enum_variants_as_option(),
3003 additional_borrow_checks,
3004 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
3005 .map(|limit| limit as u128),
3006 }
3007 }
3008
3009 pub fn apply_overrides_for_testing(
3014 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
3015 ) -> OverrideGuard {
3016 CONFIG_OVERRIDE.with(|ovr| {
3017 let mut cur = ovr.borrow_mut();
3018 assert!(cur.is_none(), "config override already present");
3019 *cur = Some(Box::new(override_fn));
3020 OverrideGuard
3021 })
3022 }
3023}
3024
3025impl ProtocolConfig {
3030 pub fn set_per_object_congestion_control_mode_for_testing(
3031 &mut self,
3032 val: PerObjectCongestionControlMode,
3033 ) {
3034 self.feature_flags.per_object_congestion_control_mode = val;
3035 }
3036
3037 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
3038 self.feature_flags.consensus_choice = val;
3039 }
3040
3041 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
3042 self.feature_flags.consensus_network = val;
3043 }
3044
3045 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
3046 self.feature_flags.passkey_auth = val
3047 }
3048
3049 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
3050 self.feature_flags
3051 .disallow_new_modules_in_deps_only_packages = val;
3052 }
3053
3054 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
3055 self.feature_flags.consensus_round_prober = val;
3056 }
3057
3058 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
3059 self.feature_flags
3060 .consensus_distributed_vote_scoring_strategy = val;
3061 }
3062
3063 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
3064 self.consensus_gc_depth = Some(val);
3065 }
3066
3067 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
3068 self.feature_flags.consensus_linearize_subdag_v2 = val;
3069 }
3070
3071 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
3072 self.feature_flags
3073 .consensus_round_prober_probe_accepted_rounds = val;
3074 }
3075
3076 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
3077 self.feature_flags.accept_passkey_in_multisig = val;
3078 }
3079
3080 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
3081 self.feature_flags.consensus_smart_ancestor_selection = val;
3082 }
3083
3084 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
3085 self.feature_flags.consensus_batched_block_sync = val;
3086 }
3087
3088 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
3089 self.feature_flags
3090 .congestion_control_min_free_execution_slot = val;
3091 }
3092
3093 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
3094 self.feature_flags
3095 .congestion_control_gas_price_feedback_mechanism = val;
3096 }
3097
3098 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
3099 self.feature_flags.select_committee_from_eligible_validators = val;
3100 }
3101
3102 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
3103 self.feature_flags.track_non_committee_eligible_validators = val;
3104 }
3105
3106 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
3107 self.feature_flags
3108 .select_committee_supporting_next_epoch_version = val;
3109 }
3110
3111 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
3112 &mut self,
3113 val: bool,
3114 ) {
3115 self.feature_flags
3116 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3117 }
3118
3119 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3120 &mut self,
3121 val: bool,
3122 ) {
3123 self.feature_flags
3124 .consensus_commit_transactions_only_for_traversed_headers = val;
3125 }
3126
3127 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3128 &mut self,
3129 val: bool,
3130 ) {
3131 self.feature_flags
3132 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3133 }
3134
3135 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3136 &mut self,
3137 val: bool,
3138 ) {
3139 self.feature_flags
3140 .separate_gas_price_feedback_mechanism_for_randomness = val;
3141 }
3142
3143 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3144 self.feature_flags.metadata_in_module_bytes = val;
3145 }
3146
3147 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3148 self.feature_flags.publish_package_metadata = val;
3149 }
3150
3151 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3152 self.feature_flags.enable_move_authentication = val;
3153 }
3154
3155 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3156 self.feature_flags.enable_move_authentication_for_sponsor = val;
3157 }
3158
3159 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3160 self.feature_flags.consensus_fast_commit_sync = val;
3161 }
3162
3163 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3164 self.feature_flags.consensus_block_restrictions = val;
3165 }
3166
3167 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3168 self.feature_flags
3169 .pre_consensus_sponsor_only_move_authentication = val;
3170 }
3171
3172 pub fn set_consensus_starfish_speed_for_testing(&mut self, val: bool) {
3173 self.feature_flags.consensus_starfish_speed = val;
3174 }
3175
3176 pub fn set_always_advance_dkg_to_resolution_for_testing(&mut self, val: bool) {
3177 self.feature_flags.always_advance_dkg_to_resolution = val;
3178 }
3179
3180 pub fn set_enable_white_flag_flow_for_testing(&mut self, val: bool) {
3181 self.feature_flags.enable_white_flag_flow = val;
3182 }
3183}
3184
3185type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
3186
3187thread_local! {
3188 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
3189}
3190
3191#[must_use]
3192pub struct OverrideGuard;
3193
3194impl Drop for OverrideGuard {
3195 fn drop(&mut self) {
3196 info!("restoring override fn");
3197 CONFIG_OVERRIDE.with(|ovr| {
3198 *ovr.borrow_mut() = None;
3199 });
3200 }
3201}
3202
3203#[derive(PartialEq, Eq)]
3207pub enum LimitThresholdCrossed {
3208 None,
3209 Soft(u128, u128),
3210 Hard(u128, u128),
3211}
3212
3213pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
3216 x: T,
3217 soft_limit: U,
3218 hard_limit: V,
3219) -> LimitThresholdCrossed {
3220 let x: V = x.into();
3221 let soft_limit: V = soft_limit.into();
3222
3223 debug_assert!(soft_limit <= hard_limit);
3224
3225 if x >= hard_limit {
3228 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
3229 } else if x < soft_limit {
3230 LimitThresholdCrossed::None
3231 } else {
3232 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
3233 }
3234}
3235
3236#[macro_export]
3237macro_rules! check_limit {
3238 ($x:expr, $hard:expr) => {
3239 check_limit!($x, $hard, $hard)
3240 };
3241 ($x:expr, $soft:expr, $hard:expr) => {
3242 check_limit_in_range($x as u64, $soft, $hard)
3243 };
3244}
3245
3246#[macro_export]
3250macro_rules! check_limit_by_meter {
3251 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
3252 let (h, metered_str) = if $is_metered {
3254 ($metered_limit, "metered")
3255 } else {
3256 ($unmetered_hard_limit, "unmetered")
3258 };
3259 use iota_protocol_config::check_limit_in_range;
3260 let result = check_limit_in_range($x as u64, $metered_limit, h);
3261 match result {
3262 LimitThresholdCrossed::None => {}
3263 LimitThresholdCrossed::Soft(_, _) => {
3264 $metric.with_label_values(&[metered_str, "soft"]).inc();
3265 }
3266 LimitThresholdCrossed::Hard(_, _) => {
3267 $metric.with_label_values(&[metered_str, "hard"]).inc();
3268 }
3269 };
3270 result
3271 }};
3272}
3273
3274#[cfg(all(test, not(msim)))]
3275mod test {
3276 use insta::assert_yaml_snapshot;
3277
3278 use super::*;
3279
3280 #[test]
3281 fn snapshot_tests() {
3282 println!("\n============================================================================");
3283 println!("! !");
3284 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
3285 println!("! !");
3286 println!("============================================================================\n");
3287 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
3288 let chain_str = match chain_id {
3293 Chain::Unknown => "".to_string(),
3294 _ => format!("{chain_id:?}_"),
3295 };
3296 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
3297 let cur = ProtocolVersion::new(i);
3298 assert_yaml_snapshot!(
3299 format!("{}version_{}", chain_str, cur.as_u64()),
3300 ProtocolConfig::get_for_version(cur, *chain_id)
3301 );
3302 }
3303 }
3304 }
3305
3306 #[test]
3307 fn test_getters() {
3308 let prot: ProtocolConfig =
3309 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3310 assert_eq!(
3311 prot.max_arguments(),
3312 prot.max_arguments_as_option().unwrap()
3313 );
3314 }
3315
3316 #[test]
3317 fn test_setters() {
3318 let mut prot: ProtocolConfig =
3319 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3320 prot.set_max_arguments_for_testing(123);
3321 assert_eq!(prot.max_arguments(), 123);
3322
3323 prot.set_max_arguments_from_str_for_testing("321".to_string());
3324 assert_eq!(prot.max_arguments(), 321);
3325
3326 prot.disable_max_arguments_for_testing();
3327 assert_eq!(prot.max_arguments_as_option(), None);
3328
3329 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
3330 assert_eq!(prot.max_arguments(), 456);
3331 }
3332
3333 #[test]
3334 #[should_panic(expected = "unsupported version")]
3335 fn max_version_test() {
3336 let _ = ProtocolConfig::get_for_version_impl(
3339 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
3340 Chain::Unknown,
3341 );
3342 }
3343
3344 #[test]
3345 fn lookup_by_string_test() {
3346 let prot: ProtocolConfig =
3347 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3348 assert!(prot.lookup_attr("some random string".to_string()).is_none());
3350
3351 assert!(
3352 prot.lookup_attr("max_arguments".to_string())
3353 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
3354 );
3355
3356 assert!(
3358 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3359 .is_none()
3360 );
3361 assert!(
3362 prot.attr_map()
3363 .get("poseidon_bn254_cost_base")
3364 .unwrap()
3365 .is_none()
3366 );
3367
3368 let prot: ProtocolConfig =
3370 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3371
3372 assert!(
3373 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3374 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3375 );
3376 assert!(
3377 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
3378 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3379 );
3380
3381 let prot: ProtocolConfig =
3383 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3384 assert!(
3386 prot.feature_flags
3387 .lookup_attr("some random string".to_owned())
3388 .is_none()
3389 );
3390 assert!(
3391 !prot
3392 .feature_flags
3393 .attr_map()
3394 .contains_key("some random string")
3395 );
3396
3397 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
3399 assert!(
3400 prot.feature_flags
3401 .attr_map()
3402 .get("enable_poseidon")
3403 .unwrap()
3404 == &false
3405 );
3406 let prot: ProtocolConfig =
3407 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3408 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
3410 assert!(
3411 prot.feature_flags
3412 .attr_map()
3413 .get("enable_poseidon")
3414 .unwrap()
3415 == &true
3416 );
3417 }
3418
3419 #[test]
3420 fn limit_range_fn_test() {
3421 let low = 100u32;
3422 let high = 10000u64;
3423
3424 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
3425 assert!(matches!(
3426 check_limit!(255u16, low, high),
3427 LimitThresholdCrossed::Soft(255u128, 100)
3428 ));
3429 assert!(matches!(
3436 check_limit!(2550000u64, low, high),
3437 LimitThresholdCrossed::Hard(2550000, 10000)
3438 ));
3439
3440 assert!(matches!(
3441 check_limit!(2550000u64, high, high),
3442 LimitThresholdCrossed::Hard(2550000, 10000)
3443 ));
3444
3445 assert!(matches!(
3446 check_limit!(1u8, high),
3447 LimitThresholdCrossed::None
3448 ));
3449
3450 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
3451
3452 assert!(matches!(
3453 check_limit!(2550000u64, high),
3454 LimitThresholdCrossed::Hard(2550000, 10000)
3455 ));
3456 }
3457}