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 = 7;
23
24#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
55pub struct ProtocolVersion(u64);
56
57impl ProtocolVersion {
58 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
64
65 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
66
67 #[cfg(not(msim))]
68 const MAX_ALLOWED: Self = Self::MAX;
69
70 #[cfg(msim)]
73 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
74
75 pub fn new(v: u64) -> Self {
76 Self(v)
77 }
78
79 pub const fn as_u64(&self) -> u64 {
80 self.0
81 }
82
83 pub fn max() -> Self {
86 Self::MAX
87 }
88}
89
90impl From<u64> for ProtocolVersion {
91 fn from(v: u64) -> Self {
92 Self::new(v)
93 }
94}
95
96impl std::ops::Sub<u64> for ProtocolVersion {
97 type Output = Self;
98 fn sub(self, rhs: u64) -> Self::Output {
99 Self::new(self.0 - rhs)
100 }
101}
102
103impl std::ops::Add<u64> for ProtocolVersion {
104 type Output = Self;
105 fn add(self, rhs: u64) -> Self::Output {
106 Self::new(self.0 + rhs)
107 }
108}
109
110#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum)]
111pub enum Chain {
112 Mainnet,
113 Testnet,
114 Unknown,
115}
116
117impl Default for Chain {
118 fn default() -> Self {
119 Self::Unknown
120 }
121}
122
123impl Chain {
124 pub fn as_str(self) -> &'static str {
125 match self {
126 Chain::Mainnet => "mainnet",
127 Chain::Testnet => "testnet",
128 Chain::Unknown => "unknown",
129 }
130 }
131}
132
133pub struct Error(pub String);
134
135#[derive(Default, Clone, Serialize, Deserialize, Debug, ProtocolConfigFeatureFlagsGetters)]
139struct FeatureFlags {
140 #[serde(skip_serializing_if = "is_true")]
146 disable_invariant_violation_check_in_swap_loc: bool,
147
148 #[serde(skip_serializing_if = "is_true")]
151 no_extraneous_module_bytes: bool,
152
153 #[serde(skip_serializing_if = "is_false")]
155 zklogin_auth: bool,
156
157 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
159 consensus_transaction_ordering: ConsensusTransactionOrdering,
160
161 #[serde(skip_serializing_if = "is_false")]
162 enable_jwk_consensus_updates: bool,
163
164 #[serde(skip_serializing_if = "is_false")]
166 bridge: bool,
167
168 #[serde(skip_serializing_if = "is_false")]
170 accept_zklogin_in_multisig: bool,
171
172 #[serde(skip_serializing_if = "is_true")]
175 hardened_otw_check: bool,
176
177 #[serde(skip_serializing_if = "is_false")]
179 enable_poseidon: bool,
180
181 #[serde(skip_serializing_if = "is_false")]
183 enable_group_ops_native_function_msm: bool,
184
185 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
187 per_object_congestion_control_mode: PerObjectCongestionControlMode,
188
189 #[serde(skip_serializing_if = "ConsensusChoice::is_mysticeti")]
191 consensus_choice: ConsensusChoice,
192
193 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
195 consensus_network: ConsensusNetwork,
196
197 #[serde(skip_serializing_if = "Option::is_none")]
199 zklogin_max_epoch_upper_bound_delta: Option<u64>,
200
201 #[serde(skip_serializing_if = "is_false")]
203 enable_vdf: bool,
204
205 #[serde(skip_serializing_if = "is_false")]
207 passkey_auth: bool,
208
209 #[serde(skip_serializing_if = "is_true")]
212 rethrow_serialization_type_layout_errors: bool,
213
214 #[serde(skip_serializing_if = "is_false")]
216 relocate_event_module: bool,
217
218 #[serde(skip_serializing_if = "is_false")]
220 protocol_defined_base_fee: bool,
221
222 #[serde(skip_serializing_if = "is_false")]
224 uncompressed_g1_group_elements: bool,
225
226 #[serde(skip_serializing_if = "is_false")]
228 disallow_new_modules_in_deps_only_packages: bool,
229
230 #[serde(skip_serializing_if = "is_false")]
232 native_charging_v2: bool,
233
234 #[serde(skip_serializing_if = "is_false")]
236 convert_type_argument_error: bool,
237
238 #[serde(skip_serializing_if = "is_false")]
240 consensus_round_prober: bool,
241
242 #[serde(skip_serializing_if = "is_false")]
244 consensus_distributed_vote_scoring_strategy: bool,
245
246 #[serde(skip_serializing_if = "is_false")]
250 consensus_linearize_subdag_v2: bool,
251
252 #[serde(skip_serializing_if = "is_false")]
254 variant_nodes: bool,
255
256 #[serde(skip_serializing_if = "is_false")]
258 consensus_smart_ancestor_selection: bool,
259
260 #[serde(skip_serializing_if = "is_false")]
262 consensus_round_prober_probe_accepted_rounds: bool,
263
264 #[serde(skip_serializing_if = "is_false")]
266 consensus_zstd_compression: bool,
267
268 #[serde(skip_serializing_if = "is_false")]
271 congestion_control_min_free_execution_slot: bool,
272}
273
274fn is_true(b: &bool) -> bool {
275 *b
276}
277
278fn is_false(b: &bool) -> bool {
279 !b
280}
281
282#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
284pub enum ConsensusTransactionOrdering {
285 #[default]
288 None,
289 ByGasPrice,
291}
292
293impl ConsensusTransactionOrdering {
294 pub fn is_none(&self) -> bool {
295 matches!(self, ConsensusTransactionOrdering::None)
296 }
297}
298
299#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
301pub enum PerObjectCongestionControlMode {
302 #[default]
303 None, TotalGasBudget, TotalTxCount, }
307
308impl PerObjectCongestionControlMode {
309 pub fn is_none(&self) -> bool {
310 matches!(self, PerObjectCongestionControlMode::None)
311 }
312}
313
314#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
316pub enum ConsensusChoice {
317 #[default]
318 Mysticeti,
319}
320
321impl ConsensusChoice {
322 pub fn is_mysticeti(&self) -> bool {
323 matches!(self, ConsensusChoice::Mysticeti)
324 }
325}
326
327#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
329pub enum ConsensusNetwork {
330 #[default]
331 Tonic,
332}
333
334impl ConsensusNetwork {
335 pub fn is_tonic(&self) -> bool {
336 matches!(self, ConsensusNetwork::Tonic)
337 }
338}
339
340#[skip_serializing_none]
374#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
375pub struct ProtocolConfig {
376 pub version: ProtocolVersion,
377
378 feature_flags: FeatureFlags,
379
380 max_tx_size_bytes: Option<u64>,
385
386 max_input_objects: Option<u64>,
389
390 max_size_written_objects: Option<u64>,
395 max_size_written_objects_system_tx: Option<u64>,
399
400 max_serialized_tx_effects_size_bytes: Option<u64>,
402
403 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
405
406 max_gas_payment_objects: Option<u32>,
408
409 max_modules_in_publish: Option<u32>,
411
412 max_package_dependencies: Option<u32>,
414
415 max_arguments: Option<u32>,
418
419 max_type_arguments: Option<u32>,
421
422 max_type_argument_depth: Option<u32>,
424
425 max_pure_argument_size: Option<u32>,
427
428 max_programmable_tx_commands: Option<u32>,
430
431 move_binary_format_version: Option<u32>,
437 min_move_binary_format_version: Option<u32>,
438
439 binary_module_handles: Option<u16>,
441 binary_struct_handles: Option<u16>,
442 binary_function_handles: Option<u16>,
443 binary_function_instantiations: Option<u16>,
444 binary_signatures: Option<u16>,
445 binary_constant_pool: Option<u16>,
446 binary_identifiers: Option<u16>,
447 binary_address_identifiers: Option<u16>,
448 binary_struct_defs: Option<u16>,
449 binary_struct_def_instantiations: Option<u16>,
450 binary_function_defs: Option<u16>,
451 binary_field_handles: Option<u16>,
452 binary_field_instantiations: Option<u16>,
453 binary_friend_decls: Option<u16>,
454 binary_enum_defs: Option<u16>,
455 binary_enum_def_instantiations: Option<u16>,
456 binary_variant_handles: Option<u16>,
457 binary_variant_instantiation_handles: Option<u16>,
458
459 max_move_object_size: Option<u64>,
462
463 max_move_package_size: Option<u64>,
468
469 max_publish_or_upgrade_per_ptb: Option<u64>,
472
473 max_tx_gas: Option<u64>,
475
476 max_gas_price: Option<u64>,
479
480 max_gas_computation_bucket: Option<u64>,
483
484 gas_rounding_step: Option<u64>,
486
487 max_loop_depth: Option<u64>,
489
490 max_generic_instantiation_length: Option<u64>,
493
494 max_function_parameters: Option<u64>,
497
498 max_basic_blocks: Option<u64>,
501
502 max_value_stack_size: Option<u64>,
504
505 max_type_nodes: Option<u64>,
509
510 max_push_size: Option<u64>,
513
514 max_struct_definitions: Option<u64>,
517
518 max_function_definitions: Option<u64>,
521
522 max_fields_in_struct: Option<u64>,
525
526 max_dependency_depth: Option<u64>,
529
530 max_num_event_emit: Option<u64>,
533
534 max_num_new_move_object_ids: Option<u64>,
537
538 max_num_new_move_object_ids_system_tx: Option<u64>,
541
542 max_num_deleted_move_object_ids: Option<u64>,
545
546 max_num_deleted_move_object_ids_system_tx: Option<u64>,
549
550 max_num_transferred_move_object_ids: Option<u64>,
553
554 max_num_transferred_move_object_ids_system_tx: Option<u64>,
557
558 max_event_emit_size: Option<u64>,
560
561 max_event_emit_size_total: Option<u64>,
563
564 max_move_vector_len: Option<u64>,
567
568 max_move_identifier_len: Option<u64>,
571
572 max_move_value_depth: Option<u64>,
574
575 max_move_enum_variants: Option<u64>,
578
579 max_back_edges_per_function: Option<u64>,
582
583 max_back_edges_per_module: Option<u64>,
586
587 max_verifier_meter_ticks_per_function: Option<u64>,
590
591 max_meter_ticks_per_module: Option<u64>,
594
595 max_meter_ticks_per_package: Option<u64>,
598
599 object_runtime_max_num_cached_objects: Option<u64>,
606
607 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
610
611 object_runtime_max_num_store_entries: Option<u64>,
614
615 object_runtime_max_num_store_entries_system_tx: Option<u64>,
618
619 base_tx_cost_fixed: Option<u64>,
624
625 package_publish_cost_fixed: Option<u64>,
629
630 base_tx_cost_per_byte: Option<u64>,
634
635 package_publish_cost_per_byte: Option<u64>,
637
638 obj_access_cost_read_per_byte: Option<u64>,
640
641 obj_access_cost_mutate_per_byte: Option<u64>,
643
644 obj_access_cost_delete_per_byte: Option<u64>,
646
647 obj_access_cost_verify_per_byte: Option<u64>,
657
658 max_type_to_layout_nodes: Option<u64>,
660
661 max_ptb_value_size: Option<u64>,
663
664 gas_model_version: Option<u64>,
669
670 obj_data_cost_refundable: Option<u64>,
676
677 obj_metadata_cost_non_refundable: Option<u64>,
681
682 storage_rebate_rate: Option<u64>,
688
689 reward_slashing_rate: Option<u64>,
692
693 storage_gas_price: Option<u64>,
695
696 base_gas_price: Option<u64>,
698
699 validator_target_reward: Option<u64>,
701
702 max_transactions_per_checkpoint: Option<u64>,
709
710 max_checkpoint_size_bytes: Option<u64>,
714
715 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
721
722 address_from_bytes_cost_base: Option<u64>,
727 address_to_u256_cost_base: Option<u64>,
729 address_from_u256_cost_base: Option<u64>,
731
732 config_read_setting_impl_cost_base: Option<u64>,
737 config_read_setting_impl_cost_per_byte: Option<u64>,
738
739 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
743 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
744 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
745 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
746 dynamic_field_add_child_object_cost_base: Option<u64>,
749 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
750 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
751 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
752 dynamic_field_borrow_child_object_cost_base: Option<u64>,
755 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
756 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
757 dynamic_field_remove_child_object_cost_base: Option<u64>,
760 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
761 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
762 dynamic_field_has_child_object_cost_base: Option<u64>,
765 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
768 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
769 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
770
771 event_emit_cost_base: Option<u64>,
774 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
775 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
776 event_emit_output_cost_per_byte: Option<u64>,
777
778 object_borrow_uid_cost_base: Option<u64>,
781 object_delete_impl_cost_base: Option<u64>,
783 object_record_new_uid_cost_base: Option<u64>,
785
786 transfer_transfer_internal_cost_base: Option<u64>,
789 transfer_freeze_object_cost_base: Option<u64>,
791 transfer_share_object_cost_base: Option<u64>,
793 transfer_receive_object_cost_base: Option<u64>,
796
797 tx_context_derive_id_cost_base: Option<u64>,
800
801 types_is_one_time_witness_cost_base: Option<u64>,
804 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
805 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
806
807 validator_validate_metadata_cost_base: Option<u64>,
810 validator_validate_metadata_data_cost_per_byte: Option<u64>,
811
812 crypto_invalid_arguments_cost: Option<u64>,
814 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
816 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
817 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
818
819 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
821 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
822 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
823
824 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
826 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
827 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
828 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
829 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
830 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
831
832 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
834
835 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
837 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
838 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
839 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
840 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
841 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
842
843 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
845 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
846 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
847 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
848 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
849 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
850
851 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
853 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
854 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
855 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
856 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
857 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
858
859 ecvrf_ecvrf_verify_cost_base: Option<u64>,
861 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
862 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
863
864 ed25519_ed25519_verify_cost_base: Option<u64>,
866 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
867 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
868
869 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
871 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
872
873 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
875 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
876 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
877 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
878 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
879
880 hash_blake2b256_cost_base: Option<u64>,
882 hash_blake2b256_data_cost_per_byte: Option<u64>,
883 hash_blake2b256_data_cost_per_block: Option<u64>,
884
885 hash_keccak256_cost_base: Option<u64>,
887 hash_keccak256_data_cost_per_byte: Option<u64>,
888 hash_keccak256_data_cost_per_block: Option<u64>,
889
890 poseidon_bn254_cost_base: Option<u64>,
892 poseidon_bn254_cost_per_block: Option<u64>,
893
894 group_ops_bls12381_decode_scalar_cost: Option<u64>,
896 group_ops_bls12381_decode_g1_cost: Option<u64>,
897 group_ops_bls12381_decode_g2_cost: Option<u64>,
898 group_ops_bls12381_decode_gt_cost: Option<u64>,
899 group_ops_bls12381_scalar_add_cost: Option<u64>,
900 group_ops_bls12381_g1_add_cost: Option<u64>,
901 group_ops_bls12381_g2_add_cost: Option<u64>,
902 group_ops_bls12381_gt_add_cost: Option<u64>,
903 group_ops_bls12381_scalar_sub_cost: Option<u64>,
904 group_ops_bls12381_g1_sub_cost: Option<u64>,
905 group_ops_bls12381_g2_sub_cost: Option<u64>,
906 group_ops_bls12381_gt_sub_cost: Option<u64>,
907 group_ops_bls12381_scalar_mul_cost: Option<u64>,
908 group_ops_bls12381_g1_mul_cost: Option<u64>,
909 group_ops_bls12381_g2_mul_cost: Option<u64>,
910 group_ops_bls12381_gt_mul_cost: Option<u64>,
911 group_ops_bls12381_scalar_div_cost: Option<u64>,
912 group_ops_bls12381_g1_div_cost: Option<u64>,
913 group_ops_bls12381_g2_div_cost: Option<u64>,
914 group_ops_bls12381_gt_div_cost: Option<u64>,
915 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
916 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
917 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
918 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
919 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
920 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
921 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
922 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
923 group_ops_bls12381_msm_max_len: Option<u32>,
924 group_ops_bls12381_pairing_cost: Option<u64>,
925 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
926 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
927 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
928 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
929 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
930
931 hmac_hmac_sha3_256_cost_base: Option<u64>,
933 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
934 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
935
936 check_zklogin_id_cost_base: Option<u64>,
938 check_zklogin_issuer_cost_base: Option<u64>,
940
941 vdf_verify_vdf_cost: Option<u64>,
942 vdf_hash_to_input_cost: Option<u64>,
943
944 bcs_per_byte_serialized_cost: Option<u64>,
946 bcs_legacy_min_output_size_cost: Option<u64>,
947 bcs_failure_cost: Option<u64>,
948
949 hash_sha2_256_base_cost: Option<u64>,
950 hash_sha2_256_per_byte_cost: Option<u64>,
951 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
952 hash_sha3_256_base_cost: Option<u64>,
953 hash_sha3_256_per_byte_cost: Option<u64>,
954 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
955 type_name_get_base_cost: Option<u64>,
956 type_name_get_per_byte_cost: Option<u64>,
957
958 string_check_utf8_base_cost: Option<u64>,
959 string_check_utf8_per_byte_cost: Option<u64>,
960 string_is_char_boundary_base_cost: Option<u64>,
961 string_sub_string_base_cost: Option<u64>,
962 string_sub_string_per_byte_cost: Option<u64>,
963 string_index_of_base_cost: Option<u64>,
964 string_index_of_per_byte_pattern_cost: Option<u64>,
965 string_index_of_per_byte_searched_cost: Option<u64>,
966
967 vector_empty_base_cost: Option<u64>,
968 vector_length_base_cost: Option<u64>,
969 vector_push_back_base_cost: Option<u64>,
970 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
971 vector_borrow_base_cost: Option<u64>,
972 vector_pop_back_base_cost: Option<u64>,
973 vector_destroy_empty_base_cost: Option<u64>,
974 vector_swap_base_cost: Option<u64>,
975 debug_print_base_cost: Option<u64>,
976 debug_print_stack_trace_base_cost: Option<u64>,
977
978 execution_version: Option<u64>,
980
981 consensus_bad_nodes_stake_threshold: Option<u64>,
985
986 max_jwk_votes_per_validator_per_epoch: Option<u64>,
987 max_age_of_jwk_in_epochs: Option<u64>,
991
992 random_beacon_reduction_allowed_delta: Option<u16>,
996
997 random_beacon_reduction_lower_bound: Option<u32>,
1000
1001 random_beacon_dkg_timeout_round: Option<u32>,
1004
1005 random_beacon_min_round_interval_ms: Option<u64>,
1007
1008 random_beacon_dkg_version: Option<u64>,
1012
1013 consensus_max_transaction_size_bytes: Option<u64>,
1018 consensus_max_transactions_in_block_bytes: Option<u64>,
1020 consensus_max_num_transactions_in_block: Option<u64>,
1022
1023 max_deferral_rounds_for_congestion_control: Option<u64>,
1027
1028 min_checkpoint_interval_ms: Option<u64>,
1030
1031 checkpoint_summary_version_specific_data: Option<u64>,
1033
1034 max_soft_bundle_size: Option<u64>,
1037
1038 bridge_should_try_to_finalize_committee: Option<bool>,
1042
1043 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1047
1048 max_committee_members_count: Option<u64>,
1052
1053 consensus_gc_depth: Option<u32>,
1056}
1057
1058impl ProtocolConfig {
1060 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1073 self.feature_flags
1074 .disable_invariant_violation_check_in_swap_loc
1075 }
1076
1077 pub fn no_extraneous_module_bytes(&self) -> bool {
1078 self.feature_flags.no_extraneous_module_bytes
1079 }
1080
1081 pub fn zklogin_auth(&self) -> bool {
1082 self.feature_flags.zklogin_auth
1083 }
1084
1085 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1086 self.feature_flags.consensus_transaction_ordering
1087 }
1088
1089 pub fn enable_jwk_consensus_updates(&self) -> bool {
1090 self.feature_flags.enable_jwk_consensus_updates
1091 }
1092
1093 pub fn create_authenticator_state_in_genesis(&self) -> bool {
1095 self.enable_jwk_consensus_updates()
1096 }
1097
1098 pub fn dkg_version(&self) -> u64 {
1099 self.random_beacon_dkg_version.unwrap_or(1)
1101 }
1102
1103 pub fn enable_bridge(&self) -> bool {
1104 self.feature_flags.bridge
1105 }
1106
1107 pub fn should_try_to_finalize_bridge_committee(&self) -> bool {
1108 if !self.enable_bridge() {
1109 return false;
1110 }
1111 self.bridge_should_try_to_finalize_committee.unwrap_or(true)
1113 }
1114
1115 pub fn accept_zklogin_in_multisig(&self) -> bool {
1116 self.feature_flags.accept_zklogin_in_multisig
1117 }
1118
1119 pub fn zklogin_max_epoch_upper_bound_delta(&self) -> Option<u64> {
1120 self.feature_flags.zklogin_max_epoch_upper_bound_delta
1121 }
1122
1123 pub fn hardened_otw_check(&self) -> bool {
1124 self.feature_flags.hardened_otw_check
1125 }
1126
1127 pub fn enable_poseidon(&self) -> bool {
1128 self.feature_flags.enable_poseidon
1129 }
1130
1131 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1132 self.feature_flags.enable_group_ops_native_function_msm
1133 }
1134
1135 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1136 self.feature_flags.per_object_congestion_control_mode
1137 }
1138
1139 pub fn consensus_choice(&self) -> ConsensusChoice {
1140 self.feature_flags.consensus_choice
1141 }
1142
1143 pub fn consensus_network(&self) -> ConsensusNetwork {
1144 self.feature_flags.consensus_network
1145 }
1146
1147 pub fn enable_vdf(&self) -> bool {
1148 self.feature_flags.enable_vdf
1149 }
1150
1151 pub fn passkey_auth(&self) -> bool {
1152 self.feature_flags.passkey_auth
1153 }
1154
1155 pub fn max_transaction_size_bytes(&self) -> u64 {
1156 self.consensus_max_transaction_size_bytes
1158 .unwrap_or(256 * 1024)
1159 }
1160
1161 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1162 self.consensus_max_transactions_in_block_bytes
1164 .unwrap_or(512 * 1024)
1165 }
1166
1167 pub fn max_num_transactions_in_block(&self) -> u64 {
1168 self.consensus_max_num_transactions_in_block.unwrap_or(500)
1170 }
1171
1172 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1173 self.feature_flags.rethrow_serialization_type_layout_errors
1174 }
1175
1176 pub fn relocate_event_module(&self) -> bool {
1177 self.feature_flags.relocate_event_module
1178 }
1179
1180 pub fn protocol_defined_base_fee(&self) -> bool {
1181 self.feature_flags.protocol_defined_base_fee
1182 }
1183
1184 pub fn uncompressed_g1_group_elements(&self) -> bool {
1185 self.feature_flags.uncompressed_g1_group_elements
1186 }
1187
1188 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1189 self.feature_flags
1190 .disallow_new_modules_in_deps_only_packages
1191 }
1192
1193 pub fn native_charging_v2(&self) -> bool {
1194 self.feature_flags.native_charging_v2
1195 }
1196
1197 pub fn consensus_round_prober(&self) -> bool {
1198 self.feature_flags.consensus_round_prober
1199 }
1200
1201 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1202 self.feature_flags
1203 .consensus_distributed_vote_scoring_strategy
1204 }
1205
1206 pub fn gc_depth(&self) -> u32 {
1207 if cfg!(msim) {
1208 min(5, self.consensus_gc_depth.unwrap_or(0))
1210 } else {
1211 self.consensus_gc_depth.unwrap_or(0)
1212 }
1213 }
1214
1215 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1216 let res = self.feature_flags.consensus_linearize_subdag_v2;
1217 assert!(
1218 !res || self.gc_depth() > 0,
1219 "The consensus linearize sub dag V2 requires GC to be enabled"
1220 );
1221 res
1222 }
1223
1224 pub fn variant_nodes(&self) -> bool {
1225 self.feature_flags.variant_nodes
1226 }
1227
1228 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1229 self.feature_flags.consensus_smart_ancestor_selection
1230 }
1231
1232 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1233 self.feature_flags
1234 .consensus_round_prober_probe_accepted_rounds
1235 }
1236
1237 pub fn consensus_zstd_compression(&self) -> bool {
1238 self.feature_flags.consensus_zstd_compression
1239 }
1240
1241 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1242 self.feature_flags
1243 .congestion_control_min_free_execution_slot
1244 }
1245}
1246
1247#[cfg(not(msim))]
1248static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1249
1250#[cfg(msim)]
1252thread_local! {
1253 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1254}
1255
1256impl ProtocolConfig {
1258 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1261 assert!(
1263 version >= ProtocolVersion::MIN,
1264 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1265 version,
1266 ProtocolVersion::MIN.0,
1267 );
1268 assert!(
1269 version <= ProtocolVersion::MAX_ALLOWED,
1270 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1271 version,
1272 ProtocolVersion::MAX_ALLOWED.0,
1273 );
1274
1275 let mut ret = Self::get_for_version_impl(version, chain);
1276 ret.version = version;
1277
1278 ret = CONFIG_OVERRIDE.with(|ovr| {
1279 if let Some(override_fn) = &*ovr.borrow() {
1280 warn!(
1281 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1282 );
1283 override_fn(version, ret)
1284 } else {
1285 ret
1286 }
1287 });
1288
1289 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1290 warn!(
1291 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1292 );
1293 let overrides: ProtocolConfigOptional =
1294 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1295 .expect("failed to parse ProtocolConfig override env variables");
1296 overrides.apply_to(&mut ret);
1297 }
1298
1299 ret
1300 }
1301
1302 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1305 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1306 let mut ret = Self::get_for_version_impl(version, chain);
1307 ret.version = version;
1308 Some(ret)
1309 } else {
1310 None
1311 }
1312 }
1313
1314 #[cfg(not(msim))]
1315 pub fn poison_get_for_min_version() {
1316 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1317 }
1318
1319 #[cfg(not(msim))]
1320 fn load_poison_get_for_min_version() -> bool {
1321 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1322 }
1323
1324 #[cfg(msim)]
1325 pub fn poison_get_for_min_version() {
1326 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1327 }
1328
1329 #[cfg(msim)]
1330 fn load_poison_get_for_min_version() -> bool {
1331 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1332 }
1333
1334 pub fn convert_type_argument_error(&self) -> bool {
1335 self.feature_flags.convert_type_argument_error
1336 }
1337
1338 pub fn get_for_min_version() -> Self {
1342 if Self::load_poison_get_for_min_version() {
1343 panic!("get_for_min_version called on validator");
1344 }
1345 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1346 }
1347
1348 #[expect(non_snake_case)]
1359 pub fn get_for_max_version_UNSAFE() -> Self {
1360 if Self::load_poison_get_for_min_version() {
1361 panic!("get_for_max_version_UNSAFE called on validator");
1362 }
1363 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1364 }
1365
1366 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1367 #[cfg(msim)]
1368 {
1369 if version > ProtocolVersion::MAX {
1371 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1372 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1373 return config;
1374 }
1375 }
1376
1377 let mut cfg = Self {
1381 version,
1382
1383 feature_flags: Default::default(),
1384
1385 max_tx_size_bytes: Some(128 * 1024),
1386 max_input_objects: Some(2048),
1389 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1390 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1391 max_gas_payment_objects: Some(256),
1392 max_modules_in_publish: Some(64),
1393 max_package_dependencies: Some(32),
1394 max_arguments: Some(512),
1395 max_type_arguments: Some(16),
1396 max_type_argument_depth: Some(16),
1397 max_pure_argument_size: Some(16 * 1024),
1398 max_programmable_tx_commands: Some(1024),
1399 move_binary_format_version: Some(7),
1400 min_move_binary_format_version: Some(6),
1401 binary_module_handles: Some(100),
1402 binary_struct_handles: Some(300),
1403 binary_function_handles: Some(1500),
1404 binary_function_instantiations: Some(750),
1405 binary_signatures: Some(1000),
1406 binary_constant_pool: Some(4000),
1407 binary_identifiers: Some(10000),
1408 binary_address_identifiers: Some(100),
1409 binary_struct_defs: Some(200),
1410 binary_struct_def_instantiations: Some(100),
1411 binary_function_defs: Some(1000),
1412 binary_field_handles: Some(500),
1413 binary_field_instantiations: Some(250),
1414 binary_friend_decls: Some(100),
1415 binary_enum_defs: None,
1416 binary_enum_def_instantiations: None,
1417 binary_variant_handles: None,
1418 binary_variant_instantiation_handles: None,
1419 max_move_object_size: Some(250 * 1024),
1420 max_move_package_size: Some(100 * 1024),
1421 max_publish_or_upgrade_per_ptb: Some(5),
1422 max_tx_gas: Some(50_000_000_000),
1424 max_gas_price: Some(100_000),
1425 max_gas_computation_bucket: Some(5_000_000),
1426 max_loop_depth: Some(5),
1427 max_generic_instantiation_length: Some(32),
1428 max_function_parameters: Some(128),
1429 max_basic_blocks: Some(1024),
1430 max_value_stack_size: Some(1024),
1431 max_type_nodes: Some(256),
1432 max_push_size: Some(10000),
1433 max_struct_definitions: Some(200),
1434 max_function_definitions: Some(1000),
1435 max_fields_in_struct: Some(32),
1436 max_dependency_depth: Some(100),
1437 max_num_event_emit: Some(1024),
1438 max_num_new_move_object_ids: Some(2048),
1439 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1440 max_num_deleted_move_object_ids: Some(2048),
1441 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1442 max_num_transferred_move_object_ids: Some(2048),
1443 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1444 max_event_emit_size: Some(250 * 1024),
1445 max_move_vector_len: Some(256 * 1024),
1446 max_type_to_layout_nodes: None,
1447 max_ptb_value_size: None,
1448
1449 max_back_edges_per_function: Some(10_000),
1450 max_back_edges_per_module: Some(10_000),
1451
1452 max_verifier_meter_ticks_per_function: Some(16_000_000),
1453
1454 max_meter_ticks_per_module: Some(16_000_000),
1455 max_meter_ticks_per_package: Some(16_000_000),
1456
1457 object_runtime_max_num_cached_objects: Some(1000),
1458 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
1459 object_runtime_max_num_store_entries: Some(1000),
1460 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
1461 base_tx_cost_fixed: Some(1_000),
1463 package_publish_cost_fixed: Some(1_000),
1464 base_tx_cost_per_byte: Some(0),
1465 package_publish_cost_per_byte: Some(80),
1466 obj_access_cost_read_per_byte: Some(15),
1467 obj_access_cost_mutate_per_byte: Some(40),
1468 obj_access_cost_delete_per_byte: Some(40),
1469 obj_access_cost_verify_per_byte: Some(200),
1470 obj_data_cost_refundable: Some(100),
1471 obj_metadata_cost_non_refundable: Some(50),
1472 gas_model_version: Some(1),
1473 storage_rebate_rate: Some(10000),
1474 reward_slashing_rate: Some(10000),
1476 storage_gas_price: Some(76),
1477 base_gas_price: None,
1478 validator_target_reward: Some(767_000 * 1_000_000_000),
1481 max_transactions_per_checkpoint: Some(10_000),
1482 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
1483
1484 buffer_stake_for_protocol_upgrade_bps: Some(5000),
1486
1487 address_from_bytes_cost_base: Some(52),
1491 address_to_u256_cost_base: Some(52),
1493 address_from_u256_cost_base: Some(52),
1495
1496 config_read_setting_impl_cost_base: Some(100),
1499 config_read_setting_impl_cost_per_byte: Some(40),
1500
1501 dynamic_field_hash_type_and_key_cost_base: Some(100),
1505 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
1506 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
1507 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
1508 dynamic_field_add_child_object_cost_base: Some(100),
1511 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
1512 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
1513 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
1514 dynamic_field_borrow_child_object_cost_base: Some(100),
1517 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
1518 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
1519 dynamic_field_remove_child_object_cost_base: Some(100),
1522 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
1523 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
1524 dynamic_field_has_child_object_cost_base: Some(100),
1527 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
1530 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
1531 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
1532
1533 event_emit_cost_base: Some(52),
1536 event_emit_value_size_derivation_cost_per_byte: Some(2),
1537 event_emit_tag_size_derivation_cost_per_byte: Some(5),
1538 event_emit_output_cost_per_byte: Some(10),
1539
1540 object_borrow_uid_cost_base: Some(52),
1543 object_delete_impl_cost_base: Some(52),
1545 object_record_new_uid_cost_base: Some(52),
1547
1548 transfer_transfer_internal_cost_base: Some(52),
1552 transfer_freeze_object_cost_base: Some(52),
1554 transfer_share_object_cost_base: Some(52),
1556 transfer_receive_object_cost_base: Some(52),
1557
1558 tx_context_derive_id_cost_base: Some(52),
1562
1563 types_is_one_time_witness_cost_base: Some(52),
1566 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
1567 types_is_one_time_witness_type_cost_per_byte: Some(2),
1568
1569 validator_validate_metadata_cost_base: Some(52),
1573 validator_validate_metadata_data_cost_per_byte: Some(2),
1574
1575 crypto_invalid_arguments_cost: Some(100),
1577 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
1579 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
1580 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
1581
1582 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
1584 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
1585 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
1586
1587 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
1589 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1590 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1591 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
1592 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1593 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
1594
1595 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
1597
1598 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
1600 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
1601 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
1602 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
1603 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
1604 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
1605
1606 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
1608 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1609 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1610 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
1611 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1612 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
1613
1614 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
1616 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
1617 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
1618 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
1619 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
1620 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
1621
1622 ecvrf_ecvrf_verify_cost_base: Some(52),
1624 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
1625 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
1626
1627 ed25519_ed25519_verify_cost_base: Some(52),
1629 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
1630 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
1631
1632 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
1634 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
1635
1636 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
1638 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
1639 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
1640 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
1641 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
1642
1643 hash_blake2b256_cost_base: Some(52),
1645 hash_blake2b256_data_cost_per_byte: Some(2),
1646 hash_blake2b256_data_cost_per_block: Some(2),
1647 hash_keccak256_cost_base: Some(52),
1649 hash_keccak256_data_cost_per_byte: Some(2),
1650 hash_keccak256_data_cost_per_block: Some(2),
1651
1652 poseidon_bn254_cost_base: None,
1653 poseidon_bn254_cost_per_block: None,
1654
1655 hmac_hmac_sha3_256_cost_base: Some(52),
1657 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
1658 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
1659
1660 group_ops_bls12381_decode_scalar_cost: Some(52),
1662 group_ops_bls12381_decode_g1_cost: Some(52),
1663 group_ops_bls12381_decode_g2_cost: Some(52),
1664 group_ops_bls12381_decode_gt_cost: Some(52),
1665 group_ops_bls12381_scalar_add_cost: Some(52),
1666 group_ops_bls12381_g1_add_cost: Some(52),
1667 group_ops_bls12381_g2_add_cost: Some(52),
1668 group_ops_bls12381_gt_add_cost: Some(52),
1669 group_ops_bls12381_scalar_sub_cost: Some(52),
1670 group_ops_bls12381_g1_sub_cost: Some(52),
1671 group_ops_bls12381_g2_sub_cost: Some(52),
1672 group_ops_bls12381_gt_sub_cost: Some(52),
1673 group_ops_bls12381_scalar_mul_cost: Some(52),
1674 group_ops_bls12381_g1_mul_cost: Some(52),
1675 group_ops_bls12381_g2_mul_cost: Some(52),
1676 group_ops_bls12381_gt_mul_cost: Some(52),
1677 group_ops_bls12381_scalar_div_cost: Some(52),
1678 group_ops_bls12381_g1_div_cost: Some(52),
1679 group_ops_bls12381_g2_div_cost: Some(52),
1680 group_ops_bls12381_gt_div_cost: Some(52),
1681 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
1682 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
1683 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
1684 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
1685 group_ops_bls12381_g1_msm_base_cost: Some(52),
1686 group_ops_bls12381_g2_msm_base_cost: Some(52),
1687 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
1688 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
1689 group_ops_bls12381_msm_max_len: Some(32),
1690 group_ops_bls12381_pairing_cost: Some(52),
1691 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
1692 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
1693 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
1694 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
1695 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
1696
1697 check_zklogin_id_cost_base: Some(200),
1699 check_zklogin_issuer_cost_base: Some(200),
1701
1702 vdf_verify_vdf_cost: None,
1703 vdf_hash_to_input_cost: None,
1704
1705 bcs_per_byte_serialized_cost: Some(2),
1706 bcs_legacy_min_output_size_cost: Some(1),
1707 bcs_failure_cost: Some(52),
1708 hash_sha2_256_base_cost: Some(52),
1709 hash_sha2_256_per_byte_cost: Some(2),
1710 hash_sha2_256_legacy_min_input_len_cost: Some(1),
1711 hash_sha3_256_base_cost: Some(52),
1712 hash_sha3_256_per_byte_cost: Some(2),
1713 hash_sha3_256_legacy_min_input_len_cost: Some(1),
1714 type_name_get_base_cost: Some(52),
1715 type_name_get_per_byte_cost: Some(2),
1716 string_check_utf8_base_cost: Some(52),
1717 string_check_utf8_per_byte_cost: Some(2),
1718 string_is_char_boundary_base_cost: Some(52),
1719 string_sub_string_base_cost: Some(52),
1720 string_sub_string_per_byte_cost: Some(2),
1721 string_index_of_base_cost: Some(52),
1722 string_index_of_per_byte_pattern_cost: Some(2),
1723 string_index_of_per_byte_searched_cost: Some(2),
1724 vector_empty_base_cost: Some(52),
1725 vector_length_base_cost: Some(52),
1726 vector_push_back_base_cost: Some(52),
1727 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
1728 vector_borrow_base_cost: Some(52),
1729 vector_pop_back_base_cost: Some(52),
1730 vector_destroy_empty_base_cost: Some(52),
1731 vector_swap_base_cost: Some(52),
1732 debug_print_base_cost: Some(52),
1733 debug_print_stack_trace_base_cost: Some(52),
1734
1735 max_size_written_objects: Some(5 * 1000 * 1000),
1736 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
1739
1740 max_move_identifier_len: Some(128),
1742 max_move_value_depth: Some(128),
1743 max_move_enum_variants: None,
1744
1745 gas_rounding_step: Some(1_000),
1746
1747 execution_version: Some(1),
1748
1749 max_event_emit_size_total: Some(
1752 256 * 250 * 1024, ),
1754
1755 consensus_bad_nodes_stake_threshold: Some(20),
1762
1763 max_jwk_votes_per_validator_per_epoch: Some(240),
1765
1766 max_age_of_jwk_in_epochs: Some(1),
1767
1768 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
1772
1773 random_beacon_reduction_allowed_delta: Some(800),
1774
1775 random_beacon_reduction_lower_bound: Some(1000),
1776 random_beacon_dkg_timeout_round: Some(3000),
1777 random_beacon_min_round_interval_ms: Some(500),
1778
1779 random_beacon_dkg_version: Some(1),
1780
1781 consensus_max_num_transactions_in_block: Some(512),
1785
1786 max_deferral_rounds_for_congestion_control: Some(10),
1787
1788 min_checkpoint_interval_ms: Some(200),
1789
1790 checkpoint_summary_version_specific_data: Some(1),
1791
1792 max_soft_bundle_size: Some(5),
1793
1794 bridge_should_try_to_finalize_committee: None,
1795
1796 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
1797
1798 max_committee_members_count: None,
1799
1800 consensus_gc_depth: None,
1801 };
1804
1805 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
1806
1807 {
1809 cfg.feature_flags
1810 .disable_invariant_violation_check_in_swap_loc = true;
1811 cfg.feature_flags.no_extraneous_module_bytes = true;
1812 cfg.feature_flags.hardened_otw_check = true;
1813 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
1814 }
1815
1816 {
1818 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
1819 }
1820
1821 cfg.feature_flags.consensus_choice = ConsensusChoice::Mysticeti;
1823 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
1825
1826 cfg.feature_flags.per_object_congestion_control_mode =
1827 PerObjectCongestionControlMode::TotalTxCount;
1828
1829 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
1831
1832 if chain != Chain::Mainnet && chain != Chain::Testnet {
1834 cfg.feature_flags.enable_poseidon = true;
1835 cfg.poseidon_bn254_cost_base = Some(260);
1836 cfg.poseidon_bn254_cost_per_block = Some(10);
1837
1838 cfg.feature_flags.enable_group_ops_native_function_msm = true;
1839
1840 cfg.feature_flags.enable_vdf = true;
1841 cfg.vdf_verify_vdf_cost = Some(1500);
1844 cfg.vdf_hash_to_input_cost = Some(100);
1845
1846 cfg.feature_flags.passkey_auth = true;
1847 }
1848
1849 for cur in 2..=version.0 {
1850 match cur {
1851 1 => unreachable!(),
1852 2 => {}
1854 3 => {
1855 cfg.feature_flags.relocate_event_module = true;
1856 }
1857 4 => {
1858 cfg.max_type_to_layout_nodes = Some(512);
1859 }
1860 5 => {
1861 cfg.feature_flags.protocol_defined_base_fee = true;
1862 cfg.base_gas_price = Some(1000);
1863
1864 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
1865 cfg.feature_flags.convert_type_argument_error = true;
1866 cfg.feature_flags.native_charging_v2 = true;
1867
1868 if chain != Chain::Mainnet && chain != Chain::Testnet {
1869 cfg.feature_flags.uncompressed_g1_group_elements = true;
1870 }
1871
1872 cfg.gas_model_version = Some(2);
1873
1874 cfg.poseidon_bn254_cost_per_block = Some(388);
1875
1876 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
1877 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
1878 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
1879 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
1880 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
1881 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
1882 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
1883 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
1884
1885 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
1887 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
1888 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
1889 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
1890
1891 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
1892 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
1893 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
1894 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
1895 Some(8213);
1896 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
1897 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
1898 Some(9484);
1899
1900 cfg.hash_keccak256_cost_base = Some(10);
1901 cfg.hash_blake2b256_cost_base = Some(10);
1902
1903 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
1905 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
1906 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
1907 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
1908
1909 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
1910 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
1911 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
1912 cfg.group_ops_bls12381_gt_add_cost = Some(188);
1913
1914 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
1915 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
1916 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
1917 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
1918
1919 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
1920 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
1921 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
1922 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
1923
1924 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
1925 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
1926 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
1927 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
1928
1929 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
1930 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
1931
1932 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
1933 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
1934 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
1935 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
1936
1937 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
1938 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
1939 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
1940 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
1941 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
1942
1943 cfg.group_ops_bls12381_pairing_cost = Some(26897);
1944
1945 cfg.validator_validate_metadata_cost_base = Some(20000);
1946
1947 cfg.max_committee_members_count = Some(50);
1948 }
1949 6 => {
1950 cfg.max_ptb_value_size = Some(1024 * 1024);
1951 }
1952 7 => {
1953 cfg.feature_flags.variant_nodes = true;
1957
1958 if chain != Chain::Mainnet {
1959 cfg.feature_flags.consensus_round_prober = true;
1961 cfg.feature_flags
1963 .consensus_distributed_vote_scoring_strategy = true;
1964 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
1965 cfg.feature_flags.consensus_smart_ancestor_selection = true;
1967 cfg.feature_flags
1969 .consensus_round_prober_probe_accepted_rounds = true;
1970 cfg.feature_flags.consensus_zstd_compression = true;
1972 cfg.consensus_gc_depth = Some(60);
1976 }
1977 if chain != Chain::Testnet && chain != Chain::Mainnet {
1980 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
1981 }
1982 }
1983 _ => panic!("unsupported version {:?}", version),
1994 }
1995 }
1996 cfg
1997 }
1998
1999 pub fn verifier_config(&self, signing_limits: Option<(usize, usize)>) -> VerifierConfig {
2003 let (max_back_edges_per_function, max_back_edges_per_module) = if let Some((
2004 max_back_edges_per_function,
2005 max_back_edges_per_module,
2006 )) = signing_limits
2007 {
2008 (
2009 Some(max_back_edges_per_function),
2010 Some(max_back_edges_per_module),
2011 )
2012 } else {
2013 (None, None)
2014 };
2015
2016 VerifierConfig {
2017 max_loop_depth: Some(self.max_loop_depth() as usize),
2018 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2019 max_function_parameters: Some(self.max_function_parameters() as usize),
2020 max_basic_blocks: Some(self.max_basic_blocks() as usize),
2021 max_value_stack_size: self.max_value_stack_size() as usize,
2022 max_type_nodes: Some(self.max_type_nodes() as usize),
2023 max_push_size: Some(self.max_push_size() as usize),
2024 max_dependency_depth: Some(self.max_dependency_depth() as usize),
2025 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2026 max_function_definitions: Some(self.max_function_definitions() as usize),
2027 max_data_definitions: Some(self.max_struct_definitions() as usize),
2028 max_constant_vector_len: Some(self.max_move_vector_len()),
2029 max_back_edges_per_function,
2030 max_back_edges_per_module,
2031 max_basic_blocks_in_script: None,
2032 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
2036 max_variants_in_enum: self.max_move_enum_variants_as_option(),
2037 }
2038 }
2039
2040 pub fn apply_overrides_for_testing(
2045 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
2046 ) -> OverrideGuard {
2047 CONFIG_OVERRIDE.with(|ovr| {
2048 let mut cur = ovr.borrow_mut();
2049 assert!(cur.is_none(), "config override already present");
2050 *cur = Some(Box::new(override_fn));
2051 OverrideGuard
2052 })
2053 }
2054}
2055
2056impl ProtocolConfig {
2061 pub fn set_zklogin_auth_for_testing(&mut self, val: bool) {
2062 self.feature_flags.zklogin_auth = val
2063 }
2064 pub fn set_enable_jwk_consensus_updates_for_testing(&mut self, val: bool) {
2065 self.feature_flags.enable_jwk_consensus_updates = val
2066 }
2067
2068 pub fn set_accept_zklogin_in_multisig_for_testing(&mut self, val: bool) {
2069 self.feature_flags.accept_zklogin_in_multisig = val
2070 }
2071
2072 pub fn set_per_object_congestion_control_mode_for_testing(
2073 &mut self,
2074 val: PerObjectCongestionControlMode,
2075 ) {
2076 self.feature_flags.per_object_congestion_control_mode = val;
2077 }
2078
2079 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
2080 self.feature_flags.consensus_choice = val;
2081 }
2082
2083 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
2084 self.feature_flags.consensus_network = val;
2085 }
2086
2087 pub fn set_zklogin_max_epoch_upper_bound_delta_for_testing(&mut self, val: Option<u64>) {
2088 self.feature_flags.zklogin_max_epoch_upper_bound_delta = val
2089 }
2090 pub fn set_disable_bridge_for_testing(&mut self) {
2091 self.feature_flags.bridge = false
2092 }
2093
2094 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
2095 self.feature_flags.passkey_auth = val
2096 }
2097
2098 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
2099 self.feature_flags
2100 .disallow_new_modules_in_deps_only_packages = val;
2101 }
2102
2103 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
2104 self.feature_flags.consensus_round_prober = val;
2105 }
2106
2107 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
2108 self.feature_flags
2109 .consensus_distributed_vote_scoring_strategy = val;
2110 }
2111
2112 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
2113 self.consensus_gc_depth = Some(val);
2114 }
2115
2116 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
2117 self.feature_flags.consensus_linearize_subdag_v2 = val;
2118 }
2119
2120 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
2121 self.feature_flags
2122 .consensus_round_prober_probe_accepted_rounds = val;
2123 }
2124}
2125
2126type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
2127
2128thread_local! {
2129 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
2130}
2131
2132#[must_use]
2133pub struct OverrideGuard;
2134
2135impl Drop for OverrideGuard {
2136 fn drop(&mut self) {
2137 info!("restoring override fn");
2138 CONFIG_OVERRIDE.with(|ovr| {
2139 *ovr.borrow_mut() = None;
2140 });
2141 }
2142}
2143
2144#[derive(PartialEq, Eq)]
2148pub enum LimitThresholdCrossed {
2149 None,
2150 Soft(u128, u128),
2151 Hard(u128, u128),
2152}
2153
2154pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
2157 x: T,
2158 soft_limit: U,
2159 hard_limit: V,
2160) -> LimitThresholdCrossed {
2161 let x: V = x.into();
2162 let soft_limit: V = soft_limit.into();
2163
2164 debug_assert!(soft_limit <= hard_limit);
2165
2166 if x >= hard_limit {
2169 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
2170 } else if x < soft_limit {
2171 LimitThresholdCrossed::None
2172 } else {
2173 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
2174 }
2175}
2176
2177#[macro_export]
2178macro_rules! check_limit {
2179 ($x:expr, $hard:expr) => {
2180 check_limit!($x, $hard, $hard)
2181 };
2182 ($x:expr, $soft:expr, $hard:expr) => {
2183 check_limit_in_range($x as u64, $soft, $hard)
2184 };
2185}
2186
2187#[macro_export]
2191macro_rules! check_limit_by_meter {
2192 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
2193 let (h, metered_str) = if $is_metered {
2195 ($metered_limit, "metered")
2196 } else {
2197 ($unmetered_hard_limit, "unmetered")
2199 };
2200 use iota_protocol_config::check_limit_in_range;
2201 let result = check_limit_in_range($x as u64, $metered_limit, h);
2202 match result {
2203 LimitThresholdCrossed::None => {}
2204 LimitThresholdCrossed::Soft(_, _) => {
2205 $metric.with_label_values(&[metered_str, "soft"]).inc();
2206 }
2207 LimitThresholdCrossed::Hard(_, _) => {
2208 $metric.with_label_values(&[metered_str, "hard"]).inc();
2209 }
2210 };
2211 result
2212 }};
2213}
2214
2215#[cfg(all(test, not(msim)))]
2216mod test {
2217 use insta::assert_yaml_snapshot;
2218
2219 use super::*;
2220
2221 #[test]
2222 fn snapshot_tests() {
2223 println!("\n============================================================================");
2224 println!("! !");
2225 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
2226 println!("! !");
2227 println!("============================================================================\n");
2228 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
2229 let chain_str = match chain_id {
2234 Chain::Unknown => "".to_string(),
2235 _ => format!("{:?}_", chain_id),
2236 };
2237 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
2238 let cur = ProtocolVersion::new(i);
2239 assert_yaml_snapshot!(
2240 format!("{}version_{}", chain_str, cur.as_u64()),
2241 ProtocolConfig::get_for_version(cur, *chain_id)
2242 );
2243 }
2244 }
2245 }
2246
2247 #[test]
2248 fn test_getters() {
2249 let prot: ProtocolConfig =
2250 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2251 assert_eq!(
2252 prot.max_arguments(),
2253 prot.max_arguments_as_option().unwrap()
2254 );
2255 }
2256
2257 #[test]
2258 fn test_setters() {
2259 let mut prot: ProtocolConfig =
2260 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2261 prot.set_max_arguments_for_testing(123);
2262 assert_eq!(prot.max_arguments(), 123);
2263
2264 prot.set_max_arguments_from_str_for_testing("321".to_string());
2265 assert_eq!(prot.max_arguments(), 321);
2266
2267 prot.disable_max_arguments_for_testing();
2268 assert_eq!(prot.max_arguments_as_option(), None);
2269
2270 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
2271 assert_eq!(prot.max_arguments(), 456);
2272 }
2273
2274 #[test]
2275 fn lookup_by_string_test() {
2276 let prot: ProtocolConfig =
2277 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2278 assert!(prot.lookup_attr("some random string".to_string()).is_none());
2280
2281 assert!(
2282 prot.lookup_attr("max_arguments".to_string())
2283 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
2284 );
2285
2286 assert!(
2288 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2289 .is_none()
2290 );
2291 assert!(
2292 prot.attr_map()
2293 .get("poseidon_bn254_cost_base")
2294 .unwrap()
2295 .is_none()
2296 );
2297
2298 let prot: ProtocolConfig =
2300 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2301
2302 assert!(
2303 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2304 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2305 );
2306 assert!(
2307 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
2308 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2309 );
2310
2311 let prot: ProtocolConfig =
2313 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2314 assert!(
2316 prot.feature_flags
2317 .lookup_attr("some random string".to_owned())
2318 .is_none()
2319 );
2320 assert!(
2321 !prot
2322 .feature_flags
2323 .attr_map()
2324 .contains_key("some random string")
2325 );
2326
2327 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
2329 assert!(
2330 prot.feature_flags
2331 .attr_map()
2332 .get("enable_poseidon")
2333 .unwrap()
2334 == &false
2335 );
2336 let prot: ProtocolConfig =
2337 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2338 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
2340 assert!(
2341 prot.feature_flags
2342 .attr_map()
2343 .get("enable_poseidon")
2344 .unwrap()
2345 == &true
2346 );
2347 }
2348
2349 #[test]
2350 fn limit_range_fn_test() {
2351 let low = 100u32;
2352 let high = 10000u64;
2353
2354 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
2355 assert!(matches!(
2356 check_limit!(255u16, low, high),
2357 LimitThresholdCrossed::Soft(255u128, 100)
2358 ));
2359 assert!(matches!(
2366 check_limit!(2550000u64, low, high),
2367 LimitThresholdCrossed::Hard(2550000, 10000)
2368 ));
2369
2370 assert!(matches!(
2371 check_limit!(2550000u64, high, high),
2372 LimitThresholdCrossed::Hard(2550000, 10000)
2373 ));
2374
2375 assert!(matches!(
2376 check_limit!(1u8, high),
2377 LimitThresholdCrossed::None
2378 ));
2379
2380 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
2381
2382 assert!(matches!(
2383 check_limit!(2550000u64, high),
2384 LimitThresholdCrossed::Hard(2550000, 10000)
2385 ));
2386 }
2387}