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)]
155pub struct ProtocolVersion(u64);
156
157impl ProtocolVersion {
158 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
164
165 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
166
167 #[cfg(not(msim))]
168 const MAX_ALLOWED: Self = Self::MAX;
169
170 #[cfg(msim)]
173 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
174
175 pub fn new(v: u64) -> Self {
176 Self(v)
177 }
178
179 pub const fn as_u64(&self) -> u64 {
180 self.0
181 }
182
183 pub fn max() -> Self {
186 Self::MAX
187 }
188}
189
190impl From<u64> for ProtocolVersion {
191 fn from(v: u64) -> Self {
192 Self::new(v)
193 }
194}
195
196impl std::ops::Sub<u64> for ProtocolVersion {
197 type Output = Self;
198 fn sub(self, rhs: u64) -> Self::Output {
199 Self::new(self.0 - rhs)
200 }
201}
202
203impl std::ops::Add<u64> for ProtocolVersion {
204 type Output = Self;
205 fn add(self, rhs: u64) -> Self::Output {
206 Self::new(self.0 + rhs)
207 }
208}
209
210#[derive(
211 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
212)]
213pub enum Chain {
214 Mainnet,
215 Testnet,
216 #[default]
217 Unknown,
218}
219
220impl Chain {
221 pub fn as_str(self) -> &'static str {
222 match self {
223 Chain::Mainnet => "mainnet",
224 Chain::Testnet => "testnet",
225 Chain::Unknown => "unknown",
226 }
227 }
228}
229
230pub struct Error(pub String);
231
232#[derive(Default, Clone, Serialize, Deserialize, Debug, ProtocolConfigFeatureFlagsGetters)]
236struct FeatureFlags {
237 #[serde(skip_serializing_if = "is_true")]
243 disable_invariant_violation_check_in_swap_loc: bool,
244
245 #[serde(skip_serializing_if = "is_true")]
248 no_extraneous_module_bytes: bool,
249
250 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
252 consensus_transaction_ordering: ConsensusTransactionOrdering,
253
254 #[serde(skip_serializing_if = "is_true")]
257 hardened_otw_check: bool,
258
259 #[serde(skip_serializing_if = "is_false")]
261 enable_poseidon: bool,
262
263 #[serde(skip_serializing_if = "is_false")]
265 enable_group_ops_native_function_msm: bool,
266
267 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
269 per_object_congestion_control_mode: PerObjectCongestionControlMode,
270
271 #[serde(
273 default = "ConsensusChoice::mysticeti_deprecated",
274 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
275 )]
276 consensus_choice: ConsensusChoice,
277
278 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
280 consensus_network: ConsensusNetwork,
281
282 #[deprecated]
284 #[serde(skip_serializing_if = "Option::is_none")]
285 zklogin_max_epoch_upper_bound_delta: Option<u64>,
286
287 #[serde(skip_serializing_if = "is_false")]
289 enable_vdf: bool,
290
291 #[serde(skip_serializing_if = "is_false")]
293 passkey_auth: bool,
294
295 #[serde(skip_serializing_if = "is_true")]
298 rethrow_serialization_type_layout_errors: bool,
299
300 #[serde(skip_serializing_if = "is_false")]
302 relocate_event_module: bool,
303
304 #[serde(skip_serializing_if = "is_false")]
306 protocol_defined_base_fee: bool,
307
308 #[serde(skip_serializing_if = "is_false")]
310 uncompressed_g1_group_elements: bool,
311
312 #[serde(skip_serializing_if = "is_false")]
314 disallow_new_modules_in_deps_only_packages: bool,
315
316 #[serde(skip_serializing_if = "is_false")]
318 native_charging_v2: bool,
319
320 #[serde(skip_serializing_if = "is_false")]
322 convert_type_argument_error: bool,
323
324 #[serde(skip_serializing_if = "is_false")]
326 consensus_round_prober: bool,
327
328 #[serde(skip_serializing_if = "is_false")]
330 consensus_distributed_vote_scoring_strategy: bool,
331
332 #[serde(skip_serializing_if = "is_false")]
336 consensus_linearize_subdag_v2: bool,
337
338 #[serde(skip_serializing_if = "is_false")]
340 variant_nodes: bool,
341
342 #[serde(skip_serializing_if = "is_false")]
344 consensus_smart_ancestor_selection: bool,
345
346 #[serde(skip_serializing_if = "is_false")]
348 consensus_round_prober_probe_accepted_rounds: bool,
349
350 #[serde(skip_serializing_if = "is_false")]
352 consensus_zstd_compression: bool,
353
354 #[serde(skip_serializing_if = "is_false")]
357 congestion_control_min_free_execution_slot: bool,
358
359 #[serde(skip_serializing_if = "is_false")]
361 accept_passkey_in_multisig: bool,
362
363 #[serde(skip_serializing_if = "is_false")]
365 consensus_batched_block_sync: bool,
366
367 #[serde(skip_serializing_if = "is_false")]
370 congestion_control_gas_price_feedback_mechanism: bool,
371
372 #[serde(skip_serializing_if = "is_false")]
374 validate_identifier_inputs: bool,
375
376 #[serde(skip_serializing_if = "is_false")]
379 minimize_child_object_mutations: bool,
380
381 #[serde(skip_serializing_if = "is_false")]
383 dependency_linkage_error: bool,
384
385 #[serde(skip_serializing_if = "is_false")]
387 additional_multisig_checks: bool,
388
389 #[serde(skip_serializing_if = "is_false")]
392 normalize_ptb_arguments: bool,
393
394 #[serde(skip_serializing_if = "is_false")]
398 select_committee_from_eligible_validators: bool,
399
400 #[serde(skip_serializing_if = "is_false")]
407 track_non_committee_eligible_validators: bool,
408
409 #[serde(skip_serializing_if = "is_false")]
415 select_committee_supporting_next_epoch_version: bool,
416
417 #[serde(skip_serializing_if = "is_false")]
421 consensus_median_timestamp_with_checkpoint_enforcement: bool,
422
423 #[serde(skip_serializing_if = "is_false")]
425 consensus_commit_transactions_only_for_traversed_headers: bool,
426
427 #[serde(skip_serializing_if = "is_false")]
429 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
430
431 #[serde(skip_serializing_if = "is_false")]
434 separate_gas_price_feedback_mechanism_for_randomness: bool,
435
436 #[serde(skip_serializing_if = "is_false")]
439 metadata_in_module_bytes: bool,
440
441 #[serde(skip_serializing_if = "is_false")]
443 publish_package_metadata: bool,
444
445 #[serde(skip_serializing_if = "is_false")]
447 enable_move_authentication: bool,
448
449 #[serde(skip_serializing_if = "is_false")]
451 enable_move_authentication_for_sponsor: bool,
452
453 #[serde(skip_serializing_if = "is_false")]
455 pass_validator_scores_to_advance_epoch: bool,
456
457 #[serde(skip_serializing_if = "is_false")]
459 calculate_validator_scores: bool,
460
461 #[serde(skip_serializing_if = "is_false")]
463 adjust_rewards_by_score: bool,
464
465 #[serde(skip_serializing_if = "is_false")]
468 pass_calculated_validator_scores_to_advance_epoch: bool,
469
470 #[serde(skip_serializing_if = "is_false")]
475 consensus_fast_commit_sync: bool,
476
477 #[serde(skip_serializing_if = "is_false")]
480 consensus_block_restrictions: bool,
481
482 #[serde(skip_serializing_if = "is_false")]
484 move_native_tx_context: bool,
485
486 #[serde(skip_serializing_if = "is_false")]
488 additional_borrow_checks: bool,
489
490 #[serde(skip_serializing_if = "is_false")]
492 pre_consensus_sponsor_only_move_authentication: bool,
493}
494
495fn is_true(b: &bool) -> bool {
496 *b
497}
498
499fn is_false(b: &bool) -> bool {
500 !b
501}
502
503#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
505pub enum ConsensusTransactionOrdering {
506 #[default]
509 None,
510 ByGasPrice,
512}
513
514impl ConsensusTransactionOrdering {
515 pub fn is_none(&self) -> bool {
516 matches!(self, ConsensusTransactionOrdering::None)
517 }
518}
519
520#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
522pub enum PerObjectCongestionControlMode {
523 #[default]
524 None, TotalGasBudget, TotalTxCount, }
528
529impl PerObjectCongestionControlMode {
530 pub fn is_none(&self) -> bool {
531 matches!(self, PerObjectCongestionControlMode::None)
532 }
533}
534
535#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
537pub enum ConsensusChoice {
538 #[deprecated(note = "Mysticeti was replaced by Starfish")]
541 MysticetiDeprecated,
542 #[default]
543 Starfish,
544}
545
546#[expect(deprecated)]
547impl ConsensusChoice {
548 fn mysticeti_deprecated() -> Self {
555 ConsensusChoice::MysticetiDeprecated
556 }
557
558 pub fn is_mysticeti_deprecated(&self) -> bool {
559 matches!(self, ConsensusChoice::MysticetiDeprecated)
560 }
561 pub fn is_starfish(&self) -> bool {
562 matches!(self, ConsensusChoice::Starfish)
563 }
564}
565
566#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
568pub enum ConsensusNetwork {
569 #[default]
570 Tonic,
571}
572
573impl ConsensusNetwork {
574 pub fn is_tonic(&self) -> bool {
575 matches!(self, ConsensusNetwork::Tonic)
576 }
577}
578
579#[skip_serializing_none]
613#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
614pub struct ProtocolConfig {
615 pub version: ProtocolVersion,
616
617 feature_flags: FeatureFlags,
618
619 max_tx_size_bytes: Option<u64>,
624
625 max_input_objects: Option<u64>,
628
629 max_size_written_objects: Option<u64>,
634 max_size_written_objects_system_tx: Option<u64>,
638
639 max_serialized_tx_effects_size_bytes: Option<u64>,
641
642 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
644
645 max_gas_payment_objects: Option<u32>,
647
648 max_modules_in_publish: Option<u32>,
650
651 max_package_dependencies: Option<u32>,
653
654 max_arguments: Option<u32>,
657
658 max_type_arguments: Option<u32>,
660
661 max_type_argument_depth: Option<u32>,
663
664 max_pure_argument_size: Option<u32>,
666
667 max_programmable_tx_commands: Option<u32>,
669
670 move_binary_format_version: Option<u32>,
676 min_move_binary_format_version: Option<u32>,
677
678 binary_module_handles: Option<u16>,
680 binary_struct_handles: Option<u16>,
681 binary_function_handles: Option<u16>,
682 binary_function_instantiations: Option<u16>,
683 binary_signatures: Option<u16>,
684 binary_constant_pool: Option<u16>,
685 binary_identifiers: Option<u16>,
686 binary_address_identifiers: Option<u16>,
687 binary_struct_defs: Option<u16>,
688 binary_struct_def_instantiations: Option<u16>,
689 binary_function_defs: Option<u16>,
690 binary_field_handles: Option<u16>,
691 binary_field_instantiations: Option<u16>,
692 binary_friend_decls: Option<u16>,
693 binary_enum_defs: Option<u16>,
694 binary_enum_def_instantiations: Option<u16>,
695 binary_variant_handles: Option<u16>,
696 binary_variant_instantiation_handles: Option<u16>,
697
698 max_move_object_size: Option<u64>,
701
702 max_move_package_size: Option<u64>,
707
708 max_publish_or_upgrade_per_ptb: Option<u64>,
711
712 max_tx_gas: Option<u64>,
714
715 max_auth_gas: Option<u64>,
717
718 max_gas_price: Option<u64>,
721
722 max_gas_computation_bucket: Option<u64>,
725
726 gas_rounding_step: Option<u64>,
728
729 max_loop_depth: Option<u64>,
731
732 max_generic_instantiation_length: Option<u64>,
735
736 max_function_parameters: Option<u64>,
739
740 max_basic_blocks: Option<u64>,
743
744 max_value_stack_size: Option<u64>,
746
747 max_type_nodes: Option<u64>,
751
752 max_push_size: Option<u64>,
755
756 max_struct_definitions: Option<u64>,
759
760 max_function_definitions: Option<u64>,
763
764 max_fields_in_struct: Option<u64>,
767
768 max_dependency_depth: Option<u64>,
771
772 max_num_event_emit: Option<u64>,
775
776 max_num_new_move_object_ids: Option<u64>,
779
780 max_num_new_move_object_ids_system_tx: Option<u64>,
783
784 max_num_deleted_move_object_ids: Option<u64>,
787
788 max_num_deleted_move_object_ids_system_tx: Option<u64>,
791
792 max_num_transferred_move_object_ids: Option<u64>,
795
796 max_num_transferred_move_object_ids_system_tx: Option<u64>,
799
800 max_event_emit_size: Option<u64>,
802
803 max_event_emit_size_total: Option<u64>,
805
806 max_move_vector_len: Option<u64>,
809
810 max_move_identifier_len: Option<u64>,
813
814 max_move_value_depth: Option<u64>,
816
817 max_move_enum_variants: Option<u64>,
820
821 max_back_edges_per_function: Option<u64>,
824
825 max_back_edges_per_module: Option<u64>,
828
829 max_verifier_meter_ticks_per_function: Option<u64>,
832
833 max_meter_ticks_per_module: Option<u64>,
836
837 max_meter_ticks_per_package: Option<u64>,
840
841 object_runtime_max_num_cached_objects: Option<u64>,
848
849 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
852
853 object_runtime_max_num_store_entries: Option<u64>,
856
857 object_runtime_max_num_store_entries_system_tx: Option<u64>,
860
861 base_tx_cost_fixed: Option<u64>,
866
867 package_publish_cost_fixed: Option<u64>,
871
872 base_tx_cost_per_byte: Option<u64>,
876
877 package_publish_cost_per_byte: Option<u64>,
879
880 obj_access_cost_read_per_byte: Option<u64>,
882
883 obj_access_cost_mutate_per_byte: Option<u64>,
885
886 obj_access_cost_delete_per_byte: Option<u64>,
888
889 obj_access_cost_verify_per_byte: Option<u64>,
899
900 max_type_to_layout_nodes: Option<u64>,
902
903 max_ptb_value_size: Option<u64>,
905
906 gas_model_version: Option<u64>,
911
912 obj_data_cost_refundable: Option<u64>,
918
919 obj_metadata_cost_non_refundable: Option<u64>,
923
924 storage_rebate_rate: Option<u64>,
930
931 reward_slashing_rate: Option<u64>,
934
935 storage_gas_price: Option<u64>,
937
938 base_gas_price: Option<u64>,
940
941 validator_target_reward: Option<u64>,
943
944 max_transactions_per_checkpoint: Option<u64>,
951
952 max_checkpoint_size_bytes: Option<u64>,
956
957 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
963
964 address_from_bytes_cost_base: Option<u64>,
969 address_to_u256_cost_base: Option<u64>,
971 address_from_u256_cost_base: Option<u64>,
973
974 config_read_setting_impl_cost_base: Option<u64>,
979 config_read_setting_impl_cost_per_byte: Option<u64>,
980
981 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
985 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
986 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
987 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
988 dynamic_field_add_child_object_cost_base: Option<u64>,
991 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
992 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
993 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
994 dynamic_field_borrow_child_object_cost_base: Option<u64>,
997 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
998 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
999 dynamic_field_remove_child_object_cost_base: Option<u64>,
1002 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1003 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1004 dynamic_field_has_child_object_cost_base: Option<u64>,
1007 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1010 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1011 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1012
1013 event_emit_cost_base: Option<u64>,
1016 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1017 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1018 event_emit_output_cost_per_byte: Option<u64>,
1019
1020 object_borrow_uid_cost_base: Option<u64>,
1023 object_delete_impl_cost_base: Option<u64>,
1025 object_record_new_uid_cost_base: Option<u64>,
1027
1028 transfer_transfer_internal_cost_base: Option<u64>,
1031 transfer_freeze_object_cost_base: Option<u64>,
1033 transfer_share_object_cost_base: Option<u64>,
1035 transfer_receive_object_cost_base: Option<u64>,
1038
1039 tx_context_derive_id_cost_base: Option<u64>,
1042 tx_context_fresh_id_cost_base: Option<u64>,
1043 tx_context_sender_cost_base: Option<u64>,
1044 tx_context_digest_cost_base: Option<u64>,
1045 tx_context_epoch_cost_base: Option<u64>,
1046 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1047 tx_context_sponsor_cost_base: Option<u64>,
1048 tx_context_rgp_cost_base: Option<u64>,
1049 tx_context_gas_price_cost_base: Option<u64>,
1050 tx_context_gas_budget_cost_base: Option<u64>,
1051 tx_context_ids_created_cost_base: Option<u64>,
1052 tx_context_replace_cost_base: Option<u64>,
1053
1054 types_is_one_time_witness_cost_base: Option<u64>,
1057 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1058 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1059
1060 validator_validate_metadata_cost_base: Option<u64>,
1063 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1064
1065 crypto_invalid_arguments_cost: Option<u64>,
1067 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1069 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1070 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1071
1072 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1074 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1075 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1076
1077 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1079 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1080 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1081 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1082 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1083 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1084
1085 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1087
1088 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1090 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1091 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1092 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1093 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1094 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1095
1096 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1098 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1099 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1100 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1101 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1102 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1103
1104 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1106 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1107 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1108 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1109 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1110 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1111
1112 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1114 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1115 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1116
1117 ed25519_ed25519_verify_cost_base: Option<u64>,
1119 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1120 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1121
1122 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1124 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1125
1126 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1128 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1129 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1130 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1131 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1132
1133 hash_blake2b256_cost_base: Option<u64>,
1135 hash_blake2b256_data_cost_per_byte: Option<u64>,
1136 hash_blake2b256_data_cost_per_block: Option<u64>,
1137
1138 hash_keccak256_cost_base: Option<u64>,
1140 hash_keccak256_data_cost_per_byte: Option<u64>,
1141 hash_keccak256_data_cost_per_block: Option<u64>,
1142
1143 poseidon_bn254_cost_base: Option<u64>,
1145 poseidon_bn254_cost_per_block: Option<u64>,
1146
1147 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1149 group_ops_bls12381_decode_g1_cost: Option<u64>,
1150 group_ops_bls12381_decode_g2_cost: Option<u64>,
1151 group_ops_bls12381_decode_gt_cost: Option<u64>,
1152 group_ops_bls12381_scalar_add_cost: Option<u64>,
1153 group_ops_bls12381_g1_add_cost: Option<u64>,
1154 group_ops_bls12381_g2_add_cost: Option<u64>,
1155 group_ops_bls12381_gt_add_cost: Option<u64>,
1156 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1157 group_ops_bls12381_g1_sub_cost: Option<u64>,
1158 group_ops_bls12381_g2_sub_cost: Option<u64>,
1159 group_ops_bls12381_gt_sub_cost: Option<u64>,
1160 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1161 group_ops_bls12381_g1_mul_cost: Option<u64>,
1162 group_ops_bls12381_g2_mul_cost: Option<u64>,
1163 group_ops_bls12381_gt_mul_cost: Option<u64>,
1164 group_ops_bls12381_scalar_div_cost: Option<u64>,
1165 group_ops_bls12381_g1_div_cost: Option<u64>,
1166 group_ops_bls12381_g2_div_cost: Option<u64>,
1167 group_ops_bls12381_gt_div_cost: Option<u64>,
1168 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1169 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1170 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1171 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1172 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1173 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1174 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1175 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1176 group_ops_bls12381_msm_max_len: Option<u32>,
1177 group_ops_bls12381_pairing_cost: Option<u64>,
1178 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1179 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1180 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1181 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1182 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1183
1184 hmac_hmac_sha3_256_cost_base: Option<u64>,
1186 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1187 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1188
1189 #[deprecated]
1191 check_zklogin_id_cost_base: Option<u64>,
1192 #[deprecated]
1194 check_zklogin_issuer_cost_base: Option<u64>,
1195
1196 vdf_verify_vdf_cost: Option<u64>,
1197 vdf_hash_to_input_cost: Option<u64>,
1198
1199 bcs_per_byte_serialized_cost: Option<u64>,
1201 bcs_legacy_min_output_size_cost: Option<u64>,
1202 bcs_failure_cost: Option<u64>,
1203
1204 hash_sha2_256_base_cost: Option<u64>,
1205 hash_sha2_256_per_byte_cost: Option<u64>,
1206 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1207 hash_sha3_256_base_cost: Option<u64>,
1208 hash_sha3_256_per_byte_cost: Option<u64>,
1209 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1210 type_name_get_base_cost: Option<u64>,
1211 type_name_get_per_byte_cost: Option<u64>,
1212
1213 string_check_utf8_base_cost: Option<u64>,
1214 string_check_utf8_per_byte_cost: Option<u64>,
1215 string_is_char_boundary_base_cost: Option<u64>,
1216 string_sub_string_base_cost: Option<u64>,
1217 string_sub_string_per_byte_cost: Option<u64>,
1218 string_index_of_base_cost: Option<u64>,
1219 string_index_of_per_byte_pattern_cost: Option<u64>,
1220 string_index_of_per_byte_searched_cost: Option<u64>,
1221
1222 vector_empty_base_cost: Option<u64>,
1223 vector_length_base_cost: Option<u64>,
1224 vector_push_back_base_cost: Option<u64>,
1225 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1226 vector_borrow_base_cost: Option<u64>,
1227 vector_pop_back_base_cost: Option<u64>,
1228 vector_destroy_empty_base_cost: Option<u64>,
1229 vector_swap_base_cost: Option<u64>,
1230 debug_print_base_cost: Option<u64>,
1231 debug_print_stack_trace_base_cost: Option<u64>,
1232
1233 execution_version: Option<u64>,
1235
1236 consensus_bad_nodes_stake_threshold: Option<u64>,
1240
1241 #[deprecated]
1242 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1243 #[deprecated]
1247 max_age_of_jwk_in_epochs: Option<u64>,
1248
1249 random_beacon_reduction_allowed_delta: Option<u16>,
1253
1254 random_beacon_reduction_lower_bound: Option<u32>,
1257
1258 random_beacon_dkg_timeout_round: Option<u32>,
1261
1262 random_beacon_min_round_interval_ms: Option<u64>,
1264
1265 random_beacon_dkg_version: Option<u64>,
1269
1270 consensus_max_transaction_size_bytes: Option<u64>,
1275 consensus_max_transactions_in_block_bytes: Option<u64>,
1277 consensus_max_num_transactions_in_block: Option<u64>,
1279
1280 max_deferral_rounds_for_congestion_control: Option<u64>,
1284
1285 min_checkpoint_interval_ms: Option<u64>,
1287
1288 checkpoint_summary_version_specific_data: Option<u64>,
1290
1291 max_soft_bundle_size: Option<u64>,
1294
1295 bridge_should_try_to_finalize_committee: Option<bool>,
1300
1301 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1307
1308 max_committee_members_count: Option<u64>,
1312
1313 consensus_gc_depth: Option<u32>,
1316
1317 consensus_max_acknowledgments_per_block: Option<u32>,
1323
1324 max_congestion_limit_overshoot_per_commit: Option<u64>,
1329
1330 scorer_version: Option<u16>,
1339
1340 auth_context_digest_cost_base: Option<u64>,
1343 auth_context_tx_data_bytes_cost_base: Option<u64>,
1345 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1346 auth_context_tx_commands_cost_base: Option<u64>,
1348 auth_context_tx_commands_cost_per_byte: Option<u64>,
1349 auth_context_tx_inputs_cost_base: Option<u64>,
1351 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1352 auth_context_replace_cost_base: Option<u64>,
1355 auth_context_replace_cost_per_byte: Option<u64>,
1356 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1360}
1361
1362impl ProtocolConfig {
1364 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1377 self.feature_flags
1378 .disable_invariant_violation_check_in_swap_loc
1379 }
1380
1381 pub fn no_extraneous_module_bytes(&self) -> bool {
1382 self.feature_flags.no_extraneous_module_bytes
1383 }
1384
1385 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1386 self.feature_flags.consensus_transaction_ordering
1387 }
1388
1389 pub fn dkg_version(&self) -> u64 {
1390 self.random_beacon_dkg_version.unwrap_or(1)
1392 }
1393
1394 pub fn hardened_otw_check(&self) -> bool {
1395 self.feature_flags.hardened_otw_check
1396 }
1397
1398 pub fn enable_poseidon(&self) -> bool {
1399 self.feature_flags.enable_poseidon
1400 }
1401
1402 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1403 self.feature_flags.enable_group_ops_native_function_msm
1404 }
1405
1406 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1407 self.feature_flags.per_object_congestion_control_mode
1408 }
1409
1410 pub fn consensus_choice(&self) -> ConsensusChoice {
1411 self.feature_flags.consensus_choice
1412 }
1413
1414 pub fn consensus_network(&self) -> ConsensusNetwork {
1415 self.feature_flags.consensus_network
1416 }
1417
1418 pub fn enable_vdf(&self) -> bool {
1419 self.feature_flags.enable_vdf
1420 }
1421
1422 pub fn passkey_auth(&self) -> bool {
1423 self.feature_flags.passkey_auth
1424 }
1425
1426 pub fn max_transaction_size_bytes(&self) -> u64 {
1427 self.consensus_max_transaction_size_bytes
1429 .unwrap_or(256 * 1024)
1430 }
1431
1432 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1433 if cfg!(msim) {
1434 256 * 1024
1435 } else {
1436 self.consensus_max_transactions_in_block_bytes
1437 .unwrap_or(512 * 1024)
1438 }
1439 }
1440
1441 pub fn max_num_transactions_in_block(&self) -> u64 {
1442 if cfg!(msim) {
1443 8
1444 } else {
1445 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1446 }
1447 }
1448
1449 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1450 self.feature_flags.rethrow_serialization_type_layout_errors
1451 }
1452
1453 pub fn relocate_event_module(&self) -> bool {
1454 self.feature_flags.relocate_event_module
1455 }
1456
1457 pub fn protocol_defined_base_fee(&self) -> bool {
1458 self.feature_flags.protocol_defined_base_fee
1459 }
1460
1461 pub fn uncompressed_g1_group_elements(&self) -> bool {
1462 self.feature_flags.uncompressed_g1_group_elements
1463 }
1464
1465 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1466 self.feature_flags
1467 .disallow_new_modules_in_deps_only_packages
1468 }
1469
1470 pub fn native_charging_v2(&self) -> bool {
1471 self.feature_flags.native_charging_v2
1472 }
1473
1474 pub fn consensus_round_prober(&self) -> bool {
1475 self.feature_flags.consensus_round_prober
1476 }
1477
1478 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1479 self.feature_flags
1480 .consensus_distributed_vote_scoring_strategy
1481 }
1482
1483 pub fn gc_depth(&self) -> u32 {
1484 if cfg!(msim) {
1485 min(5, self.consensus_gc_depth.unwrap_or(0))
1487 } else {
1488 self.consensus_gc_depth.unwrap_or(0)
1489 }
1490 }
1491
1492 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1493 let res = self.feature_flags.consensus_linearize_subdag_v2;
1494 assert!(
1495 !res || self.gc_depth() > 0,
1496 "The consensus linearize sub dag V2 requires GC to be enabled"
1497 );
1498 res
1499 }
1500
1501 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1502 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1503 }
1504
1505 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1506 if self.consensus_block_restrictions() {
1507 2 * committee_size
1508 } else {
1509 self.consensus_max_acknowledgments_per_block_or_default() as usize
1510 }
1511 }
1512
1513 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1514 if self.consensus_block_restrictions() {
1515 committee_size
1516 } else {
1517 100
1518 }
1519 }
1520
1521 pub fn variant_nodes(&self) -> bool {
1522 self.feature_flags.variant_nodes
1523 }
1524
1525 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1526 self.feature_flags.consensus_smart_ancestor_selection
1527 }
1528
1529 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1530 self.feature_flags
1531 .consensus_round_prober_probe_accepted_rounds
1532 }
1533
1534 pub fn consensus_zstd_compression(&self) -> bool {
1535 self.feature_flags.consensus_zstd_compression
1536 }
1537
1538 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1539 self.feature_flags
1540 .congestion_control_min_free_execution_slot
1541 }
1542
1543 pub fn accept_passkey_in_multisig(&self) -> bool {
1544 self.feature_flags.accept_passkey_in_multisig
1545 }
1546
1547 pub fn consensus_batched_block_sync(&self) -> bool {
1548 self.feature_flags.consensus_batched_block_sync
1549 }
1550
1551 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1554 self.feature_flags
1555 .congestion_control_gas_price_feedback_mechanism
1556 }
1557
1558 pub fn validate_identifier_inputs(&self) -> bool {
1559 self.feature_flags.validate_identifier_inputs
1560 }
1561
1562 pub fn minimize_child_object_mutations(&self) -> bool {
1563 self.feature_flags.minimize_child_object_mutations
1564 }
1565
1566 pub fn dependency_linkage_error(&self) -> bool {
1567 self.feature_flags.dependency_linkage_error
1568 }
1569
1570 pub fn additional_multisig_checks(&self) -> bool {
1571 self.feature_flags.additional_multisig_checks
1572 }
1573
1574 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1575 0
1578 }
1579
1580 pub fn normalize_ptb_arguments(&self) -> bool {
1581 self.feature_flags.normalize_ptb_arguments
1582 }
1583
1584 pub fn select_committee_from_eligible_validators(&self) -> bool {
1585 let res = self.feature_flags.select_committee_from_eligible_validators;
1586 assert!(
1587 !res || (self.protocol_defined_base_fee()
1588 && self.max_committee_members_count_as_option().is_some()),
1589 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1590 );
1591 res
1592 }
1593
1594 pub fn track_non_committee_eligible_validators(&self) -> bool {
1595 self.feature_flags.track_non_committee_eligible_validators
1596 }
1597
1598 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1599 let res = self
1600 .feature_flags
1601 .select_committee_supporting_next_epoch_version;
1602 assert!(
1603 !res || (self.track_non_committee_eligible_validators()
1604 && self.select_committee_from_eligible_validators()),
1605 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1606 );
1607 res
1608 }
1609
1610 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1611 let res = self
1612 .feature_flags
1613 .consensus_median_timestamp_with_checkpoint_enforcement;
1614 assert!(
1615 !res || self.gc_depth() > 0,
1616 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1617 );
1618 res
1619 }
1620
1621 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1622 self.feature_flags
1623 .consensus_commit_transactions_only_for_traversed_headers
1624 }
1625
1626 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1629 self.feature_flags
1630 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1631 }
1632
1633 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1636 self.feature_flags
1637 .separate_gas_price_feedback_mechanism_for_randomness
1638 }
1639
1640 pub fn metadata_in_module_bytes(&self) -> bool {
1641 self.feature_flags.metadata_in_module_bytes
1642 }
1643
1644 pub fn publish_package_metadata(&self) -> bool {
1645 self.feature_flags.publish_package_metadata
1646 }
1647
1648 pub fn enable_move_authentication(&self) -> bool {
1649 self.feature_flags.enable_move_authentication
1650 }
1651
1652 pub fn additional_borrow_checks(&self) -> bool {
1653 self.feature_flags.additional_borrow_checks
1654 }
1655
1656 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1657 let enable_move_authentication_for_sponsor =
1658 self.feature_flags.enable_move_authentication_for_sponsor;
1659 assert!(
1660 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1661 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1662 );
1663 enable_move_authentication_for_sponsor
1664 }
1665
1666 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1667 self.feature_flags.pass_validator_scores_to_advance_epoch
1668 }
1669
1670 pub fn calculate_validator_scores(&self) -> bool {
1671 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1672 assert!(
1673 !calculate_validator_scores || self.scorer_version.is_some(),
1674 "calculate_validator_scores requires scorer_version to be set"
1675 );
1676 calculate_validator_scores
1677 }
1678
1679 pub fn adjust_rewards_by_score(&self) -> bool {
1680 let adjust = self.feature_flags.adjust_rewards_by_score;
1681 assert!(
1682 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1683 "adjust_rewards_by_score requires scorer_version to be set"
1684 );
1685 adjust
1686 }
1687
1688 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1689 let pass = self
1690 .feature_flags
1691 .pass_calculated_validator_scores_to_advance_epoch;
1692 assert!(
1693 !pass
1694 || (self.pass_validator_scores_to_advance_epoch()
1695 && self.calculate_validator_scores()),
1696 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
1697 );
1698 pass
1699 }
1700 pub fn consensus_fast_commit_sync(&self) -> bool {
1701 let res = self.feature_flags.consensus_fast_commit_sync;
1702 assert!(
1703 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
1704 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
1705 );
1706 res
1707 }
1708
1709 pub fn consensus_block_restrictions(&self) -> bool {
1710 self.feature_flags.consensus_block_restrictions
1711 }
1712
1713 pub fn move_native_tx_context(&self) -> bool {
1714 self.feature_flags.move_native_tx_context
1715 }
1716
1717 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
1718 let pre_consensus_sponsor_only_move_authentication = self
1719 .feature_flags
1720 .pre_consensus_sponsor_only_move_authentication;
1721 if pre_consensus_sponsor_only_move_authentication {
1722 assert!(
1723 self.enable_move_authentication(),
1724 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
1725 );
1726 assert!(
1727 self.enable_move_authentication_for_sponsor(),
1728 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
1729 );
1730 }
1731 pre_consensus_sponsor_only_move_authentication
1732 }
1733}
1734
1735#[cfg(not(msim))]
1736static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1737
1738#[cfg(msim)]
1740thread_local! {
1741 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1742}
1743
1744impl ProtocolConfig {
1746 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1749 assert!(
1751 version >= ProtocolVersion::MIN,
1752 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1753 version,
1754 ProtocolVersion::MIN.0,
1755 );
1756 assert!(
1757 version <= ProtocolVersion::MAX_ALLOWED,
1758 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1759 version,
1760 ProtocolVersion::MAX_ALLOWED.0,
1761 );
1762
1763 let mut ret = Self::get_for_version_impl(version, chain);
1764 ret.version = version;
1765
1766 ret = CONFIG_OVERRIDE.with(|ovr| {
1767 if let Some(override_fn) = &*ovr.borrow() {
1768 warn!(
1769 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1770 );
1771 override_fn(version, ret)
1772 } else {
1773 ret
1774 }
1775 });
1776
1777 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1778 warn!(
1779 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1780 );
1781 let overrides: ProtocolConfigOptional =
1782 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1783 .expect("failed to parse ProtocolConfig override env variables");
1784 overrides.apply_to(&mut ret);
1785 }
1786
1787 ret
1788 }
1789
1790 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1793 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1794 let mut ret = Self::get_for_version_impl(version, chain);
1795 ret.version = version;
1796 Some(ret)
1797 } else {
1798 None
1799 }
1800 }
1801
1802 #[cfg(not(msim))]
1803 pub fn poison_get_for_min_version() {
1804 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1805 }
1806
1807 #[cfg(not(msim))]
1808 fn load_poison_get_for_min_version() -> bool {
1809 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1810 }
1811
1812 #[cfg(msim)]
1813 pub fn poison_get_for_min_version() {
1814 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1815 }
1816
1817 #[cfg(msim)]
1818 fn load_poison_get_for_min_version() -> bool {
1819 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1820 }
1821
1822 pub fn convert_type_argument_error(&self) -> bool {
1823 self.feature_flags.convert_type_argument_error
1824 }
1825
1826 pub fn get_for_min_version() -> Self {
1830 if Self::load_poison_get_for_min_version() {
1831 panic!("get_for_min_version called on validator");
1832 }
1833 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1834 }
1835
1836 #[expect(non_snake_case)]
1847 pub fn get_for_max_version_UNSAFE() -> Self {
1848 if Self::load_poison_get_for_min_version() {
1849 panic!("get_for_max_version_UNSAFE called on validator");
1850 }
1851 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1852 }
1853
1854 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1855 #[cfg(msim)]
1856 {
1857 if version > ProtocolVersion::MAX {
1859 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1860 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1861 return config;
1862 }
1863 }
1864
1865 let mut cfg = Self {
1869 version,
1870
1871 feature_flags: Default::default(),
1872
1873 max_tx_size_bytes: Some(128 * 1024),
1874 max_input_objects: Some(2048),
1877 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1878 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1879 max_gas_payment_objects: Some(256),
1880 max_modules_in_publish: Some(64),
1881 max_package_dependencies: Some(32),
1882 max_arguments: Some(512),
1883 max_type_arguments: Some(16),
1884 max_type_argument_depth: Some(16),
1885 max_pure_argument_size: Some(16 * 1024),
1886 max_programmable_tx_commands: Some(1024),
1887 move_binary_format_version: Some(7),
1888 min_move_binary_format_version: Some(6),
1889 binary_module_handles: Some(100),
1890 binary_struct_handles: Some(300),
1891 binary_function_handles: Some(1500),
1892 binary_function_instantiations: Some(750),
1893 binary_signatures: Some(1000),
1894 binary_constant_pool: Some(4000),
1895 binary_identifiers: Some(10000),
1896 binary_address_identifiers: Some(100),
1897 binary_struct_defs: Some(200),
1898 binary_struct_def_instantiations: Some(100),
1899 binary_function_defs: Some(1000),
1900 binary_field_handles: Some(500),
1901 binary_field_instantiations: Some(250),
1902 binary_friend_decls: Some(100),
1903 binary_enum_defs: None,
1904 binary_enum_def_instantiations: None,
1905 binary_variant_handles: None,
1906 binary_variant_instantiation_handles: None,
1907 max_move_object_size: Some(250 * 1024),
1908 max_move_package_size: Some(100 * 1024),
1909 max_publish_or_upgrade_per_ptb: Some(5),
1910 max_auth_gas: None,
1912 max_tx_gas: Some(50_000_000_000),
1914 max_gas_price: Some(100_000),
1915 max_gas_computation_bucket: Some(5_000_000),
1916 max_loop_depth: Some(5),
1917 max_generic_instantiation_length: Some(32),
1918 max_function_parameters: Some(128),
1919 max_basic_blocks: Some(1024),
1920 max_value_stack_size: Some(1024),
1921 max_type_nodes: Some(256),
1922 max_push_size: Some(10000),
1923 max_struct_definitions: Some(200),
1924 max_function_definitions: Some(1000),
1925 max_fields_in_struct: Some(32),
1926 max_dependency_depth: Some(100),
1927 max_num_event_emit: Some(1024),
1928 max_num_new_move_object_ids: Some(2048),
1929 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1930 max_num_deleted_move_object_ids: Some(2048),
1931 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1932 max_num_transferred_move_object_ids: Some(2048),
1933 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1934 max_event_emit_size: Some(250 * 1024),
1935 max_move_vector_len: Some(256 * 1024),
1936 max_type_to_layout_nodes: None,
1937 max_ptb_value_size: None,
1938
1939 max_back_edges_per_function: Some(10_000),
1940 max_back_edges_per_module: Some(10_000),
1941
1942 max_verifier_meter_ticks_per_function: Some(16_000_000),
1943
1944 max_meter_ticks_per_module: Some(16_000_000),
1945 max_meter_ticks_per_package: Some(16_000_000),
1946
1947 object_runtime_max_num_cached_objects: Some(1000),
1948 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
1949 object_runtime_max_num_store_entries: Some(1000),
1950 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
1951 base_tx_cost_fixed: Some(1_000),
1953 package_publish_cost_fixed: Some(1_000),
1954 base_tx_cost_per_byte: Some(0),
1955 package_publish_cost_per_byte: Some(80),
1956 obj_access_cost_read_per_byte: Some(15),
1957 obj_access_cost_mutate_per_byte: Some(40),
1958 obj_access_cost_delete_per_byte: Some(40),
1959 obj_access_cost_verify_per_byte: Some(200),
1960 obj_data_cost_refundable: Some(100),
1961 obj_metadata_cost_non_refundable: Some(50),
1962 gas_model_version: Some(1),
1963 storage_rebate_rate: Some(10000),
1964 reward_slashing_rate: Some(10000),
1966 storage_gas_price: Some(76),
1967 base_gas_price: None,
1968 validator_target_reward: Some(767_000 * 1_000_000_000),
1971 max_transactions_per_checkpoint: Some(10_000),
1972 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
1973
1974 buffer_stake_for_protocol_upgrade_bps: Some(5000),
1976
1977 address_from_bytes_cost_base: Some(52),
1981 address_to_u256_cost_base: Some(52),
1983 address_from_u256_cost_base: Some(52),
1985
1986 config_read_setting_impl_cost_base: Some(100),
1989 config_read_setting_impl_cost_per_byte: Some(40),
1990
1991 dynamic_field_hash_type_and_key_cost_base: Some(100),
1995 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
1996 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
1997 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
1998 dynamic_field_add_child_object_cost_base: Some(100),
2001 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2002 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2003 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2004 dynamic_field_borrow_child_object_cost_base: Some(100),
2007 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2008 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2009 dynamic_field_remove_child_object_cost_base: Some(100),
2012 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2013 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2014 dynamic_field_has_child_object_cost_base: Some(100),
2017 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2020 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2021 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2022
2023 event_emit_cost_base: Some(52),
2026 event_emit_value_size_derivation_cost_per_byte: Some(2),
2027 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2028 event_emit_output_cost_per_byte: Some(10),
2029
2030 object_borrow_uid_cost_base: Some(52),
2033 object_delete_impl_cost_base: Some(52),
2035 object_record_new_uid_cost_base: Some(52),
2037
2038 transfer_transfer_internal_cost_base: Some(52),
2042 transfer_freeze_object_cost_base: Some(52),
2044 transfer_share_object_cost_base: Some(52),
2046 transfer_receive_object_cost_base: Some(52),
2047
2048 tx_context_derive_id_cost_base: Some(52),
2052 tx_context_fresh_id_cost_base: None,
2053 tx_context_sender_cost_base: None,
2054 tx_context_digest_cost_base: None,
2055 tx_context_epoch_cost_base: None,
2056 tx_context_epoch_timestamp_ms_cost_base: None,
2057 tx_context_sponsor_cost_base: None,
2058 tx_context_rgp_cost_base: None,
2059 tx_context_gas_price_cost_base: None,
2060 tx_context_gas_budget_cost_base: None,
2061 tx_context_ids_created_cost_base: None,
2062 tx_context_replace_cost_base: None,
2063
2064 types_is_one_time_witness_cost_base: Some(52),
2067 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2068 types_is_one_time_witness_type_cost_per_byte: Some(2),
2069
2070 validator_validate_metadata_cost_base: Some(52),
2074 validator_validate_metadata_data_cost_per_byte: Some(2),
2075
2076 crypto_invalid_arguments_cost: Some(100),
2078 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2080 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2081 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2082
2083 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2085 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2086 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2087
2088 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2090 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2091 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2092 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2093 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2094 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2095
2096 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2098
2099 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2101 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2102 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2103 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2104 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2105 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2106
2107 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2109 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2110 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2111 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2112 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2113 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2114
2115 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2117 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2118 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2119 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2120 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2121 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2122
2123 ecvrf_ecvrf_verify_cost_base: Some(52),
2125 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2126 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2127
2128 ed25519_ed25519_verify_cost_base: Some(52),
2130 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2131 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2132
2133 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2135 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2136
2137 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2139 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2140 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2141 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2142 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2143
2144 hash_blake2b256_cost_base: Some(52),
2146 hash_blake2b256_data_cost_per_byte: Some(2),
2147 hash_blake2b256_data_cost_per_block: Some(2),
2148 hash_keccak256_cost_base: Some(52),
2150 hash_keccak256_data_cost_per_byte: Some(2),
2151 hash_keccak256_data_cost_per_block: Some(2),
2152
2153 poseidon_bn254_cost_base: None,
2154 poseidon_bn254_cost_per_block: None,
2155
2156 hmac_hmac_sha3_256_cost_base: Some(52),
2158 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2159 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2160
2161 group_ops_bls12381_decode_scalar_cost: Some(52),
2163 group_ops_bls12381_decode_g1_cost: Some(52),
2164 group_ops_bls12381_decode_g2_cost: Some(52),
2165 group_ops_bls12381_decode_gt_cost: Some(52),
2166 group_ops_bls12381_scalar_add_cost: Some(52),
2167 group_ops_bls12381_g1_add_cost: Some(52),
2168 group_ops_bls12381_g2_add_cost: Some(52),
2169 group_ops_bls12381_gt_add_cost: Some(52),
2170 group_ops_bls12381_scalar_sub_cost: Some(52),
2171 group_ops_bls12381_g1_sub_cost: Some(52),
2172 group_ops_bls12381_g2_sub_cost: Some(52),
2173 group_ops_bls12381_gt_sub_cost: Some(52),
2174 group_ops_bls12381_scalar_mul_cost: Some(52),
2175 group_ops_bls12381_g1_mul_cost: Some(52),
2176 group_ops_bls12381_g2_mul_cost: Some(52),
2177 group_ops_bls12381_gt_mul_cost: Some(52),
2178 group_ops_bls12381_scalar_div_cost: Some(52),
2179 group_ops_bls12381_g1_div_cost: Some(52),
2180 group_ops_bls12381_g2_div_cost: Some(52),
2181 group_ops_bls12381_gt_div_cost: Some(52),
2182 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2183 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2184 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2185 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2186 group_ops_bls12381_g1_msm_base_cost: Some(52),
2187 group_ops_bls12381_g2_msm_base_cost: Some(52),
2188 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2189 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2190 group_ops_bls12381_msm_max_len: Some(32),
2191 group_ops_bls12381_pairing_cost: Some(52),
2192 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2193 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2194 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2195 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2196 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2197
2198 #[allow(deprecated)]
2200 check_zklogin_id_cost_base: Some(200),
2201 #[allow(deprecated)]
2202 check_zklogin_issuer_cost_base: Some(200),
2204
2205 vdf_verify_vdf_cost: None,
2206 vdf_hash_to_input_cost: None,
2207
2208 bcs_per_byte_serialized_cost: Some(2),
2209 bcs_legacy_min_output_size_cost: Some(1),
2210 bcs_failure_cost: Some(52),
2211 hash_sha2_256_base_cost: Some(52),
2212 hash_sha2_256_per_byte_cost: Some(2),
2213 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2214 hash_sha3_256_base_cost: Some(52),
2215 hash_sha3_256_per_byte_cost: Some(2),
2216 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2217 type_name_get_base_cost: Some(52),
2218 type_name_get_per_byte_cost: Some(2),
2219 string_check_utf8_base_cost: Some(52),
2220 string_check_utf8_per_byte_cost: Some(2),
2221 string_is_char_boundary_base_cost: Some(52),
2222 string_sub_string_base_cost: Some(52),
2223 string_sub_string_per_byte_cost: Some(2),
2224 string_index_of_base_cost: Some(52),
2225 string_index_of_per_byte_pattern_cost: Some(2),
2226 string_index_of_per_byte_searched_cost: Some(2),
2227 vector_empty_base_cost: Some(52),
2228 vector_length_base_cost: Some(52),
2229 vector_push_back_base_cost: Some(52),
2230 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2231 vector_borrow_base_cost: Some(52),
2232 vector_pop_back_base_cost: Some(52),
2233 vector_destroy_empty_base_cost: Some(52),
2234 vector_swap_base_cost: Some(52),
2235 debug_print_base_cost: Some(52),
2236 debug_print_stack_trace_base_cost: Some(52),
2237
2238 max_size_written_objects: Some(5 * 1000 * 1000),
2239 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2242
2243 max_move_identifier_len: Some(128),
2245 max_move_value_depth: Some(128),
2246 max_move_enum_variants: None,
2247
2248 gas_rounding_step: Some(1_000),
2249
2250 execution_version: Some(1),
2251
2252 max_event_emit_size_total: Some(
2255 256 * 250 * 1024, ),
2257
2258 consensus_bad_nodes_stake_threshold: Some(20),
2265
2266 #[allow(deprecated)]
2268 max_jwk_votes_per_validator_per_epoch: Some(240),
2269
2270 #[allow(deprecated)]
2271 max_age_of_jwk_in_epochs: Some(1),
2272
2273 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2277
2278 random_beacon_reduction_allowed_delta: Some(800),
2279
2280 random_beacon_reduction_lower_bound: Some(1000),
2281 random_beacon_dkg_timeout_round: Some(3000),
2282 random_beacon_min_round_interval_ms: Some(500),
2283
2284 random_beacon_dkg_version: Some(1),
2285
2286 consensus_max_num_transactions_in_block: Some(512),
2290
2291 max_deferral_rounds_for_congestion_control: Some(10),
2292
2293 min_checkpoint_interval_ms: Some(200),
2294
2295 checkpoint_summary_version_specific_data: Some(1),
2296
2297 max_soft_bundle_size: Some(5),
2298
2299 bridge_should_try_to_finalize_committee: None,
2300
2301 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2302
2303 max_committee_members_count: None,
2304
2305 consensus_gc_depth: None,
2306
2307 consensus_max_acknowledgments_per_block: None,
2308
2309 max_congestion_limit_overshoot_per_commit: None,
2310
2311 scorer_version: None,
2312
2313 auth_context_digest_cost_base: None,
2315 auth_context_tx_data_bytes_cost_base: None,
2316 auth_context_tx_data_bytes_cost_per_byte: None,
2317 auth_context_tx_commands_cost_base: None,
2318 auth_context_tx_commands_cost_per_byte: None,
2319 auth_context_tx_inputs_cost_base: None,
2320 auth_context_tx_inputs_cost_per_byte: None,
2321 auth_context_replace_cost_base: None,
2322 auth_context_replace_cost_per_byte: None,
2323 auth_context_authenticator_function_info_v1_cost_base: None,
2324 };
2327
2328 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2329
2330 {
2332 cfg.feature_flags
2333 .disable_invariant_violation_check_in_swap_loc = true;
2334 cfg.feature_flags.no_extraneous_module_bytes = true;
2335 cfg.feature_flags.hardened_otw_check = true;
2336 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2337 }
2338
2339 {
2341 #[allow(deprecated)]
2342 {
2343 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2344 }
2345 }
2346
2347 #[expect(deprecated)]
2351 {
2352 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2353 }
2354 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2356
2357 cfg.feature_flags.per_object_congestion_control_mode =
2358 PerObjectCongestionControlMode::TotalTxCount;
2359
2360 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2362
2363 if chain != Chain::Mainnet && chain != Chain::Testnet {
2365 cfg.feature_flags.enable_poseidon = true;
2366 cfg.poseidon_bn254_cost_base = Some(260);
2367 cfg.poseidon_bn254_cost_per_block = Some(10);
2368
2369 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2370
2371 cfg.feature_flags.enable_vdf = true;
2372 cfg.vdf_verify_vdf_cost = Some(1500);
2375 cfg.vdf_hash_to_input_cost = Some(100);
2376
2377 cfg.feature_flags.passkey_auth = true;
2378 }
2379
2380 for cur in 2..=version.0 {
2381 match cur {
2382 1 => unreachable!(),
2383 2 => {}
2385 3 => {
2386 cfg.feature_flags.relocate_event_module = true;
2387 }
2388 4 => {
2389 cfg.max_type_to_layout_nodes = Some(512);
2390 }
2391 5 => {
2392 cfg.feature_flags.protocol_defined_base_fee = true;
2393 cfg.base_gas_price = Some(1000);
2394
2395 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2396 cfg.feature_flags.convert_type_argument_error = true;
2397 cfg.feature_flags.native_charging_v2 = true;
2398
2399 if chain != Chain::Mainnet && chain != Chain::Testnet {
2400 cfg.feature_flags.uncompressed_g1_group_elements = true;
2401 }
2402
2403 cfg.gas_model_version = Some(2);
2404
2405 cfg.poseidon_bn254_cost_per_block = Some(388);
2406
2407 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2408 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2409 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2410 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2411 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2412 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2413 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2414 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2415
2416 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2418 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2419 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2420 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2421
2422 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2423 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2424 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2425 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2426 Some(8213);
2427 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2428 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2429 Some(9484);
2430
2431 cfg.hash_keccak256_cost_base = Some(10);
2432 cfg.hash_blake2b256_cost_base = Some(10);
2433
2434 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2436 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2437 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2438 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2439
2440 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2441 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2442 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2443 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2444
2445 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2446 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2447 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2448 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2449
2450 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2451 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2452 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2453 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2454
2455 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2456 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2457 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2458 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2459
2460 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2461 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2462
2463 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2464 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2465 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2466 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2467
2468 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2469 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2470 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2471 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2472 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2473
2474 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2475
2476 cfg.validator_validate_metadata_cost_base = Some(20000);
2477
2478 cfg.max_committee_members_count = Some(50);
2479 }
2480 6 => {
2481 cfg.max_ptb_value_size = Some(1024 * 1024);
2482 }
2483 7 => {
2484 }
2487 8 => {
2488 cfg.feature_flags.variant_nodes = true;
2489
2490 if chain != Chain::Mainnet {
2491 cfg.feature_flags.consensus_round_prober = true;
2493 cfg.feature_flags
2495 .consensus_distributed_vote_scoring_strategy = true;
2496 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2497 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2499 cfg.feature_flags
2501 .consensus_round_prober_probe_accepted_rounds = true;
2502 cfg.feature_flags.consensus_zstd_compression = true;
2504 cfg.consensus_gc_depth = Some(60);
2508 }
2509
2510 if chain != Chain::Testnet && chain != Chain::Mainnet {
2513 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2514 }
2515 }
2516 9 => {
2517 if chain != Chain::Mainnet {
2518 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2520 }
2521
2522 cfg.feature_flags.consensus_zstd_compression = true;
2524
2525 if chain != Chain::Testnet && chain != Chain::Mainnet {
2527 cfg.feature_flags.accept_passkey_in_multisig = true;
2528 }
2529
2530 cfg.bridge_should_try_to_finalize_committee = None;
2532 }
2533 10 => {
2534 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2537
2538 cfg.max_committee_members_count = Some(80);
2540
2541 cfg.feature_flags.consensus_round_prober = true;
2543 cfg.feature_flags
2545 .consensus_round_prober_probe_accepted_rounds = true;
2546 cfg.feature_flags
2548 .consensus_distributed_vote_scoring_strategy = true;
2549 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2551
2552 cfg.consensus_gc_depth = Some(60);
2557
2558 cfg.feature_flags.minimize_child_object_mutations = true;
2560
2561 if chain != Chain::Mainnet {
2562 cfg.feature_flags.consensus_batched_block_sync = true;
2564 }
2565
2566 if chain != Chain::Testnet && chain != Chain::Mainnet {
2567 cfg.feature_flags
2570 .congestion_control_gas_price_feedback_mechanism = true;
2571 }
2572
2573 cfg.feature_flags.validate_identifier_inputs = true;
2574 cfg.feature_flags.dependency_linkage_error = true;
2575 cfg.feature_flags.additional_multisig_checks = true;
2576 }
2577 11 => {
2578 }
2581 12 => {
2582 cfg.feature_flags
2585 .congestion_control_gas_price_feedback_mechanism = true;
2586
2587 cfg.feature_flags.normalize_ptb_arguments = true;
2589 }
2590 13 => {
2591 cfg.feature_flags.select_committee_from_eligible_validators = true;
2594 cfg.feature_flags.track_non_committee_eligible_validators = true;
2597
2598 if chain != Chain::Testnet && chain != Chain::Mainnet {
2599 cfg.feature_flags
2602 .select_committee_supporting_next_epoch_version = true;
2603 }
2604 }
2605 14 => {
2606 cfg.feature_flags.consensus_batched_block_sync = true;
2608
2609 if chain != Chain::Mainnet {
2610 cfg.feature_flags
2613 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2614 cfg.feature_flags
2618 .select_committee_supporting_next_epoch_version = true;
2619 }
2620 if chain != Chain::Testnet && chain != Chain::Mainnet {
2621 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2623 }
2624 }
2625 15 => {
2626 if chain != Chain::Mainnet && chain != Chain::Testnet {
2627 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2631 }
2632 }
2633 16 => {
2634 cfg.feature_flags
2637 .select_committee_supporting_next_epoch_version = true;
2638 cfg.feature_flags
2640 .consensus_commit_transactions_only_for_traversed_headers = true;
2641 }
2642 17 => {
2643 cfg.max_committee_members_count = Some(100);
2645 }
2646 18 => {
2647 if chain != Chain::Mainnet {
2648 cfg.feature_flags.passkey_auth = true;
2650 }
2651 }
2652 19 => {
2653 if chain != Chain::Testnet && chain != Chain::Mainnet {
2654 cfg.feature_flags
2657 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2658 cfg.feature_flags
2661 .separate_gas_price_feedback_mechanism_for_randomness = true;
2662 cfg.feature_flags.metadata_in_module_bytes = true;
2665 cfg.feature_flags.publish_package_metadata = true;
2666 cfg.feature_flags.enable_move_authentication = true;
2668 cfg.max_auth_gas = Some(250_000_000);
2670 cfg.transfer_receive_object_cost_base = Some(100);
2673 cfg.feature_flags.adjust_rewards_by_score = true;
2675 }
2676
2677 if chain != Chain::Mainnet {
2678 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2680
2681 cfg.feature_flags.calculate_validator_scores = true;
2683 cfg.scorer_version = Some(1);
2684 }
2685
2686 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
2688
2689 cfg.feature_flags.passkey_auth = true;
2691 }
2692 20 => {
2693 if chain != Chain::Testnet && chain != Chain::Mainnet {
2694 cfg.feature_flags
2696 .pass_calculated_validator_scores_to_advance_epoch = true;
2697 }
2698 }
2699 21 => {
2700 if chain != Chain::Testnet && chain != Chain::Mainnet {
2701 cfg.feature_flags.consensus_fast_commit_sync = true;
2703 }
2704 if chain != Chain::Mainnet {
2705 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2710 cfg.feature_flags
2713 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2714 cfg.feature_flags
2717 .separate_gas_price_feedback_mechanism_for_randomness = true;
2718 }
2719
2720 cfg.auth_context_digest_cost_base = Some(30);
2721 cfg.auth_context_tx_commands_cost_base = Some(30);
2722 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
2723 cfg.auth_context_tx_inputs_cost_base = Some(30);
2724 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
2725 cfg.auth_context_replace_cost_base = Some(30);
2726 cfg.auth_context_replace_cost_per_byte = Some(2);
2727
2728 if chain != Chain::Testnet && chain != Chain::Mainnet {
2729 cfg.max_auth_gas = Some(250_000);
2731 }
2732 }
2733 22 => {
2734 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2739 cfg.feature_flags
2742 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2743 cfg.feature_flags
2746 .separate_gas_price_feedback_mechanism_for_randomness = true;
2747
2748 if chain != Chain::Mainnet {
2749 cfg.feature_flags.metadata_in_module_bytes = true;
2752 cfg.feature_flags.publish_package_metadata = true;
2753 cfg.feature_flags.enable_move_authentication = true;
2755 cfg.max_auth_gas = Some(250_000);
2757 cfg.transfer_receive_object_cost_base = Some(100);
2760 }
2761
2762 if chain != Chain::Mainnet {
2763 cfg.feature_flags.consensus_fast_commit_sync = true;
2765 }
2766 }
2767 23 => {
2768 cfg.feature_flags.move_native_tx_context = true;
2770 cfg.tx_context_fresh_id_cost_base = Some(52);
2771 cfg.tx_context_sender_cost_base = Some(30);
2772 cfg.tx_context_digest_cost_base = Some(30);
2773 cfg.tx_context_epoch_cost_base = Some(30);
2774 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
2775 cfg.tx_context_sponsor_cost_base = Some(30);
2776 cfg.tx_context_rgp_cost_base = Some(30);
2777 cfg.tx_context_gas_price_cost_base = Some(30);
2778 cfg.tx_context_gas_budget_cost_base = Some(30);
2779 cfg.tx_context_ids_created_cost_base = Some(30);
2780 cfg.tx_context_replace_cost_base = Some(30);
2781 }
2782 24 => {
2783 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2785
2786 if chain != Chain::Testnet && chain != Chain::Mainnet {
2787 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2789 }
2790
2791 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
2794 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
2795
2796 cfg.feature_flags.additional_borrow_checks = true;
2798 }
2799 #[allow(deprecated)]
2800 25 => {
2801 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
2804 cfg.check_zklogin_id_cost_base = None;
2805 cfg.check_zklogin_issuer_cost_base = None;
2806 cfg.max_jwk_votes_per_validator_per_epoch = None;
2807 cfg.max_age_of_jwk_in_epochs = None;
2808 }
2809 26 => {
2810 }
2813 27 => {
2814 if chain != Chain::Mainnet {
2815 cfg.feature_flags.consensus_block_restrictions = true;
2818 }
2819
2820 if chain != Chain::Testnet && chain != Chain::Mainnet {
2821 cfg.feature_flags
2823 .pre_consensus_sponsor_only_move_authentication = true;
2824 }
2825 }
2826 28 => {
2827 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
2832 }
2833 _ => panic!("unsupported version {version:?}"),
2844 }
2845 }
2846 cfg
2847 }
2848
2849 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
2855 let (
2856 max_back_edges_per_function,
2857 max_back_edges_per_module,
2858 sanity_check_with_regex_reference_safety,
2859 ) = if let Some((
2860 max_back_edges_per_function,
2861 max_back_edges_per_module,
2862 sanity_check_with_regex_reference_safety,
2863 )) = signing_limits
2864 {
2865 (
2866 Some(max_back_edges_per_function),
2867 Some(max_back_edges_per_module),
2868 Some(sanity_check_with_regex_reference_safety),
2869 )
2870 } else {
2871 (None, None, None)
2872 };
2873
2874 let additional_borrow_checks = if signing_limits.is_some() {
2875 true
2878 } else {
2879 self.additional_borrow_checks()
2880 };
2881
2882 VerifierConfig {
2883 max_loop_depth: Some(self.max_loop_depth() as usize),
2884 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2885 max_function_parameters: Some(self.max_function_parameters() as usize),
2886 max_basic_blocks: Some(self.max_basic_blocks() as usize),
2887 max_value_stack_size: self.max_value_stack_size() as usize,
2888 max_type_nodes: Some(self.max_type_nodes() as usize),
2889 max_push_size: Some(self.max_push_size() as usize),
2890 max_dependency_depth: Some(self.max_dependency_depth() as usize),
2891 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2892 max_function_definitions: Some(self.max_function_definitions() as usize),
2893 max_data_definitions: Some(self.max_struct_definitions() as usize),
2894 max_constant_vector_len: Some(self.max_move_vector_len()),
2895 max_back_edges_per_function,
2896 max_back_edges_per_module,
2897 max_basic_blocks_in_script: None,
2898 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
2902 max_variants_in_enum: self.max_move_enum_variants_as_option(),
2903 additional_borrow_checks,
2904 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
2905 .map(|limit| limit as u128),
2906 }
2907 }
2908
2909 pub fn apply_overrides_for_testing(
2914 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
2915 ) -> OverrideGuard {
2916 CONFIG_OVERRIDE.with(|ovr| {
2917 let mut cur = ovr.borrow_mut();
2918 assert!(cur.is_none(), "config override already present");
2919 *cur = Some(Box::new(override_fn));
2920 OverrideGuard
2921 })
2922 }
2923}
2924
2925impl ProtocolConfig {
2930 pub fn set_per_object_congestion_control_mode_for_testing(
2931 &mut self,
2932 val: PerObjectCongestionControlMode,
2933 ) {
2934 self.feature_flags.per_object_congestion_control_mode = val;
2935 }
2936
2937 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
2938 self.feature_flags.consensus_choice = val;
2939 }
2940
2941 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
2942 self.feature_flags.consensus_network = val;
2943 }
2944
2945 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
2946 self.feature_flags.passkey_auth = val
2947 }
2948
2949 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
2950 self.feature_flags
2951 .disallow_new_modules_in_deps_only_packages = val;
2952 }
2953
2954 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
2955 self.feature_flags.consensus_round_prober = val;
2956 }
2957
2958 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
2959 self.feature_flags
2960 .consensus_distributed_vote_scoring_strategy = val;
2961 }
2962
2963 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
2964 self.consensus_gc_depth = Some(val);
2965 }
2966
2967 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
2968 self.feature_flags.consensus_linearize_subdag_v2 = val;
2969 }
2970
2971 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
2972 self.feature_flags
2973 .consensus_round_prober_probe_accepted_rounds = val;
2974 }
2975
2976 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
2977 self.feature_flags.accept_passkey_in_multisig = val;
2978 }
2979
2980 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
2981 self.feature_flags.consensus_smart_ancestor_selection = val;
2982 }
2983
2984 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
2985 self.feature_flags.consensus_batched_block_sync = val;
2986 }
2987
2988 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
2989 self.feature_flags
2990 .congestion_control_min_free_execution_slot = val;
2991 }
2992
2993 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
2994 self.feature_flags
2995 .congestion_control_gas_price_feedback_mechanism = val;
2996 }
2997
2998 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
2999 self.feature_flags.select_committee_from_eligible_validators = val;
3000 }
3001
3002 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
3003 self.feature_flags.track_non_committee_eligible_validators = val;
3004 }
3005
3006 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
3007 self.feature_flags
3008 .select_committee_supporting_next_epoch_version = val;
3009 }
3010
3011 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
3012 &mut self,
3013 val: bool,
3014 ) {
3015 self.feature_flags
3016 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3017 }
3018
3019 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3020 &mut self,
3021 val: bool,
3022 ) {
3023 self.feature_flags
3024 .consensus_commit_transactions_only_for_traversed_headers = val;
3025 }
3026
3027 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3028 &mut self,
3029 val: bool,
3030 ) {
3031 self.feature_flags
3032 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3033 }
3034
3035 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3036 &mut self,
3037 val: bool,
3038 ) {
3039 self.feature_flags
3040 .separate_gas_price_feedback_mechanism_for_randomness = val;
3041 }
3042
3043 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3044 self.feature_flags.metadata_in_module_bytes = val;
3045 }
3046
3047 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3048 self.feature_flags.publish_package_metadata = val;
3049 }
3050
3051 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3052 self.feature_flags.enable_move_authentication = val;
3053 }
3054
3055 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3056 self.feature_flags.enable_move_authentication_for_sponsor = val;
3057 }
3058
3059 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3060 self.feature_flags.consensus_fast_commit_sync = val;
3061 }
3062
3063 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3064 self.feature_flags.consensus_block_restrictions = val;
3065 }
3066
3067 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3068 self.feature_flags
3069 .pre_consensus_sponsor_only_move_authentication = val;
3070 }
3071}
3072
3073type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
3074
3075thread_local! {
3076 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
3077}
3078
3079#[must_use]
3080pub struct OverrideGuard;
3081
3082impl Drop for OverrideGuard {
3083 fn drop(&mut self) {
3084 info!("restoring override fn");
3085 CONFIG_OVERRIDE.with(|ovr| {
3086 *ovr.borrow_mut() = None;
3087 });
3088 }
3089}
3090
3091#[derive(PartialEq, Eq)]
3095pub enum LimitThresholdCrossed {
3096 None,
3097 Soft(u128, u128),
3098 Hard(u128, u128),
3099}
3100
3101pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
3104 x: T,
3105 soft_limit: U,
3106 hard_limit: V,
3107) -> LimitThresholdCrossed {
3108 let x: V = x.into();
3109 let soft_limit: V = soft_limit.into();
3110
3111 debug_assert!(soft_limit <= hard_limit);
3112
3113 if x >= hard_limit {
3116 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
3117 } else if x < soft_limit {
3118 LimitThresholdCrossed::None
3119 } else {
3120 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
3121 }
3122}
3123
3124#[macro_export]
3125macro_rules! check_limit {
3126 ($x:expr, $hard:expr) => {
3127 check_limit!($x, $hard, $hard)
3128 };
3129 ($x:expr, $soft:expr, $hard:expr) => {
3130 check_limit_in_range($x as u64, $soft, $hard)
3131 };
3132}
3133
3134#[macro_export]
3138macro_rules! check_limit_by_meter {
3139 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
3140 let (h, metered_str) = if $is_metered {
3142 ($metered_limit, "metered")
3143 } else {
3144 ($unmetered_hard_limit, "unmetered")
3146 };
3147 use iota_protocol_config::check_limit_in_range;
3148 let result = check_limit_in_range($x as u64, $metered_limit, h);
3149 match result {
3150 LimitThresholdCrossed::None => {}
3151 LimitThresholdCrossed::Soft(_, _) => {
3152 $metric.with_label_values(&[metered_str, "soft"]).inc();
3153 }
3154 LimitThresholdCrossed::Hard(_, _) => {
3155 $metric.with_label_values(&[metered_str, "hard"]).inc();
3156 }
3157 };
3158 result
3159 }};
3160}
3161
3162#[cfg(all(test, not(msim)))]
3163mod test {
3164 use insta::assert_yaml_snapshot;
3165
3166 use super::*;
3167
3168 #[test]
3169 fn snapshot_tests() {
3170 println!("\n============================================================================");
3171 println!("! !");
3172 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
3173 println!("! !");
3174 println!("============================================================================\n");
3175 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
3176 let chain_str = match chain_id {
3181 Chain::Unknown => "".to_string(),
3182 _ => format!("{chain_id:?}_"),
3183 };
3184 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
3185 let cur = ProtocolVersion::new(i);
3186 assert_yaml_snapshot!(
3187 format!("{}version_{}", chain_str, cur.as_u64()),
3188 ProtocolConfig::get_for_version(cur, *chain_id)
3189 );
3190 }
3191 }
3192 }
3193
3194 #[test]
3195 fn test_getters() {
3196 let prot: ProtocolConfig =
3197 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3198 assert_eq!(
3199 prot.max_arguments(),
3200 prot.max_arguments_as_option().unwrap()
3201 );
3202 }
3203
3204 #[test]
3205 fn test_setters() {
3206 let mut prot: ProtocolConfig =
3207 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3208 prot.set_max_arguments_for_testing(123);
3209 assert_eq!(prot.max_arguments(), 123);
3210
3211 prot.set_max_arguments_from_str_for_testing("321".to_string());
3212 assert_eq!(prot.max_arguments(), 321);
3213
3214 prot.disable_max_arguments_for_testing();
3215 assert_eq!(prot.max_arguments_as_option(), None);
3216
3217 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
3218 assert_eq!(prot.max_arguments(), 456);
3219 }
3220
3221 #[test]
3222 #[should_panic(expected = "unsupported version")]
3223 fn max_version_test() {
3224 let _ = ProtocolConfig::get_for_version_impl(
3227 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
3228 Chain::Unknown,
3229 );
3230 }
3231
3232 #[test]
3233 fn lookup_by_string_test() {
3234 let prot: ProtocolConfig =
3235 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3236 assert!(prot.lookup_attr("some random string".to_string()).is_none());
3238
3239 assert!(
3240 prot.lookup_attr("max_arguments".to_string())
3241 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
3242 );
3243
3244 assert!(
3246 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3247 .is_none()
3248 );
3249 assert!(
3250 prot.attr_map()
3251 .get("poseidon_bn254_cost_base")
3252 .unwrap()
3253 .is_none()
3254 );
3255
3256 let prot: ProtocolConfig =
3258 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3259
3260 assert!(
3261 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3262 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3263 );
3264 assert!(
3265 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
3266 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3267 );
3268
3269 let prot: ProtocolConfig =
3271 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3272 assert!(
3274 prot.feature_flags
3275 .lookup_attr("some random string".to_owned())
3276 .is_none()
3277 );
3278 assert!(
3279 !prot
3280 .feature_flags
3281 .attr_map()
3282 .contains_key("some random string")
3283 );
3284
3285 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
3287 assert!(
3288 prot.feature_flags
3289 .attr_map()
3290 .get("enable_poseidon")
3291 .unwrap()
3292 == &false
3293 );
3294 let prot: ProtocolConfig =
3295 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3296 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
3298 assert!(
3299 prot.feature_flags
3300 .attr_map()
3301 .get("enable_poseidon")
3302 .unwrap()
3303 == &true
3304 );
3305 }
3306
3307 #[test]
3308 fn limit_range_fn_test() {
3309 let low = 100u32;
3310 let high = 10000u64;
3311
3312 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
3313 assert!(matches!(
3314 check_limit!(255u16, low, high),
3315 LimitThresholdCrossed::Soft(255u128, 100)
3316 ));
3317 assert!(matches!(
3324 check_limit!(2550000u64, low, high),
3325 LimitThresholdCrossed::Hard(2550000, 10000)
3326 ));
3327
3328 assert!(matches!(
3329 check_limit!(2550000u64, high, high),
3330 LimitThresholdCrossed::Hard(2550000, 10000)
3331 ));
3332
3333 assert!(matches!(
3334 check_limit!(1u8, high),
3335 LimitThresholdCrossed::None
3336 ));
3337
3338 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
3339
3340 assert!(matches!(
3341 check_limit!(2550000u64, high),
3342 LimitThresholdCrossed::Hard(2550000, 10000)
3343 ));
3344 }
3345}