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 = 16;
23
24#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
95pub struct ProtocolVersion(u64);
96
97impl ProtocolVersion {
98 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
104
105 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
106
107 #[cfg(not(msim))]
108 const MAX_ALLOWED: Self = Self::MAX;
109
110 #[cfg(msim)]
113 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
114
115 pub fn new(v: u64) -> Self {
116 Self(v)
117 }
118
119 pub const fn as_u64(&self) -> u64 {
120 self.0
121 }
122
123 pub fn max() -> Self {
126 Self::MAX
127 }
128}
129
130impl From<u64> for ProtocolVersion {
131 fn from(v: u64) -> Self {
132 Self::new(v)
133 }
134}
135
136impl std::ops::Sub<u64> for ProtocolVersion {
137 type Output = Self;
138 fn sub(self, rhs: u64) -> Self::Output {
139 Self::new(self.0 - rhs)
140 }
141}
142
143impl std::ops::Add<u64> for ProtocolVersion {
144 type Output = Self;
145 fn add(self, rhs: u64) -> Self::Output {
146 Self::new(self.0 + rhs)
147 }
148}
149
150#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum)]
151pub enum Chain {
152 Mainnet,
153 Testnet,
154 Unknown,
155}
156
157impl Default for Chain {
158 fn default() -> Self {
159 Self::Unknown
160 }
161}
162
163impl Chain {
164 pub fn as_str(self) -> &'static str {
165 match self {
166 Chain::Mainnet => "mainnet",
167 Chain::Testnet => "testnet",
168 Chain::Unknown => "unknown",
169 }
170 }
171}
172
173pub struct Error(pub String);
174
175#[derive(Default, Clone, Serialize, Deserialize, Debug, ProtocolConfigFeatureFlagsGetters)]
179struct FeatureFlags {
180 #[serde(skip_serializing_if = "is_true")]
186 disable_invariant_violation_check_in_swap_loc: bool,
187
188 #[serde(skip_serializing_if = "is_true")]
191 no_extraneous_module_bytes: bool,
192
193 #[serde(skip_serializing_if = "is_false")]
195 zklogin_auth: bool,
196
197 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
199 consensus_transaction_ordering: ConsensusTransactionOrdering,
200
201 #[serde(skip_serializing_if = "is_false")]
202 enable_jwk_consensus_updates: bool,
203
204 #[serde(skip_serializing_if = "is_false")]
206 accept_zklogin_in_multisig: bool,
207
208 #[serde(skip_serializing_if = "is_true")]
211 hardened_otw_check: bool,
212
213 #[serde(skip_serializing_if = "is_false")]
215 enable_poseidon: bool,
216
217 #[serde(skip_serializing_if = "is_false")]
219 enable_group_ops_native_function_msm: bool,
220
221 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
223 per_object_congestion_control_mode: PerObjectCongestionControlMode,
224
225 #[serde(skip_serializing_if = "ConsensusChoice::is_mysticeti")]
227 consensus_choice: ConsensusChoice,
228
229 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
231 consensus_network: ConsensusNetwork,
232
233 #[serde(skip_serializing_if = "Option::is_none")]
235 zklogin_max_epoch_upper_bound_delta: Option<u64>,
236
237 #[serde(skip_serializing_if = "is_false")]
239 enable_vdf: bool,
240
241 #[serde(skip_serializing_if = "is_false")]
243 passkey_auth: bool,
244
245 #[serde(skip_serializing_if = "is_true")]
248 rethrow_serialization_type_layout_errors: bool,
249
250 #[serde(skip_serializing_if = "is_false")]
252 relocate_event_module: bool,
253
254 #[serde(skip_serializing_if = "is_false")]
256 protocol_defined_base_fee: bool,
257
258 #[serde(skip_serializing_if = "is_false")]
260 uncompressed_g1_group_elements: bool,
261
262 #[serde(skip_serializing_if = "is_false")]
264 disallow_new_modules_in_deps_only_packages: bool,
265
266 #[serde(skip_serializing_if = "is_false")]
268 native_charging_v2: bool,
269
270 #[serde(skip_serializing_if = "is_false")]
272 convert_type_argument_error: bool,
273
274 #[serde(skip_serializing_if = "is_false")]
276 consensus_round_prober: bool,
277
278 #[serde(skip_serializing_if = "is_false")]
280 consensus_distributed_vote_scoring_strategy: bool,
281
282 #[serde(skip_serializing_if = "is_false")]
286 consensus_linearize_subdag_v2: bool,
287
288 #[serde(skip_serializing_if = "is_false")]
290 variant_nodes: bool,
291
292 #[serde(skip_serializing_if = "is_false")]
294 consensus_smart_ancestor_selection: bool,
295
296 #[serde(skip_serializing_if = "is_false")]
298 consensus_round_prober_probe_accepted_rounds: bool,
299
300 #[serde(skip_serializing_if = "is_false")]
302 consensus_zstd_compression: bool,
303
304 #[serde(skip_serializing_if = "is_false")]
307 congestion_control_min_free_execution_slot: bool,
308
309 #[serde(skip_serializing_if = "is_false")]
311 accept_passkey_in_multisig: bool,
312
313 #[serde(skip_serializing_if = "is_false")]
315 consensus_batched_block_sync: bool,
316
317 #[serde(skip_serializing_if = "is_false")]
320 congestion_control_gas_price_feedback_mechanism: bool,
321
322 #[serde(skip_serializing_if = "is_false")]
324 validate_identifier_inputs: bool,
325
326 #[serde(skip_serializing_if = "is_false")]
329 minimize_child_object_mutations: bool,
330
331 #[serde(skip_serializing_if = "is_false")]
333 dependency_linkage_error: bool,
334
335 #[serde(skip_serializing_if = "is_false")]
337 additional_multisig_checks: bool,
338
339 #[serde(skip_serializing_if = "is_false")]
342 normalize_ptb_arguments: bool,
343
344 #[serde(skip_serializing_if = "is_false")]
348 select_committee_from_eligible_validators: bool,
349
350 #[serde(skip_serializing_if = "is_false")]
357 track_non_committee_eligible_validators: bool,
358
359 #[serde(skip_serializing_if = "is_false")]
365 select_committee_supporting_next_epoch_version: bool,
366
367 #[serde(skip_serializing_if = "is_false")]
371 consensus_median_timestamp_with_checkpoint_enforcement: bool,
372 #[serde(skip_serializing_if = "is_false")]
374 consensus_commit_transactions_only_for_traversed_headers: bool,
375}
376
377fn is_true(b: &bool) -> bool {
378 *b
379}
380
381fn is_false(b: &bool) -> bool {
382 !b
383}
384
385#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
387pub enum ConsensusTransactionOrdering {
388 #[default]
391 None,
392 ByGasPrice,
394}
395
396impl ConsensusTransactionOrdering {
397 pub fn is_none(&self) -> bool {
398 matches!(self, ConsensusTransactionOrdering::None)
399 }
400}
401
402#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
404pub enum PerObjectCongestionControlMode {
405 #[default]
406 None, TotalGasBudget, TotalTxCount, }
410
411impl PerObjectCongestionControlMode {
412 pub fn is_none(&self) -> bool {
413 matches!(self, PerObjectCongestionControlMode::None)
414 }
415}
416
417#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
419pub enum ConsensusChoice {
420 #[default]
421 Mysticeti,
422 Starfish,
423}
424
425impl ConsensusChoice {
426 pub fn is_mysticeti(&self) -> bool {
427 matches!(self, ConsensusChoice::Mysticeti)
428 }
429 pub fn is_starfish(&self) -> bool {
430 matches!(self, ConsensusChoice::Starfish)
431 }
432}
433
434#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
436pub enum ConsensusNetwork {
437 #[default]
438 Tonic,
439}
440
441impl ConsensusNetwork {
442 pub fn is_tonic(&self) -> bool {
443 matches!(self, ConsensusNetwork::Tonic)
444 }
445}
446
447#[skip_serializing_none]
481#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
482pub struct ProtocolConfig {
483 pub version: ProtocolVersion,
484
485 feature_flags: FeatureFlags,
486
487 max_tx_size_bytes: Option<u64>,
492
493 max_input_objects: Option<u64>,
496
497 max_size_written_objects: Option<u64>,
502 max_size_written_objects_system_tx: Option<u64>,
506
507 max_serialized_tx_effects_size_bytes: Option<u64>,
509
510 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
512
513 max_gas_payment_objects: Option<u32>,
515
516 max_modules_in_publish: Option<u32>,
518
519 max_package_dependencies: Option<u32>,
521
522 max_arguments: Option<u32>,
525
526 max_type_arguments: Option<u32>,
528
529 max_type_argument_depth: Option<u32>,
531
532 max_pure_argument_size: Option<u32>,
534
535 max_programmable_tx_commands: Option<u32>,
537
538 move_binary_format_version: Option<u32>,
544 min_move_binary_format_version: Option<u32>,
545
546 binary_module_handles: Option<u16>,
548 binary_struct_handles: Option<u16>,
549 binary_function_handles: Option<u16>,
550 binary_function_instantiations: Option<u16>,
551 binary_signatures: Option<u16>,
552 binary_constant_pool: Option<u16>,
553 binary_identifiers: Option<u16>,
554 binary_address_identifiers: Option<u16>,
555 binary_struct_defs: Option<u16>,
556 binary_struct_def_instantiations: Option<u16>,
557 binary_function_defs: Option<u16>,
558 binary_field_handles: Option<u16>,
559 binary_field_instantiations: Option<u16>,
560 binary_friend_decls: Option<u16>,
561 binary_enum_defs: Option<u16>,
562 binary_enum_def_instantiations: Option<u16>,
563 binary_variant_handles: Option<u16>,
564 binary_variant_instantiation_handles: Option<u16>,
565
566 max_move_object_size: Option<u64>,
569
570 max_move_package_size: Option<u64>,
575
576 max_publish_or_upgrade_per_ptb: Option<u64>,
579
580 max_tx_gas: Option<u64>,
582
583 max_gas_price: Option<u64>,
586
587 max_gas_computation_bucket: Option<u64>,
590
591 gas_rounding_step: Option<u64>,
593
594 max_loop_depth: Option<u64>,
596
597 max_generic_instantiation_length: Option<u64>,
600
601 max_function_parameters: Option<u64>,
604
605 max_basic_blocks: Option<u64>,
608
609 max_value_stack_size: Option<u64>,
611
612 max_type_nodes: Option<u64>,
616
617 max_push_size: Option<u64>,
620
621 max_struct_definitions: Option<u64>,
624
625 max_function_definitions: Option<u64>,
628
629 max_fields_in_struct: Option<u64>,
632
633 max_dependency_depth: Option<u64>,
636
637 max_num_event_emit: Option<u64>,
640
641 max_num_new_move_object_ids: Option<u64>,
644
645 max_num_new_move_object_ids_system_tx: Option<u64>,
648
649 max_num_deleted_move_object_ids: Option<u64>,
652
653 max_num_deleted_move_object_ids_system_tx: Option<u64>,
656
657 max_num_transferred_move_object_ids: Option<u64>,
660
661 max_num_transferred_move_object_ids_system_tx: Option<u64>,
664
665 max_event_emit_size: Option<u64>,
667
668 max_event_emit_size_total: Option<u64>,
670
671 max_move_vector_len: Option<u64>,
674
675 max_move_identifier_len: Option<u64>,
678
679 max_move_value_depth: Option<u64>,
681
682 max_move_enum_variants: Option<u64>,
685
686 max_back_edges_per_function: Option<u64>,
689
690 max_back_edges_per_module: Option<u64>,
693
694 max_verifier_meter_ticks_per_function: Option<u64>,
697
698 max_meter_ticks_per_module: Option<u64>,
701
702 max_meter_ticks_per_package: Option<u64>,
705
706 object_runtime_max_num_cached_objects: Option<u64>,
713
714 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
717
718 object_runtime_max_num_store_entries: Option<u64>,
721
722 object_runtime_max_num_store_entries_system_tx: Option<u64>,
725
726 base_tx_cost_fixed: Option<u64>,
731
732 package_publish_cost_fixed: Option<u64>,
736
737 base_tx_cost_per_byte: Option<u64>,
741
742 package_publish_cost_per_byte: Option<u64>,
744
745 obj_access_cost_read_per_byte: Option<u64>,
747
748 obj_access_cost_mutate_per_byte: Option<u64>,
750
751 obj_access_cost_delete_per_byte: Option<u64>,
753
754 obj_access_cost_verify_per_byte: Option<u64>,
764
765 max_type_to_layout_nodes: Option<u64>,
767
768 max_ptb_value_size: Option<u64>,
770
771 gas_model_version: Option<u64>,
776
777 obj_data_cost_refundable: Option<u64>,
783
784 obj_metadata_cost_non_refundable: Option<u64>,
788
789 storage_rebate_rate: Option<u64>,
795
796 reward_slashing_rate: Option<u64>,
799
800 storage_gas_price: Option<u64>,
802
803 base_gas_price: Option<u64>,
805
806 validator_target_reward: Option<u64>,
808
809 max_transactions_per_checkpoint: Option<u64>,
816
817 max_checkpoint_size_bytes: Option<u64>,
821
822 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
828
829 address_from_bytes_cost_base: Option<u64>,
834 address_to_u256_cost_base: Option<u64>,
836 address_from_u256_cost_base: Option<u64>,
838
839 config_read_setting_impl_cost_base: Option<u64>,
844 config_read_setting_impl_cost_per_byte: Option<u64>,
845
846 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
850 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
851 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
852 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
853 dynamic_field_add_child_object_cost_base: Option<u64>,
856 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
857 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
858 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
859 dynamic_field_borrow_child_object_cost_base: Option<u64>,
862 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
863 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
864 dynamic_field_remove_child_object_cost_base: Option<u64>,
867 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
868 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
869 dynamic_field_has_child_object_cost_base: Option<u64>,
872 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
875 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
876 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
877
878 event_emit_cost_base: Option<u64>,
881 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
882 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
883 event_emit_output_cost_per_byte: Option<u64>,
884
885 object_borrow_uid_cost_base: Option<u64>,
888 object_delete_impl_cost_base: Option<u64>,
890 object_record_new_uid_cost_base: Option<u64>,
892
893 transfer_transfer_internal_cost_base: Option<u64>,
896 transfer_freeze_object_cost_base: Option<u64>,
898 transfer_share_object_cost_base: Option<u64>,
900 transfer_receive_object_cost_base: Option<u64>,
903
904 tx_context_derive_id_cost_base: Option<u64>,
907
908 types_is_one_time_witness_cost_base: Option<u64>,
911 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
912 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
913
914 validator_validate_metadata_cost_base: Option<u64>,
917 validator_validate_metadata_data_cost_per_byte: Option<u64>,
918
919 crypto_invalid_arguments_cost: Option<u64>,
921 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
923 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
924 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
925
926 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
928 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
929 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
930
931 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
933 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
934 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
935 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
936 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
937 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
938
939 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
941
942 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
944 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
945 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
946 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
947 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
948 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
949
950 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
952 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
953 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
954 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
955 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
956 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
957
958 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
960 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
961 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
962 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
963 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
964 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
965
966 ecvrf_ecvrf_verify_cost_base: Option<u64>,
968 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
969 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
970
971 ed25519_ed25519_verify_cost_base: Option<u64>,
973 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
974 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
975
976 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
978 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
979
980 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
982 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
983 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
984 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
985 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
986
987 hash_blake2b256_cost_base: Option<u64>,
989 hash_blake2b256_data_cost_per_byte: Option<u64>,
990 hash_blake2b256_data_cost_per_block: Option<u64>,
991
992 hash_keccak256_cost_base: Option<u64>,
994 hash_keccak256_data_cost_per_byte: Option<u64>,
995 hash_keccak256_data_cost_per_block: Option<u64>,
996
997 poseidon_bn254_cost_base: Option<u64>,
999 poseidon_bn254_cost_per_block: Option<u64>,
1000
1001 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1003 group_ops_bls12381_decode_g1_cost: Option<u64>,
1004 group_ops_bls12381_decode_g2_cost: Option<u64>,
1005 group_ops_bls12381_decode_gt_cost: Option<u64>,
1006 group_ops_bls12381_scalar_add_cost: Option<u64>,
1007 group_ops_bls12381_g1_add_cost: Option<u64>,
1008 group_ops_bls12381_g2_add_cost: Option<u64>,
1009 group_ops_bls12381_gt_add_cost: Option<u64>,
1010 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1011 group_ops_bls12381_g1_sub_cost: Option<u64>,
1012 group_ops_bls12381_g2_sub_cost: Option<u64>,
1013 group_ops_bls12381_gt_sub_cost: Option<u64>,
1014 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1015 group_ops_bls12381_g1_mul_cost: Option<u64>,
1016 group_ops_bls12381_g2_mul_cost: Option<u64>,
1017 group_ops_bls12381_gt_mul_cost: Option<u64>,
1018 group_ops_bls12381_scalar_div_cost: Option<u64>,
1019 group_ops_bls12381_g1_div_cost: Option<u64>,
1020 group_ops_bls12381_g2_div_cost: Option<u64>,
1021 group_ops_bls12381_gt_div_cost: Option<u64>,
1022 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1023 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1024 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1025 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1026 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1027 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1028 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1029 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1030 group_ops_bls12381_msm_max_len: Option<u32>,
1031 group_ops_bls12381_pairing_cost: Option<u64>,
1032 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1033 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1034 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1035 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1036 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1037
1038 hmac_hmac_sha3_256_cost_base: Option<u64>,
1040 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1041 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1042
1043 check_zklogin_id_cost_base: Option<u64>,
1045 check_zklogin_issuer_cost_base: Option<u64>,
1047
1048 vdf_verify_vdf_cost: Option<u64>,
1049 vdf_hash_to_input_cost: Option<u64>,
1050
1051 bcs_per_byte_serialized_cost: Option<u64>,
1053 bcs_legacy_min_output_size_cost: Option<u64>,
1054 bcs_failure_cost: Option<u64>,
1055
1056 hash_sha2_256_base_cost: Option<u64>,
1057 hash_sha2_256_per_byte_cost: Option<u64>,
1058 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1059 hash_sha3_256_base_cost: Option<u64>,
1060 hash_sha3_256_per_byte_cost: Option<u64>,
1061 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1062 type_name_get_base_cost: Option<u64>,
1063 type_name_get_per_byte_cost: Option<u64>,
1064
1065 string_check_utf8_base_cost: Option<u64>,
1066 string_check_utf8_per_byte_cost: Option<u64>,
1067 string_is_char_boundary_base_cost: Option<u64>,
1068 string_sub_string_base_cost: Option<u64>,
1069 string_sub_string_per_byte_cost: Option<u64>,
1070 string_index_of_base_cost: Option<u64>,
1071 string_index_of_per_byte_pattern_cost: Option<u64>,
1072 string_index_of_per_byte_searched_cost: Option<u64>,
1073
1074 vector_empty_base_cost: Option<u64>,
1075 vector_length_base_cost: Option<u64>,
1076 vector_push_back_base_cost: Option<u64>,
1077 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1078 vector_borrow_base_cost: Option<u64>,
1079 vector_pop_back_base_cost: Option<u64>,
1080 vector_destroy_empty_base_cost: Option<u64>,
1081 vector_swap_base_cost: Option<u64>,
1082 debug_print_base_cost: Option<u64>,
1083 debug_print_stack_trace_base_cost: Option<u64>,
1084
1085 execution_version: Option<u64>,
1087
1088 consensus_bad_nodes_stake_threshold: Option<u64>,
1092
1093 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1094 max_age_of_jwk_in_epochs: Option<u64>,
1098
1099 random_beacon_reduction_allowed_delta: Option<u16>,
1103
1104 random_beacon_reduction_lower_bound: Option<u32>,
1107
1108 random_beacon_dkg_timeout_round: Option<u32>,
1111
1112 random_beacon_min_round_interval_ms: Option<u64>,
1114
1115 random_beacon_dkg_version: Option<u64>,
1119
1120 consensus_max_transaction_size_bytes: Option<u64>,
1125 consensus_max_transactions_in_block_bytes: Option<u64>,
1127 consensus_max_num_transactions_in_block: Option<u64>,
1129
1130 max_deferral_rounds_for_congestion_control: Option<u64>,
1134
1135 min_checkpoint_interval_ms: Option<u64>,
1137
1138 checkpoint_summary_version_specific_data: Option<u64>,
1140
1141 max_soft_bundle_size: Option<u64>,
1144
1145 bridge_should_try_to_finalize_committee: Option<bool>,
1150
1151 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1157
1158 max_committee_members_count: Option<u64>,
1162
1163 consensus_gc_depth: Option<u32>,
1166
1167 consensus_max_acknowledgments_per_block: Option<u32>,
1173
1174 max_congestion_limit_overshoot_per_commit: Option<u64>,
1179}
1180
1181impl ProtocolConfig {
1183 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1196 self.feature_flags
1197 .disable_invariant_violation_check_in_swap_loc
1198 }
1199
1200 pub fn no_extraneous_module_bytes(&self) -> bool {
1201 self.feature_flags.no_extraneous_module_bytes
1202 }
1203
1204 pub fn zklogin_auth(&self) -> bool {
1205 self.feature_flags.zklogin_auth
1206 }
1207
1208 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1209 self.feature_flags.consensus_transaction_ordering
1210 }
1211
1212 pub fn enable_jwk_consensus_updates(&self) -> bool {
1213 self.feature_flags.enable_jwk_consensus_updates
1214 }
1215
1216 pub fn create_authenticator_state_in_genesis(&self) -> bool {
1218 self.enable_jwk_consensus_updates()
1219 }
1220
1221 pub fn dkg_version(&self) -> u64 {
1222 self.random_beacon_dkg_version.unwrap_or(1)
1224 }
1225
1226 pub fn accept_zklogin_in_multisig(&self) -> bool {
1227 self.feature_flags.accept_zklogin_in_multisig
1228 }
1229
1230 pub fn zklogin_max_epoch_upper_bound_delta(&self) -> Option<u64> {
1231 self.feature_flags.zklogin_max_epoch_upper_bound_delta
1232 }
1233
1234 pub fn hardened_otw_check(&self) -> bool {
1235 self.feature_flags.hardened_otw_check
1236 }
1237
1238 pub fn enable_poseidon(&self) -> bool {
1239 self.feature_flags.enable_poseidon
1240 }
1241
1242 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1243 self.feature_flags.enable_group_ops_native_function_msm
1244 }
1245
1246 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1247 self.feature_flags.per_object_congestion_control_mode
1248 }
1249
1250 pub fn consensus_choice(&self) -> ConsensusChoice {
1251 self.feature_flags.consensus_choice
1252 }
1253
1254 pub fn consensus_network(&self) -> ConsensusNetwork {
1255 self.feature_flags.consensus_network
1256 }
1257
1258 pub fn enable_vdf(&self) -> bool {
1259 self.feature_flags.enable_vdf
1260 }
1261
1262 pub fn passkey_auth(&self) -> bool {
1263 self.feature_flags.passkey_auth
1264 }
1265
1266 pub fn max_transaction_size_bytes(&self) -> u64 {
1267 self.consensus_max_transaction_size_bytes
1269 .unwrap_or(256 * 1024)
1270 }
1271
1272 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1273 if cfg!(msim) {
1274 256 * 1024
1275 } else {
1276 self.consensus_max_transactions_in_block_bytes
1277 .unwrap_or(512 * 1024)
1278 }
1279 }
1280
1281 pub fn max_num_transactions_in_block(&self) -> u64 {
1282 if cfg!(msim) {
1283 8
1284 } else {
1285 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1286 }
1287 }
1288
1289 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1290 self.feature_flags.rethrow_serialization_type_layout_errors
1291 }
1292
1293 pub fn relocate_event_module(&self) -> bool {
1294 self.feature_flags.relocate_event_module
1295 }
1296
1297 pub fn protocol_defined_base_fee(&self) -> bool {
1298 self.feature_flags.protocol_defined_base_fee
1299 }
1300
1301 pub fn uncompressed_g1_group_elements(&self) -> bool {
1302 self.feature_flags.uncompressed_g1_group_elements
1303 }
1304
1305 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1306 self.feature_flags
1307 .disallow_new_modules_in_deps_only_packages
1308 }
1309
1310 pub fn native_charging_v2(&self) -> bool {
1311 self.feature_flags.native_charging_v2
1312 }
1313
1314 pub fn consensus_round_prober(&self) -> bool {
1315 self.feature_flags.consensus_round_prober
1316 }
1317
1318 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1319 self.feature_flags
1320 .consensus_distributed_vote_scoring_strategy
1321 }
1322
1323 pub fn gc_depth(&self) -> u32 {
1324 if cfg!(msim) {
1325 min(5, self.consensus_gc_depth.unwrap_or(0))
1327 } else {
1328 self.consensus_gc_depth.unwrap_or(0)
1329 }
1330 }
1331
1332 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1333 let res = self.feature_flags.consensus_linearize_subdag_v2;
1334 assert!(
1335 !res || self.gc_depth() > 0,
1336 "The consensus linearize sub dag V2 requires GC to be enabled"
1337 );
1338 res
1339 }
1340
1341 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1342 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1343 }
1344
1345 pub fn variant_nodes(&self) -> bool {
1346 self.feature_flags.variant_nodes
1347 }
1348
1349 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1350 self.feature_flags.consensus_smart_ancestor_selection
1351 }
1352
1353 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1354 self.feature_flags
1355 .consensus_round_prober_probe_accepted_rounds
1356 }
1357
1358 pub fn consensus_zstd_compression(&self) -> bool {
1359 self.feature_flags.consensus_zstd_compression
1360 }
1361
1362 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1363 self.feature_flags
1364 .congestion_control_min_free_execution_slot
1365 }
1366
1367 pub fn accept_passkey_in_multisig(&self) -> bool {
1368 self.feature_flags.accept_passkey_in_multisig
1369 }
1370
1371 pub fn consensus_batched_block_sync(&self) -> bool {
1372 self.feature_flags.consensus_batched_block_sync
1373 }
1374
1375 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1378 self.feature_flags
1379 .congestion_control_gas_price_feedback_mechanism
1380 }
1381
1382 pub fn validate_identifier_inputs(&self) -> bool {
1383 self.feature_flags.validate_identifier_inputs
1384 }
1385
1386 pub fn minimize_child_object_mutations(&self) -> bool {
1387 self.feature_flags.minimize_child_object_mutations
1388 }
1389
1390 pub fn dependency_linkage_error(&self) -> bool {
1391 self.feature_flags.dependency_linkage_error
1392 }
1393
1394 pub fn additional_multisig_checks(&self) -> bool {
1395 self.feature_flags.additional_multisig_checks
1396 }
1397
1398 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1399 0
1402 }
1403
1404 pub fn normalize_ptb_arguments(&self) -> bool {
1405 self.feature_flags.normalize_ptb_arguments
1406 }
1407
1408 pub fn select_committee_from_eligible_validators(&self) -> bool {
1409 let res = self.feature_flags.select_committee_from_eligible_validators;
1410 assert!(
1411 !res || (self.protocol_defined_base_fee()
1412 && self.max_committee_members_count_as_option().is_some()),
1413 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1414 );
1415 res
1416 }
1417
1418 pub fn track_non_committee_eligible_validators(&self) -> bool {
1419 self.feature_flags.track_non_committee_eligible_validators
1420 }
1421
1422 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1423 let res = self
1424 .feature_flags
1425 .select_committee_supporting_next_epoch_version;
1426 assert!(
1427 !res || (self.track_non_committee_eligible_validators()
1428 && self.select_committee_from_eligible_validators()),
1429 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1430 );
1431 res
1432 }
1433
1434 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1435 let res = self
1436 .feature_flags
1437 .consensus_median_timestamp_with_checkpoint_enforcement;
1438 assert!(
1439 !res || self.gc_depth() > 0,
1440 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1441 );
1442 res
1443 }
1444 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1445 self.feature_flags
1446 .consensus_commit_transactions_only_for_traversed_headers
1447 }
1448}
1449
1450#[cfg(not(msim))]
1451static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1452
1453#[cfg(msim)]
1455thread_local! {
1456 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1457}
1458
1459impl ProtocolConfig {
1461 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1464 assert!(
1466 version >= ProtocolVersion::MIN,
1467 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1468 version,
1469 ProtocolVersion::MIN.0,
1470 );
1471 assert!(
1472 version <= ProtocolVersion::MAX_ALLOWED,
1473 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1474 version,
1475 ProtocolVersion::MAX_ALLOWED.0,
1476 );
1477
1478 let mut ret = Self::get_for_version_impl(version, chain);
1479 ret.version = version;
1480
1481 ret = CONFIG_OVERRIDE.with(|ovr| {
1482 if let Some(override_fn) = &*ovr.borrow() {
1483 warn!(
1484 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1485 );
1486 override_fn(version, ret)
1487 } else {
1488 ret
1489 }
1490 });
1491
1492 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1493 warn!(
1494 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1495 );
1496 let overrides: ProtocolConfigOptional =
1497 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1498 .expect("failed to parse ProtocolConfig override env variables");
1499 overrides.apply_to(&mut ret);
1500 }
1501
1502 ret
1503 }
1504
1505 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1508 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1509 let mut ret = Self::get_for_version_impl(version, chain);
1510 ret.version = version;
1511 Some(ret)
1512 } else {
1513 None
1514 }
1515 }
1516
1517 #[cfg(not(msim))]
1518 pub fn poison_get_for_min_version() {
1519 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1520 }
1521
1522 #[cfg(not(msim))]
1523 fn load_poison_get_for_min_version() -> bool {
1524 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1525 }
1526
1527 #[cfg(msim)]
1528 pub fn poison_get_for_min_version() {
1529 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1530 }
1531
1532 #[cfg(msim)]
1533 fn load_poison_get_for_min_version() -> bool {
1534 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1535 }
1536
1537 pub fn convert_type_argument_error(&self) -> bool {
1538 self.feature_flags.convert_type_argument_error
1539 }
1540
1541 pub fn get_for_min_version() -> Self {
1545 if Self::load_poison_get_for_min_version() {
1546 panic!("get_for_min_version called on validator");
1547 }
1548 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1549 }
1550
1551 #[expect(non_snake_case)]
1562 pub fn get_for_max_version_UNSAFE() -> Self {
1563 if Self::load_poison_get_for_min_version() {
1564 panic!("get_for_max_version_UNSAFE called on validator");
1565 }
1566 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1567 }
1568
1569 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1570 #[cfg(msim)]
1571 {
1572 if version > ProtocolVersion::MAX {
1574 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1575 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1576 return config;
1577 }
1578 }
1579
1580 let mut cfg = Self {
1584 version,
1585
1586 feature_flags: Default::default(),
1587
1588 max_tx_size_bytes: Some(128 * 1024),
1589 max_input_objects: Some(2048),
1592 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1593 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1594 max_gas_payment_objects: Some(256),
1595 max_modules_in_publish: Some(64),
1596 max_package_dependencies: Some(32),
1597 max_arguments: Some(512),
1598 max_type_arguments: Some(16),
1599 max_type_argument_depth: Some(16),
1600 max_pure_argument_size: Some(16 * 1024),
1601 max_programmable_tx_commands: Some(1024),
1602 move_binary_format_version: Some(7),
1603 min_move_binary_format_version: Some(6),
1604 binary_module_handles: Some(100),
1605 binary_struct_handles: Some(300),
1606 binary_function_handles: Some(1500),
1607 binary_function_instantiations: Some(750),
1608 binary_signatures: Some(1000),
1609 binary_constant_pool: Some(4000),
1610 binary_identifiers: Some(10000),
1611 binary_address_identifiers: Some(100),
1612 binary_struct_defs: Some(200),
1613 binary_struct_def_instantiations: Some(100),
1614 binary_function_defs: Some(1000),
1615 binary_field_handles: Some(500),
1616 binary_field_instantiations: Some(250),
1617 binary_friend_decls: Some(100),
1618 binary_enum_defs: None,
1619 binary_enum_def_instantiations: None,
1620 binary_variant_handles: None,
1621 binary_variant_instantiation_handles: None,
1622 max_move_object_size: Some(250 * 1024),
1623 max_move_package_size: Some(100 * 1024),
1624 max_publish_or_upgrade_per_ptb: Some(5),
1625 max_tx_gas: Some(50_000_000_000),
1627 max_gas_price: Some(100_000),
1628 max_gas_computation_bucket: Some(5_000_000),
1629 max_loop_depth: Some(5),
1630 max_generic_instantiation_length: Some(32),
1631 max_function_parameters: Some(128),
1632 max_basic_blocks: Some(1024),
1633 max_value_stack_size: Some(1024),
1634 max_type_nodes: Some(256),
1635 max_push_size: Some(10000),
1636 max_struct_definitions: Some(200),
1637 max_function_definitions: Some(1000),
1638 max_fields_in_struct: Some(32),
1639 max_dependency_depth: Some(100),
1640 max_num_event_emit: Some(1024),
1641 max_num_new_move_object_ids: Some(2048),
1642 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1643 max_num_deleted_move_object_ids: Some(2048),
1644 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1645 max_num_transferred_move_object_ids: Some(2048),
1646 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1647 max_event_emit_size: Some(250 * 1024),
1648 max_move_vector_len: Some(256 * 1024),
1649 max_type_to_layout_nodes: None,
1650 max_ptb_value_size: None,
1651
1652 max_back_edges_per_function: Some(10_000),
1653 max_back_edges_per_module: Some(10_000),
1654
1655 max_verifier_meter_ticks_per_function: Some(16_000_000),
1656
1657 max_meter_ticks_per_module: Some(16_000_000),
1658 max_meter_ticks_per_package: Some(16_000_000),
1659
1660 object_runtime_max_num_cached_objects: Some(1000),
1661 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
1662 object_runtime_max_num_store_entries: Some(1000),
1663 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
1664 base_tx_cost_fixed: Some(1_000),
1666 package_publish_cost_fixed: Some(1_000),
1667 base_tx_cost_per_byte: Some(0),
1668 package_publish_cost_per_byte: Some(80),
1669 obj_access_cost_read_per_byte: Some(15),
1670 obj_access_cost_mutate_per_byte: Some(40),
1671 obj_access_cost_delete_per_byte: Some(40),
1672 obj_access_cost_verify_per_byte: Some(200),
1673 obj_data_cost_refundable: Some(100),
1674 obj_metadata_cost_non_refundable: Some(50),
1675 gas_model_version: Some(1),
1676 storage_rebate_rate: Some(10000),
1677 reward_slashing_rate: Some(10000),
1679 storage_gas_price: Some(76),
1680 base_gas_price: None,
1681 validator_target_reward: Some(767_000 * 1_000_000_000),
1684 max_transactions_per_checkpoint: Some(10_000),
1685 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
1686
1687 buffer_stake_for_protocol_upgrade_bps: Some(5000),
1689
1690 address_from_bytes_cost_base: Some(52),
1694 address_to_u256_cost_base: Some(52),
1696 address_from_u256_cost_base: Some(52),
1698
1699 config_read_setting_impl_cost_base: Some(100),
1702 config_read_setting_impl_cost_per_byte: Some(40),
1703
1704 dynamic_field_hash_type_and_key_cost_base: Some(100),
1708 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
1709 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
1710 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
1711 dynamic_field_add_child_object_cost_base: Some(100),
1714 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
1715 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
1716 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
1717 dynamic_field_borrow_child_object_cost_base: Some(100),
1720 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
1721 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
1722 dynamic_field_remove_child_object_cost_base: Some(100),
1725 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
1726 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
1727 dynamic_field_has_child_object_cost_base: Some(100),
1730 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
1733 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
1734 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
1735
1736 event_emit_cost_base: Some(52),
1739 event_emit_value_size_derivation_cost_per_byte: Some(2),
1740 event_emit_tag_size_derivation_cost_per_byte: Some(5),
1741 event_emit_output_cost_per_byte: Some(10),
1742
1743 object_borrow_uid_cost_base: Some(52),
1746 object_delete_impl_cost_base: Some(52),
1748 object_record_new_uid_cost_base: Some(52),
1750
1751 transfer_transfer_internal_cost_base: Some(52),
1755 transfer_freeze_object_cost_base: Some(52),
1757 transfer_share_object_cost_base: Some(52),
1759 transfer_receive_object_cost_base: Some(52),
1760
1761 tx_context_derive_id_cost_base: Some(52),
1765
1766 types_is_one_time_witness_cost_base: Some(52),
1769 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
1770 types_is_one_time_witness_type_cost_per_byte: Some(2),
1771
1772 validator_validate_metadata_cost_base: Some(52),
1776 validator_validate_metadata_data_cost_per_byte: Some(2),
1777
1778 crypto_invalid_arguments_cost: Some(100),
1780 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
1782 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
1783 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
1784
1785 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
1787 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
1788 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
1789
1790 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
1792 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1793 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1794 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
1795 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1796 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
1797
1798 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
1800
1801 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
1803 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
1804 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
1805 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
1806 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
1807 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
1808
1809 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
1811 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1812 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1813 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
1814 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1815 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
1816
1817 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
1819 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
1820 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
1821 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
1822 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
1823 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
1824
1825 ecvrf_ecvrf_verify_cost_base: Some(52),
1827 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
1828 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
1829
1830 ed25519_ed25519_verify_cost_base: Some(52),
1832 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
1833 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
1834
1835 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
1837 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
1838
1839 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
1841 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
1842 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
1843 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
1844 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
1845
1846 hash_blake2b256_cost_base: Some(52),
1848 hash_blake2b256_data_cost_per_byte: Some(2),
1849 hash_blake2b256_data_cost_per_block: Some(2),
1850 hash_keccak256_cost_base: Some(52),
1852 hash_keccak256_data_cost_per_byte: Some(2),
1853 hash_keccak256_data_cost_per_block: Some(2),
1854
1855 poseidon_bn254_cost_base: None,
1856 poseidon_bn254_cost_per_block: None,
1857
1858 hmac_hmac_sha3_256_cost_base: Some(52),
1860 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
1861 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
1862
1863 group_ops_bls12381_decode_scalar_cost: Some(52),
1865 group_ops_bls12381_decode_g1_cost: Some(52),
1866 group_ops_bls12381_decode_g2_cost: Some(52),
1867 group_ops_bls12381_decode_gt_cost: Some(52),
1868 group_ops_bls12381_scalar_add_cost: Some(52),
1869 group_ops_bls12381_g1_add_cost: Some(52),
1870 group_ops_bls12381_g2_add_cost: Some(52),
1871 group_ops_bls12381_gt_add_cost: Some(52),
1872 group_ops_bls12381_scalar_sub_cost: Some(52),
1873 group_ops_bls12381_g1_sub_cost: Some(52),
1874 group_ops_bls12381_g2_sub_cost: Some(52),
1875 group_ops_bls12381_gt_sub_cost: Some(52),
1876 group_ops_bls12381_scalar_mul_cost: Some(52),
1877 group_ops_bls12381_g1_mul_cost: Some(52),
1878 group_ops_bls12381_g2_mul_cost: Some(52),
1879 group_ops_bls12381_gt_mul_cost: Some(52),
1880 group_ops_bls12381_scalar_div_cost: Some(52),
1881 group_ops_bls12381_g1_div_cost: Some(52),
1882 group_ops_bls12381_g2_div_cost: Some(52),
1883 group_ops_bls12381_gt_div_cost: Some(52),
1884 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
1885 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
1886 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
1887 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
1888 group_ops_bls12381_g1_msm_base_cost: Some(52),
1889 group_ops_bls12381_g2_msm_base_cost: Some(52),
1890 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
1891 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
1892 group_ops_bls12381_msm_max_len: Some(32),
1893 group_ops_bls12381_pairing_cost: Some(52),
1894 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
1895 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
1896 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
1897 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
1898 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
1899
1900 check_zklogin_id_cost_base: Some(200),
1902 check_zklogin_issuer_cost_base: Some(200),
1904
1905 vdf_verify_vdf_cost: None,
1906 vdf_hash_to_input_cost: None,
1907
1908 bcs_per_byte_serialized_cost: Some(2),
1909 bcs_legacy_min_output_size_cost: Some(1),
1910 bcs_failure_cost: Some(52),
1911 hash_sha2_256_base_cost: Some(52),
1912 hash_sha2_256_per_byte_cost: Some(2),
1913 hash_sha2_256_legacy_min_input_len_cost: Some(1),
1914 hash_sha3_256_base_cost: Some(52),
1915 hash_sha3_256_per_byte_cost: Some(2),
1916 hash_sha3_256_legacy_min_input_len_cost: Some(1),
1917 type_name_get_base_cost: Some(52),
1918 type_name_get_per_byte_cost: Some(2),
1919 string_check_utf8_base_cost: Some(52),
1920 string_check_utf8_per_byte_cost: Some(2),
1921 string_is_char_boundary_base_cost: Some(52),
1922 string_sub_string_base_cost: Some(52),
1923 string_sub_string_per_byte_cost: Some(2),
1924 string_index_of_base_cost: Some(52),
1925 string_index_of_per_byte_pattern_cost: Some(2),
1926 string_index_of_per_byte_searched_cost: Some(2),
1927 vector_empty_base_cost: Some(52),
1928 vector_length_base_cost: Some(52),
1929 vector_push_back_base_cost: Some(52),
1930 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
1931 vector_borrow_base_cost: Some(52),
1932 vector_pop_back_base_cost: Some(52),
1933 vector_destroy_empty_base_cost: Some(52),
1934 vector_swap_base_cost: Some(52),
1935 debug_print_base_cost: Some(52),
1936 debug_print_stack_trace_base_cost: Some(52),
1937
1938 max_size_written_objects: Some(5 * 1000 * 1000),
1939 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
1942
1943 max_move_identifier_len: Some(128),
1945 max_move_value_depth: Some(128),
1946 max_move_enum_variants: None,
1947
1948 gas_rounding_step: Some(1_000),
1949
1950 execution_version: Some(1),
1951
1952 max_event_emit_size_total: Some(
1955 256 * 250 * 1024, ),
1957
1958 consensus_bad_nodes_stake_threshold: Some(20),
1965
1966 max_jwk_votes_per_validator_per_epoch: Some(240),
1968
1969 max_age_of_jwk_in_epochs: Some(1),
1970
1971 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
1975
1976 random_beacon_reduction_allowed_delta: Some(800),
1977
1978 random_beacon_reduction_lower_bound: Some(1000),
1979 random_beacon_dkg_timeout_round: Some(3000),
1980 random_beacon_min_round_interval_ms: Some(500),
1981
1982 random_beacon_dkg_version: Some(1),
1983
1984 consensus_max_num_transactions_in_block: Some(512),
1988
1989 max_deferral_rounds_for_congestion_control: Some(10),
1990
1991 min_checkpoint_interval_ms: Some(200),
1992
1993 checkpoint_summary_version_specific_data: Some(1),
1994
1995 max_soft_bundle_size: Some(5),
1996
1997 bridge_should_try_to_finalize_committee: None,
1998
1999 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2000
2001 max_committee_members_count: None,
2002
2003 consensus_gc_depth: None,
2004
2005 consensus_max_acknowledgments_per_block: None,
2006
2007 max_congestion_limit_overshoot_per_commit: None,
2008 };
2011
2012 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2013
2014 {
2016 cfg.feature_flags
2017 .disable_invariant_violation_check_in_swap_loc = true;
2018 cfg.feature_flags.no_extraneous_module_bytes = true;
2019 cfg.feature_flags.hardened_otw_check = true;
2020 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2021 }
2022
2023 {
2025 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2026 }
2027
2028 cfg.feature_flags.consensus_choice = ConsensusChoice::Mysticeti;
2030 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2032
2033 cfg.feature_flags.per_object_congestion_control_mode =
2034 PerObjectCongestionControlMode::TotalTxCount;
2035
2036 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2038
2039 if chain != Chain::Mainnet && chain != Chain::Testnet {
2041 cfg.feature_flags.enable_poseidon = true;
2042 cfg.poseidon_bn254_cost_base = Some(260);
2043 cfg.poseidon_bn254_cost_per_block = Some(10);
2044
2045 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2046
2047 cfg.feature_flags.enable_vdf = true;
2048 cfg.vdf_verify_vdf_cost = Some(1500);
2051 cfg.vdf_hash_to_input_cost = Some(100);
2052
2053 cfg.feature_flags.passkey_auth = true;
2054 }
2055
2056 for cur in 2..=version.0 {
2057 match cur {
2058 1 => unreachable!(),
2059 2 => {}
2061 3 => {
2062 cfg.feature_flags.relocate_event_module = true;
2063 }
2064 4 => {
2065 cfg.max_type_to_layout_nodes = Some(512);
2066 }
2067 5 => {
2068 cfg.feature_flags.protocol_defined_base_fee = true;
2069 cfg.base_gas_price = Some(1000);
2070
2071 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2072 cfg.feature_flags.convert_type_argument_error = true;
2073 cfg.feature_flags.native_charging_v2 = true;
2074
2075 if chain != Chain::Mainnet && chain != Chain::Testnet {
2076 cfg.feature_flags.uncompressed_g1_group_elements = true;
2077 }
2078
2079 cfg.gas_model_version = Some(2);
2080
2081 cfg.poseidon_bn254_cost_per_block = Some(388);
2082
2083 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2084 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2085 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2086 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2087 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2088 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2089 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2090 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2091
2092 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2094 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2095 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2096 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2097
2098 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2099 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2100 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2101 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2102 Some(8213);
2103 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2104 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2105 Some(9484);
2106
2107 cfg.hash_keccak256_cost_base = Some(10);
2108 cfg.hash_blake2b256_cost_base = Some(10);
2109
2110 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2112 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2113 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2114 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2115
2116 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2117 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2118 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2119 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2120
2121 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2122 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2123 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2124 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2125
2126 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2127 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2128 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2129 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2130
2131 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2132 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2133 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2134 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2135
2136 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2137 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2138
2139 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2140 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2141 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2142 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2143
2144 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2145 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2146 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2147 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2148 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2149
2150 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2151
2152 cfg.validator_validate_metadata_cost_base = Some(20000);
2153
2154 cfg.max_committee_members_count = Some(50);
2155 }
2156 6 => {
2157 cfg.max_ptb_value_size = Some(1024 * 1024);
2158 }
2159 7 => {
2160 }
2163 8 => {
2164 cfg.feature_flags.variant_nodes = true;
2165
2166 if chain != Chain::Mainnet {
2167 cfg.feature_flags.consensus_round_prober = true;
2169 cfg.feature_flags
2171 .consensus_distributed_vote_scoring_strategy = true;
2172 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2173 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2175 cfg.feature_flags
2177 .consensus_round_prober_probe_accepted_rounds = true;
2178 cfg.feature_flags.consensus_zstd_compression = true;
2180 cfg.consensus_gc_depth = Some(60);
2184 }
2185
2186 if chain != Chain::Testnet && chain != Chain::Mainnet {
2189 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2190 }
2191 }
2192 9 => {
2193 if chain != Chain::Mainnet {
2194 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2196 }
2197
2198 cfg.feature_flags.consensus_zstd_compression = true;
2200
2201 if chain != Chain::Testnet && chain != Chain::Mainnet {
2203 cfg.feature_flags.accept_passkey_in_multisig = true;
2204 }
2205
2206 cfg.bridge_should_try_to_finalize_committee = None;
2208 }
2209 10 => {
2210 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2213
2214 cfg.max_committee_members_count = Some(80);
2216
2217 cfg.feature_flags.consensus_round_prober = true;
2219 cfg.feature_flags
2221 .consensus_round_prober_probe_accepted_rounds = true;
2222 cfg.feature_flags
2224 .consensus_distributed_vote_scoring_strategy = true;
2225 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2227
2228 cfg.consensus_gc_depth = Some(60);
2233
2234 cfg.feature_flags.minimize_child_object_mutations = true;
2236
2237 if chain != Chain::Mainnet {
2238 cfg.feature_flags.consensus_batched_block_sync = true;
2240 }
2241
2242 if chain != Chain::Testnet && chain != Chain::Mainnet {
2243 cfg.feature_flags
2246 .congestion_control_gas_price_feedback_mechanism = true;
2247 }
2248
2249 cfg.feature_flags.validate_identifier_inputs = true;
2250 cfg.feature_flags.dependency_linkage_error = true;
2251 cfg.feature_flags.additional_multisig_checks = true;
2252 }
2253 11 => {
2254 }
2257 12 => {
2258 cfg.feature_flags
2261 .congestion_control_gas_price_feedback_mechanism = true;
2262
2263 cfg.feature_flags.normalize_ptb_arguments = true;
2265 }
2266 13 => {
2267 cfg.feature_flags.select_committee_from_eligible_validators = true;
2270 cfg.feature_flags.track_non_committee_eligible_validators = true;
2273
2274 if chain != Chain::Testnet && chain != Chain::Mainnet {
2275 cfg.feature_flags
2278 .select_committee_supporting_next_epoch_version = true;
2279 }
2280 }
2281 14 => {
2282 cfg.feature_flags.consensus_batched_block_sync = true;
2284
2285 if chain != Chain::Mainnet {
2286 cfg.feature_flags
2289 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2290 cfg.feature_flags
2294 .select_committee_supporting_next_epoch_version = true;
2295 }
2296 if chain != Chain::Testnet && chain != Chain::Mainnet {
2297 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2299 }
2300 }
2301 15 => {
2302 if chain != Chain::Mainnet && chain != Chain::Testnet {
2303 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2307 }
2308 }
2309 16 => {
2310 cfg.feature_flags
2313 .select_committee_supporting_next_epoch_version = true;
2314 cfg.feature_flags
2316 .consensus_commit_transactions_only_for_traversed_headers = true;
2317 }
2318 _ => panic!("unsupported version {version:?}"),
2329 }
2330 }
2331 cfg
2332 }
2333
2334 pub fn verifier_config(&self, signing_limits: Option<(usize, usize)>) -> VerifierConfig {
2338 let (max_back_edges_per_function, max_back_edges_per_module) = if let Some((
2339 max_back_edges_per_function,
2340 max_back_edges_per_module,
2341 )) = signing_limits
2342 {
2343 (
2344 Some(max_back_edges_per_function),
2345 Some(max_back_edges_per_module),
2346 )
2347 } else {
2348 (None, None)
2349 };
2350
2351 VerifierConfig {
2352 max_loop_depth: Some(self.max_loop_depth() as usize),
2353 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2354 max_function_parameters: Some(self.max_function_parameters() as usize),
2355 max_basic_blocks: Some(self.max_basic_blocks() as usize),
2356 max_value_stack_size: self.max_value_stack_size() as usize,
2357 max_type_nodes: Some(self.max_type_nodes() as usize),
2358 max_push_size: Some(self.max_push_size() as usize),
2359 max_dependency_depth: Some(self.max_dependency_depth() as usize),
2360 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2361 max_function_definitions: Some(self.max_function_definitions() as usize),
2362 max_data_definitions: Some(self.max_struct_definitions() as usize),
2363 max_constant_vector_len: Some(self.max_move_vector_len()),
2364 max_back_edges_per_function,
2365 max_back_edges_per_module,
2366 max_basic_blocks_in_script: None,
2367 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
2371 max_variants_in_enum: self.max_move_enum_variants_as_option(),
2372 }
2373 }
2374
2375 pub fn apply_overrides_for_testing(
2380 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
2381 ) -> OverrideGuard {
2382 CONFIG_OVERRIDE.with(|ovr| {
2383 let mut cur = ovr.borrow_mut();
2384 assert!(cur.is_none(), "config override already present");
2385 *cur = Some(Box::new(override_fn));
2386 OverrideGuard
2387 })
2388 }
2389}
2390
2391impl ProtocolConfig {
2396 pub fn set_zklogin_auth_for_testing(&mut self, val: bool) {
2397 self.feature_flags.zklogin_auth = val
2398 }
2399 pub fn set_enable_jwk_consensus_updates_for_testing(&mut self, val: bool) {
2400 self.feature_flags.enable_jwk_consensus_updates = val
2401 }
2402
2403 pub fn set_accept_zklogin_in_multisig_for_testing(&mut self, val: bool) {
2404 self.feature_flags.accept_zklogin_in_multisig = val
2405 }
2406
2407 pub fn set_per_object_congestion_control_mode_for_testing(
2408 &mut self,
2409 val: PerObjectCongestionControlMode,
2410 ) {
2411 self.feature_flags.per_object_congestion_control_mode = val;
2412 }
2413
2414 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
2415 self.feature_flags.consensus_choice = val;
2416 }
2417
2418 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
2419 self.feature_flags.consensus_network = val;
2420 }
2421
2422 pub fn set_zklogin_max_epoch_upper_bound_delta_for_testing(&mut self, val: Option<u64>) {
2423 self.feature_flags.zklogin_max_epoch_upper_bound_delta = val
2424 }
2425
2426 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
2427 self.feature_flags.passkey_auth = val
2428 }
2429
2430 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
2431 self.feature_flags
2432 .disallow_new_modules_in_deps_only_packages = val;
2433 }
2434
2435 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
2436 self.feature_flags.consensus_round_prober = val;
2437 }
2438
2439 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
2440 self.feature_flags
2441 .consensus_distributed_vote_scoring_strategy = val;
2442 }
2443
2444 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
2445 self.consensus_gc_depth = Some(val);
2446 }
2447
2448 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
2449 self.feature_flags.consensus_linearize_subdag_v2 = val;
2450 }
2451
2452 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
2453 self.feature_flags
2454 .consensus_round_prober_probe_accepted_rounds = val;
2455 }
2456
2457 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
2458 self.feature_flags.accept_passkey_in_multisig = val;
2459 }
2460
2461 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
2462 self.feature_flags.consensus_smart_ancestor_selection = val;
2463 }
2464
2465 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
2466 self.feature_flags.consensus_batched_block_sync = val;
2467 }
2468
2469 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
2470 self.feature_flags
2471 .congestion_control_min_free_execution_slot = val;
2472 }
2473
2474 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
2475 self.feature_flags
2476 .congestion_control_gas_price_feedback_mechanism = val;
2477 }
2478 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
2479 self.feature_flags.select_committee_from_eligible_validators = val;
2480 }
2481
2482 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
2483 self.feature_flags.track_non_committee_eligible_validators = val;
2484 }
2485
2486 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
2487 self.feature_flags
2488 .select_committee_supporting_next_epoch_version = val;
2489 }
2490
2491 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
2492 &mut self,
2493 val: bool,
2494 ) {
2495 self.feature_flags
2496 .consensus_median_timestamp_with_checkpoint_enforcement = val;
2497 }
2498 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
2499 &mut self,
2500 val: bool,
2501 ) {
2502 self.feature_flags
2503 .consensus_commit_transactions_only_for_traversed_headers = val;
2504 }
2505}
2506
2507type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
2508
2509thread_local! {
2510 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
2511}
2512
2513#[must_use]
2514pub struct OverrideGuard;
2515
2516impl Drop for OverrideGuard {
2517 fn drop(&mut self) {
2518 info!("restoring override fn");
2519 CONFIG_OVERRIDE.with(|ovr| {
2520 *ovr.borrow_mut() = None;
2521 });
2522 }
2523}
2524
2525#[derive(PartialEq, Eq)]
2529pub enum LimitThresholdCrossed {
2530 None,
2531 Soft(u128, u128),
2532 Hard(u128, u128),
2533}
2534
2535pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
2538 x: T,
2539 soft_limit: U,
2540 hard_limit: V,
2541) -> LimitThresholdCrossed {
2542 let x: V = x.into();
2543 let soft_limit: V = soft_limit.into();
2544
2545 debug_assert!(soft_limit <= hard_limit);
2546
2547 if x >= hard_limit {
2550 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
2551 } else if x < soft_limit {
2552 LimitThresholdCrossed::None
2553 } else {
2554 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
2555 }
2556}
2557
2558#[macro_export]
2559macro_rules! check_limit {
2560 ($x:expr, $hard:expr) => {
2561 check_limit!($x, $hard, $hard)
2562 };
2563 ($x:expr, $soft:expr, $hard:expr) => {
2564 check_limit_in_range($x as u64, $soft, $hard)
2565 };
2566}
2567
2568#[macro_export]
2572macro_rules! check_limit_by_meter {
2573 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
2574 let (h, metered_str) = if $is_metered {
2576 ($metered_limit, "metered")
2577 } else {
2578 ($unmetered_hard_limit, "unmetered")
2580 };
2581 use iota_protocol_config::check_limit_in_range;
2582 let result = check_limit_in_range($x as u64, $metered_limit, h);
2583 match result {
2584 LimitThresholdCrossed::None => {}
2585 LimitThresholdCrossed::Soft(_, _) => {
2586 $metric.with_label_values(&[metered_str, "soft"]).inc();
2587 }
2588 LimitThresholdCrossed::Hard(_, _) => {
2589 $metric.with_label_values(&[metered_str, "hard"]).inc();
2590 }
2591 };
2592 result
2593 }};
2594}
2595
2596#[cfg(all(test, not(msim)))]
2597mod test {
2598 use insta::assert_yaml_snapshot;
2599
2600 use super::*;
2601
2602 #[test]
2603 fn snapshot_tests() {
2604 println!("\n============================================================================");
2605 println!("! !");
2606 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
2607 println!("! !");
2608 println!("============================================================================\n");
2609 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
2610 let chain_str = match chain_id {
2615 Chain::Unknown => "".to_string(),
2616 _ => format!("{chain_id:?}_"),
2617 };
2618 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
2619 let cur = ProtocolVersion::new(i);
2620 assert_yaml_snapshot!(
2621 format!("{}version_{}", chain_str, cur.as_u64()),
2622 ProtocolConfig::get_for_version(cur, *chain_id)
2623 );
2624 }
2625 }
2626 }
2627
2628 #[test]
2629 fn test_getters() {
2630 let prot: ProtocolConfig =
2631 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2632 assert_eq!(
2633 prot.max_arguments(),
2634 prot.max_arguments_as_option().unwrap()
2635 );
2636 }
2637
2638 #[test]
2639 fn test_setters() {
2640 let mut prot: ProtocolConfig =
2641 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2642 prot.set_max_arguments_for_testing(123);
2643 assert_eq!(prot.max_arguments(), 123);
2644
2645 prot.set_max_arguments_from_str_for_testing("321".to_string());
2646 assert_eq!(prot.max_arguments(), 321);
2647
2648 prot.disable_max_arguments_for_testing();
2649 assert_eq!(prot.max_arguments_as_option(), None);
2650
2651 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
2652 assert_eq!(prot.max_arguments(), 456);
2653 }
2654
2655 #[test]
2656 #[should_panic(expected = "unsupported version")]
2657 fn max_version_test() {
2658 let _ = ProtocolConfig::get_for_version_impl(
2661 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
2662 Chain::Unknown,
2663 );
2664 }
2665
2666 #[test]
2667 fn lookup_by_string_test() {
2668 let prot: ProtocolConfig =
2669 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2670 assert!(prot.lookup_attr("some random string".to_string()).is_none());
2672
2673 assert!(
2674 prot.lookup_attr("max_arguments".to_string())
2675 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
2676 );
2677
2678 assert!(
2680 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2681 .is_none()
2682 );
2683 assert!(
2684 prot.attr_map()
2685 .get("poseidon_bn254_cost_base")
2686 .unwrap()
2687 .is_none()
2688 );
2689
2690 let prot: ProtocolConfig =
2692 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2693
2694 assert!(
2695 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2696 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2697 );
2698 assert!(
2699 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
2700 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2701 );
2702
2703 let prot: ProtocolConfig =
2705 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2706 assert!(
2708 prot.feature_flags
2709 .lookup_attr("some random string".to_owned())
2710 .is_none()
2711 );
2712 assert!(
2713 !prot
2714 .feature_flags
2715 .attr_map()
2716 .contains_key("some random string")
2717 );
2718
2719 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
2721 assert!(
2722 prot.feature_flags
2723 .attr_map()
2724 .get("enable_poseidon")
2725 .unwrap()
2726 == &false
2727 );
2728 let prot: ProtocolConfig =
2729 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2730 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
2732 assert!(
2733 prot.feature_flags
2734 .attr_map()
2735 .get("enable_poseidon")
2736 .unwrap()
2737 == &true
2738 );
2739 }
2740
2741 #[test]
2742 fn limit_range_fn_test() {
2743 let low = 100u32;
2744 let high = 10000u64;
2745
2746 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
2747 assert!(matches!(
2748 check_limit!(255u16, low, high),
2749 LimitThresholdCrossed::Soft(255u128, 100)
2750 ));
2751 assert!(matches!(
2758 check_limit!(2550000u64, low, high),
2759 LimitThresholdCrossed::Hard(2550000, 10000)
2760 ));
2761
2762 assert!(matches!(
2763 check_limit!(2550000u64, high, high),
2764 LimitThresholdCrossed::Hard(2550000, 10000)
2765 ));
2766
2767 assert!(matches!(
2768 check_limit!(1u8, high),
2769 LimitThresholdCrossed::None
2770 ));
2771
2772 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
2773
2774 assert!(matches!(
2775 check_limit!(2550000u64, high),
2776 LimitThresholdCrossed::Hard(2550000, 10000)
2777 ));
2778 }
2779}