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 = 9;
23
24#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
60pub struct ProtocolVersion(u64);
61
62impl ProtocolVersion {
63 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
69
70 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
71
72 #[cfg(not(msim))]
73 const MAX_ALLOWED: Self = Self::MAX;
74
75 #[cfg(msim)]
78 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
79
80 pub fn new(v: u64) -> Self {
81 Self(v)
82 }
83
84 pub const fn as_u64(&self) -> u64 {
85 self.0
86 }
87
88 pub fn max() -> Self {
91 Self::MAX
92 }
93}
94
95impl From<u64> for ProtocolVersion {
96 fn from(v: u64) -> Self {
97 Self::new(v)
98 }
99}
100
101impl std::ops::Sub<u64> for ProtocolVersion {
102 type Output = Self;
103 fn sub(self, rhs: u64) -> Self::Output {
104 Self::new(self.0 - rhs)
105 }
106}
107
108impl std::ops::Add<u64> for ProtocolVersion {
109 type Output = Self;
110 fn add(self, rhs: u64) -> Self::Output {
111 Self::new(self.0 + rhs)
112 }
113}
114
115#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum)]
116pub enum Chain {
117 Mainnet,
118 Testnet,
119 Unknown,
120}
121
122impl Default for Chain {
123 fn default() -> Self {
124 Self::Unknown
125 }
126}
127
128impl Chain {
129 pub fn as_str(self) -> &'static str {
130 match self {
131 Chain::Mainnet => "mainnet",
132 Chain::Testnet => "testnet",
133 Chain::Unknown => "unknown",
134 }
135 }
136}
137
138pub struct Error(pub String);
139
140#[derive(Default, Clone, Serialize, Deserialize, Debug, ProtocolConfigFeatureFlagsGetters)]
144struct FeatureFlags {
145 #[serde(skip_serializing_if = "is_true")]
151 disable_invariant_violation_check_in_swap_loc: bool,
152
153 #[serde(skip_serializing_if = "is_true")]
156 no_extraneous_module_bytes: bool,
157
158 #[serde(skip_serializing_if = "is_false")]
160 zklogin_auth: bool,
161
162 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
164 consensus_transaction_ordering: ConsensusTransactionOrdering,
165
166 #[serde(skip_serializing_if = "is_false")]
167 enable_jwk_consensus_updates: bool,
168
169 #[serde(skip_serializing_if = "is_false")]
171 accept_zklogin_in_multisig: bool,
172
173 #[serde(skip_serializing_if = "is_true")]
176 hardened_otw_check: bool,
177
178 #[serde(skip_serializing_if = "is_false")]
180 enable_poseidon: bool,
181
182 #[serde(skip_serializing_if = "is_false")]
184 enable_group_ops_native_function_msm: bool,
185
186 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
188 per_object_congestion_control_mode: PerObjectCongestionControlMode,
189
190 #[serde(skip_serializing_if = "ConsensusChoice::is_mysticeti")]
192 consensus_choice: ConsensusChoice,
193
194 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
196 consensus_network: ConsensusNetwork,
197
198 #[serde(skip_serializing_if = "Option::is_none")]
200 zklogin_max_epoch_upper_bound_delta: Option<u64>,
201
202 #[serde(skip_serializing_if = "is_false")]
204 enable_vdf: bool,
205
206 #[serde(skip_serializing_if = "is_false")]
208 passkey_auth: bool,
209
210 #[serde(skip_serializing_if = "is_true")]
213 rethrow_serialization_type_layout_errors: bool,
214
215 #[serde(skip_serializing_if = "is_false")]
217 relocate_event_module: bool,
218
219 #[serde(skip_serializing_if = "is_false")]
221 protocol_defined_base_fee: bool,
222
223 #[serde(skip_serializing_if = "is_false")]
225 uncompressed_g1_group_elements: bool,
226
227 #[serde(skip_serializing_if = "is_false")]
229 disallow_new_modules_in_deps_only_packages: bool,
230
231 #[serde(skip_serializing_if = "is_false")]
233 native_charging_v2: bool,
234
235 #[serde(skip_serializing_if = "is_false")]
237 convert_type_argument_error: bool,
238
239 #[serde(skip_serializing_if = "is_false")]
241 consensus_round_prober: bool,
242
243 #[serde(skip_serializing_if = "is_false")]
245 consensus_distributed_vote_scoring_strategy: bool,
246
247 #[serde(skip_serializing_if = "is_false")]
251 consensus_linearize_subdag_v2: bool,
252
253 #[serde(skip_serializing_if = "is_false")]
255 variant_nodes: bool,
256
257 #[serde(skip_serializing_if = "is_false")]
259 consensus_smart_ancestor_selection: bool,
260
261 #[serde(skip_serializing_if = "is_false")]
263 consensus_round_prober_probe_accepted_rounds: bool,
264
265 #[serde(skip_serializing_if = "is_false")]
267 consensus_zstd_compression: bool,
268
269 #[serde(skip_serializing_if = "is_false")]
272 congestion_control_min_free_execution_slot: bool,
273
274 #[serde(skip_serializing_if = "is_false")]
276 accept_passkey_in_multisig: bool,
277}
278
279fn is_true(b: &bool) -> bool {
280 *b
281}
282
283fn is_false(b: &bool) -> bool {
284 !b
285}
286
287#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
289pub enum ConsensusTransactionOrdering {
290 #[default]
293 None,
294 ByGasPrice,
296}
297
298impl ConsensusTransactionOrdering {
299 pub fn is_none(&self) -> bool {
300 matches!(self, ConsensusTransactionOrdering::None)
301 }
302}
303
304#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
306pub enum PerObjectCongestionControlMode {
307 #[default]
308 None, TotalGasBudget, TotalTxCount, }
312
313impl PerObjectCongestionControlMode {
314 pub fn is_none(&self) -> bool {
315 matches!(self, PerObjectCongestionControlMode::None)
316 }
317}
318
319#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
321pub enum ConsensusChoice {
322 #[default]
323 Mysticeti,
324}
325
326impl ConsensusChoice {
327 pub fn is_mysticeti(&self) -> bool {
328 matches!(self, ConsensusChoice::Mysticeti)
329 }
330}
331
332#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
334pub enum ConsensusNetwork {
335 #[default]
336 Tonic,
337}
338
339impl ConsensusNetwork {
340 pub fn is_tonic(&self) -> bool {
341 matches!(self, ConsensusNetwork::Tonic)
342 }
343}
344
345#[skip_serializing_none]
379#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
380pub struct ProtocolConfig {
381 pub version: ProtocolVersion,
382
383 feature_flags: FeatureFlags,
384
385 max_tx_size_bytes: Option<u64>,
390
391 max_input_objects: Option<u64>,
394
395 max_size_written_objects: Option<u64>,
400 max_size_written_objects_system_tx: Option<u64>,
404
405 max_serialized_tx_effects_size_bytes: Option<u64>,
407
408 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
410
411 max_gas_payment_objects: Option<u32>,
413
414 max_modules_in_publish: Option<u32>,
416
417 max_package_dependencies: Option<u32>,
419
420 max_arguments: Option<u32>,
423
424 max_type_arguments: Option<u32>,
426
427 max_type_argument_depth: Option<u32>,
429
430 max_pure_argument_size: Option<u32>,
432
433 max_programmable_tx_commands: Option<u32>,
435
436 move_binary_format_version: Option<u32>,
442 min_move_binary_format_version: Option<u32>,
443
444 binary_module_handles: Option<u16>,
446 binary_struct_handles: Option<u16>,
447 binary_function_handles: Option<u16>,
448 binary_function_instantiations: Option<u16>,
449 binary_signatures: Option<u16>,
450 binary_constant_pool: Option<u16>,
451 binary_identifiers: Option<u16>,
452 binary_address_identifiers: Option<u16>,
453 binary_struct_defs: Option<u16>,
454 binary_struct_def_instantiations: Option<u16>,
455 binary_function_defs: Option<u16>,
456 binary_field_handles: Option<u16>,
457 binary_field_instantiations: Option<u16>,
458 binary_friend_decls: Option<u16>,
459 binary_enum_defs: Option<u16>,
460 binary_enum_def_instantiations: Option<u16>,
461 binary_variant_handles: Option<u16>,
462 binary_variant_instantiation_handles: Option<u16>,
463
464 max_move_object_size: Option<u64>,
467
468 max_move_package_size: Option<u64>,
473
474 max_publish_or_upgrade_per_ptb: Option<u64>,
477
478 max_tx_gas: Option<u64>,
480
481 max_gas_price: Option<u64>,
484
485 max_gas_computation_bucket: Option<u64>,
488
489 gas_rounding_step: Option<u64>,
491
492 max_loop_depth: Option<u64>,
494
495 max_generic_instantiation_length: Option<u64>,
498
499 max_function_parameters: Option<u64>,
502
503 max_basic_blocks: Option<u64>,
506
507 max_value_stack_size: Option<u64>,
509
510 max_type_nodes: Option<u64>,
514
515 max_push_size: Option<u64>,
518
519 max_struct_definitions: Option<u64>,
522
523 max_function_definitions: Option<u64>,
526
527 max_fields_in_struct: Option<u64>,
530
531 max_dependency_depth: Option<u64>,
534
535 max_num_event_emit: Option<u64>,
538
539 max_num_new_move_object_ids: Option<u64>,
542
543 max_num_new_move_object_ids_system_tx: Option<u64>,
546
547 max_num_deleted_move_object_ids: Option<u64>,
550
551 max_num_deleted_move_object_ids_system_tx: Option<u64>,
554
555 max_num_transferred_move_object_ids: Option<u64>,
558
559 max_num_transferred_move_object_ids_system_tx: Option<u64>,
562
563 max_event_emit_size: Option<u64>,
565
566 max_event_emit_size_total: Option<u64>,
568
569 max_move_vector_len: Option<u64>,
572
573 max_move_identifier_len: Option<u64>,
576
577 max_move_value_depth: Option<u64>,
579
580 max_move_enum_variants: Option<u64>,
583
584 max_back_edges_per_function: Option<u64>,
587
588 max_back_edges_per_module: Option<u64>,
591
592 max_verifier_meter_ticks_per_function: Option<u64>,
595
596 max_meter_ticks_per_module: Option<u64>,
599
600 max_meter_ticks_per_package: Option<u64>,
603
604 object_runtime_max_num_cached_objects: Option<u64>,
611
612 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
615
616 object_runtime_max_num_store_entries: Option<u64>,
619
620 object_runtime_max_num_store_entries_system_tx: Option<u64>,
623
624 base_tx_cost_fixed: Option<u64>,
629
630 package_publish_cost_fixed: Option<u64>,
634
635 base_tx_cost_per_byte: Option<u64>,
639
640 package_publish_cost_per_byte: Option<u64>,
642
643 obj_access_cost_read_per_byte: Option<u64>,
645
646 obj_access_cost_mutate_per_byte: Option<u64>,
648
649 obj_access_cost_delete_per_byte: Option<u64>,
651
652 obj_access_cost_verify_per_byte: Option<u64>,
662
663 max_type_to_layout_nodes: Option<u64>,
665
666 max_ptb_value_size: Option<u64>,
668
669 gas_model_version: Option<u64>,
674
675 obj_data_cost_refundable: Option<u64>,
681
682 obj_metadata_cost_non_refundable: Option<u64>,
686
687 storage_rebate_rate: Option<u64>,
693
694 reward_slashing_rate: Option<u64>,
697
698 storage_gas_price: Option<u64>,
700
701 base_gas_price: Option<u64>,
703
704 validator_target_reward: Option<u64>,
706
707 max_transactions_per_checkpoint: Option<u64>,
714
715 max_checkpoint_size_bytes: Option<u64>,
719
720 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
726
727 address_from_bytes_cost_base: Option<u64>,
732 address_to_u256_cost_base: Option<u64>,
734 address_from_u256_cost_base: Option<u64>,
736
737 config_read_setting_impl_cost_base: Option<u64>,
742 config_read_setting_impl_cost_per_byte: Option<u64>,
743
744 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
748 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
749 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
750 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
751 dynamic_field_add_child_object_cost_base: Option<u64>,
754 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
755 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
756 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
757 dynamic_field_borrow_child_object_cost_base: Option<u64>,
760 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
761 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
762 dynamic_field_remove_child_object_cost_base: Option<u64>,
765 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
766 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
767 dynamic_field_has_child_object_cost_base: Option<u64>,
770 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
773 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
774 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
775
776 event_emit_cost_base: Option<u64>,
779 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
780 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
781 event_emit_output_cost_per_byte: Option<u64>,
782
783 object_borrow_uid_cost_base: Option<u64>,
786 object_delete_impl_cost_base: Option<u64>,
788 object_record_new_uid_cost_base: Option<u64>,
790
791 transfer_transfer_internal_cost_base: Option<u64>,
794 transfer_freeze_object_cost_base: Option<u64>,
796 transfer_share_object_cost_base: Option<u64>,
798 transfer_receive_object_cost_base: Option<u64>,
801
802 tx_context_derive_id_cost_base: Option<u64>,
805
806 types_is_one_time_witness_cost_base: Option<u64>,
809 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
810 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
811
812 validator_validate_metadata_cost_base: Option<u64>,
815 validator_validate_metadata_data_cost_per_byte: Option<u64>,
816
817 crypto_invalid_arguments_cost: Option<u64>,
819 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
821 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
822 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
823
824 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
826 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
827 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
828
829 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
831 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
832 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
833 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
834 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
835 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
836
837 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
839
840 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
842 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
843 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
844 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
845 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
846 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
847
848 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
850 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
851 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
852 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
853 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
854 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
855
856 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
858 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
859 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
860 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
861 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
862 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
863
864 ecvrf_ecvrf_verify_cost_base: Option<u64>,
866 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
867 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
868
869 ed25519_ed25519_verify_cost_base: Option<u64>,
871 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
872 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
873
874 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
876 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
877
878 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
880 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
881 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
882 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
883 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
884
885 hash_blake2b256_cost_base: Option<u64>,
887 hash_blake2b256_data_cost_per_byte: Option<u64>,
888 hash_blake2b256_data_cost_per_block: Option<u64>,
889
890 hash_keccak256_cost_base: Option<u64>,
892 hash_keccak256_data_cost_per_byte: Option<u64>,
893 hash_keccak256_data_cost_per_block: Option<u64>,
894
895 poseidon_bn254_cost_base: Option<u64>,
897 poseidon_bn254_cost_per_block: Option<u64>,
898
899 group_ops_bls12381_decode_scalar_cost: Option<u64>,
901 group_ops_bls12381_decode_g1_cost: Option<u64>,
902 group_ops_bls12381_decode_g2_cost: Option<u64>,
903 group_ops_bls12381_decode_gt_cost: Option<u64>,
904 group_ops_bls12381_scalar_add_cost: Option<u64>,
905 group_ops_bls12381_g1_add_cost: Option<u64>,
906 group_ops_bls12381_g2_add_cost: Option<u64>,
907 group_ops_bls12381_gt_add_cost: Option<u64>,
908 group_ops_bls12381_scalar_sub_cost: Option<u64>,
909 group_ops_bls12381_g1_sub_cost: Option<u64>,
910 group_ops_bls12381_g2_sub_cost: Option<u64>,
911 group_ops_bls12381_gt_sub_cost: Option<u64>,
912 group_ops_bls12381_scalar_mul_cost: Option<u64>,
913 group_ops_bls12381_g1_mul_cost: Option<u64>,
914 group_ops_bls12381_g2_mul_cost: Option<u64>,
915 group_ops_bls12381_gt_mul_cost: Option<u64>,
916 group_ops_bls12381_scalar_div_cost: Option<u64>,
917 group_ops_bls12381_g1_div_cost: Option<u64>,
918 group_ops_bls12381_g2_div_cost: Option<u64>,
919 group_ops_bls12381_gt_div_cost: Option<u64>,
920 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
921 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
922 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
923 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
924 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
925 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
926 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
927 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
928 group_ops_bls12381_msm_max_len: Option<u32>,
929 group_ops_bls12381_pairing_cost: Option<u64>,
930 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
931 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
932 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
933 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
934 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
935
936 hmac_hmac_sha3_256_cost_base: Option<u64>,
938 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
939 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
940
941 check_zklogin_id_cost_base: Option<u64>,
943 check_zklogin_issuer_cost_base: Option<u64>,
945
946 vdf_verify_vdf_cost: Option<u64>,
947 vdf_hash_to_input_cost: Option<u64>,
948
949 bcs_per_byte_serialized_cost: Option<u64>,
951 bcs_legacy_min_output_size_cost: Option<u64>,
952 bcs_failure_cost: Option<u64>,
953
954 hash_sha2_256_base_cost: Option<u64>,
955 hash_sha2_256_per_byte_cost: Option<u64>,
956 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
957 hash_sha3_256_base_cost: Option<u64>,
958 hash_sha3_256_per_byte_cost: Option<u64>,
959 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
960 type_name_get_base_cost: Option<u64>,
961 type_name_get_per_byte_cost: Option<u64>,
962
963 string_check_utf8_base_cost: Option<u64>,
964 string_check_utf8_per_byte_cost: Option<u64>,
965 string_is_char_boundary_base_cost: Option<u64>,
966 string_sub_string_base_cost: Option<u64>,
967 string_sub_string_per_byte_cost: Option<u64>,
968 string_index_of_base_cost: Option<u64>,
969 string_index_of_per_byte_pattern_cost: Option<u64>,
970 string_index_of_per_byte_searched_cost: Option<u64>,
971
972 vector_empty_base_cost: Option<u64>,
973 vector_length_base_cost: Option<u64>,
974 vector_push_back_base_cost: Option<u64>,
975 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
976 vector_borrow_base_cost: Option<u64>,
977 vector_pop_back_base_cost: Option<u64>,
978 vector_destroy_empty_base_cost: Option<u64>,
979 vector_swap_base_cost: Option<u64>,
980 debug_print_base_cost: Option<u64>,
981 debug_print_stack_trace_base_cost: Option<u64>,
982
983 execution_version: Option<u64>,
985
986 consensus_bad_nodes_stake_threshold: Option<u64>,
990
991 max_jwk_votes_per_validator_per_epoch: Option<u64>,
992 max_age_of_jwk_in_epochs: Option<u64>,
996
997 random_beacon_reduction_allowed_delta: Option<u16>,
1001
1002 random_beacon_reduction_lower_bound: Option<u32>,
1005
1006 random_beacon_dkg_timeout_round: Option<u32>,
1009
1010 random_beacon_min_round_interval_ms: Option<u64>,
1012
1013 random_beacon_dkg_version: Option<u64>,
1017
1018 consensus_max_transaction_size_bytes: Option<u64>,
1023 consensus_max_transactions_in_block_bytes: Option<u64>,
1025 consensus_max_num_transactions_in_block: Option<u64>,
1027
1028 max_deferral_rounds_for_congestion_control: Option<u64>,
1032
1033 min_checkpoint_interval_ms: Option<u64>,
1035
1036 checkpoint_summary_version_specific_data: Option<u64>,
1038
1039 max_soft_bundle_size: Option<u64>,
1042
1043 bridge_should_try_to_finalize_committee: Option<bool>,
1048
1049 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1053
1054 max_committee_members_count: Option<u64>,
1058
1059 consensus_gc_depth: Option<u32>,
1062}
1063
1064impl ProtocolConfig {
1066 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1079 self.feature_flags
1080 .disable_invariant_violation_check_in_swap_loc
1081 }
1082
1083 pub fn no_extraneous_module_bytes(&self) -> bool {
1084 self.feature_flags.no_extraneous_module_bytes
1085 }
1086
1087 pub fn zklogin_auth(&self) -> bool {
1088 self.feature_flags.zklogin_auth
1089 }
1090
1091 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1092 self.feature_flags.consensus_transaction_ordering
1093 }
1094
1095 pub fn enable_jwk_consensus_updates(&self) -> bool {
1096 self.feature_flags.enable_jwk_consensus_updates
1097 }
1098
1099 pub fn create_authenticator_state_in_genesis(&self) -> bool {
1101 self.enable_jwk_consensus_updates()
1102 }
1103
1104 pub fn dkg_version(&self) -> u64 {
1105 self.random_beacon_dkg_version.unwrap_or(1)
1107 }
1108
1109 pub fn accept_zklogin_in_multisig(&self) -> bool {
1110 self.feature_flags.accept_zklogin_in_multisig
1111 }
1112
1113 pub fn zklogin_max_epoch_upper_bound_delta(&self) -> Option<u64> {
1114 self.feature_flags.zklogin_max_epoch_upper_bound_delta
1115 }
1116
1117 pub fn hardened_otw_check(&self) -> bool {
1118 self.feature_flags.hardened_otw_check
1119 }
1120
1121 pub fn enable_poseidon(&self) -> bool {
1122 self.feature_flags.enable_poseidon
1123 }
1124
1125 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1126 self.feature_flags.enable_group_ops_native_function_msm
1127 }
1128
1129 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1130 self.feature_flags.per_object_congestion_control_mode
1131 }
1132
1133 pub fn consensus_choice(&self) -> ConsensusChoice {
1134 self.feature_flags.consensus_choice
1135 }
1136
1137 pub fn consensus_network(&self) -> ConsensusNetwork {
1138 self.feature_flags.consensus_network
1139 }
1140
1141 pub fn enable_vdf(&self) -> bool {
1142 self.feature_flags.enable_vdf
1143 }
1144
1145 pub fn passkey_auth(&self) -> bool {
1146 self.feature_flags.passkey_auth
1147 }
1148
1149 pub fn max_transaction_size_bytes(&self) -> u64 {
1150 self.consensus_max_transaction_size_bytes
1152 .unwrap_or(256 * 1024)
1153 }
1154
1155 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1156 self.consensus_max_transactions_in_block_bytes
1158 .unwrap_or(512 * 1024)
1159 }
1160
1161 pub fn max_num_transactions_in_block(&self) -> u64 {
1162 self.consensus_max_num_transactions_in_block.unwrap_or(500)
1164 }
1165
1166 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1167 self.feature_flags.rethrow_serialization_type_layout_errors
1168 }
1169
1170 pub fn relocate_event_module(&self) -> bool {
1171 self.feature_flags.relocate_event_module
1172 }
1173
1174 pub fn protocol_defined_base_fee(&self) -> bool {
1175 self.feature_flags.protocol_defined_base_fee
1176 }
1177
1178 pub fn uncompressed_g1_group_elements(&self) -> bool {
1179 self.feature_flags.uncompressed_g1_group_elements
1180 }
1181
1182 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1183 self.feature_flags
1184 .disallow_new_modules_in_deps_only_packages
1185 }
1186
1187 pub fn native_charging_v2(&self) -> bool {
1188 self.feature_flags.native_charging_v2
1189 }
1190
1191 pub fn consensus_round_prober(&self) -> bool {
1192 self.feature_flags.consensus_round_prober
1193 }
1194
1195 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1196 self.feature_flags
1197 .consensus_distributed_vote_scoring_strategy
1198 }
1199
1200 pub fn gc_depth(&self) -> u32 {
1201 if cfg!(msim) {
1202 min(5, self.consensus_gc_depth.unwrap_or(0))
1204 } else {
1205 self.consensus_gc_depth.unwrap_or(0)
1206 }
1207 }
1208
1209 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1210 let res = self.feature_flags.consensus_linearize_subdag_v2;
1211 assert!(
1212 !res || self.gc_depth() > 0,
1213 "The consensus linearize sub dag V2 requires GC to be enabled"
1214 );
1215 res
1216 }
1217
1218 pub fn variant_nodes(&self) -> bool {
1219 self.feature_flags.variant_nodes
1220 }
1221
1222 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1223 self.feature_flags.consensus_smart_ancestor_selection
1224 }
1225
1226 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1227 self.feature_flags
1228 .consensus_round_prober_probe_accepted_rounds
1229 }
1230
1231 pub fn consensus_zstd_compression(&self) -> bool {
1232 self.feature_flags.consensus_zstd_compression
1233 }
1234
1235 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1236 self.feature_flags
1237 .congestion_control_min_free_execution_slot
1238 }
1239
1240 pub fn accept_passkey_in_multisig(&self) -> bool {
1241 self.feature_flags.accept_passkey_in_multisig
1242 }
1243}
1244
1245#[cfg(not(msim))]
1246static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1247
1248#[cfg(msim)]
1250thread_local! {
1251 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1252}
1253
1254impl ProtocolConfig {
1256 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1259 assert!(
1261 version >= ProtocolVersion::MIN,
1262 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1263 version,
1264 ProtocolVersion::MIN.0,
1265 );
1266 assert!(
1267 version <= ProtocolVersion::MAX_ALLOWED,
1268 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1269 version,
1270 ProtocolVersion::MAX_ALLOWED.0,
1271 );
1272
1273 let mut ret = Self::get_for_version_impl(version, chain);
1274 ret.version = version;
1275
1276 ret = CONFIG_OVERRIDE.with(|ovr| {
1277 if let Some(override_fn) = &*ovr.borrow() {
1278 warn!(
1279 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1280 );
1281 override_fn(version, ret)
1282 } else {
1283 ret
1284 }
1285 });
1286
1287 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1288 warn!(
1289 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1290 );
1291 let overrides: ProtocolConfigOptional =
1292 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1293 .expect("failed to parse ProtocolConfig override env variables");
1294 overrides.apply_to(&mut ret);
1295 }
1296
1297 ret
1298 }
1299
1300 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1303 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1304 let mut ret = Self::get_for_version_impl(version, chain);
1305 ret.version = version;
1306 Some(ret)
1307 } else {
1308 None
1309 }
1310 }
1311
1312 #[cfg(not(msim))]
1313 pub fn poison_get_for_min_version() {
1314 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1315 }
1316
1317 #[cfg(not(msim))]
1318 fn load_poison_get_for_min_version() -> bool {
1319 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1320 }
1321
1322 #[cfg(msim)]
1323 pub fn poison_get_for_min_version() {
1324 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1325 }
1326
1327 #[cfg(msim)]
1328 fn load_poison_get_for_min_version() -> bool {
1329 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1330 }
1331
1332 pub fn convert_type_argument_error(&self) -> bool {
1333 self.feature_flags.convert_type_argument_error
1334 }
1335
1336 pub fn get_for_min_version() -> Self {
1340 if Self::load_poison_get_for_min_version() {
1341 panic!("get_for_min_version called on validator");
1342 }
1343 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1344 }
1345
1346 #[expect(non_snake_case)]
1357 pub fn get_for_max_version_UNSAFE() -> Self {
1358 if Self::load_poison_get_for_min_version() {
1359 panic!("get_for_max_version_UNSAFE called on validator");
1360 }
1361 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1362 }
1363
1364 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1365 #[cfg(msim)]
1366 {
1367 if version > ProtocolVersion::MAX {
1369 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1370 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1371 return config;
1372 }
1373 }
1374
1375 let mut cfg = Self {
1379 version,
1380
1381 feature_flags: Default::default(),
1382
1383 max_tx_size_bytes: Some(128 * 1024),
1384 max_input_objects: Some(2048),
1387 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1388 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1389 max_gas_payment_objects: Some(256),
1390 max_modules_in_publish: Some(64),
1391 max_package_dependencies: Some(32),
1392 max_arguments: Some(512),
1393 max_type_arguments: Some(16),
1394 max_type_argument_depth: Some(16),
1395 max_pure_argument_size: Some(16 * 1024),
1396 max_programmable_tx_commands: Some(1024),
1397 move_binary_format_version: Some(7),
1398 min_move_binary_format_version: Some(6),
1399 binary_module_handles: Some(100),
1400 binary_struct_handles: Some(300),
1401 binary_function_handles: Some(1500),
1402 binary_function_instantiations: Some(750),
1403 binary_signatures: Some(1000),
1404 binary_constant_pool: Some(4000),
1405 binary_identifiers: Some(10000),
1406 binary_address_identifiers: Some(100),
1407 binary_struct_defs: Some(200),
1408 binary_struct_def_instantiations: Some(100),
1409 binary_function_defs: Some(1000),
1410 binary_field_handles: Some(500),
1411 binary_field_instantiations: Some(250),
1412 binary_friend_decls: Some(100),
1413 binary_enum_defs: None,
1414 binary_enum_def_instantiations: None,
1415 binary_variant_handles: None,
1416 binary_variant_instantiation_handles: None,
1417 max_move_object_size: Some(250 * 1024),
1418 max_move_package_size: Some(100 * 1024),
1419 max_publish_or_upgrade_per_ptb: Some(5),
1420 max_tx_gas: Some(50_000_000_000),
1422 max_gas_price: Some(100_000),
1423 max_gas_computation_bucket: Some(5_000_000),
1424 max_loop_depth: Some(5),
1425 max_generic_instantiation_length: Some(32),
1426 max_function_parameters: Some(128),
1427 max_basic_blocks: Some(1024),
1428 max_value_stack_size: Some(1024),
1429 max_type_nodes: Some(256),
1430 max_push_size: Some(10000),
1431 max_struct_definitions: Some(200),
1432 max_function_definitions: Some(1000),
1433 max_fields_in_struct: Some(32),
1434 max_dependency_depth: Some(100),
1435 max_num_event_emit: Some(1024),
1436 max_num_new_move_object_ids: Some(2048),
1437 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1438 max_num_deleted_move_object_ids: Some(2048),
1439 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1440 max_num_transferred_move_object_ids: Some(2048),
1441 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1442 max_event_emit_size: Some(250 * 1024),
1443 max_move_vector_len: Some(256 * 1024),
1444 max_type_to_layout_nodes: None,
1445 max_ptb_value_size: None,
1446
1447 max_back_edges_per_function: Some(10_000),
1448 max_back_edges_per_module: Some(10_000),
1449
1450 max_verifier_meter_ticks_per_function: Some(16_000_000),
1451
1452 max_meter_ticks_per_module: Some(16_000_000),
1453 max_meter_ticks_per_package: Some(16_000_000),
1454
1455 object_runtime_max_num_cached_objects: Some(1000),
1456 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
1457 object_runtime_max_num_store_entries: Some(1000),
1458 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
1459 base_tx_cost_fixed: Some(1_000),
1461 package_publish_cost_fixed: Some(1_000),
1462 base_tx_cost_per_byte: Some(0),
1463 package_publish_cost_per_byte: Some(80),
1464 obj_access_cost_read_per_byte: Some(15),
1465 obj_access_cost_mutate_per_byte: Some(40),
1466 obj_access_cost_delete_per_byte: Some(40),
1467 obj_access_cost_verify_per_byte: Some(200),
1468 obj_data_cost_refundable: Some(100),
1469 obj_metadata_cost_non_refundable: Some(50),
1470 gas_model_version: Some(1),
1471 storage_rebate_rate: Some(10000),
1472 reward_slashing_rate: Some(10000),
1474 storage_gas_price: Some(76),
1475 base_gas_price: None,
1476 validator_target_reward: Some(767_000 * 1_000_000_000),
1479 max_transactions_per_checkpoint: Some(10_000),
1480 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
1481
1482 buffer_stake_for_protocol_upgrade_bps: Some(5000),
1484
1485 address_from_bytes_cost_base: Some(52),
1489 address_to_u256_cost_base: Some(52),
1491 address_from_u256_cost_base: Some(52),
1493
1494 config_read_setting_impl_cost_base: Some(100),
1497 config_read_setting_impl_cost_per_byte: Some(40),
1498
1499 dynamic_field_hash_type_and_key_cost_base: Some(100),
1503 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
1504 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
1505 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
1506 dynamic_field_add_child_object_cost_base: Some(100),
1509 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
1510 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
1511 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
1512 dynamic_field_borrow_child_object_cost_base: Some(100),
1515 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
1516 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
1517 dynamic_field_remove_child_object_cost_base: Some(100),
1520 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
1521 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
1522 dynamic_field_has_child_object_cost_base: Some(100),
1525 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
1528 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
1529 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
1530
1531 event_emit_cost_base: Some(52),
1534 event_emit_value_size_derivation_cost_per_byte: Some(2),
1535 event_emit_tag_size_derivation_cost_per_byte: Some(5),
1536 event_emit_output_cost_per_byte: Some(10),
1537
1538 object_borrow_uid_cost_base: Some(52),
1541 object_delete_impl_cost_base: Some(52),
1543 object_record_new_uid_cost_base: Some(52),
1545
1546 transfer_transfer_internal_cost_base: Some(52),
1550 transfer_freeze_object_cost_base: Some(52),
1552 transfer_share_object_cost_base: Some(52),
1554 transfer_receive_object_cost_base: Some(52),
1555
1556 tx_context_derive_id_cost_base: Some(52),
1560
1561 types_is_one_time_witness_cost_base: Some(52),
1564 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
1565 types_is_one_time_witness_type_cost_per_byte: Some(2),
1566
1567 validator_validate_metadata_cost_base: Some(52),
1571 validator_validate_metadata_data_cost_per_byte: Some(2),
1572
1573 crypto_invalid_arguments_cost: Some(100),
1575 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
1577 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
1578 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
1579
1580 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
1582 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
1583 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
1584
1585 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
1587 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1588 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1589 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
1590 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1591 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
1592
1593 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
1595
1596 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
1598 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
1599 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
1600 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
1601 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
1602 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
1603
1604 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
1606 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1607 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1608 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
1609 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1610 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
1611
1612 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
1614 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
1615 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
1616 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
1617 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
1618 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
1619
1620 ecvrf_ecvrf_verify_cost_base: Some(52),
1622 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
1623 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
1624
1625 ed25519_ed25519_verify_cost_base: Some(52),
1627 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
1628 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
1629
1630 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
1632 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
1633
1634 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
1636 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
1637 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
1638 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
1639 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
1640
1641 hash_blake2b256_cost_base: Some(52),
1643 hash_blake2b256_data_cost_per_byte: Some(2),
1644 hash_blake2b256_data_cost_per_block: Some(2),
1645 hash_keccak256_cost_base: Some(52),
1647 hash_keccak256_data_cost_per_byte: Some(2),
1648 hash_keccak256_data_cost_per_block: Some(2),
1649
1650 poseidon_bn254_cost_base: None,
1651 poseidon_bn254_cost_per_block: None,
1652
1653 hmac_hmac_sha3_256_cost_base: Some(52),
1655 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
1656 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
1657
1658 group_ops_bls12381_decode_scalar_cost: Some(52),
1660 group_ops_bls12381_decode_g1_cost: Some(52),
1661 group_ops_bls12381_decode_g2_cost: Some(52),
1662 group_ops_bls12381_decode_gt_cost: Some(52),
1663 group_ops_bls12381_scalar_add_cost: Some(52),
1664 group_ops_bls12381_g1_add_cost: Some(52),
1665 group_ops_bls12381_g2_add_cost: Some(52),
1666 group_ops_bls12381_gt_add_cost: Some(52),
1667 group_ops_bls12381_scalar_sub_cost: Some(52),
1668 group_ops_bls12381_g1_sub_cost: Some(52),
1669 group_ops_bls12381_g2_sub_cost: Some(52),
1670 group_ops_bls12381_gt_sub_cost: Some(52),
1671 group_ops_bls12381_scalar_mul_cost: Some(52),
1672 group_ops_bls12381_g1_mul_cost: Some(52),
1673 group_ops_bls12381_g2_mul_cost: Some(52),
1674 group_ops_bls12381_gt_mul_cost: Some(52),
1675 group_ops_bls12381_scalar_div_cost: Some(52),
1676 group_ops_bls12381_g1_div_cost: Some(52),
1677 group_ops_bls12381_g2_div_cost: Some(52),
1678 group_ops_bls12381_gt_div_cost: Some(52),
1679 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
1680 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
1681 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
1682 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
1683 group_ops_bls12381_g1_msm_base_cost: Some(52),
1684 group_ops_bls12381_g2_msm_base_cost: Some(52),
1685 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
1686 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
1687 group_ops_bls12381_msm_max_len: Some(32),
1688 group_ops_bls12381_pairing_cost: Some(52),
1689 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
1690 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
1691 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
1692 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
1693 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
1694
1695 check_zklogin_id_cost_base: Some(200),
1697 check_zklogin_issuer_cost_base: Some(200),
1699
1700 vdf_verify_vdf_cost: None,
1701 vdf_hash_to_input_cost: None,
1702
1703 bcs_per_byte_serialized_cost: Some(2),
1704 bcs_legacy_min_output_size_cost: Some(1),
1705 bcs_failure_cost: Some(52),
1706 hash_sha2_256_base_cost: Some(52),
1707 hash_sha2_256_per_byte_cost: Some(2),
1708 hash_sha2_256_legacy_min_input_len_cost: Some(1),
1709 hash_sha3_256_base_cost: Some(52),
1710 hash_sha3_256_per_byte_cost: Some(2),
1711 hash_sha3_256_legacy_min_input_len_cost: Some(1),
1712 type_name_get_base_cost: Some(52),
1713 type_name_get_per_byte_cost: Some(2),
1714 string_check_utf8_base_cost: Some(52),
1715 string_check_utf8_per_byte_cost: Some(2),
1716 string_is_char_boundary_base_cost: Some(52),
1717 string_sub_string_base_cost: Some(52),
1718 string_sub_string_per_byte_cost: Some(2),
1719 string_index_of_base_cost: Some(52),
1720 string_index_of_per_byte_pattern_cost: Some(2),
1721 string_index_of_per_byte_searched_cost: Some(2),
1722 vector_empty_base_cost: Some(52),
1723 vector_length_base_cost: Some(52),
1724 vector_push_back_base_cost: Some(52),
1725 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
1726 vector_borrow_base_cost: Some(52),
1727 vector_pop_back_base_cost: Some(52),
1728 vector_destroy_empty_base_cost: Some(52),
1729 vector_swap_base_cost: Some(52),
1730 debug_print_base_cost: Some(52),
1731 debug_print_stack_trace_base_cost: Some(52),
1732
1733 max_size_written_objects: Some(5 * 1000 * 1000),
1734 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
1737
1738 max_move_identifier_len: Some(128),
1740 max_move_value_depth: Some(128),
1741 max_move_enum_variants: None,
1742
1743 gas_rounding_step: Some(1_000),
1744
1745 execution_version: Some(1),
1746
1747 max_event_emit_size_total: Some(
1750 256 * 250 * 1024, ),
1752
1753 consensus_bad_nodes_stake_threshold: Some(20),
1760
1761 max_jwk_votes_per_validator_per_epoch: Some(240),
1763
1764 max_age_of_jwk_in_epochs: Some(1),
1765
1766 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
1770
1771 random_beacon_reduction_allowed_delta: Some(800),
1772
1773 random_beacon_reduction_lower_bound: Some(1000),
1774 random_beacon_dkg_timeout_round: Some(3000),
1775 random_beacon_min_round_interval_ms: Some(500),
1776
1777 random_beacon_dkg_version: Some(1),
1778
1779 consensus_max_num_transactions_in_block: Some(512),
1783
1784 max_deferral_rounds_for_congestion_control: Some(10),
1785
1786 min_checkpoint_interval_ms: Some(200),
1787
1788 checkpoint_summary_version_specific_data: Some(1),
1789
1790 max_soft_bundle_size: Some(5),
1791
1792 bridge_should_try_to_finalize_committee: None,
1793
1794 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
1795
1796 max_committee_members_count: None,
1797
1798 consensus_gc_depth: None,
1799 };
1802
1803 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
1804
1805 {
1807 cfg.feature_flags
1808 .disable_invariant_violation_check_in_swap_loc = true;
1809 cfg.feature_flags.no_extraneous_module_bytes = true;
1810 cfg.feature_flags.hardened_otw_check = true;
1811 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
1812 }
1813
1814 {
1816 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
1817 }
1818
1819 cfg.feature_flags.consensus_choice = ConsensusChoice::Mysticeti;
1821 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
1823
1824 cfg.feature_flags.per_object_congestion_control_mode =
1825 PerObjectCongestionControlMode::TotalTxCount;
1826
1827 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
1829
1830 if chain != Chain::Mainnet && chain != Chain::Testnet {
1832 cfg.feature_flags.enable_poseidon = true;
1833 cfg.poseidon_bn254_cost_base = Some(260);
1834 cfg.poseidon_bn254_cost_per_block = Some(10);
1835
1836 cfg.feature_flags.enable_group_ops_native_function_msm = true;
1837
1838 cfg.feature_flags.enable_vdf = true;
1839 cfg.vdf_verify_vdf_cost = Some(1500);
1842 cfg.vdf_hash_to_input_cost = Some(100);
1843
1844 cfg.feature_flags.passkey_auth = true;
1845 }
1846
1847 for cur in 2..=version.0 {
1848 match cur {
1849 1 => unreachable!(),
1850 2 => {}
1852 3 => {
1853 cfg.feature_flags.relocate_event_module = true;
1854 }
1855 4 => {
1856 cfg.max_type_to_layout_nodes = Some(512);
1857 }
1858 5 => {
1859 cfg.feature_flags.protocol_defined_base_fee = true;
1860 cfg.base_gas_price = Some(1000);
1861
1862 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
1863 cfg.feature_flags.convert_type_argument_error = true;
1864 cfg.feature_flags.native_charging_v2 = true;
1865
1866 if chain != Chain::Mainnet && chain != Chain::Testnet {
1867 cfg.feature_flags.uncompressed_g1_group_elements = true;
1868 }
1869
1870 cfg.gas_model_version = Some(2);
1871
1872 cfg.poseidon_bn254_cost_per_block = Some(388);
1873
1874 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
1875 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
1876 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
1877 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
1878 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
1879 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
1880 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
1881 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
1882
1883 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
1885 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
1886 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
1887 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
1888
1889 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
1890 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
1891 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
1892 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
1893 Some(8213);
1894 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
1895 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
1896 Some(9484);
1897
1898 cfg.hash_keccak256_cost_base = Some(10);
1899 cfg.hash_blake2b256_cost_base = Some(10);
1900
1901 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
1903 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
1904 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
1905 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
1906
1907 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
1908 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
1909 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
1910 cfg.group_ops_bls12381_gt_add_cost = Some(188);
1911
1912 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
1913 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
1914 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
1915 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
1916
1917 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
1918 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
1919 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
1920 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
1921
1922 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
1923 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
1924 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
1925 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
1926
1927 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
1928 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
1929
1930 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
1931 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
1932 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
1933 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
1934
1935 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
1936 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
1937 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
1938 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
1939 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
1940
1941 cfg.group_ops_bls12381_pairing_cost = Some(26897);
1942
1943 cfg.validator_validate_metadata_cost_base = Some(20000);
1944
1945 cfg.max_committee_members_count = Some(50);
1946 }
1947 6 => {
1948 cfg.max_ptb_value_size = Some(1024 * 1024);
1949 }
1950 7 => {}
1952 8 => {
1953 cfg.feature_flags.variant_nodes = true;
1954
1955 if chain != Chain::Mainnet {
1956 cfg.feature_flags.consensus_round_prober = true;
1958 cfg.feature_flags
1960 .consensus_distributed_vote_scoring_strategy = true;
1961 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
1962 cfg.feature_flags.consensus_smart_ancestor_selection = true;
1964 cfg.feature_flags
1966 .consensus_round_prober_probe_accepted_rounds = true;
1967 cfg.feature_flags.consensus_zstd_compression = true;
1969 cfg.consensus_gc_depth = Some(60);
1973 }
1974 if chain != Chain::Testnet && chain != Chain::Mainnet {
1977 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
1978 }
1979 }
1980 9 => {
1981 if chain != Chain::Mainnet {
1982 cfg.feature_flags.consensus_smart_ancestor_selection = false;
1984 }
1985
1986 cfg.feature_flags.consensus_zstd_compression = true;
1988
1989 if chain != Chain::Testnet && chain != Chain::Mainnet {
1991 cfg.feature_flags.accept_passkey_in_multisig = true;
1992 }
1993
1994 cfg.bridge_should_try_to_finalize_committee = None;
1996 }
1997 _ => panic!("unsupported version {:?}", version),
2008 }
2009 }
2010 cfg
2011 }
2012
2013 pub fn verifier_config(&self, signing_limits: Option<(usize, usize)>) -> VerifierConfig {
2017 let (max_back_edges_per_function, max_back_edges_per_module) = if let Some((
2018 max_back_edges_per_function,
2019 max_back_edges_per_module,
2020 )) = signing_limits
2021 {
2022 (
2023 Some(max_back_edges_per_function),
2024 Some(max_back_edges_per_module),
2025 )
2026 } else {
2027 (None, None)
2028 };
2029
2030 VerifierConfig {
2031 max_loop_depth: Some(self.max_loop_depth() as usize),
2032 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2033 max_function_parameters: Some(self.max_function_parameters() as usize),
2034 max_basic_blocks: Some(self.max_basic_blocks() as usize),
2035 max_value_stack_size: self.max_value_stack_size() as usize,
2036 max_type_nodes: Some(self.max_type_nodes() as usize),
2037 max_push_size: Some(self.max_push_size() as usize),
2038 max_dependency_depth: Some(self.max_dependency_depth() as usize),
2039 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2040 max_function_definitions: Some(self.max_function_definitions() as usize),
2041 max_data_definitions: Some(self.max_struct_definitions() as usize),
2042 max_constant_vector_len: Some(self.max_move_vector_len()),
2043 max_back_edges_per_function,
2044 max_back_edges_per_module,
2045 max_basic_blocks_in_script: None,
2046 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
2050 max_variants_in_enum: self.max_move_enum_variants_as_option(),
2051 }
2052 }
2053
2054 pub fn apply_overrides_for_testing(
2059 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
2060 ) -> OverrideGuard {
2061 CONFIG_OVERRIDE.with(|ovr| {
2062 let mut cur = ovr.borrow_mut();
2063 assert!(cur.is_none(), "config override already present");
2064 *cur = Some(Box::new(override_fn));
2065 OverrideGuard
2066 })
2067 }
2068}
2069
2070impl ProtocolConfig {
2075 pub fn set_zklogin_auth_for_testing(&mut self, val: bool) {
2076 self.feature_flags.zklogin_auth = val
2077 }
2078 pub fn set_enable_jwk_consensus_updates_for_testing(&mut self, val: bool) {
2079 self.feature_flags.enable_jwk_consensus_updates = val
2080 }
2081
2082 pub fn set_accept_zklogin_in_multisig_for_testing(&mut self, val: bool) {
2083 self.feature_flags.accept_zklogin_in_multisig = val
2084 }
2085
2086 pub fn set_per_object_congestion_control_mode_for_testing(
2087 &mut self,
2088 val: PerObjectCongestionControlMode,
2089 ) {
2090 self.feature_flags.per_object_congestion_control_mode = val;
2091 }
2092
2093 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
2094 self.feature_flags.consensus_choice = val;
2095 }
2096
2097 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
2098 self.feature_flags.consensus_network = val;
2099 }
2100
2101 pub fn set_zklogin_max_epoch_upper_bound_delta_for_testing(&mut self, val: Option<u64>) {
2102 self.feature_flags.zklogin_max_epoch_upper_bound_delta = val
2103 }
2104
2105 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
2106 self.feature_flags.passkey_auth = val
2107 }
2108
2109 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
2110 self.feature_flags
2111 .disallow_new_modules_in_deps_only_packages = val;
2112 }
2113
2114 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
2115 self.feature_flags.consensus_round_prober = val;
2116 }
2117
2118 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
2119 self.feature_flags
2120 .consensus_distributed_vote_scoring_strategy = val;
2121 }
2122
2123 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
2124 self.consensus_gc_depth = Some(val);
2125 }
2126
2127 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
2128 self.feature_flags.consensus_linearize_subdag_v2 = val;
2129 }
2130
2131 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
2132 self.feature_flags
2133 .consensus_round_prober_probe_accepted_rounds = val;
2134 }
2135
2136 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
2137 self.feature_flags.accept_passkey_in_multisig = val;
2138 }
2139
2140 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
2141 self.feature_flags.consensus_smart_ancestor_selection = val;
2142 }
2143}
2144
2145type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
2146
2147thread_local! {
2148 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
2149}
2150
2151#[must_use]
2152pub struct OverrideGuard;
2153
2154impl Drop for OverrideGuard {
2155 fn drop(&mut self) {
2156 info!("restoring override fn");
2157 CONFIG_OVERRIDE.with(|ovr| {
2158 *ovr.borrow_mut() = None;
2159 });
2160 }
2161}
2162
2163#[derive(PartialEq, Eq)]
2167pub enum LimitThresholdCrossed {
2168 None,
2169 Soft(u128, u128),
2170 Hard(u128, u128),
2171}
2172
2173pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
2176 x: T,
2177 soft_limit: U,
2178 hard_limit: V,
2179) -> LimitThresholdCrossed {
2180 let x: V = x.into();
2181 let soft_limit: V = soft_limit.into();
2182
2183 debug_assert!(soft_limit <= hard_limit);
2184
2185 if x >= hard_limit {
2188 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
2189 } else if x < soft_limit {
2190 LimitThresholdCrossed::None
2191 } else {
2192 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
2193 }
2194}
2195
2196#[macro_export]
2197macro_rules! check_limit {
2198 ($x:expr, $hard:expr) => {
2199 check_limit!($x, $hard, $hard)
2200 };
2201 ($x:expr, $soft:expr, $hard:expr) => {
2202 check_limit_in_range($x as u64, $soft, $hard)
2203 };
2204}
2205
2206#[macro_export]
2210macro_rules! check_limit_by_meter {
2211 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
2212 let (h, metered_str) = if $is_metered {
2214 ($metered_limit, "metered")
2215 } else {
2216 ($unmetered_hard_limit, "unmetered")
2218 };
2219 use iota_protocol_config::check_limit_in_range;
2220 let result = check_limit_in_range($x as u64, $metered_limit, h);
2221 match result {
2222 LimitThresholdCrossed::None => {}
2223 LimitThresholdCrossed::Soft(_, _) => {
2224 $metric.with_label_values(&[metered_str, "soft"]).inc();
2225 }
2226 LimitThresholdCrossed::Hard(_, _) => {
2227 $metric.with_label_values(&[metered_str, "hard"]).inc();
2228 }
2229 };
2230 result
2231 }};
2232}
2233
2234#[cfg(all(test, not(msim)))]
2235mod test {
2236 use insta::assert_yaml_snapshot;
2237
2238 use super::*;
2239
2240 #[test]
2241 fn snapshot_tests() {
2242 println!("\n============================================================================");
2243 println!("! !");
2244 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
2245 println!("! !");
2246 println!("============================================================================\n");
2247 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
2248 let chain_str = match chain_id {
2253 Chain::Unknown => "".to_string(),
2254 _ => format!("{:?}_", chain_id),
2255 };
2256 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
2257 let cur = ProtocolVersion::new(i);
2258 assert_yaml_snapshot!(
2259 format!("{}version_{}", chain_str, cur.as_u64()),
2260 ProtocolConfig::get_for_version(cur, *chain_id)
2261 );
2262 }
2263 }
2264 }
2265
2266 #[test]
2267 fn test_getters() {
2268 let prot: ProtocolConfig =
2269 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2270 assert_eq!(
2271 prot.max_arguments(),
2272 prot.max_arguments_as_option().unwrap()
2273 );
2274 }
2275
2276 #[test]
2277 fn test_setters() {
2278 let mut prot: ProtocolConfig =
2279 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2280 prot.set_max_arguments_for_testing(123);
2281 assert_eq!(prot.max_arguments(), 123);
2282
2283 prot.set_max_arguments_from_str_for_testing("321".to_string());
2284 assert_eq!(prot.max_arguments(), 321);
2285
2286 prot.disable_max_arguments_for_testing();
2287 assert_eq!(prot.max_arguments_as_option(), None);
2288
2289 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
2290 assert_eq!(prot.max_arguments(), 456);
2291 }
2292
2293 #[test]
2294 #[should_panic(expected = "unsupported version")]
2295 fn max_version_test() {
2296 let _ = ProtocolConfig::get_for_version_impl(
2299 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
2300 Chain::Unknown,
2301 );
2302 }
2303
2304 #[test]
2305 fn lookup_by_string_test() {
2306 let prot: ProtocolConfig =
2307 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2308 assert!(prot.lookup_attr("some random string".to_string()).is_none());
2310
2311 assert!(
2312 prot.lookup_attr("max_arguments".to_string())
2313 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
2314 );
2315
2316 assert!(
2318 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2319 .is_none()
2320 );
2321 assert!(
2322 prot.attr_map()
2323 .get("poseidon_bn254_cost_base")
2324 .unwrap()
2325 .is_none()
2326 );
2327
2328 let prot: ProtocolConfig =
2330 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2331
2332 assert!(
2333 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2334 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2335 );
2336 assert!(
2337 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
2338 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2339 );
2340
2341 let prot: ProtocolConfig =
2343 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2344 assert!(
2346 prot.feature_flags
2347 .lookup_attr("some random string".to_owned())
2348 .is_none()
2349 );
2350 assert!(
2351 !prot
2352 .feature_flags
2353 .attr_map()
2354 .contains_key("some random string")
2355 );
2356
2357 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
2359 assert!(
2360 prot.feature_flags
2361 .attr_map()
2362 .get("enable_poseidon")
2363 .unwrap()
2364 == &false
2365 );
2366 let prot: ProtocolConfig =
2367 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2368 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
2370 assert!(
2371 prot.feature_flags
2372 .attr_map()
2373 .get("enable_poseidon")
2374 .unwrap()
2375 == &true
2376 );
2377 }
2378
2379 #[test]
2380 fn limit_range_fn_test() {
2381 let low = 100u32;
2382 let high = 10000u64;
2383
2384 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
2385 assert!(matches!(
2386 check_limit!(255u16, low, high),
2387 LimitThresholdCrossed::Soft(255u128, 100)
2388 ));
2389 assert!(matches!(
2396 check_limit!(2550000u64, low, high),
2397 LimitThresholdCrossed::Hard(2550000, 10000)
2398 ));
2399
2400 assert!(matches!(
2401 check_limit!(2550000u64, high, high),
2402 LimitThresholdCrossed::Hard(2550000, 10000)
2403 ));
2404
2405 assert!(matches!(
2406 check_limit!(1u8, high),
2407 LimitThresholdCrossed::None
2408 ));
2409
2410 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
2411
2412 assert!(matches!(
2413 check_limit!(2550000u64, high),
2414 LimitThresholdCrossed::Hard(2550000, 10000)
2415 ));
2416 }
2417}