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 = 13;
23
24#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
82pub struct ProtocolVersion(u64);
83
84impl ProtocolVersion {
85 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
91
92 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
93
94 #[cfg(not(msim))]
95 const MAX_ALLOWED: Self = Self::MAX;
96
97 #[cfg(msim)]
100 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
101
102 pub fn new(v: u64) -> Self {
103 Self(v)
104 }
105
106 pub const fn as_u64(&self) -> u64 {
107 self.0
108 }
109
110 pub fn max() -> Self {
113 Self::MAX
114 }
115}
116
117impl From<u64> for ProtocolVersion {
118 fn from(v: u64) -> Self {
119 Self::new(v)
120 }
121}
122
123impl std::ops::Sub<u64> for ProtocolVersion {
124 type Output = Self;
125 fn sub(self, rhs: u64) -> Self::Output {
126 Self::new(self.0 - rhs)
127 }
128}
129
130impl std::ops::Add<u64> for ProtocolVersion {
131 type Output = Self;
132 fn add(self, rhs: u64) -> Self::Output {
133 Self::new(self.0 + rhs)
134 }
135}
136
137#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum)]
138pub enum Chain {
139 Mainnet,
140 Testnet,
141 Unknown,
142}
143
144impl Default for Chain {
145 fn default() -> Self {
146 Self::Unknown
147 }
148}
149
150impl Chain {
151 pub fn as_str(self) -> &'static str {
152 match self {
153 Chain::Mainnet => "mainnet",
154 Chain::Testnet => "testnet",
155 Chain::Unknown => "unknown",
156 }
157 }
158}
159
160pub struct Error(pub String);
161
162#[derive(Default, Clone, Serialize, Deserialize, Debug, ProtocolConfigFeatureFlagsGetters)]
166struct FeatureFlags {
167 #[serde(skip_serializing_if = "is_true")]
173 disable_invariant_violation_check_in_swap_loc: bool,
174
175 #[serde(skip_serializing_if = "is_true")]
178 no_extraneous_module_bytes: bool,
179
180 #[serde(skip_serializing_if = "is_false")]
182 zklogin_auth: bool,
183
184 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
186 consensus_transaction_ordering: ConsensusTransactionOrdering,
187
188 #[serde(skip_serializing_if = "is_false")]
189 enable_jwk_consensus_updates: bool,
190
191 #[serde(skip_serializing_if = "is_false")]
193 accept_zklogin_in_multisig: bool,
194
195 #[serde(skip_serializing_if = "is_true")]
198 hardened_otw_check: bool,
199
200 #[serde(skip_serializing_if = "is_false")]
202 enable_poseidon: bool,
203
204 #[serde(skip_serializing_if = "is_false")]
206 enable_group_ops_native_function_msm: bool,
207
208 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
210 per_object_congestion_control_mode: PerObjectCongestionControlMode,
211
212 #[serde(skip_serializing_if = "ConsensusChoice::is_mysticeti")]
214 consensus_choice: ConsensusChoice,
215
216 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
218 consensus_network: ConsensusNetwork,
219
220 #[serde(skip_serializing_if = "Option::is_none")]
222 zklogin_max_epoch_upper_bound_delta: Option<u64>,
223
224 #[serde(skip_serializing_if = "is_false")]
226 enable_vdf: bool,
227
228 #[serde(skip_serializing_if = "is_false")]
230 passkey_auth: bool,
231
232 #[serde(skip_serializing_if = "is_true")]
235 rethrow_serialization_type_layout_errors: bool,
236
237 #[serde(skip_serializing_if = "is_false")]
239 relocate_event_module: bool,
240
241 #[serde(skip_serializing_if = "is_false")]
243 protocol_defined_base_fee: bool,
244
245 #[serde(skip_serializing_if = "is_false")]
247 uncompressed_g1_group_elements: bool,
248
249 #[serde(skip_serializing_if = "is_false")]
251 disallow_new_modules_in_deps_only_packages: bool,
252
253 #[serde(skip_serializing_if = "is_false")]
255 native_charging_v2: bool,
256
257 #[serde(skip_serializing_if = "is_false")]
259 convert_type_argument_error: bool,
260
261 #[serde(skip_serializing_if = "is_false")]
263 consensus_round_prober: bool,
264
265 #[serde(skip_serializing_if = "is_false")]
267 consensus_distributed_vote_scoring_strategy: bool,
268
269 #[serde(skip_serializing_if = "is_false")]
273 consensus_linearize_subdag_v2: bool,
274
275 #[serde(skip_serializing_if = "is_false")]
277 variant_nodes: bool,
278
279 #[serde(skip_serializing_if = "is_false")]
281 consensus_smart_ancestor_selection: bool,
282
283 #[serde(skip_serializing_if = "is_false")]
285 consensus_round_prober_probe_accepted_rounds: bool,
286
287 #[serde(skip_serializing_if = "is_false")]
289 consensus_zstd_compression: bool,
290
291 #[serde(skip_serializing_if = "is_false")]
294 congestion_control_min_free_execution_slot: bool,
295
296 #[serde(skip_serializing_if = "is_false")]
298 accept_passkey_in_multisig: bool,
299
300 #[serde(skip_serializing_if = "is_false")]
302 consensus_batched_block_sync: bool,
303
304 #[serde(skip_serializing_if = "is_false")]
307 congestion_control_gas_price_feedback_mechanism: bool,
308
309 #[serde(skip_serializing_if = "is_false")]
311 validate_identifier_inputs: bool,
312
313 #[serde(skip_serializing_if = "is_false")]
316 minimize_child_object_mutations: bool,
317
318 #[serde(skip_serializing_if = "is_false")]
320 dependency_linkage_error: bool,
321
322 #[serde(skip_serializing_if = "is_false")]
324 additional_multisig_checks: bool,
325
326 #[serde(skip_serializing_if = "is_false")]
329 normalize_ptb_arguments: bool,
330
331 #[serde(skip_serializing_if = "is_false")]
335 select_committee_from_eligible_validators: bool,
336
337 #[serde(skip_serializing_if = "is_false")]
344 track_non_committee_eligible_validators: bool,
345
346 #[serde(skip_serializing_if = "is_false")]
352 select_committee_supporting_next_epoch_version: bool,
353}
354
355fn is_true(b: &bool) -> bool {
356 *b
357}
358
359fn is_false(b: &bool) -> bool {
360 !b
361}
362
363#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
365pub enum ConsensusTransactionOrdering {
366 #[default]
369 None,
370 ByGasPrice,
372}
373
374impl ConsensusTransactionOrdering {
375 pub fn is_none(&self) -> bool {
376 matches!(self, ConsensusTransactionOrdering::None)
377 }
378}
379
380#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
382pub enum PerObjectCongestionControlMode {
383 #[default]
384 None, TotalGasBudget, TotalTxCount, }
388
389impl PerObjectCongestionControlMode {
390 pub fn is_none(&self) -> bool {
391 matches!(self, PerObjectCongestionControlMode::None)
392 }
393}
394
395#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
397pub enum ConsensusChoice {
398 #[default]
399 Mysticeti,
400}
401
402impl ConsensusChoice {
403 pub fn is_mysticeti(&self) -> bool {
404 matches!(self, ConsensusChoice::Mysticeti)
405 }
406}
407
408#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
410pub enum ConsensusNetwork {
411 #[default]
412 Tonic,
413}
414
415impl ConsensusNetwork {
416 pub fn is_tonic(&self) -> bool {
417 matches!(self, ConsensusNetwork::Tonic)
418 }
419}
420
421#[skip_serializing_none]
455#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
456pub struct ProtocolConfig {
457 pub version: ProtocolVersion,
458
459 feature_flags: FeatureFlags,
460
461 max_tx_size_bytes: Option<u64>,
466
467 max_input_objects: Option<u64>,
470
471 max_size_written_objects: Option<u64>,
476 max_size_written_objects_system_tx: Option<u64>,
480
481 max_serialized_tx_effects_size_bytes: Option<u64>,
483
484 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
486
487 max_gas_payment_objects: Option<u32>,
489
490 max_modules_in_publish: Option<u32>,
492
493 max_package_dependencies: Option<u32>,
495
496 max_arguments: Option<u32>,
499
500 max_type_arguments: Option<u32>,
502
503 max_type_argument_depth: Option<u32>,
505
506 max_pure_argument_size: Option<u32>,
508
509 max_programmable_tx_commands: Option<u32>,
511
512 move_binary_format_version: Option<u32>,
518 min_move_binary_format_version: Option<u32>,
519
520 binary_module_handles: Option<u16>,
522 binary_struct_handles: Option<u16>,
523 binary_function_handles: Option<u16>,
524 binary_function_instantiations: Option<u16>,
525 binary_signatures: Option<u16>,
526 binary_constant_pool: Option<u16>,
527 binary_identifiers: Option<u16>,
528 binary_address_identifiers: Option<u16>,
529 binary_struct_defs: Option<u16>,
530 binary_struct_def_instantiations: Option<u16>,
531 binary_function_defs: Option<u16>,
532 binary_field_handles: Option<u16>,
533 binary_field_instantiations: Option<u16>,
534 binary_friend_decls: Option<u16>,
535 binary_enum_defs: Option<u16>,
536 binary_enum_def_instantiations: Option<u16>,
537 binary_variant_handles: Option<u16>,
538 binary_variant_instantiation_handles: Option<u16>,
539
540 max_move_object_size: Option<u64>,
543
544 max_move_package_size: Option<u64>,
549
550 max_publish_or_upgrade_per_ptb: Option<u64>,
553
554 max_tx_gas: Option<u64>,
556
557 max_gas_price: Option<u64>,
560
561 max_gas_computation_bucket: Option<u64>,
564
565 gas_rounding_step: Option<u64>,
567
568 max_loop_depth: Option<u64>,
570
571 max_generic_instantiation_length: Option<u64>,
574
575 max_function_parameters: Option<u64>,
578
579 max_basic_blocks: Option<u64>,
582
583 max_value_stack_size: Option<u64>,
585
586 max_type_nodes: Option<u64>,
590
591 max_push_size: Option<u64>,
594
595 max_struct_definitions: Option<u64>,
598
599 max_function_definitions: Option<u64>,
602
603 max_fields_in_struct: Option<u64>,
606
607 max_dependency_depth: Option<u64>,
610
611 max_num_event_emit: Option<u64>,
614
615 max_num_new_move_object_ids: Option<u64>,
618
619 max_num_new_move_object_ids_system_tx: Option<u64>,
622
623 max_num_deleted_move_object_ids: Option<u64>,
626
627 max_num_deleted_move_object_ids_system_tx: Option<u64>,
630
631 max_num_transferred_move_object_ids: Option<u64>,
634
635 max_num_transferred_move_object_ids_system_tx: Option<u64>,
638
639 max_event_emit_size: Option<u64>,
641
642 max_event_emit_size_total: Option<u64>,
644
645 max_move_vector_len: Option<u64>,
648
649 max_move_identifier_len: Option<u64>,
652
653 max_move_value_depth: Option<u64>,
655
656 max_move_enum_variants: Option<u64>,
659
660 max_back_edges_per_function: Option<u64>,
663
664 max_back_edges_per_module: Option<u64>,
667
668 max_verifier_meter_ticks_per_function: Option<u64>,
671
672 max_meter_ticks_per_module: Option<u64>,
675
676 max_meter_ticks_per_package: Option<u64>,
679
680 object_runtime_max_num_cached_objects: Option<u64>,
687
688 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
691
692 object_runtime_max_num_store_entries: Option<u64>,
695
696 object_runtime_max_num_store_entries_system_tx: Option<u64>,
699
700 base_tx_cost_fixed: Option<u64>,
705
706 package_publish_cost_fixed: Option<u64>,
710
711 base_tx_cost_per_byte: Option<u64>,
715
716 package_publish_cost_per_byte: Option<u64>,
718
719 obj_access_cost_read_per_byte: Option<u64>,
721
722 obj_access_cost_mutate_per_byte: Option<u64>,
724
725 obj_access_cost_delete_per_byte: Option<u64>,
727
728 obj_access_cost_verify_per_byte: Option<u64>,
738
739 max_type_to_layout_nodes: Option<u64>,
741
742 max_ptb_value_size: Option<u64>,
744
745 gas_model_version: Option<u64>,
750
751 obj_data_cost_refundable: Option<u64>,
757
758 obj_metadata_cost_non_refundable: Option<u64>,
762
763 storage_rebate_rate: Option<u64>,
769
770 reward_slashing_rate: Option<u64>,
773
774 storage_gas_price: Option<u64>,
776
777 base_gas_price: Option<u64>,
779
780 validator_target_reward: Option<u64>,
782
783 max_transactions_per_checkpoint: Option<u64>,
790
791 max_checkpoint_size_bytes: Option<u64>,
795
796 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
802
803 address_from_bytes_cost_base: Option<u64>,
808 address_to_u256_cost_base: Option<u64>,
810 address_from_u256_cost_base: Option<u64>,
812
813 config_read_setting_impl_cost_base: Option<u64>,
818 config_read_setting_impl_cost_per_byte: Option<u64>,
819
820 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
824 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
825 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
826 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
827 dynamic_field_add_child_object_cost_base: Option<u64>,
830 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
831 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
832 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
833 dynamic_field_borrow_child_object_cost_base: Option<u64>,
836 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
837 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
838 dynamic_field_remove_child_object_cost_base: Option<u64>,
841 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
842 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
843 dynamic_field_has_child_object_cost_base: Option<u64>,
846 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
849 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
850 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
851
852 event_emit_cost_base: Option<u64>,
855 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
856 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
857 event_emit_output_cost_per_byte: Option<u64>,
858
859 object_borrow_uid_cost_base: Option<u64>,
862 object_delete_impl_cost_base: Option<u64>,
864 object_record_new_uid_cost_base: Option<u64>,
866
867 transfer_transfer_internal_cost_base: Option<u64>,
870 transfer_freeze_object_cost_base: Option<u64>,
872 transfer_share_object_cost_base: Option<u64>,
874 transfer_receive_object_cost_base: Option<u64>,
877
878 tx_context_derive_id_cost_base: Option<u64>,
881
882 types_is_one_time_witness_cost_base: Option<u64>,
885 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
886 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
887
888 validator_validate_metadata_cost_base: Option<u64>,
891 validator_validate_metadata_data_cost_per_byte: Option<u64>,
892
893 crypto_invalid_arguments_cost: Option<u64>,
895 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
897 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
898 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
899
900 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
902 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
903 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
904
905 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
907 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
908 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
909 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
910 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
911 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
912
913 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
915
916 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
918 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
919 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
920 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
921 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
922 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
923
924 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
926 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
927 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
928 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
929 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
930 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
931
932 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
934 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
935 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
936 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
937 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
938 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
939
940 ecvrf_ecvrf_verify_cost_base: Option<u64>,
942 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
943 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
944
945 ed25519_ed25519_verify_cost_base: Option<u64>,
947 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
948 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
949
950 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
952 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
953
954 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
956 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
957 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
958 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
959 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
960
961 hash_blake2b256_cost_base: Option<u64>,
963 hash_blake2b256_data_cost_per_byte: Option<u64>,
964 hash_blake2b256_data_cost_per_block: Option<u64>,
965
966 hash_keccak256_cost_base: Option<u64>,
968 hash_keccak256_data_cost_per_byte: Option<u64>,
969 hash_keccak256_data_cost_per_block: Option<u64>,
970
971 poseidon_bn254_cost_base: Option<u64>,
973 poseidon_bn254_cost_per_block: Option<u64>,
974
975 group_ops_bls12381_decode_scalar_cost: Option<u64>,
977 group_ops_bls12381_decode_g1_cost: Option<u64>,
978 group_ops_bls12381_decode_g2_cost: Option<u64>,
979 group_ops_bls12381_decode_gt_cost: Option<u64>,
980 group_ops_bls12381_scalar_add_cost: Option<u64>,
981 group_ops_bls12381_g1_add_cost: Option<u64>,
982 group_ops_bls12381_g2_add_cost: Option<u64>,
983 group_ops_bls12381_gt_add_cost: Option<u64>,
984 group_ops_bls12381_scalar_sub_cost: Option<u64>,
985 group_ops_bls12381_g1_sub_cost: Option<u64>,
986 group_ops_bls12381_g2_sub_cost: Option<u64>,
987 group_ops_bls12381_gt_sub_cost: Option<u64>,
988 group_ops_bls12381_scalar_mul_cost: Option<u64>,
989 group_ops_bls12381_g1_mul_cost: Option<u64>,
990 group_ops_bls12381_g2_mul_cost: Option<u64>,
991 group_ops_bls12381_gt_mul_cost: Option<u64>,
992 group_ops_bls12381_scalar_div_cost: Option<u64>,
993 group_ops_bls12381_g1_div_cost: Option<u64>,
994 group_ops_bls12381_g2_div_cost: Option<u64>,
995 group_ops_bls12381_gt_div_cost: Option<u64>,
996 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
997 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
998 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
999 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1000 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1001 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1002 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1003 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1004 group_ops_bls12381_msm_max_len: Option<u32>,
1005 group_ops_bls12381_pairing_cost: Option<u64>,
1006 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1007 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1008 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1009 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1010 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1011
1012 hmac_hmac_sha3_256_cost_base: Option<u64>,
1014 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1015 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1016
1017 check_zklogin_id_cost_base: Option<u64>,
1019 check_zklogin_issuer_cost_base: Option<u64>,
1021
1022 vdf_verify_vdf_cost: Option<u64>,
1023 vdf_hash_to_input_cost: Option<u64>,
1024
1025 bcs_per_byte_serialized_cost: Option<u64>,
1027 bcs_legacy_min_output_size_cost: Option<u64>,
1028 bcs_failure_cost: Option<u64>,
1029
1030 hash_sha2_256_base_cost: Option<u64>,
1031 hash_sha2_256_per_byte_cost: Option<u64>,
1032 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1033 hash_sha3_256_base_cost: Option<u64>,
1034 hash_sha3_256_per_byte_cost: Option<u64>,
1035 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1036 type_name_get_base_cost: Option<u64>,
1037 type_name_get_per_byte_cost: Option<u64>,
1038
1039 string_check_utf8_base_cost: Option<u64>,
1040 string_check_utf8_per_byte_cost: Option<u64>,
1041 string_is_char_boundary_base_cost: Option<u64>,
1042 string_sub_string_base_cost: Option<u64>,
1043 string_sub_string_per_byte_cost: Option<u64>,
1044 string_index_of_base_cost: Option<u64>,
1045 string_index_of_per_byte_pattern_cost: Option<u64>,
1046 string_index_of_per_byte_searched_cost: Option<u64>,
1047
1048 vector_empty_base_cost: Option<u64>,
1049 vector_length_base_cost: Option<u64>,
1050 vector_push_back_base_cost: Option<u64>,
1051 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1052 vector_borrow_base_cost: Option<u64>,
1053 vector_pop_back_base_cost: Option<u64>,
1054 vector_destroy_empty_base_cost: Option<u64>,
1055 vector_swap_base_cost: Option<u64>,
1056 debug_print_base_cost: Option<u64>,
1057 debug_print_stack_trace_base_cost: Option<u64>,
1058
1059 execution_version: Option<u64>,
1061
1062 consensus_bad_nodes_stake_threshold: Option<u64>,
1066
1067 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1068 max_age_of_jwk_in_epochs: Option<u64>,
1072
1073 random_beacon_reduction_allowed_delta: Option<u16>,
1077
1078 random_beacon_reduction_lower_bound: Option<u32>,
1081
1082 random_beacon_dkg_timeout_round: Option<u32>,
1085
1086 random_beacon_min_round_interval_ms: Option<u64>,
1088
1089 random_beacon_dkg_version: Option<u64>,
1093
1094 consensus_max_transaction_size_bytes: Option<u64>,
1099 consensus_max_transactions_in_block_bytes: Option<u64>,
1101 consensus_max_num_transactions_in_block: Option<u64>,
1103
1104 max_deferral_rounds_for_congestion_control: Option<u64>,
1108
1109 min_checkpoint_interval_ms: Option<u64>,
1111
1112 checkpoint_summary_version_specific_data: Option<u64>,
1114
1115 max_soft_bundle_size: Option<u64>,
1118
1119 bridge_should_try_to_finalize_committee: Option<bool>,
1124
1125 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1129
1130 max_committee_members_count: Option<u64>,
1134
1135 consensus_gc_depth: Option<u32>,
1138
1139 consensus_max_acknowledgments_per_block: Option<u32>,
1145}
1146
1147impl ProtocolConfig {
1149 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1162 self.feature_flags
1163 .disable_invariant_violation_check_in_swap_loc
1164 }
1165
1166 pub fn no_extraneous_module_bytes(&self) -> bool {
1167 self.feature_flags.no_extraneous_module_bytes
1168 }
1169
1170 pub fn zklogin_auth(&self) -> bool {
1171 self.feature_flags.zklogin_auth
1172 }
1173
1174 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1175 self.feature_flags.consensus_transaction_ordering
1176 }
1177
1178 pub fn enable_jwk_consensus_updates(&self) -> bool {
1179 self.feature_flags.enable_jwk_consensus_updates
1180 }
1181
1182 pub fn create_authenticator_state_in_genesis(&self) -> bool {
1184 self.enable_jwk_consensus_updates()
1185 }
1186
1187 pub fn dkg_version(&self) -> u64 {
1188 self.random_beacon_dkg_version.unwrap_or(1)
1190 }
1191
1192 pub fn accept_zklogin_in_multisig(&self) -> bool {
1193 self.feature_flags.accept_zklogin_in_multisig
1194 }
1195
1196 pub fn zklogin_max_epoch_upper_bound_delta(&self) -> Option<u64> {
1197 self.feature_flags.zklogin_max_epoch_upper_bound_delta
1198 }
1199
1200 pub fn hardened_otw_check(&self) -> bool {
1201 self.feature_flags.hardened_otw_check
1202 }
1203
1204 pub fn enable_poseidon(&self) -> bool {
1205 self.feature_flags.enable_poseidon
1206 }
1207
1208 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1209 self.feature_flags.enable_group_ops_native_function_msm
1210 }
1211
1212 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1213 self.feature_flags.per_object_congestion_control_mode
1214 }
1215
1216 pub fn consensus_choice(&self) -> ConsensusChoice {
1217 self.feature_flags.consensus_choice
1218 }
1219
1220 pub fn consensus_network(&self) -> ConsensusNetwork {
1221 self.feature_flags.consensus_network
1222 }
1223
1224 pub fn enable_vdf(&self) -> bool {
1225 self.feature_flags.enable_vdf
1226 }
1227
1228 pub fn passkey_auth(&self) -> bool {
1229 self.feature_flags.passkey_auth
1230 }
1231
1232 pub fn max_transaction_size_bytes(&self) -> u64 {
1233 self.consensus_max_transaction_size_bytes
1235 .unwrap_or(256 * 1024)
1236 }
1237
1238 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1239 if cfg!(msim) {
1240 256 * 1024
1241 } else {
1242 self.consensus_max_transactions_in_block_bytes
1243 .unwrap_or(512 * 1024)
1244 }
1245 }
1246
1247 pub fn max_num_transactions_in_block(&self) -> u64 {
1248 if cfg!(msim) {
1249 8
1250 } else {
1251 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1252 }
1253 }
1254
1255 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1256 self.feature_flags.rethrow_serialization_type_layout_errors
1257 }
1258
1259 pub fn relocate_event_module(&self) -> bool {
1260 self.feature_flags.relocate_event_module
1261 }
1262
1263 pub fn protocol_defined_base_fee(&self) -> bool {
1264 self.feature_flags.protocol_defined_base_fee
1265 }
1266
1267 pub fn uncompressed_g1_group_elements(&self) -> bool {
1268 self.feature_flags.uncompressed_g1_group_elements
1269 }
1270
1271 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1272 self.feature_flags
1273 .disallow_new_modules_in_deps_only_packages
1274 }
1275
1276 pub fn native_charging_v2(&self) -> bool {
1277 self.feature_flags.native_charging_v2
1278 }
1279
1280 pub fn consensus_round_prober(&self) -> bool {
1281 self.feature_flags.consensus_round_prober
1282 }
1283
1284 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1285 self.feature_flags
1286 .consensus_distributed_vote_scoring_strategy
1287 }
1288
1289 pub fn gc_depth(&self) -> u32 {
1290 if cfg!(msim) {
1291 min(5, self.consensus_gc_depth.unwrap_or(0))
1293 } else {
1294 self.consensus_gc_depth.unwrap_or(0)
1295 }
1296 }
1297
1298 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1299 let res = self.feature_flags.consensus_linearize_subdag_v2;
1300 assert!(
1301 !res || self.gc_depth() > 0,
1302 "The consensus linearize sub dag V2 requires GC to be enabled"
1303 );
1304 res
1305 }
1306
1307 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1308 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1309 }
1310
1311 pub fn variant_nodes(&self) -> bool {
1312 self.feature_flags.variant_nodes
1313 }
1314
1315 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1316 self.feature_flags.consensus_smart_ancestor_selection
1317 }
1318
1319 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1320 self.feature_flags
1321 .consensus_round_prober_probe_accepted_rounds
1322 }
1323
1324 pub fn consensus_zstd_compression(&self) -> bool {
1325 self.feature_flags.consensus_zstd_compression
1326 }
1327
1328 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1329 self.feature_flags
1330 .congestion_control_min_free_execution_slot
1331 }
1332
1333 pub fn accept_passkey_in_multisig(&self) -> bool {
1334 self.feature_flags.accept_passkey_in_multisig
1335 }
1336
1337 pub fn consensus_batched_block_sync(&self) -> bool {
1338 self.feature_flags.consensus_batched_block_sync
1339 }
1340
1341 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1344 self.feature_flags
1345 .congestion_control_gas_price_feedback_mechanism
1346 }
1347
1348 pub fn validate_identifier_inputs(&self) -> bool {
1349 self.feature_flags.validate_identifier_inputs
1350 }
1351
1352 pub fn minimize_child_object_mutations(&self) -> bool {
1353 self.feature_flags.minimize_child_object_mutations
1354 }
1355
1356 pub fn dependency_linkage_error(&self) -> bool {
1357 self.feature_flags.dependency_linkage_error
1358 }
1359
1360 pub fn additional_multisig_checks(&self) -> bool {
1361 self.feature_flags.additional_multisig_checks
1362 }
1363
1364 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1365 0
1368 }
1369
1370 pub fn normalize_ptb_arguments(&self) -> bool {
1371 self.feature_flags.normalize_ptb_arguments
1372 }
1373
1374 pub fn select_committee_from_eligible_validators(&self) -> bool {
1375 let res = self.feature_flags.select_committee_from_eligible_validators;
1376 assert!(
1377 !res || (self.protocol_defined_base_fee()
1378 && self.max_committee_members_count_as_option().is_some()),
1379 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1380 );
1381 res
1382 }
1383
1384 pub fn track_non_committee_eligible_validators(&self) -> bool {
1385 self.feature_flags.track_non_committee_eligible_validators
1386 }
1387
1388 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1389 let res = self
1390 .feature_flags
1391 .select_committee_supporting_next_epoch_version;
1392 assert!(
1393 !res || (self.track_non_committee_eligible_validators()
1394 && self.select_committee_from_eligible_validators()),
1395 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1396 );
1397 res
1398 }
1399}
1400
1401#[cfg(not(msim))]
1402static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1403
1404#[cfg(msim)]
1406thread_local! {
1407 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1408}
1409
1410impl ProtocolConfig {
1412 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1415 assert!(
1417 version >= ProtocolVersion::MIN,
1418 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1419 version,
1420 ProtocolVersion::MIN.0,
1421 );
1422 assert!(
1423 version <= ProtocolVersion::MAX_ALLOWED,
1424 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1425 version,
1426 ProtocolVersion::MAX_ALLOWED.0,
1427 );
1428
1429 let mut ret = Self::get_for_version_impl(version, chain);
1430 ret.version = version;
1431
1432 ret = CONFIG_OVERRIDE.with(|ovr| {
1433 if let Some(override_fn) = &*ovr.borrow() {
1434 warn!(
1435 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1436 );
1437 override_fn(version, ret)
1438 } else {
1439 ret
1440 }
1441 });
1442
1443 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1444 warn!(
1445 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1446 );
1447 let overrides: ProtocolConfigOptional =
1448 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1449 .expect("failed to parse ProtocolConfig override env variables");
1450 overrides.apply_to(&mut ret);
1451 }
1452
1453 ret
1454 }
1455
1456 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1459 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1460 let mut ret = Self::get_for_version_impl(version, chain);
1461 ret.version = version;
1462 Some(ret)
1463 } else {
1464 None
1465 }
1466 }
1467
1468 #[cfg(not(msim))]
1469 pub fn poison_get_for_min_version() {
1470 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1471 }
1472
1473 #[cfg(not(msim))]
1474 fn load_poison_get_for_min_version() -> bool {
1475 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1476 }
1477
1478 #[cfg(msim)]
1479 pub fn poison_get_for_min_version() {
1480 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1481 }
1482
1483 #[cfg(msim)]
1484 fn load_poison_get_for_min_version() -> bool {
1485 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1486 }
1487
1488 pub fn convert_type_argument_error(&self) -> bool {
1489 self.feature_flags.convert_type_argument_error
1490 }
1491
1492 pub fn get_for_min_version() -> Self {
1496 if Self::load_poison_get_for_min_version() {
1497 panic!("get_for_min_version called on validator");
1498 }
1499 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1500 }
1501
1502 #[expect(non_snake_case)]
1513 pub fn get_for_max_version_UNSAFE() -> Self {
1514 if Self::load_poison_get_for_min_version() {
1515 panic!("get_for_max_version_UNSAFE called on validator");
1516 }
1517 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1518 }
1519
1520 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1521 #[cfg(msim)]
1522 {
1523 if version > ProtocolVersion::MAX {
1525 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1526 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1527 return config;
1528 }
1529 }
1530
1531 let mut cfg = Self {
1535 version,
1536
1537 feature_flags: Default::default(),
1538
1539 max_tx_size_bytes: Some(128 * 1024),
1540 max_input_objects: Some(2048),
1543 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1544 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1545 max_gas_payment_objects: Some(256),
1546 max_modules_in_publish: Some(64),
1547 max_package_dependencies: Some(32),
1548 max_arguments: Some(512),
1549 max_type_arguments: Some(16),
1550 max_type_argument_depth: Some(16),
1551 max_pure_argument_size: Some(16 * 1024),
1552 max_programmable_tx_commands: Some(1024),
1553 move_binary_format_version: Some(7),
1554 min_move_binary_format_version: Some(6),
1555 binary_module_handles: Some(100),
1556 binary_struct_handles: Some(300),
1557 binary_function_handles: Some(1500),
1558 binary_function_instantiations: Some(750),
1559 binary_signatures: Some(1000),
1560 binary_constant_pool: Some(4000),
1561 binary_identifiers: Some(10000),
1562 binary_address_identifiers: Some(100),
1563 binary_struct_defs: Some(200),
1564 binary_struct_def_instantiations: Some(100),
1565 binary_function_defs: Some(1000),
1566 binary_field_handles: Some(500),
1567 binary_field_instantiations: Some(250),
1568 binary_friend_decls: Some(100),
1569 binary_enum_defs: None,
1570 binary_enum_def_instantiations: None,
1571 binary_variant_handles: None,
1572 binary_variant_instantiation_handles: None,
1573 max_move_object_size: Some(250 * 1024),
1574 max_move_package_size: Some(100 * 1024),
1575 max_publish_or_upgrade_per_ptb: Some(5),
1576 max_tx_gas: Some(50_000_000_000),
1578 max_gas_price: Some(100_000),
1579 max_gas_computation_bucket: Some(5_000_000),
1580 max_loop_depth: Some(5),
1581 max_generic_instantiation_length: Some(32),
1582 max_function_parameters: Some(128),
1583 max_basic_blocks: Some(1024),
1584 max_value_stack_size: Some(1024),
1585 max_type_nodes: Some(256),
1586 max_push_size: Some(10000),
1587 max_struct_definitions: Some(200),
1588 max_function_definitions: Some(1000),
1589 max_fields_in_struct: Some(32),
1590 max_dependency_depth: Some(100),
1591 max_num_event_emit: Some(1024),
1592 max_num_new_move_object_ids: Some(2048),
1593 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1594 max_num_deleted_move_object_ids: Some(2048),
1595 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1596 max_num_transferred_move_object_ids: Some(2048),
1597 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1598 max_event_emit_size: Some(250 * 1024),
1599 max_move_vector_len: Some(256 * 1024),
1600 max_type_to_layout_nodes: None,
1601 max_ptb_value_size: None,
1602
1603 max_back_edges_per_function: Some(10_000),
1604 max_back_edges_per_module: Some(10_000),
1605
1606 max_verifier_meter_ticks_per_function: Some(16_000_000),
1607
1608 max_meter_ticks_per_module: Some(16_000_000),
1609 max_meter_ticks_per_package: Some(16_000_000),
1610
1611 object_runtime_max_num_cached_objects: Some(1000),
1612 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
1613 object_runtime_max_num_store_entries: Some(1000),
1614 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
1615 base_tx_cost_fixed: Some(1_000),
1617 package_publish_cost_fixed: Some(1_000),
1618 base_tx_cost_per_byte: Some(0),
1619 package_publish_cost_per_byte: Some(80),
1620 obj_access_cost_read_per_byte: Some(15),
1621 obj_access_cost_mutate_per_byte: Some(40),
1622 obj_access_cost_delete_per_byte: Some(40),
1623 obj_access_cost_verify_per_byte: Some(200),
1624 obj_data_cost_refundable: Some(100),
1625 obj_metadata_cost_non_refundable: Some(50),
1626 gas_model_version: Some(1),
1627 storage_rebate_rate: Some(10000),
1628 reward_slashing_rate: Some(10000),
1630 storage_gas_price: Some(76),
1631 base_gas_price: None,
1632 validator_target_reward: Some(767_000 * 1_000_000_000),
1635 max_transactions_per_checkpoint: Some(10_000),
1636 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
1637
1638 buffer_stake_for_protocol_upgrade_bps: Some(5000),
1640
1641 address_from_bytes_cost_base: Some(52),
1645 address_to_u256_cost_base: Some(52),
1647 address_from_u256_cost_base: Some(52),
1649
1650 config_read_setting_impl_cost_base: Some(100),
1653 config_read_setting_impl_cost_per_byte: Some(40),
1654
1655 dynamic_field_hash_type_and_key_cost_base: Some(100),
1659 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
1660 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
1661 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
1662 dynamic_field_add_child_object_cost_base: Some(100),
1665 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
1666 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
1667 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
1668 dynamic_field_borrow_child_object_cost_base: Some(100),
1671 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
1672 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
1673 dynamic_field_remove_child_object_cost_base: Some(100),
1676 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
1677 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
1678 dynamic_field_has_child_object_cost_base: Some(100),
1681 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
1684 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
1685 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
1686
1687 event_emit_cost_base: Some(52),
1690 event_emit_value_size_derivation_cost_per_byte: Some(2),
1691 event_emit_tag_size_derivation_cost_per_byte: Some(5),
1692 event_emit_output_cost_per_byte: Some(10),
1693
1694 object_borrow_uid_cost_base: Some(52),
1697 object_delete_impl_cost_base: Some(52),
1699 object_record_new_uid_cost_base: Some(52),
1701
1702 transfer_transfer_internal_cost_base: Some(52),
1706 transfer_freeze_object_cost_base: Some(52),
1708 transfer_share_object_cost_base: Some(52),
1710 transfer_receive_object_cost_base: Some(52),
1711
1712 tx_context_derive_id_cost_base: Some(52),
1716
1717 types_is_one_time_witness_cost_base: Some(52),
1720 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
1721 types_is_one_time_witness_type_cost_per_byte: Some(2),
1722
1723 validator_validate_metadata_cost_base: Some(52),
1727 validator_validate_metadata_data_cost_per_byte: Some(2),
1728
1729 crypto_invalid_arguments_cost: Some(100),
1731 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
1733 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
1734 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
1735
1736 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
1738 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
1739 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
1740
1741 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
1743 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1744 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1745 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
1746 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1747 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
1748
1749 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
1751
1752 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
1754 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
1755 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
1756 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
1757 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
1758 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
1759
1760 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
1762 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1763 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1764 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
1765 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1766 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
1767
1768 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
1770 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
1771 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
1772 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
1773 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
1774 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
1775
1776 ecvrf_ecvrf_verify_cost_base: Some(52),
1778 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
1779 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
1780
1781 ed25519_ed25519_verify_cost_base: Some(52),
1783 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
1784 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
1785
1786 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
1788 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
1789
1790 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
1792 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
1793 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
1794 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
1795 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
1796
1797 hash_blake2b256_cost_base: Some(52),
1799 hash_blake2b256_data_cost_per_byte: Some(2),
1800 hash_blake2b256_data_cost_per_block: Some(2),
1801 hash_keccak256_cost_base: Some(52),
1803 hash_keccak256_data_cost_per_byte: Some(2),
1804 hash_keccak256_data_cost_per_block: Some(2),
1805
1806 poseidon_bn254_cost_base: None,
1807 poseidon_bn254_cost_per_block: None,
1808
1809 hmac_hmac_sha3_256_cost_base: Some(52),
1811 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
1812 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
1813
1814 group_ops_bls12381_decode_scalar_cost: Some(52),
1816 group_ops_bls12381_decode_g1_cost: Some(52),
1817 group_ops_bls12381_decode_g2_cost: Some(52),
1818 group_ops_bls12381_decode_gt_cost: Some(52),
1819 group_ops_bls12381_scalar_add_cost: Some(52),
1820 group_ops_bls12381_g1_add_cost: Some(52),
1821 group_ops_bls12381_g2_add_cost: Some(52),
1822 group_ops_bls12381_gt_add_cost: Some(52),
1823 group_ops_bls12381_scalar_sub_cost: Some(52),
1824 group_ops_bls12381_g1_sub_cost: Some(52),
1825 group_ops_bls12381_g2_sub_cost: Some(52),
1826 group_ops_bls12381_gt_sub_cost: Some(52),
1827 group_ops_bls12381_scalar_mul_cost: Some(52),
1828 group_ops_bls12381_g1_mul_cost: Some(52),
1829 group_ops_bls12381_g2_mul_cost: Some(52),
1830 group_ops_bls12381_gt_mul_cost: Some(52),
1831 group_ops_bls12381_scalar_div_cost: Some(52),
1832 group_ops_bls12381_g1_div_cost: Some(52),
1833 group_ops_bls12381_g2_div_cost: Some(52),
1834 group_ops_bls12381_gt_div_cost: Some(52),
1835 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
1836 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
1837 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
1838 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
1839 group_ops_bls12381_g1_msm_base_cost: Some(52),
1840 group_ops_bls12381_g2_msm_base_cost: Some(52),
1841 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
1842 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
1843 group_ops_bls12381_msm_max_len: Some(32),
1844 group_ops_bls12381_pairing_cost: Some(52),
1845 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
1846 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
1847 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
1848 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
1849 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
1850
1851 check_zklogin_id_cost_base: Some(200),
1853 check_zklogin_issuer_cost_base: Some(200),
1855
1856 vdf_verify_vdf_cost: None,
1857 vdf_hash_to_input_cost: None,
1858
1859 bcs_per_byte_serialized_cost: Some(2),
1860 bcs_legacy_min_output_size_cost: Some(1),
1861 bcs_failure_cost: Some(52),
1862 hash_sha2_256_base_cost: Some(52),
1863 hash_sha2_256_per_byte_cost: Some(2),
1864 hash_sha2_256_legacy_min_input_len_cost: Some(1),
1865 hash_sha3_256_base_cost: Some(52),
1866 hash_sha3_256_per_byte_cost: Some(2),
1867 hash_sha3_256_legacy_min_input_len_cost: Some(1),
1868 type_name_get_base_cost: Some(52),
1869 type_name_get_per_byte_cost: Some(2),
1870 string_check_utf8_base_cost: Some(52),
1871 string_check_utf8_per_byte_cost: Some(2),
1872 string_is_char_boundary_base_cost: Some(52),
1873 string_sub_string_base_cost: Some(52),
1874 string_sub_string_per_byte_cost: Some(2),
1875 string_index_of_base_cost: Some(52),
1876 string_index_of_per_byte_pattern_cost: Some(2),
1877 string_index_of_per_byte_searched_cost: Some(2),
1878 vector_empty_base_cost: Some(52),
1879 vector_length_base_cost: Some(52),
1880 vector_push_back_base_cost: Some(52),
1881 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
1882 vector_borrow_base_cost: Some(52),
1883 vector_pop_back_base_cost: Some(52),
1884 vector_destroy_empty_base_cost: Some(52),
1885 vector_swap_base_cost: Some(52),
1886 debug_print_base_cost: Some(52),
1887 debug_print_stack_trace_base_cost: Some(52),
1888
1889 max_size_written_objects: Some(5 * 1000 * 1000),
1890 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
1893
1894 max_move_identifier_len: Some(128),
1896 max_move_value_depth: Some(128),
1897 max_move_enum_variants: None,
1898
1899 gas_rounding_step: Some(1_000),
1900
1901 execution_version: Some(1),
1902
1903 max_event_emit_size_total: Some(
1906 256 * 250 * 1024, ),
1908
1909 consensus_bad_nodes_stake_threshold: Some(20),
1916
1917 max_jwk_votes_per_validator_per_epoch: Some(240),
1919
1920 max_age_of_jwk_in_epochs: Some(1),
1921
1922 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
1926
1927 random_beacon_reduction_allowed_delta: Some(800),
1928
1929 random_beacon_reduction_lower_bound: Some(1000),
1930 random_beacon_dkg_timeout_round: Some(3000),
1931 random_beacon_min_round_interval_ms: Some(500),
1932
1933 random_beacon_dkg_version: Some(1),
1934
1935 consensus_max_num_transactions_in_block: Some(512),
1939
1940 max_deferral_rounds_for_congestion_control: Some(10),
1941
1942 min_checkpoint_interval_ms: Some(200),
1943
1944 checkpoint_summary_version_specific_data: Some(1),
1945
1946 max_soft_bundle_size: Some(5),
1947
1948 bridge_should_try_to_finalize_committee: None,
1949
1950 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
1951
1952 max_committee_members_count: None,
1953
1954 consensus_gc_depth: None,
1955
1956 consensus_max_acknowledgments_per_block: None,
1957 };
1960
1961 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
1962
1963 {
1965 cfg.feature_flags
1966 .disable_invariant_violation_check_in_swap_loc = true;
1967 cfg.feature_flags.no_extraneous_module_bytes = true;
1968 cfg.feature_flags.hardened_otw_check = true;
1969 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
1970 }
1971
1972 {
1974 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
1975 }
1976
1977 cfg.feature_flags.consensus_choice = ConsensusChoice::Mysticeti;
1979 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
1981
1982 cfg.feature_flags.per_object_congestion_control_mode =
1983 PerObjectCongestionControlMode::TotalTxCount;
1984
1985 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
1987
1988 if chain != Chain::Mainnet && chain != Chain::Testnet {
1990 cfg.feature_flags.enable_poseidon = true;
1991 cfg.poseidon_bn254_cost_base = Some(260);
1992 cfg.poseidon_bn254_cost_per_block = Some(10);
1993
1994 cfg.feature_flags.enable_group_ops_native_function_msm = true;
1995
1996 cfg.feature_flags.enable_vdf = true;
1997 cfg.vdf_verify_vdf_cost = Some(1500);
2000 cfg.vdf_hash_to_input_cost = Some(100);
2001
2002 cfg.feature_flags.passkey_auth = true;
2003 }
2004
2005 for cur in 2..=version.0 {
2006 match cur {
2007 1 => unreachable!(),
2008 2 => {}
2010 3 => {
2011 cfg.feature_flags.relocate_event_module = true;
2012 }
2013 4 => {
2014 cfg.max_type_to_layout_nodes = Some(512);
2015 }
2016 5 => {
2017 cfg.feature_flags.protocol_defined_base_fee = true;
2018 cfg.base_gas_price = Some(1000);
2019
2020 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2021 cfg.feature_flags.convert_type_argument_error = true;
2022 cfg.feature_flags.native_charging_v2 = true;
2023
2024 if chain != Chain::Mainnet && chain != Chain::Testnet {
2025 cfg.feature_flags.uncompressed_g1_group_elements = true;
2026 }
2027
2028 cfg.gas_model_version = Some(2);
2029
2030 cfg.poseidon_bn254_cost_per_block = Some(388);
2031
2032 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2033 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2034 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2035 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2036 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2037 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2038 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2039 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2040
2041 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2043 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2044 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2045 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2046
2047 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2048 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2049 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2050 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2051 Some(8213);
2052 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2053 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2054 Some(9484);
2055
2056 cfg.hash_keccak256_cost_base = Some(10);
2057 cfg.hash_blake2b256_cost_base = Some(10);
2058
2059 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2061 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2062 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2063 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2064
2065 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2066 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2067 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2068 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2069
2070 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2071 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2072 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2073 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2074
2075 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2076 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2077 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2078 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2079
2080 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2081 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2082 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2083 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2084
2085 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2086 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2087
2088 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2089 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2090 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2091 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2092
2093 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2094 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2095 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2096 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2097 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2098
2099 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2100
2101 cfg.validator_validate_metadata_cost_base = Some(20000);
2102
2103 cfg.max_committee_members_count = Some(50);
2104 }
2105 6 => {
2106 cfg.max_ptb_value_size = Some(1024 * 1024);
2107 }
2108 7 => {
2109 }
2112 8 => {
2113 cfg.feature_flags.variant_nodes = true;
2114
2115 if chain != Chain::Mainnet {
2116 cfg.feature_flags.consensus_round_prober = true;
2118 cfg.feature_flags
2120 .consensus_distributed_vote_scoring_strategy = true;
2121 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2122 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2124 cfg.feature_flags
2126 .consensus_round_prober_probe_accepted_rounds = true;
2127 cfg.feature_flags.consensus_zstd_compression = true;
2129 cfg.consensus_gc_depth = Some(60);
2133 }
2134
2135 if chain != Chain::Testnet && chain != Chain::Mainnet {
2138 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2139 }
2140 }
2141 9 => {
2142 if chain != Chain::Mainnet {
2143 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2145 }
2146
2147 cfg.feature_flags.consensus_zstd_compression = true;
2149
2150 if chain != Chain::Testnet && chain != Chain::Mainnet {
2152 cfg.feature_flags.accept_passkey_in_multisig = true;
2153 }
2154
2155 cfg.bridge_should_try_to_finalize_committee = None;
2157 }
2158 10 => {
2159 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2162
2163 cfg.max_committee_members_count = Some(80);
2165
2166 cfg.feature_flags.consensus_round_prober = true;
2168 cfg.feature_flags
2170 .consensus_round_prober_probe_accepted_rounds = true;
2171 cfg.feature_flags
2173 .consensus_distributed_vote_scoring_strategy = true;
2174 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2176
2177 cfg.consensus_gc_depth = Some(60);
2182
2183 cfg.feature_flags.minimize_child_object_mutations = true;
2185
2186 if chain != Chain::Mainnet {
2187 cfg.feature_flags.consensus_batched_block_sync = true;
2189 }
2190
2191 if chain != Chain::Testnet && chain != Chain::Mainnet {
2192 cfg.feature_flags
2195 .congestion_control_gas_price_feedback_mechanism = true;
2196 }
2197
2198 cfg.feature_flags.validate_identifier_inputs = true;
2199 cfg.feature_flags.dependency_linkage_error = true;
2200 cfg.feature_flags.additional_multisig_checks = true;
2201 }
2202 11 => {
2203 }
2206 12 => {
2207 cfg.feature_flags
2210 .congestion_control_gas_price_feedback_mechanism = true;
2211
2212 cfg.feature_flags.normalize_ptb_arguments = true;
2214 }
2215 13 => {
2216 cfg.feature_flags.select_committee_from_eligible_validators = true;
2219 cfg.feature_flags.track_non_committee_eligible_validators = true;
2222
2223 if chain != Chain::Testnet && chain != Chain::Mainnet {
2224 cfg.feature_flags
2227 .select_committee_supporting_next_epoch_version = true;
2228 }
2229 }
2230 _ => panic!("unsupported version {version:?}"),
2241 }
2242 }
2243 cfg
2244 }
2245
2246 pub fn verifier_config(&self, signing_limits: Option<(usize, usize)>) -> VerifierConfig {
2250 let (max_back_edges_per_function, max_back_edges_per_module) = if let Some((
2251 max_back_edges_per_function,
2252 max_back_edges_per_module,
2253 )) = signing_limits
2254 {
2255 (
2256 Some(max_back_edges_per_function),
2257 Some(max_back_edges_per_module),
2258 )
2259 } else {
2260 (None, None)
2261 };
2262
2263 VerifierConfig {
2264 max_loop_depth: Some(self.max_loop_depth() as usize),
2265 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2266 max_function_parameters: Some(self.max_function_parameters() as usize),
2267 max_basic_blocks: Some(self.max_basic_blocks() as usize),
2268 max_value_stack_size: self.max_value_stack_size() as usize,
2269 max_type_nodes: Some(self.max_type_nodes() as usize),
2270 max_push_size: Some(self.max_push_size() as usize),
2271 max_dependency_depth: Some(self.max_dependency_depth() as usize),
2272 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2273 max_function_definitions: Some(self.max_function_definitions() as usize),
2274 max_data_definitions: Some(self.max_struct_definitions() as usize),
2275 max_constant_vector_len: Some(self.max_move_vector_len()),
2276 max_back_edges_per_function,
2277 max_back_edges_per_module,
2278 max_basic_blocks_in_script: None,
2279 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
2283 max_variants_in_enum: self.max_move_enum_variants_as_option(),
2284 }
2285 }
2286
2287 pub fn apply_overrides_for_testing(
2292 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
2293 ) -> OverrideGuard {
2294 CONFIG_OVERRIDE.with(|ovr| {
2295 let mut cur = ovr.borrow_mut();
2296 assert!(cur.is_none(), "config override already present");
2297 *cur = Some(Box::new(override_fn));
2298 OverrideGuard
2299 })
2300 }
2301}
2302
2303impl ProtocolConfig {
2308 pub fn set_zklogin_auth_for_testing(&mut self, val: bool) {
2309 self.feature_flags.zklogin_auth = val
2310 }
2311 pub fn set_enable_jwk_consensus_updates_for_testing(&mut self, val: bool) {
2312 self.feature_flags.enable_jwk_consensus_updates = val
2313 }
2314
2315 pub fn set_accept_zklogin_in_multisig_for_testing(&mut self, val: bool) {
2316 self.feature_flags.accept_zklogin_in_multisig = val
2317 }
2318
2319 pub fn set_per_object_congestion_control_mode_for_testing(
2320 &mut self,
2321 val: PerObjectCongestionControlMode,
2322 ) {
2323 self.feature_flags.per_object_congestion_control_mode = val;
2324 }
2325
2326 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
2327 self.feature_flags.consensus_choice = val;
2328 }
2329
2330 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
2331 self.feature_flags.consensus_network = val;
2332 }
2333
2334 pub fn set_zklogin_max_epoch_upper_bound_delta_for_testing(&mut self, val: Option<u64>) {
2335 self.feature_flags.zklogin_max_epoch_upper_bound_delta = val
2336 }
2337
2338 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
2339 self.feature_flags.passkey_auth = val
2340 }
2341
2342 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
2343 self.feature_flags
2344 .disallow_new_modules_in_deps_only_packages = val;
2345 }
2346
2347 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
2348 self.feature_flags.consensus_round_prober = val;
2349 }
2350
2351 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
2352 self.feature_flags
2353 .consensus_distributed_vote_scoring_strategy = val;
2354 }
2355
2356 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
2357 self.consensus_gc_depth = Some(val);
2358 }
2359
2360 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
2361 self.feature_flags.consensus_linearize_subdag_v2 = val;
2362 }
2363
2364 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
2365 self.feature_flags
2366 .consensus_round_prober_probe_accepted_rounds = val;
2367 }
2368
2369 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
2370 self.feature_flags.accept_passkey_in_multisig = val;
2371 }
2372
2373 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
2374 self.feature_flags.consensus_smart_ancestor_selection = val;
2375 }
2376
2377 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
2378 self.feature_flags.consensus_batched_block_sync = val;
2379 }
2380
2381 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
2382 self.feature_flags
2383 .congestion_control_min_free_execution_slot = val;
2384 }
2385
2386 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
2387 self.feature_flags
2388 .congestion_control_gas_price_feedback_mechanism = val;
2389 }
2390 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
2391 self.feature_flags.select_committee_from_eligible_validators = val;
2392 }
2393
2394 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
2395 self.feature_flags.track_non_committee_eligible_validators = val;
2396 }
2397
2398 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
2399 self.feature_flags
2400 .select_committee_supporting_next_epoch_version = val;
2401 }
2402}
2403
2404type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
2405
2406thread_local! {
2407 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
2408}
2409
2410#[must_use]
2411pub struct OverrideGuard;
2412
2413impl Drop for OverrideGuard {
2414 fn drop(&mut self) {
2415 info!("restoring override fn");
2416 CONFIG_OVERRIDE.with(|ovr| {
2417 *ovr.borrow_mut() = None;
2418 });
2419 }
2420}
2421
2422#[derive(PartialEq, Eq)]
2426pub enum LimitThresholdCrossed {
2427 None,
2428 Soft(u128, u128),
2429 Hard(u128, u128),
2430}
2431
2432pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
2435 x: T,
2436 soft_limit: U,
2437 hard_limit: V,
2438) -> LimitThresholdCrossed {
2439 let x: V = x.into();
2440 let soft_limit: V = soft_limit.into();
2441
2442 debug_assert!(soft_limit <= hard_limit);
2443
2444 if x >= hard_limit {
2447 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
2448 } else if x < soft_limit {
2449 LimitThresholdCrossed::None
2450 } else {
2451 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
2452 }
2453}
2454
2455#[macro_export]
2456macro_rules! check_limit {
2457 ($x:expr, $hard:expr) => {
2458 check_limit!($x, $hard, $hard)
2459 };
2460 ($x:expr, $soft:expr, $hard:expr) => {
2461 check_limit_in_range($x as u64, $soft, $hard)
2462 };
2463}
2464
2465#[macro_export]
2469macro_rules! check_limit_by_meter {
2470 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
2471 let (h, metered_str) = if $is_metered {
2473 ($metered_limit, "metered")
2474 } else {
2475 ($unmetered_hard_limit, "unmetered")
2477 };
2478 use iota_protocol_config::check_limit_in_range;
2479 let result = check_limit_in_range($x as u64, $metered_limit, h);
2480 match result {
2481 LimitThresholdCrossed::None => {}
2482 LimitThresholdCrossed::Soft(_, _) => {
2483 $metric.with_label_values(&[metered_str, "soft"]).inc();
2484 }
2485 LimitThresholdCrossed::Hard(_, _) => {
2486 $metric.with_label_values(&[metered_str, "hard"]).inc();
2487 }
2488 };
2489 result
2490 }};
2491}
2492
2493#[cfg(all(test, not(msim)))]
2494mod test {
2495 use insta::assert_yaml_snapshot;
2496
2497 use super::*;
2498
2499 #[test]
2500 fn snapshot_tests() {
2501 println!("\n============================================================================");
2502 println!("! !");
2503 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
2504 println!("! !");
2505 println!("============================================================================\n");
2506 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
2507 let chain_str = match chain_id {
2512 Chain::Unknown => "".to_string(),
2513 _ => format!("{chain_id:?}_"),
2514 };
2515 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
2516 let cur = ProtocolVersion::new(i);
2517 assert_yaml_snapshot!(
2518 format!("{}version_{}", chain_str, cur.as_u64()),
2519 ProtocolConfig::get_for_version(cur, *chain_id)
2520 );
2521 }
2522 }
2523 }
2524
2525 #[test]
2526 fn test_getters() {
2527 let prot: ProtocolConfig =
2528 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2529 assert_eq!(
2530 prot.max_arguments(),
2531 prot.max_arguments_as_option().unwrap()
2532 );
2533 }
2534
2535 #[test]
2536 fn test_setters() {
2537 let mut prot: ProtocolConfig =
2538 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2539 prot.set_max_arguments_for_testing(123);
2540 assert_eq!(prot.max_arguments(), 123);
2541
2542 prot.set_max_arguments_from_str_for_testing("321".to_string());
2543 assert_eq!(prot.max_arguments(), 321);
2544
2545 prot.disable_max_arguments_for_testing();
2546 assert_eq!(prot.max_arguments_as_option(), None);
2547
2548 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
2549 assert_eq!(prot.max_arguments(), 456);
2550 }
2551
2552 #[test]
2553 #[should_panic(expected = "unsupported version")]
2554 fn max_version_test() {
2555 let _ = ProtocolConfig::get_for_version_impl(
2558 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
2559 Chain::Unknown,
2560 );
2561 }
2562
2563 #[test]
2564 fn lookup_by_string_test() {
2565 let prot: ProtocolConfig =
2566 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2567 assert!(prot.lookup_attr("some random string".to_string()).is_none());
2569
2570 assert!(
2571 prot.lookup_attr("max_arguments".to_string())
2572 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
2573 );
2574
2575 assert!(
2577 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2578 .is_none()
2579 );
2580 assert!(
2581 prot.attr_map()
2582 .get("poseidon_bn254_cost_base")
2583 .unwrap()
2584 .is_none()
2585 );
2586
2587 let prot: ProtocolConfig =
2589 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2590
2591 assert!(
2592 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2593 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2594 );
2595 assert!(
2596 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
2597 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2598 );
2599
2600 let prot: ProtocolConfig =
2602 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2603 assert!(
2605 prot.feature_flags
2606 .lookup_attr("some random string".to_owned())
2607 .is_none()
2608 );
2609 assert!(
2610 !prot
2611 .feature_flags
2612 .attr_map()
2613 .contains_key("some random string")
2614 );
2615
2616 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
2618 assert!(
2619 prot.feature_flags
2620 .attr_map()
2621 .get("enable_poseidon")
2622 .unwrap()
2623 == &false
2624 );
2625 let prot: ProtocolConfig =
2626 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2627 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
2629 assert!(
2630 prot.feature_flags
2631 .attr_map()
2632 .get("enable_poseidon")
2633 .unwrap()
2634 == &true
2635 );
2636 }
2637
2638 #[test]
2639 fn limit_range_fn_test() {
2640 let low = 100u32;
2641 let high = 10000u64;
2642
2643 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
2644 assert!(matches!(
2645 check_limit!(255u16, low, high),
2646 LimitThresholdCrossed::Soft(255u128, 100)
2647 ));
2648 assert!(matches!(
2655 check_limit!(2550000u64, low, high),
2656 LimitThresholdCrossed::Hard(2550000, 10000)
2657 ));
2658
2659 assert!(matches!(
2660 check_limit!(2550000u64, high, high),
2661 LimitThresholdCrossed::Hard(2550000, 10000)
2662 ));
2663
2664 assert!(matches!(
2665 check_limit!(1u8, high),
2666 LimitThresholdCrossed::None
2667 ));
2668
2669 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
2670
2671 assert!(matches!(
2672 check_limit!(2550000u64, high),
2673 LimitThresholdCrossed::Hard(2550000, 10000)
2674 ));
2675 }
2676}