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 = 28;
23
24pub const PROTOCOL_VERSION_IIP8: u64 = 20;
26#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
157pub struct ProtocolVersion(u64);
158
159impl ProtocolVersion {
160 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
166
167 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
168
169 #[cfg(not(msim))]
170 const MAX_ALLOWED: Self = Self::MAX;
171
172 #[cfg(msim)]
175 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
176
177 pub fn new(v: u64) -> Self {
178 Self(v)
179 }
180
181 pub const fn as_u64(&self) -> u64 {
182 self.0
183 }
184
185 pub fn max() -> Self {
188 Self::MAX
189 }
190}
191
192impl From<u64> for ProtocolVersion {
193 fn from(v: u64) -> Self {
194 Self::new(v)
195 }
196}
197
198impl std::ops::Sub<u64> for ProtocolVersion {
199 type Output = Self;
200 fn sub(self, rhs: u64) -> Self::Output {
201 Self::new(self.0 - rhs)
202 }
203}
204
205impl std::ops::Add<u64> for ProtocolVersion {
206 type Output = Self;
207 fn add(self, rhs: u64) -> Self::Output {
208 Self::new(self.0 + rhs)
209 }
210}
211
212#[derive(
213 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
214)]
215pub enum Chain {
216 Mainnet,
217 Testnet,
218 #[default]
219 Unknown,
220}
221
222impl Chain {
223 pub fn as_str(self) -> &'static str {
224 match self {
225 Chain::Mainnet => "mainnet",
226 Chain::Testnet => "testnet",
227 Chain::Unknown => "unknown",
228 }
229 }
230}
231
232pub struct Error(pub String);
233
234#[derive(Default, Clone, Serialize, Deserialize, Debug, ProtocolConfigFeatureFlagsGetters)]
238struct FeatureFlags {
239 #[serde(skip_serializing_if = "is_true")]
245 disable_invariant_violation_check_in_swap_loc: bool,
246
247 #[serde(skip_serializing_if = "is_true")]
250 no_extraneous_module_bytes: bool,
251
252 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
254 consensus_transaction_ordering: ConsensusTransactionOrdering,
255
256 #[serde(skip_serializing_if = "is_true")]
259 hardened_otw_check: bool,
260
261 #[serde(skip_serializing_if = "is_false")]
263 enable_poseidon: bool,
264
265 #[serde(skip_serializing_if = "is_false")]
267 enable_group_ops_native_function_msm: bool,
268
269 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
271 per_object_congestion_control_mode: PerObjectCongestionControlMode,
272
273 #[serde(
275 default = "ConsensusChoice::mysticeti_deprecated",
276 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
277 )]
278 consensus_choice: ConsensusChoice,
279
280 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
282 consensus_network: ConsensusNetwork,
283
284 #[deprecated]
286 #[serde(skip_serializing_if = "Option::is_none")]
287 zklogin_max_epoch_upper_bound_delta: Option<u64>,
288
289 #[serde(skip_serializing_if = "is_false")]
291 enable_vdf: bool,
292
293 #[serde(skip_serializing_if = "is_false")]
295 passkey_auth: bool,
296
297 #[serde(skip_serializing_if = "is_true")]
300 rethrow_serialization_type_layout_errors: bool,
301
302 #[serde(skip_serializing_if = "is_false")]
304 relocate_event_module: bool,
305
306 #[serde(skip_serializing_if = "is_false")]
308 protocol_defined_base_fee: bool,
309
310 #[serde(skip_serializing_if = "is_false")]
312 uncompressed_g1_group_elements: bool,
313
314 #[serde(skip_serializing_if = "is_false")]
316 disallow_new_modules_in_deps_only_packages: bool,
317
318 #[serde(skip_serializing_if = "is_false")]
320 native_charging_v2: bool,
321
322 #[serde(skip_serializing_if = "is_false")]
324 convert_type_argument_error: bool,
325
326 #[serde(skip_serializing_if = "is_false")]
328 consensus_round_prober: bool,
329
330 #[serde(skip_serializing_if = "is_false")]
332 consensus_distributed_vote_scoring_strategy: bool,
333
334 #[serde(skip_serializing_if = "is_false")]
338 consensus_linearize_subdag_v2: bool,
339
340 #[serde(skip_serializing_if = "is_false")]
342 variant_nodes: bool,
343
344 #[serde(skip_serializing_if = "is_false")]
346 consensus_smart_ancestor_selection: bool,
347
348 #[serde(skip_serializing_if = "is_false")]
350 consensus_round_prober_probe_accepted_rounds: bool,
351
352 #[serde(skip_serializing_if = "is_false")]
354 consensus_zstd_compression: bool,
355
356 #[serde(skip_serializing_if = "is_false")]
359 congestion_control_min_free_execution_slot: bool,
360
361 #[serde(skip_serializing_if = "is_false")]
363 accept_passkey_in_multisig: bool,
364
365 #[serde(skip_serializing_if = "is_false")]
367 consensus_batched_block_sync: bool,
368
369 #[serde(skip_serializing_if = "is_false")]
372 congestion_control_gas_price_feedback_mechanism: bool,
373
374 #[serde(skip_serializing_if = "is_false")]
376 validate_identifier_inputs: bool,
377
378 #[serde(skip_serializing_if = "is_false")]
381 minimize_child_object_mutations: bool,
382
383 #[serde(skip_serializing_if = "is_false")]
385 dependency_linkage_error: bool,
386
387 #[serde(skip_serializing_if = "is_false")]
389 additional_multisig_checks: bool,
390
391 #[serde(skip_serializing_if = "is_false")]
394 normalize_ptb_arguments: bool,
395
396 #[serde(skip_serializing_if = "is_false")]
400 select_committee_from_eligible_validators: bool,
401
402 #[serde(skip_serializing_if = "is_false")]
409 track_non_committee_eligible_validators: bool,
410
411 #[serde(skip_serializing_if = "is_false")]
417 select_committee_supporting_next_epoch_version: bool,
418
419 #[serde(skip_serializing_if = "is_false")]
423 consensus_median_timestamp_with_checkpoint_enforcement: bool,
424
425 #[serde(skip_serializing_if = "is_false")]
427 consensus_commit_transactions_only_for_traversed_headers: bool,
428
429 #[serde(skip_serializing_if = "is_false")]
431 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
432
433 #[serde(skip_serializing_if = "is_false")]
436 separate_gas_price_feedback_mechanism_for_randomness: bool,
437
438 #[serde(skip_serializing_if = "is_false")]
441 metadata_in_module_bytes: bool,
442
443 #[serde(skip_serializing_if = "is_false")]
445 publish_package_metadata: bool,
446
447 #[serde(skip_serializing_if = "is_false")]
449 enable_move_authentication: bool,
450
451 #[serde(skip_serializing_if = "is_false")]
453 enable_move_authentication_for_sponsor: bool,
454
455 #[serde(skip_serializing_if = "is_false")]
457 pass_validator_scores_to_advance_epoch: bool,
458
459 #[serde(skip_serializing_if = "is_false")]
461 calculate_validator_scores: bool,
462
463 #[serde(skip_serializing_if = "is_false")]
465 adjust_rewards_by_score: bool,
466
467 #[serde(skip_serializing_if = "is_false")]
470 pass_calculated_validator_scores_to_advance_epoch: bool,
471
472 #[serde(skip_serializing_if = "is_false")]
477 consensus_fast_commit_sync: bool,
478
479 #[serde(skip_serializing_if = "is_false")]
482 consensus_block_restrictions: bool,
483
484 #[serde(skip_serializing_if = "is_false")]
486 move_native_tx_context: bool,
487
488 #[serde(skip_serializing_if = "is_false")]
490 additional_borrow_checks: bool,
491
492 #[serde(skip_serializing_if = "is_false")]
494 pre_consensus_sponsor_only_move_authentication: bool,
495}
496
497fn is_true(b: &bool) -> bool {
498 *b
499}
500
501fn is_false(b: &bool) -> bool {
502 !b
503}
504
505#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
507pub enum ConsensusTransactionOrdering {
508 #[default]
511 None,
512 ByGasPrice,
514}
515
516impl ConsensusTransactionOrdering {
517 pub fn is_none(&self) -> bool {
518 matches!(self, ConsensusTransactionOrdering::None)
519 }
520}
521
522#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
524pub enum PerObjectCongestionControlMode {
525 #[default]
526 None, TotalGasBudget, TotalTxCount, }
530
531impl PerObjectCongestionControlMode {
532 pub fn is_none(&self) -> bool {
533 matches!(self, PerObjectCongestionControlMode::None)
534 }
535}
536
537#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
539pub enum ConsensusChoice {
540 #[deprecated(note = "Mysticeti was replaced by Starfish")]
543 MysticetiDeprecated,
544 #[default]
545 Starfish,
546}
547
548#[expect(deprecated)]
549impl ConsensusChoice {
550 fn mysticeti_deprecated() -> Self {
557 ConsensusChoice::MysticetiDeprecated
558 }
559
560 pub fn is_mysticeti_deprecated(&self) -> bool {
561 matches!(self, ConsensusChoice::MysticetiDeprecated)
562 }
563 pub fn is_starfish(&self) -> bool {
564 matches!(self, ConsensusChoice::Starfish)
565 }
566}
567
568#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
570pub enum ConsensusNetwork {
571 #[default]
572 Tonic,
573}
574
575impl ConsensusNetwork {
576 pub fn is_tonic(&self) -> bool {
577 matches!(self, ConsensusNetwork::Tonic)
578 }
579}
580
581#[skip_serializing_none]
615#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
616pub struct ProtocolConfig {
617 pub version: ProtocolVersion,
618
619 feature_flags: FeatureFlags,
620
621 max_tx_size_bytes: Option<u64>,
626
627 max_input_objects: Option<u64>,
630
631 max_size_written_objects: Option<u64>,
636 max_size_written_objects_system_tx: Option<u64>,
640
641 max_serialized_tx_effects_size_bytes: Option<u64>,
643
644 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
646
647 max_gas_payment_objects: Option<u32>,
649
650 max_modules_in_publish: Option<u32>,
652
653 max_package_dependencies: Option<u32>,
655
656 max_arguments: Option<u32>,
659
660 max_type_arguments: Option<u32>,
662
663 max_type_argument_depth: Option<u32>,
665
666 max_pure_argument_size: Option<u32>,
668
669 max_programmable_tx_commands: Option<u32>,
671
672 move_binary_format_version: Option<u32>,
678 min_move_binary_format_version: Option<u32>,
679
680 binary_module_handles: Option<u16>,
682 binary_struct_handles: Option<u16>,
683 binary_function_handles: Option<u16>,
684 binary_function_instantiations: Option<u16>,
685 binary_signatures: Option<u16>,
686 binary_constant_pool: Option<u16>,
687 binary_identifiers: Option<u16>,
688 binary_address_identifiers: Option<u16>,
689 binary_struct_defs: Option<u16>,
690 binary_struct_def_instantiations: Option<u16>,
691 binary_function_defs: Option<u16>,
692 binary_field_handles: Option<u16>,
693 binary_field_instantiations: Option<u16>,
694 binary_friend_decls: Option<u16>,
695 binary_enum_defs: Option<u16>,
696 binary_enum_def_instantiations: Option<u16>,
697 binary_variant_handles: Option<u16>,
698 binary_variant_instantiation_handles: Option<u16>,
699
700 max_move_object_size: Option<u64>,
703
704 max_move_package_size: Option<u64>,
709
710 max_publish_or_upgrade_per_ptb: Option<u64>,
713
714 max_tx_gas: Option<u64>,
716
717 max_auth_gas: Option<u64>,
719
720 max_gas_price: Option<u64>,
723
724 max_gas_computation_bucket: Option<u64>,
727
728 gas_rounding_step: Option<u64>,
730
731 max_loop_depth: Option<u64>,
733
734 max_generic_instantiation_length: Option<u64>,
737
738 max_function_parameters: Option<u64>,
741
742 max_basic_blocks: Option<u64>,
745
746 max_value_stack_size: Option<u64>,
748
749 max_type_nodes: Option<u64>,
753
754 max_push_size: Option<u64>,
757
758 max_struct_definitions: Option<u64>,
761
762 max_function_definitions: Option<u64>,
765
766 max_fields_in_struct: Option<u64>,
769
770 max_dependency_depth: Option<u64>,
773
774 max_num_event_emit: Option<u64>,
777
778 max_num_new_move_object_ids: Option<u64>,
781
782 max_num_new_move_object_ids_system_tx: Option<u64>,
785
786 max_num_deleted_move_object_ids: Option<u64>,
789
790 max_num_deleted_move_object_ids_system_tx: Option<u64>,
793
794 max_num_transferred_move_object_ids: Option<u64>,
797
798 max_num_transferred_move_object_ids_system_tx: Option<u64>,
801
802 max_event_emit_size: Option<u64>,
804
805 max_event_emit_size_total: Option<u64>,
807
808 max_move_vector_len: Option<u64>,
811
812 max_move_identifier_len: Option<u64>,
815
816 max_move_value_depth: Option<u64>,
818
819 max_move_enum_variants: Option<u64>,
822
823 max_back_edges_per_function: Option<u64>,
826
827 max_back_edges_per_module: Option<u64>,
830
831 max_verifier_meter_ticks_per_function: Option<u64>,
834
835 max_meter_ticks_per_module: Option<u64>,
838
839 max_meter_ticks_per_package: Option<u64>,
842
843 object_runtime_max_num_cached_objects: Option<u64>,
850
851 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
854
855 object_runtime_max_num_store_entries: Option<u64>,
858
859 object_runtime_max_num_store_entries_system_tx: Option<u64>,
862
863 base_tx_cost_fixed: Option<u64>,
868
869 package_publish_cost_fixed: Option<u64>,
873
874 base_tx_cost_per_byte: Option<u64>,
878
879 package_publish_cost_per_byte: Option<u64>,
881
882 obj_access_cost_read_per_byte: Option<u64>,
884
885 obj_access_cost_mutate_per_byte: Option<u64>,
887
888 obj_access_cost_delete_per_byte: Option<u64>,
890
891 obj_access_cost_verify_per_byte: Option<u64>,
901
902 max_type_to_layout_nodes: Option<u64>,
904
905 max_ptb_value_size: Option<u64>,
907
908 gas_model_version: Option<u64>,
913
914 obj_data_cost_refundable: Option<u64>,
920
921 obj_metadata_cost_non_refundable: Option<u64>,
925
926 storage_rebate_rate: Option<u64>,
932
933 reward_slashing_rate: Option<u64>,
936
937 storage_gas_price: Option<u64>,
939
940 base_gas_price: Option<u64>,
942
943 validator_target_reward: Option<u64>,
945
946 max_transactions_per_checkpoint: Option<u64>,
953
954 max_checkpoint_size_bytes: Option<u64>,
958
959 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
965
966 address_from_bytes_cost_base: Option<u64>,
971 address_to_u256_cost_base: Option<u64>,
973 address_from_u256_cost_base: Option<u64>,
975
976 config_read_setting_impl_cost_base: Option<u64>,
981 config_read_setting_impl_cost_per_byte: Option<u64>,
982
983 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
987 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
988 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
989 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
990 dynamic_field_add_child_object_cost_base: Option<u64>,
993 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
994 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
995 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
996 dynamic_field_borrow_child_object_cost_base: Option<u64>,
999 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1000 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1001 dynamic_field_remove_child_object_cost_base: Option<u64>,
1004 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1005 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1006 dynamic_field_has_child_object_cost_base: Option<u64>,
1009 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1012 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1013 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1014
1015 event_emit_cost_base: Option<u64>,
1018 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1019 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1020 event_emit_output_cost_per_byte: Option<u64>,
1021
1022 object_borrow_uid_cost_base: Option<u64>,
1025 object_delete_impl_cost_base: Option<u64>,
1027 object_record_new_uid_cost_base: Option<u64>,
1029
1030 transfer_transfer_internal_cost_base: Option<u64>,
1033 transfer_freeze_object_cost_base: Option<u64>,
1035 transfer_share_object_cost_base: Option<u64>,
1037 transfer_receive_object_cost_base: Option<u64>,
1040
1041 tx_context_derive_id_cost_base: Option<u64>,
1044 tx_context_fresh_id_cost_base: Option<u64>,
1045 tx_context_sender_cost_base: Option<u64>,
1046 tx_context_digest_cost_base: Option<u64>,
1047 tx_context_epoch_cost_base: Option<u64>,
1048 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1049 tx_context_sponsor_cost_base: Option<u64>,
1050 tx_context_rgp_cost_base: Option<u64>,
1051 tx_context_gas_price_cost_base: Option<u64>,
1052 tx_context_gas_budget_cost_base: Option<u64>,
1053 tx_context_ids_created_cost_base: Option<u64>,
1054 tx_context_replace_cost_base: Option<u64>,
1055
1056 types_is_one_time_witness_cost_base: Option<u64>,
1059 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1060 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1061
1062 validator_validate_metadata_cost_base: Option<u64>,
1065 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1066
1067 crypto_invalid_arguments_cost: Option<u64>,
1069 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1071 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1072 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1073
1074 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1076 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1077 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1078
1079 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1081 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1082 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1083 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1084 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1085 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1086
1087 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1089
1090 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1092 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1093 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1094 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1095 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1096 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1097
1098 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1100 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1101 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1102 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1103 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1104 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1105
1106 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1108 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1109 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1110 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1111 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1112 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1113
1114 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1116 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1117 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1118
1119 ed25519_ed25519_verify_cost_base: Option<u64>,
1121 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1122 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1123
1124 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1126 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1127
1128 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1130 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1131 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1132 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1133 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1134
1135 hash_blake2b256_cost_base: Option<u64>,
1137 hash_blake2b256_data_cost_per_byte: Option<u64>,
1138 hash_blake2b256_data_cost_per_block: Option<u64>,
1139
1140 hash_keccak256_cost_base: Option<u64>,
1142 hash_keccak256_data_cost_per_byte: Option<u64>,
1143 hash_keccak256_data_cost_per_block: Option<u64>,
1144
1145 poseidon_bn254_cost_base: Option<u64>,
1147 poseidon_bn254_cost_per_block: Option<u64>,
1148
1149 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1151 group_ops_bls12381_decode_g1_cost: Option<u64>,
1152 group_ops_bls12381_decode_g2_cost: Option<u64>,
1153 group_ops_bls12381_decode_gt_cost: Option<u64>,
1154 group_ops_bls12381_scalar_add_cost: Option<u64>,
1155 group_ops_bls12381_g1_add_cost: Option<u64>,
1156 group_ops_bls12381_g2_add_cost: Option<u64>,
1157 group_ops_bls12381_gt_add_cost: Option<u64>,
1158 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1159 group_ops_bls12381_g1_sub_cost: Option<u64>,
1160 group_ops_bls12381_g2_sub_cost: Option<u64>,
1161 group_ops_bls12381_gt_sub_cost: Option<u64>,
1162 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1163 group_ops_bls12381_g1_mul_cost: Option<u64>,
1164 group_ops_bls12381_g2_mul_cost: Option<u64>,
1165 group_ops_bls12381_gt_mul_cost: Option<u64>,
1166 group_ops_bls12381_scalar_div_cost: Option<u64>,
1167 group_ops_bls12381_g1_div_cost: Option<u64>,
1168 group_ops_bls12381_g2_div_cost: Option<u64>,
1169 group_ops_bls12381_gt_div_cost: Option<u64>,
1170 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1171 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1172 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1173 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1174 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1175 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1176 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1177 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1178 group_ops_bls12381_msm_max_len: Option<u32>,
1179 group_ops_bls12381_pairing_cost: Option<u64>,
1180 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1181 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1182 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1183 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1184 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1185
1186 hmac_hmac_sha3_256_cost_base: Option<u64>,
1188 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1189 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1190
1191 #[deprecated]
1193 check_zklogin_id_cost_base: Option<u64>,
1194 #[deprecated]
1196 check_zklogin_issuer_cost_base: Option<u64>,
1197
1198 vdf_verify_vdf_cost: Option<u64>,
1199 vdf_hash_to_input_cost: Option<u64>,
1200
1201 bcs_per_byte_serialized_cost: Option<u64>,
1203 bcs_legacy_min_output_size_cost: Option<u64>,
1204 bcs_failure_cost: Option<u64>,
1205
1206 hash_sha2_256_base_cost: Option<u64>,
1207 hash_sha2_256_per_byte_cost: Option<u64>,
1208 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1209 hash_sha3_256_base_cost: Option<u64>,
1210 hash_sha3_256_per_byte_cost: Option<u64>,
1211 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1212 type_name_get_base_cost: Option<u64>,
1213 type_name_get_per_byte_cost: Option<u64>,
1214
1215 string_check_utf8_base_cost: Option<u64>,
1216 string_check_utf8_per_byte_cost: Option<u64>,
1217 string_is_char_boundary_base_cost: Option<u64>,
1218 string_sub_string_base_cost: Option<u64>,
1219 string_sub_string_per_byte_cost: Option<u64>,
1220 string_index_of_base_cost: Option<u64>,
1221 string_index_of_per_byte_pattern_cost: Option<u64>,
1222 string_index_of_per_byte_searched_cost: Option<u64>,
1223
1224 vector_empty_base_cost: Option<u64>,
1225 vector_length_base_cost: Option<u64>,
1226 vector_push_back_base_cost: Option<u64>,
1227 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1228 vector_borrow_base_cost: Option<u64>,
1229 vector_pop_back_base_cost: Option<u64>,
1230 vector_destroy_empty_base_cost: Option<u64>,
1231 vector_swap_base_cost: Option<u64>,
1232 debug_print_base_cost: Option<u64>,
1233 debug_print_stack_trace_base_cost: Option<u64>,
1234
1235 execution_version: Option<u64>,
1237
1238 consensus_bad_nodes_stake_threshold: Option<u64>,
1242
1243 #[deprecated]
1244 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1245 #[deprecated]
1249 max_age_of_jwk_in_epochs: Option<u64>,
1250
1251 random_beacon_reduction_allowed_delta: Option<u16>,
1255
1256 random_beacon_reduction_lower_bound: Option<u32>,
1259
1260 random_beacon_dkg_timeout_round: Option<u32>,
1263
1264 random_beacon_min_round_interval_ms: Option<u64>,
1266
1267 random_beacon_dkg_version: Option<u64>,
1271
1272 consensus_max_transaction_size_bytes: Option<u64>,
1277 consensus_max_transactions_in_block_bytes: Option<u64>,
1279 consensus_max_num_transactions_in_block: Option<u64>,
1281
1282 max_deferral_rounds_for_congestion_control: Option<u64>,
1286
1287 min_checkpoint_interval_ms: Option<u64>,
1289
1290 checkpoint_summary_version_specific_data: Option<u64>,
1292
1293 max_soft_bundle_size: Option<u64>,
1296
1297 bridge_should_try_to_finalize_committee: Option<bool>,
1302
1303 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1309
1310 max_committee_members_count: Option<u64>,
1314
1315 consensus_gc_depth: Option<u32>,
1318
1319 consensus_max_acknowledgments_per_block: Option<u32>,
1325
1326 max_congestion_limit_overshoot_per_commit: Option<u64>,
1331
1332 scorer_version: Option<u16>,
1341
1342 auth_context_digest_cost_base: Option<u64>,
1345 auth_context_tx_data_bytes_cost_base: Option<u64>,
1347 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1348 auth_context_tx_commands_cost_base: Option<u64>,
1350 auth_context_tx_commands_cost_per_byte: Option<u64>,
1351 auth_context_tx_inputs_cost_base: Option<u64>,
1353 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1354 auth_context_replace_cost_base: Option<u64>,
1357 auth_context_replace_cost_per_byte: Option<u64>,
1358 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1362}
1363
1364impl ProtocolConfig {
1366 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1379 self.feature_flags
1380 .disable_invariant_violation_check_in_swap_loc
1381 }
1382
1383 pub fn no_extraneous_module_bytes(&self) -> bool {
1384 self.feature_flags.no_extraneous_module_bytes
1385 }
1386
1387 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1388 self.feature_flags.consensus_transaction_ordering
1389 }
1390
1391 pub fn dkg_version(&self) -> u64 {
1392 self.random_beacon_dkg_version.unwrap_or(1)
1394 }
1395
1396 pub fn hardened_otw_check(&self) -> bool {
1397 self.feature_flags.hardened_otw_check
1398 }
1399
1400 pub fn enable_poseidon(&self) -> bool {
1401 self.feature_flags.enable_poseidon
1402 }
1403
1404 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1405 self.feature_flags.enable_group_ops_native_function_msm
1406 }
1407
1408 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1409 self.feature_flags.per_object_congestion_control_mode
1410 }
1411
1412 pub fn consensus_choice(&self) -> ConsensusChoice {
1413 self.feature_flags.consensus_choice
1414 }
1415
1416 pub fn consensus_network(&self) -> ConsensusNetwork {
1417 self.feature_flags.consensus_network
1418 }
1419
1420 pub fn enable_vdf(&self) -> bool {
1421 self.feature_flags.enable_vdf
1422 }
1423
1424 pub fn passkey_auth(&self) -> bool {
1425 self.feature_flags.passkey_auth
1426 }
1427
1428 pub fn max_transaction_size_bytes(&self) -> u64 {
1429 self.consensus_max_transaction_size_bytes
1431 .unwrap_or(256 * 1024)
1432 }
1433
1434 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1435 if cfg!(msim) {
1436 256 * 1024
1437 } else {
1438 self.consensus_max_transactions_in_block_bytes
1439 .unwrap_or(512 * 1024)
1440 }
1441 }
1442
1443 pub fn max_num_transactions_in_block(&self) -> u64 {
1444 if cfg!(msim) {
1445 8
1446 } else {
1447 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1448 }
1449 }
1450
1451 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1452 self.feature_flags.rethrow_serialization_type_layout_errors
1453 }
1454
1455 pub fn relocate_event_module(&self) -> bool {
1456 self.feature_flags.relocate_event_module
1457 }
1458
1459 pub fn protocol_defined_base_fee(&self) -> bool {
1460 self.feature_flags.protocol_defined_base_fee
1461 }
1462
1463 pub fn uncompressed_g1_group_elements(&self) -> bool {
1464 self.feature_flags.uncompressed_g1_group_elements
1465 }
1466
1467 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1468 self.feature_flags
1469 .disallow_new_modules_in_deps_only_packages
1470 }
1471
1472 pub fn native_charging_v2(&self) -> bool {
1473 self.feature_flags.native_charging_v2
1474 }
1475
1476 pub fn consensus_round_prober(&self) -> bool {
1477 self.feature_flags.consensus_round_prober
1478 }
1479
1480 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1481 self.feature_flags
1482 .consensus_distributed_vote_scoring_strategy
1483 }
1484
1485 pub fn gc_depth(&self) -> u32 {
1486 if cfg!(msim) {
1487 min(5, self.consensus_gc_depth.unwrap_or(0))
1489 } else {
1490 self.consensus_gc_depth.unwrap_or(0)
1491 }
1492 }
1493
1494 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1495 let res = self.feature_flags.consensus_linearize_subdag_v2;
1496 assert!(
1497 !res || self.gc_depth() > 0,
1498 "The consensus linearize sub dag V2 requires GC to be enabled"
1499 );
1500 res
1501 }
1502
1503 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1504 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1505 }
1506
1507 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1508 if self.consensus_block_restrictions() {
1509 2 * committee_size
1510 } else {
1511 self.consensus_max_acknowledgments_per_block_or_default() as usize
1512 }
1513 }
1514
1515 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1516 if self.consensus_block_restrictions() {
1517 committee_size
1518 } else {
1519 100
1520 }
1521 }
1522
1523 pub fn variant_nodes(&self) -> bool {
1524 self.feature_flags.variant_nodes
1525 }
1526
1527 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1528 self.feature_flags.consensus_smart_ancestor_selection
1529 }
1530
1531 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1532 self.feature_flags
1533 .consensus_round_prober_probe_accepted_rounds
1534 }
1535
1536 pub fn consensus_zstd_compression(&self) -> bool {
1537 self.feature_flags.consensus_zstd_compression
1538 }
1539
1540 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1541 self.feature_flags
1542 .congestion_control_min_free_execution_slot
1543 }
1544
1545 pub fn accept_passkey_in_multisig(&self) -> bool {
1546 self.feature_flags.accept_passkey_in_multisig
1547 }
1548
1549 pub fn consensus_batched_block_sync(&self) -> bool {
1550 self.feature_flags.consensus_batched_block_sync
1551 }
1552
1553 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1556 self.feature_flags
1557 .congestion_control_gas_price_feedback_mechanism
1558 }
1559
1560 pub fn validate_identifier_inputs(&self) -> bool {
1561 self.feature_flags.validate_identifier_inputs
1562 }
1563
1564 pub fn minimize_child_object_mutations(&self) -> bool {
1565 self.feature_flags.minimize_child_object_mutations
1566 }
1567
1568 pub fn dependency_linkage_error(&self) -> bool {
1569 self.feature_flags.dependency_linkage_error
1570 }
1571
1572 pub fn additional_multisig_checks(&self) -> bool {
1573 self.feature_flags.additional_multisig_checks
1574 }
1575
1576 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1577 0
1580 }
1581
1582 pub fn normalize_ptb_arguments(&self) -> bool {
1583 self.feature_flags.normalize_ptb_arguments
1584 }
1585
1586 pub fn select_committee_from_eligible_validators(&self) -> bool {
1587 let res = self.feature_flags.select_committee_from_eligible_validators;
1588 assert!(
1589 !res || (self.protocol_defined_base_fee()
1590 && self.max_committee_members_count_as_option().is_some()),
1591 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1592 );
1593 res
1594 }
1595
1596 pub fn track_non_committee_eligible_validators(&self) -> bool {
1597 self.feature_flags.track_non_committee_eligible_validators
1598 }
1599
1600 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1601 let res = self
1602 .feature_flags
1603 .select_committee_supporting_next_epoch_version;
1604 assert!(
1605 !res || (self.track_non_committee_eligible_validators()
1606 && self.select_committee_from_eligible_validators()),
1607 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1608 );
1609 res
1610 }
1611
1612 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1613 let res = self
1614 .feature_flags
1615 .consensus_median_timestamp_with_checkpoint_enforcement;
1616 assert!(
1617 !res || self.gc_depth() > 0,
1618 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1619 );
1620 res
1621 }
1622
1623 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1624 self.feature_flags
1625 .consensus_commit_transactions_only_for_traversed_headers
1626 }
1627
1628 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1631 self.feature_flags
1632 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1633 }
1634
1635 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1638 self.feature_flags
1639 .separate_gas_price_feedback_mechanism_for_randomness
1640 }
1641
1642 pub fn metadata_in_module_bytes(&self) -> bool {
1643 self.feature_flags.metadata_in_module_bytes
1644 }
1645
1646 pub fn publish_package_metadata(&self) -> bool {
1647 self.feature_flags.publish_package_metadata
1648 }
1649
1650 pub fn enable_move_authentication(&self) -> bool {
1651 self.feature_flags.enable_move_authentication
1652 }
1653
1654 pub fn additional_borrow_checks(&self) -> bool {
1655 self.feature_flags.additional_borrow_checks
1656 }
1657
1658 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1659 let enable_move_authentication_for_sponsor =
1660 self.feature_flags.enable_move_authentication_for_sponsor;
1661 assert!(
1662 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1663 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1664 );
1665 enable_move_authentication_for_sponsor
1666 }
1667
1668 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1669 self.feature_flags.pass_validator_scores_to_advance_epoch
1670 }
1671
1672 pub fn calculate_validator_scores(&self) -> bool {
1673 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1674 assert!(
1675 !calculate_validator_scores || self.scorer_version.is_some(),
1676 "calculate_validator_scores requires scorer_version to be set"
1677 );
1678 calculate_validator_scores
1679 }
1680
1681 pub fn adjust_rewards_by_score(&self) -> bool {
1682 let adjust = self.feature_flags.adjust_rewards_by_score;
1683 assert!(
1684 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1685 "adjust_rewards_by_score requires scorer_version to be set"
1686 );
1687 adjust
1688 }
1689
1690 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1691 let pass = self
1692 .feature_flags
1693 .pass_calculated_validator_scores_to_advance_epoch;
1694 assert!(
1695 !pass
1696 || (self.pass_validator_scores_to_advance_epoch()
1697 && self.calculate_validator_scores()),
1698 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
1699 );
1700 pass
1701 }
1702 pub fn consensus_fast_commit_sync(&self) -> bool {
1703 let res = self.feature_flags.consensus_fast_commit_sync;
1704 assert!(
1705 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
1706 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
1707 );
1708 res
1709 }
1710
1711 pub fn consensus_block_restrictions(&self) -> bool {
1712 self.feature_flags.consensus_block_restrictions
1713 }
1714
1715 pub fn move_native_tx_context(&self) -> bool {
1716 self.feature_flags.move_native_tx_context
1717 }
1718
1719 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
1720 let pre_consensus_sponsor_only_move_authentication = self
1721 .feature_flags
1722 .pre_consensus_sponsor_only_move_authentication;
1723 if pre_consensus_sponsor_only_move_authentication {
1724 assert!(
1725 self.enable_move_authentication(),
1726 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
1727 );
1728 assert!(
1729 self.enable_move_authentication_for_sponsor(),
1730 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
1731 );
1732 }
1733 pre_consensus_sponsor_only_move_authentication
1734 }
1735}
1736
1737#[cfg(not(msim))]
1738static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1739
1740#[cfg(msim)]
1742thread_local! {
1743 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1744}
1745
1746impl ProtocolConfig {
1748 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1751 assert!(
1753 version >= ProtocolVersion::MIN,
1754 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1755 version,
1756 ProtocolVersion::MIN.0,
1757 );
1758 assert!(
1759 version <= ProtocolVersion::MAX_ALLOWED,
1760 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1761 version,
1762 ProtocolVersion::MAX_ALLOWED.0,
1763 );
1764
1765 let mut ret = Self::get_for_version_impl(version, chain);
1766 ret.version = version;
1767
1768 ret = CONFIG_OVERRIDE.with(|ovr| {
1769 if let Some(override_fn) = &*ovr.borrow() {
1770 warn!(
1771 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1772 );
1773 override_fn(version, ret)
1774 } else {
1775 ret
1776 }
1777 });
1778
1779 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1780 warn!(
1781 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1782 );
1783 let overrides: ProtocolConfigOptional =
1784 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1785 .expect("failed to parse ProtocolConfig override env variables");
1786 overrides.apply_to(&mut ret);
1787 }
1788
1789 ret
1790 }
1791
1792 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1795 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1796 let mut ret = Self::get_for_version_impl(version, chain);
1797 ret.version = version;
1798 Some(ret)
1799 } else {
1800 None
1801 }
1802 }
1803
1804 #[cfg(not(msim))]
1805 pub fn poison_get_for_min_version() {
1806 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1807 }
1808
1809 #[cfg(not(msim))]
1810 fn load_poison_get_for_min_version() -> bool {
1811 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1812 }
1813
1814 #[cfg(msim)]
1815 pub fn poison_get_for_min_version() {
1816 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1817 }
1818
1819 #[cfg(msim)]
1820 fn load_poison_get_for_min_version() -> bool {
1821 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1822 }
1823
1824 pub fn convert_type_argument_error(&self) -> bool {
1825 self.feature_flags.convert_type_argument_error
1826 }
1827
1828 pub fn get_for_min_version() -> Self {
1832 if Self::load_poison_get_for_min_version() {
1833 panic!("get_for_min_version called on validator");
1834 }
1835 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1836 }
1837
1838 #[expect(non_snake_case)]
1849 pub fn get_for_max_version_UNSAFE() -> Self {
1850 if Self::load_poison_get_for_min_version() {
1851 panic!("get_for_max_version_UNSAFE called on validator");
1852 }
1853 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1854 }
1855
1856 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1857 #[cfg(msim)]
1858 {
1859 if version > ProtocolVersion::MAX {
1861 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1862 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1863 return config;
1864 }
1865 }
1866
1867 let mut cfg = Self {
1871 version,
1872
1873 feature_flags: Default::default(),
1874
1875 max_tx_size_bytes: Some(128 * 1024),
1876 max_input_objects: Some(2048),
1879 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1880 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1881 max_gas_payment_objects: Some(256),
1882 max_modules_in_publish: Some(64),
1883 max_package_dependencies: Some(32),
1884 max_arguments: Some(512),
1885 max_type_arguments: Some(16),
1886 max_type_argument_depth: Some(16),
1887 max_pure_argument_size: Some(16 * 1024),
1888 max_programmable_tx_commands: Some(1024),
1889 move_binary_format_version: Some(7),
1890 min_move_binary_format_version: Some(6),
1891 binary_module_handles: Some(100),
1892 binary_struct_handles: Some(300),
1893 binary_function_handles: Some(1500),
1894 binary_function_instantiations: Some(750),
1895 binary_signatures: Some(1000),
1896 binary_constant_pool: Some(4000),
1897 binary_identifiers: Some(10000),
1898 binary_address_identifiers: Some(100),
1899 binary_struct_defs: Some(200),
1900 binary_struct_def_instantiations: Some(100),
1901 binary_function_defs: Some(1000),
1902 binary_field_handles: Some(500),
1903 binary_field_instantiations: Some(250),
1904 binary_friend_decls: Some(100),
1905 binary_enum_defs: None,
1906 binary_enum_def_instantiations: None,
1907 binary_variant_handles: None,
1908 binary_variant_instantiation_handles: None,
1909 max_move_object_size: Some(250 * 1024),
1910 max_move_package_size: Some(100 * 1024),
1911 max_publish_or_upgrade_per_ptb: Some(5),
1912 max_auth_gas: None,
1914 max_tx_gas: Some(50_000_000_000),
1916 max_gas_price: Some(100_000),
1917 max_gas_computation_bucket: Some(5_000_000),
1918 max_loop_depth: Some(5),
1919 max_generic_instantiation_length: Some(32),
1920 max_function_parameters: Some(128),
1921 max_basic_blocks: Some(1024),
1922 max_value_stack_size: Some(1024),
1923 max_type_nodes: Some(256),
1924 max_push_size: Some(10000),
1925 max_struct_definitions: Some(200),
1926 max_function_definitions: Some(1000),
1927 max_fields_in_struct: Some(32),
1928 max_dependency_depth: Some(100),
1929 max_num_event_emit: Some(1024),
1930 max_num_new_move_object_ids: Some(2048),
1931 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1932 max_num_deleted_move_object_ids: Some(2048),
1933 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1934 max_num_transferred_move_object_ids: Some(2048),
1935 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1936 max_event_emit_size: Some(250 * 1024),
1937 max_move_vector_len: Some(256 * 1024),
1938 max_type_to_layout_nodes: None,
1939 max_ptb_value_size: None,
1940
1941 max_back_edges_per_function: Some(10_000),
1942 max_back_edges_per_module: Some(10_000),
1943
1944 max_verifier_meter_ticks_per_function: Some(16_000_000),
1945
1946 max_meter_ticks_per_module: Some(16_000_000),
1947 max_meter_ticks_per_package: Some(16_000_000),
1948
1949 object_runtime_max_num_cached_objects: Some(1000),
1950 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
1951 object_runtime_max_num_store_entries: Some(1000),
1952 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
1953 base_tx_cost_fixed: Some(1_000),
1955 package_publish_cost_fixed: Some(1_000),
1956 base_tx_cost_per_byte: Some(0),
1957 package_publish_cost_per_byte: Some(80),
1958 obj_access_cost_read_per_byte: Some(15),
1959 obj_access_cost_mutate_per_byte: Some(40),
1960 obj_access_cost_delete_per_byte: Some(40),
1961 obj_access_cost_verify_per_byte: Some(200),
1962 obj_data_cost_refundable: Some(100),
1963 obj_metadata_cost_non_refundable: Some(50),
1964 gas_model_version: Some(1),
1965 storage_rebate_rate: Some(10000),
1966 reward_slashing_rate: Some(10000),
1968 storage_gas_price: Some(76),
1969 base_gas_price: None,
1970 validator_target_reward: Some(767_000 * 1_000_000_000),
1973 max_transactions_per_checkpoint: Some(10_000),
1974 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
1975
1976 buffer_stake_for_protocol_upgrade_bps: Some(5000),
1978
1979 address_from_bytes_cost_base: Some(52),
1983 address_to_u256_cost_base: Some(52),
1985 address_from_u256_cost_base: Some(52),
1987
1988 config_read_setting_impl_cost_base: Some(100),
1991 config_read_setting_impl_cost_per_byte: Some(40),
1992
1993 dynamic_field_hash_type_and_key_cost_base: Some(100),
1997 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
1998 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
1999 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
2000 dynamic_field_add_child_object_cost_base: Some(100),
2003 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2004 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2005 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2006 dynamic_field_borrow_child_object_cost_base: Some(100),
2009 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2010 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2011 dynamic_field_remove_child_object_cost_base: Some(100),
2014 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2015 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2016 dynamic_field_has_child_object_cost_base: Some(100),
2019 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2022 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2023 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2024
2025 event_emit_cost_base: Some(52),
2028 event_emit_value_size_derivation_cost_per_byte: Some(2),
2029 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2030 event_emit_output_cost_per_byte: Some(10),
2031
2032 object_borrow_uid_cost_base: Some(52),
2035 object_delete_impl_cost_base: Some(52),
2037 object_record_new_uid_cost_base: Some(52),
2039
2040 transfer_transfer_internal_cost_base: Some(52),
2044 transfer_freeze_object_cost_base: Some(52),
2046 transfer_share_object_cost_base: Some(52),
2048 transfer_receive_object_cost_base: Some(52),
2049
2050 tx_context_derive_id_cost_base: Some(52),
2054 tx_context_fresh_id_cost_base: None,
2055 tx_context_sender_cost_base: None,
2056 tx_context_digest_cost_base: None,
2057 tx_context_epoch_cost_base: None,
2058 tx_context_epoch_timestamp_ms_cost_base: None,
2059 tx_context_sponsor_cost_base: None,
2060 tx_context_rgp_cost_base: None,
2061 tx_context_gas_price_cost_base: None,
2062 tx_context_gas_budget_cost_base: None,
2063 tx_context_ids_created_cost_base: None,
2064 tx_context_replace_cost_base: None,
2065
2066 types_is_one_time_witness_cost_base: Some(52),
2069 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2070 types_is_one_time_witness_type_cost_per_byte: Some(2),
2071
2072 validator_validate_metadata_cost_base: Some(52),
2076 validator_validate_metadata_data_cost_per_byte: Some(2),
2077
2078 crypto_invalid_arguments_cost: Some(100),
2080 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2082 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2083 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2084
2085 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2087 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2088 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2089
2090 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2092 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2093 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2094 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2095 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2096 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2097
2098 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2100
2101 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2103 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2104 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2105 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2106 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2107 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2108
2109 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2111 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2112 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2113 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2114 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2115 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2116
2117 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2119 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2120 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2121 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2122 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2123 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2124
2125 ecvrf_ecvrf_verify_cost_base: Some(52),
2127 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2128 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2129
2130 ed25519_ed25519_verify_cost_base: Some(52),
2132 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2133 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2134
2135 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2137 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2138
2139 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2141 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2142 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2143 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2144 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2145
2146 hash_blake2b256_cost_base: Some(52),
2148 hash_blake2b256_data_cost_per_byte: Some(2),
2149 hash_blake2b256_data_cost_per_block: Some(2),
2150 hash_keccak256_cost_base: Some(52),
2152 hash_keccak256_data_cost_per_byte: Some(2),
2153 hash_keccak256_data_cost_per_block: Some(2),
2154
2155 poseidon_bn254_cost_base: None,
2156 poseidon_bn254_cost_per_block: None,
2157
2158 hmac_hmac_sha3_256_cost_base: Some(52),
2160 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2161 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2162
2163 group_ops_bls12381_decode_scalar_cost: Some(52),
2165 group_ops_bls12381_decode_g1_cost: Some(52),
2166 group_ops_bls12381_decode_g2_cost: Some(52),
2167 group_ops_bls12381_decode_gt_cost: Some(52),
2168 group_ops_bls12381_scalar_add_cost: Some(52),
2169 group_ops_bls12381_g1_add_cost: Some(52),
2170 group_ops_bls12381_g2_add_cost: Some(52),
2171 group_ops_bls12381_gt_add_cost: Some(52),
2172 group_ops_bls12381_scalar_sub_cost: Some(52),
2173 group_ops_bls12381_g1_sub_cost: Some(52),
2174 group_ops_bls12381_g2_sub_cost: Some(52),
2175 group_ops_bls12381_gt_sub_cost: Some(52),
2176 group_ops_bls12381_scalar_mul_cost: Some(52),
2177 group_ops_bls12381_g1_mul_cost: Some(52),
2178 group_ops_bls12381_g2_mul_cost: Some(52),
2179 group_ops_bls12381_gt_mul_cost: Some(52),
2180 group_ops_bls12381_scalar_div_cost: Some(52),
2181 group_ops_bls12381_g1_div_cost: Some(52),
2182 group_ops_bls12381_g2_div_cost: Some(52),
2183 group_ops_bls12381_gt_div_cost: Some(52),
2184 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2185 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2186 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2187 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2188 group_ops_bls12381_g1_msm_base_cost: Some(52),
2189 group_ops_bls12381_g2_msm_base_cost: Some(52),
2190 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2191 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2192 group_ops_bls12381_msm_max_len: Some(32),
2193 group_ops_bls12381_pairing_cost: Some(52),
2194 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2195 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2196 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2197 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2198 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2199
2200 #[allow(deprecated)]
2202 check_zklogin_id_cost_base: Some(200),
2203 #[allow(deprecated)]
2204 check_zklogin_issuer_cost_base: Some(200),
2206
2207 vdf_verify_vdf_cost: None,
2208 vdf_hash_to_input_cost: None,
2209
2210 bcs_per_byte_serialized_cost: Some(2),
2211 bcs_legacy_min_output_size_cost: Some(1),
2212 bcs_failure_cost: Some(52),
2213 hash_sha2_256_base_cost: Some(52),
2214 hash_sha2_256_per_byte_cost: Some(2),
2215 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2216 hash_sha3_256_base_cost: Some(52),
2217 hash_sha3_256_per_byte_cost: Some(2),
2218 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2219 type_name_get_base_cost: Some(52),
2220 type_name_get_per_byte_cost: Some(2),
2221 string_check_utf8_base_cost: Some(52),
2222 string_check_utf8_per_byte_cost: Some(2),
2223 string_is_char_boundary_base_cost: Some(52),
2224 string_sub_string_base_cost: Some(52),
2225 string_sub_string_per_byte_cost: Some(2),
2226 string_index_of_base_cost: Some(52),
2227 string_index_of_per_byte_pattern_cost: Some(2),
2228 string_index_of_per_byte_searched_cost: Some(2),
2229 vector_empty_base_cost: Some(52),
2230 vector_length_base_cost: Some(52),
2231 vector_push_back_base_cost: Some(52),
2232 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2233 vector_borrow_base_cost: Some(52),
2234 vector_pop_back_base_cost: Some(52),
2235 vector_destroy_empty_base_cost: Some(52),
2236 vector_swap_base_cost: Some(52),
2237 debug_print_base_cost: Some(52),
2238 debug_print_stack_trace_base_cost: Some(52),
2239
2240 max_size_written_objects: Some(5 * 1000 * 1000),
2241 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2244
2245 max_move_identifier_len: Some(128),
2247 max_move_value_depth: Some(128),
2248 max_move_enum_variants: None,
2249
2250 gas_rounding_step: Some(1_000),
2251
2252 execution_version: Some(1),
2253
2254 max_event_emit_size_total: Some(
2257 256 * 250 * 1024, ),
2259
2260 consensus_bad_nodes_stake_threshold: Some(20),
2267
2268 #[allow(deprecated)]
2270 max_jwk_votes_per_validator_per_epoch: Some(240),
2271
2272 #[allow(deprecated)]
2273 max_age_of_jwk_in_epochs: Some(1),
2274
2275 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2279
2280 random_beacon_reduction_allowed_delta: Some(800),
2281
2282 random_beacon_reduction_lower_bound: Some(1000),
2283 random_beacon_dkg_timeout_round: Some(3000),
2284 random_beacon_min_round_interval_ms: Some(500),
2285
2286 random_beacon_dkg_version: Some(1),
2287
2288 consensus_max_num_transactions_in_block: Some(512),
2292
2293 max_deferral_rounds_for_congestion_control: Some(10),
2294
2295 min_checkpoint_interval_ms: Some(200),
2296
2297 checkpoint_summary_version_specific_data: Some(1),
2298
2299 max_soft_bundle_size: Some(5),
2300
2301 bridge_should_try_to_finalize_committee: None,
2302
2303 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2304
2305 max_committee_members_count: None,
2306
2307 consensus_gc_depth: None,
2308
2309 consensus_max_acknowledgments_per_block: None,
2310
2311 max_congestion_limit_overshoot_per_commit: None,
2312
2313 scorer_version: None,
2314
2315 auth_context_digest_cost_base: None,
2317 auth_context_tx_data_bytes_cost_base: None,
2318 auth_context_tx_data_bytes_cost_per_byte: None,
2319 auth_context_tx_commands_cost_base: None,
2320 auth_context_tx_commands_cost_per_byte: None,
2321 auth_context_tx_inputs_cost_base: None,
2322 auth_context_tx_inputs_cost_per_byte: None,
2323 auth_context_replace_cost_base: None,
2324 auth_context_replace_cost_per_byte: None,
2325 auth_context_authenticator_function_info_v1_cost_base: None,
2326 };
2329
2330 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2331
2332 {
2334 cfg.feature_flags
2335 .disable_invariant_violation_check_in_swap_loc = true;
2336 cfg.feature_flags.no_extraneous_module_bytes = true;
2337 cfg.feature_flags.hardened_otw_check = true;
2338 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2339 }
2340
2341 {
2343 #[allow(deprecated)]
2344 {
2345 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2346 }
2347 }
2348
2349 #[expect(deprecated)]
2353 {
2354 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2355 }
2356 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2358
2359 cfg.feature_flags.per_object_congestion_control_mode =
2360 PerObjectCongestionControlMode::TotalTxCount;
2361
2362 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2364
2365 if chain != Chain::Mainnet && chain != Chain::Testnet {
2367 cfg.feature_flags.enable_poseidon = true;
2368 cfg.poseidon_bn254_cost_base = Some(260);
2369 cfg.poseidon_bn254_cost_per_block = Some(10);
2370
2371 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2372
2373 cfg.feature_flags.enable_vdf = true;
2374 cfg.vdf_verify_vdf_cost = Some(1500);
2377 cfg.vdf_hash_to_input_cost = Some(100);
2378
2379 cfg.feature_flags.passkey_auth = true;
2380 }
2381
2382 for cur in 2..=version.0 {
2383 match cur {
2384 1 => unreachable!(),
2385 2 => {}
2387 3 => {
2388 cfg.feature_flags.relocate_event_module = true;
2389 }
2390 4 => {
2391 cfg.max_type_to_layout_nodes = Some(512);
2392 }
2393 5 => {
2394 cfg.feature_flags.protocol_defined_base_fee = true;
2395 cfg.base_gas_price = Some(1000);
2396
2397 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2398 cfg.feature_flags.convert_type_argument_error = true;
2399 cfg.feature_flags.native_charging_v2 = true;
2400
2401 if chain != Chain::Mainnet && chain != Chain::Testnet {
2402 cfg.feature_flags.uncompressed_g1_group_elements = true;
2403 }
2404
2405 cfg.gas_model_version = Some(2);
2406
2407 cfg.poseidon_bn254_cost_per_block = Some(388);
2408
2409 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2410 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2411 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2412 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2413 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2414 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2415 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2416 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2417
2418 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2420 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2421 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2422 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2423
2424 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2425 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2426 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2427 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2428 Some(8213);
2429 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2430 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2431 Some(9484);
2432
2433 cfg.hash_keccak256_cost_base = Some(10);
2434 cfg.hash_blake2b256_cost_base = Some(10);
2435
2436 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2438 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2439 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2440 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2441
2442 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2443 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2444 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2445 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2446
2447 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2448 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2449 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2450 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2451
2452 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2453 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2454 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2455 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2456
2457 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2458 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2459 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2460 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2461
2462 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2463 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2464
2465 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2466 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2467 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2468 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2469
2470 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2471 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2472 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2473 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2474 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2475
2476 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2477
2478 cfg.validator_validate_metadata_cost_base = Some(20000);
2479
2480 cfg.max_committee_members_count = Some(50);
2481 }
2482 6 => {
2483 cfg.max_ptb_value_size = Some(1024 * 1024);
2484 }
2485 7 => {
2486 }
2489 8 => {
2490 cfg.feature_flags.variant_nodes = true;
2491
2492 if chain != Chain::Mainnet {
2493 cfg.feature_flags.consensus_round_prober = true;
2495 cfg.feature_flags
2497 .consensus_distributed_vote_scoring_strategy = true;
2498 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2499 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2501 cfg.feature_flags
2503 .consensus_round_prober_probe_accepted_rounds = true;
2504 cfg.feature_flags.consensus_zstd_compression = true;
2506 cfg.consensus_gc_depth = Some(60);
2510 }
2511
2512 if chain != Chain::Testnet && chain != Chain::Mainnet {
2515 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2516 }
2517 }
2518 9 => {
2519 if chain != Chain::Mainnet {
2520 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2522 }
2523
2524 cfg.feature_flags.consensus_zstd_compression = true;
2526
2527 if chain != Chain::Testnet && chain != Chain::Mainnet {
2529 cfg.feature_flags.accept_passkey_in_multisig = true;
2530 }
2531
2532 cfg.bridge_should_try_to_finalize_committee = None;
2534 }
2535 10 => {
2536 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2539
2540 cfg.max_committee_members_count = Some(80);
2542
2543 cfg.feature_flags.consensus_round_prober = true;
2545 cfg.feature_flags
2547 .consensus_round_prober_probe_accepted_rounds = true;
2548 cfg.feature_flags
2550 .consensus_distributed_vote_scoring_strategy = true;
2551 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2553
2554 cfg.consensus_gc_depth = Some(60);
2559
2560 cfg.feature_flags.minimize_child_object_mutations = true;
2562
2563 if chain != Chain::Mainnet {
2564 cfg.feature_flags.consensus_batched_block_sync = true;
2566 }
2567
2568 if chain != Chain::Testnet && chain != Chain::Mainnet {
2569 cfg.feature_flags
2572 .congestion_control_gas_price_feedback_mechanism = true;
2573 }
2574
2575 cfg.feature_flags.validate_identifier_inputs = true;
2576 cfg.feature_flags.dependency_linkage_error = true;
2577 cfg.feature_flags.additional_multisig_checks = true;
2578 }
2579 11 => {
2580 }
2583 12 => {
2584 cfg.feature_flags
2587 .congestion_control_gas_price_feedback_mechanism = true;
2588
2589 cfg.feature_flags.normalize_ptb_arguments = true;
2591 }
2592 13 => {
2593 cfg.feature_flags.select_committee_from_eligible_validators = true;
2596 cfg.feature_flags.track_non_committee_eligible_validators = true;
2599
2600 if chain != Chain::Testnet && chain != Chain::Mainnet {
2601 cfg.feature_flags
2604 .select_committee_supporting_next_epoch_version = true;
2605 }
2606 }
2607 14 => {
2608 cfg.feature_flags.consensus_batched_block_sync = true;
2610
2611 if chain != Chain::Mainnet {
2612 cfg.feature_flags
2615 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2616 cfg.feature_flags
2620 .select_committee_supporting_next_epoch_version = true;
2621 }
2622 if chain != Chain::Testnet && chain != Chain::Mainnet {
2623 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2625 }
2626 }
2627 15 => {
2628 if chain != Chain::Mainnet && chain != Chain::Testnet {
2629 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2633 }
2634 }
2635 16 => {
2636 cfg.feature_flags
2639 .select_committee_supporting_next_epoch_version = true;
2640 cfg.feature_flags
2642 .consensus_commit_transactions_only_for_traversed_headers = true;
2643 }
2644 17 => {
2645 cfg.max_committee_members_count = Some(100);
2647 }
2648 18 => {
2649 if chain != Chain::Mainnet {
2650 cfg.feature_flags.passkey_auth = true;
2652 }
2653 }
2654 19 => {
2655 if chain != Chain::Testnet && chain != Chain::Mainnet {
2656 cfg.feature_flags
2659 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2660 cfg.feature_flags
2663 .separate_gas_price_feedback_mechanism_for_randomness = true;
2664 cfg.feature_flags.metadata_in_module_bytes = true;
2667 cfg.feature_flags.publish_package_metadata = true;
2668 cfg.feature_flags.enable_move_authentication = true;
2670 cfg.max_auth_gas = Some(250_000_000);
2672 cfg.transfer_receive_object_cost_base = Some(100);
2675 cfg.feature_flags.adjust_rewards_by_score = true;
2677 }
2678
2679 if chain != Chain::Mainnet {
2680 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2682
2683 cfg.feature_flags.calculate_validator_scores = true;
2685 cfg.scorer_version = Some(1);
2686 }
2687
2688 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
2690
2691 cfg.feature_flags.passkey_auth = true;
2693 }
2694 20 => {
2695 if chain != Chain::Testnet && chain != Chain::Mainnet {
2696 cfg.feature_flags
2698 .pass_calculated_validator_scores_to_advance_epoch = true;
2699 }
2700 }
2701 21 => {
2702 if chain != Chain::Testnet && chain != Chain::Mainnet {
2703 cfg.feature_flags.consensus_fast_commit_sync = true;
2705 }
2706 if chain != Chain::Mainnet {
2707 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2712 cfg.feature_flags
2715 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2716 cfg.feature_flags
2719 .separate_gas_price_feedback_mechanism_for_randomness = true;
2720 }
2721
2722 cfg.auth_context_digest_cost_base = Some(30);
2723 cfg.auth_context_tx_commands_cost_base = Some(30);
2724 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
2725 cfg.auth_context_tx_inputs_cost_base = Some(30);
2726 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
2727 cfg.auth_context_replace_cost_base = Some(30);
2728 cfg.auth_context_replace_cost_per_byte = Some(2);
2729
2730 if chain != Chain::Testnet && chain != Chain::Mainnet {
2731 cfg.max_auth_gas = Some(250_000);
2733 }
2734 }
2735 22 => {
2736 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2741 cfg.feature_flags
2744 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2745 cfg.feature_flags
2748 .separate_gas_price_feedback_mechanism_for_randomness = true;
2749
2750 if chain != Chain::Mainnet {
2751 cfg.feature_flags.metadata_in_module_bytes = true;
2754 cfg.feature_flags.publish_package_metadata = true;
2755 cfg.feature_flags.enable_move_authentication = true;
2757 cfg.max_auth_gas = Some(250_000);
2759 cfg.transfer_receive_object_cost_base = Some(100);
2762 }
2763
2764 if chain != Chain::Mainnet {
2765 cfg.feature_flags.consensus_fast_commit_sync = true;
2767 }
2768 }
2769 23 => {
2770 cfg.feature_flags.move_native_tx_context = true;
2772 cfg.tx_context_fresh_id_cost_base = Some(52);
2773 cfg.tx_context_sender_cost_base = Some(30);
2774 cfg.tx_context_digest_cost_base = Some(30);
2775 cfg.tx_context_epoch_cost_base = Some(30);
2776 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
2777 cfg.tx_context_sponsor_cost_base = Some(30);
2778 cfg.tx_context_rgp_cost_base = Some(30);
2779 cfg.tx_context_gas_price_cost_base = Some(30);
2780 cfg.tx_context_gas_budget_cost_base = Some(30);
2781 cfg.tx_context_ids_created_cost_base = Some(30);
2782 cfg.tx_context_replace_cost_base = Some(30);
2783 }
2784 24 => {
2785 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2787
2788 if chain != Chain::Testnet && chain != Chain::Mainnet {
2789 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2791 }
2792
2793 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
2796 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
2797
2798 cfg.feature_flags.additional_borrow_checks = true;
2800 }
2801 #[allow(deprecated)]
2802 25 => {
2803 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
2806 cfg.check_zklogin_id_cost_base = None;
2807 cfg.check_zklogin_issuer_cost_base = None;
2808 cfg.max_jwk_votes_per_validator_per_epoch = None;
2809 cfg.max_age_of_jwk_in_epochs = None;
2810 }
2811 26 => {
2812 }
2815 27 => {
2816 if chain != Chain::Mainnet {
2817 cfg.feature_flags.consensus_block_restrictions = true;
2820 }
2821
2822 if chain != Chain::Testnet && chain != Chain::Mainnet {
2823 cfg.feature_flags
2825 .pre_consensus_sponsor_only_move_authentication = true;
2826 }
2827 }
2828 28 => {
2829 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
2834
2835 cfg.feature_flags.metadata_in_module_bytes = true;
2838 cfg.feature_flags.publish_package_metadata = true;
2839 cfg.feature_flags.enable_move_authentication = true;
2841 cfg.transfer_receive_object_cost_base = Some(100);
2844
2845 if chain != Chain::Unknown {
2846 cfg.max_auth_gas = Some(20_000);
2848 }
2849
2850 if chain != Chain::Mainnet {
2851 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2853 cfg.feature_flags
2855 .pre_consensus_sponsor_only_move_authentication = true;
2856 }
2857 }
2858 _ => panic!("unsupported version {version:?}"),
2869 }
2870 }
2871 cfg
2872 }
2873
2874 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
2880 let (
2881 max_back_edges_per_function,
2882 max_back_edges_per_module,
2883 sanity_check_with_regex_reference_safety,
2884 ) = if let Some((
2885 max_back_edges_per_function,
2886 max_back_edges_per_module,
2887 sanity_check_with_regex_reference_safety,
2888 )) = signing_limits
2889 {
2890 (
2891 Some(max_back_edges_per_function),
2892 Some(max_back_edges_per_module),
2893 Some(sanity_check_with_regex_reference_safety),
2894 )
2895 } else {
2896 (None, None, None)
2897 };
2898
2899 let additional_borrow_checks = if signing_limits.is_some() {
2900 true
2903 } else {
2904 self.additional_borrow_checks()
2905 };
2906
2907 VerifierConfig {
2908 max_loop_depth: Some(self.max_loop_depth() as usize),
2909 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2910 max_function_parameters: Some(self.max_function_parameters() as usize),
2911 max_basic_blocks: Some(self.max_basic_blocks() as usize),
2912 max_value_stack_size: self.max_value_stack_size() as usize,
2913 max_type_nodes: Some(self.max_type_nodes() as usize),
2914 max_push_size: Some(self.max_push_size() as usize),
2915 max_dependency_depth: Some(self.max_dependency_depth() as usize),
2916 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2917 max_function_definitions: Some(self.max_function_definitions() as usize),
2918 max_data_definitions: Some(self.max_struct_definitions() as usize),
2919 max_constant_vector_len: Some(self.max_move_vector_len()),
2920 max_back_edges_per_function,
2921 max_back_edges_per_module,
2922 max_basic_blocks_in_script: None,
2923 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
2927 max_variants_in_enum: self.max_move_enum_variants_as_option(),
2928 additional_borrow_checks,
2929 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
2930 .map(|limit| limit as u128),
2931 }
2932 }
2933
2934 pub fn apply_overrides_for_testing(
2939 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
2940 ) -> OverrideGuard {
2941 CONFIG_OVERRIDE.with(|ovr| {
2942 let mut cur = ovr.borrow_mut();
2943 assert!(cur.is_none(), "config override already present");
2944 *cur = Some(Box::new(override_fn));
2945 OverrideGuard
2946 })
2947 }
2948}
2949
2950impl ProtocolConfig {
2955 pub fn set_per_object_congestion_control_mode_for_testing(
2956 &mut self,
2957 val: PerObjectCongestionControlMode,
2958 ) {
2959 self.feature_flags.per_object_congestion_control_mode = val;
2960 }
2961
2962 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
2963 self.feature_flags.consensus_choice = val;
2964 }
2965
2966 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
2967 self.feature_flags.consensus_network = val;
2968 }
2969
2970 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
2971 self.feature_flags.passkey_auth = val
2972 }
2973
2974 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
2975 self.feature_flags
2976 .disallow_new_modules_in_deps_only_packages = val;
2977 }
2978
2979 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
2980 self.feature_flags.consensus_round_prober = val;
2981 }
2982
2983 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
2984 self.feature_flags
2985 .consensus_distributed_vote_scoring_strategy = val;
2986 }
2987
2988 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
2989 self.consensus_gc_depth = Some(val);
2990 }
2991
2992 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
2993 self.feature_flags.consensus_linearize_subdag_v2 = val;
2994 }
2995
2996 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
2997 self.feature_flags
2998 .consensus_round_prober_probe_accepted_rounds = val;
2999 }
3000
3001 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
3002 self.feature_flags.accept_passkey_in_multisig = val;
3003 }
3004
3005 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
3006 self.feature_flags.consensus_smart_ancestor_selection = val;
3007 }
3008
3009 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
3010 self.feature_flags.consensus_batched_block_sync = val;
3011 }
3012
3013 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
3014 self.feature_flags
3015 .congestion_control_min_free_execution_slot = val;
3016 }
3017
3018 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
3019 self.feature_flags
3020 .congestion_control_gas_price_feedback_mechanism = val;
3021 }
3022
3023 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
3024 self.feature_flags.select_committee_from_eligible_validators = val;
3025 }
3026
3027 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
3028 self.feature_flags.track_non_committee_eligible_validators = val;
3029 }
3030
3031 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
3032 self.feature_flags
3033 .select_committee_supporting_next_epoch_version = val;
3034 }
3035
3036 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
3037 &mut self,
3038 val: bool,
3039 ) {
3040 self.feature_flags
3041 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3042 }
3043
3044 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3045 &mut self,
3046 val: bool,
3047 ) {
3048 self.feature_flags
3049 .consensus_commit_transactions_only_for_traversed_headers = val;
3050 }
3051
3052 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3053 &mut self,
3054 val: bool,
3055 ) {
3056 self.feature_flags
3057 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3058 }
3059
3060 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3061 &mut self,
3062 val: bool,
3063 ) {
3064 self.feature_flags
3065 .separate_gas_price_feedback_mechanism_for_randomness = val;
3066 }
3067
3068 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3069 self.feature_flags.metadata_in_module_bytes = val;
3070 }
3071
3072 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3073 self.feature_flags.publish_package_metadata = val;
3074 }
3075
3076 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3077 self.feature_flags.enable_move_authentication = val;
3078 }
3079
3080 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3081 self.feature_flags.enable_move_authentication_for_sponsor = val;
3082 }
3083
3084 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3085 self.feature_flags.consensus_fast_commit_sync = val;
3086 }
3087
3088 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3089 self.feature_flags.consensus_block_restrictions = val;
3090 }
3091
3092 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3093 self.feature_flags
3094 .pre_consensus_sponsor_only_move_authentication = val;
3095 }
3096}
3097
3098type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
3099
3100thread_local! {
3101 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
3102}
3103
3104#[must_use]
3105pub struct OverrideGuard;
3106
3107impl Drop for OverrideGuard {
3108 fn drop(&mut self) {
3109 info!("restoring override fn");
3110 CONFIG_OVERRIDE.with(|ovr| {
3111 *ovr.borrow_mut() = None;
3112 });
3113 }
3114}
3115
3116#[derive(PartialEq, Eq)]
3120pub enum LimitThresholdCrossed {
3121 None,
3122 Soft(u128, u128),
3123 Hard(u128, u128),
3124}
3125
3126pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
3129 x: T,
3130 soft_limit: U,
3131 hard_limit: V,
3132) -> LimitThresholdCrossed {
3133 let x: V = x.into();
3134 let soft_limit: V = soft_limit.into();
3135
3136 debug_assert!(soft_limit <= hard_limit);
3137
3138 if x >= hard_limit {
3141 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
3142 } else if x < soft_limit {
3143 LimitThresholdCrossed::None
3144 } else {
3145 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
3146 }
3147}
3148
3149#[macro_export]
3150macro_rules! check_limit {
3151 ($x:expr, $hard:expr) => {
3152 check_limit!($x, $hard, $hard)
3153 };
3154 ($x:expr, $soft:expr, $hard:expr) => {
3155 check_limit_in_range($x as u64, $soft, $hard)
3156 };
3157}
3158
3159#[macro_export]
3163macro_rules! check_limit_by_meter {
3164 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
3165 let (h, metered_str) = if $is_metered {
3167 ($metered_limit, "metered")
3168 } else {
3169 ($unmetered_hard_limit, "unmetered")
3171 };
3172 use iota_protocol_config::check_limit_in_range;
3173 let result = check_limit_in_range($x as u64, $metered_limit, h);
3174 match result {
3175 LimitThresholdCrossed::None => {}
3176 LimitThresholdCrossed::Soft(_, _) => {
3177 $metric.with_label_values(&[metered_str, "soft"]).inc();
3178 }
3179 LimitThresholdCrossed::Hard(_, _) => {
3180 $metric.with_label_values(&[metered_str, "hard"]).inc();
3181 }
3182 };
3183 result
3184 }};
3185}
3186
3187#[cfg(all(test, not(msim)))]
3188mod test {
3189 use insta::assert_yaml_snapshot;
3190
3191 use super::*;
3192
3193 #[test]
3194 fn snapshot_tests() {
3195 println!("\n============================================================================");
3196 println!("! !");
3197 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
3198 println!("! !");
3199 println!("============================================================================\n");
3200 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
3201 let chain_str = match chain_id {
3206 Chain::Unknown => "".to_string(),
3207 _ => format!("{chain_id:?}_"),
3208 };
3209 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
3210 let cur = ProtocolVersion::new(i);
3211 assert_yaml_snapshot!(
3212 format!("{}version_{}", chain_str, cur.as_u64()),
3213 ProtocolConfig::get_for_version(cur, *chain_id)
3214 );
3215 }
3216 }
3217 }
3218
3219 #[test]
3220 fn test_getters() {
3221 let prot: ProtocolConfig =
3222 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3223 assert_eq!(
3224 prot.max_arguments(),
3225 prot.max_arguments_as_option().unwrap()
3226 );
3227 }
3228
3229 #[test]
3230 fn test_setters() {
3231 let mut prot: ProtocolConfig =
3232 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3233 prot.set_max_arguments_for_testing(123);
3234 assert_eq!(prot.max_arguments(), 123);
3235
3236 prot.set_max_arguments_from_str_for_testing("321".to_string());
3237 assert_eq!(prot.max_arguments(), 321);
3238
3239 prot.disable_max_arguments_for_testing();
3240 assert_eq!(prot.max_arguments_as_option(), None);
3241
3242 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
3243 assert_eq!(prot.max_arguments(), 456);
3244 }
3245
3246 #[test]
3247 #[should_panic(expected = "unsupported version")]
3248 fn max_version_test() {
3249 let _ = ProtocolConfig::get_for_version_impl(
3252 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
3253 Chain::Unknown,
3254 );
3255 }
3256
3257 #[test]
3258 fn lookup_by_string_test() {
3259 let prot: ProtocolConfig =
3260 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3261 assert!(prot.lookup_attr("some random string".to_string()).is_none());
3263
3264 assert!(
3265 prot.lookup_attr("max_arguments".to_string())
3266 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
3267 );
3268
3269 assert!(
3271 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3272 .is_none()
3273 );
3274 assert!(
3275 prot.attr_map()
3276 .get("poseidon_bn254_cost_base")
3277 .unwrap()
3278 .is_none()
3279 );
3280
3281 let prot: ProtocolConfig =
3283 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3284
3285 assert!(
3286 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3287 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3288 );
3289 assert!(
3290 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
3291 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3292 );
3293
3294 let prot: ProtocolConfig =
3296 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3297 assert!(
3299 prot.feature_flags
3300 .lookup_attr("some random string".to_owned())
3301 .is_none()
3302 );
3303 assert!(
3304 !prot
3305 .feature_flags
3306 .attr_map()
3307 .contains_key("some random string")
3308 );
3309
3310 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
3312 assert!(
3313 prot.feature_flags
3314 .attr_map()
3315 .get("enable_poseidon")
3316 .unwrap()
3317 == &false
3318 );
3319 let prot: ProtocolConfig =
3320 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3321 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
3323 assert!(
3324 prot.feature_flags
3325 .attr_map()
3326 .get("enable_poseidon")
3327 .unwrap()
3328 == &true
3329 );
3330 }
3331
3332 #[test]
3333 fn limit_range_fn_test() {
3334 let low = 100u32;
3335 let high = 10000u64;
3336
3337 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
3338 assert!(matches!(
3339 check_limit!(255u16, low, high),
3340 LimitThresholdCrossed::Soft(255u128, 100)
3341 ));
3342 assert!(matches!(
3349 check_limit!(2550000u64, low, high),
3350 LimitThresholdCrossed::Hard(2550000, 10000)
3351 ));
3352
3353 assert!(matches!(
3354 check_limit!(2550000u64, high, high),
3355 LimitThresholdCrossed::Hard(2550000, 10000)
3356 ));
3357
3358 assert!(matches!(
3359 check_limit!(1u8, high),
3360 LimitThresholdCrossed::None
3361 ));
3362
3363 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
3364
3365 assert!(matches!(
3366 check_limit!(2550000u64, high),
3367 LimitThresholdCrossed::Hard(2550000, 10000)
3368 ));
3369 }
3370}