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)]
64pub struct ProtocolVersion(u64);
65
66impl ProtocolVersion {
67 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
73
74 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
75
76 #[cfg(not(msim))]
77 const MAX_ALLOWED: Self = Self::MAX;
78
79 #[cfg(msim)]
82 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
83
84 pub fn new(v: u64) -> Self {
85 Self(v)
86 }
87
88 pub const fn as_u64(&self) -> u64 {
89 self.0
90 }
91
92 pub fn max() -> Self {
95 Self::MAX
96 }
97}
98
99impl From<u64> for ProtocolVersion {
100 fn from(v: u64) -> Self {
101 Self::new(v)
102 }
103}
104
105impl std::ops::Sub<u64> for ProtocolVersion {
106 type Output = Self;
107 fn sub(self, rhs: u64) -> Self::Output {
108 Self::new(self.0 - rhs)
109 }
110}
111
112impl std::ops::Add<u64> for ProtocolVersion {
113 type Output = Self;
114 fn add(self, rhs: u64) -> Self::Output {
115 Self::new(self.0 + rhs)
116 }
117}
118
119#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum)]
120pub enum Chain {
121 Mainnet,
122 Testnet,
123 Unknown,
124}
125
126impl Default for Chain {
127 fn default() -> Self {
128 Self::Unknown
129 }
130}
131
132impl Chain {
133 pub fn as_str(self) -> &'static str {
134 match self {
135 Chain::Mainnet => "mainnet",
136 Chain::Testnet => "testnet",
137 Chain::Unknown => "unknown",
138 }
139 }
140}
141
142pub struct Error(pub String);
143
144#[derive(Default, Clone, Serialize, Deserialize, Debug, ProtocolConfigFeatureFlagsGetters)]
148struct FeatureFlags {
149 #[serde(skip_serializing_if = "is_true")]
155 disable_invariant_violation_check_in_swap_loc: bool,
156
157 #[serde(skip_serializing_if = "is_true")]
160 no_extraneous_module_bytes: bool,
161
162 #[serde(skip_serializing_if = "is_false")]
164 zklogin_auth: bool,
165
166 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
168 consensus_transaction_ordering: ConsensusTransactionOrdering,
169
170 #[serde(skip_serializing_if = "is_false")]
171 enable_jwk_consensus_updates: bool,
172
173 #[serde(skip_serializing_if = "is_false")]
175 bridge: bool,
176
177 #[serde(skip_serializing_if = "is_false")]
179 accept_zklogin_in_multisig: bool,
180
181 #[serde(skip_serializing_if = "is_true")]
184 hardened_otw_check: bool,
185
186 #[serde(skip_serializing_if = "is_false")]
188 enable_poseidon: bool,
189
190 #[serde(skip_serializing_if = "is_false")]
192 enable_group_ops_native_function_msm: bool,
193
194 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
196 per_object_congestion_control_mode: PerObjectCongestionControlMode,
197
198 #[serde(skip_serializing_if = "ConsensusChoice::is_mysticeti")]
200 consensus_choice: ConsensusChoice,
201
202 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
204 consensus_network: ConsensusNetwork,
205
206 #[serde(skip_serializing_if = "Option::is_none")]
208 zklogin_max_epoch_upper_bound_delta: Option<u64>,
209
210 #[serde(skip_serializing_if = "is_false")]
212 enable_vdf: bool,
213
214 #[serde(skip_serializing_if = "is_false")]
216 passkey_auth: bool,
217
218 #[serde(skip_serializing_if = "is_true")]
221 rethrow_serialization_type_layout_errors: bool,
222
223 #[serde(skip_serializing_if = "is_false")]
225 relocate_event_module: bool,
226
227 #[serde(skip_serializing_if = "is_false")]
229 protocol_defined_base_fee: bool,
230
231 #[serde(skip_serializing_if = "is_false")]
233 uncompressed_g1_group_elements: bool,
234
235 #[serde(skip_serializing_if = "is_false")]
237 disallow_new_modules_in_deps_only_packages: bool,
238
239 #[serde(skip_serializing_if = "is_false")]
241 native_charging_v2: bool,
242
243 #[serde(skip_serializing_if = "is_false")]
245 convert_type_argument_error: bool,
246
247 #[serde(skip_serializing_if = "is_false")]
249 consensus_round_prober: bool,
250
251 #[serde(skip_serializing_if = "is_false")]
253 consensus_distributed_vote_scoring_strategy: bool,
254
255 #[serde(skip_serializing_if = "is_false")]
259 consensus_linearize_subdag_v2: bool,
260
261 #[serde(skip_serializing_if = "is_false")]
263 variant_nodes: bool,
264
265 #[serde(skip_serializing_if = "is_false")]
267 consensus_smart_ancestor_selection: bool,
268
269 #[serde(skip_serializing_if = "is_false")]
271 consensus_round_prober_probe_accepted_rounds: bool,
272
273 #[serde(skip_serializing_if = "is_false")]
275 consensus_zstd_compression: bool,
276
277 #[serde(skip_serializing_if = "is_false")]
280 congestion_control_min_free_execution_slot: bool,
281
282 #[serde(skip_serializing_if = "is_false")]
284 accept_passkey_in_multisig: bool,
285}
286
287fn is_true(b: &bool) -> bool {
288 *b
289}
290
291fn is_false(b: &bool) -> bool {
292 !b
293}
294
295#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
297pub enum ConsensusTransactionOrdering {
298 #[default]
301 None,
302 ByGasPrice,
304}
305
306impl ConsensusTransactionOrdering {
307 pub fn is_none(&self) -> bool {
308 matches!(self, ConsensusTransactionOrdering::None)
309 }
310}
311
312#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
314pub enum PerObjectCongestionControlMode {
315 #[default]
316 None, TotalGasBudget, TotalTxCount, }
320
321impl PerObjectCongestionControlMode {
322 pub fn is_none(&self) -> bool {
323 matches!(self, PerObjectCongestionControlMode::None)
324 }
325}
326
327#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
329pub enum ConsensusChoice {
330 #[default]
331 Mysticeti,
332}
333
334impl ConsensusChoice {
335 pub fn is_mysticeti(&self) -> bool {
336 matches!(self, ConsensusChoice::Mysticeti)
337 }
338}
339
340#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
342pub enum ConsensusNetwork {
343 #[default]
344 Tonic,
345}
346
347impl ConsensusNetwork {
348 pub fn is_tonic(&self) -> bool {
349 matches!(self, ConsensusNetwork::Tonic)
350 }
351}
352
353#[skip_serializing_none]
387#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
388pub struct ProtocolConfig {
389 pub version: ProtocolVersion,
390
391 feature_flags: FeatureFlags,
392
393 max_tx_size_bytes: Option<u64>,
398
399 max_input_objects: Option<u64>,
402
403 max_size_written_objects: Option<u64>,
408 max_size_written_objects_system_tx: Option<u64>,
412
413 max_serialized_tx_effects_size_bytes: Option<u64>,
415
416 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
418
419 max_gas_payment_objects: Option<u32>,
421
422 max_modules_in_publish: Option<u32>,
424
425 max_package_dependencies: Option<u32>,
427
428 max_arguments: Option<u32>,
431
432 max_type_arguments: Option<u32>,
434
435 max_type_argument_depth: Option<u32>,
437
438 max_pure_argument_size: Option<u32>,
440
441 max_programmable_tx_commands: Option<u32>,
443
444 move_binary_format_version: Option<u32>,
450 min_move_binary_format_version: Option<u32>,
451
452 binary_module_handles: Option<u16>,
454 binary_struct_handles: Option<u16>,
455 binary_function_handles: Option<u16>,
456 binary_function_instantiations: Option<u16>,
457 binary_signatures: Option<u16>,
458 binary_constant_pool: Option<u16>,
459 binary_identifiers: Option<u16>,
460 binary_address_identifiers: Option<u16>,
461 binary_struct_defs: Option<u16>,
462 binary_struct_def_instantiations: Option<u16>,
463 binary_function_defs: Option<u16>,
464 binary_field_handles: Option<u16>,
465 binary_field_instantiations: Option<u16>,
466 binary_friend_decls: Option<u16>,
467 binary_enum_defs: Option<u16>,
468 binary_enum_def_instantiations: Option<u16>,
469 binary_variant_handles: Option<u16>,
470 binary_variant_instantiation_handles: Option<u16>,
471
472 max_move_object_size: Option<u64>,
475
476 max_move_package_size: Option<u64>,
481
482 max_publish_or_upgrade_per_ptb: Option<u64>,
485
486 max_tx_gas: Option<u64>,
488
489 max_gas_price: Option<u64>,
492
493 max_gas_computation_bucket: Option<u64>,
496
497 gas_rounding_step: Option<u64>,
499
500 max_loop_depth: Option<u64>,
502
503 max_generic_instantiation_length: Option<u64>,
506
507 max_function_parameters: Option<u64>,
510
511 max_basic_blocks: Option<u64>,
514
515 max_value_stack_size: Option<u64>,
517
518 max_type_nodes: Option<u64>,
522
523 max_push_size: Option<u64>,
526
527 max_struct_definitions: Option<u64>,
530
531 max_function_definitions: Option<u64>,
534
535 max_fields_in_struct: Option<u64>,
538
539 max_dependency_depth: Option<u64>,
542
543 max_num_event_emit: Option<u64>,
546
547 max_num_new_move_object_ids: Option<u64>,
550
551 max_num_new_move_object_ids_system_tx: Option<u64>,
554
555 max_num_deleted_move_object_ids: Option<u64>,
558
559 max_num_deleted_move_object_ids_system_tx: Option<u64>,
562
563 max_num_transferred_move_object_ids: Option<u64>,
566
567 max_num_transferred_move_object_ids_system_tx: Option<u64>,
570
571 max_event_emit_size: Option<u64>,
573
574 max_event_emit_size_total: Option<u64>,
576
577 max_move_vector_len: Option<u64>,
580
581 max_move_identifier_len: Option<u64>,
584
585 max_move_value_depth: Option<u64>,
587
588 max_move_enum_variants: Option<u64>,
591
592 max_back_edges_per_function: Option<u64>,
595
596 max_back_edges_per_module: Option<u64>,
599
600 max_verifier_meter_ticks_per_function: Option<u64>,
603
604 max_meter_ticks_per_module: Option<u64>,
607
608 max_meter_ticks_per_package: Option<u64>,
611
612 object_runtime_max_num_cached_objects: Option<u64>,
619
620 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
623
624 object_runtime_max_num_store_entries: Option<u64>,
627
628 object_runtime_max_num_store_entries_system_tx: Option<u64>,
631
632 base_tx_cost_fixed: Option<u64>,
637
638 package_publish_cost_fixed: Option<u64>,
642
643 base_tx_cost_per_byte: Option<u64>,
647
648 package_publish_cost_per_byte: Option<u64>,
650
651 obj_access_cost_read_per_byte: Option<u64>,
653
654 obj_access_cost_mutate_per_byte: Option<u64>,
656
657 obj_access_cost_delete_per_byte: Option<u64>,
659
660 obj_access_cost_verify_per_byte: Option<u64>,
670
671 max_type_to_layout_nodes: Option<u64>,
673
674 max_ptb_value_size: Option<u64>,
676
677 gas_model_version: Option<u64>,
682
683 obj_data_cost_refundable: Option<u64>,
689
690 obj_metadata_cost_non_refundable: Option<u64>,
694
695 storage_rebate_rate: Option<u64>,
701
702 reward_slashing_rate: Option<u64>,
705
706 storage_gas_price: Option<u64>,
708
709 base_gas_price: Option<u64>,
711
712 validator_target_reward: Option<u64>,
714
715 max_transactions_per_checkpoint: Option<u64>,
722
723 max_checkpoint_size_bytes: Option<u64>,
727
728 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
734
735 address_from_bytes_cost_base: Option<u64>,
740 address_to_u256_cost_base: Option<u64>,
742 address_from_u256_cost_base: Option<u64>,
744
745 config_read_setting_impl_cost_base: Option<u64>,
750 config_read_setting_impl_cost_per_byte: Option<u64>,
751
752 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
756 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
757 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
758 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
759 dynamic_field_add_child_object_cost_base: Option<u64>,
762 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
763 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
764 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
765 dynamic_field_borrow_child_object_cost_base: Option<u64>,
768 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
769 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
770 dynamic_field_remove_child_object_cost_base: Option<u64>,
773 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
774 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
775 dynamic_field_has_child_object_cost_base: Option<u64>,
778 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
781 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
782 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
783
784 event_emit_cost_base: Option<u64>,
787 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
788 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
789 event_emit_output_cost_per_byte: Option<u64>,
790
791 object_borrow_uid_cost_base: Option<u64>,
794 object_delete_impl_cost_base: Option<u64>,
796 object_record_new_uid_cost_base: Option<u64>,
798
799 transfer_transfer_internal_cost_base: Option<u64>,
802 transfer_freeze_object_cost_base: Option<u64>,
804 transfer_share_object_cost_base: Option<u64>,
806 transfer_receive_object_cost_base: Option<u64>,
809
810 tx_context_derive_id_cost_base: Option<u64>,
813
814 types_is_one_time_witness_cost_base: Option<u64>,
817 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
818 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
819
820 validator_validate_metadata_cost_base: Option<u64>,
823 validator_validate_metadata_data_cost_per_byte: Option<u64>,
824
825 crypto_invalid_arguments_cost: Option<u64>,
827 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
829 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
830 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
831
832 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
834 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
835 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
836
837 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
839 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
840 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
841 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
842 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
843 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
844
845 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
847
848 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
850 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
851 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
852 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
853 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
854 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
855
856 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
858 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
859 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
860 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
861 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
862 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
863
864 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
866 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
867 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
868 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
869 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
870 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
871
872 ecvrf_ecvrf_verify_cost_base: Option<u64>,
874 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
875 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
876
877 ed25519_ed25519_verify_cost_base: Option<u64>,
879 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
880 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
881
882 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
884 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
885
886 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
888 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
889 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
890 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
891 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
892
893 hash_blake2b256_cost_base: Option<u64>,
895 hash_blake2b256_data_cost_per_byte: Option<u64>,
896 hash_blake2b256_data_cost_per_block: Option<u64>,
897
898 hash_keccak256_cost_base: Option<u64>,
900 hash_keccak256_data_cost_per_byte: Option<u64>,
901 hash_keccak256_data_cost_per_block: Option<u64>,
902
903 poseidon_bn254_cost_base: Option<u64>,
905 poseidon_bn254_cost_per_block: Option<u64>,
906
907 group_ops_bls12381_decode_scalar_cost: Option<u64>,
909 group_ops_bls12381_decode_g1_cost: Option<u64>,
910 group_ops_bls12381_decode_g2_cost: Option<u64>,
911 group_ops_bls12381_decode_gt_cost: Option<u64>,
912 group_ops_bls12381_scalar_add_cost: Option<u64>,
913 group_ops_bls12381_g1_add_cost: Option<u64>,
914 group_ops_bls12381_g2_add_cost: Option<u64>,
915 group_ops_bls12381_gt_add_cost: Option<u64>,
916 group_ops_bls12381_scalar_sub_cost: Option<u64>,
917 group_ops_bls12381_g1_sub_cost: Option<u64>,
918 group_ops_bls12381_g2_sub_cost: Option<u64>,
919 group_ops_bls12381_gt_sub_cost: Option<u64>,
920 group_ops_bls12381_scalar_mul_cost: Option<u64>,
921 group_ops_bls12381_g1_mul_cost: Option<u64>,
922 group_ops_bls12381_g2_mul_cost: Option<u64>,
923 group_ops_bls12381_gt_mul_cost: Option<u64>,
924 group_ops_bls12381_scalar_div_cost: Option<u64>,
925 group_ops_bls12381_g1_div_cost: Option<u64>,
926 group_ops_bls12381_g2_div_cost: Option<u64>,
927 group_ops_bls12381_gt_div_cost: Option<u64>,
928 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
929 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
930 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
931 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
932 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
933 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
934 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
935 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
936 group_ops_bls12381_msm_max_len: Option<u32>,
937 group_ops_bls12381_pairing_cost: Option<u64>,
938 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
939 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
940 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
941 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
942 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
943
944 hmac_hmac_sha3_256_cost_base: Option<u64>,
946 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
947 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
948
949 check_zklogin_id_cost_base: Option<u64>,
951 check_zklogin_issuer_cost_base: Option<u64>,
953
954 vdf_verify_vdf_cost: Option<u64>,
955 vdf_hash_to_input_cost: Option<u64>,
956
957 bcs_per_byte_serialized_cost: Option<u64>,
959 bcs_legacy_min_output_size_cost: Option<u64>,
960 bcs_failure_cost: Option<u64>,
961
962 hash_sha2_256_base_cost: Option<u64>,
963 hash_sha2_256_per_byte_cost: Option<u64>,
964 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
965 hash_sha3_256_base_cost: Option<u64>,
966 hash_sha3_256_per_byte_cost: Option<u64>,
967 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
968 type_name_get_base_cost: Option<u64>,
969 type_name_get_per_byte_cost: Option<u64>,
970
971 string_check_utf8_base_cost: Option<u64>,
972 string_check_utf8_per_byte_cost: Option<u64>,
973 string_is_char_boundary_base_cost: Option<u64>,
974 string_sub_string_base_cost: Option<u64>,
975 string_sub_string_per_byte_cost: Option<u64>,
976 string_index_of_base_cost: Option<u64>,
977 string_index_of_per_byte_pattern_cost: Option<u64>,
978 string_index_of_per_byte_searched_cost: Option<u64>,
979
980 vector_empty_base_cost: Option<u64>,
981 vector_length_base_cost: Option<u64>,
982 vector_push_back_base_cost: Option<u64>,
983 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
984 vector_borrow_base_cost: Option<u64>,
985 vector_pop_back_base_cost: Option<u64>,
986 vector_destroy_empty_base_cost: Option<u64>,
987 vector_swap_base_cost: Option<u64>,
988 debug_print_base_cost: Option<u64>,
989 debug_print_stack_trace_base_cost: Option<u64>,
990
991 execution_version: Option<u64>,
993
994 consensus_bad_nodes_stake_threshold: Option<u64>,
998
999 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1000 max_age_of_jwk_in_epochs: Option<u64>,
1004
1005 random_beacon_reduction_allowed_delta: Option<u16>,
1009
1010 random_beacon_reduction_lower_bound: Option<u32>,
1013
1014 random_beacon_dkg_timeout_round: Option<u32>,
1017
1018 random_beacon_min_round_interval_ms: Option<u64>,
1020
1021 random_beacon_dkg_version: Option<u64>,
1025
1026 consensus_max_transaction_size_bytes: Option<u64>,
1031 consensus_max_transactions_in_block_bytes: Option<u64>,
1033 consensus_max_num_transactions_in_block: Option<u64>,
1035
1036 max_deferral_rounds_for_congestion_control: Option<u64>,
1040
1041 min_checkpoint_interval_ms: Option<u64>,
1043
1044 checkpoint_summary_version_specific_data: Option<u64>,
1046
1047 max_soft_bundle_size: Option<u64>,
1050
1051 bridge_should_try_to_finalize_committee: Option<bool>,
1055
1056 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1060
1061 max_committee_members_count: Option<u64>,
1065
1066 consensus_gc_depth: Option<u32>,
1069}
1070
1071impl ProtocolConfig {
1073 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1086 self.feature_flags
1087 .disable_invariant_violation_check_in_swap_loc
1088 }
1089
1090 pub fn no_extraneous_module_bytes(&self) -> bool {
1091 self.feature_flags.no_extraneous_module_bytes
1092 }
1093
1094 pub fn zklogin_auth(&self) -> bool {
1095 self.feature_flags.zklogin_auth
1096 }
1097
1098 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1099 self.feature_flags.consensus_transaction_ordering
1100 }
1101
1102 pub fn enable_jwk_consensus_updates(&self) -> bool {
1103 self.feature_flags.enable_jwk_consensus_updates
1104 }
1105
1106 pub fn create_authenticator_state_in_genesis(&self) -> bool {
1108 self.enable_jwk_consensus_updates()
1109 }
1110
1111 pub fn dkg_version(&self) -> u64 {
1112 self.random_beacon_dkg_version.unwrap_or(1)
1114 }
1115
1116 pub fn enable_bridge(&self) -> bool {
1117 self.feature_flags.bridge
1118 }
1119
1120 pub fn should_try_to_finalize_bridge_committee(&self) -> bool {
1121 if !self.enable_bridge() {
1122 return false;
1123 }
1124 self.bridge_should_try_to_finalize_committee.unwrap_or(true)
1126 }
1127
1128 pub fn accept_zklogin_in_multisig(&self) -> bool {
1129 self.feature_flags.accept_zklogin_in_multisig
1130 }
1131
1132 pub fn zklogin_max_epoch_upper_bound_delta(&self) -> Option<u64> {
1133 self.feature_flags.zklogin_max_epoch_upper_bound_delta
1134 }
1135
1136 pub fn hardened_otw_check(&self) -> bool {
1137 self.feature_flags.hardened_otw_check
1138 }
1139
1140 pub fn enable_poseidon(&self) -> bool {
1141 self.feature_flags.enable_poseidon
1142 }
1143
1144 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1145 self.feature_flags.enable_group_ops_native_function_msm
1146 }
1147
1148 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1149 self.feature_flags.per_object_congestion_control_mode
1150 }
1151
1152 pub fn consensus_choice(&self) -> ConsensusChoice {
1153 self.feature_flags.consensus_choice
1154 }
1155
1156 pub fn consensus_network(&self) -> ConsensusNetwork {
1157 self.feature_flags.consensus_network
1158 }
1159
1160 pub fn enable_vdf(&self) -> bool {
1161 self.feature_flags.enable_vdf
1162 }
1163
1164 pub fn passkey_auth(&self) -> bool {
1165 self.feature_flags.passkey_auth
1166 }
1167
1168 pub fn max_transaction_size_bytes(&self) -> u64 {
1169 self.consensus_max_transaction_size_bytes
1171 .unwrap_or(256 * 1024)
1172 }
1173
1174 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1175 self.consensus_max_transactions_in_block_bytes
1177 .unwrap_or(512 * 1024)
1178 }
1179
1180 pub fn max_num_transactions_in_block(&self) -> u64 {
1181 self.consensus_max_num_transactions_in_block.unwrap_or(500)
1183 }
1184
1185 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1186 self.feature_flags.rethrow_serialization_type_layout_errors
1187 }
1188
1189 pub fn relocate_event_module(&self) -> bool {
1190 self.feature_flags.relocate_event_module
1191 }
1192
1193 pub fn protocol_defined_base_fee(&self) -> bool {
1194 self.feature_flags.protocol_defined_base_fee
1195 }
1196
1197 pub fn uncompressed_g1_group_elements(&self) -> bool {
1198 self.feature_flags.uncompressed_g1_group_elements
1199 }
1200
1201 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1202 self.feature_flags
1203 .disallow_new_modules_in_deps_only_packages
1204 }
1205
1206 pub fn native_charging_v2(&self) -> bool {
1207 self.feature_flags.native_charging_v2
1208 }
1209
1210 pub fn consensus_round_prober(&self) -> bool {
1211 self.feature_flags.consensus_round_prober
1212 }
1213
1214 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1215 self.feature_flags
1216 .consensus_distributed_vote_scoring_strategy
1217 }
1218
1219 pub fn gc_depth(&self) -> u32 {
1220 if cfg!(msim) {
1221 min(5, self.consensus_gc_depth.unwrap_or(0))
1223 } else {
1224 self.consensus_gc_depth.unwrap_or(0)
1225 }
1226 }
1227
1228 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1229 let res = self.feature_flags.consensus_linearize_subdag_v2;
1230 assert!(
1231 !res || self.gc_depth() > 0,
1232 "The consensus linearize sub dag V2 requires GC to be enabled"
1233 );
1234 res
1235 }
1236
1237 pub fn variant_nodes(&self) -> bool {
1238 self.feature_flags.variant_nodes
1239 }
1240
1241 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1242 self.feature_flags.consensus_smart_ancestor_selection
1243 }
1244
1245 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1246 self.feature_flags
1247 .consensus_round_prober_probe_accepted_rounds
1248 }
1249
1250 pub fn consensus_zstd_compression(&self) -> bool {
1251 self.feature_flags.consensus_zstd_compression
1252 }
1253
1254 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1255 self.feature_flags
1256 .congestion_control_min_free_execution_slot
1257 }
1258
1259 pub fn accept_passkey_in_multisig(&self) -> bool {
1260 self.feature_flags.accept_passkey_in_multisig
1261 }
1262}
1263
1264#[cfg(not(msim))]
1265static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1266
1267#[cfg(msim)]
1269thread_local! {
1270 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1271}
1272
1273impl ProtocolConfig {
1275 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1278 assert!(
1280 version >= ProtocolVersion::MIN,
1281 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1282 version,
1283 ProtocolVersion::MIN.0,
1284 );
1285 assert!(
1286 version <= ProtocolVersion::MAX_ALLOWED,
1287 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1288 version,
1289 ProtocolVersion::MAX_ALLOWED.0,
1290 );
1291
1292 let mut ret = Self::get_for_version_impl(version, chain);
1293 ret.version = version;
1294
1295 ret = CONFIG_OVERRIDE.with(|ovr| {
1296 if let Some(override_fn) = &*ovr.borrow() {
1297 warn!(
1298 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1299 );
1300 override_fn(version, ret)
1301 } else {
1302 ret
1303 }
1304 });
1305
1306 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1307 warn!(
1308 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1309 );
1310 let overrides: ProtocolConfigOptional =
1311 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1312 .expect("failed to parse ProtocolConfig override env variables");
1313 overrides.apply_to(&mut ret);
1314 }
1315
1316 ret
1317 }
1318
1319 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1322 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1323 let mut ret = Self::get_for_version_impl(version, chain);
1324 ret.version = version;
1325 Some(ret)
1326 } else {
1327 None
1328 }
1329 }
1330
1331 #[cfg(not(msim))]
1332 pub fn poison_get_for_min_version() {
1333 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1334 }
1335
1336 #[cfg(not(msim))]
1337 fn load_poison_get_for_min_version() -> bool {
1338 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1339 }
1340
1341 #[cfg(msim)]
1342 pub fn poison_get_for_min_version() {
1343 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1344 }
1345
1346 #[cfg(msim)]
1347 fn load_poison_get_for_min_version() -> bool {
1348 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1349 }
1350
1351 pub fn convert_type_argument_error(&self) -> bool {
1352 self.feature_flags.convert_type_argument_error
1353 }
1354
1355 pub fn get_for_min_version() -> Self {
1359 if Self::load_poison_get_for_min_version() {
1360 panic!("get_for_min_version called on validator");
1361 }
1362 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1363 }
1364
1365 #[expect(non_snake_case)]
1376 pub fn get_for_max_version_UNSAFE() -> Self {
1377 if Self::load_poison_get_for_min_version() {
1378 panic!("get_for_max_version_UNSAFE called on validator");
1379 }
1380 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1381 }
1382
1383 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1384 #[cfg(msim)]
1385 {
1386 if version > ProtocolVersion::MAX {
1388 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1389 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1390 return config;
1391 }
1392 }
1393
1394 let mut cfg = Self {
1398 version,
1399
1400 feature_flags: Default::default(),
1401
1402 max_tx_size_bytes: Some(128 * 1024),
1403 max_input_objects: Some(2048),
1406 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1407 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1408 max_gas_payment_objects: Some(256),
1409 max_modules_in_publish: Some(64),
1410 max_package_dependencies: Some(32),
1411 max_arguments: Some(512),
1412 max_type_arguments: Some(16),
1413 max_type_argument_depth: Some(16),
1414 max_pure_argument_size: Some(16 * 1024),
1415 max_programmable_tx_commands: Some(1024),
1416 move_binary_format_version: Some(7),
1417 min_move_binary_format_version: Some(6),
1418 binary_module_handles: Some(100),
1419 binary_struct_handles: Some(300),
1420 binary_function_handles: Some(1500),
1421 binary_function_instantiations: Some(750),
1422 binary_signatures: Some(1000),
1423 binary_constant_pool: Some(4000),
1424 binary_identifiers: Some(10000),
1425 binary_address_identifiers: Some(100),
1426 binary_struct_defs: Some(200),
1427 binary_struct_def_instantiations: Some(100),
1428 binary_function_defs: Some(1000),
1429 binary_field_handles: Some(500),
1430 binary_field_instantiations: Some(250),
1431 binary_friend_decls: Some(100),
1432 binary_enum_defs: None,
1433 binary_enum_def_instantiations: None,
1434 binary_variant_handles: None,
1435 binary_variant_instantiation_handles: None,
1436 max_move_object_size: Some(250 * 1024),
1437 max_move_package_size: Some(100 * 1024),
1438 max_publish_or_upgrade_per_ptb: Some(5),
1439 max_tx_gas: Some(50_000_000_000),
1441 max_gas_price: Some(100_000),
1442 max_gas_computation_bucket: Some(5_000_000),
1443 max_loop_depth: Some(5),
1444 max_generic_instantiation_length: Some(32),
1445 max_function_parameters: Some(128),
1446 max_basic_blocks: Some(1024),
1447 max_value_stack_size: Some(1024),
1448 max_type_nodes: Some(256),
1449 max_push_size: Some(10000),
1450 max_struct_definitions: Some(200),
1451 max_function_definitions: Some(1000),
1452 max_fields_in_struct: Some(32),
1453 max_dependency_depth: Some(100),
1454 max_num_event_emit: Some(1024),
1455 max_num_new_move_object_ids: Some(2048),
1456 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1457 max_num_deleted_move_object_ids: Some(2048),
1458 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1459 max_num_transferred_move_object_ids: Some(2048),
1460 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1461 max_event_emit_size: Some(250 * 1024),
1462 max_move_vector_len: Some(256 * 1024),
1463 max_type_to_layout_nodes: None,
1464 max_ptb_value_size: None,
1465
1466 max_back_edges_per_function: Some(10_000),
1467 max_back_edges_per_module: Some(10_000),
1468
1469 max_verifier_meter_ticks_per_function: Some(16_000_000),
1470
1471 max_meter_ticks_per_module: Some(16_000_000),
1472 max_meter_ticks_per_package: Some(16_000_000),
1473
1474 object_runtime_max_num_cached_objects: Some(1000),
1475 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
1476 object_runtime_max_num_store_entries: Some(1000),
1477 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
1478 base_tx_cost_fixed: Some(1_000),
1480 package_publish_cost_fixed: Some(1_000),
1481 base_tx_cost_per_byte: Some(0),
1482 package_publish_cost_per_byte: Some(80),
1483 obj_access_cost_read_per_byte: Some(15),
1484 obj_access_cost_mutate_per_byte: Some(40),
1485 obj_access_cost_delete_per_byte: Some(40),
1486 obj_access_cost_verify_per_byte: Some(200),
1487 obj_data_cost_refundable: Some(100),
1488 obj_metadata_cost_non_refundable: Some(50),
1489 gas_model_version: Some(1),
1490 storage_rebate_rate: Some(10000),
1491 reward_slashing_rate: Some(10000),
1493 storage_gas_price: Some(76),
1494 base_gas_price: None,
1495 validator_target_reward: Some(767_000 * 1_000_000_000),
1498 max_transactions_per_checkpoint: Some(10_000),
1499 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
1500
1501 buffer_stake_for_protocol_upgrade_bps: Some(5000),
1503
1504 address_from_bytes_cost_base: Some(52),
1508 address_to_u256_cost_base: Some(52),
1510 address_from_u256_cost_base: Some(52),
1512
1513 config_read_setting_impl_cost_base: Some(100),
1516 config_read_setting_impl_cost_per_byte: Some(40),
1517
1518 dynamic_field_hash_type_and_key_cost_base: Some(100),
1522 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
1523 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
1524 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
1525 dynamic_field_add_child_object_cost_base: Some(100),
1528 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
1529 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
1530 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
1531 dynamic_field_borrow_child_object_cost_base: Some(100),
1534 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
1535 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
1536 dynamic_field_remove_child_object_cost_base: Some(100),
1539 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
1540 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
1541 dynamic_field_has_child_object_cost_base: Some(100),
1544 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
1547 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
1548 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
1549
1550 event_emit_cost_base: Some(52),
1553 event_emit_value_size_derivation_cost_per_byte: Some(2),
1554 event_emit_tag_size_derivation_cost_per_byte: Some(5),
1555 event_emit_output_cost_per_byte: Some(10),
1556
1557 object_borrow_uid_cost_base: Some(52),
1560 object_delete_impl_cost_base: Some(52),
1562 object_record_new_uid_cost_base: Some(52),
1564
1565 transfer_transfer_internal_cost_base: Some(52),
1569 transfer_freeze_object_cost_base: Some(52),
1571 transfer_share_object_cost_base: Some(52),
1573 transfer_receive_object_cost_base: Some(52),
1574
1575 tx_context_derive_id_cost_base: Some(52),
1579
1580 types_is_one_time_witness_cost_base: Some(52),
1583 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
1584 types_is_one_time_witness_type_cost_per_byte: Some(2),
1585
1586 validator_validate_metadata_cost_base: Some(52),
1590 validator_validate_metadata_data_cost_per_byte: Some(2),
1591
1592 crypto_invalid_arguments_cost: Some(100),
1594 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
1596 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
1597 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
1598
1599 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
1601 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
1602 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
1603
1604 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
1606 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1607 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1608 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
1609 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1610 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
1611
1612 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
1614
1615 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
1617 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
1618 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
1619 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
1620 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
1621 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
1622
1623 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
1625 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1626 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1627 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
1628 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1629 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
1630
1631 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
1633 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
1634 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
1635 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
1636 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
1637 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
1638
1639 ecvrf_ecvrf_verify_cost_base: Some(52),
1641 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
1642 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
1643
1644 ed25519_ed25519_verify_cost_base: Some(52),
1646 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
1647 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
1648
1649 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
1651 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
1652
1653 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
1655 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
1656 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
1657 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
1658 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
1659
1660 hash_blake2b256_cost_base: Some(52),
1662 hash_blake2b256_data_cost_per_byte: Some(2),
1663 hash_blake2b256_data_cost_per_block: Some(2),
1664 hash_keccak256_cost_base: Some(52),
1666 hash_keccak256_data_cost_per_byte: Some(2),
1667 hash_keccak256_data_cost_per_block: Some(2),
1668
1669 poseidon_bn254_cost_base: None,
1670 poseidon_bn254_cost_per_block: None,
1671
1672 hmac_hmac_sha3_256_cost_base: Some(52),
1674 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
1675 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
1676
1677 group_ops_bls12381_decode_scalar_cost: Some(52),
1679 group_ops_bls12381_decode_g1_cost: Some(52),
1680 group_ops_bls12381_decode_g2_cost: Some(52),
1681 group_ops_bls12381_decode_gt_cost: Some(52),
1682 group_ops_bls12381_scalar_add_cost: Some(52),
1683 group_ops_bls12381_g1_add_cost: Some(52),
1684 group_ops_bls12381_g2_add_cost: Some(52),
1685 group_ops_bls12381_gt_add_cost: Some(52),
1686 group_ops_bls12381_scalar_sub_cost: Some(52),
1687 group_ops_bls12381_g1_sub_cost: Some(52),
1688 group_ops_bls12381_g2_sub_cost: Some(52),
1689 group_ops_bls12381_gt_sub_cost: Some(52),
1690 group_ops_bls12381_scalar_mul_cost: Some(52),
1691 group_ops_bls12381_g1_mul_cost: Some(52),
1692 group_ops_bls12381_g2_mul_cost: Some(52),
1693 group_ops_bls12381_gt_mul_cost: Some(52),
1694 group_ops_bls12381_scalar_div_cost: Some(52),
1695 group_ops_bls12381_g1_div_cost: Some(52),
1696 group_ops_bls12381_g2_div_cost: Some(52),
1697 group_ops_bls12381_gt_div_cost: Some(52),
1698 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
1699 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
1700 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
1701 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
1702 group_ops_bls12381_g1_msm_base_cost: Some(52),
1703 group_ops_bls12381_g2_msm_base_cost: Some(52),
1704 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
1705 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
1706 group_ops_bls12381_msm_max_len: Some(32),
1707 group_ops_bls12381_pairing_cost: Some(52),
1708 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
1709 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
1710 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
1711 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
1712 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
1713
1714 check_zklogin_id_cost_base: Some(200),
1716 check_zklogin_issuer_cost_base: Some(200),
1718
1719 vdf_verify_vdf_cost: None,
1720 vdf_hash_to_input_cost: None,
1721
1722 bcs_per_byte_serialized_cost: Some(2),
1723 bcs_legacy_min_output_size_cost: Some(1),
1724 bcs_failure_cost: Some(52),
1725 hash_sha2_256_base_cost: Some(52),
1726 hash_sha2_256_per_byte_cost: Some(2),
1727 hash_sha2_256_legacy_min_input_len_cost: Some(1),
1728 hash_sha3_256_base_cost: Some(52),
1729 hash_sha3_256_per_byte_cost: Some(2),
1730 hash_sha3_256_legacy_min_input_len_cost: Some(1),
1731 type_name_get_base_cost: Some(52),
1732 type_name_get_per_byte_cost: Some(2),
1733 string_check_utf8_base_cost: Some(52),
1734 string_check_utf8_per_byte_cost: Some(2),
1735 string_is_char_boundary_base_cost: Some(52),
1736 string_sub_string_base_cost: Some(52),
1737 string_sub_string_per_byte_cost: Some(2),
1738 string_index_of_base_cost: Some(52),
1739 string_index_of_per_byte_pattern_cost: Some(2),
1740 string_index_of_per_byte_searched_cost: Some(2),
1741 vector_empty_base_cost: Some(52),
1742 vector_length_base_cost: Some(52),
1743 vector_push_back_base_cost: Some(52),
1744 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
1745 vector_borrow_base_cost: Some(52),
1746 vector_pop_back_base_cost: Some(52),
1747 vector_destroy_empty_base_cost: Some(52),
1748 vector_swap_base_cost: Some(52),
1749 debug_print_base_cost: Some(52),
1750 debug_print_stack_trace_base_cost: Some(52),
1751
1752 max_size_written_objects: Some(5 * 1000 * 1000),
1753 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
1756
1757 max_move_identifier_len: Some(128),
1759 max_move_value_depth: Some(128),
1760 max_move_enum_variants: None,
1761
1762 gas_rounding_step: Some(1_000),
1763
1764 execution_version: Some(1),
1765
1766 max_event_emit_size_total: Some(
1769 256 * 250 * 1024, ),
1771
1772 consensus_bad_nodes_stake_threshold: Some(20),
1779
1780 max_jwk_votes_per_validator_per_epoch: Some(240),
1782
1783 max_age_of_jwk_in_epochs: Some(1),
1784
1785 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
1789
1790 random_beacon_reduction_allowed_delta: Some(800),
1791
1792 random_beacon_reduction_lower_bound: Some(1000),
1793 random_beacon_dkg_timeout_round: Some(3000),
1794 random_beacon_min_round_interval_ms: Some(500),
1795
1796 random_beacon_dkg_version: Some(1),
1797
1798 consensus_max_num_transactions_in_block: Some(512),
1802
1803 max_deferral_rounds_for_congestion_control: Some(10),
1804
1805 min_checkpoint_interval_ms: Some(200),
1806
1807 checkpoint_summary_version_specific_data: Some(1),
1808
1809 max_soft_bundle_size: Some(5),
1810
1811 bridge_should_try_to_finalize_committee: None,
1812
1813 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
1814
1815 max_committee_members_count: None,
1816
1817 consensus_gc_depth: None,
1818 };
1821
1822 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
1823
1824 {
1826 cfg.feature_flags
1827 .disable_invariant_violation_check_in_swap_loc = true;
1828 cfg.feature_flags.no_extraneous_module_bytes = true;
1829 cfg.feature_flags.hardened_otw_check = true;
1830 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
1831 }
1832
1833 {
1835 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
1836 }
1837
1838 cfg.feature_flags.consensus_choice = ConsensusChoice::Mysticeti;
1840 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
1842
1843 cfg.feature_flags.per_object_congestion_control_mode =
1844 PerObjectCongestionControlMode::TotalTxCount;
1845
1846 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
1848
1849 if chain != Chain::Mainnet && chain != Chain::Testnet {
1851 cfg.feature_flags.enable_poseidon = true;
1852 cfg.poseidon_bn254_cost_base = Some(260);
1853 cfg.poseidon_bn254_cost_per_block = Some(10);
1854
1855 cfg.feature_flags.enable_group_ops_native_function_msm = true;
1856
1857 cfg.feature_flags.enable_vdf = true;
1858 cfg.vdf_verify_vdf_cost = Some(1500);
1861 cfg.vdf_hash_to_input_cost = Some(100);
1862
1863 cfg.feature_flags.passkey_auth = true;
1864 }
1865
1866 for cur in 2..=version.0 {
1867 match cur {
1868 1 => unreachable!(),
1869 2 => {}
1871 3 => {
1872 cfg.feature_flags.relocate_event_module = true;
1873 }
1874 4 => {
1875 cfg.max_type_to_layout_nodes = Some(512);
1876 }
1877 5 => {
1878 cfg.feature_flags.protocol_defined_base_fee = true;
1879 cfg.base_gas_price = Some(1000);
1880
1881 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
1882 cfg.feature_flags.convert_type_argument_error = true;
1883 cfg.feature_flags.native_charging_v2 = true;
1884
1885 if chain != Chain::Mainnet && chain != Chain::Testnet {
1886 cfg.feature_flags.uncompressed_g1_group_elements = true;
1887 }
1888
1889 cfg.gas_model_version = Some(2);
1890
1891 cfg.poseidon_bn254_cost_per_block = Some(388);
1892
1893 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
1894 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
1895 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
1896 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
1897 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
1898 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
1899 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
1900 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
1901
1902 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
1904 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
1905 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
1906 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
1907
1908 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
1909 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
1910 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
1911 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
1912 Some(8213);
1913 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
1914 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
1915 Some(9484);
1916
1917 cfg.hash_keccak256_cost_base = Some(10);
1918 cfg.hash_blake2b256_cost_base = Some(10);
1919
1920 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
1922 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
1923 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
1924 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
1925
1926 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
1927 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
1928 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
1929 cfg.group_ops_bls12381_gt_add_cost = Some(188);
1930
1931 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
1932 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
1933 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
1934 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
1935
1936 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
1937 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
1938 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
1939 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
1940
1941 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
1942 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
1943 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
1944 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
1945
1946 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
1947 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
1948
1949 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
1950 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
1951 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
1952 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
1953
1954 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
1955 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
1956 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
1957 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
1958 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
1959
1960 cfg.group_ops_bls12381_pairing_cost = Some(26897);
1961
1962 cfg.validator_validate_metadata_cost_base = Some(20000);
1963
1964 cfg.max_committee_members_count = Some(50);
1965 }
1966 6 => {
1967 cfg.max_ptb_value_size = Some(1024 * 1024);
1968 }
1969 7 => {}
1971 8 => {
1972 cfg.feature_flags.variant_nodes = true;
1973
1974 if chain != Chain::Mainnet {
1975 cfg.feature_flags.consensus_round_prober = true;
1977 cfg.feature_flags
1979 .consensus_distributed_vote_scoring_strategy = true;
1980 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
1981 cfg.feature_flags.consensus_smart_ancestor_selection = true;
1983 cfg.feature_flags
1985 .consensus_round_prober_probe_accepted_rounds = true;
1986 cfg.feature_flags.consensus_zstd_compression = true;
1988 cfg.consensus_gc_depth = Some(60);
1992 }
1993 if chain != Chain::Testnet && chain != Chain::Mainnet {
1996 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
1997 }
1998 }
1999 9 => {
2000 cfg.feature_flags.consensus_round_prober = true;
2002 cfg.feature_flags
2004 .consensus_distributed_vote_scoring_strategy = true;
2005 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2006 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2008 cfg.feature_flags
2010 .consensus_round_prober_probe_accepted_rounds = true;
2011 cfg.feature_flags.consensus_zstd_compression = true;
2013 cfg.consensus_gc_depth = Some(60);
2017
2018 cfg.max_committee_members_count = Some(80);
2019
2020 if chain != Chain::Testnet && chain != Chain::Mainnet {
2022 cfg.feature_flags.accept_passkey_in_multisig = true;
2023 }
2024 }
2025 _ => panic!("unsupported version {:?}", version),
2036 }
2037 }
2038 cfg
2039 }
2040
2041 pub fn verifier_config(&self, signing_limits: Option<(usize, usize)>) -> VerifierConfig {
2045 let (max_back_edges_per_function, max_back_edges_per_module) = if let Some((
2046 max_back_edges_per_function,
2047 max_back_edges_per_module,
2048 )) = signing_limits
2049 {
2050 (
2051 Some(max_back_edges_per_function),
2052 Some(max_back_edges_per_module),
2053 )
2054 } else {
2055 (None, None)
2056 };
2057
2058 VerifierConfig {
2059 max_loop_depth: Some(self.max_loop_depth() as usize),
2060 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2061 max_function_parameters: Some(self.max_function_parameters() as usize),
2062 max_basic_blocks: Some(self.max_basic_blocks() as usize),
2063 max_value_stack_size: self.max_value_stack_size() as usize,
2064 max_type_nodes: Some(self.max_type_nodes() as usize),
2065 max_push_size: Some(self.max_push_size() as usize),
2066 max_dependency_depth: Some(self.max_dependency_depth() as usize),
2067 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2068 max_function_definitions: Some(self.max_function_definitions() as usize),
2069 max_data_definitions: Some(self.max_struct_definitions() as usize),
2070 max_constant_vector_len: Some(self.max_move_vector_len()),
2071 max_back_edges_per_function,
2072 max_back_edges_per_module,
2073 max_basic_blocks_in_script: None,
2074 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
2078 max_variants_in_enum: self.max_move_enum_variants_as_option(),
2079 }
2080 }
2081
2082 pub fn apply_overrides_for_testing(
2087 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
2088 ) -> OverrideGuard {
2089 CONFIG_OVERRIDE.with(|ovr| {
2090 let mut cur = ovr.borrow_mut();
2091 assert!(cur.is_none(), "config override already present");
2092 *cur = Some(Box::new(override_fn));
2093 OverrideGuard
2094 })
2095 }
2096}
2097
2098impl ProtocolConfig {
2103 pub fn set_zklogin_auth_for_testing(&mut self, val: bool) {
2104 self.feature_flags.zklogin_auth = val
2105 }
2106 pub fn set_enable_jwk_consensus_updates_for_testing(&mut self, val: bool) {
2107 self.feature_flags.enable_jwk_consensus_updates = val
2108 }
2109
2110 pub fn set_accept_zklogin_in_multisig_for_testing(&mut self, val: bool) {
2111 self.feature_flags.accept_zklogin_in_multisig = val
2112 }
2113
2114 pub fn set_per_object_congestion_control_mode_for_testing(
2115 &mut self,
2116 val: PerObjectCongestionControlMode,
2117 ) {
2118 self.feature_flags.per_object_congestion_control_mode = val;
2119 }
2120
2121 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
2122 self.feature_flags.consensus_choice = val;
2123 }
2124
2125 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
2126 self.feature_flags.consensus_network = val;
2127 }
2128
2129 pub fn set_zklogin_max_epoch_upper_bound_delta_for_testing(&mut self, val: Option<u64>) {
2130 self.feature_flags.zklogin_max_epoch_upper_bound_delta = val
2131 }
2132 pub fn set_disable_bridge_for_testing(&mut self) {
2133 self.feature_flags.bridge = false
2134 }
2135
2136 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
2137 self.feature_flags.passkey_auth = val
2138 }
2139
2140 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
2141 self.feature_flags
2142 .disallow_new_modules_in_deps_only_packages = val;
2143 }
2144
2145 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
2146 self.feature_flags.consensus_round_prober = val;
2147 }
2148
2149 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
2150 self.feature_flags
2151 .consensus_distributed_vote_scoring_strategy = val;
2152 }
2153
2154 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
2155 self.consensus_gc_depth = Some(val);
2156 }
2157
2158 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
2159 self.feature_flags.consensus_linearize_subdag_v2 = val;
2160 }
2161
2162 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
2163 self.feature_flags
2164 .consensus_round_prober_probe_accepted_rounds = val;
2165 }
2166
2167 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
2168 self.feature_flags.accept_passkey_in_multisig = val;
2169 }
2170}
2171
2172type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
2173
2174thread_local! {
2175 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
2176}
2177
2178#[must_use]
2179pub struct OverrideGuard;
2180
2181impl Drop for OverrideGuard {
2182 fn drop(&mut self) {
2183 info!("restoring override fn");
2184 CONFIG_OVERRIDE.with(|ovr| {
2185 *ovr.borrow_mut() = None;
2186 });
2187 }
2188}
2189
2190#[derive(PartialEq, Eq)]
2194pub enum LimitThresholdCrossed {
2195 None,
2196 Soft(u128, u128),
2197 Hard(u128, u128),
2198}
2199
2200pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
2203 x: T,
2204 soft_limit: U,
2205 hard_limit: V,
2206) -> LimitThresholdCrossed {
2207 let x: V = x.into();
2208 let soft_limit: V = soft_limit.into();
2209
2210 debug_assert!(soft_limit <= hard_limit);
2211
2212 if x >= hard_limit {
2215 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
2216 } else if x < soft_limit {
2217 LimitThresholdCrossed::None
2218 } else {
2219 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
2220 }
2221}
2222
2223#[macro_export]
2224macro_rules! check_limit {
2225 ($x:expr, $hard:expr) => {
2226 check_limit!($x, $hard, $hard)
2227 };
2228 ($x:expr, $soft:expr, $hard:expr) => {
2229 check_limit_in_range($x as u64, $soft, $hard)
2230 };
2231}
2232
2233#[macro_export]
2237macro_rules! check_limit_by_meter {
2238 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
2239 let (h, metered_str) = if $is_metered {
2241 ($metered_limit, "metered")
2242 } else {
2243 ($unmetered_hard_limit, "unmetered")
2245 };
2246 use iota_protocol_config::check_limit_in_range;
2247 let result = check_limit_in_range($x as u64, $metered_limit, h);
2248 match result {
2249 LimitThresholdCrossed::None => {}
2250 LimitThresholdCrossed::Soft(_, _) => {
2251 $metric.with_label_values(&[metered_str, "soft"]).inc();
2252 }
2253 LimitThresholdCrossed::Hard(_, _) => {
2254 $metric.with_label_values(&[metered_str, "hard"]).inc();
2255 }
2256 };
2257 result
2258 }};
2259}
2260
2261#[cfg(all(test, not(msim)))]
2262mod test {
2263 use insta::assert_yaml_snapshot;
2264
2265 use super::*;
2266
2267 #[test]
2268 fn snapshot_tests() {
2269 println!("\n============================================================================");
2270 println!("! !");
2271 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
2272 println!("! !");
2273 println!("============================================================================\n");
2274 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
2275 let chain_str = match chain_id {
2280 Chain::Unknown => "".to_string(),
2281 _ => format!("{:?}_", chain_id),
2282 };
2283 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
2284 let cur = ProtocolVersion::new(i);
2285 assert_yaml_snapshot!(
2286 format!("{}version_{}", chain_str, cur.as_u64()),
2287 ProtocolConfig::get_for_version(cur, *chain_id)
2288 );
2289 }
2290 }
2291 }
2292
2293 #[test]
2294 fn test_getters() {
2295 let prot: ProtocolConfig =
2296 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2297 assert_eq!(
2298 prot.max_arguments(),
2299 prot.max_arguments_as_option().unwrap()
2300 );
2301 }
2302
2303 #[test]
2304 fn test_setters() {
2305 let mut prot: ProtocolConfig =
2306 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2307 prot.set_max_arguments_for_testing(123);
2308 assert_eq!(prot.max_arguments(), 123);
2309
2310 prot.set_max_arguments_from_str_for_testing("321".to_string());
2311 assert_eq!(prot.max_arguments(), 321);
2312
2313 prot.disable_max_arguments_for_testing();
2314 assert_eq!(prot.max_arguments_as_option(), None);
2315
2316 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
2317 assert_eq!(prot.max_arguments(), 456);
2318 }
2319
2320 #[test]
2321 #[should_panic(expected = "unsupported version")]
2322 fn max_version_test() {
2323 let _ = ProtocolConfig::get_for_version_impl(
2326 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
2327 Chain::Unknown,
2328 );
2329 }
2330
2331 #[test]
2332 fn lookup_by_string_test() {
2333 let prot: ProtocolConfig =
2334 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2335 assert!(prot.lookup_attr("some random string".to_string()).is_none());
2337
2338 assert!(
2339 prot.lookup_attr("max_arguments".to_string())
2340 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
2341 );
2342
2343 assert!(
2345 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2346 .is_none()
2347 );
2348 assert!(
2349 prot.attr_map()
2350 .get("poseidon_bn254_cost_base")
2351 .unwrap()
2352 .is_none()
2353 );
2354
2355 let prot: ProtocolConfig =
2357 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2358
2359 assert!(
2360 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2361 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2362 );
2363 assert!(
2364 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
2365 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2366 );
2367
2368 let prot: ProtocolConfig =
2370 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2371 assert!(
2373 prot.feature_flags
2374 .lookup_attr("some random string".to_owned())
2375 .is_none()
2376 );
2377 assert!(
2378 !prot
2379 .feature_flags
2380 .attr_map()
2381 .contains_key("some random string")
2382 );
2383
2384 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
2386 assert!(
2387 prot.feature_flags
2388 .attr_map()
2389 .get("enable_poseidon")
2390 .unwrap()
2391 == &false
2392 );
2393 let prot: ProtocolConfig =
2394 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2395 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
2397 assert!(
2398 prot.feature_flags
2399 .attr_map()
2400 .get("enable_poseidon")
2401 .unwrap()
2402 == &true
2403 );
2404 }
2405
2406 #[test]
2407 fn limit_range_fn_test() {
2408 let low = 100u32;
2409 let high = 10000u64;
2410
2411 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
2412 assert!(matches!(
2413 check_limit!(255u16, low, high),
2414 LimitThresholdCrossed::Soft(255u128, 100)
2415 ));
2416 assert!(matches!(
2423 check_limit!(2550000u64, low, high),
2424 LimitThresholdCrossed::Hard(2550000, 10000)
2425 ));
2426
2427 assert!(matches!(
2428 check_limit!(2550000u64, high, high),
2429 LimitThresholdCrossed::Hard(2550000, 10000)
2430 ));
2431
2432 assert!(matches!(
2433 check_limit!(1u8, high),
2434 LimitThresholdCrossed::None
2435 ));
2436
2437 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
2438
2439 assert!(matches!(
2440 check_limit!(2550000u64, high),
2441 LimitThresholdCrossed::Hard(2550000, 10000)
2442 ));
2443 }
2444}