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)]
149pub struct ProtocolVersion(u64);
150
151impl ProtocolVersion {
152 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
158
159 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
160
161 #[cfg(not(msim))]
162 const MAX_ALLOWED: Self = Self::MAX;
163
164 #[cfg(msim)]
167 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
168
169 pub fn new(v: u64) -> Self {
170 Self(v)
171 }
172
173 pub const fn as_u64(&self) -> u64 {
174 self.0
175 }
176
177 pub fn max() -> Self {
180 Self::MAX
181 }
182}
183
184impl From<u64> for ProtocolVersion {
185 fn from(v: u64) -> Self {
186 Self::new(v)
187 }
188}
189
190impl std::ops::Sub<u64> for ProtocolVersion {
191 type Output = Self;
192 fn sub(self, rhs: u64) -> Self::Output {
193 Self::new(self.0 - rhs)
194 }
195}
196
197impl std::ops::Add<u64> for ProtocolVersion {
198 type Output = Self;
199 fn add(self, rhs: u64) -> Self::Output {
200 Self::new(self.0 + rhs)
201 }
202}
203
204#[derive(
205 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
206)]
207pub enum Chain {
208 Mainnet,
209 Testnet,
210 #[default]
211 Unknown,
212}
213
214impl Chain {
215 pub fn as_str(self) -> &'static str {
216 match self {
217 Chain::Mainnet => "mainnet",
218 Chain::Testnet => "testnet",
219 Chain::Unknown => "unknown",
220 }
221 }
222}
223
224pub struct Error(pub String);
225
226#[derive(Default, Clone, Serialize, Deserialize, Debug, ProtocolConfigFeatureFlagsGetters)]
230struct FeatureFlags {
231 #[serde(skip_serializing_if = "is_true")]
237 disable_invariant_violation_check_in_swap_loc: bool,
238
239 #[serde(skip_serializing_if = "is_true")]
242 no_extraneous_module_bytes: bool,
243
244 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
246 consensus_transaction_ordering: ConsensusTransactionOrdering,
247
248 #[serde(skip_serializing_if = "is_true")]
251 hardened_otw_check: bool,
252
253 #[serde(skip_serializing_if = "is_false")]
255 enable_poseidon: bool,
256
257 #[serde(skip_serializing_if = "is_false")]
259 enable_group_ops_native_function_msm: bool,
260
261 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
263 per_object_congestion_control_mode: PerObjectCongestionControlMode,
264
265 #[serde(
267 default = "ConsensusChoice::mysticeti_deprecated",
268 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
269 )]
270 consensus_choice: ConsensusChoice,
271
272 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
274 consensus_network: ConsensusNetwork,
275
276 #[deprecated]
278 #[serde(skip_serializing_if = "Option::is_none")]
279 zklogin_max_epoch_upper_bound_delta: Option<u64>,
280
281 #[serde(skip_serializing_if = "is_false")]
283 enable_vdf: bool,
284
285 #[serde(skip_serializing_if = "is_false")]
287 passkey_auth: bool,
288
289 #[serde(skip_serializing_if = "is_true")]
292 rethrow_serialization_type_layout_errors: bool,
293
294 #[serde(skip_serializing_if = "is_false")]
296 relocate_event_module: bool,
297
298 #[serde(skip_serializing_if = "is_false")]
300 protocol_defined_base_fee: bool,
301
302 #[serde(skip_serializing_if = "is_false")]
304 uncompressed_g1_group_elements: bool,
305
306 #[serde(skip_serializing_if = "is_false")]
308 disallow_new_modules_in_deps_only_packages: bool,
309
310 #[serde(skip_serializing_if = "is_false")]
312 native_charging_v2: bool,
313
314 #[serde(skip_serializing_if = "is_false")]
316 convert_type_argument_error: bool,
317
318 #[serde(skip_serializing_if = "is_false")]
320 consensus_round_prober: bool,
321
322 #[serde(skip_serializing_if = "is_false")]
324 consensus_distributed_vote_scoring_strategy: bool,
325
326 #[serde(skip_serializing_if = "is_false")]
330 consensus_linearize_subdag_v2: bool,
331
332 #[serde(skip_serializing_if = "is_false")]
334 variant_nodes: bool,
335
336 #[serde(skip_serializing_if = "is_false")]
338 consensus_smart_ancestor_selection: bool,
339
340 #[serde(skip_serializing_if = "is_false")]
342 consensus_round_prober_probe_accepted_rounds: bool,
343
344 #[serde(skip_serializing_if = "is_false")]
346 consensus_zstd_compression: bool,
347
348 #[serde(skip_serializing_if = "is_false")]
351 congestion_control_min_free_execution_slot: bool,
352
353 #[serde(skip_serializing_if = "is_false")]
355 accept_passkey_in_multisig: bool,
356
357 #[serde(skip_serializing_if = "is_false")]
359 consensus_batched_block_sync: bool,
360
361 #[serde(skip_serializing_if = "is_false")]
364 congestion_control_gas_price_feedback_mechanism: bool,
365
366 #[serde(skip_serializing_if = "is_false")]
368 validate_identifier_inputs: bool,
369
370 #[serde(skip_serializing_if = "is_false")]
373 minimize_child_object_mutations: bool,
374
375 #[serde(skip_serializing_if = "is_false")]
377 dependency_linkage_error: bool,
378
379 #[serde(skip_serializing_if = "is_false")]
381 additional_multisig_checks: bool,
382
383 #[serde(skip_serializing_if = "is_false")]
386 normalize_ptb_arguments: bool,
387
388 #[serde(skip_serializing_if = "is_false")]
392 select_committee_from_eligible_validators: bool,
393
394 #[serde(skip_serializing_if = "is_false")]
401 track_non_committee_eligible_validators: bool,
402
403 #[serde(skip_serializing_if = "is_false")]
409 select_committee_supporting_next_epoch_version: bool,
410
411 #[serde(skip_serializing_if = "is_false")]
415 consensus_median_timestamp_with_checkpoint_enforcement: bool,
416
417 #[serde(skip_serializing_if = "is_false")]
419 consensus_commit_transactions_only_for_traversed_headers: bool,
420
421 #[serde(skip_serializing_if = "is_false")]
423 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
424
425 #[serde(skip_serializing_if = "is_false")]
428 separate_gas_price_feedback_mechanism_for_randomness: bool,
429
430 #[serde(skip_serializing_if = "is_false")]
433 metadata_in_module_bytes: bool,
434
435 #[serde(skip_serializing_if = "is_false")]
437 publish_package_metadata: bool,
438
439 #[serde(skip_serializing_if = "is_false")]
441 enable_move_authentication: bool,
442
443 #[serde(skip_serializing_if = "is_false")]
445 enable_move_authentication_for_sponsor: bool,
446
447 #[serde(skip_serializing_if = "is_false")]
449 pass_validator_scores_to_advance_epoch: bool,
450
451 #[serde(skip_serializing_if = "is_false")]
453 calculate_validator_scores: bool,
454
455 #[serde(skip_serializing_if = "is_false")]
457 adjust_rewards_by_score: bool,
458
459 #[serde(skip_serializing_if = "is_false")]
462 pass_calculated_validator_scores_to_advance_epoch: bool,
463
464 #[serde(skip_serializing_if = "is_false")]
469 consensus_fast_commit_sync: bool,
470
471 #[serde(skip_serializing_if = "is_false")]
474 consensus_block_restrictions: bool,
475
476 #[serde(skip_serializing_if = "is_false")]
478 move_native_tx_context: bool,
479
480 #[serde(skip_serializing_if = "is_false")]
482 additional_borrow_checks: bool,
483
484 #[serde(skip_serializing_if = "is_false")]
486 pre_consensus_sponsor_only_move_authentication: bool,
487}
488
489fn is_true(b: &bool) -> bool {
490 *b
491}
492
493fn is_false(b: &bool) -> bool {
494 !b
495}
496
497#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
499pub enum ConsensusTransactionOrdering {
500 #[default]
503 None,
504 ByGasPrice,
506}
507
508impl ConsensusTransactionOrdering {
509 pub fn is_none(&self) -> bool {
510 matches!(self, ConsensusTransactionOrdering::None)
511 }
512}
513
514#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
516pub enum PerObjectCongestionControlMode {
517 #[default]
518 None, TotalGasBudget, TotalTxCount, }
522
523impl PerObjectCongestionControlMode {
524 pub fn is_none(&self) -> bool {
525 matches!(self, PerObjectCongestionControlMode::None)
526 }
527}
528
529#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
531pub enum ConsensusChoice {
532 #[deprecated(note = "Mysticeti was replaced by Starfish")]
535 MysticetiDeprecated,
536 #[default]
537 Starfish,
538}
539
540#[expect(deprecated)]
541impl ConsensusChoice {
542 fn mysticeti_deprecated() -> Self {
549 ConsensusChoice::MysticetiDeprecated
550 }
551
552 pub fn is_mysticeti_deprecated(&self) -> bool {
553 matches!(self, ConsensusChoice::MysticetiDeprecated)
554 }
555 pub fn is_starfish(&self) -> bool {
556 matches!(self, ConsensusChoice::Starfish)
557 }
558}
559
560#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
562pub enum ConsensusNetwork {
563 #[default]
564 Tonic,
565}
566
567impl ConsensusNetwork {
568 pub fn is_tonic(&self) -> bool {
569 matches!(self, ConsensusNetwork::Tonic)
570 }
571}
572
573#[skip_serializing_none]
607#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
608pub struct ProtocolConfig {
609 pub version: ProtocolVersion,
610
611 feature_flags: FeatureFlags,
612
613 max_tx_size_bytes: Option<u64>,
618
619 max_input_objects: Option<u64>,
622
623 max_size_written_objects: Option<u64>,
628 max_size_written_objects_system_tx: Option<u64>,
632
633 max_serialized_tx_effects_size_bytes: Option<u64>,
635
636 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
638
639 max_gas_payment_objects: Option<u32>,
641
642 max_modules_in_publish: Option<u32>,
644
645 max_package_dependencies: Option<u32>,
647
648 max_arguments: Option<u32>,
651
652 max_type_arguments: Option<u32>,
654
655 max_type_argument_depth: Option<u32>,
657
658 max_pure_argument_size: Option<u32>,
660
661 max_programmable_tx_commands: Option<u32>,
663
664 move_binary_format_version: Option<u32>,
670 min_move_binary_format_version: Option<u32>,
671
672 binary_module_handles: Option<u16>,
674 binary_struct_handles: Option<u16>,
675 binary_function_handles: Option<u16>,
676 binary_function_instantiations: Option<u16>,
677 binary_signatures: Option<u16>,
678 binary_constant_pool: Option<u16>,
679 binary_identifiers: Option<u16>,
680 binary_address_identifiers: Option<u16>,
681 binary_struct_defs: Option<u16>,
682 binary_struct_def_instantiations: Option<u16>,
683 binary_function_defs: Option<u16>,
684 binary_field_handles: Option<u16>,
685 binary_field_instantiations: Option<u16>,
686 binary_friend_decls: Option<u16>,
687 binary_enum_defs: Option<u16>,
688 binary_enum_def_instantiations: Option<u16>,
689 binary_variant_handles: Option<u16>,
690 binary_variant_instantiation_handles: Option<u16>,
691
692 max_move_object_size: Option<u64>,
695
696 max_move_package_size: Option<u64>,
701
702 max_publish_or_upgrade_per_ptb: Option<u64>,
705
706 max_tx_gas: Option<u64>,
708
709 max_auth_gas: Option<u64>,
711
712 max_gas_price: Option<u64>,
715
716 max_gas_computation_bucket: Option<u64>,
719
720 gas_rounding_step: Option<u64>,
722
723 max_loop_depth: Option<u64>,
725
726 max_generic_instantiation_length: Option<u64>,
729
730 max_function_parameters: Option<u64>,
733
734 max_basic_blocks: Option<u64>,
737
738 max_value_stack_size: Option<u64>,
740
741 max_type_nodes: Option<u64>,
745
746 max_push_size: Option<u64>,
749
750 max_struct_definitions: Option<u64>,
753
754 max_function_definitions: Option<u64>,
757
758 max_fields_in_struct: Option<u64>,
761
762 max_dependency_depth: Option<u64>,
765
766 max_num_event_emit: Option<u64>,
769
770 max_num_new_move_object_ids: Option<u64>,
773
774 max_num_new_move_object_ids_system_tx: Option<u64>,
777
778 max_num_deleted_move_object_ids: Option<u64>,
781
782 max_num_deleted_move_object_ids_system_tx: Option<u64>,
785
786 max_num_transferred_move_object_ids: Option<u64>,
789
790 max_num_transferred_move_object_ids_system_tx: Option<u64>,
793
794 max_event_emit_size: Option<u64>,
796
797 max_event_emit_size_total: Option<u64>,
799
800 max_move_vector_len: Option<u64>,
803
804 max_move_identifier_len: Option<u64>,
807
808 max_move_value_depth: Option<u64>,
810
811 max_move_enum_variants: Option<u64>,
814
815 max_back_edges_per_function: Option<u64>,
818
819 max_back_edges_per_module: Option<u64>,
822
823 max_verifier_meter_ticks_per_function: Option<u64>,
826
827 max_meter_ticks_per_module: Option<u64>,
830
831 max_meter_ticks_per_package: Option<u64>,
834
835 object_runtime_max_num_cached_objects: Option<u64>,
842
843 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
846
847 object_runtime_max_num_store_entries: Option<u64>,
850
851 object_runtime_max_num_store_entries_system_tx: Option<u64>,
854
855 base_tx_cost_fixed: Option<u64>,
860
861 package_publish_cost_fixed: Option<u64>,
865
866 base_tx_cost_per_byte: Option<u64>,
870
871 package_publish_cost_per_byte: Option<u64>,
873
874 obj_access_cost_read_per_byte: Option<u64>,
876
877 obj_access_cost_mutate_per_byte: Option<u64>,
879
880 obj_access_cost_delete_per_byte: Option<u64>,
882
883 obj_access_cost_verify_per_byte: Option<u64>,
893
894 max_type_to_layout_nodes: Option<u64>,
896
897 max_ptb_value_size: Option<u64>,
899
900 gas_model_version: Option<u64>,
905
906 obj_data_cost_refundable: Option<u64>,
912
913 obj_metadata_cost_non_refundable: Option<u64>,
917
918 storage_rebate_rate: Option<u64>,
924
925 reward_slashing_rate: Option<u64>,
928
929 storage_gas_price: Option<u64>,
931
932 base_gas_price: Option<u64>,
934
935 validator_target_reward: Option<u64>,
937
938 max_transactions_per_checkpoint: Option<u64>,
945
946 max_checkpoint_size_bytes: Option<u64>,
950
951 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
957
958 address_from_bytes_cost_base: Option<u64>,
963 address_to_u256_cost_base: Option<u64>,
965 address_from_u256_cost_base: Option<u64>,
967
968 config_read_setting_impl_cost_base: Option<u64>,
973 config_read_setting_impl_cost_per_byte: Option<u64>,
974
975 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
979 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
980 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
981 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
982 dynamic_field_add_child_object_cost_base: Option<u64>,
985 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
986 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
987 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
988 dynamic_field_borrow_child_object_cost_base: Option<u64>,
991 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
992 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
993 dynamic_field_remove_child_object_cost_base: Option<u64>,
996 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
997 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
998 dynamic_field_has_child_object_cost_base: Option<u64>,
1001 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1004 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1005 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1006
1007 event_emit_cost_base: Option<u64>,
1010 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1011 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1012 event_emit_output_cost_per_byte: Option<u64>,
1013
1014 object_borrow_uid_cost_base: Option<u64>,
1017 object_delete_impl_cost_base: Option<u64>,
1019 object_record_new_uid_cost_base: Option<u64>,
1021
1022 transfer_transfer_internal_cost_base: Option<u64>,
1025 transfer_freeze_object_cost_base: Option<u64>,
1027 transfer_share_object_cost_base: Option<u64>,
1029 transfer_receive_object_cost_base: Option<u64>,
1032
1033 tx_context_derive_id_cost_base: Option<u64>,
1036 tx_context_fresh_id_cost_base: Option<u64>,
1037 tx_context_sender_cost_base: Option<u64>,
1038 tx_context_digest_cost_base: Option<u64>,
1039 tx_context_epoch_cost_base: Option<u64>,
1040 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1041 tx_context_sponsor_cost_base: Option<u64>,
1042 tx_context_rgp_cost_base: Option<u64>,
1043 tx_context_gas_price_cost_base: Option<u64>,
1044 tx_context_gas_budget_cost_base: Option<u64>,
1045 tx_context_ids_created_cost_base: Option<u64>,
1046 tx_context_replace_cost_base: Option<u64>,
1047
1048 types_is_one_time_witness_cost_base: Option<u64>,
1051 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1052 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1053
1054 validator_validate_metadata_cost_base: Option<u64>,
1057 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1058
1059 crypto_invalid_arguments_cost: Option<u64>,
1061 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1063 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1064 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1065
1066 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1068 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1069 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1070
1071 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1073 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1074 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1075 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1076 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1077 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1078
1079 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1081
1082 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1084 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1085 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1086 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1087 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1088 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1089
1090 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1092 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1093 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1094 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1095 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1096 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1097
1098 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1100 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1101 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1102 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1103 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1104 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1105
1106 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1108 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1109 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1110
1111 ed25519_ed25519_verify_cost_base: Option<u64>,
1113 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1114 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1115
1116 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1118 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1119
1120 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1122 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1123 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1124 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1125 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1126
1127 hash_blake2b256_cost_base: Option<u64>,
1129 hash_blake2b256_data_cost_per_byte: Option<u64>,
1130 hash_blake2b256_data_cost_per_block: Option<u64>,
1131
1132 hash_keccak256_cost_base: Option<u64>,
1134 hash_keccak256_data_cost_per_byte: Option<u64>,
1135 hash_keccak256_data_cost_per_block: Option<u64>,
1136
1137 poseidon_bn254_cost_base: Option<u64>,
1139 poseidon_bn254_cost_per_block: Option<u64>,
1140
1141 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1143 group_ops_bls12381_decode_g1_cost: Option<u64>,
1144 group_ops_bls12381_decode_g2_cost: Option<u64>,
1145 group_ops_bls12381_decode_gt_cost: Option<u64>,
1146 group_ops_bls12381_scalar_add_cost: Option<u64>,
1147 group_ops_bls12381_g1_add_cost: Option<u64>,
1148 group_ops_bls12381_g2_add_cost: Option<u64>,
1149 group_ops_bls12381_gt_add_cost: Option<u64>,
1150 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1151 group_ops_bls12381_g1_sub_cost: Option<u64>,
1152 group_ops_bls12381_g2_sub_cost: Option<u64>,
1153 group_ops_bls12381_gt_sub_cost: Option<u64>,
1154 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1155 group_ops_bls12381_g1_mul_cost: Option<u64>,
1156 group_ops_bls12381_g2_mul_cost: Option<u64>,
1157 group_ops_bls12381_gt_mul_cost: Option<u64>,
1158 group_ops_bls12381_scalar_div_cost: Option<u64>,
1159 group_ops_bls12381_g1_div_cost: Option<u64>,
1160 group_ops_bls12381_g2_div_cost: Option<u64>,
1161 group_ops_bls12381_gt_div_cost: Option<u64>,
1162 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1163 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1164 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1165 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1166 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1167 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1168 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1169 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1170 group_ops_bls12381_msm_max_len: Option<u32>,
1171 group_ops_bls12381_pairing_cost: Option<u64>,
1172 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1173 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1174 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1175 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1176 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1177
1178 hmac_hmac_sha3_256_cost_base: Option<u64>,
1180 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1181 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1182
1183 #[deprecated]
1185 check_zklogin_id_cost_base: Option<u64>,
1186 #[deprecated]
1188 check_zklogin_issuer_cost_base: Option<u64>,
1189
1190 vdf_verify_vdf_cost: Option<u64>,
1191 vdf_hash_to_input_cost: Option<u64>,
1192
1193 bcs_per_byte_serialized_cost: Option<u64>,
1195 bcs_legacy_min_output_size_cost: Option<u64>,
1196 bcs_failure_cost: Option<u64>,
1197
1198 hash_sha2_256_base_cost: Option<u64>,
1199 hash_sha2_256_per_byte_cost: Option<u64>,
1200 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1201 hash_sha3_256_base_cost: Option<u64>,
1202 hash_sha3_256_per_byte_cost: Option<u64>,
1203 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1204 type_name_get_base_cost: Option<u64>,
1205 type_name_get_per_byte_cost: Option<u64>,
1206
1207 string_check_utf8_base_cost: Option<u64>,
1208 string_check_utf8_per_byte_cost: Option<u64>,
1209 string_is_char_boundary_base_cost: Option<u64>,
1210 string_sub_string_base_cost: Option<u64>,
1211 string_sub_string_per_byte_cost: Option<u64>,
1212 string_index_of_base_cost: Option<u64>,
1213 string_index_of_per_byte_pattern_cost: Option<u64>,
1214 string_index_of_per_byte_searched_cost: Option<u64>,
1215
1216 vector_empty_base_cost: Option<u64>,
1217 vector_length_base_cost: Option<u64>,
1218 vector_push_back_base_cost: Option<u64>,
1219 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1220 vector_borrow_base_cost: Option<u64>,
1221 vector_pop_back_base_cost: Option<u64>,
1222 vector_destroy_empty_base_cost: Option<u64>,
1223 vector_swap_base_cost: Option<u64>,
1224 debug_print_base_cost: Option<u64>,
1225 debug_print_stack_trace_base_cost: Option<u64>,
1226
1227 execution_version: Option<u64>,
1229
1230 consensus_bad_nodes_stake_threshold: Option<u64>,
1234
1235 #[deprecated]
1236 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1237 #[deprecated]
1241 max_age_of_jwk_in_epochs: Option<u64>,
1242
1243 random_beacon_reduction_allowed_delta: Option<u16>,
1247
1248 random_beacon_reduction_lower_bound: Option<u32>,
1251
1252 random_beacon_dkg_timeout_round: Option<u32>,
1255
1256 random_beacon_min_round_interval_ms: Option<u64>,
1258
1259 random_beacon_dkg_version: Option<u64>,
1263
1264 consensus_max_transaction_size_bytes: Option<u64>,
1269 consensus_max_transactions_in_block_bytes: Option<u64>,
1271 consensus_max_num_transactions_in_block: Option<u64>,
1273
1274 max_deferral_rounds_for_congestion_control: Option<u64>,
1278
1279 min_checkpoint_interval_ms: Option<u64>,
1281
1282 checkpoint_summary_version_specific_data: Option<u64>,
1284
1285 max_soft_bundle_size: Option<u64>,
1288
1289 bridge_should_try_to_finalize_committee: Option<bool>,
1294
1295 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1301
1302 max_committee_members_count: Option<u64>,
1306
1307 consensus_gc_depth: Option<u32>,
1310
1311 consensus_max_acknowledgments_per_block: Option<u32>,
1317
1318 max_congestion_limit_overshoot_per_commit: Option<u64>,
1323
1324 scorer_version: Option<u16>,
1333
1334 auth_context_digest_cost_base: Option<u64>,
1337 auth_context_tx_data_bytes_cost_base: Option<u64>,
1339 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1340 auth_context_tx_commands_cost_base: Option<u64>,
1342 auth_context_tx_commands_cost_per_byte: Option<u64>,
1343 auth_context_tx_inputs_cost_base: Option<u64>,
1345 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1346 auth_context_replace_cost_base: Option<u64>,
1349 auth_context_replace_cost_per_byte: Option<u64>,
1350}
1351
1352impl ProtocolConfig {
1354 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1367 self.feature_flags
1368 .disable_invariant_violation_check_in_swap_loc
1369 }
1370
1371 pub fn no_extraneous_module_bytes(&self) -> bool {
1372 self.feature_flags.no_extraneous_module_bytes
1373 }
1374
1375 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1376 self.feature_flags.consensus_transaction_ordering
1377 }
1378
1379 pub fn dkg_version(&self) -> u64 {
1380 self.random_beacon_dkg_version.unwrap_or(1)
1382 }
1383
1384 pub fn hardened_otw_check(&self) -> bool {
1385 self.feature_flags.hardened_otw_check
1386 }
1387
1388 pub fn enable_poseidon(&self) -> bool {
1389 self.feature_flags.enable_poseidon
1390 }
1391
1392 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1393 self.feature_flags.enable_group_ops_native_function_msm
1394 }
1395
1396 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1397 self.feature_flags.per_object_congestion_control_mode
1398 }
1399
1400 pub fn consensus_choice(&self) -> ConsensusChoice {
1401 self.feature_flags.consensus_choice
1402 }
1403
1404 pub fn consensus_network(&self) -> ConsensusNetwork {
1405 self.feature_flags.consensus_network
1406 }
1407
1408 pub fn enable_vdf(&self) -> bool {
1409 self.feature_flags.enable_vdf
1410 }
1411
1412 pub fn passkey_auth(&self) -> bool {
1413 self.feature_flags.passkey_auth
1414 }
1415
1416 pub fn max_transaction_size_bytes(&self) -> u64 {
1417 self.consensus_max_transaction_size_bytes
1419 .unwrap_or(256 * 1024)
1420 }
1421
1422 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1423 if cfg!(msim) {
1424 256 * 1024
1425 } else {
1426 self.consensus_max_transactions_in_block_bytes
1427 .unwrap_or(512 * 1024)
1428 }
1429 }
1430
1431 pub fn max_num_transactions_in_block(&self) -> u64 {
1432 if cfg!(msim) {
1433 8
1434 } else {
1435 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1436 }
1437 }
1438
1439 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1440 self.feature_flags.rethrow_serialization_type_layout_errors
1441 }
1442
1443 pub fn relocate_event_module(&self) -> bool {
1444 self.feature_flags.relocate_event_module
1445 }
1446
1447 pub fn protocol_defined_base_fee(&self) -> bool {
1448 self.feature_flags.protocol_defined_base_fee
1449 }
1450
1451 pub fn uncompressed_g1_group_elements(&self) -> bool {
1452 self.feature_flags.uncompressed_g1_group_elements
1453 }
1454
1455 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1456 self.feature_flags
1457 .disallow_new_modules_in_deps_only_packages
1458 }
1459
1460 pub fn native_charging_v2(&self) -> bool {
1461 self.feature_flags.native_charging_v2
1462 }
1463
1464 pub fn consensus_round_prober(&self) -> bool {
1465 self.feature_flags.consensus_round_prober
1466 }
1467
1468 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1469 self.feature_flags
1470 .consensus_distributed_vote_scoring_strategy
1471 }
1472
1473 pub fn gc_depth(&self) -> u32 {
1474 if cfg!(msim) {
1475 min(5, self.consensus_gc_depth.unwrap_or(0))
1477 } else {
1478 self.consensus_gc_depth.unwrap_or(0)
1479 }
1480 }
1481
1482 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1483 let res = self.feature_flags.consensus_linearize_subdag_v2;
1484 assert!(
1485 !res || self.gc_depth() > 0,
1486 "The consensus linearize sub dag V2 requires GC to be enabled"
1487 );
1488 res
1489 }
1490
1491 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1492 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1493 }
1494
1495 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1496 if self.consensus_block_restrictions() {
1497 2 * committee_size
1498 } else {
1499 self.consensus_max_acknowledgments_per_block_or_default() as usize
1500 }
1501 }
1502
1503 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1504 if self.consensus_block_restrictions() {
1505 committee_size
1506 } else {
1507 100
1508 }
1509 }
1510
1511 pub fn variant_nodes(&self) -> bool {
1512 self.feature_flags.variant_nodes
1513 }
1514
1515 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1516 self.feature_flags.consensus_smart_ancestor_selection
1517 }
1518
1519 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1520 self.feature_flags
1521 .consensus_round_prober_probe_accepted_rounds
1522 }
1523
1524 pub fn consensus_zstd_compression(&self) -> bool {
1525 self.feature_flags.consensus_zstd_compression
1526 }
1527
1528 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1529 self.feature_flags
1530 .congestion_control_min_free_execution_slot
1531 }
1532
1533 pub fn accept_passkey_in_multisig(&self) -> bool {
1534 self.feature_flags.accept_passkey_in_multisig
1535 }
1536
1537 pub fn consensus_batched_block_sync(&self) -> bool {
1538 self.feature_flags.consensus_batched_block_sync
1539 }
1540
1541 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1544 self.feature_flags
1545 .congestion_control_gas_price_feedback_mechanism
1546 }
1547
1548 pub fn validate_identifier_inputs(&self) -> bool {
1549 self.feature_flags.validate_identifier_inputs
1550 }
1551
1552 pub fn minimize_child_object_mutations(&self) -> bool {
1553 self.feature_flags.minimize_child_object_mutations
1554 }
1555
1556 pub fn dependency_linkage_error(&self) -> bool {
1557 self.feature_flags.dependency_linkage_error
1558 }
1559
1560 pub fn additional_multisig_checks(&self) -> bool {
1561 self.feature_flags.additional_multisig_checks
1562 }
1563
1564 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1565 0
1568 }
1569
1570 pub fn normalize_ptb_arguments(&self) -> bool {
1571 self.feature_flags.normalize_ptb_arguments
1572 }
1573
1574 pub fn select_committee_from_eligible_validators(&self) -> bool {
1575 let res = self.feature_flags.select_committee_from_eligible_validators;
1576 assert!(
1577 !res || (self.protocol_defined_base_fee()
1578 && self.max_committee_members_count_as_option().is_some()),
1579 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1580 );
1581 res
1582 }
1583
1584 pub fn track_non_committee_eligible_validators(&self) -> bool {
1585 self.feature_flags.track_non_committee_eligible_validators
1586 }
1587
1588 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1589 let res = self
1590 .feature_flags
1591 .select_committee_supporting_next_epoch_version;
1592 assert!(
1593 !res || (self.track_non_committee_eligible_validators()
1594 && self.select_committee_from_eligible_validators()),
1595 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1596 );
1597 res
1598 }
1599
1600 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1601 let res = self
1602 .feature_flags
1603 .consensus_median_timestamp_with_checkpoint_enforcement;
1604 assert!(
1605 !res || self.gc_depth() > 0,
1606 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1607 );
1608 res
1609 }
1610
1611 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1612 self.feature_flags
1613 .consensus_commit_transactions_only_for_traversed_headers
1614 }
1615
1616 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1619 self.feature_flags
1620 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1621 }
1622
1623 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1626 self.feature_flags
1627 .separate_gas_price_feedback_mechanism_for_randomness
1628 }
1629
1630 pub fn metadata_in_module_bytes(&self) -> bool {
1631 self.feature_flags.metadata_in_module_bytes
1632 }
1633
1634 pub fn publish_package_metadata(&self) -> bool {
1635 self.feature_flags.publish_package_metadata
1636 }
1637
1638 pub fn enable_move_authentication(&self) -> bool {
1639 self.feature_flags.enable_move_authentication
1640 }
1641
1642 pub fn additional_borrow_checks(&self) -> bool {
1643 self.feature_flags.additional_borrow_checks
1644 }
1645
1646 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1647 let enable_move_authentication_for_sponsor =
1648 self.feature_flags.enable_move_authentication_for_sponsor;
1649 assert!(
1650 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1651 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1652 );
1653 enable_move_authentication_for_sponsor
1654 }
1655
1656 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1657 self.feature_flags.pass_validator_scores_to_advance_epoch
1658 }
1659
1660 pub fn calculate_validator_scores(&self) -> bool {
1661 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1662 assert!(
1663 !calculate_validator_scores || self.scorer_version.is_some(),
1664 "calculate_validator_scores requires scorer_version to be set"
1665 );
1666 calculate_validator_scores
1667 }
1668
1669 pub fn adjust_rewards_by_score(&self) -> bool {
1670 let adjust = self.feature_flags.adjust_rewards_by_score;
1671 assert!(
1672 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1673 "adjust_rewards_by_score requires scorer_version to be set"
1674 );
1675 adjust
1676 }
1677
1678 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1679 let pass = self
1680 .feature_flags
1681 .pass_calculated_validator_scores_to_advance_epoch;
1682 assert!(
1683 !pass
1684 || (self.pass_validator_scores_to_advance_epoch()
1685 && self.calculate_validator_scores()),
1686 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
1687 );
1688 pass
1689 }
1690 pub fn consensus_fast_commit_sync(&self) -> bool {
1691 let res = self.feature_flags.consensus_fast_commit_sync;
1692 assert!(
1693 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
1694 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
1695 );
1696 res
1697 }
1698
1699 pub fn consensus_block_restrictions(&self) -> bool {
1700 self.feature_flags.consensus_block_restrictions
1701 }
1702
1703 pub fn move_native_tx_context(&self) -> bool {
1704 self.feature_flags.move_native_tx_context
1705 }
1706
1707 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
1708 let pre_consensus_sponsor_only_move_authentication = self
1709 .feature_flags
1710 .pre_consensus_sponsor_only_move_authentication;
1711 if pre_consensus_sponsor_only_move_authentication {
1712 assert!(
1713 self.enable_move_authentication(),
1714 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
1715 );
1716 assert!(
1717 self.enable_move_authentication_for_sponsor(),
1718 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
1719 );
1720 }
1721 pre_consensus_sponsor_only_move_authentication
1722 }
1723}
1724
1725#[cfg(not(msim))]
1726static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1727
1728#[cfg(msim)]
1730thread_local! {
1731 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1732}
1733
1734impl ProtocolConfig {
1736 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1739 assert!(
1741 version >= ProtocolVersion::MIN,
1742 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1743 version,
1744 ProtocolVersion::MIN.0,
1745 );
1746 assert!(
1747 version <= ProtocolVersion::MAX_ALLOWED,
1748 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1749 version,
1750 ProtocolVersion::MAX_ALLOWED.0,
1751 );
1752
1753 let mut ret = Self::get_for_version_impl(version, chain);
1754 ret.version = version;
1755
1756 ret = CONFIG_OVERRIDE.with(|ovr| {
1757 if let Some(override_fn) = &*ovr.borrow() {
1758 warn!(
1759 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1760 );
1761 override_fn(version, ret)
1762 } else {
1763 ret
1764 }
1765 });
1766
1767 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1768 warn!(
1769 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1770 );
1771 let overrides: ProtocolConfigOptional =
1772 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1773 .expect("failed to parse ProtocolConfig override env variables");
1774 overrides.apply_to(&mut ret);
1775 }
1776
1777 ret
1778 }
1779
1780 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1783 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1784 let mut ret = Self::get_for_version_impl(version, chain);
1785 ret.version = version;
1786 Some(ret)
1787 } else {
1788 None
1789 }
1790 }
1791
1792 #[cfg(not(msim))]
1793 pub fn poison_get_for_min_version() {
1794 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1795 }
1796
1797 #[cfg(not(msim))]
1798 fn load_poison_get_for_min_version() -> bool {
1799 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1800 }
1801
1802 #[cfg(msim)]
1803 pub fn poison_get_for_min_version() {
1804 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1805 }
1806
1807 #[cfg(msim)]
1808 fn load_poison_get_for_min_version() -> bool {
1809 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1810 }
1811
1812 pub fn convert_type_argument_error(&self) -> bool {
1813 self.feature_flags.convert_type_argument_error
1814 }
1815
1816 pub fn get_for_min_version() -> Self {
1820 if Self::load_poison_get_for_min_version() {
1821 panic!("get_for_min_version called on validator");
1822 }
1823 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1824 }
1825
1826 #[expect(non_snake_case)]
1837 pub fn get_for_max_version_UNSAFE() -> Self {
1838 if Self::load_poison_get_for_min_version() {
1839 panic!("get_for_max_version_UNSAFE called on validator");
1840 }
1841 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1842 }
1843
1844 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1845 #[cfg(msim)]
1846 {
1847 if version > ProtocolVersion::MAX {
1849 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1850 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1851 return config;
1852 }
1853 }
1854
1855 let mut cfg = Self {
1859 version,
1860
1861 feature_flags: Default::default(),
1862
1863 max_tx_size_bytes: Some(128 * 1024),
1864 max_input_objects: Some(2048),
1867 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1868 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1869 max_gas_payment_objects: Some(256),
1870 max_modules_in_publish: Some(64),
1871 max_package_dependencies: Some(32),
1872 max_arguments: Some(512),
1873 max_type_arguments: Some(16),
1874 max_type_argument_depth: Some(16),
1875 max_pure_argument_size: Some(16 * 1024),
1876 max_programmable_tx_commands: Some(1024),
1877 move_binary_format_version: Some(7),
1878 min_move_binary_format_version: Some(6),
1879 binary_module_handles: Some(100),
1880 binary_struct_handles: Some(300),
1881 binary_function_handles: Some(1500),
1882 binary_function_instantiations: Some(750),
1883 binary_signatures: Some(1000),
1884 binary_constant_pool: Some(4000),
1885 binary_identifiers: Some(10000),
1886 binary_address_identifiers: Some(100),
1887 binary_struct_defs: Some(200),
1888 binary_struct_def_instantiations: Some(100),
1889 binary_function_defs: Some(1000),
1890 binary_field_handles: Some(500),
1891 binary_field_instantiations: Some(250),
1892 binary_friend_decls: Some(100),
1893 binary_enum_defs: None,
1894 binary_enum_def_instantiations: None,
1895 binary_variant_handles: None,
1896 binary_variant_instantiation_handles: None,
1897 max_move_object_size: Some(250 * 1024),
1898 max_move_package_size: Some(100 * 1024),
1899 max_publish_or_upgrade_per_ptb: Some(5),
1900 max_auth_gas: None,
1902 max_tx_gas: Some(50_000_000_000),
1904 max_gas_price: Some(100_000),
1905 max_gas_computation_bucket: Some(5_000_000),
1906 max_loop_depth: Some(5),
1907 max_generic_instantiation_length: Some(32),
1908 max_function_parameters: Some(128),
1909 max_basic_blocks: Some(1024),
1910 max_value_stack_size: Some(1024),
1911 max_type_nodes: Some(256),
1912 max_push_size: Some(10000),
1913 max_struct_definitions: Some(200),
1914 max_function_definitions: Some(1000),
1915 max_fields_in_struct: Some(32),
1916 max_dependency_depth: Some(100),
1917 max_num_event_emit: Some(1024),
1918 max_num_new_move_object_ids: Some(2048),
1919 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1920 max_num_deleted_move_object_ids: Some(2048),
1921 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1922 max_num_transferred_move_object_ids: Some(2048),
1923 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1924 max_event_emit_size: Some(250 * 1024),
1925 max_move_vector_len: Some(256 * 1024),
1926 max_type_to_layout_nodes: None,
1927 max_ptb_value_size: None,
1928
1929 max_back_edges_per_function: Some(10_000),
1930 max_back_edges_per_module: Some(10_000),
1931
1932 max_verifier_meter_ticks_per_function: Some(16_000_000),
1933
1934 max_meter_ticks_per_module: Some(16_000_000),
1935 max_meter_ticks_per_package: Some(16_000_000),
1936
1937 object_runtime_max_num_cached_objects: Some(1000),
1938 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
1939 object_runtime_max_num_store_entries: Some(1000),
1940 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
1941 base_tx_cost_fixed: Some(1_000),
1943 package_publish_cost_fixed: Some(1_000),
1944 base_tx_cost_per_byte: Some(0),
1945 package_publish_cost_per_byte: Some(80),
1946 obj_access_cost_read_per_byte: Some(15),
1947 obj_access_cost_mutate_per_byte: Some(40),
1948 obj_access_cost_delete_per_byte: Some(40),
1949 obj_access_cost_verify_per_byte: Some(200),
1950 obj_data_cost_refundable: Some(100),
1951 obj_metadata_cost_non_refundable: Some(50),
1952 gas_model_version: Some(1),
1953 storage_rebate_rate: Some(10000),
1954 reward_slashing_rate: Some(10000),
1956 storage_gas_price: Some(76),
1957 base_gas_price: None,
1958 validator_target_reward: Some(767_000 * 1_000_000_000),
1961 max_transactions_per_checkpoint: Some(10_000),
1962 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
1963
1964 buffer_stake_for_protocol_upgrade_bps: Some(5000),
1966
1967 address_from_bytes_cost_base: Some(52),
1971 address_to_u256_cost_base: Some(52),
1973 address_from_u256_cost_base: Some(52),
1975
1976 config_read_setting_impl_cost_base: Some(100),
1979 config_read_setting_impl_cost_per_byte: Some(40),
1980
1981 dynamic_field_hash_type_and_key_cost_base: Some(100),
1985 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
1986 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
1987 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
1988 dynamic_field_add_child_object_cost_base: Some(100),
1991 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
1992 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
1993 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
1994 dynamic_field_borrow_child_object_cost_base: Some(100),
1997 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
1998 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
1999 dynamic_field_remove_child_object_cost_base: Some(100),
2002 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2003 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2004 dynamic_field_has_child_object_cost_base: Some(100),
2007 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2010 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2011 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2012
2013 event_emit_cost_base: Some(52),
2016 event_emit_value_size_derivation_cost_per_byte: Some(2),
2017 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2018 event_emit_output_cost_per_byte: Some(10),
2019
2020 object_borrow_uid_cost_base: Some(52),
2023 object_delete_impl_cost_base: Some(52),
2025 object_record_new_uid_cost_base: Some(52),
2027
2028 transfer_transfer_internal_cost_base: Some(52),
2032 transfer_freeze_object_cost_base: Some(52),
2034 transfer_share_object_cost_base: Some(52),
2036 transfer_receive_object_cost_base: Some(52),
2037
2038 tx_context_derive_id_cost_base: Some(52),
2042 tx_context_fresh_id_cost_base: None,
2043 tx_context_sender_cost_base: None,
2044 tx_context_digest_cost_base: None,
2045 tx_context_epoch_cost_base: None,
2046 tx_context_epoch_timestamp_ms_cost_base: None,
2047 tx_context_sponsor_cost_base: None,
2048 tx_context_rgp_cost_base: None,
2049 tx_context_gas_price_cost_base: None,
2050 tx_context_gas_budget_cost_base: None,
2051 tx_context_ids_created_cost_base: None,
2052 tx_context_replace_cost_base: None,
2053
2054 types_is_one_time_witness_cost_base: Some(52),
2057 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2058 types_is_one_time_witness_type_cost_per_byte: Some(2),
2059
2060 validator_validate_metadata_cost_base: Some(52),
2064 validator_validate_metadata_data_cost_per_byte: Some(2),
2065
2066 crypto_invalid_arguments_cost: Some(100),
2068 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2070 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2071 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2072
2073 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2075 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2076 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2077
2078 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2080 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2081 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2082 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2083 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2084 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2085
2086 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2088
2089 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2091 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2092 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2093 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2094 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2095 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2096
2097 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2099 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2100 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2101 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2102 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2103 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2104
2105 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2107 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2108 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2109 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2110 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2111 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2112
2113 ecvrf_ecvrf_verify_cost_base: Some(52),
2115 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2116 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2117
2118 ed25519_ed25519_verify_cost_base: Some(52),
2120 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2121 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2122
2123 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2125 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2126
2127 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2129 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2130 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2131 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2132 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2133
2134 hash_blake2b256_cost_base: Some(52),
2136 hash_blake2b256_data_cost_per_byte: Some(2),
2137 hash_blake2b256_data_cost_per_block: Some(2),
2138 hash_keccak256_cost_base: Some(52),
2140 hash_keccak256_data_cost_per_byte: Some(2),
2141 hash_keccak256_data_cost_per_block: Some(2),
2142
2143 poseidon_bn254_cost_base: None,
2144 poseidon_bn254_cost_per_block: None,
2145
2146 hmac_hmac_sha3_256_cost_base: Some(52),
2148 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2149 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2150
2151 group_ops_bls12381_decode_scalar_cost: Some(52),
2153 group_ops_bls12381_decode_g1_cost: Some(52),
2154 group_ops_bls12381_decode_g2_cost: Some(52),
2155 group_ops_bls12381_decode_gt_cost: Some(52),
2156 group_ops_bls12381_scalar_add_cost: Some(52),
2157 group_ops_bls12381_g1_add_cost: Some(52),
2158 group_ops_bls12381_g2_add_cost: Some(52),
2159 group_ops_bls12381_gt_add_cost: Some(52),
2160 group_ops_bls12381_scalar_sub_cost: Some(52),
2161 group_ops_bls12381_g1_sub_cost: Some(52),
2162 group_ops_bls12381_g2_sub_cost: Some(52),
2163 group_ops_bls12381_gt_sub_cost: Some(52),
2164 group_ops_bls12381_scalar_mul_cost: Some(52),
2165 group_ops_bls12381_g1_mul_cost: Some(52),
2166 group_ops_bls12381_g2_mul_cost: Some(52),
2167 group_ops_bls12381_gt_mul_cost: Some(52),
2168 group_ops_bls12381_scalar_div_cost: Some(52),
2169 group_ops_bls12381_g1_div_cost: Some(52),
2170 group_ops_bls12381_g2_div_cost: Some(52),
2171 group_ops_bls12381_gt_div_cost: Some(52),
2172 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2173 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2174 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2175 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2176 group_ops_bls12381_g1_msm_base_cost: Some(52),
2177 group_ops_bls12381_g2_msm_base_cost: Some(52),
2178 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2179 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2180 group_ops_bls12381_msm_max_len: Some(32),
2181 group_ops_bls12381_pairing_cost: Some(52),
2182 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2183 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2184 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2185 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2186 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2187
2188 #[allow(deprecated)]
2190 check_zklogin_id_cost_base: Some(200),
2191 #[allow(deprecated)]
2192 check_zklogin_issuer_cost_base: Some(200),
2194
2195 vdf_verify_vdf_cost: None,
2196 vdf_hash_to_input_cost: None,
2197
2198 bcs_per_byte_serialized_cost: Some(2),
2199 bcs_legacy_min_output_size_cost: Some(1),
2200 bcs_failure_cost: Some(52),
2201 hash_sha2_256_base_cost: Some(52),
2202 hash_sha2_256_per_byte_cost: Some(2),
2203 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2204 hash_sha3_256_base_cost: Some(52),
2205 hash_sha3_256_per_byte_cost: Some(2),
2206 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2207 type_name_get_base_cost: Some(52),
2208 type_name_get_per_byte_cost: Some(2),
2209 string_check_utf8_base_cost: Some(52),
2210 string_check_utf8_per_byte_cost: Some(2),
2211 string_is_char_boundary_base_cost: Some(52),
2212 string_sub_string_base_cost: Some(52),
2213 string_sub_string_per_byte_cost: Some(2),
2214 string_index_of_base_cost: Some(52),
2215 string_index_of_per_byte_pattern_cost: Some(2),
2216 string_index_of_per_byte_searched_cost: Some(2),
2217 vector_empty_base_cost: Some(52),
2218 vector_length_base_cost: Some(52),
2219 vector_push_back_base_cost: Some(52),
2220 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2221 vector_borrow_base_cost: Some(52),
2222 vector_pop_back_base_cost: Some(52),
2223 vector_destroy_empty_base_cost: Some(52),
2224 vector_swap_base_cost: Some(52),
2225 debug_print_base_cost: Some(52),
2226 debug_print_stack_trace_base_cost: Some(52),
2227
2228 max_size_written_objects: Some(5 * 1000 * 1000),
2229 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2232
2233 max_move_identifier_len: Some(128),
2235 max_move_value_depth: Some(128),
2236 max_move_enum_variants: None,
2237
2238 gas_rounding_step: Some(1_000),
2239
2240 execution_version: Some(1),
2241
2242 max_event_emit_size_total: Some(
2245 256 * 250 * 1024, ),
2247
2248 consensus_bad_nodes_stake_threshold: Some(20),
2255
2256 #[allow(deprecated)]
2258 max_jwk_votes_per_validator_per_epoch: Some(240),
2259
2260 #[allow(deprecated)]
2261 max_age_of_jwk_in_epochs: Some(1),
2262
2263 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2267
2268 random_beacon_reduction_allowed_delta: Some(800),
2269
2270 random_beacon_reduction_lower_bound: Some(1000),
2271 random_beacon_dkg_timeout_round: Some(3000),
2272 random_beacon_min_round_interval_ms: Some(500),
2273
2274 random_beacon_dkg_version: Some(1),
2275
2276 consensus_max_num_transactions_in_block: Some(512),
2280
2281 max_deferral_rounds_for_congestion_control: Some(10),
2282
2283 min_checkpoint_interval_ms: Some(200),
2284
2285 checkpoint_summary_version_specific_data: Some(1),
2286
2287 max_soft_bundle_size: Some(5),
2288
2289 bridge_should_try_to_finalize_committee: None,
2290
2291 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2292
2293 max_committee_members_count: None,
2294
2295 consensus_gc_depth: None,
2296
2297 consensus_max_acknowledgments_per_block: None,
2298
2299 max_congestion_limit_overshoot_per_commit: None,
2300
2301 scorer_version: None,
2302
2303 auth_context_digest_cost_base: None,
2305 auth_context_tx_data_bytes_cost_base: None,
2306 auth_context_tx_data_bytes_cost_per_byte: None,
2307 auth_context_tx_commands_cost_base: None,
2308 auth_context_tx_commands_cost_per_byte: None,
2309 auth_context_tx_inputs_cost_base: None,
2310 auth_context_tx_inputs_cost_per_byte: None,
2311 auth_context_replace_cost_base: None,
2312 auth_context_replace_cost_per_byte: None,
2313 };
2316
2317 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2318
2319 {
2321 cfg.feature_flags
2322 .disable_invariant_violation_check_in_swap_loc = true;
2323 cfg.feature_flags.no_extraneous_module_bytes = true;
2324 cfg.feature_flags.hardened_otw_check = true;
2325 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2326 }
2327
2328 {
2330 #[allow(deprecated)]
2331 {
2332 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2333 }
2334 }
2335
2336 #[expect(deprecated)]
2340 {
2341 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2342 }
2343 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2345
2346 cfg.feature_flags.per_object_congestion_control_mode =
2347 PerObjectCongestionControlMode::TotalTxCount;
2348
2349 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2351
2352 if chain != Chain::Mainnet && chain != Chain::Testnet {
2354 cfg.feature_flags.enable_poseidon = true;
2355 cfg.poseidon_bn254_cost_base = Some(260);
2356 cfg.poseidon_bn254_cost_per_block = Some(10);
2357
2358 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2359
2360 cfg.feature_flags.enable_vdf = true;
2361 cfg.vdf_verify_vdf_cost = Some(1500);
2364 cfg.vdf_hash_to_input_cost = Some(100);
2365
2366 cfg.feature_flags.passkey_auth = true;
2367 }
2368
2369 for cur in 2..=version.0 {
2370 match cur {
2371 1 => unreachable!(),
2372 2 => {}
2374 3 => {
2375 cfg.feature_flags.relocate_event_module = true;
2376 }
2377 4 => {
2378 cfg.max_type_to_layout_nodes = Some(512);
2379 }
2380 5 => {
2381 cfg.feature_flags.protocol_defined_base_fee = true;
2382 cfg.base_gas_price = Some(1000);
2383
2384 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2385 cfg.feature_flags.convert_type_argument_error = true;
2386 cfg.feature_flags.native_charging_v2 = true;
2387
2388 if chain != Chain::Mainnet && chain != Chain::Testnet {
2389 cfg.feature_flags.uncompressed_g1_group_elements = true;
2390 }
2391
2392 cfg.gas_model_version = Some(2);
2393
2394 cfg.poseidon_bn254_cost_per_block = Some(388);
2395
2396 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2397 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2398 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2399 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2400 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2401 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2402 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2403 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2404
2405 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2407 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2408 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2409 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2410
2411 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2412 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2413 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2414 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2415 Some(8213);
2416 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2417 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2418 Some(9484);
2419
2420 cfg.hash_keccak256_cost_base = Some(10);
2421 cfg.hash_blake2b256_cost_base = Some(10);
2422
2423 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2425 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2426 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2427 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2428
2429 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2430 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2431 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2432 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2433
2434 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2435 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2436 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2437 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2438
2439 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2440 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2441 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2442 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2443
2444 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2445 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2446 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2447 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2448
2449 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2450 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2451
2452 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2453 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2454 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2455 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2456
2457 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2458 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2459 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2460 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2461 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2462
2463 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2464
2465 cfg.validator_validate_metadata_cost_base = Some(20000);
2466
2467 cfg.max_committee_members_count = Some(50);
2468 }
2469 6 => {
2470 cfg.max_ptb_value_size = Some(1024 * 1024);
2471 }
2472 7 => {
2473 }
2476 8 => {
2477 cfg.feature_flags.variant_nodes = true;
2478
2479 if chain != Chain::Mainnet {
2480 cfg.feature_flags.consensus_round_prober = true;
2482 cfg.feature_flags
2484 .consensus_distributed_vote_scoring_strategy = true;
2485 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2486 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2488 cfg.feature_flags
2490 .consensus_round_prober_probe_accepted_rounds = true;
2491 cfg.feature_flags.consensus_zstd_compression = true;
2493 cfg.consensus_gc_depth = Some(60);
2497 }
2498
2499 if chain != Chain::Testnet && chain != Chain::Mainnet {
2502 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2503 }
2504 }
2505 9 => {
2506 if chain != Chain::Mainnet {
2507 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2509 }
2510
2511 cfg.feature_flags.consensus_zstd_compression = true;
2513
2514 if chain != Chain::Testnet && chain != Chain::Mainnet {
2516 cfg.feature_flags.accept_passkey_in_multisig = true;
2517 }
2518
2519 cfg.bridge_should_try_to_finalize_committee = None;
2521 }
2522 10 => {
2523 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2526
2527 cfg.max_committee_members_count = Some(80);
2529
2530 cfg.feature_flags.consensus_round_prober = true;
2532 cfg.feature_flags
2534 .consensus_round_prober_probe_accepted_rounds = true;
2535 cfg.feature_flags
2537 .consensus_distributed_vote_scoring_strategy = true;
2538 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2540
2541 cfg.consensus_gc_depth = Some(60);
2546
2547 cfg.feature_flags.minimize_child_object_mutations = true;
2549
2550 if chain != Chain::Mainnet {
2551 cfg.feature_flags.consensus_batched_block_sync = true;
2553 }
2554
2555 if chain != Chain::Testnet && chain != Chain::Mainnet {
2556 cfg.feature_flags
2559 .congestion_control_gas_price_feedback_mechanism = true;
2560 }
2561
2562 cfg.feature_flags.validate_identifier_inputs = true;
2563 cfg.feature_flags.dependency_linkage_error = true;
2564 cfg.feature_flags.additional_multisig_checks = true;
2565 }
2566 11 => {
2567 }
2570 12 => {
2571 cfg.feature_flags
2574 .congestion_control_gas_price_feedback_mechanism = true;
2575
2576 cfg.feature_flags.normalize_ptb_arguments = true;
2578 }
2579 13 => {
2580 cfg.feature_flags.select_committee_from_eligible_validators = true;
2583 cfg.feature_flags.track_non_committee_eligible_validators = true;
2586
2587 if chain != Chain::Testnet && chain != Chain::Mainnet {
2588 cfg.feature_flags
2591 .select_committee_supporting_next_epoch_version = true;
2592 }
2593 }
2594 14 => {
2595 cfg.feature_flags.consensus_batched_block_sync = true;
2597
2598 if chain != Chain::Mainnet {
2599 cfg.feature_flags
2602 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2603 cfg.feature_flags
2607 .select_committee_supporting_next_epoch_version = true;
2608 }
2609 if chain != Chain::Testnet && chain != Chain::Mainnet {
2610 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2612 }
2613 }
2614 15 => {
2615 if chain != Chain::Mainnet && chain != Chain::Testnet {
2616 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2620 }
2621 }
2622 16 => {
2623 cfg.feature_flags
2626 .select_committee_supporting_next_epoch_version = true;
2627 cfg.feature_flags
2629 .consensus_commit_transactions_only_for_traversed_headers = true;
2630 }
2631 17 => {
2632 cfg.max_committee_members_count = Some(100);
2634 }
2635 18 => {
2636 if chain != Chain::Mainnet {
2637 cfg.feature_flags.passkey_auth = true;
2639 }
2640 }
2641 19 => {
2642 if chain != Chain::Testnet && chain != Chain::Mainnet {
2643 cfg.feature_flags
2646 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2647 cfg.feature_flags
2650 .separate_gas_price_feedback_mechanism_for_randomness = true;
2651 cfg.feature_flags.metadata_in_module_bytes = true;
2654 cfg.feature_flags.publish_package_metadata = true;
2655 cfg.feature_flags.enable_move_authentication = true;
2657 cfg.max_auth_gas = Some(250_000_000);
2659 cfg.transfer_receive_object_cost_base = Some(100);
2662 cfg.feature_flags.adjust_rewards_by_score = true;
2664 }
2665
2666 if chain != Chain::Mainnet {
2667 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2669
2670 cfg.feature_flags.calculate_validator_scores = true;
2672 cfg.scorer_version = Some(1);
2673 }
2674
2675 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
2677
2678 cfg.feature_flags.passkey_auth = true;
2680 }
2681 20 => {
2682 if chain != Chain::Testnet && chain != Chain::Mainnet {
2683 cfg.feature_flags
2685 .pass_calculated_validator_scores_to_advance_epoch = true;
2686 }
2687 }
2688 21 => {
2689 if chain != Chain::Testnet && chain != Chain::Mainnet {
2690 cfg.feature_flags.consensus_fast_commit_sync = true;
2692 }
2693 if chain != Chain::Mainnet {
2694 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2699 cfg.feature_flags
2702 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2703 cfg.feature_flags
2706 .separate_gas_price_feedback_mechanism_for_randomness = true;
2707 }
2708
2709 cfg.auth_context_digest_cost_base = Some(30);
2710 cfg.auth_context_tx_commands_cost_base = Some(30);
2711 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
2712 cfg.auth_context_tx_inputs_cost_base = Some(30);
2713 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
2714 cfg.auth_context_replace_cost_base = Some(30);
2715 cfg.auth_context_replace_cost_per_byte = Some(2);
2716
2717 if chain != Chain::Testnet && chain != Chain::Mainnet {
2718 cfg.max_auth_gas = Some(250_000);
2720 }
2721 }
2722 22 => {
2723 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2728 cfg.feature_flags
2731 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2732 cfg.feature_flags
2735 .separate_gas_price_feedback_mechanism_for_randomness = true;
2736
2737 if chain != Chain::Mainnet {
2738 cfg.feature_flags.metadata_in_module_bytes = true;
2741 cfg.feature_flags.publish_package_metadata = true;
2742 cfg.feature_flags.enable_move_authentication = true;
2744 cfg.max_auth_gas = Some(250_000);
2746 cfg.transfer_receive_object_cost_base = Some(100);
2749 }
2750
2751 if chain != Chain::Mainnet {
2752 cfg.feature_flags.consensus_fast_commit_sync = true;
2754 }
2755 }
2756 23 => {
2757 cfg.feature_flags.move_native_tx_context = true;
2759 cfg.tx_context_fresh_id_cost_base = Some(52);
2760 cfg.tx_context_sender_cost_base = Some(30);
2761 cfg.tx_context_digest_cost_base = Some(30);
2762 cfg.tx_context_epoch_cost_base = Some(30);
2763 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
2764 cfg.tx_context_sponsor_cost_base = Some(30);
2765 cfg.tx_context_rgp_cost_base = Some(30);
2766 cfg.tx_context_gas_price_cost_base = Some(30);
2767 cfg.tx_context_gas_budget_cost_base = Some(30);
2768 cfg.tx_context_ids_created_cost_base = Some(30);
2769 cfg.tx_context_replace_cost_base = Some(30);
2770 }
2771 24 => {
2772 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2774
2775 if chain != Chain::Testnet && chain != Chain::Mainnet {
2776 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2778 }
2779
2780 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
2783 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
2784
2785 cfg.feature_flags.additional_borrow_checks = true;
2787 }
2788 #[allow(deprecated)]
2789 25 => {
2790 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
2793 cfg.check_zklogin_id_cost_base = None;
2794 cfg.check_zklogin_issuer_cost_base = None;
2795 cfg.max_jwk_votes_per_validator_per_epoch = None;
2796 cfg.max_age_of_jwk_in_epochs = None;
2797 }
2798 26 => {
2799 }
2802 27 => {
2803 if chain != Chain::Mainnet {
2804 cfg.feature_flags.consensus_block_restrictions = true;
2807 }
2808
2809 if chain != Chain::Testnet && chain != Chain::Mainnet {
2810 cfg.feature_flags
2812 .pre_consensus_sponsor_only_move_authentication = true;
2813 }
2814 }
2815 _ => panic!("unsupported version {version:?}"),
2826 }
2827 }
2828 cfg
2829 }
2830
2831 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
2837 let (
2838 max_back_edges_per_function,
2839 max_back_edges_per_module,
2840 sanity_check_with_regex_reference_safety,
2841 ) = if let Some((
2842 max_back_edges_per_function,
2843 max_back_edges_per_module,
2844 sanity_check_with_regex_reference_safety,
2845 )) = signing_limits
2846 {
2847 (
2848 Some(max_back_edges_per_function),
2849 Some(max_back_edges_per_module),
2850 Some(sanity_check_with_regex_reference_safety),
2851 )
2852 } else {
2853 (None, None, None)
2854 };
2855
2856 let additional_borrow_checks = if signing_limits.is_some() {
2857 true
2860 } else {
2861 self.additional_borrow_checks()
2862 };
2863
2864 VerifierConfig {
2865 max_loop_depth: Some(self.max_loop_depth() as usize),
2866 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2867 max_function_parameters: Some(self.max_function_parameters() as usize),
2868 max_basic_blocks: Some(self.max_basic_blocks() as usize),
2869 max_value_stack_size: self.max_value_stack_size() as usize,
2870 max_type_nodes: Some(self.max_type_nodes() as usize),
2871 max_push_size: Some(self.max_push_size() as usize),
2872 max_dependency_depth: Some(self.max_dependency_depth() as usize),
2873 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2874 max_function_definitions: Some(self.max_function_definitions() as usize),
2875 max_data_definitions: Some(self.max_struct_definitions() as usize),
2876 max_constant_vector_len: Some(self.max_move_vector_len()),
2877 max_back_edges_per_function,
2878 max_back_edges_per_module,
2879 max_basic_blocks_in_script: None,
2880 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
2884 max_variants_in_enum: self.max_move_enum_variants_as_option(),
2885 additional_borrow_checks,
2886 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
2887 .map(|limit| limit as u128),
2888 }
2889 }
2890
2891 pub fn apply_overrides_for_testing(
2896 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
2897 ) -> OverrideGuard {
2898 CONFIG_OVERRIDE.with(|ovr| {
2899 let mut cur = ovr.borrow_mut();
2900 assert!(cur.is_none(), "config override already present");
2901 *cur = Some(Box::new(override_fn));
2902 OverrideGuard
2903 })
2904 }
2905}
2906
2907impl ProtocolConfig {
2912 pub fn set_per_object_congestion_control_mode_for_testing(
2913 &mut self,
2914 val: PerObjectCongestionControlMode,
2915 ) {
2916 self.feature_flags.per_object_congestion_control_mode = val;
2917 }
2918
2919 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
2920 self.feature_flags.consensus_choice = val;
2921 }
2922
2923 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
2924 self.feature_flags.consensus_network = val;
2925 }
2926
2927 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
2928 self.feature_flags.passkey_auth = val
2929 }
2930
2931 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
2932 self.feature_flags
2933 .disallow_new_modules_in_deps_only_packages = val;
2934 }
2935
2936 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
2937 self.feature_flags.consensus_round_prober = val;
2938 }
2939
2940 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
2941 self.feature_flags
2942 .consensus_distributed_vote_scoring_strategy = val;
2943 }
2944
2945 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
2946 self.consensus_gc_depth = Some(val);
2947 }
2948
2949 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
2950 self.feature_flags.consensus_linearize_subdag_v2 = val;
2951 }
2952
2953 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
2954 self.feature_flags
2955 .consensus_round_prober_probe_accepted_rounds = val;
2956 }
2957
2958 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
2959 self.feature_flags.accept_passkey_in_multisig = val;
2960 }
2961
2962 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
2963 self.feature_flags.consensus_smart_ancestor_selection = val;
2964 }
2965
2966 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
2967 self.feature_flags.consensus_batched_block_sync = val;
2968 }
2969
2970 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
2971 self.feature_flags
2972 .congestion_control_min_free_execution_slot = val;
2973 }
2974
2975 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
2976 self.feature_flags
2977 .congestion_control_gas_price_feedback_mechanism = val;
2978 }
2979
2980 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
2981 self.feature_flags.select_committee_from_eligible_validators = val;
2982 }
2983
2984 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
2985 self.feature_flags.track_non_committee_eligible_validators = val;
2986 }
2987
2988 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
2989 self.feature_flags
2990 .select_committee_supporting_next_epoch_version = val;
2991 }
2992
2993 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
2994 &mut self,
2995 val: bool,
2996 ) {
2997 self.feature_flags
2998 .consensus_median_timestamp_with_checkpoint_enforcement = val;
2999 }
3000
3001 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3002 &mut self,
3003 val: bool,
3004 ) {
3005 self.feature_flags
3006 .consensus_commit_transactions_only_for_traversed_headers = val;
3007 }
3008
3009 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3010 &mut self,
3011 val: bool,
3012 ) {
3013 self.feature_flags
3014 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3015 }
3016
3017 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3018 &mut self,
3019 val: bool,
3020 ) {
3021 self.feature_flags
3022 .separate_gas_price_feedback_mechanism_for_randomness = val;
3023 }
3024
3025 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3026 self.feature_flags.metadata_in_module_bytes = val;
3027 }
3028
3029 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3030 self.feature_flags.publish_package_metadata = val;
3031 }
3032
3033 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3034 self.feature_flags.enable_move_authentication = val;
3035 }
3036
3037 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3038 self.feature_flags.enable_move_authentication_for_sponsor = val;
3039 }
3040
3041 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3042 self.feature_flags.consensus_fast_commit_sync = val;
3043 }
3044
3045 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3046 self.feature_flags.consensus_block_restrictions = val;
3047 }
3048
3049 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3050 self.feature_flags
3051 .pre_consensus_sponsor_only_move_authentication = val;
3052 }
3053}
3054
3055type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
3056
3057thread_local! {
3058 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
3059}
3060
3061#[must_use]
3062pub struct OverrideGuard;
3063
3064impl Drop for OverrideGuard {
3065 fn drop(&mut self) {
3066 info!("restoring override fn");
3067 CONFIG_OVERRIDE.with(|ovr| {
3068 *ovr.borrow_mut() = None;
3069 });
3070 }
3071}
3072
3073#[derive(PartialEq, Eq)]
3077pub enum LimitThresholdCrossed {
3078 None,
3079 Soft(u128, u128),
3080 Hard(u128, u128),
3081}
3082
3083pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
3086 x: T,
3087 soft_limit: U,
3088 hard_limit: V,
3089) -> LimitThresholdCrossed {
3090 let x: V = x.into();
3091 let soft_limit: V = soft_limit.into();
3092
3093 debug_assert!(soft_limit <= hard_limit);
3094
3095 if x >= hard_limit {
3098 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
3099 } else if x < soft_limit {
3100 LimitThresholdCrossed::None
3101 } else {
3102 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
3103 }
3104}
3105
3106#[macro_export]
3107macro_rules! check_limit {
3108 ($x:expr, $hard:expr) => {
3109 check_limit!($x, $hard, $hard)
3110 };
3111 ($x:expr, $soft:expr, $hard:expr) => {
3112 check_limit_in_range($x as u64, $soft, $hard)
3113 };
3114}
3115
3116#[macro_export]
3120macro_rules! check_limit_by_meter {
3121 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
3122 let (h, metered_str) = if $is_metered {
3124 ($metered_limit, "metered")
3125 } else {
3126 ($unmetered_hard_limit, "unmetered")
3128 };
3129 use iota_protocol_config::check_limit_in_range;
3130 let result = check_limit_in_range($x as u64, $metered_limit, h);
3131 match result {
3132 LimitThresholdCrossed::None => {}
3133 LimitThresholdCrossed::Soft(_, _) => {
3134 $metric.with_label_values(&[metered_str, "soft"]).inc();
3135 }
3136 LimitThresholdCrossed::Hard(_, _) => {
3137 $metric.with_label_values(&[metered_str, "hard"]).inc();
3138 }
3139 };
3140 result
3141 }};
3142}
3143
3144#[cfg(all(test, not(msim)))]
3145mod test {
3146 use insta::assert_yaml_snapshot;
3147
3148 use super::*;
3149
3150 #[test]
3151 fn snapshot_tests() {
3152 println!("\n============================================================================");
3153 println!("! !");
3154 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
3155 println!("! !");
3156 println!("============================================================================\n");
3157 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
3158 let chain_str = match chain_id {
3163 Chain::Unknown => "".to_string(),
3164 _ => format!("{chain_id:?}_"),
3165 };
3166 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
3167 let cur = ProtocolVersion::new(i);
3168 assert_yaml_snapshot!(
3169 format!("{}version_{}", chain_str, cur.as_u64()),
3170 ProtocolConfig::get_for_version(cur, *chain_id)
3171 );
3172 }
3173 }
3174 }
3175
3176 #[test]
3177 fn test_getters() {
3178 let prot: ProtocolConfig =
3179 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3180 assert_eq!(
3181 prot.max_arguments(),
3182 prot.max_arguments_as_option().unwrap()
3183 );
3184 }
3185
3186 #[test]
3187 fn test_setters() {
3188 let mut prot: ProtocolConfig =
3189 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3190 prot.set_max_arguments_for_testing(123);
3191 assert_eq!(prot.max_arguments(), 123);
3192
3193 prot.set_max_arguments_from_str_for_testing("321".to_string());
3194 assert_eq!(prot.max_arguments(), 321);
3195
3196 prot.disable_max_arguments_for_testing();
3197 assert_eq!(prot.max_arguments_as_option(), None);
3198
3199 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
3200 assert_eq!(prot.max_arguments(), 456);
3201 }
3202
3203 #[test]
3204 #[should_panic(expected = "unsupported version")]
3205 fn max_version_test() {
3206 let _ = ProtocolConfig::get_for_version_impl(
3209 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
3210 Chain::Unknown,
3211 );
3212 }
3213
3214 #[test]
3215 fn lookup_by_string_test() {
3216 let prot: ProtocolConfig =
3217 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3218 assert!(prot.lookup_attr("some random string".to_string()).is_none());
3220
3221 assert!(
3222 prot.lookup_attr("max_arguments".to_string())
3223 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
3224 );
3225
3226 assert!(
3228 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3229 .is_none()
3230 );
3231 assert!(
3232 prot.attr_map()
3233 .get("poseidon_bn254_cost_base")
3234 .unwrap()
3235 .is_none()
3236 );
3237
3238 let prot: ProtocolConfig =
3240 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3241
3242 assert!(
3243 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3244 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3245 );
3246 assert!(
3247 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
3248 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3249 );
3250
3251 let prot: ProtocolConfig =
3253 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3254 assert!(
3256 prot.feature_flags
3257 .lookup_attr("some random string".to_owned())
3258 .is_none()
3259 );
3260 assert!(
3261 !prot
3262 .feature_flags
3263 .attr_map()
3264 .contains_key("some random string")
3265 );
3266
3267 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
3269 assert!(
3270 prot.feature_flags
3271 .attr_map()
3272 .get("enable_poseidon")
3273 .unwrap()
3274 == &false
3275 );
3276 let prot: ProtocolConfig =
3277 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3278 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
3280 assert!(
3281 prot.feature_flags
3282 .attr_map()
3283 .get("enable_poseidon")
3284 .unwrap()
3285 == &true
3286 );
3287 }
3288
3289 #[test]
3290 fn limit_range_fn_test() {
3291 let low = 100u32;
3292 let high = 10000u64;
3293
3294 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
3295 assert!(matches!(
3296 check_limit!(255u16, low, high),
3297 LimitThresholdCrossed::Soft(255u128, 100)
3298 ));
3299 assert!(matches!(
3306 check_limit!(2550000u64, low, high),
3307 LimitThresholdCrossed::Hard(2550000, 10000)
3308 ));
3309
3310 assert!(matches!(
3311 check_limit!(2550000u64, high, high),
3312 LimitThresholdCrossed::Hard(2550000, 10000)
3313 ));
3314
3315 assert!(matches!(
3316 check_limit!(1u8, high),
3317 LimitThresholdCrossed::None
3318 ));
3319
3320 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
3321
3322 assert!(matches!(
3323 check_limit!(2550000u64, high),
3324 LimitThresholdCrossed::Hard(2550000, 10000)
3325 ));
3326 }
3327}