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 = 17;
23
24#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
96pub struct ProtocolVersion(u64);
97
98impl ProtocolVersion {
99 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
105
106 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
107
108 #[cfg(not(msim))]
109 const MAX_ALLOWED: Self = Self::MAX;
110
111 #[cfg(msim)]
114 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
115
116 pub fn new(v: u64) -> Self {
117 Self(v)
118 }
119
120 pub const fn as_u64(&self) -> u64 {
121 self.0
122 }
123
124 pub fn max() -> Self {
127 Self::MAX
128 }
129}
130
131impl From<u64> for ProtocolVersion {
132 fn from(v: u64) -> Self {
133 Self::new(v)
134 }
135}
136
137impl std::ops::Sub<u64> for ProtocolVersion {
138 type Output = Self;
139 fn sub(self, rhs: u64) -> Self::Output {
140 Self::new(self.0 - rhs)
141 }
142}
143
144impl std::ops::Add<u64> for ProtocolVersion {
145 type Output = Self;
146 fn add(self, rhs: u64) -> Self::Output {
147 Self::new(self.0 + rhs)
148 }
149}
150
151#[derive(
152 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
153)]
154pub enum Chain {
155 Mainnet,
156 Testnet,
157 #[default]
158 Unknown,
159}
160
161impl Chain {
162 pub fn as_str(self) -> &'static str {
163 match self {
164 Chain::Mainnet => "mainnet",
165 Chain::Testnet => "testnet",
166 Chain::Unknown => "unknown",
167 }
168 }
169}
170
171pub struct Error(pub String);
172
173#[derive(Default, Clone, Serialize, Deserialize, Debug, ProtocolConfigFeatureFlagsGetters)]
177struct FeatureFlags {
178 #[serde(skip_serializing_if = "is_true")]
184 disable_invariant_violation_check_in_swap_loc: bool,
185
186 #[serde(skip_serializing_if = "is_true")]
189 no_extraneous_module_bytes: bool,
190
191 #[serde(skip_serializing_if = "is_false")]
193 zklogin_auth: bool,
194
195 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
197 consensus_transaction_ordering: ConsensusTransactionOrdering,
198
199 #[serde(skip_serializing_if = "is_false")]
200 enable_jwk_consensus_updates: bool,
201
202 #[serde(skip_serializing_if = "is_false")]
204 accept_zklogin_in_multisig: bool,
205
206 #[serde(skip_serializing_if = "is_true")]
209 hardened_otw_check: bool,
210
211 #[serde(skip_serializing_if = "is_false")]
213 enable_poseidon: bool,
214
215 #[serde(skip_serializing_if = "is_false")]
217 enable_group_ops_native_function_msm: bool,
218
219 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
221 per_object_congestion_control_mode: PerObjectCongestionControlMode,
222
223 #[serde(skip_serializing_if = "ConsensusChoice::is_mysticeti")]
225 consensus_choice: ConsensusChoice,
226
227 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
229 consensus_network: ConsensusNetwork,
230
231 #[serde(skip_serializing_if = "Option::is_none")]
233 zklogin_max_epoch_upper_bound_delta: Option<u64>,
234
235 #[serde(skip_serializing_if = "is_false")]
237 enable_vdf: bool,
238
239 #[serde(skip_serializing_if = "is_false")]
241 passkey_auth: bool,
242
243 #[serde(skip_serializing_if = "is_true")]
246 rethrow_serialization_type_layout_errors: bool,
247
248 #[serde(skip_serializing_if = "is_false")]
250 relocate_event_module: bool,
251
252 #[serde(skip_serializing_if = "is_false")]
254 protocol_defined_base_fee: bool,
255
256 #[serde(skip_serializing_if = "is_false")]
258 uncompressed_g1_group_elements: bool,
259
260 #[serde(skip_serializing_if = "is_false")]
262 disallow_new_modules_in_deps_only_packages: bool,
263
264 #[serde(skip_serializing_if = "is_false")]
266 native_charging_v2: bool,
267
268 #[serde(skip_serializing_if = "is_false")]
270 convert_type_argument_error: bool,
271
272 #[serde(skip_serializing_if = "is_false")]
274 consensus_round_prober: bool,
275
276 #[serde(skip_serializing_if = "is_false")]
278 consensus_distributed_vote_scoring_strategy: bool,
279
280 #[serde(skip_serializing_if = "is_false")]
284 consensus_linearize_subdag_v2: bool,
285
286 #[serde(skip_serializing_if = "is_false")]
288 variant_nodes: bool,
289
290 #[serde(skip_serializing_if = "is_false")]
292 consensus_smart_ancestor_selection: bool,
293
294 #[serde(skip_serializing_if = "is_false")]
296 consensus_round_prober_probe_accepted_rounds: bool,
297
298 #[serde(skip_serializing_if = "is_false")]
300 consensus_zstd_compression: bool,
301
302 #[serde(skip_serializing_if = "is_false")]
305 congestion_control_min_free_execution_slot: bool,
306
307 #[serde(skip_serializing_if = "is_false")]
309 accept_passkey_in_multisig: bool,
310
311 #[serde(skip_serializing_if = "is_false")]
313 consensus_batched_block_sync: bool,
314
315 #[serde(skip_serializing_if = "is_false")]
318 congestion_control_gas_price_feedback_mechanism: bool,
319
320 #[serde(skip_serializing_if = "is_false")]
322 validate_identifier_inputs: bool,
323
324 #[serde(skip_serializing_if = "is_false")]
327 minimize_child_object_mutations: bool,
328
329 #[serde(skip_serializing_if = "is_false")]
331 dependency_linkage_error: bool,
332
333 #[serde(skip_serializing_if = "is_false")]
335 additional_multisig_checks: bool,
336
337 #[serde(skip_serializing_if = "is_false")]
340 normalize_ptb_arguments: bool,
341
342 #[serde(skip_serializing_if = "is_false")]
346 select_committee_from_eligible_validators: bool,
347
348 #[serde(skip_serializing_if = "is_false")]
355 track_non_committee_eligible_validators: bool,
356
357 #[serde(skip_serializing_if = "is_false")]
363 select_committee_supporting_next_epoch_version: bool,
364
365 #[serde(skip_serializing_if = "is_false")]
369 consensus_median_timestamp_with_checkpoint_enforcement: bool,
370 #[serde(skip_serializing_if = "is_false")]
372 consensus_commit_transactions_only_for_traversed_headers: bool,
373}
374
375fn is_true(b: &bool) -> bool {
376 *b
377}
378
379fn is_false(b: &bool) -> bool {
380 !b
381}
382
383#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
385pub enum ConsensusTransactionOrdering {
386 #[default]
389 None,
390 ByGasPrice,
392}
393
394impl ConsensusTransactionOrdering {
395 pub fn is_none(&self) -> bool {
396 matches!(self, ConsensusTransactionOrdering::None)
397 }
398}
399
400#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
402pub enum PerObjectCongestionControlMode {
403 #[default]
404 None, TotalGasBudget, TotalTxCount, }
408
409impl PerObjectCongestionControlMode {
410 pub fn is_none(&self) -> bool {
411 matches!(self, PerObjectCongestionControlMode::None)
412 }
413}
414
415#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
417pub enum ConsensusChoice {
418 #[default]
419 Mysticeti,
420 Starfish,
421}
422
423impl ConsensusChoice {
424 pub fn is_mysticeti(&self) -> bool {
425 matches!(self, ConsensusChoice::Mysticeti)
426 }
427 pub fn is_starfish(&self) -> bool {
428 matches!(self, ConsensusChoice::Starfish)
429 }
430}
431
432#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
434pub enum ConsensusNetwork {
435 #[default]
436 Tonic,
437}
438
439impl ConsensusNetwork {
440 pub fn is_tonic(&self) -> bool {
441 matches!(self, ConsensusNetwork::Tonic)
442 }
443}
444
445#[skip_serializing_none]
479#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
480pub struct ProtocolConfig {
481 pub version: ProtocolVersion,
482
483 feature_flags: FeatureFlags,
484
485 max_tx_size_bytes: Option<u64>,
490
491 max_input_objects: Option<u64>,
494
495 max_size_written_objects: Option<u64>,
500 max_size_written_objects_system_tx: Option<u64>,
504
505 max_serialized_tx_effects_size_bytes: Option<u64>,
507
508 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
510
511 max_gas_payment_objects: Option<u32>,
513
514 max_modules_in_publish: Option<u32>,
516
517 max_package_dependencies: Option<u32>,
519
520 max_arguments: Option<u32>,
523
524 max_type_arguments: Option<u32>,
526
527 max_type_argument_depth: Option<u32>,
529
530 max_pure_argument_size: Option<u32>,
532
533 max_programmable_tx_commands: Option<u32>,
535
536 move_binary_format_version: Option<u32>,
542 min_move_binary_format_version: Option<u32>,
543
544 binary_module_handles: Option<u16>,
546 binary_struct_handles: Option<u16>,
547 binary_function_handles: Option<u16>,
548 binary_function_instantiations: Option<u16>,
549 binary_signatures: Option<u16>,
550 binary_constant_pool: Option<u16>,
551 binary_identifiers: Option<u16>,
552 binary_address_identifiers: Option<u16>,
553 binary_struct_defs: Option<u16>,
554 binary_struct_def_instantiations: Option<u16>,
555 binary_function_defs: Option<u16>,
556 binary_field_handles: Option<u16>,
557 binary_field_instantiations: Option<u16>,
558 binary_friend_decls: Option<u16>,
559 binary_enum_defs: Option<u16>,
560 binary_enum_def_instantiations: Option<u16>,
561 binary_variant_handles: Option<u16>,
562 binary_variant_instantiation_handles: Option<u16>,
563
564 max_move_object_size: Option<u64>,
567
568 max_move_package_size: Option<u64>,
573
574 max_publish_or_upgrade_per_ptb: Option<u64>,
577
578 max_tx_gas: Option<u64>,
580
581 max_gas_price: Option<u64>,
584
585 max_gas_computation_bucket: Option<u64>,
588
589 gas_rounding_step: Option<u64>,
591
592 max_loop_depth: Option<u64>,
594
595 max_generic_instantiation_length: Option<u64>,
598
599 max_function_parameters: Option<u64>,
602
603 max_basic_blocks: Option<u64>,
606
607 max_value_stack_size: Option<u64>,
609
610 max_type_nodes: Option<u64>,
614
615 max_push_size: Option<u64>,
618
619 max_struct_definitions: Option<u64>,
622
623 max_function_definitions: Option<u64>,
626
627 max_fields_in_struct: Option<u64>,
630
631 max_dependency_depth: Option<u64>,
634
635 max_num_event_emit: Option<u64>,
638
639 max_num_new_move_object_ids: Option<u64>,
642
643 max_num_new_move_object_ids_system_tx: Option<u64>,
646
647 max_num_deleted_move_object_ids: Option<u64>,
650
651 max_num_deleted_move_object_ids_system_tx: Option<u64>,
654
655 max_num_transferred_move_object_ids: Option<u64>,
658
659 max_num_transferred_move_object_ids_system_tx: Option<u64>,
662
663 max_event_emit_size: Option<u64>,
665
666 max_event_emit_size_total: Option<u64>,
668
669 max_move_vector_len: Option<u64>,
672
673 max_move_identifier_len: Option<u64>,
676
677 max_move_value_depth: Option<u64>,
679
680 max_move_enum_variants: Option<u64>,
683
684 max_back_edges_per_function: Option<u64>,
687
688 max_back_edges_per_module: Option<u64>,
691
692 max_verifier_meter_ticks_per_function: Option<u64>,
695
696 max_meter_ticks_per_module: Option<u64>,
699
700 max_meter_ticks_per_package: Option<u64>,
703
704 object_runtime_max_num_cached_objects: Option<u64>,
711
712 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
715
716 object_runtime_max_num_store_entries: Option<u64>,
719
720 object_runtime_max_num_store_entries_system_tx: Option<u64>,
723
724 base_tx_cost_fixed: Option<u64>,
729
730 package_publish_cost_fixed: Option<u64>,
734
735 base_tx_cost_per_byte: Option<u64>,
739
740 package_publish_cost_per_byte: Option<u64>,
742
743 obj_access_cost_read_per_byte: Option<u64>,
745
746 obj_access_cost_mutate_per_byte: Option<u64>,
748
749 obj_access_cost_delete_per_byte: Option<u64>,
751
752 obj_access_cost_verify_per_byte: Option<u64>,
762
763 max_type_to_layout_nodes: Option<u64>,
765
766 max_ptb_value_size: Option<u64>,
768
769 gas_model_version: Option<u64>,
774
775 obj_data_cost_refundable: Option<u64>,
781
782 obj_metadata_cost_non_refundable: Option<u64>,
786
787 storage_rebate_rate: Option<u64>,
793
794 reward_slashing_rate: Option<u64>,
797
798 storage_gas_price: Option<u64>,
800
801 base_gas_price: Option<u64>,
803
804 validator_target_reward: Option<u64>,
806
807 max_transactions_per_checkpoint: Option<u64>,
814
815 max_checkpoint_size_bytes: Option<u64>,
819
820 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
826
827 address_from_bytes_cost_base: Option<u64>,
832 address_to_u256_cost_base: Option<u64>,
834 address_from_u256_cost_base: Option<u64>,
836
837 config_read_setting_impl_cost_base: Option<u64>,
842 config_read_setting_impl_cost_per_byte: Option<u64>,
843
844 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
848 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
849 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
850 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
851 dynamic_field_add_child_object_cost_base: Option<u64>,
854 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
855 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
856 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
857 dynamic_field_borrow_child_object_cost_base: Option<u64>,
860 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
861 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
862 dynamic_field_remove_child_object_cost_base: Option<u64>,
865 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
866 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
867 dynamic_field_has_child_object_cost_base: Option<u64>,
870 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
873 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
874 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
875
876 event_emit_cost_base: Option<u64>,
879 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
880 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
881 event_emit_output_cost_per_byte: Option<u64>,
882
883 object_borrow_uid_cost_base: Option<u64>,
886 object_delete_impl_cost_base: Option<u64>,
888 object_record_new_uid_cost_base: Option<u64>,
890
891 transfer_transfer_internal_cost_base: Option<u64>,
894 transfer_freeze_object_cost_base: Option<u64>,
896 transfer_share_object_cost_base: Option<u64>,
898 transfer_receive_object_cost_base: Option<u64>,
901
902 tx_context_derive_id_cost_base: Option<u64>,
905
906 types_is_one_time_witness_cost_base: Option<u64>,
909 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
910 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
911
912 validator_validate_metadata_cost_base: Option<u64>,
915 validator_validate_metadata_data_cost_per_byte: Option<u64>,
916
917 crypto_invalid_arguments_cost: Option<u64>,
919 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
921 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
922 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
923
924 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
926 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
927 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
928
929 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
931 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
932 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
933 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
934 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
935 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
936
937 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
939
940 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
942 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
943 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
944 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
945 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
946 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
947
948 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
950 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
951 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
952 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
953 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
954 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
955
956 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
958 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
959 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
960 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
961 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
962 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
963
964 ecvrf_ecvrf_verify_cost_base: Option<u64>,
966 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
967 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
968
969 ed25519_ed25519_verify_cost_base: Option<u64>,
971 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
972 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
973
974 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
976 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
977
978 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
980 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
981 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
982 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
983 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
984
985 hash_blake2b256_cost_base: Option<u64>,
987 hash_blake2b256_data_cost_per_byte: Option<u64>,
988 hash_blake2b256_data_cost_per_block: Option<u64>,
989
990 hash_keccak256_cost_base: Option<u64>,
992 hash_keccak256_data_cost_per_byte: Option<u64>,
993 hash_keccak256_data_cost_per_block: Option<u64>,
994
995 poseidon_bn254_cost_base: Option<u64>,
997 poseidon_bn254_cost_per_block: Option<u64>,
998
999 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1001 group_ops_bls12381_decode_g1_cost: Option<u64>,
1002 group_ops_bls12381_decode_g2_cost: Option<u64>,
1003 group_ops_bls12381_decode_gt_cost: Option<u64>,
1004 group_ops_bls12381_scalar_add_cost: Option<u64>,
1005 group_ops_bls12381_g1_add_cost: Option<u64>,
1006 group_ops_bls12381_g2_add_cost: Option<u64>,
1007 group_ops_bls12381_gt_add_cost: Option<u64>,
1008 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1009 group_ops_bls12381_g1_sub_cost: Option<u64>,
1010 group_ops_bls12381_g2_sub_cost: Option<u64>,
1011 group_ops_bls12381_gt_sub_cost: Option<u64>,
1012 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1013 group_ops_bls12381_g1_mul_cost: Option<u64>,
1014 group_ops_bls12381_g2_mul_cost: Option<u64>,
1015 group_ops_bls12381_gt_mul_cost: Option<u64>,
1016 group_ops_bls12381_scalar_div_cost: Option<u64>,
1017 group_ops_bls12381_g1_div_cost: Option<u64>,
1018 group_ops_bls12381_g2_div_cost: Option<u64>,
1019 group_ops_bls12381_gt_div_cost: Option<u64>,
1020 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1021 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1022 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1023 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1024 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1025 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1026 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1027 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1028 group_ops_bls12381_msm_max_len: Option<u32>,
1029 group_ops_bls12381_pairing_cost: Option<u64>,
1030 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1031 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1032 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1033 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1034 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1035
1036 hmac_hmac_sha3_256_cost_base: Option<u64>,
1038 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1039 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1040
1041 check_zklogin_id_cost_base: Option<u64>,
1043 check_zklogin_issuer_cost_base: Option<u64>,
1045
1046 vdf_verify_vdf_cost: Option<u64>,
1047 vdf_hash_to_input_cost: Option<u64>,
1048
1049 bcs_per_byte_serialized_cost: Option<u64>,
1051 bcs_legacy_min_output_size_cost: Option<u64>,
1052 bcs_failure_cost: Option<u64>,
1053
1054 hash_sha2_256_base_cost: Option<u64>,
1055 hash_sha2_256_per_byte_cost: Option<u64>,
1056 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1057 hash_sha3_256_base_cost: Option<u64>,
1058 hash_sha3_256_per_byte_cost: Option<u64>,
1059 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1060 type_name_get_base_cost: Option<u64>,
1061 type_name_get_per_byte_cost: Option<u64>,
1062
1063 string_check_utf8_base_cost: Option<u64>,
1064 string_check_utf8_per_byte_cost: Option<u64>,
1065 string_is_char_boundary_base_cost: Option<u64>,
1066 string_sub_string_base_cost: Option<u64>,
1067 string_sub_string_per_byte_cost: Option<u64>,
1068 string_index_of_base_cost: Option<u64>,
1069 string_index_of_per_byte_pattern_cost: Option<u64>,
1070 string_index_of_per_byte_searched_cost: Option<u64>,
1071
1072 vector_empty_base_cost: Option<u64>,
1073 vector_length_base_cost: Option<u64>,
1074 vector_push_back_base_cost: Option<u64>,
1075 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1076 vector_borrow_base_cost: Option<u64>,
1077 vector_pop_back_base_cost: Option<u64>,
1078 vector_destroy_empty_base_cost: Option<u64>,
1079 vector_swap_base_cost: Option<u64>,
1080 debug_print_base_cost: Option<u64>,
1081 debug_print_stack_trace_base_cost: Option<u64>,
1082
1083 execution_version: Option<u64>,
1085
1086 consensus_bad_nodes_stake_threshold: Option<u64>,
1090
1091 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1092 max_age_of_jwk_in_epochs: Option<u64>,
1096
1097 random_beacon_reduction_allowed_delta: Option<u16>,
1101
1102 random_beacon_reduction_lower_bound: Option<u32>,
1105
1106 random_beacon_dkg_timeout_round: Option<u32>,
1109
1110 random_beacon_min_round_interval_ms: Option<u64>,
1112
1113 random_beacon_dkg_version: Option<u64>,
1117
1118 consensus_max_transaction_size_bytes: Option<u64>,
1123 consensus_max_transactions_in_block_bytes: Option<u64>,
1125 consensus_max_num_transactions_in_block: Option<u64>,
1127
1128 max_deferral_rounds_for_congestion_control: Option<u64>,
1132
1133 min_checkpoint_interval_ms: Option<u64>,
1135
1136 checkpoint_summary_version_specific_data: Option<u64>,
1138
1139 max_soft_bundle_size: Option<u64>,
1142
1143 bridge_should_try_to_finalize_committee: Option<bool>,
1148
1149 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1155
1156 max_committee_members_count: Option<u64>,
1160
1161 consensus_gc_depth: Option<u32>,
1164
1165 consensus_max_acknowledgments_per_block: Option<u32>,
1171
1172 max_congestion_limit_overshoot_per_commit: Option<u64>,
1177}
1178
1179impl ProtocolConfig {
1181 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1194 self.feature_flags
1195 .disable_invariant_violation_check_in_swap_loc
1196 }
1197
1198 pub fn no_extraneous_module_bytes(&self) -> bool {
1199 self.feature_flags.no_extraneous_module_bytes
1200 }
1201
1202 pub fn zklogin_auth(&self) -> bool {
1203 self.feature_flags.zklogin_auth
1204 }
1205
1206 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1207 self.feature_flags.consensus_transaction_ordering
1208 }
1209
1210 pub fn enable_jwk_consensus_updates(&self) -> bool {
1211 self.feature_flags.enable_jwk_consensus_updates
1212 }
1213
1214 pub fn create_authenticator_state_in_genesis(&self) -> bool {
1216 self.enable_jwk_consensus_updates()
1217 }
1218
1219 pub fn dkg_version(&self) -> u64 {
1220 self.random_beacon_dkg_version.unwrap_or(1)
1222 }
1223
1224 pub fn accept_zklogin_in_multisig(&self) -> bool {
1225 self.feature_flags.accept_zklogin_in_multisig
1226 }
1227
1228 pub fn zklogin_max_epoch_upper_bound_delta(&self) -> Option<u64> {
1229 self.feature_flags.zklogin_max_epoch_upper_bound_delta
1230 }
1231
1232 pub fn hardened_otw_check(&self) -> bool {
1233 self.feature_flags.hardened_otw_check
1234 }
1235
1236 pub fn enable_poseidon(&self) -> bool {
1237 self.feature_flags.enable_poseidon
1238 }
1239
1240 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1241 self.feature_flags.enable_group_ops_native_function_msm
1242 }
1243
1244 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1245 self.feature_flags.per_object_congestion_control_mode
1246 }
1247
1248 pub fn consensus_choice(&self) -> ConsensusChoice {
1249 self.feature_flags.consensus_choice
1250 }
1251
1252 pub fn consensus_network(&self) -> ConsensusNetwork {
1253 self.feature_flags.consensus_network
1254 }
1255
1256 pub fn enable_vdf(&self) -> bool {
1257 self.feature_flags.enable_vdf
1258 }
1259
1260 pub fn passkey_auth(&self) -> bool {
1261 self.feature_flags.passkey_auth
1262 }
1263
1264 pub fn max_transaction_size_bytes(&self) -> u64 {
1265 self.consensus_max_transaction_size_bytes
1267 .unwrap_or(256 * 1024)
1268 }
1269
1270 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1271 if cfg!(msim) {
1272 256 * 1024
1273 } else {
1274 self.consensus_max_transactions_in_block_bytes
1275 .unwrap_or(512 * 1024)
1276 }
1277 }
1278
1279 pub fn max_num_transactions_in_block(&self) -> u64 {
1280 if cfg!(msim) {
1281 8
1282 } else {
1283 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1284 }
1285 }
1286
1287 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1288 self.feature_flags.rethrow_serialization_type_layout_errors
1289 }
1290
1291 pub fn relocate_event_module(&self) -> bool {
1292 self.feature_flags.relocate_event_module
1293 }
1294
1295 pub fn protocol_defined_base_fee(&self) -> bool {
1296 self.feature_flags.protocol_defined_base_fee
1297 }
1298
1299 pub fn uncompressed_g1_group_elements(&self) -> bool {
1300 self.feature_flags.uncompressed_g1_group_elements
1301 }
1302
1303 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1304 self.feature_flags
1305 .disallow_new_modules_in_deps_only_packages
1306 }
1307
1308 pub fn native_charging_v2(&self) -> bool {
1309 self.feature_flags.native_charging_v2
1310 }
1311
1312 pub fn consensus_round_prober(&self) -> bool {
1313 self.feature_flags.consensus_round_prober
1314 }
1315
1316 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1317 self.feature_flags
1318 .consensus_distributed_vote_scoring_strategy
1319 }
1320
1321 pub fn gc_depth(&self) -> u32 {
1322 if cfg!(msim) {
1323 min(5, self.consensus_gc_depth.unwrap_or(0))
1325 } else {
1326 self.consensus_gc_depth.unwrap_or(0)
1327 }
1328 }
1329
1330 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1331 let res = self.feature_flags.consensus_linearize_subdag_v2;
1332 assert!(
1333 !res || self.gc_depth() > 0,
1334 "The consensus linearize sub dag V2 requires GC to be enabled"
1335 );
1336 res
1337 }
1338
1339 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1340 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1341 }
1342
1343 pub fn variant_nodes(&self) -> bool {
1344 self.feature_flags.variant_nodes
1345 }
1346
1347 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1348 self.feature_flags.consensus_smart_ancestor_selection
1349 }
1350
1351 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1352 self.feature_flags
1353 .consensus_round_prober_probe_accepted_rounds
1354 }
1355
1356 pub fn consensus_zstd_compression(&self) -> bool {
1357 self.feature_flags.consensus_zstd_compression
1358 }
1359
1360 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1361 self.feature_flags
1362 .congestion_control_min_free_execution_slot
1363 }
1364
1365 pub fn accept_passkey_in_multisig(&self) -> bool {
1366 self.feature_flags.accept_passkey_in_multisig
1367 }
1368
1369 pub fn consensus_batched_block_sync(&self) -> bool {
1370 self.feature_flags.consensus_batched_block_sync
1371 }
1372
1373 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1376 self.feature_flags
1377 .congestion_control_gas_price_feedback_mechanism
1378 }
1379
1380 pub fn validate_identifier_inputs(&self) -> bool {
1381 self.feature_flags.validate_identifier_inputs
1382 }
1383
1384 pub fn minimize_child_object_mutations(&self) -> bool {
1385 self.feature_flags.minimize_child_object_mutations
1386 }
1387
1388 pub fn dependency_linkage_error(&self) -> bool {
1389 self.feature_flags.dependency_linkage_error
1390 }
1391
1392 pub fn additional_multisig_checks(&self) -> bool {
1393 self.feature_flags.additional_multisig_checks
1394 }
1395
1396 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1397 0
1400 }
1401
1402 pub fn normalize_ptb_arguments(&self) -> bool {
1403 self.feature_flags.normalize_ptb_arguments
1404 }
1405
1406 pub fn select_committee_from_eligible_validators(&self) -> bool {
1407 let res = self.feature_flags.select_committee_from_eligible_validators;
1408 assert!(
1409 !res || (self.protocol_defined_base_fee()
1410 && self.max_committee_members_count_as_option().is_some()),
1411 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1412 );
1413 res
1414 }
1415
1416 pub fn track_non_committee_eligible_validators(&self) -> bool {
1417 self.feature_flags.track_non_committee_eligible_validators
1418 }
1419
1420 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1421 let res = self
1422 .feature_flags
1423 .select_committee_supporting_next_epoch_version;
1424 assert!(
1425 !res || (self.track_non_committee_eligible_validators()
1426 && self.select_committee_from_eligible_validators()),
1427 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1428 );
1429 res
1430 }
1431
1432 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1433 let res = self
1434 .feature_flags
1435 .consensus_median_timestamp_with_checkpoint_enforcement;
1436 assert!(
1437 !res || self.gc_depth() > 0,
1438 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1439 );
1440 res
1441 }
1442 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1443 self.feature_flags
1444 .consensus_commit_transactions_only_for_traversed_headers
1445 }
1446}
1447
1448#[cfg(not(msim))]
1449static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1450
1451#[cfg(msim)]
1453thread_local! {
1454 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1455}
1456
1457impl ProtocolConfig {
1459 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1462 assert!(
1464 version >= ProtocolVersion::MIN,
1465 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1466 version,
1467 ProtocolVersion::MIN.0,
1468 );
1469 assert!(
1470 version <= ProtocolVersion::MAX_ALLOWED,
1471 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1472 version,
1473 ProtocolVersion::MAX_ALLOWED.0,
1474 );
1475
1476 let mut ret = Self::get_for_version_impl(version, chain);
1477 ret.version = version;
1478
1479 ret = CONFIG_OVERRIDE.with(|ovr| {
1480 if let Some(override_fn) = &*ovr.borrow() {
1481 warn!(
1482 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1483 );
1484 override_fn(version, ret)
1485 } else {
1486 ret
1487 }
1488 });
1489
1490 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1491 warn!(
1492 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1493 );
1494 let overrides: ProtocolConfigOptional =
1495 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1496 .expect("failed to parse ProtocolConfig override env variables");
1497 overrides.apply_to(&mut ret);
1498 }
1499
1500 ret
1501 }
1502
1503 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1506 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1507 let mut ret = Self::get_for_version_impl(version, chain);
1508 ret.version = version;
1509 Some(ret)
1510 } else {
1511 None
1512 }
1513 }
1514
1515 #[cfg(not(msim))]
1516 pub fn poison_get_for_min_version() {
1517 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1518 }
1519
1520 #[cfg(not(msim))]
1521 fn load_poison_get_for_min_version() -> bool {
1522 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1523 }
1524
1525 #[cfg(msim)]
1526 pub fn poison_get_for_min_version() {
1527 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1528 }
1529
1530 #[cfg(msim)]
1531 fn load_poison_get_for_min_version() -> bool {
1532 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1533 }
1534
1535 pub fn convert_type_argument_error(&self) -> bool {
1536 self.feature_flags.convert_type_argument_error
1537 }
1538
1539 pub fn get_for_min_version() -> Self {
1543 if Self::load_poison_get_for_min_version() {
1544 panic!("get_for_min_version called on validator");
1545 }
1546 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1547 }
1548
1549 #[expect(non_snake_case)]
1560 pub fn get_for_max_version_UNSAFE() -> Self {
1561 if Self::load_poison_get_for_min_version() {
1562 panic!("get_for_max_version_UNSAFE called on validator");
1563 }
1564 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1565 }
1566
1567 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1568 #[cfg(msim)]
1569 {
1570 if version > ProtocolVersion::MAX {
1572 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1573 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1574 return config;
1575 }
1576 }
1577
1578 let mut cfg = Self {
1582 version,
1583
1584 feature_flags: Default::default(),
1585
1586 max_tx_size_bytes: Some(128 * 1024),
1587 max_input_objects: Some(2048),
1590 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1591 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1592 max_gas_payment_objects: Some(256),
1593 max_modules_in_publish: Some(64),
1594 max_package_dependencies: Some(32),
1595 max_arguments: Some(512),
1596 max_type_arguments: Some(16),
1597 max_type_argument_depth: Some(16),
1598 max_pure_argument_size: Some(16 * 1024),
1599 max_programmable_tx_commands: Some(1024),
1600 move_binary_format_version: Some(7),
1601 min_move_binary_format_version: Some(6),
1602 binary_module_handles: Some(100),
1603 binary_struct_handles: Some(300),
1604 binary_function_handles: Some(1500),
1605 binary_function_instantiations: Some(750),
1606 binary_signatures: Some(1000),
1607 binary_constant_pool: Some(4000),
1608 binary_identifiers: Some(10000),
1609 binary_address_identifiers: Some(100),
1610 binary_struct_defs: Some(200),
1611 binary_struct_def_instantiations: Some(100),
1612 binary_function_defs: Some(1000),
1613 binary_field_handles: Some(500),
1614 binary_field_instantiations: Some(250),
1615 binary_friend_decls: Some(100),
1616 binary_enum_defs: None,
1617 binary_enum_def_instantiations: None,
1618 binary_variant_handles: None,
1619 binary_variant_instantiation_handles: None,
1620 max_move_object_size: Some(250 * 1024),
1621 max_move_package_size: Some(100 * 1024),
1622 max_publish_or_upgrade_per_ptb: Some(5),
1623 max_tx_gas: Some(50_000_000_000),
1625 max_gas_price: Some(100_000),
1626 max_gas_computation_bucket: Some(5_000_000),
1627 max_loop_depth: Some(5),
1628 max_generic_instantiation_length: Some(32),
1629 max_function_parameters: Some(128),
1630 max_basic_blocks: Some(1024),
1631 max_value_stack_size: Some(1024),
1632 max_type_nodes: Some(256),
1633 max_push_size: Some(10000),
1634 max_struct_definitions: Some(200),
1635 max_function_definitions: Some(1000),
1636 max_fields_in_struct: Some(32),
1637 max_dependency_depth: Some(100),
1638 max_num_event_emit: Some(1024),
1639 max_num_new_move_object_ids: Some(2048),
1640 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1641 max_num_deleted_move_object_ids: Some(2048),
1642 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1643 max_num_transferred_move_object_ids: Some(2048),
1644 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1645 max_event_emit_size: Some(250 * 1024),
1646 max_move_vector_len: Some(256 * 1024),
1647 max_type_to_layout_nodes: None,
1648 max_ptb_value_size: None,
1649
1650 max_back_edges_per_function: Some(10_000),
1651 max_back_edges_per_module: Some(10_000),
1652
1653 max_verifier_meter_ticks_per_function: Some(16_000_000),
1654
1655 max_meter_ticks_per_module: Some(16_000_000),
1656 max_meter_ticks_per_package: Some(16_000_000),
1657
1658 object_runtime_max_num_cached_objects: Some(1000),
1659 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
1660 object_runtime_max_num_store_entries: Some(1000),
1661 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
1662 base_tx_cost_fixed: Some(1_000),
1664 package_publish_cost_fixed: Some(1_000),
1665 base_tx_cost_per_byte: Some(0),
1666 package_publish_cost_per_byte: Some(80),
1667 obj_access_cost_read_per_byte: Some(15),
1668 obj_access_cost_mutate_per_byte: Some(40),
1669 obj_access_cost_delete_per_byte: Some(40),
1670 obj_access_cost_verify_per_byte: Some(200),
1671 obj_data_cost_refundable: Some(100),
1672 obj_metadata_cost_non_refundable: Some(50),
1673 gas_model_version: Some(1),
1674 storage_rebate_rate: Some(10000),
1675 reward_slashing_rate: Some(10000),
1677 storage_gas_price: Some(76),
1678 base_gas_price: None,
1679 validator_target_reward: Some(767_000 * 1_000_000_000),
1682 max_transactions_per_checkpoint: Some(10_000),
1683 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
1684
1685 buffer_stake_for_protocol_upgrade_bps: Some(5000),
1687
1688 address_from_bytes_cost_base: Some(52),
1692 address_to_u256_cost_base: Some(52),
1694 address_from_u256_cost_base: Some(52),
1696
1697 config_read_setting_impl_cost_base: Some(100),
1700 config_read_setting_impl_cost_per_byte: Some(40),
1701
1702 dynamic_field_hash_type_and_key_cost_base: Some(100),
1706 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
1707 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
1708 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
1709 dynamic_field_add_child_object_cost_base: Some(100),
1712 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
1713 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
1714 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
1715 dynamic_field_borrow_child_object_cost_base: Some(100),
1718 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
1719 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
1720 dynamic_field_remove_child_object_cost_base: Some(100),
1723 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
1724 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
1725 dynamic_field_has_child_object_cost_base: Some(100),
1728 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
1731 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
1732 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
1733
1734 event_emit_cost_base: Some(52),
1737 event_emit_value_size_derivation_cost_per_byte: Some(2),
1738 event_emit_tag_size_derivation_cost_per_byte: Some(5),
1739 event_emit_output_cost_per_byte: Some(10),
1740
1741 object_borrow_uid_cost_base: Some(52),
1744 object_delete_impl_cost_base: Some(52),
1746 object_record_new_uid_cost_base: Some(52),
1748
1749 transfer_transfer_internal_cost_base: Some(52),
1753 transfer_freeze_object_cost_base: Some(52),
1755 transfer_share_object_cost_base: Some(52),
1757 transfer_receive_object_cost_base: Some(52),
1758
1759 tx_context_derive_id_cost_base: Some(52),
1763
1764 types_is_one_time_witness_cost_base: Some(52),
1767 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
1768 types_is_one_time_witness_type_cost_per_byte: Some(2),
1769
1770 validator_validate_metadata_cost_base: Some(52),
1774 validator_validate_metadata_data_cost_per_byte: Some(2),
1775
1776 crypto_invalid_arguments_cost: Some(100),
1778 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
1780 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
1781 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
1782
1783 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
1785 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
1786 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
1787
1788 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
1790 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1791 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1792 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
1793 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1794 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
1795
1796 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
1798
1799 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
1801 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
1802 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
1803 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
1804 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
1805 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
1806
1807 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
1809 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1810 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1811 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
1812 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1813 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
1814
1815 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
1817 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
1818 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
1819 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
1820 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
1821 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
1822
1823 ecvrf_ecvrf_verify_cost_base: Some(52),
1825 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
1826 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
1827
1828 ed25519_ed25519_verify_cost_base: Some(52),
1830 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
1831 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
1832
1833 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
1835 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
1836
1837 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
1839 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
1840 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
1841 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
1842 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
1843
1844 hash_blake2b256_cost_base: Some(52),
1846 hash_blake2b256_data_cost_per_byte: Some(2),
1847 hash_blake2b256_data_cost_per_block: Some(2),
1848 hash_keccak256_cost_base: Some(52),
1850 hash_keccak256_data_cost_per_byte: Some(2),
1851 hash_keccak256_data_cost_per_block: Some(2),
1852
1853 poseidon_bn254_cost_base: None,
1854 poseidon_bn254_cost_per_block: None,
1855
1856 hmac_hmac_sha3_256_cost_base: Some(52),
1858 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
1859 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
1860
1861 group_ops_bls12381_decode_scalar_cost: Some(52),
1863 group_ops_bls12381_decode_g1_cost: Some(52),
1864 group_ops_bls12381_decode_g2_cost: Some(52),
1865 group_ops_bls12381_decode_gt_cost: Some(52),
1866 group_ops_bls12381_scalar_add_cost: Some(52),
1867 group_ops_bls12381_g1_add_cost: Some(52),
1868 group_ops_bls12381_g2_add_cost: Some(52),
1869 group_ops_bls12381_gt_add_cost: Some(52),
1870 group_ops_bls12381_scalar_sub_cost: Some(52),
1871 group_ops_bls12381_g1_sub_cost: Some(52),
1872 group_ops_bls12381_g2_sub_cost: Some(52),
1873 group_ops_bls12381_gt_sub_cost: Some(52),
1874 group_ops_bls12381_scalar_mul_cost: Some(52),
1875 group_ops_bls12381_g1_mul_cost: Some(52),
1876 group_ops_bls12381_g2_mul_cost: Some(52),
1877 group_ops_bls12381_gt_mul_cost: Some(52),
1878 group_ops_bls12381_scalar_div_cost: Some(52),
1879 group_ops_bls12381_g1_div_cost: Some(52),
1880 group_ops_bls12381_g2_div_cost: Some(52),
1881 group_ops_bls12381_gt_div_cost: Some(52),
1882 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
1883 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
1884 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
1885 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
1886 group_ops_bls12381_g1_msm_base_cost: Some(52),
1887 group_ops_bls12381_g2_msm_base_cost: Some(52),
1888 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
1889 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
1890 group_ops_bls12381_msm_max_len: Some(32),
1891 group_ops_bls12381_pairing_cost: Some(52),
1892 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
1893 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
1894 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
1895 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
1896 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
1897
1898 check_zklogin_id_cost_base: Some(200),
1900 check_zklogin_issuer_cost_base: Some(200),
1902
1903 vdf_verify_vdf_cost: None,
1904 vdf_hash_to_input_cost: None,
1905
1906 bcs_per_byte_serialized_cost: Some(2),
1907 bcs_legacy_min_output_size_cost: Some(1),
1908 bcs_failure_cost: Some(52),
1909 hash_sha2_256_base_cost: Some(52),
1910 hash_sha2_256_per_byte_cost: Some(2),
1911 hash_sha2_256_legacy_min_input_len_cost: Some(1),
1912 hash_sha3_256_base_cost: Some(52),
1913 hash_sha3_256_per_byte_cost: Some(2),
1914 hash_sha3_256_legacy_min_input_len_cost: Some(1),
1915 type_name_get_base_cost: Some(52),
1916 type_name_get_per_byte_cost: Some(2),
1917 string_check_utf8_base_cost: Some(52),
1918 string_check_utf8_per_byte_cost: Some(2),
1919 string_is_char_boundary_base_cost: Some(52),
1920 string_sub_string_base_cost: Some(52),
1921 string_sub_string_per_byte_cost: Some(2),
1922 string_index_of_base_cost: Some(52),
1923 string_index_of_per_byte_pattern_cost: Some(2),
1924 string_index_of_per_byte_searched_cost: Some(2),
1925 vector_empty_base_cost: Some(52),
1926 vector_length_base_cost: Some(52),
1927 vector_push_back_base_cost: Some(52),
1928 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
1929 vector_borrow_base_cost: Some(52),
1930 vector_pop_back_base_cost: Some(52),
1931 vector_destroy_empty_base_cost: Some(52),
1932 vector_swap_base_cost: Some(52),
1933 debug_print_base_cost: Some(52),
1934 debug_print_stack_trace_base_cost: Some(52),
1935
1936 max_size_written_objects: Some(5 * 1000 * 1000),
1937 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
1940
1941 max_move_identifier_len: Some(128),
1943 max_move_value_depth: Some(128),
1944 max_move_enum_variants: None,
1945
1946 gas_rounding_step: Some(1_000),
1947
1948 execution_version: Some(1),
1949
1950 max_event_emit_size_total: Some(
1953 256 * 250 * 1024, ),
1955
1956 consensus_bad_nodes_stake_threshold: Some(20),
1963
1964 max_jwk_votes_per_validator_per_epoch: Some(240),
1966
1967 max_age_of_jwk_in_epochs: Some(1),
1968
1969 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
1973
1974 random_beacon_reduction_allowed_delta: Some(800),
1975
1976 random_beacon_reduction_lower_bound: Some(1000),
1977 random_beacon_dkg_timeout_round: Some(3000),
1978 random_beacon_min_round_interval_ms: Some(500),
1979
1980 random_beacon_dkg_version: Some(1),
1981
1982 consensus_max_num_transactions_in_block: Some(512),
1986
1987 max_deferral_rounds_for_congestion_control: Some(10),
1988
1989 min_checkpoint_interval_ms: Some(200),
1990
1991 checkpoint_summary_version_specific_data: Some(1),
1992
1993 max_soft_bundle_size: Some(5),
1994
1995 bridge_should_try_to_finalize_committee: None,
1996
1997 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
1998
1999 max_committee_members_count: None,
2000
2001 consensus_gc_depth: None,
2002
2003 consensus_max_acknowledgments_per_block: None,
2004
2005 max_congestion_limit_overshoot_per_commit: None,
2006 };
2009
2010 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2011
2012 {
2014 cfg.feature_flags
2015 .disable_invariant_violation_check_in_swap_loc = true;
2016 cfg.feature_flags.no_extraneous_module_bytes = true;
2017 cfg.feature_flags.hardened_otw_check = true;
2018 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2019 }
2020
2021 {
2023 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2024 }
2025
2026 cfg.feature_flags.consensus_choice = ConsensusChoice::Mysticeti;
2028 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2030
2031 cfg.feature_flags.per_object_congestion_control_mode =
2032 PerObjectCongestionControlMode::TotalTxCount;
2033
2034 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2036
2037 if chain != Chain::Mainnet && chain != Chain::Testnet {
2039 cfg.feature_flags.enable_poseidon = true;
2040 cfg.poseidon_bn254_cost_base = Some(260);
2041 cfg.poseidon_bn254_cost_per_block = Some(10);
2042
2043 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2044
2045 cfg.feature_flags.enable_vdf = true;
2046 cfg.vdf_verify_vdf_cost = Some(1500);
2049 cfg.vdf_hash_to_input_cost = Some(100);
2050
2051 cfg.feature_flags.passkey_auth = true;
2052 }
2053
2054 for cur in 2..=version.0 {
2055 match cur {
2056 1 => unreachable!(),
2057 2 => {}
2059 3 => {
2060 cfg.feature_flags.relocate_event_module = true;
2061 }
2062 4 => {
2063 cfg.max_type_to_layout_nodes = Some(512);
2064 }
2065 5 => {
2066 cfg.feature_flags.protocol_defined_base_fee = true;
2067 cfg.base_gas_price = Some(1000);
2068
2069 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2070 cfg.feature_flags.convert_type_argument_error = true;
2071 cfg.feature_flags.native_charging_v2 = true;
2072
2073 if chain != Chain::Mainnet && chain != Chain::Testnet {
2074 cfg.feature_flags.uncompressed_g1_group_elements = true;
2075 }
2076
2077 cfg.gas_model_version = Some(2);
2078
2079 cfg.poseidon_bn254_cost_per_block = Some(388);
2080
2081 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2082 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2083 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2084 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2085 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2086 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2087 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2088 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2089
2090 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2092 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2093 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2094 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2095
2096 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2097 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2098 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2099 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2100 Some(8213);
2101 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2102 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2103 Some(9484);
2104
2105 cfg.hash_keccak256_cost_base = Some(10);
2106 cfg.hash_blake2b256_cost_base = Some(10);
2107
2108 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2110 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2111 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2112 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2113
2114 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2115 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2116 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2117 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2118
2119 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2120 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2121 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2122 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2123
2124 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2125 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2126 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2127 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2128
2129 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2130 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2131 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2132 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2133
2134 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2135 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2136
2137 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2138 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2139 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2140 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2141
2142 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2143 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2144 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2145 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2146 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2147
2148 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2149
2150 cfg.validator_validate_metadata_cost_base = Some(20000);
2151
2152 cfg.max_committee_members_count = Some(50);
2153 }
2154 6 => {
2155 cfg.max_ptb_value_size = Some(1024 * 1024);
2156 }
2157 7 => {
2158 }
2161 8 => {
2162 cfg.feature_flags.variant_nodes = true;
2163
2164 if chain != Chain::Mainnet {
2165 cfg.feature_flags.consensus_round_prober = true;
2167 cfg.feature_flags
2169 .consensus_distributed_vote_scoring_strategy = true;
2170 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2171 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2173 cfg.feature_flags
2175 .consensus_round_prober_probe_accepted_rounds = true;
2176 cfg.feature_flags.consensus_zstd_compression = true;
2178 cfg.consensus_gc_depth = Some(60);
2182 }
2183
2184 if chain != Chain::Testnet && chain != Chain::Mainnet {
2187 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2188 }
2189 }
2190 9 => {
2191 if chain != Chain::Mainnet {
2192 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2194 }
2195
2196 cfg.feature_flags.consensus_zstd_compression = true;
2198
2199 if chain != Chain::Testnet && chain != Chain::Mainnet {
2201 cfg.feature_flags.accept_passkey_in_multisig = true;
2202 }
2203
2204 cfg.bridge_should_try_to_finalize_committee = None;
2206 }
2207 10 => {
2208 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2211
2212 cfg.max_committee_members_count = Some(80);
2214
2215 cfg.feature_flags.consensus_round_prober = true;
2217 cfg.feature_flags
2219 .consensus_round_prober_probe_accepted_rounds = true;
2220 cfg.feature_flags
2222 .consensus_distributed_vote_scoring_strategy = true;
2223 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2225
2226 cfg.consensus_gc_depth = Some(60);
2231
2232 cfg.feature_flags.minimize_child_object_mutations = true;
2234
2235 if chain != Chain::Mainnet {
2236 cfg.feature_flags.consensus_batched_block_sync = true;
2238 }
2239
2240 if chain != Chain::Testnet && chain != Chain::Mainnet {
2241 cfg.feature_flags
2244 .congestion_control_gas_price_feedback_mechanism = true;
2245 }
2246
2247 cfg.feature_flags.validate_identifier_inputs = true;
2248 cfg.feature_flags.dependency_linkage_error = true;
2249 cfg.feature_flags.additional_multisig_checks = true;
2250 }
2251 11 => {
2252 }
2255 12 => {
2256 cfg.feature_flags
2259 .congestion_control_gas_price_feedback_mechanism = true;
2260
2261 cfg.feature_flags.normalize_ptb_arguments = true;
2263 }
2264 13 => {
2265 cfg.feature_flags.select_committee_from_eligible_validators = true;
2268 cfg.feature_flags.track_non_committee_eligible_validators = true;
2271
2272 if chain != Chain::Testnet && chain != Chain::Mainnet {
2273 cfg.feature_flags
2276 .select_committee_supporting_next_epoch_version = true;
2277 }
2278 }
2279 14 => {
2280 cfg.feature_flags.consensus_batched_block_sync = true;
2282
2283 if chain != Chain::Mainnet {
2284 cfg.feature_flags
2287 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2288 cfg.feature_flags
2292 .select_committee_supporting_next_epoch_version = true;
2293 }
2294 if chain != Chain::Testnet && chain != Chain::Mainnet {
2295 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2297 }
2298 }
2299 15 => {
2300 if chain != Chain::Mainnet && chain != Chain::Testnet {
2301 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2305 }
2306 }
2307 16 => {
2308 cfg.feature_flags
2311 .select_committee_supporting_next_epoch_version = true;
2312 cfg.feature_flags
2314 .consensus_commit_transactions_only_for_traversed_headers = true;
2315 }
2316 17 => {
2317 cfg.max_committee_members_count = Some(100);
2319 }
2320 _ => panic!("unsupported version {version:?}"),
2331 }
2332 }
2333 cfg
2334 }
2335
2336 pub fn verifier_config(&self, signing_limits: Option<(usize, usize)>) -> VerifierConfig {
2340 let (max_back_edges_per_function, max_back_edges_per_module) = if let Some((
2341 max_back_edges_per_function,
2342 max_back_edges_per_module,
2343 )) = signing_limits
2344 {
2345 (
2346 Some(max_back_edges_per_function),
2347 Some(max_back_edges_per_module),
2348 )
2349 } else {
2350 (None, None)
2351 };
2352
2353 VerifierConfig {
2354 max_loop_depth: Some(self.max_loop_depth() as usize),
2355 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2356 max_function_parameters: Some(self.max_function_parameters() as usize),
2357 max_basic_blocks: Some(self.max_basic_blocks() as usize),
2358 max_value_stack_size: self.max_value_stack_size() as usize,
2359 max_type_nodes: Some(self.max_type_nodes() as usize),
2360 max_push_size: Some(self.max_push_size() as usize),
2361 max_dependency_depth: Some(self.max_dependency_depth() as usize),
2362 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2363 max_function_definitions: Some(self.max_function_definitions() as usize),
2364 max_data_definitions: Some(self.max_struct_definitions() as usize),
2365 max_constant_vector_len: Some(self.max_move_vector_len()),
2366 max_back_edges_per_function,
2367 max_back_edges_per_module,
2368 max_basic_blocks_in_script: None,
2369 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
2373 max_variants_in_enum: self.max_move_enum_variants_as_option(),
2374 }
2375 }
2376
2377 pub fn apply_overrides_for_testing(
2382 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
2383 ) -> OverrideGuard {
2384 CONFIG_OVERRIDE.with(|ovr| {
2385 let mut cur = ovr.borrow_mut();
2386 assert!(cur.is_none(), "config override already present");
2387 *cur = Some(Box::new(override_fn));
2388 OverrideGuard
2389 })
2390 }
2391}
2392
2393impl ProtocolConfig {
2398 pub fn set_zklogin_auth_for_testing(&mut self, val: bool) {
2399 self.feature_flags.zklogin_auth = val
2400 }
2401 pub fn set_enable_jwk_consensus_updates_for_testing(&mut self, val: bool) {
2402 self.feature_flags.enable_jwk_consensus_updates = val
2403 }
2404
2405 pub fn set_accept_zklogin_in_multisig_for_testing(&mut self, val: bool) {
2406 self.feature_flags.accept_zklogin_in_multisig = val
2407 }
2408
2409 pub fn set_per_object_congestion_control_mode_for_testing(
2410 &mut self,
2411 val: PerObjectCongestionControlMode,
2412 ) {
2413 self.feature_flags.per_object_congestion_control_mode = val;
2414 }
2415
2416 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
2417 self.feature_flags.consensus_choice = val;
2418 }
2419
2420 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
2421 self.feature_flags.consensus_network = val;
2422 }
2423
2424 pub fn set_zklogin_max_epoch_upper_bound_delta_for_testing(&mut self, val: Option<u64>) {
2425 self.feature_flags.zklogin_max_epoch_upper_bound_delta = val
2426 }
2427
2428 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
2429 self.feature_flags.passkey_auth = val
2430 }
2431
2432 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
2433 self.feature_flags
2434 .disallow_new_modules_in_deps_only_packages = val;
2435 }
2436
2437 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
2438 self.feature_flags.consensus_round_prober = val;
2439 }
2440
2441 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
2442 self.feature_flags
2443 .consensus_distributed_vote_scoring_strategy = val;
2444 }
2445
2446 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
2447 self.consensus_gc_depth = Some(val);
2448 }
2449
2450 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
2451 self.feature_flags.consensus_linearize_subdag_v2 = val;
2452 }
2453
2454 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
2455 self.feature_flags
2456 .consensus_round_prober_probe_accepted_rounds = val;
2457 }
2458
2459 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
2460 self.feature_flags.accept_passkey_in_multisig = val;
2461 }
2462
2463 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
2464 self.feature_flags.consensus_smart_ancestor_selection = val;
2465 }
2466
2467 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
2468 self.feature_flags.consensus_batched_block_sync = val;
2469 }
2470
2471 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
2472 self.feature_flags
2473 .congestion_control_min_free_execution_slot = val;
2474 }
2475
2476 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
2477 self.feature_flags
2478 .congestion_control_gas_price_feedback_mechanism = val;
2479 }
2480 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
2481 self.feature_flags.select_committee_from_eligible_validators = val;
2482 }
2483
2484 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
2485 self.feature_flags.track_non_committee_eligible_validators = val;
2486 }
2487
2488 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
2489 self.feature_flags
2490 .select_committee_supporting_next_epoch_version = val;
2491 }
2492
2493 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
2494 &mut self,
2495 val: bool,
2496 ) {
2497 self.feature_flags
2498 .consensus_median_timestamp_with_checkpoint_enforcement = val;
2499 }
2500 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
2501 &mut self,
2502 val: bool,
2503 ) {
2504 self.feature_flags
2505 .consensus_commit_transactions_only_for_traversed_headers = val;
2506 }
2507}
2508
2509type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
2510
2511thread_local! {
2512 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
2513}
2514
2515#[must_use]
2516pub struct OverrideGuard;
2517
2518impl Drop for OverrideGuard {
2519 fn drop(&mut self) {
2520 info!("restoring override fn");
2521 CONFIG_OVERRIDE.with(|ovr| {
2522 *ovr.borrow_mut() = None;
2523 });
2524 }
2525}
2526
2527#[derive(PartialEq, Eq)]
2531pub enum LimitThresholdCrossed {
2532 None,
2533 Soft(u128, u128),
2534 Hard(u128, u128),
2535}
2536
2537pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
2540 x: T,
2541 soft_limit: U,
2542 hard_limit: V,
2543) -> LimitThresholdCrossed {
2544 let x: V = x.into();
2545 let soft_limit: V = soft_limit.into();
2546
2547 debug_assert!(soft_limit <= hard_limit);
2548
2549 if x >= hard_limit {
2552 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
2553 } else if x < soft_limit {
2554 LimitThresholdCrossed::None
2555 } else {
2556 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
2557 }
2558}
2559
2560#[macro_export]
2561macro_rules! check_limit {
2562 ($x:expr, $hard:expr) => {
2563 check_limit!($x, $hard, $hard)
2564 };
2565 ($x:expr, $soft:expr, $hard:expr) => {
2566 check_limit_in_range($x as u64, $soft, $hard)
2567 };
2568}
2569
2570#[macro_export]
2574macro_rules! check_limit_by_meter {
2575 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
2576 let (h, metered_str) = if $is_metered {
2578 ($metered_limit, "metered")
2579 } else {
2580 ($unmetered_hard_limit, "unmetered")
2582 };
2583 use iota_protocol_config::check_limit_in_range;
2584 let result = check_limit_in_range($x as u64, $metered_limit, h);
2585 match result {
2586 LimitThresholdCrossed::None => {}
2587 LimitThresholdCrossed::Soft(_, _) => {
2588 $metric.with_label_values(&[metered_str, "soft"]).inc();
2589 }
2590 LimitThresholdCrossed::Hard(_, _) => {
2591 $metric.with_label_values(&[metered_str, "hard"]).inc();
2592 }
2593 };
2594 result
2595 }};
2596}
2597
2598#[cfg(all(test, not(msim)))]
2599mod test {
2600 use insta::assert_yaml_snapshot;
2601
2602 use super::*;
2603
2604 #[test]
2605 fn snapshot_tests() {
2606 println!("\n============================================================================");
2607 println!("! !");
2608 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
2609 println!("! !");
2610 println!("============================================================================\n");
2611 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
2612 let chain_str = match chain_id {
2617 Chain::Unknown => "".to_string(),
2618 _ => format!("{chain_id:?}_"),
2619 };
2620 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
2621 let cur = ProtocolVersion::new(i);
2622 assert_yaml_snapshot!(
2623 format!("{}version_{}", chain_str, cur.as_u64()),
2624 ProtocolConfig::get_for_version(cur, *chain_id)
2625 );
2626 }
2627 }
2628 }
2629
2630 #[test]
2631 fn test_getters() {
2632 let prot: ProtocolConfig =
2633 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2634 assert_eq!(
2635 prot.max_arguments(),
2636 prot.max_arguments_as_option().unwrap()
2637 );
2638 }
2639
2640 #[test]
2641 fn test_setters() {
2642 let mut prot: ProtocolConfig =
2643 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2644 prot.set_max_arguments_for_testing(123);
2645 assert_eq!(prot.max_arguments(), 123);
2646
2647 prot.set_max_arguments_from_str_for_testing("321".to_string());
2648 assert_eq!(prot.max_arguments(), 321);
2649
2650 prot.disable_max_arguments_for_testing();
2651 assert_eq!(prot.max_arguments_as_option(), None);
2652
2653 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
2654 assert_eq!(prot.max_arguments(), 456);
2655 }
2656
2657 #[test]
2658 #[should_panic(expected = "unsupported version")]
2659 fn max_version_test() {
2660 let _ = ProtocolConfig::get_for_version_impl(
2663 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
2664 Chain::Unknown,
2665 );
2666 }
2667
2668 #[test]
2669 fn lookup_by_string_test() {
2670 let prot: ProtocolConfig =
2671 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2672 assert!(prot.lookup_attr("some random string".to_string()).is_none());
2674
2675 assert!(
2676 prot.lookup_attr("max_arguments".to_string())
2677 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
2678 );
2679
2680 assert!(
2682 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2683 .is_none()
2684 );
2685 assert!(
2686 prot.attr_map()
2687 .get("poseidon_bn254_cost_base")
2688 .unwrap()
2689 .is_none()
2690 );
2691
2692 let prot: ProtocolConfig =
2694 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2695
2696 assert!(
2697 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2698 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2699 );
2700 assert!(
2701 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
2702 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2703 );
2704
2705 let prot: ProtocolConfig =
2707 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2708 assert!(
2710 prot.feature_flags
2711 .lookup_attr("some random string".to_owned())
2712 .is_none()
2713 );
2714 assert!(
2715 !prot
2716 .feature_flags
2717 .attr_map()
2718 .contains_key("some random string")
2719 );
2720
2721 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
2723 assert!(
2724 prot.feature_flags
2725 .attr_map()
2726 .get("enable_poseidon")
2727 .unwrap()
2728 == &false
2729 );
2730 let prot: ProtocolConfig =
2731 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2732 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
2734 assert!(
2735 prot.feature_flags
2736 .attr_map()
2737 .get("enable_poseidon")
2738 .unwrap()
2739 == &true
2740 );
2741 }
2742
2743 #[test]
2744 fn limit_range_fn_test() {
2745 let low = 100u32;
2746 let high = 10000u64;
2747
2748 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
2749 assert!(matches!(
2750 check_limit!(255u16, low, high),
2751 LimitThresholdCrossed::Soft(255u128, 100)
2752 ));
2753 assert!(matches!(
2760 check_limit!(2550000u64, low, high),
2761 LimitThresholdCrossed::Hard(2550000, 10000)
2762 ));
2763
2764 assert!(matches!(
2765 check_limit!(2550000u64, high, high),
2766 LimitThresholdCrossed::Hard(2550000, 10000)
2767 ));
2768
2769 assert!(matches!(
2770 check_limit!(1u8, high),
2771 LimitThresholdCrossed::None
2772 ));
2773
2774 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
2775
2776 assert!(matches!(
2777 check_limit!(2550000u64, high),
2778 LimitThresholdCrossed::Hard(2550000, 10000)
2779 ));
2780 }
2781}