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 = 27;
23
24pub const PROTOCOL_VERSION_IIP8: u64 = 20;
26#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
152pub struct ProtocolVersion(u64);
153
154impl ProtocolVersion {
155 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
161
162 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
163
164 #[cfg(not(msim))]
165 const MAX_ALLOWED: Self = Self::MAX;
166
167 #[cfg(msim)]
170 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
171
172 pub fn new(v: u64) -> Self {
173 Self(v)
174 }
175
176 pub const fn as_u64(&self) -> u64 {
177 self.0
178 }
179
180 pub fn max() -> Self {
183 Self::MAX
184 }
185}
186
187impl From<u64> for ProtocolVersion {
188 fn from(v: u64) -> Self {
189 Self::new(v)
190 }
191}
192
193impl std::ops::Sub<u64> for ProtocolVersion {
194 type Output = Self;
195 fn sub(self, rhs: u64) -> Self::Output {
196 Self::new(self.0 - rhs)
197 }
198}
199
200impl std::ops::Add<u64> for ProtocolVersion {
201 type Output = Self;
202 fn add(self, rhs: u64) -> Self::Output {
203 Self::new(self.0 + rhs)
204 }
205}
206
207#[derive(
208 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
209)]
210pub enum Chain {
211 Mainnet,
212 Testnet,
213 #[default]
214 Unknown,
215}
216
217impl Chain {
218 pub fn as_str(self) -> &'static str {
219 match self {
220 Chain::Mainnet => "mainnet",
221 Chain::Testnet => "testnet",
222 Chain::Unknown => "unknown",
223 }
224 }
225}
226
227pub struct Error(pub String);
228
229#[derive(Default, Clone, Serialize, Deserialize, Debug, ProtocolConfigFeatureFlagsGetters)]
233struct FeatureFlags {
234 #[serde(skip_serializing_if = "is_true")]
240 disable_invariant_violation_check_in_swap_loc: bool,
241
242 #[serde(skip_serializing_if = "is_true")]
245 no_extraneous_module_bytes: bool,
246
247 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
249 consensus_transaction_ordering: ConsensusTransactionOrdering,
250
251 #[serde(skip_serializing_if = "is_true")]
254 hardened_otw_check: bool,
255
256 #[serde(skip_serializing_if = "is_false")]
258 enable_poseidon: bool,
259
260 #[serde(skip_serializing_if = "is_false")]
262 enable_group_ops_native_function_msm: bool,
263
264 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
266 per_object_congestion_control_mode: PerObjectCongestionControlMode,
267
268 #[serde(
270 default = "ConsensusChoice::mysticeti_deprecated",
271 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
272 )]
273 consensus_choice: ConsensusChoice,
274
275 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
277 consensus_network: ConsensusNetwork,
278
279 #[deprecated]
281 #[serde(skip_serializing_if = "Option::is_none")]
282 zklogin_max_epoch_upper_bound_delta: Option<u64>,
283
284 #[serde(skip_serializing_if = "is_false")]
286 enable_vdf: bool,
287
288 #[serde(skip_serializing_if = "is_false")]
290 passkey_auth: bool,
291
292 #[serde(skip_serializing_if = "is_true")]
295 rethrow_serialization_type_layout_errors: bool,
296
297 #[serde(skip_serializing_if = "is_false")]
299 relocate_event_module: bool,
300
301 #[serde(skip_serializing_if = "is_false")]
303 protocol_defined_base_fee: bool,
304
305 #[serde(skip_serializing_if = "is_false")]
307 uncompressed_g1_group_elements: bool,
308
309 #[serde(skip_serializing_if = "is_false")]
311 disallow_new_modules_in_deps_only_packages: bool,
312
313 #[serde(skip_serializing_if = "is_false")]
315 native_charging_v2: bool,
316
317 #[serde(skip_serializing_if = "is_false")]
319 convert_type_argument_error: bool,
320
321 #[serde(skip_serializing_if = "is_false")]
323 consensus_round_prober: bool,
324
325 #[serde(skip_serializing_if = "is_false")]
327 consensus_distributed_vote_scoring_strategy: bool,
328
329 #[serde(skip_serializing_if = "is_false")]
333 consensus_linearize_subdag_v2: bool,
334
335 #[serde(skip_serializing_if = "is_false")]
337 variant_nodes: bool,
338
339 #[serde(skip_serializing_if = "is_false")]
341 consensus_smart_ancestor_selection: bool,
342
343 #[serde(skip_serializing_if = "is_false")]
345 consensus_round_prober_probe_accepted_rounds: bool,
346
347 #[serde(skip_serializing_if = "is_false")]
349 consensus_zstd_compression: bool,
350
351 #[serde(skip_serializing_if = "is_false")]
354 congestion_control_min_free_execution_slot: bool,
355
356 #[serde(skip_serializing_if = "is_false")]
358 accept_passkey_in_multisig: bool,
359
360 #[serde(skip_serializing_if = "is_false")]
362 consensus_batched_block_sync: bool,
363
364 #[serde(skip_serializing_if = "is_false")]
367 congestion_control_gas_price_feedback_mechanism: bool,
368
369 #[serde(skip_serializing_if = "is_false")]
371 validate_identifier_inputs: bool,
372
373 #[serde(skip_serializing_if = "is_false")]
376 minimize_child_object_mutations: bool,
377
378 #[serde(skip_serializing_if = "is_false")]
380 dependency_linkage_error: bool,
381
382 #[serde(skip_serializing_if = "is_false")]
384 additional_multisig_checks: bool,
385
386 #[serde(skip_serializing_if = "is_false")]
389 normalize_ptb_arguments: bool,
390
391 #[serde(skip_serializing_if = "is_false")]
395 select_committee_from_eligible_validators: bool,
396
397 #[serde(skip_serializing_if = "is_false")]
404 track_non_committee_eligible_validators: bool,
405
406 #[serde(skip_serializing_if = "is_false")]
412 select_committee_supporting_next_epoch_version: bool,
413
414 #[serde(skip_serializing_if = "is_false")]
418 consensus_median_timestamp_with_checkpoint_enforcement: bool,
419
420 #[serde(skip_serializing_if = "is_false")]
422 consensus_commit_transactions_only_for_traversed_headers: bool,
423
424 #[serde(skip_serializing_if = "is_false")]
426 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
427
428 #[serde(skip_serializing_if = "is_false")]
431 separate_gas_price_feedback_mechanism_for_randomness: bool,
432
433 #[serde(skip_serializing_if = "is_false")]
436 metadata_in_module_bytes: bool,
437
438 #[serde(skip_serializing_if = "is_false")]
440 publish_package_metadata: bool,
441
442 #[serde(skip_serializing_if = "is_false")]
444 enable_move_authentication: bool,
445
446 #[serde(skip_serializing_if = "is_false")]
448 enable_move_authentication_for_sponsor: bool,
449
450 #[serde(skip_serializing_if = "is_false")]
452 pass_validator_scores_to_advance_epoch: bool,
453
454 #[serde(skip_serializing_if = "is_false")]
456 calculate_validator_scores: bool,
457
458 #[serde(skip_serializing_if = "is_false")]
460 adjust_rewards_by_score: bool,
461
462 #[serde(skip_serializing_if = "is_false")]
465 pass_calculated_validator_scores_to_advance_epoch: bool,
466
467 #[serde(skip_serializing_if = "is_false")]
472 consensus_fast_commit_sync: bool,
473
474 #[serde(skip_serializing_if = "is_false")]
477 consensus_block_restrictions: bool,
478
479 #[serde(skip_serializing_if = "is_false")]
481 move_native_tx_context: bool,
482
483 #[serde(skip_serializing_if = "is_false")]
485 additional_borrow_checks: bool,
486
487 #[serde(skip_serializing_if = "is_false")]
489 pre_consensus_sponsor_only_move_authentication: bool,
490}
491
492fn is_true(b: &bool) -> bool {
493 *b
494}
495
496fn is_false(b: &bool) -> bool {
497 !b
498}
499
500#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
502pub enum ConsensusTransactionOrdering {
503 #[default]
506 None,
507 ByGasPrice,
509}
510
511impl ConsensusTransactionOrdering {
512 pub fn is_none(&self) -> bool {
513 matches!(self, ConsensusTransactionOrdering::None)
514 }
515}
516
517#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
519pub enum PerObjectCongestionControlMode {
520 #[default]
521 None, TotalGasBudget, TotalTxCount, }
525
526impl PerObjectCongestionControlMode {
527 pub fn is_none(&self) -> bool {
528 matches!(self, PerObjectCongestionControlMode::None)
529 }
530}
531
532#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
534pub enum ConsensusChoice {
535 #[deprecated(note = "Mysticeti was replaced by Starfish")]
538 MysticetiDeprecated,
539 #[default]
540 Starfish,
541}
542
543#[expect(deprecated)]
544impl ConsensusChoice {
545 fn mysticeti_deprecated() -> Self {
552 ConsensusChoice::MysticetiDeprecated
553 }
554
555 pub fn is_mysticeti_deprecated(&self) -> bool {
556 matches!(self, ConsensusChoice::MysticetiDeprecated)
557 }
558 pub fn is_starfish(&self) -> bool {
559 matches!(self, ConsensusChoice::Starfish)
560 }
561}
562
563#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
565pub enum ConsensusNetwork {
566 #[default]
567 Tonic,
568}
569
570impl ConsensusNetwork {
571 pub fn is_tonic(&self) -> bool {
572 matches!(self, ConsensusNetwork::Tonic)
573 }
574}
575
576#[skip_serializing_none]
610#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
611pub struct ProtocolConfig {
612 pub version: ProtocolVersion,
613
614 feature_flags: FeatureFlags,
615
616 max_tx_size_bytes: Option<u64>,
621
622 max_input_objects: Option<u64>,
625
626 max_size_written_objects: Option<u64>,
631 max_size_written_objects_system_tx: Option<u64>,
635
636 max_serialized_tx_effects_size_bytes: Option<u64>,
638
639 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
641
642 max_gas_payment_objects: Option<u32>,
644
645 max_modules_in_publish: Option<u32>,
647
648 max_package_dependencies: Option<u32>,
650
651 max_arguments: Option<u32>,
654
655 max_type_arguments: Option<u32>,
657
658 max_type_argument_depth: Option<u32>,
660
661 max_pure_argument_size: Option<u32>,
663
664 max_programmable_tx_commands: Option<u32>,
666
667 move_binary_format_version: Option<u32>,
673 min_move_binary_format_version: Option<u32>,
674
675 binary_module_handles: Option<u16>,
677 binary_struct_handles: Option<u16>,
678 binary_function_handles: Option<u16>,
679 binary_function_instantiations: Option<u16>,
680 binary_signatures: Option<u16>,
681 binary_constant_pool: Option<u16>,
682 binary_identifiers: Option<u16>,
683 binary_address_identifiers: Option<u16>,
684 binary_struct_defs: Option<u16>,
685 binary_struct_def_instantiations: Option<u16>,
686 binary_function_defs: Option<u16>,
687 binary_field_handles: Option<u16>,
688 binary_field_instantiations: Option<u16>,
689 binary_friend_decls: Option<u16>,
690 binary_enum_defs: Option<u16>,
691 binary_enum_def_instantiations: Option<u16>,
692 binary_variant_handles: Option<u16>,
693 binary_variant_instantiation_handles: Option<u16>,
694
695 max_move_object_size: Option<u64>,
698
699 max_move_package_size: Option<u64>,
704
705 max_publish_or_upgrade_per_ptb: Option<u64>,
708
709 max_tx_gas: Option<u64>,
711
712 max_auth_gas: Option<u64>,
714
715 max_gas_price: Option<u64>,
718
719 max_gas_computation_bucket: Option<u64>,
722
723 gas_rounding_step: Option<u64>,
725
726 max_loop_depth: Option<u64>,
728
729 max_generic_instantiation_length: Option<u64>,
732
733 max_function_parameters: Option<u64>,
736
737 max_basic_blocks: Option<u64>,
740
741 max_value_stack_size: Option<u64>,
743
744 max_type_nodes: Option<u64>,
748
749 max_push_size: Option<u64>,
752
753 max_struct_definitions: Option<u64>,
756
757 max_function_definitions: Option<u64>,
760
761 max_fields_in_struct: Option<u64>,
764
765 max_dependency_depth: Option<u64>,
768
769 max_num_event_emit: Option<u64>,
772
773 max_num_new_move_object_ids: Option<u64>,
776
777 max_num_new_move_object_ids_system_tx: Option<u64>,
780
781 max_num_deleted_move_object_ids: Option<u64>,
784
785 max_num_deleted_move_object_ids_system_tx: Option<u64>,
788
789 max_num_transferred_move_object_ids: Option<u64>,
792
793 max_num_transferred_move_object_ids_system_tx: Option<u64>,
796
797 max_event_emit_size: Option<u64>,
799
800 max_event_emit_size_total: Option<u64>,
802
803 max_move_vector_len: Option<u64>,
806
807 max_move_identifier_len: Option<u64>,
810
811 max_move_value_depth: Option<u64>,
813
814 max_move_enum_variants: Option<u64>,
817
818 max_back_edges_per_function: Option<u64>,
821
822 max_back_edges_per_module: Option<u64>,
825
826 max_verifier_meter_ticks_per_function: Option<u64>,
829
830 max_meter_ticks_per_module: Option<u64>,
833
834 max_meter_ticks_per_package: Option<u64>,
837
838 object_runtime_max_num_cached_objects: Option<u64>,
845
846 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
849
850 object_runtime_max_num_store_entries: Option<u64>,
853
854 object_runtime_max_num_store_entries_system_tx: Option<u64>,
857
858 base_tx_cost_fixed: Option<u64>,
863
864 package_publish_cost_fixed: Option<u64>,
868
869 base_tx_cost_per_byte: Option<u64>,
873
874 package_publish_cost_per_byte: Option<u64>,
876
877 obj_access_cost_read_per_byte: Option<u64>,
879
880 obj_access_cost_mutate_per_byte: Option<u64>,
882
883 obj_access_cost_delete_per_byte: Option<u64>,
885
886 obj_access_cost_verify_per_byte: Option<u64>,
896
897 max_type_to_layout_nodes: Option<u64>,
899
900 max_ptb_value_size: Option<u64>,
902
903 gas_model_version: Option<u64>,
908
909 obj_data_cost_refundable: Option<u64>,
915
916 obj_metadata_cost_non_refundable: Option<u64>,
920
921 storage_rebate_rate: Option<u64>,
927
928 reward_slashing_rate: Option<u64>,
931
932 storage_gas_price: Option<u64>,
934
935 base_gas_price: Option<u64>,
937
938 validator_target_reward: Option<u64>,
940
941 max_transactions_per_checkpoint: Option<u64>,
948
949 max_checkpoint_size_bytes: Option<u64>,
953
954 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
960
961 address_from_bytes_cost_base: Option<u64>,
966 address_to_u256_cost_base: Option<u64>,
968 address_from_u256_cost_base: Option<u64>,
970
971 config_read_setting_impl_cost_base: Option<u64>,
976 config_read_setting_impl_cost_per_byte: Option<u64>,
977
978 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
982 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
983 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
984 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
985 dynamic_field_add_child_object_cost_base: Option<u64>,
988 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
989 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
990 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
991 dynamic_field_borrow_child_object_cost_base: Option<u64>,
994 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
995 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
996 dynamic_field_remove_child_object_cost_base: Option<u64>,
999 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1000 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1001 dynamic_field_has_child_object_cost_base: Option<u64>,
1004 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1007 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1008 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1009
1010 event_emit_cost_base: Option<u64>,
1013 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1014 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1015 event_emit_output_cost_per_byte: Option<u64>,
1016
1017 object_borrow_uid_cost_base: Option<u64>,
1020 object_delete_impl_cost_base: Option<u64>,
1022 object_record_new_uid_cost_base: Option<u64>,
1024
1025 transfer_transfer_internal_cost_base: Option<u64>,
1028 transfer_freeze_object_cost_base: Option<u64>,
1030 transfer_share_object_cost_base: Option<u64>,
1032 transfer_receive_object_cost_base: Option<u64>,
1035
1036 tx_context_derive_id_cost_base: Option<u64>,
1039 tx_context_fresh_id_cost_base: Option<u64>,
1040 tx_context_sender_cost_base: Option<u64>,
1041 tx_context_digest_cost_base: Option<u64>,
1042 tx_context_epoch_cost_base: Option<u64>,
1043 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1044 tx_context_sponsor_cost_base: Option<u64>,
1045 tx_context_rgp_cost_base: Option<u64>,
1046 tx_context_gas_price_cost_base: Option<u64>,
1047 tx_context_gas_budget_cost_base: Option<u64>,
1048 tx_context_ids_created_cost_base: Option<u64>,
1049 tx_context_replace_cost_base: Option<u64>,
1050
1051 types_is_one_time_witness_cost_base: Option<u64>,
1054 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1055 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1056
1057 validator_validate_metadata_cost_base: Option<u64>,
1060 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1061
1062 crypto_invalid_arguments_cost: Option<u64>,
1064 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1066 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1067 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1068
1069 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1071 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1072 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1073
1074 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1076 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1077 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1078 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1079 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1080 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1081
1082 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1084
1085 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1087 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1088 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1089 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1090 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1091 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1092
1093 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1095 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1096 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1097 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1098 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1099 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1100
1101 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1103 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1104 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1105 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1106 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1107 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1108
1109 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1111 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1112 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1113
1114 ed25519_ed25519_verify_cost_base: Option<u64>,
1116 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1117 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1118
1119 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1121 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1122
1123 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1125 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1126 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1127 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1128 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1129
1130 hash_blake2b256_cost_base: Option<u64>,
1132 hash_blake2b256_data_cost_per_byte: Option<u64>,
1133 hash_blake2b256_data_cost_per_block: Option<u64>,
1134
1135 hash_keccak256_cost_base: Option<u64>,
1137 hash_keccak256_data_cost_per_byte: Option<u64>,
1138 hash_keccak256_data_cost_per_block: Option<u64>,
1139
1140 poseidon_bn254_cost_base: Option<u64>,
1142 poseidon_bn254_cost_per_block: Option<u64>,
1143
1144 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1146 group_ops_bls12381_decode_g1_cost: Option<u64>,
1147 group_ops_bls12381_decode_g2_cost: Option<u64>,
1148 group_ops_bls12381_decode_gt_cost: Option<u64>,
1149 group_ops_bls12381_scalar_add_cost: Option<u64>,
1150 group_ops_bls12381_g1_add_cost: Option<u64>,
1151 group_ops_bls12381_g2_add_cost: Option<u64>,
1152 group_ops_bls12381_gt_add_cost: Option<u64>,
1153 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1154 group_ops_bls12381_g1_sub_cost: Option<u64>,
1155 group_ops_bls12381_g2_sub_cost: Option<u64>,
1156 group_ops_bls12381_gt_sub_cost: Option<u64>,
1157 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1158 group_ops_bls12381_g1_mul_cost: Option<u64>,
1159 group_ops_bls12381_g2_mul_cost: Option<u64>,
1160 group_ops_bls12381_gt_mul_cost: Option<u64>,
1161 group_ops_bls12381_scalar_div_cost: Option<u64>,
1162 group_ops_bls12381_g1_div_cost: Option<u64>,
1163 group_ops_bls12381_g2_div_cost: Option<u64>,
1164 group_ops_bls12381_gt_div_cost: Option<u64>,
1165 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1166 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1167 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1168 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1169 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1170 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1171 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1172 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1173 group_ops_bls12381_msm_max_len: Option<u32>,
1174 group_ops_bls12381_pairing_cost: Option<u64>,
1175 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1176 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1177 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1178 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1179 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1180
1181 hmac_hmac_sha3_256_cost_base: Option<u64>,
1183 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1184 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1185
1186 #[deprecated]
1188 check_zklogin_id_cost_base: Option<u64>,
1189 #[deprecated]
1191 check_zklogin_issuer_cost_base: Option<u64>,
1192
1193 vdf_verify_vdf_cost: Option<u64>,
1194 vdf_hash_to_input_cost: Option<u64>,
1195
1196 bcs_per_byte_serialized_cost: Option<u64>,
1198 bcs_legacy_min_output_size_cost: Option<u64>,
1199 bcs_failure_cost: Option<u64>,
1200
1201 hash_sha2_256_base_cost: Option<u64>,
1202 hash_sha2_256_per_byte_cost: Option<u64>,
1203 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1204 hash_sha3_256_base_cost: Option<u64>,
1205 hash_sha3_256_per_byte_cost: Option<u64>,
1206 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1207 type_name_get_base_cost: Option<u64>,
1208 type_name_get_per_byte_cost: Option<u64>,
1209
1210 string_check_utf8_base_cost: Option<u64>,
1211 string_check_utf8_per_byte_cost: Option<u64>,
1212 string_is_char_boundary_base_cost: Option<u64>,
1213 string_sub_string_base_cost: Option<u64>,
1214 string_sub_string_per_byte_cost: Option<u64>,
1215 string_index_of_base_cost: Option<u64>,
1216 string_index_of_per_byte_pattern_cost: Option<u64>,
1217 string_index_of_per_byte_searched_cost: Option<u64>,
1218
1219 vector_empty_base_cost: Option<u64>,
1220 vector_length_base_cost: Option<u64>,
1221 vector_push_back_base_cost: Option<u64>,
1222 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1223 vector_borrow_base_cost: Option<u64>,
1224 vector_pop_back_base_cost: Option<u64>,
1225 vector_destroy_empty_base_cost: Option<u64>,
1226 vector_swap_base_cost: Option<u64>,
1227 debug_print_base_cost: Option<u64>,
1228 debug_print_stack_trace_base_cost: Option<u64>,
1229
1230 execution_version: Option<u64>,
1232
1233 consensus_bad_nodes_stake_threshold: Option<u64>,
1237
1238 #[deprecated]
1239 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1240 #[deprecated]
1244 max_age_of_jwk_in_epochs: Option<u64>,
1245
1246 random_beacon_reduction_allowed_delta: Option<u16>,
1250
1251 random_beacon_reduction_lower_bound: Option<u32>,
1254
1255 random_beacon_dkg_timeout_round: Option<u32>,
1258
1259 random_beacon_min_round_interval_ms: Option<u64>,
1261
1262 random_beacon_dkg_version: Option<u64>,
1266
1267 consensus_max_transaction_size_bytes: Option<u64>,
1272 consensus_max_transactions_in_block_bytes: Option<u64>,
1274 consensus_max_num_transactions_in_block: Option<u64>,
1276
1277 max_deferral_rounds_for_congestion_control: Option<u64>,
1281
1282 min_checkpoint_interval_ms: Option<u64>,
1284
1285 checkpoint_summary_version_specific_data: Option<u64>,
1287
1288 max_soft_bundle_size: Option<u64>,
1291
1292 bridge_should_try_to_finalize_committee: Option<bool>,
1297
1298 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1304
1305 max_committee_members_count: Option<u64>,
1309
1310 consensus_gc_depth: Option<u32>,
1313
1314 consensus_max_acknowledgments_per_block: Option<u32>,
1320
1321 max_congestion_limit_overshoot_per_commit: Option<u64>,
1326
1327 scorer_version: Option<u16>,
1336
1337 auth_context_digest_cost_base: Option<u64>,
1340 auth_context_tx_data_bytes_cost_base: Option<u64>,
1342 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1343 auth_context_tx_commands_cost_base: Option<u64>,
1345 auth_context_tx_commands_cost_per_byte: Option<u64>,
1346 auth_context_tx_inputs_cost_base: Option<u64>,
1348 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1349 auth_context_replace_cost_base: Option<u64>,
1352 auth_context_replace_cost_per_byte: Option<u64>,
1353}
1354
1355impl ProtocolConfig {
1357 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1370 self.feature_flags
1371 .disable_invariant_violation_check_in_swap_loc
1372 }
1373
1374 pub fn no_extraneous_module_bytes(&self) -> bool {
1375 self.feature_flags.no_extraneous_module_bytes
1376 }
1377
1378 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1379 self.feature_flags.consensus_transaction_ordering
1380 }
1381
1382 pub fn dkg_version(&self) -> u64 {
1383 self.random_beacon_dkg_version.unwrap_or(1)
1385 }
1386
1387 pub fn hardened_otw_check(&self) -> bool {
1388 self.feature_flags.hardened_otw_check
1389 }
1390
1391 pub fn enable_poseidon(&self) -> bool {
1392 self.feature_flags.enable_poseidon
1393 }
1394
1395 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1396 self.feature_flags.enable_group_ops_native_function_msm
1397 }
1398
1399 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1400 self.feature_flags.per_object_congestion_control_mode
1401 }
1402
1403 pub fn consensus_choice(&self) -> ConsensusChoice {
1404 self.feature_flags.consensus_choice
1405 }
1406
1407 pub fn consensus_network(&self) -> ConsensusNetwork {
1408 self.feature_flags.consensus_network
1409 }
1410
1411 pub fn enable_vdf(&self) -> bool {
1412 self.feature_flags.enable_vdf
1413 }
1414
1415 pub fn passkey_auth(&self) -> bool {
1416 self.feature_flags.passkey_auth
1417 }
1418
1419 pub fn max_transaction_size_bytes(&self) -> u64 {
1420 self.consensus_max_transaction_size_bytes
1422 .unwrap_or(256 * 1024)
1423 }
1424
1425 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1426 if cfg!(msim) {
1427 256 * 1024
1428 } else {
1429 self.consensus_max_transactions_in_block_bytes
1430 .unwrap_or(512 * 1024)
1431 }
1432 }
1433
1434 pub fn max_num_transactions_in_block(&self) -> u64 {
1435 if cfg!(msim) {
1436 8
1437 } else {
1438 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1439 }
1440 }
1441
1442 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1443 self.feature_flags.rethrow_serialization_type_layout_errors
1444 }
1445
1446 pub fn relocate_event_module(&self) -> bool {
1447 self.feature_flags.relocate_event_module
1448 }
1449
1450 pub fn protocol_defined_base_fee(&self) -> bool {
1451 self.feature_flags.protocol_defined_base_fee
1452 }
1453
1454 pub fn uncompressed_g1_group_elements(&self) -> bool {
1455 self.feature_flags.uncompressed_g1_group_elements
1456 }
1457
1458 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1459 self.feature_flags
1460 .disallow_new_modules_in_deps_only_packages
1461 }
1462
1463 pub fn native_charging_v2(&self) -> bool {
1464 self.feature_flags.native_charging_v2
1465 }
1466
1467 pub fn consensus_round_prober(&self) -> bool {
1468 self.feature_flags.consensus_round_prober
1469 }
1470
1471 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1472 self.feature_flags
1473 .consensus_distributed_vote_scoring_strategy
1474 }
1475
1476 pub fn gc_depth(&self) -> u32 {
1477 if cfg!(msim) {
1478 min(5, self.consensus_gc_depth.unwrap_or(0))
1480 } else {
1481 self.consensus_gc_depth.unwrap_or(0)
1482 }
1483 }
1484
1485 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1486 let res = self.feature_flags.consensus_linearize_subdag_v2;
1487 assert!(
1488 !res || self.gc_depth() > 0,
1489 "The consensus linearize sub dag V2 requires GC to be enabled"
1490 );
1491 res
1492 }
1493
1494 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1495 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1496 }
1497
1498 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1499 if self.consensus_block_restrictions() {
1500 2 * committee_size
1501 } else {
1502 self.consensus_max_acknowledgments_per_block_or_default() as usize
1503 }
1504 }
1505
1506 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1507 if self.consensus_block_restrictions() {
1508 committee_size
1509 } else {
1510 100
1511 }
1512 }
1513
1514 pub fn variant_nodes(&self) -> bool {
1515 self.feature_flags.variant_nodes
1516 }
1517
1518 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1519 self.feature_flags.consensus_smart_ancestor_selection
1520 }
1521
1522 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1523 self.feature_flags
1524 .consensus_round_prober_probe_accepted_rounds
1525 }
1526
1527 pub fn consensus_zstd_compression(&self) -> bool {
1528 self.feature_flags.consensus_zstd_compression
1529 }
1530
1531 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1532 self.feature_flags
1533 .congestion_control_min_free_execution_slot
1534 }
1535
1536 pub fn accept_passkey_in_multisig(&self) -> bool {
1537 self.feature_flags.accept_passkey_in_multisig
1538 }
1539
1540 pub fn consensus_batched_block_sync(&self) -> bool {
1541 self.feature_flags.consensus_batched_block_sync
1542 }
1543
1544 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1547 self.feature_flags
1548 .congestion_control_gas_price_feedback_mechanism
1549 }
1550
1551 pub fn validate_identifier_inputs(&self) -> bool {
1552 self.feature_flags.validate_identifier_inputs
1553 }
1554
1555 pub fn minimize_child_object_mutations(&self) -> bool {
1556 self.feature_flags.minimize_child_object_mutations
1557 }
1558
1559 pub fn dependency_linkage_error(&self) -> bool {
1560 self.feature_flags.dependency_linkage_error
1561 }
1562
1563 pub fn additional_multisig_checks(&self) -> bool {
1564 self.feature_flags.additional_multisig_checks
1565 }
1566
1567 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1568 0
1571 }
1572
1573 pub fn normalize_ptb_arguments(&self) -> bool {
1574 self.feature_flags.normalize_ptb_arguments
1575 }
1576
1577 pub fn select_committee_from_eligible_validators(&self) -> bool {
1578 let res = self.feature_flags.select_committee_from_eligible_validators;
1579 assert!(
1580 !res || (self.protocol_defined_base_fee()
1581 && self.max_committee_members_count_as_option().is_some()),
1582 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1583 );
1584 res
1585 }
1586
1587 pub fn track_non_committee_eligible_validators(&self) -> bool {
1588 self.feature_flags.track_non_committee_eligible_validators
1589 }
1590
1591 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1592 let res = self
1593 .feature_flags
1594 .select_committee_supporting_next_epoch_version;
1595 assert!(
1596 !res || (self.track_non_committee_eligible_validators()
1597 && self.select_committee_from_eligible_validators()),
1598 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1599 );
1600 res
1601 }
1602
1603 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1604 let res = self
1605 .feature_flags
1606 .consensus_median_timestamp_with_checkpoint_enforcement;
1607 assert!(
1608 !res || self.gc_depth() > 0,
1609 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1610 );
1611 res
1612 }
1613
1614 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1615 self.feature_flags
1616 .consensus_commit_transactions_only_for_traversed_headers
1617 }
1618
1619 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1622 self.feature_flags
1623 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1624 }
1625
1626 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1629 self.feature_flags
1630 .separate_gas_price_feedback_mechanism_for_randomness
1631 }
1632
1633 pub fn metadata_in_module_bytes(&self) -> bool {
1634 self.feature_flags.metadata_in_module_bytes
1635 }
1636
1637 pub fn publish_package_metadata(&self) -> bool {
1638 self.feature_flags.publish_package_metadata
1639 }
1640
1641 pub fn enable_move_authentication(&self) -> bool {
1642 self.feature_flags.enable_move_authentication
1643 }
1644
1645 pub fn additional_borrow_checks(&self) -> bool {
1646 self.feature_flags.additional_borrow_checks
1647 }
1648
1649 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1650 let enable_move_authentication_for_sponsor =
1651 self.feature_flags.enable_move_authentication_for_sponsor;
1652 assert!(
1653 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1654 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1655 );
1656 enable_move_authentication_for_sponsor
1657 }
1658
1659 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1660 self.feature_flags.pass_validator_scores_to_advance_epoch
1661 }
1662
1663 pub fn calculate_validator_scores(&self) -> bool {
1664 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1665 assert!(
1666 !calculate_validator_scores || self.scorer_version.is_some(),
1667 "calculate_validator_scores requires scorer_version to be set"
1668 );
1669 calculate_validator_scores
1670 }
1671
1672 pub fn adjust_rewards_by_score(&self) -> bool {
1673 let adjust = self.feature_flags.adjust_rewards_by_score;
1674 assert!(
1675 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1676 "adjust_rewards_by_score requires scorer_version to be set"
1677 );
1678 adjust
1679 }
1680
1681 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1682 let pass = self
1683 .feature_flags
1684 .pass_calculated_validator_scores_to_advance_epoch;
1685 assert!(
1686 !pass
1687 || (self.pass_validator_scores_to_advance_epoch()
1688 && self.calculate_validator_scores()),
1689 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
1690 );
1691 pass
1692 }
1693 pub fn consensus_fast_commit_sync(&self) -> bool {
1694 let res = self.feature_flags.consensus_fast_commit_sync;
1695 assert!(
1696 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
1697 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
1698 );
1699 res
1700 }
1701
1702 pub fn consensus_block_restrictions(&self) -> bool {
1703 self.feature_flags.consensus_block_restrictions
1704 }
1705
1706 pub fn move_native_tx_context(&self) -> bool {
1707 self.feature_flags.move_native_tx_context
1708 }
1709
1710 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
1711 let pre_consensus_sponsor_only_move_authentication = self
1712 .feature_flags
1713 .pre_consensus_sponsor_only_move_authentication;
1714 if pre_consensus_sponsor_only_move_authentication {
1715 assert!(
1716 self.enable_move_authentication(),
1717 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
1718 );
1719 assert!(
1720 self.enable_move_authentication_for_sponsor(),
1721 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
1722 );
1723 }
1724 pre_consensus_sponsor_only_move_authentication
1725 }
1726}
1727
1728#[cfg(not(msim))]
1729static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1730
1731#[cfg(msim)]
1733thread_local! {
1734 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1735}
1736
1737impl ProtocolConfig {
1739 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1742 assert!(
1744 version >= ProtocolVersion::MIN,
1745 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1746 version,
1747 ProtocolVersion::MIN.0,
1748 );
1749 assert!(
1750 version <= ProtocolVersion::MAX_ALLOWED,
1751 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1752 version,
1753 ProtocolVersion::MAX_ALLOWED.0,
1754 );
1755
1756 let mut ret = Self::get_for_version_impl(version, chain);
1757 ret.version = version;
1758
1759 ret = CONFIG_OVERRIDE.with(|ovr| {
1760 if let Some(override_fn) = &*ovr.borrow() {
1761 warn!(
1762 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1763 );
1764 override_fn(version, ret)
1765 } else {
1766 ret
1767 }
1768 });
1769
1770 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1771 warn!(
1772 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1773 );
1774 let overrides: ProtocolConfigOptional =
1775 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1776 .expect("failed to parse ProtocolConfig override env variables");
1777 overrides.apply_to(&mut ret);
1778 }
1779
1780 ret
1781 }
1782
1783 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1786 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1787 let mut ret = Self::get_for_version_impl(version, chain);
1788 ret.version = version;
1789 Some(ret)
1790 } else {
1791 None
1792 }
1793 }
1794
1795 #[cfg(not(msim))]
1796 pub fn poison_get_for_min_version() {
1797 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1798 }
1799
1800 #[cfg(not(msim))]
1801 fn load_poison_get_for_min_version() -> bool {
1802 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1803 }
1804
1805 #[cfg(msim)]
1806 pub fn poison_get_for_min_version() {
1807 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1808 }
1809
1810 #[cfg(msim)]
1811 fn load_poison_get_for_min_version() -> bool {
1812 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1813 }
1814
1815 pub fn convert_type_argument_error(&self) -> bool {
1816 self.feature_flags.convert_type_argument_error
1817 }
1818
1819 pub fn get_for_min_version() -> Self {
1823 if Self::load_poison_get_for_min_version() {
1824 panic!("get_for_min_version called on validator");
1825 }
1826 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1827 }
1828
1829 #[expect(non_snake_case)]
1840 pub fn get_for_max_version_UNSAFE() -> Self {
1841 if Self::load_poison_get_for_min_version() {
1842 panic!("get_for_max_version_UNSAFE called on validator");
1843 }
1844 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1845 }
1846
1847 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1848 #[cfg(msim)]
1849 {
1850 if version > ProtocolVersion::MAX {
1852 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1853 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1854 return config;
1855 }
1856 }
1857
1858 let mut cfg = Self {
1862 version,
1863
1864 feature_flags: Default::default(),
1865
1866 max_tx_size_bytes: Some(128 * 1024),
1867 max_input_objects: Some(2048),
1870 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1871 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1872 max_gas_payment_objects: Some(256),
1873 max_modules_in_publish: Some(64),
1874 max_package_dependencies: Some(32),
1875 max_arguments: Some(512),
1876 max_type_arguments: Some(16),
1877 max_type_argument_depth: Some(16),
1878 max_pure_argument_size: Some(16 * 1024),
1879 max_programmable_tx_commands: Some(1024),
1880 move_binary_format_version: Some(7),
1881 min_move_binary_format_version: Some(6),
1882 binary_module_handles: Some(100),
1883 binary_struct_handles: Some(300),
1884 binary_function_handles: Some(1500),
1885 binary_function_instantiations: Some(750),
1886 binary_signatures: Some(1000),
1887 binary_constant_pool: Some(4000),
1888 binary_identifiers: Some(10000),
1889 binary_address_identifiers: Some(100),
1890 binary_struct_defs: Some(200),
1891 binary_struct_def_instantiations: Some(100),
1892 binary_function_defs: Some(1000),
1893 binary_field_handles: Some(500),
1894 binary_field_instantiations: Some(250),
1895 binary_friend_decls: Some(100),
1896 binary_enum_defs: None,
1897 binary_enum_def_instantiations: None,
1898 binary_variant_handles: None,
1899 binary_variant_instantiation_handles: None,
1900 max_move_object_size: Some(250 * 1024),
1901 max_move_package_size: Some(100 * 1024),
1902 max_publish_or_upgrade_per_ptb: Some(5),
1903 max_auth_gas: None,
1905 max_tx_gas: Some(50_000_000_000),
1907 max_gas_price: Some(100_000),
1908 max_gas_computation_bucket: Some(5_000_000),
1909 max_loop_depth: Some(5),
1910 max_generic_instantiation_length: Some(32),
1911 max_function_parameters: Some(128),
1912 max_basic_blocks: Some(1024),
1913 max_value_stack_size: Some(1024),
1914 max_type_nodes: Some(256),
1915 max_push_size: Some(10000),
1916 max_struct_definitions: Some(200),
1917 max_function_definitions: Some(1000),
1918 max_fields_in_struct: Some(32),
1919 max_dependency_depth: Some(100),
1920 max_num_event_emit: Some(1024),
1921 max_num_new_move_object_ids: Some(2048),
1922 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1923 max_num_deleted_move_object_ids: Some(2048),
1924 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1925 max_num_transferred_move_object_ids: Some(2048),
1926 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1927 max_event_emit_size: Some(250 * 1024),
1928 max_move_vector_len: Some(256 * 1024),
1929 max_type_to_layout_nodes: None,
1930 max_ptb_value_size: None,
1931
1932 max_back_edges_per_function: Some(10_000),
1933 max_back_edges_per_module: Some(10_000),
1934
1935 max_verifier_meter_ticks_per_function: Some(16_000_000),
1936
1937 max_meter_ticks_per_module: Some(16_000_000),
1938 max_meter_ticks_per_package: Some(16_000_000),
1939
1940 object_runtime_max_num_cached_objects: Some(1000),
1941 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
1942 object_runtime_max_num_store_entries: Some(1000),
1943 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
1944 base_tx_cost_fixed: Some(1_000),
1946 package_publish_cost_fixed: Some(1_000),
1947 base_tx_cost_per_byte: Some(0),
1948 package_publish_cost_per_byte: Some(80),
1949 obj_access_cost_read_per_byte: Some(15),
1950 obj_access_cost_mutate_per_byte: Some(40),
1951 obj_access_cost_delete_per_byte: Some(40),
1952 obj_access_cost_verify_per_byte: Some(200),
1953 obj_data_cost_refundable: Some(100),
1954 obj_metadata_cost_non_refundable: Some(50),
1955 gas_model_version: Some(1),
1956 storage_rebate_rate: Some(10000),
1957 reward_slashing_rate: Some(10000),
1959 storage_gas_price: Some(76),
1960 base_gas_price: None,
1961 validator_target_reward: Some(767_000 * 1_000_000_000),
1964 max_transactions_per_checkpoint: Some(10_000),
1965 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
1966
1967 buffer_stake_for_protocol_upgrade_bps: Some(5000),
1969
1970 address_from_bytes_cost_base: Some(52),
1974 address_to_u256_cost_base: Some(52),
1976 address_from_u256_cost_base: Some(52),
1978
1979 config_read_setting_impl_cost_base: Some(100),
1982 config_read_setting_impl_cost_per_byte: Some(40),
1983
1984 dynamic_field_hash_type_and_key_cost_base: Some(100),
1988 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
1989 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
1990 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
1991 dynamic_field_add_child_object_cost_base: Some(100),
1994 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
1995 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
1996 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
1997 dynamic_field_borrow_child_object_cost_base: Some(100),
2000 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2001 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2002 dynamic_field_remove_child_object_cost_base: Some(100),
2005 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2006 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2007 dynamic_field_has_child_object_cost_base: Some(100),
2010 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2013 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2014 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2015
2016 event_emit_cost_base: Some(52),
2019 event_emit_value_size_derivation_cost_per_byte: Some(2),
2020 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2021 event_emit_output_cost_per_byte: Some(10),
2022
2023 object_borrow_uid_cost_base: Some(52),
2026 object_delete_impl_cost_base: Some(52),
2028 object_record_new_uid_cost_base: Some(52),
2030
2031 transfer_transfer_internal_cost_base: Some(52),
2035 transfer_freeze_object_cost_base: Some(52),
2037 transfer_share_object_cost_base: Some(52),
2039 transfer_receive_object_cost_base: Some(52),
2040
2041 tx_context_derive_id_cost_base: Some(52),
2045 tx_context_fresh_id_cost_base: None,
2046 tx_context_sender_cost_base: None,
2047 tx_context_digest_cost_base: None,
2048 tx_context_epoch_cost_base: None,
2049 tx_context_epoch_timestamp_ms_cost_base: None,
2050 tx_context_sponsor_cost_base: None,
2051 tx_context_rgp_cost_base: None,
2052 tx_context_gas_price_cost_base: None,
2053 tx_context_gas_budget_cost_base: None,
2054 tx_context_ids_created_cost_base: None,
2055 tx_context_replace_cost_base: None,
2056
2057 types_is_one_time_witness_cost_base: Some(52),
2060 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2061 types_is_one_time_witness_type_cost_per_byte: Some(2),
2062
2063 validator_validate_metadata_cost_base: Some(52),
2067 validator_validate_metadata_data_cost_per_byte: Some(2),
2068
2069 crypto_invalid_arguments_cost: Some(100),
2071 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2073 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2074 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2075
2076 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2078 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2079 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2080
2081 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2083 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2084 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2085 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2086 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2087 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2088
2089 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2091
2092 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2094 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2095 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2096 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2097 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2098 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2099
2100 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2102 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2103 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2104 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2105 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2106 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2107
2108 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2110 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2111 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2112 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2113 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2114 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2115
2116 ecvrf_ecvrf_verify_cost_base: Some(52),
2118 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2119 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2120
2121 ed25519_ed25519_verify_cost_base: Some(52),
2123 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2124 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2125
2126 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2128 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2129
2130 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2132 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2133 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2134 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2135 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2136
2137 hash_blake2b256_cost_base: Some(52),
2139 hash_blake2b256_data_cost_per_byte: Some(2),
2140 hash_blake2b256_data_cost_per_block: Some(2),
2141 hash_keccak256_cost_base: Some(52),
2143 hash_keccak256_data_cost_per_byte: Some(2),
2144 hash_keccak256_data_cost_per_block: Some(2),
2145
2146 poseidon_bn254_cost_base: None,
2147 poseidon_bn254_cost_per_block: None,
2148
2149 hmac_hmac_sha3_256_cost_base: Some(52),
2151 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2152 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2153
2154 group_ops_bls12381_decode_scalar_cost: Some(52),
2156 group_ops_bls12381_decode_g1_cost: Some(52),
2157 group_ops_bls12381_decode_g2_cost: Some(52),
2158 group_ops_bls12381_decode_gt_cost: Some(52),
2159 group_ops_bls12381_scalar_add_cost: Some(52),
2160 group_ops_bls12381_g1_add_cost: Some(52),
2161 group_ops_bls12381_g2_add_cost: Some(52),
2162 group_ops_bls12381_gt_add_cost: Some(52),
2163 group_ops_bls12381_scalar_sub_cost: Some(52),
2164 group_ops_bls12381_g1_sub_cost: Some(52),
2165 group_ops_bls12381_g2_sub_cost: Some(52),
2166 group_ops_bls12381_gt_sub_cost: Some(52),
2167 group_ops_bls12381_scalar_mul_cost: Some(52),
2168 group_ops_bls12381_g1_mul_cost: Some(52),
2169 group_ops_bls12381_g2_mul_cost: Some(52),
2170 group_ops_bls12381_gt_mul_cost: Some(52),
2171 group_ops_bls12381_scalar_div_cost: Some(52),
2172 group_ops_bls12381_g1_div_cost: Some(52),
2173 group_ops_bls12381_g2_div_cost: Some(52),
2174 group_ops_bls12381_gt_div_cost: Some(52),
2175 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2176 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2177 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2178 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2179 group_ops_bls12381_g1_msm_base_cost: Some(52),
2180 group_ops_bls12381_g2_msm_base_cost: Some(52),
2181 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2182 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2183 group_ops_bls12381_msm_max_len: Some(32),
2184 group_ops_bls12381_pairing_cost: Some(52),
2185 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2186 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2187 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2188 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2189 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2190
2191 #[allow(deprecated)]
2193 check_zklogin_id_cost_base: Some(200),
2194 #[allow(deprecated)]
2195 check_zklogin_issuer_cost_base: Some(200),
2197
2198 vdf_verify_vdf_cost: None,
2199 vdf_hash_to_input_cost: None,
2200
2201 bcs_per_byte_serialized_cost: Some(2),
2202 bcs_legacy_min_output_size_cost: Some(1),
2203 bcs_failure_cost: Some(52),
2204 hash_sha2_256_base_cost: Some(52),
2205 hash_sha2_256_per_byte_cost: Some(2),
2206 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2207 hash_sha3_256_base_cost: Some(52),
2208 hash_sha3_256_per_byte_cost: Some(2),
2209 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2210 type_name_get_base_cost: Some(52),
2211 type_name_get_per_byte_cost: Some(2),
2212 string_check_utf8_base_cost: Some(52),
2213 string_check_utf8_per_byte_cost: Some(2),
2214 string_is_char_boundary_base_cost: Some(52),
2215 string_sub_string_base_cost: Some(52),
2216 string_sub_string_per_byte_cost: Some(2),
2217 string_index_of_base_cost: Some(52),
2218 string_index_of_per_byte_pattern_cost: Some(2),
2219 string_index_of_per_byte_searched_cost: Some(2),
2220 vector_empty_base_cost: Some(52),
2221 vector_length_base_cost: Some(52),
2222 vector_push_back_base_cost: Some(52),
2223 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2224 vector_borrow_base_cost: Some(52),
2225 vector_pop_back_base_cost: Some(52),
2226 vector_destroy_empty_base_cost: Some(52),
2227 vector_swap_base_cost: Some(52),
2228 debug_print_base_cost: Some(52),
2229 debug_print_stack_trace_base_cost: Some(52),
2230
2231 max_size_written_objects: Some(5 * 1000 * 1000),
2232 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2235
2236 max_move_identifier_len: Some(128),
2238 max_move_value_depth: Some(128),
2239 max_move_enum_variants: None,
2240
2241 gas_rounding_step: Some(1_000),
2242
2243 execution_version: Some(1),
2244
2245 max_event_emit_size_total: Some(
2248 256 * 250 * 1024, ),
2250
2251 consensus_bad_nodes_stake_threshold: Some(20),
2258
2259 #[allow(deprecated)]
2261 max_jwk_votes_per_validator_per_epoch: Some(240),
2262
2263 #[allow(deprecated)]
2264 max_age_of_jwk_in_epochs: Some(1),
2265
2266 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2270
2271 random_beacon_reduction_allowed_delta: Some(800),
2272
2273 random_beacon_reduction_lower_bound: Some(1000),
2274 random_beacon_dkg_timeout_round: Some(3000),
2275 random_beacon_min_round_interval_ms: Some(500),
2276
2277 random_beacon_dkg_version: Some(1),
2278
2279 consensus_max_num_transactions_in_block: Some(512),
2283
2284 max_deferral_rounds_for_congestion_control: Some(10),
2285
2286 min_checkpoint_interval_ms: Some(200),
2287
2288 checkpoint_summary_version_specific_data: Some(1),
2289
2290 max_soft_bundle_size: Some(5),
2291
2292 bridge_should_try_to_finalize_committee: None,
2293
2294 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2295
2296 max_committee_members_count: None,
2297
2298 consensus_gc_depth: None,
2299
2300 consensus_max_acknowledgments_per_block: None,
2301
2302 max_congestion_limit_overshoot_per_commit: None,
2303
2304 scorer_version: None,
2305
2306 auth_context_digest_cost_base: None,
2308 auth_context_tx_data_bytes_cost_base: None,
2309 auth_context_tx_data_bytes_cost_per_byte: None,
2310 auth_context_tx_commands_cost_base: None,
2311 auth_context_tx_commands_cost_per_byte: None,
2312 auth_context_tx_inputs_cost_base: None,
2313 auth_context_tx_inputs_cost_per_byte: None,
2314 auth_context_replace_cost_base: None,
2315 auth_context_replace_cost_per_byte: None,
2316 };
2319
2320 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2321
2322 {
2324 cfg.feature_flags
2325 .disable_invariant_violation_check_in_swap_loc = true;
2326 cfg.feature_flags.no_extraneous_module_bytes = true;
2327 cfg.feature_flags.hardened_otw_check = true;
2328 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2329 }
2330
2331 {
2333 #[allow(deprecated)]
2334 {
2335 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2336 }
2337 }
2338
2339 #[expect(deprecated)]
2343 {
2344 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2345 }
2346 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2348
2349 cfg.feature_flags.per_object_congestion_control_mode =
2350 PerObjectCongestionControlMode::TotalTxCount;
2351
2352 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2354
2355 if chain != Chain::Mainnet && chain != Chain::Testnet {
2357 cfg.feature_flags.enable_poseidon = true;
2358 cfg.poseidon_bn254_cost_base = Some(260);
2359 cfg.poseidon_bn254_cost_per_block = Some(10);
2360
2361 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2362
2363 cfg.feature_flags.enable_vdf = true;
2364 cfg.vdf_verify_vdf_cost = Some(1500);
2367 cfg.vdf_hash_to_input_cost = Some(100);
2368
2369 cfg.feature_flags.passkey_auth = true;
2370 }
2371
2372 for cur in 2..=version.0 {
2373 match cur {
2374 1 => unreachable!(),
2375 2 => {}
2377 3 => {
2378 cfg.feature_flags.relocate_event_module = true;
2379 }
2380 4 => {
2381 cfg.max_type_to_layout_nodes = Some(512);
2382 }
2383 5 => {
2384 cfg.feature_flags.protocol_defined_base_fee = true;
2385 cfg.base_gas_price = Some(1000);
2386
2387 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2388 cfg.feature_flags.convert_type_argument_error = true;
2389 cfg.feature_flags.native_charging_v2 = true;
2390
2391 if chain != Chain::Mainnet && chain != Chain::Testnet {
2392 cfg.feature_flags.uncompressed_g1_group_elements = true;
2393 }
2394
2395 cfg.gas_model_version = Some(2);
2396
2397 cfg.poseidon_bn254_cost_per_block = Some(388);
2398
2399 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2400 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2401 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2402 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2403 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2404 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2405 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2406 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2407
2408 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2410 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2411 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2412 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2413
2414 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2415 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2416 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2417 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2418 Some(8213);
2419 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2420 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2421 Some(9484);
2422
2423 cfg.hash_keccak256_cost_base = Some(10);
2424 cfg.hash_blake2b256_cost_base = Some(10);
2425
2426 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2428 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2429 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2430 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2431
2432 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2433 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2434 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2435 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2436
2437 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2438 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2439 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2440 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2441
2442 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2443 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2444 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2445 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2446
2447 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2448 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2449 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2450 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2451
2452 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2453 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2454
2455 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2456 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2457 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2458 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2459
2460 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2461 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2462 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2463 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2464 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2465
2466 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2467
2468 cfg.validator_validate_metadata_cost_base = Some(20000);
2469
2470 cfg.max_committee_members_count = Some(50);
2471 }
2472 6 => {
2473 cfg.max_ptb_value_size = Some(1024 * 1024);
2474 }
2475 7 => {
2476 }
2479 8 => {
2480 cfg.feature_flags.variant_nodes = true;
2481
2482 if chain != Chain::Mainnet {
2483 cfg.feature_flags.consensus_round_prober = true;
2485 cfg.feature_flags
2487 .consensus_distributed_vote_scoring_strategy = true;
2488 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2489 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2491 cfg.feature_flags
2493 .consensus_round_prober_probe_accepted_rounds = true;
2494 cfg.feature_flags.consensus_zstd_compression = true;
2496 cfg.consensus_gc_depth = Some(60);
2500 }
2501
2502 if chain != Chain::Testnet && chain != Chain::Mainnet {
2505 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2506 }
2507 }
2508 9 => {
2509 if chain != Chain::Mainnet {
2510 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2512 }
2513
2514 cfg.feature_flags.consensus_zstd_compression = true;
2516
2517 if chain != Chain::Testnet && chain != Chain::Mainnet {
2519 cfg.feature_flags.accept_passkey_in_multisig = true;
2520 }
2521
2522 cfg.bridge_should_try_to_finalize_committee = None;
2524 }
2525 10 => {
2526 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2529
2530 cfg.max_committee_members_count = Some(80);
2532
2533 cfg.feature_flags.consensus_round_prober = true;
2535 cfg.feature_flags
2537 .consensus_round_prober_probe_accepted_rounds = true;
2538 cfg.feature_flags
2540 .consensus_distributed_vote_scoring_strategy = true;
2541 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2543
2544 cfg.consensus_gc_depth = Some(60);
2549
2550 cfg.feature_flags.minimize_child_object_mutations = true;
2552
2553 if chain != Chain::Mainnet {
2554 cfg.feature_flags.consensus_batched_block_sync = true;
2556 }
2557
2558 if chain != Chain::Testnet && chain != Chain::Mainnet {
2559 cfg.feature_flags
2562 .congestion_control_gas_price_feedback_mechanism = true;
2563 }
2564
2565 cfg.feature_flags.validate_identifier_inputs = true;
2566 cfg.feature_flags.dependency_linkage_error = true;
2567 cfg.feature_flags.additional_multisig_checks = true;
2568 }
2569 11 => {
2570 }
2573 12 => {
2574 cfg.feature_flags
2577 .congestion_control_gas_price_feedback_mechanism = true;
2578
2579 cfg.feature_flags.normalize_ptb_arguments = true;
2581 }
2582 13 => {
2583 cfg.feature_flags.select_committee_from_eligible_validators = true;
2586 cfg.feature_flags.track_non_committee_eligible_validators = true;
2589
2590 if chain != Chain::Testnet && chain != Chain::Mainnet {
2591 cfg.feature_flags
2594 .select_committee_supporting_next_epoch_version = true;
2595 }
2596 }
2597 14 => {
2598 cfg.feature_flags.consensus_batched_block_sync = true;
2600
2601 if chain != Chain::Mainnet {
2602 cfg.feature_flags
2605 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2606 cfg.feature_flags
2610 .select_committee_supporting_next_epoch_version = true;
2611 }
2612 if chain != Chain::Testnet && chain != Chain::Mainnet {
2613 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2615 }
2616 }
2617 15 => {
2618 if chain != Chain::Mainnet && chain != Chain::Testnet {
2619 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2623 }
2624 }
2625 16 => {
2626 cfg.feature_flags
2629 .select_committee_supporting_next_epoch_version = true;
2630 cfg.feature_flags
2632 .consensus_commit_transactions_only_for_traversed_headers = true;
2633 }
2634 17 => {
2635 cfg.max_committee_members_count = Some(100);
2637 }
2638 18 => {
2639 if chain != Chain::Mainnet {
2640 cfg.feature_flags.passkey_auth = true;
2642 }
2643 }
2644 19 => {
2645 if chain != Chain::Testnet && chain != Chain::Mainnet {
2646 cfg.feature_flags
2649 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2650 cfg.feature_flags
2653 .separate_gas_price_feedback_mechanism_for_randomness = true;
2654 cfg.feature_flags.metadata_in_module_bytes = true;
2657 cfg.feature_flags.publish_package_metadata = true;
2658 cfg.feature_flags.enable_move_authentication = true;
2660 cfg.max_auth_gas = Some(250_000_000);
2662 cfg.transfer_receive_object_cost_base = Some(100);
2665 cfg.feature_flags.adjust_rewards_by_score = true;
2667 }
2668
2669 if chain != Chain::Mainnet {
2670 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2672
2673 cfg.feature_flags.calculate_validator_scores = true;
2675 cfg.scorer_version = Some(1);
2676 }
2677
2678 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
2680
2681 cfg.feature_flags.passkey_auth = true;
2683 }
2684 20 => {
2685 if chain != Chain::Testnet && chain != Chain::Mainnet {
2686 cfg.feature_flags
2688 .pass_calculated_validator_scores_to_advance_epoch = true;
2689 }
2690 }
2691 21 => {
2692 if chain != Chain::Testnet && chain != Chain::Mainnet {
2693 cfg.feature_flags.consensus_fast_commit_sync = true;
2695 }
2696 if chain != Chain::Mainnet {
2697 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2702 cfg.feature_flags
2705 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2706 cfg.feature_flags
2709 .separate_gas_price_feedback_mechanism_for_randomness = true;
2710 }
2711
2712 cfg.auth_context_digest_cost_base = Some(30);
2713 cfg.auth_context_tx_commands_cost_base = Some(30);
2714 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
2715 cfg.auth_context_tx_inputs_cost_base = Some(30);
2716 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
2717 cfg.auth_context_replace_cost_base = Some(30);
2718 cfg.auth_context_replace_cost_per_byte = Some(2);
2719
2720 if chain != Chain::Testnet && chain != Chain::Mainnet {
2721 cfg.max_auth_gas = Some(250_000);
2723 }
2724 }
2725 22 => {
2726 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2731 cfg.feature_flags
2734 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2735 cfg.feature_flags
2738 .separate_gas_price_feedback_mechanism_for_randomness = true;
2739
2740 if chain != Chain::Mainnet {
2741 cfg.feature_flags.metadata_in_module_bytes = true;
2744 cfg.feature_flags.publish_package_metadata = true;
2745 cfg.feature_flags.enable_move_authentication = true;
2747 cfg.max_auth_gas = Some(250_000);
2749 cfg.transfer_receive_object_cost_base = Some(100);
2752 }
2753
2754 if chain != Chain::Mainnet {
2755 cfg.feature_flags.consensus_fast_commit_sync = true;
2757 }
2758 }
2759 23 => {
2760 cfg.feature_flags.move_native_tx_context = true;
2762 cfg.tx_context_fresh_id_cost_base = Some(52);
2763 cfg.tx_context_sender_cost_base = Some(30);
2764 cfg.tx_context_digest_cost_base = Some(30);
2765 cfg.tx_context_epoch_cost_base = Some(30);
2766 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
2767 cfg.tx_context_sponsor_cost_base = Some(30);
2768 cfg.tx_context_rgp_cost_base = Some(30);
2769 cfg.tx_context_gas_price_cost_base = Some(30);
2770 cfg.tx_context_gas_budget_cost_base = Some(30);
2771 cfg.tx_context_ids_created_cost_base = Some(30);
2772 cfg.tx_context_replace_cost_base = Some(30);
2773 }
2774 24 => {
2775 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2777
2778 if chain != Chain::Testnet && chain != Chain::Mainnet {
2779 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2781 }
2782
2783 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
2786 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
2787
2788 cfg.feature_flags.additional_borrow_checks = true;
2790 }
2791 #[allow(deprecated)]
2792 25 => {
2793 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
2796 cfg.check_zklogin_id_cost_base = None;
2797 cfg.check_zklogin_issuer_cost_base = None;
2798 cfg.max_jwk_votes_per_validator_per_epoch = None;
2799 cfg.max_age_of_jwk_in_epochs = None;
2800 }
2801 26 => {
2802 }
2805 27 => {
2806 if chain != Chain::Mainnet {
2807 cfg.feature_flags.consensus_block_restrictions = true;
2810 }
2811
2812 if chain != Chain::Testnet && chain != Chain::Mainnet {
2813 cfg.feature_flags
2815 .pre_consensus_sponsor_only_move_authentication = true;
2816 }
2817 }
2818 _ => panic!("unsupported version {version:?}"),
2829 }
2830 }
2831 cfg
2832 }
2833
2834 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
2840 let (
2841 max_back_edges_per_function,
2842 max_back_edges_per_module,
2843 sanity_check_with_regex_reference_safety,
2844 ) = if let Some((
2845 max_back_edges_per_function,
2846 max_back_edges_per_module,
2847 sanity_check_with_regex_reference_safety,
2848 )) = signing_limits
2849 {
2850 (
2851 Some(max_back_edges_per_function),
2852 Some(max_back_edges_per_module),
2853 Some(sanity_check_with_regex_reference_safety),
2854 )
2855 } else {
2856 (None, None, None)
2857 };
2858
2859 let additional_borrow_checks = if signing_limits.is_some() {
2860 true
2863 } else {
2864 self.additional_borrow_checks()
2865 };
2866
2867 VerifierConfig {
2868 max_loop_depth: Some(self.max_loop_depth() as usize),
2869 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2870 max_function_parameters: Some(self.max_function_parameters() as usize),
2871 max_basic_blocks: Some(self.max_basic_blocks() as usize),
2872 max_value_stack_size: self.max_value_stack_size() as usize,
2873 max_type_nodes: Some(self.max_type_nodes() as usize),
2874 max_push_size: Some(self.max_push_size() as usize),
2875 max_dependency_depth: Some(self.max_dependency_depth() as usize),
2876 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2877 max_function_definitions: Some(self.max_function_definitions() as usize),
2878 max_data_definitions: Some(self.max_struct_definitions() as usize),
2879 max_constant_vector_len: Some(self.max_move_vector_len()),
2880 max_back_edges_per_function,
2881 max_back_edges_per_module,
2882 max_basic_blocks_in_script: None,
2883 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
2887 max_variants_in_enum: self.max_move_enum_variants_as_option(),
2888 additional_borrow_checks,
2889 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
2890 .map(|limit| limit as u128),
2891 }
2892 }
2893
2894 pub fn apply_overrides_for_testing(
2899 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
2900 ) -> OverrideGuard {
2901 CONFIG_OVERRIDE.with(|ovr| {
2902 let mut cur = ovr.borrow_mut();
2903 assert!(cur.is_none(), "config override already present");
2904 *cur = Some(Box::new(override_fn));
2905 OverrideGuard
2906 })
2907 }
2908}
2909
2910impl ProtocolConfig {
2915 pub fn set_per_object_congestion_control_mode_for_testing(
2916 &mut self,
2917 val: PerObjectCongestionControlMode,
2918 ) {
2919 self.feature_flags.per_object_congestion_control_mode = val;
2920 }
2921
2922 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
2923 self.feature_flags.consensus_choice = val;
2924 }
2925
2926 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
2927 self.feature_flags.consensus_network = val;
2928 }
2929
2930 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
2931 self.feature_flags.passkey_auth = val
2932 }
2933
2934 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
2935 self.feature_flags
2936 .disallow_new_modules_in_deps_only_packages = val;
2937 }
2938
2939 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
2940 self.feature_flags.consensus_round_prober = val;
2941 }
2942
2943 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
2944 self.feature_flags
2945 .consensus_distributed_vote_scoring_strategy = val;
2946 }
2947
2948 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
2949 self.consensus_gc_depth = Some(val);
2950 }
2951
2952 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
2953 self.feature_flags.consensus_linearize_subdag_v2 = val;
2954 }
2955
2956 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
2957 self.feature_flags
2958 .consensus_round_prober_probe_accepted_rounds = val;
2959 }
2960
2961 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
2962 self.feature_flags.accept_passkey_in_multisig = val;
2963 }
2964
2965 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
2966 self.feature_flags.consensus_smart_ancestor_selection = val;
2967 }
2968
2969 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
2970 self.feature_flags.consensus_batched_block_sync = val;
2971 }
2972
2973 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
2974 self.feature_flags
2975 .congestion_control_min_free_execution_slot = val;
2976 }
2977
2978 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
2979 self.feature_flags
2980 .congestion_control_gas_price_feedback_mechanism = val;
2981 }
2982
2983 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
2984 self.feature_flags.select_committee_from_eligible_validators = val;
2985 }
2986
2987 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
2988 self.feature_flags.track_non_committee_eligible_validators = val;
2989 }
2990
2991 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
2992 self.feature_flags
2993 .select_committee_supporting_next_epoch_version = val;
2994 }
2995
2996 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
2997 &mut self,
2998 val: bool,
2999 ) {
3000 self.feature_flags
3001 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3002 }
3003
3004 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3005 &mut self,
3006 val: bool,
3007 ) {
3008 self.feature_flags
3009 .consensus_commit_transactions_only_for_traversed_headers = val;
3010 }
3011
3012 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3013 &mut self,
3014 val: bool,
3015 ) {
3016 self.feature_flags
3017 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3018 }
3019
3020 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3021 &mut self,
3022 val: bool,
3023 ) {
3024 self.feature_flags
3025 .separate_gas_price_feedback_mechanism_for_randomness = val;
3026 }
3027
3028 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3029 self.feature_flags.metadata_in_module_bytes = val;
3030 }
3031
3032 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3033 self.feature_flags.publish_package_metadata = val;
3034 }
3035
3036 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3037 self.feature_flags.enable_move_authentication = val;
3038 }
3039
3040 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3041 self.feature_flags.enable_move_authentication_for_sponsor = val;
3042 }
3043
3044 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3045 self.feature_flags.consensus_fast_commit_sync = val;
3046 }
3047
3048 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3049 self.feature_flags.consensus_block_restrictions = val;
3050 }
3051
3052 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3053 self.feature_flags
3054 .pre_consensus_sponsor_only_move_authentication = val;
3055 }
3056}
3057
3058type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
3059
3060thread_local! {
3061 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
3062}
3063
3064#[must_use]
3065pub struct OverrideGuard;
3066
3067impl Drop for OverrideGuard {
3068 fn drop(&mut self) {
3069 info!("restoring override fn");
3070 CONFIG_OVERRIDE.with(|ovr| {
3071 *ovr.borrow_mut() = None;
3072 });
3073 }
3074}
3075
3076#[derive(PartialEq, Eq)]
3080pub enum LimitThresholdCrossed {
3081 None,
3082 Soft(u128, u128),
3083 Hard(u128, u128),
3084}
3085
3086pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
3089 x: T,
3090 soft_limit: U,
3091 hard_limit: V,
3092) -> LimitThresholdCrossed {
3093 let x: V = x.into();
3094 let soft_limit: V = soft_limit.into();
3095
3096 debug_assert!(soft_limit <= hard_limit);
3097
3098 if x >= hard_limit {
3101 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
3102 } else if x < soft_limit {
3103 LimitThresholdCrossed::None
3104 } else {
3105 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
3106 }
3107}
3108
3109#[macro_export]
3110macro_rules! check_limit {
3111 ($x:expr, $hard:expr) => {
3112 check_limit!($x, $hard, $hard)
3113 };
3114 ($x:expr, $soft:expr, $hard:expr) => {
3115 check_limit_in_range($x as u64, $soft, $hard)
3116 };
3117}
3118
3119#[macro_export]
3123macro_rules! check_limit_by_meter {
3124 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
3125 let (h, metered_str) = if $is_metered {
3127 ($metered_limit, "metered")
3128 } else {
3129 ($unmetered_hard_limit, "unmetered")
3131 };
3132 use iota_protocol_config::check_limit_in_range;
3133 let result = check_limit_in_range($x as u64, $metered_limit, h);
3134 match result {
3135 LimitThresholdCrossed::None => {}
3136 LimitThresholdCrossed::Soft(_, _) => {
3137 $metric.with_label_values(&[metered_str, "soft"]).inc();
3138 }
3139 LimitThresholdCrossed::Hard(_, _) => {
3140 $metric.with_label_values(&[metered_str, "hard"]).inc();
3141 }
3142 };
3143 result
3144 }};
3145}
3146
3147#[cfg(all(test, not(msim)))]
3148mod test {
3149 use insta::assert_yaml_snapshot;
3150
3151 use super::*;
3152
3153 #[test]
3154 fn snapshot_tests() {
3155 println!("\n============================================================================");
3156 println!("! !");
3157 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
3158 println!("! !");
3159 println!("============================================================================\n");
3160 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
3161 let chain_str = match chain_id {
3166 Chain::Unknown => "".to_string(),
3167 _ => format!("{chain_id:?}_"),
3168 };
3169 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
3170 let cur = ProtocolVersion::new(i);
3171 assert_yaml_snapshot!(
3172 format!("{}version_{}", chain_str, cur.as_u64()),
3173 ProtocolConfig::get_for_version(cur, *chain_id)
3174 );
3175 }
3176 }
3177 }
3178
3179 #[test]
3180 fn test_getters() {
3181 let prot: ProtocolConfig =
3182 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3183 assert_eq!(
3184 prot.max_arguments(),
3185 prot.max_arguments_as_option().unwrap()
3186 );
3187 }
3188
3189 #[test]
3190 fn test_setters() {
3191 let mut prot: ProtocolConfig =
3192 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3193 prot.set_max_arguments_for_testing(123);
3194 assert_eq!(prot.max_arguments(), 123);
3195
3196 prot.set_max_arguments_from_str_for_testing("321".to_string());
3197 assert_eq!(prot.max_arguments(), 321);
3198
3199 prot.disable_max_arguments_for_testing();
3200 assert_eq!(prot.max_arguments_as_option(), None);
3201
3202 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
3203 assert_eq!(prot.max_arguments(), 456);
3204 }
3205
3206 #[test]
3207 #[should_panic(expected = "unsupported version")]
3208 fn max_version_test() {
3209 let _ = ProtocolConfig::get_for_version_impl(
3212 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
3213 Chain::Unknown,
3214 );
3215 }
3216
3217 #[test]
3218 fn lookup_by_string_test() {
3219 let prot: ProtocolConfig =
3220 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3221 assert!(prot.lookup_attr("some random string".to_string()).is_none());
3223
3224 assert!(
3225 prot.lookup_attr("max_arguments".to_string())
3226 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
3227 );
3228
3229 assert!(
3231 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3232 .is_none()
3233 );
3234 assert!(
3235 prot.attr_map()
3236 .get("poseidon_bn254_cost_base")
3237 .unwrap()
3238 .is_none()
3239 );
3240
3241 let prot: ProtocolConfig =
3243 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3244
3245 assert!(
3246 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3247 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3248 );
3249 assert!(
3250 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
3251 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3252 );
3253
3254 let prot: ProtocolConfig =
3256 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3257 assert!(
3259 prot.feature_flags
3260 .lookup_attr("some random string".to_owned())
3261 .is_none()
3262 );
3263 assert!(
3264 !prot
3265 .feature_flags
3266 .attr_map()
3267 .contains_key("some random string")
3268 );
3269
3270 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
3272 assert!(
3273 prot.feature_flags
3274 .attr_map()
3275 .get("enable_poseidon")
3276 .unwrap()
3277 == &false
3278 );
3279 let prot: ProtocolConfig =
3280 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3281 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
3283 assert!(
3284 prot.feature_flags
3285 .attr_map()
3286 .get("enable_poseidon")
3287 .unwrap()
3288 == &true
3289 );
3290 }
3291
3292 #[test]
3293 fn limit_range_fn_test() {
3294 let low = 100u32;
3295 let high = 10000u64;
3296
3297 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
3298 assert!(matches!(
3299 check_limit!(255u16, low, high),
3300 LimitThresholdCrossed::Soft(255u128, 100)
3301 ));
3302 assert!(matches!(
3309 check_limit!(2550000u64, low, high),
3310 LimitThresholdCrossed::Hard(2550000, 10000)
3311 ));
3312
3313 assert!(matches!(
3314 check_limit!(2550000u64, high, high),
3315 LimitThresholdCrossed::Hard(2550000, 10000)
3316 ));
3317
3318 assert!(matches!(
3319 check_limit!(1u8, high),
3320 LimitThresholdCrossed::None
3321 ));
3322
3323 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
3324
3325 assert!(matches!(
3326 check_limit!(2550000u64, high),
3327 LimitThresholdCrossed::Hard(2550000, 10000)
3328 ));
3329 }
3330}