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 = 21;
23
24#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
125pub struct ProtocolVersion(u64);
126
127impl ProtocolVersion {
128 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
134
135 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
136
137 #[cfg(not(msim))]
138 const MAX_ALLOWED: Self = Self::MAX;
139
140 #[cfg(msim)]
143 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
144
145 pub fn new(v: u64) -> Self {
146 Self(v)
147 }
148
149 pub const fn as_u64(&self) -> u64 {
150 self.0
151 }
152
153 pub fn max() -> Self {
156 Self::MAX
157 }
158}
159
160impl From<u64> for ProtocolVersion {
161 fn from(v: u64) -> Self {
162 Self::new(v)
163 }
164}
165
166impl std::ops::Sub<u64> for ProtocolVersion {
167 type Output = Self;
168 fn sub(self, rhs: u64) -> Self::Output {
169 Self::new(self.0 - rhs)
170 }
171}
172
173impl std::ops::Add<u64> for ProtocolVersion {
174 type Output = Self;
175 fn add(self, rhs: u64) -> Self::Output {
176 Self::new(self.0 + rhs)
177 }
178}
179
180#[derive(
181 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
182)]
183pub enum Chain {
184 Mainnet,
185 Testnet,
186 #[default]
187 Unknown,
188}
189
190impl Chain {
191 pub fn as_str(self) -> &'static str {
192 match self {
193 Chain::Mainnet => "mainnet",
194 Chain::Testnet => "testnet",
195 Chain::Unknown => "unknown",
196 }
197 }
198}
199
200pub struct Error(pub String);
201
202#[derive(Default, Clone, Serialize, Deserialize, Debug, ProtocolConfigFeatureFlagsGetters)]
206struct FeatureFlags {
207 #[serde(skip_serializing_if = "is_true")]
213 disable_invariant_violation_check_in_swap_loc: bool,
214
215 #[serde(skip_serializing_if = "is_true")]
218 no_extraneous_module_bytes: bool,
219
220 #[serde(skip_serializing_if = "is_false")]
222 zklogin_auth: bool,
223
224 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
226 consensus_transaction_ordering: ConsensusTransactionOrdering,
227
228 #[serde(skip_serializing_if = "is_false")]
229 enable_jwk_consensus_updates: bool,
230
231 #[serde(skip_serializing_if = "is_false")]
233 accept_zklogin_in_multisig: bool,
234
235 #[serde(skip_serializing_if = "is_true")]
238 hardened_otw_check: bool,
239
240 #[serde(skip_serializing_if = "is_false")]
242 enable_poseidon: bool,
243
244 #[serde(skip_serializing_if = "is_false")]
246 enable_group_ops_native_function_msm: bool,
247
248 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
250 per_object_congestion_control_mode: PerObjectCongestionControlMode,
251
252 #[serde(skip_serializing_if = "ConsensusChoice::is_mysticeti")]
254 consensus_choice: ConsensusChoice,
255
256 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
258 consensus_network: ConsensusNetwork,
259
260 #[serde(skip_serializing_if = "Option::is_none")]
262 zklogin_max_epoch_upper_bound_delta: Option<u64>,
263
264 #[serde(skip_serializing_if = "is_false")]
266 enable_vdf: bool,
267
268 #[serde(skip_serializing_if = "is_false")]
270 passkey_auth: bool,
271
272 #[serde(skip_serializing_if = "is_true")]
275 rethrow_serialization_type_layout_errors: bool,
276
277 #[serde(skip_serializing_if = "is_false")]
279 relocate_event_module: bool,
280
281 #[serde(skip_serializing_if = "is_false")]
283 protocol_defined_base_fee: bool,
284
285 #[serde(skip_serializing_if = "is_false")]
287 uncompressed_g1_group_elements: bool,
288
289 #[serde(skip_serializing_if = "is_false")]
291 disallow_new_modules_in_deps_only_packages: bool,
292
293 #[serde(skip_serializing_if = "is_false")]
295 native_charging_v2: bool,
296
297 #[serde(skip_serializing_if = "is_false")]
299 convert_type_argument_error: bool,
300
301 #[serde(skip_serializing_if = "is_false")]
303 consensus_round_prober: bool,
304
305 #[serde(skip_serializing_if = "is_false")]
307 consensus_distributed_vote_scoring_strategy: bool,
308
309 #[serde(skip_serializing_if = "is_false")]
313 consensus_linearize_subdag_v2: bool,
314
315 #[serde(skip_serializing_if = "is_false")]
317 variant_nodes: bool,
318
319 #[serde(skip_serializing_if = "is_false")]
321 consensus_smart_ancestor_selection: bool,
322
323 #[serde(skip_serializing_if = "is_false")]
325 consensus_round_prober_probe_accepted_rounds: bool,
326
327 #[serde(skip_serializing_if = "is_false")]
329 consensus_zstd_compression: bool,
330
331 #[serde(skip_serializing_if = "is_false")]
334 congestion_control_min_free_execution_slot: bool,
335
336 #[serde(skip_serializing_if = "is_false")]
338 accept_passkey_in_multisig: bool,
339
340 #[serde(skip_serializing_if = "is_false")]
342 consensus_batched_block_sync: bool,
343
344 #[serde(skip_serializing_if = "is_false")]
347 congestion_control_gas_price_feedback_mechanism: bool,
348
349 #[serde(skip_serializing_if = "is_false")]
351 validate_identifier_inputs: bool,
352
353 #[serde(skip_serializing_if = "is_false")]
356 minimize_child_object_mutations: bool,
357
358 #[serde(skip_serializing_if = "is_false")]
360 dependency_linkage_error: bool,
361
362 #[serde(skip_serializing_if = "is_false")]
364 additional_multisig_checks: bool,
365
366 #[serde(skip_serializing_if = "is_false")]
369 normalize_ptb_arguments: bool,
370
371 #[serde(skip_serializing_if = "is_false")]
375 select_committee_from_eligible_validators: bool,
376
377 #[serde(skip_serializing_if = "is_false")]
384 track_non_committee_eligible_validators: bool,
385
386 #[serde(skip_serializing_if = "is_false")]
392 select_committee_supporting_next_epoch_version: bool,
393
394 #[serde(skip_serializing_if = "is_false")]
398 consensus_median_timestamp_with_checkpoint_enforcement: bool,
399
400 #[serde(skip_serializing_if = "is_false")]
402 consensus_commit_transactions_only_for_traversed_headers: bool,
403
404 #[serde(skip_serializing_if = "is_false")]
406 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
407
408 #[serde(skip_serializing_if = "is_false")]
411 separate_gas_price_feedback_mechanism_for_randomness: bool,
412
413 #[serde(skip_serializing_if = "is_false")]
416 metadata_in_module_bytes: bool,
417
418 #[serde(skip_serializing_if = "is_false")]
420 publish_package_metadata: bool,
421
422 #[serde(skip_serializing_if = "is_false")]
424 enable_move_authentication: bool,
425
426 #[serde(skip_serializing_if = "is_false")]
428 pass_validator_scores_to_advance_epoch: bool,
429
430 #[serde(skip_serializing_if = "is_false")]
432 calculate_validator_scores: bool,
433
434 #[serde(skip_serializing_if = "is_false")]
436 adjust_rewards_by_score: bool,
437
438 #[serde(skip_serializing_if = "is_false")]
441 pass_calculated_validator_scores_to_advance_epoch: bool,
442
443 #[serde(skip_serializing_if = "is_false")]
448 consensus_fast_commit_sync: bool,
449}
450
451fn is_true(b: &bool) -> bool {
452 *b
453}
454
455fn is_false(b: &bool) -> bool {
456 !b
457}
458
459#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
461pub enum ConsensusTransactionOrdering {
462 #[default]
465 None,
466 ByGasPrice,
468}
469
470impl ConsensusTransactionOrdering {
471 pub fn is_none(&self) -> bool {
472 matches!(self, ConsensusTransactionOrdering::None)
473 }
474}
475
476#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
478pub enum PerObjectCongestionControlMode {
479 #[default]
480 None, TotalGasBudget, TotalTxCount, }
484
485impl PerObjectCongestionControlMode {
486 pub fn is_none(&self) -> bool {
487 matches!(self, PerObjectCongestionControlMode::None)
488 }
489}
490
491#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
493pub enum ConsensusChoice {
494 #[default]
495 Mysticeti,
496 Starfish,
497}
498
499impl ConsensusChoice {
500 pub fn is_mysticeti(&self) -> bool {
501 matches!(self, ConsensusChoice::Mysticeti)
502 }
503 pub fn is_starfish(&self) -> bool {
504 matches!(self, ConsensusChoice::Starfish)
505 }
506}
507
508#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
510pub enum ConsensusNetwork {
511 #[default]
512 Tonic,
513}
514
515impl ConsensusNetwork {
516 pub fn is_tonic(&self) -> bool {
517 matches!(self, ConsensusNetwork::Tonic)
518 }
519}
520
521#[skip_serializing_none]
555#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
556pub struct ProtocolConfig {
557 pub version: ProtocolVersion,
558
559 feature_flags: FeatureFlags,
560
561 max_tx_size_bytes: Option<u64>,
566
567 max_input_objects: Option<u64>,
570
571 max_size_written_objects: Option<u64>,
576 max_size_written_objects_system_tx: Option<u64>,
580
581 max_serialized_tx_effects_size_bytes: Option<u64>,
583
584 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
586
587 max_gas_payment_objects: Option<u32>,
589
590 max_modules_in_publish: Option<u32>,
592
593 max_package_dependencies: Option<u32>,
595
596 max_arguments: Option<u32>,
599
600 max_type_arguments: Option<u32>,
602
603 max_type_argument_depth: Option<u32>,
605
606 max_pure_argument_size: Option<u32>,
608
609 max_programmable_tx_commands: Option<u32>,
611
612 move_binary_format_version: Option<u32>,
618 min_move_binary_format_version: Option<u32>,
619
620 binary_module_handles: Option<u16>,
622 binary_struct_handles: Option<u16>,
623 binary_function_handles: Option<u16>,
624 binary_function_instantiations: Option<u16>,
625 binary_signatures: Option<u16>,
626 binary_constant_pool: Option<u16>,
627 binary_identifiers: Option<u16>,
628 binary_address_identifiers: Option<u16>,
629 binary_struct_defs: Option<u16>,
630 binary_struct_def_instantiations: Option<u16>,
631 binary_function_defs: Option<u16>,
632 binary_field_handles: Option<u16>,
633 binary_field_instantiations: Option<u16>,
634 binary_friend_decls: Option<u16>,
635 binary_enum_defs: Option<u16>,
636 binary_enum_def_instantiations: Option<u16>,
637 binary_variant_handles: Option<u16>,
638 binary_variant_instantiation_handles: Option<u16>,
639
640 max_move_object_size: Option<u64>,
643
644 max_move_package_size: Option<u64>,
649
650 max_publish_or_upgrade_per_ptb: Option<u64>,
653
654 max_tx_gas: Option<u64>,
656
657 max_auth_gas: Option<u64>,
659
660 max_gas_price: Option<u64>,
663
664 max_gas_computation_bucket: Option<u64>,
667
668 gas_rounding_step: Option<u64>,
670
671 max_loop_depth: Option<u64>,
673
674 max_generic_instantiation_length: Option<u64>,
677
678 max_function_parameters: Option<u64>,
681
682 max_basic_blocks: Option<u64>,
685
686 max_value_stack_size: Option<u64>,
688
689 max_type_nodes: Option<u64>,
693
694 max_push_size: Option<u64>,
697
698 max_struct_definitions: Option<u64>,
701
702 max_function_definitions: Option<u64>,
705
706 max_fields_in_struct: Option<u64>,
709
710 max_dependency_depth: Option<u64>,
713
714 max_num_event_emit: Option<u64>,
717
718 max_num_new_move_object_ids: Option<u64>,
721
722 max_num_new_move_object_ids_system_tx: Option<u64>,
725
726 max_num_deleted_move_object_ids: Option<u64>,
729
730 max_num_deleted_move_object_ids_system_tx: Option<u64>,
733
734 max_num_transferred_move_object_ids: Option<u64>,
737
738 max_num_transferred_move_object_ids_system_tx: Option<u64>,
741
742 max_event_emit_size: Option<u64>,
744
745 max_event_emit_size_total: Option<u64>,
747
748 max_move_vector_len: Option<u64>,
751
752 max_move_identifier_len: Option<u64>,
755
756 max_move_value_depth: Option<u64>,
758
759 max_move_enum_variants: Option<u64>,
762
763 max_back_edges_per_function: Option<u64>,
766
767 max_back_edges_per_module: Option<u64>,
770
771 max_verifier_meter_ticks_per_function: Option<u64>,
774
775 max_meter_ticks_per_module: Option<u64>,
778
779 max_meter_ticks_per_package: Option<u64>,
782
783 object_runtime_max_num_cached_objects: Option<u64>,
790
791 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
794
795 object_runtime_max_num_store_entries: Option<u64>,
798
799 object_runtime_max_num_store_entries_system_tx: Option<u64>,
802
803 base_tx_cost_fixed: Option<u64>,
808
809 package_publish_cost_fixed: Option<u64>,
813
814 base_tx_cost_per_byte: Option<u64>,
818
819 package_publish_cost_per_byte: Option<u64>,
821
822 obj_access_cost_read_per_byte: Option<u64>,
824
825 obj_access_cost_mutate_per_byte: Option<u64>,
827
828 obj_access_cost_delete_per_byte: Option<u64>,
830
831 obj_access_cost_verify_per_byte: Option<u64>,
841
842 max_type_to_layout_nodes: Option<u64>,
844
845 max_ptb_value_size: Option<u64>,
847
848 gas_model_version: Option<u64>,
853
854 obj_data_cost_refundable: Option<u64>,
860
861 obj_metadata_cost_non_refundable: Option<u64>,
865
866 storage_rebate_rate: Option<u64>,
872
873 reward_slashing_rate: Option<u64>,
876
877 storage_gas_price: Option<u64>,
879
880 base_gas_price: Option<u64>,
882
883 validator_target_reward: Option<u64>,
885
886 max_transactions_per_checkpoint: Option<u64>,
893
894 max_checkpoint_size_bytes: Option<u64>,
898
899 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
905
906 address_from_bytes_cost_base: Option<u64>,
911 address_to_u256_cost_base: Option<u64>,
913 address_from_u256_cost_base: Option<u64>,
915
916 config_read_setting_impl_cost_base: Option<u64>,
921 config_read_setting_impl_cost_per_byte: Option<u64>,
922
923 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
927 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
928 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
929 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
930 dynamic_field_add_child_object_cost_base: Option<u64>,
933 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
934 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
935 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
936 dynamic_field_borrow_child_object_cost_base: Option<u64>,
939 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
940 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
941 dynamic_field_remove_child_object_cost_base: Option<u64>,
944 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
945 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
946 dynamic_field_has_child_object_cost_base: Option<u64>,
949 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
952 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
953 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
954
955 event_emit_cost_base: Option<u64>,
958 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
959 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
960 event_emit_output_cost_per_byte: Option<u64>,
961
962 object_borrow_uid_cost_base: Option<u64>,
965 object_delete_impl_cost_base: Option<u64>,
967 object_record_new_uid_cost_base: Option<u64>,
969
970 transfer_transfer_internal_cost_base: Option<u64>,
973 transfer_freeze_object_cost_base: Option<u64>,
975 transfer_share_object_cost_base: Option<u64>,
977 transfer_receive_object_cost_base: Option<u64>,
980
981 tx_context_derive_id_cost_base: Option<u64>,
984
985 types_is_one_time_witness_cost_base: Option<u64>,
988 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
989 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
990
991 validator_validate_metadata_cost_base: Option<u64>,
994 validator_validate_metadata_data_cost_per_byte: Option<u64>,
995
996 crypto_invalid_arguments_cost: Option<u64>,
998 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1000 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1001 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1002
1003 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1005 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1006 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1007
1008 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1010 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1011 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1012 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1013 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1014 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1015
1016 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1018
1019 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1021 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1022 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1023 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1024 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1025 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1026
1027 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1029 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1030 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1031 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1032 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1033 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1034
1035 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1037 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1038 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1039 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1040 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1041 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1042
1043 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1045 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1046 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1047
1048 ed25519_ed25519_verify_cost_base: Option<u64>,
1050 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1051 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1052
1053 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1055 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1056
1057 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1059 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1060 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1061 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1062 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1063
1064 hash_blake2b256_cost_base: Option<u64>,
1066 hash_blake2b256_data_cost_per_byte: Option<u64>,
1067 hash_blake2b256_data_cost_per_block: Option<u64>,
1068
1069 hash_keccak256_cost_base: Option<u64>,
1071 hash_keccak256_data_cost_per_byte: Option<u64>,
1072 hash_keccak256_data_cost_per_block: Option<u64>,
1073
1074 poseidon_bn254_cost_base: Option<u64>,
1076 poseidon_bn254_cost_per_block: Option<u64>,
1077
1078 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1080 group_ops_bls12381_decode_g1_cost: Option<u64>,
1081 group_ops_bls12381_decode_g2_cost: Option<u64>,
1082 group_ops_bls12381_decode_gt_cost: Option<u64>,
1083 group_ops_bls12381_scalar_add_cost: Option<u64>,
1084 group_ops_bls12381_g1_add_cost: Option<u64>,
1085 group_ops_bls12381_g2_add_cost: Option<u64>,
1086 group_ops_bls12381_gt_add_cost: Option<u64>,
1087 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1088 group_ops_bls12381_g1_sub_cost: Option<u64>,
1089 group_ops_bls12381_g2_sub_cost: Option<u64>,
1090 group_ops_bls12381_gt_sub_cost: Option<u64>,
1091 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1092 group_ops_bls12381_g1_mul_cost: Option<u64>,
1093 group_ops_bls12381_g2_mul_cost: Option<u64>,
1094 group_ops_bls12381_gt_mul_cost: Option<u64>,
1095 group_ops_bls12381_scalar_div_cost: Option<u64>,
1096 group_ops_bls12381_g1_div_cost: Option<u64>,
1097 group_ops_bls12381_g2_div_cost: Option<u64>,
1098 group_ops_bls12381_gt_div_cost: Option<u64>,
1099 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1100 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1101 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1102 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1103 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1104 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1105 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1106 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1107 group_ops_bls12381_msm_max_len: Option<u32>,
1108 group_ops_bls12381_pairing_cost: Option<u64>,
1109 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1110 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1111 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1112 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1113 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1114
1115 hmac_hmac_sha3_256_cost_base: Option<u64>,
1117 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1118 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1119
1120 check_zklogin_id_cost_base: Option<u64>,
1122 check_zklogin_issuer_cost_base: Option<u64>,
1124
1125 vdf_verify_vdf_cost: Option<u64>,
1126 vdf_hash_to_input_cost: Option<u64>,
1127
1128 bcs_per_byte_serialized_cost: Option<u64>,
1130 bcs_legacy_min_output_size_cost: Option<u64>,
1131 bcs_failure_cost: Option<u64>,
1132
1133 hash_sha2_256_base_cost: Option<u64>,
1134 hash_sha2_256_per_byte_cost: Option<u64>,
1135 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1136 hash_sha3_256_base_cost: Option<u64>,
1137 hash_sha3_256_per_byte_cost: Option<u64>,
1138 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1139 type_name_get_base_cost: Option<u64>,
1140 type_name_get_per_byte_cost: Option<u64>,
1141
1142 string_check_utf8_base_cost: Option<u64>,
1143 string_check_utf8_per_byte_cost: Option<u64>,
1144 string_is_char_boundary_base_cost: Option<u64>,
1145 string_sub_string_base_cost: Option<u64>,
1146 string_sub_string_per_byte_cost: Option<u64>,
1147 string_index_of_base_cost: Option<u64>,
1148 string_index_of_per_byte_pattern_cost: Option<u64>,
1149 string_index_of_per_byte_searched_cost: Option<u64>,
1150
1151 vector_empty_base_cost: Option<u64>,
1152 vector_length_base_cost: Option<u64>,
1153 vector_push_back_base_cost: Option<u64>,
1154 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1155 vector_borrow_base_cost: Option<u64>,
1156 vector_pop_back_base_cost: Option<u64>,
1157 vector_destroy_empty_base_cost: Option<u64>,
1158 vector_swap_base_cost: Option<u64>,
1159 debug_print_base_cost: Option<u64>,
1160 debug_print_stack_trace_base_cost: Option<u64>,
1161
1162 execution_version: Option<u64>,
1164
1165 consensus_bad_nodes_stake_threshold: Option<u64>,
1169
1170 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1171 max_age_of_jwk_in_epochs: Option<u64>,
1175
1176 random_beacon_reduction_allowed_delta: Option<u16>,
1180
1181 random_beacon_reduction_lower_bound: Option<u32>,
1184
1185 random_beacon_dkg_timeout_round: Option<u32>,
1188
1189 random_beacon_min_round_interval_ms: Option<u64>,
1191
1192 random_beacon_dkg_version: Option<u64>,
1196
1197 consensus_max_transaction_size_bytes: Option<u64>,
1202 consensus_max_transactions_in_block_bytes: Option<u64>,
1204 consensus_max_num_transactions_in_block: Option<u64>,
1206
1207 max_deferral_rounds_for_congestion_control: Option<u64>,
1211
1212 min_checkpoint_interval_ms: Option<u64>,
1214
1215 checkpoint_summary_version_specific_data: Option<u64>,
1217
1218 max_soft_bundle_size: Option<u64>,
1221
1222 bridge_should_try_to_finalize_committee: Option<bool>,
1227
1228 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1234
1235 max_committee_members_count: Option<u64>,
1239
1240 consensus_gc_depth: Option<u32>,
1243
1244 consensus_max_acknowledgments_per_block: Option<u32>,
1250
1251 max_congestion_limit_overshoot_per_commit: Option<u64>,
1256
1257 scorer_version: Option<u16>,
1264
1265 auth_context_digest_cost_base: Option<u64>,
1268 auth_context_tx_commands_cost_base: Option<u64>,
1270 auth_context_tx_commands_cost_per_byte: Option<u64>,
1271 auth_context_tx_inputs_cost_base: Option<u64>,
1273 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1274 auth_context_replace_cost_base: Option<u64>,
1277 auth_context_replace_cost_per_byte: Option<u64>,
1278}
1279
1280impl ProtocolConfig {
1282 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1295 self.feature_flags
1296 .disable_invariant_violation_check_in_swap_loc
1297 }
1298
1299 pub fn no_extraneous_module_bytes(&self) -> bool {
1300 self.feature_flags.no_extraneous_module_bytes
1301 }
1302
1303 pub fn zklogin_auth(&self) -> bool {
1304 self.feature_flags.zklogin_auth
1305 }
1306
1307 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1308 self.feature_flags.consensus_transaction_ordering
1309 }
1310
1311 pub fn enable_jwk_consensus_updates(&self) -> bool {
1312 self.feature_flags.enable_jwk_consensus_updates
1313 }
1314
1315 pub fn create_authenticator_state_in_genesis(&self) -> bool {
1317 self.enable_jwk_consensus_updates()
1318 }
1319
1320 pub fn dkg_version(&self) -> u64 {
1321 self.random_beacon_dkg_version.unwrap_or(1)
1323 }
1324
1325 pub fn accept_zklogin_in_multisig(&self) -> bool {
1326 self.feature_flags.accept_zklogin_in_multisig
1327 }
1328
1329 pub fn zklogin_max_epoch_upper_bound_delta(&self) -> Option<u64> {
1330 self.feature_flags.zklogin_max_epoch_upper_bound_delta
1331 }
1332
1333 pub fn hardened_otw_check(&self) -> bool {
1334 self.feature_flags.hardened_otw_check
1335 }
1336
1337 pub fn enable_poseidon(&self) -> bool {
1338 self.feature_flags.enable_poseidon
1339 }
1340
1341 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1342 self.feature_flags.enable_group_ops_native_function_msm
1343 }
1344
1345 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1346 self.feature_flags.per_object_congestion_control_mode
1347 }
1348
1349 pub fn consensus_choice(&self) -> ConsensusChoice {
1350 self.feature_flags.consensus_choice
1351 }
1352
1353 pub fn consensus_network(&self) -> ConsensusNetwork {
1354 self.feature_flags.consensus_network
1355 }
1356
1357 pub fn enable_vdf(&self) -> bool {
1358 self.feature_flags.enable_vdf
1359 }
1360
1361 pub fn passkey_auth(&self) -> bool {
1362 self.feature_flags.passkey_auth
1363 }
1364
1365 pub fn max_transaction_size_bytes(&self) -> u64 {
1366 self.consensus_max_transaction_size_bytes
1368 .unwrap_or(256 * 1024)
1369 }
1370
1371 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1372 if cfg!(msim) {
1373 256 * 1024
1374 } else {
1375 self.consensus_max_transactions_in_block_bytes
1376 .unwrap_or(512 * 1024)
1377 }
1378 }
1379
1380 pub fn max_num_transactions_in_block(&self) -> u64 {
1381 if cfg!(msim) {
1382 8
1383 } else {
1384 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1385 }
1386 }
1387
1388 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1389 self.feature_flags.rethrow_serialization_type_layout_errors
1390 }
1391
1392 pub fn relocate_event_module(&self) -> bool {
1393 self.feature_flags.relocate_event_module
1394 }
1395
1396 pub fn protocol_defined_base_fee(&self) -> bool {
1397 self.feature_flags.protocol_defined_base_fee
1398 }
1399
1400 pub fn uncompressed_g1_group_elements(&self) -> bool {
1401 self.feature_flags.uncompressed_g1_group_elements
1402 }
1403
1404 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1405 self.feature_flags
1406 .disallow_new_modules_in_deps_only_packages
1407 }
1408
1409 pub fn native_charging_v2(&self) -> bool {
1410 self.feature_flags.native_charging_v2
1411 }
1412
1413 pub fn consensus_round_prober(&self) -> bool {
1414 self.feature_flags.consensus_round_prober
1415 }
1416
1417 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1418 self.feature_flags
1419 .consensus_distributed_vote_scoring_strategy
1420 }
1421
1422 pub fn gc_depth(&self) -> u32 {
1423 if cfg!(msim) {
1424 min(5, self.consensus_gc_depth.unwrap_or(0))
1426 } else {
1427 self.consensus_gc_depth.unwrap_or(0)
1428 }
1429 }
1430
1431 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1432 let res = self.feature_flags.consensus_linearize_subdag_v2;
1433 assert!(
1434 !res || self.gc_depth() > 0,
1435 "The consensus linearize sub dag V2 requires GC to be enabled"
1436 );
1437 res
1438 }
1439
1440 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1441 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1442 }
1443
1444 pub fn variant_nodes(&self) -> bool {
1445 self.feature_flags.variant_nodes
1446 }
1447
1448 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1449 self.feature_flags.consensus_smart_ancestor_selection
1450 }
1451
1452 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1453 self.feature_flags
1454 .consensus_round_prober_probe_accepted_rounds
1455 }
1456
1457 pub fn consensus_zstd_compression(&self) -> bool {
1458 self.feature_flags.consensus_zstd_compression
1459 }
1460
1461 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1462 self.feature_flags
1463 .congestion_control_min_free_execution_slot
1464 }
1465
1466 pub fn accept_passkey_in_multisig(&self) -> bool {
1467 self.feature_flags.accept_passkey_in_multisig
1468 }
1469
1470 pub fn consensus_batched_block_sync(&self) -> bool {
1471 self.feature_flags.consensus_batched_block_sync
1472 }
1473
1474 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1477 self.feature_flags
1478 .congestion_control_gas_price_feedback_mechanism
1479 }
1480
1481 pub fn validate_identifier_inputs(&self) -> bool {
1482 self.feature_flags.validate_identifier_inputs
1483 }
1484
1485 pub fn minimize_child_object_mutations(&self) -> bool {
1486 self.feature_flags.minimize_child_object_mutations
1487 }
1488
1489 pub fn dependency_linkage_error(&self) -> bool {
1490 self.feature_flags.dependency_linkage_error
1491 }
1492
1493 pub fn additional_multisig_checks(&self) -> bool {
1494 self.feature_flags.additional_multisig_checks
1495 }
1496
1497 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1498 0
1501 }
1502
1503 pub fn normalize_ptb_arguments(&self) -> bool {
1504 self.feature_flags.normalize_ptb_arguments
1505 }
1506
1507 pub fn select_committee_from_eligible_validators(&self) -> bool {
1508 let res = self.feature_flags.select_committee_from_eligible_validators;
1509 assert!(
1510 !res || (self.protocol_defined_base_fee()
1511 && self.max_committee_members_count_as_option().is_some()),
1512 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1513 );
1514 res
1515 }
1516
1517 pub fn track_non_committee_eligible_validators(&self) -> bool {
1518 self.feature_flags.track_non_committee_eligible_validators
1519 }
1520
1521 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1522 let res = self
1523 .feature_flags
1524 .select_committee_supporting_next_epoch_version;
1525 assert!(
1526 !res || (self.track_non_committee_eligible_validators()
1527 && self.select_committee_from_eligible_validators()),
1528 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1529 );
1530 res
1531 }
1532
1533 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1534 let res = self
1535 .feature_flags
1536 .consensus_median_timestamp_with_checkpoint_enforcement;
1537 assert!(
1538 !res || self.gc_depth() > 0,
1539 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1540 );
1541 res
1542 }
1543
1544 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1545 self.feature_flags
1546 .consensus_commit_transactions_only_for_traversed_headers
1547 }
1548
1549 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1552 self.feature_flags
1553 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1554 }
1555
1556 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1559 self.feature_flags
1560 .separate_gas_price_feedback_mechanism_for_randomness
1561 }
1562
1563 pub fn metadata_in_module_bytes(&self) -> bool {
1564 self.feature_flags.metadata_in_module_bytes
1565 }
1566
1567 pub fn publish_package_metadata(&self) -> bool {
1568 self.feature_flags.publish_package_metadata
1569 }
1570
1571 pub fn enable_move_authentication(&self) -> bool {
1572 self.feature_flags.enable_move_authentication
1573 }
1574
1575 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1576 self.feature_flags.pass_validator_scores_to_advance_epoch
1577 }
1578
1579 pub fn calculate_validator_scores(&self) -> bool {
1580 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1581 assert!(
1582 !calculate_validator_scores || self.scorer_version.is_some(),
1583 "calculate_validator_scores requires scorer_version to be set"
1584 );
1585 calculate_validator_scores
1586 }
1587
1588 pub fn adjust_rewards_by_score(&self) -> bool {
1589 let adjust = self.feature_flags.adjust_rewards_by_score;
1590 assert!(
1591 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1592 "adjust_rewards_by_score requires scorer_version to be set"
1593 );
1594 adjust
1595 }
1596
1597 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1598 let pass = self
1599 .feature_flags
1600 .pass_calculated_validator_scores_to_advance_epoch;
1601 assert!(
1602 !pass
1603 || (self.pass_validator_scores_to_advance_epoch()
1604 && self.calculate_validator_scores()),
1605 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
1606 );
1607 pass
1608 }
1609 pub fn consensus_fast_commit_sync(&self) -> bool {
1610 let res = self.feature_flags.consensus_fast_commit_sync;
1611 assert!(
1612 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
1613 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
1614 );
1615 res
1616 }
1617}
1618
1619#[cfg(not(msim))]
1620static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1621
1622#[cfg(msim)]
1624thread_local! {
1625 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1626}
1627
1628impl ProtocolConfig {
1630 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1633 assert!(
1635 version >= ProtocolVersion::MIN,
1636 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1637 version,
1638 ProtocolVersion::MIN.0,
1639 );
1640 assert!(
1641 version <= ProtocolVersion::MAX_ALLOWED,
1642 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1643 version,
1644 ProtocolVersion::MAX_ALLOWED.0,
1645 );
1646
1647 let mut ret = Self::get_for_version_impl(version, chain);
1648 ret.version = version;
1649
1650 ret = CONFIG_OVERRIDE.with(|ovr| {
1651 if let Some(override_fn) = &*ovr.borrow() {
1652 warn!(
1653 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1654 );
1655 override_fn(version, ret)
1656 } else {
1657 ret
1658 }
1659 });
1660
1661 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1662 warn!(
1663 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1664 );
1665 let overrides: ProtocolConfigOptional =
1666 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1667 .expect("failed to parse ProtocolConfig override env variables");
1668 overrides.apply_to(&mut ret);
1669 }
1670
1671 ret
1672 }
1673
1674 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1677 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1678 let mut ret = Self::get_for_version_impl(version, chain);
1679 ret.version = version;
1680 Some(ret)
1681 } else {
1682 None
1683 }
1684 }
1685
1686 #[cfg(not(msim))]
1687 pub fn poison_get_for_min_version() {
1688 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1689 }
1690
1691 #[cfg(not(msim))]
1692 fn load_poison_get_for_min_version() -> bool {
1693 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1694 }
1695
1696 #[cfg(msim)]
1697 pub fn poison_get_for_min_version() {
1698 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1699 }
1700
1701 #[cfg(msim)]
1702 fn load_poison_get_for_min_version() -> bool {
1703 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1704 }
1705
1706 pub fn convert_type_argument_error(&self) -> bool {
1707 self.feature_flags.convert_type_argument_error
1708 }
1709
1710 pub fn get_for_min_version() -> Self {
1714 if Self::load_poison_get_for_min_version() {
1715 panic!("get_for_min_version called on validator");
1716 }
1717 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1718 }
1719
1720 #[expect(non_snake_case)]
1731 pub fn get_for_max_version_UNSAFE() -> Self {
1732 if Self::load_poison_get_for_min_version() {
1733 panic!("get_for_max_version_UNSAFE called on validator");
1734 }
1735 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1736 }
1737
1738 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1739 #[cfg(msim)]
1740 {
1741 if version > ProtocolVersion::MAX {
1743 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1744 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1745 return config;
1746 }
1747 }
1748
1749 let mut cfg = Self {
1753 version,
1754
1755 feature_flags: Default::default(),
1756
1757 max_tx_size_bytes: Some(128 * 1024),
1758 max_input_objects: Some(2048),
1761 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1762 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1763 max_gas_payment_objects: Some(256),
1764 max_modules_in_publish: Some(64),
1765 max_package_dependencies: Some(32),
1766 max_arguments: Some(512),
1767 max_type_arguments: Some(16),
1768 max_type_argument_depth: Some(16),
1769 max_pure_argument_size: Some(16 * 1024),
1770 max_programmable_tx_commands: Some(1024),
1771 move_binary_format_version: Some(7),
1772 min_move_binary_format_version: Some(6),
1773 binary_module_handles: Some(100),
1774 binary_struct_handles: Some(300),
1775 binary_function_handles: Some(1500),
1776 binary_function_instantiations: Some(750),
1777 binary_signatures: Some(1000),
1778 binary_constant_pool: Some(4000),
1779 binary_identifiers: Some(10000),
1780 binary_address_identifiers: Some(100),
1781 binary_struct_defs: Some(200),
1782 binary_struct_def_instantiations: Some(100),
1783 binary_function_defs: Some(1000),
1784 binary_field_handles: Some(500),
1785 binary_field_instantiations: Some(250),
1786 binary_friend_decls: Some(100),
1787 binary_enum_defs: None,
1788 binary_enum_def_instantiations: None,
1789 binary_variant_handles: None,
1790 binary_variant_instantiation_handles: None,
1791 max_move_object_size: Some(250 * 1024),
1792 max_move_package_size: Some(100 * 1024),
1793 max_publish_or_upgrade_per_ptb: Some(5),
1794 max_auth_gas: None,
1796 max_tx_gas: Some(50_000_000_000),
1798 max_gas_price: Some(100_000),
1799 max_gas_computation_bucket: Some(5_000_000),
1800 max_loop_depth: Some(5),
1801 max_generic_instantiation_length: Some(32),
1802 max_function_parameters: Some(128),
1803 max_basic_blocks: Some(1024),
1804 max_value_stack_size: Some(1024),
1805 max_type_nodes: Some(256),
1806 max_push_size: Some(10000),
1807 max_struct_definitions: Some(200),
1808 max_function_definitions: Some(1000),
1809 max_fields_in_struct: Some(32),
1810 max_dependency_depth: Some(100),
1811 max_num_event_emit: Some(1024),
1812 max_num_new_move_object_ids: Some(2048),
1813 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1814 max_num_deleted_move_object_ids: Some(2048),
1815 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1816 max_num_transferred_move_object_ids: Some(2048),
1817 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1818 max_event_emit_size: Some(250 * 1024),
1819 max_move_vector_len: Some(256 * 1024),
1820 max_type_to_layout_nodes: None,
1821 max_ptb_value_size: None,
1822
1823 max_back_edges_per_function: Some(10_000),
1824 max_back_edges_per_module: Some(10_000),
1825
1826 max_verifier_meter_ticks_per_function: Some(16_000_000),
1827
1828 max_meter_ticks_per_module: Some(16_000_000),
1829 max_meter_ticks_per_package: Some(16_000_000),
1830
1831 object_runtime_max_num_cached_objects: Some(1000),
1832 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
1833 object_runtime_max_num_store_entries: Some(1000),
1834 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
1835 base_tx_cost_fixed: Some(1_000),
1837 package_publish_cost_fixed: Some(1_000),
1838 base_tx_cost_per_byte: Some(0),
1839 package_publish_cost_per_byte: Some(80),
1840 obj_access_cost_read_per_byte: Some(15),
1841 obj_access_cost_mutate_per_byte: Some(40),
1842 obj_access_cost_delete_per_byte: Some(40),
1843 obj_access_cost_verify_per_byte: Some(200),
1844 obj_data_cost_refundable: Some(100),
1845 obj_metadata_cost_non_refundable: Some(50),
1846 gas_model_version: Some(1),
1847 storage_rebate_rate: Some(10000),
1848 reward_slashing_rate: Some(10000),
1850 storage_gas_price: Some(76),
1851 base_gas_price: None,
1852 validator_target_reward: Some(767_000 * 1_000_000_000),
1855 max_transactions_per_checkpoint: Some(10_000),
1856 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
1857
1858 buffer_stake_for_protocol_upgrade_bps: Some(5000),
1860
1861 address_from_bytes_cost_base: Some(52),
1865 address_to_u256_cost_base: Some(52),
1867 address_from_u256_cost_base: Some(52),
1869
1870 config_read_setting_impl_cost_base: Some(100),
1873 config_read_setting_impl_cost_per_byte: Some(40),
1874
1875 dynamic_field_hash_type_and_key_cost_base: Some(100),
1879 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
1880 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
1881 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
1882 dynamic_field_add_child_object_cost_base: Some(100),
1885 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
1886 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
1887 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
1888 dynamic_field_borrow_child_object_cost_base: Some(100),
1891 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
1892 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
1893 dynamic_field_remove_child_object_cost_base: Some(100),
1896 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
1897 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
1898 dynamic_field_has_child_object_cost_base: Some(100),
1901 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
1904 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
1905 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
1906
1907 event_emit_cost_base: Some(52),
1910 event_emit_value_size_derivation_cost_per_byte: Some(2),
1911 event_emit_tag_size_derivation_cost_per_byte: Some(5),
1912 event_emit_output_cost_per_byte: Some(10),
1913
1914 object_borrow_uid_cost_base: Some(52),
1917 object_delete_impl_cost_base: Some(52),
1919 object_record_new_uid_cost_base: Some(52),
1921
1922 transfer_transfer_internal_cost_base: Some(52),
1926 transfer_freeze_object_cost_base: Some(52),
1928 transfer_share_object_cost_base: Some(52),
1930 transfer_receive_object_cost_base: Some(52),
1931
1932 tx_context_derive_id_cost_base: Some(52),
1936
1937 types_is_one_time_witness_cost_base: Some(52),
1940 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
1941 types_is_one_time_witness_type_cost_per_byte: Some(2),
1942
1943 validator_validate_metadata_cost_base: Some(52),
1947 validator_validate_metadata_data_cost_per_byte: Some(2),
1948
1949 crypto_invalid_arguments_cost: Some(100),
1951 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
1953 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
1954 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
1955
1956 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
1958 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
1959 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
1960
1961 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
1963 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1964 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1965 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
1966 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1967 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
1968
1969 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
1971
1972 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
1974 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
1975 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
1976 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
1977 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
1978 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
1979
1980 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
1982 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1983 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1984 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
1985 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1986 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
1987
1988 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
1990 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
1991 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
1992 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
1993 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
1994 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
1995
1996 ecvrf_ecvrf_verify_cost_base: Some(52),
1998 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
1999 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2000
2001 ed25519_ed25519_verify_cost_base: Some(52),
2003 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2004 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2005
2006 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2008 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2009
2010 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2012 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2013 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2014 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2015 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2016
2017 hash_blake2b256_cost_base: Some(52),
2019 hash_blake2b256_data_cost_per_byte: Some(2),
2020 hash_blake2b256_data_cost_per_block: Some(2),
2021 hash_keccak256_cost_base: Some(52),
2023 hash_keccak256_data_cost_per_byte: Some(2),
2024 hash_keccak256_data_cost_per_block: Some(2),
2025
2026 poseidon_bn254_cost_base: None,
2027 poseidon_bn254_cost_per_block: None,
2028
2029 hmac_hmac_sha3_256_cost_base: Some(52),
2031 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2032 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2033
2034 group_ops_bls12381_decode_scalar_cost: Some(52),
2036 group_ops_bls12381_decode_g1_cost: Some(52),
2037 group_ops_bls12381_decode_g2_cost: Some(52),
2038 group_ops_bls12381_decode_gt_cost: Some(52),
2039 group_ops_bls12381_scalar_add_cost: Some(52),
2040 group_ops_bls12381_g1_add_cost: Some(52),
2041 group_ops_bls12381_g2_add_cost: Some(52),
2042 group_ops_bls12381_gt_add_cost: Some(52),
2043 group_ops_bls12381_scalar_sub_cost: Some(52),
2044 group_ops_bls12381_g1_sub_cost: Some(52),
2045 group_ops_bls12381_g2_sub_cost: Some(52),
2046 group_ops_bls12381_gt_sub_cost: Some(52),
2047 group_ops_bls12381_scalar_mul_cost: Some(52),
2048 group_ops_bls12381_g1_mul_cost: Some(52),
2049 group_ops_bls12381_g2_mul_cost: Some(52),
2050 group_ops_bls12381_gt_mul_cost: Some(52),
2051 group_ops_bls12381_scalar_div_cost: Some(52),
2052 group_ops_bls12381_g1_div_cost: Some(52),
2053 group_ops_bls12381_g2_div_cost: Some(52),
2054 group_ops_bls12381_gt_div_cost: Some(52),
2055 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2056 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2057 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2058 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2059 group_ops_bls12381_g1_msm_base_cost: Some(52),
2060 group_ops_bls12381_g2_msm_base_cost: Some(52),
2061 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2062 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2063 group_ops_bls12381_msm_max_len: Some(32),
2064 group_ops_bls12381_pairing_cost: Some(52),
2065 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2066 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2067 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2068 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2069 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2070
2071 check_zklogin_id_cost_base: Some(200),
2073 check_zklogin_issuer_cost_base: Some(200),
2075
2076 vdf_verify_vdf_cost: None,
2077 vdf_hash_to_input_cost: None,
2078
2079 bcs_per_byte_serialized_cost: Some(2),
2080 bcs_legacy_min_output_size_cost: Some(1),
2081 bcs_failure_cost: Some(52),
2082 hash_sha2_256_base_cost: Some(52),
2083 hash_sha2_256_per_byte_cost: Some(2),
2084 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2085 hash_sha3_256_base_cost: Some(52),
2086 hash_sha3_256_per_byte_cost: Some(2),
2087 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2088 type_name_get_base_cost: Some(52),
2089 type_name_get_per_byte_cost: Some(2),
2090 string_check_utf8_base_cost: Some(52),
2091 string_check_utf8_per_byte_cost: Some(2),
2092 string_is_char_boundary_base_cost: Some(52),
2093 string_sub_string_base_cost: Some(52),
2094 string_sub_string_per_byte_cost: Some(2),
2095 string_index_of_base_cost: Some(52),
2096 string_index_of_per_byte_pattern_cost: Some(2),
2097 string_index_of_per_byte_searched_cost: Some(2),
2098 vector_empty_base_cost: Some(52),
2099 vector_length_base_cost: Some(52),
2100 vector_push_back_base_cost: Some(52),
2101 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2102 vector_borrow_base_cost: Some(52),
2103 vector_pop_back_base_cost: Some(52),
2104 vector_destroy_empty_base_cost: Some(52),
2105 vector_swap_base_cost: Some(52),
2106 debug_print_base_cost: Some(52),
2107 debug_print_stack_trace_base_cost: Some(52),
2108
2109 max_size_written_objects: Some(5 * 1000 * 1000),
2110 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2113
2114 max_move_identifier_len: Some(128),
2116 max_move_value_depth: Some(128),
2117 max_move_enum_variants: None,
2118
2119 gas_rounding_step: Some(1_000),
2120
2121 execution_version: Some(1),
2122
2123 max_event_emit_size_total: Some(
2126 256 * 250 * 1024, ),
2128
2129 consensus_bad_nodes_stake_threshold: Some(20),
2136
2137 max_jwk_votes_per_validator_per_epoch: Some(240),
2139
2140 max_age_of_jwk_in_epochs: Some(1),
2141
2142 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2146
2147 random_beacon_reduction_allowed_delta: Some(800),
2148
2149 random_beacon_reduction_lower_bound: Some(1000),
2150 random_beacon_dkg_timeout_round: Some(3000),
2151 random_beacon_min_round_interval_ms: Some(500),
2152
2153 random_beacon_dkg_version: Some(1),
2154
2155 consensus_max_num_transactions_in_block: Some(512),
2159
2160 max_deferral_rounds_for_congestion_control: Some(10),
2161
2162 min_checkpoint_interval_ms: Some(200),
2163
2164 checkpoint_summary_version_specific_data: Some(1),
2165
2166 max_soft_bundle_size: Some(5),
2167
2168 bridge_should_try_to_finalize_committee: None,
2169
2170 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2171
2172 max_committee_members_count: None,
2173
2174 consensus_gc_depth: None,
2175
2176 consensus_max_acknowledgments_per_block: None,
2177
2178 max_congestion_limit_overshoot_per_commit: None,
2179
2180 scorer_version: None,
2181
2182 auth_context_digest_cost_base: None,
2184 auth_context_tx_commands_cost_base: None,
2185 auth_context_tx_commands_cost_per_byte: None,
2186 auth_context_tx_inputs_cost_base: None,
2187 auth_context_tx_inputs_cost_per_byte: None,
2188 auth_context_replace_cost_base: None,
2189 auth_context_replace_cost_per_byte: None,
2190 };
2193
2194 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2195
2196 {
2198 cfg.feature_flags
2199 .disable_invariant_violation_check_in_swap_loc = true;
2200 cfg.feature_flags.no_extraneous_module_bytes = true;
2201 cfg.feature_flags.hardened_otw_check = true;
2202 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2203 }
2204
2205 {
2207 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2208 }
2209
2210 cfg.feature_flags.consensus_choice = ConsensusChoice::Mysticeti;
2212 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2214
2215 cfg.feature_flags.per_object_congestion_control_mode =
2216 PerObjectCongestionControlMode::TotalTxCount;
2217
2218 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2220
2221 if chain != Chain::Mainnet && chain != Chain::Testnet {
2223 cfg.feature_flags.enable_poseidon = true;
2224 cfg.poseidon_bn254_cost_base = Some(260);
2225 cfg.poseidon_bn254_cost_per_block = Some(10);
2226
2227 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2228
2229 cfg.feature_flags.enable_vdf = true;
2230 cfg.vdf_verify_vdf_cost = Some(1500);
2233 cfg.vdf_hash_to_input_cost = Some(100);
2234
2235 cfg.feature_flags.passkey_auth = true;
2236 }
2237
2238 for cur in 2..=version.0 {
2239 match cur {
2240 1 => unreachable!(),
2241 2 => {}
2243 3 => {
2244 cfg.feature_flags.relocate_event_module = true;
2245 }
2246 4 => {
2247 cfg.max_type_to_layout_nodes = Some(512);
2248 }
2249 5 => {
2250 cfg.feature_flags.protocol_defined_base_fee = true;
2251 cfg.base_gas_price = Some(1000);
2252
2253 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2254 cfg.feature_flags.convert_type_argument_error = true;
2255 cfg.feature_flags.native_charging_v2 = true;
2256
2257 if chain != Chain::Mainnet && chain != Chain::Testnet {
2258 cfg.feature_flags.uncompressed_g1_group_elements = true;
2259 }
2260
2261 cfg.gas_model_version = Some(2);
2262
2263 cfg.poseidon_bn254_cost_per_block = Some(388);
2264
2265 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2266 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2267 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2268 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2269 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2270 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2271 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2272 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2273
2274 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2276 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2277 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2278 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2279
2280 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2281 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2282 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2283 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2284 Some(8213);
2285 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2286 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2287 Some(9484);
2288
2289 cfg.hash_keccak256_cost_base = Some(10);
2290 cfg.hash_blake2b256_cost_base = Some(10);
2291
2292 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2294 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2295 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2296 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2297
2298 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2299 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2300 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2301 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2302
2303 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2304 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2305 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2306 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2307
2308 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2309 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2310 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2311 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2312
2313 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2314 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2315 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2316 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2317
2318 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2319 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2320
2321 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2322 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2323 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2324 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2325
2326 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2327 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2328 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2329 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2330 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2331
2332 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2333
2334 cfg.validator_validate_metadata_cost_base = Some(20000);
2335
2336 cfg.max_committee_members_count = Some(50);
2337 }
2338 6 => {
2339 cfg.max_ptb_value_size = Some(1024 * 1024);
2340 }
2341 7 => {
2342 }
2345 8 => {
2346 cfg.feature_flags.variant_nodes = true;
2347
2348 if chain != Chain::Mainnet {
2349 cfg.feature_flags.consensus_round_prober = true;
2351 cfg.feature_flags
2353 .consensus_distributed_vote_scoring_strategy = true;
2354 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2355 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2357 cfg.feature_flags
2359 .consensus_round_prober_probe_accepted_rounds = true;
2360 cfg.feature_flags.consensus_zstd_compression = true;
2362 cfg.consensus_gc_depth = Some(60);
2366 }
2367
2368 if chain != Chain::Testnet && chain != Chain::Mainnet {
2371 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2372 }
2373 }
2374 9 => {
2375 if chain != Chain::Mainnet {
2376 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2378 }
2379
2380 cfg.feature_flags.consensus_zstd_compression = true;
2382
2383 if chain != Chain::Testnet && chain != Chain::Mainnet {
2385 cfg.feature_flags.accept_passkey_in_multisig = true;
2386 }
2387
2388 cfg.bridge_should_try_to_finalize_committee = None;
2390 }
2391 10 => {
2392 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2395
2396 cfg.max_committee_members_count = Some(80);
2398
2399 cfg.feature_flags.consensus_round_prober = true;
2401 cfg.feature_flags
2403 .consensus_round_prober_probe_accepted_rounds = true;
2404 cfg.feature_flags
2406 .consensus_distributed_vote_scoring_strategy = true;
2407 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2409
2410 cfg.consensus_gc_depth = Some(60);
2415
2416 cfg.feature_flags.minimize_child_object_mutations = true;
2418
2419 if chain != Chain::Mainnet {
2420 cfg.feature_flags.consensus_batched_block_sync = true;
2422 }
2423
2424 if chain != Chain::Testnet && chain != Chain::Mainnet {
2425 cfg.feature_flags
2428 .congestion_control_gas_price_feedback_mechanism = true;
2429 }
2430
2431 cfg.feature_flags.validate_identifier_inputs = true;
2432 cfg.feature_flags.dependency_linkage_error = true;
2433 cfg.feature_flags.additional_multisig_checks = true;
2434 }
2435 11 => {
2436 }
2439 12 => {
2440 cfg.feature_flags
2443 .congestion_control_gas_price_feedback_mechanism = true;
2444
2445 cfg.feature_flags.normalize_ptb_arguments = true;
2447 }
2448 13 => {
2449 cfg.feature_flags.select_committee_from_eligible_validators = true;
2452 cfg.feature_flags.track_non_committee_eligible_validators = true;
2455
2456 if chain != Chain::Testnet && chain != Chain::Mainnet {
2457 cfg.feature_flags
2460 .select_committee_supporting_next_epoch_version = true;
2461 }
2462 }
2463 14 => {
2464 cfg.feature_flags.consensus_batched_block_sync = true;
2466
2467 if chain != Chain::Mainnet {
2468 cfg.feature_flags
2471 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2472 cfg.feature_flags
2476 .select_committee_supporting_next_epoch_version = true;
2477 }
2478 if chain != Chain::Testnet && chain != Chain::Mainnet {
2479 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2481 }
2482 }
2483 15 => {
2484 if chain != Chain::Mainnet && chain != Chain::Testnet {
2485 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2489 }
2490 }
2491 16 => {
2492 cfg.feature_flags
2495 .select_committee_supporting_next_epoch_version = true;
2496 cfg.feature_flags
2498 .consensus_commit_transactions_only_for_traversed_headers = true;
2499 }
2500 17 => {
2501 cfg.max_committee_members_count = Some(100);
2503 }
2504 18 => {
2505 if chain != Chain::Mainnet {
2506 cfg.feature_flags.passkey_auth = true;
2508 }
2509 }
2510 19 => {
2511 if chain != Chain::Testnet && chain != Chain::Mainnet {
2512 cfg.feature_flags
2515 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2516 cfg.feature_flags
2519 .separate_gas_price_feedback_mechanism_for_randomness = true;
2520 cfg.feature_flags.metadata_in_module_bytes = true;
2523 cfg.feature_flags.publish_package_metadata = true;
2524 cfg.feature_flags.enable_move_authentication = true;
2526 cfg.max_auth_gas = Some(250_000_000);
2528 cfg.transfer_receive_object_cost_base = Some(100);
2531 cfg.feature_flags.adjust_rewards_by_score = true;
2533 }
2534
2535 if chain != Chain::Mainnet {
2536 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2538
2539 cfg.feature_flags.calculate_validator_scores = true;
2541 cfg.scorer_version = Some(1);
2542 }
2543
2544 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
2546
2547 cfg.feature_flags.passkey_auth = true;
2549 }
2550 20 => {
2551 if chain != Chain::Testnet && chain != Chain::Mainnet {
2552 cfg.feature_flags
2554 .pass_calculated_validator_scores_to_advance_epoch = true;
2555 }
2556 }
2557 21 => {
2558 if chain != Chain::Testnet && chain != Chain::Mainnet {
2559 cfg.feature_flags.consensus_fast_commit_sync = true;
2561 }
2562 if chain != Chain::Mainnet {
2563 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2568 cfg.feature_flags
2571 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2572 cfg.feature_flags
2575 .separate_gas_price_feedback_mechanism_for_randomness = true;
2576 }
2577
2578 cfg.auth_context_digest_cost_base = Some(30);
2579 cfg.auth_context_tx_commands_cost_base = Some(30);
2580 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
2581 cfg.auth_context_tx_inputs_cost_base = Some(30);
2582 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
2583 cfg.auth_context_replace_cost_base = Some(30);
2584 cfg.auth_context_replace_cost_per_byte = Some(2);
2585
2586 if chain != Chain::Testnet && chain != Chain::Mainnet {
2587 cfg.max_auth_gas = Some(250_000);
2589 }
2590 }
2591
2592 _ => panic!("unsupported version {version:?}"),
2603 }
2604 }
2605 cfg
2606 }
2607
2608 pub fn verifier_config(&self, signing_limits: Option<(usize, usize)>) -> VerifierConfig {
2612 let (max_back_edges_per_function, max_back_edges_per_module) = if let Some((
2613 max_back_edges_per_function,
2614 max_back_edges_per_module,
2615 )) = signing_limits
2616 {
2617 (
2618 Some(max_back_edges_per_function),
2619 Some(max_back_edges_per_module),
2620 )
2621 } else {
2622 (None, None)
2623 };
2624
2625 VerifierConfig {
2626 max_loop_depth: Some(self.max_loop_depth() as usize),
2627 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2628 max_function_parameters: Some(self.max_function_parameters() as usize),
2629 max_basic_blocks: Some(self.max_basic_blocks() as usize),
2630 max_value_stack_size: self.max_value_stack_size() as usize,
2631 max_type_nodes: Some(self.max_type_nodes() as usize),
2632 max_push_size: Some(self.max_push_size() as usize),
2633 max_dependency_depth: Some(self.max_dependency_depth() as usize),
2634 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2635 max_function_definitions: Some(self.max_function_definitions() as usize),
2636 max_data_definitions: Some(self.max_struct_definitions() as usize),
2637 max_constant_vector_len: Some(self.max_move_vector_len()),
2638 max_back_edges_per_function,
2639 max_back_edges_per_module,
2640 max_basic_blocks_in_script: None,
2641 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
2645 max_variants_in_enum: self.max_move_enum_variants_as_option(),
2646 }
2647 }
2648
2649 pub fn apply_overrides_for_testing(
2654 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
2655 ) -> OverrideGuard {
2656 CONFIG_OVERRIDE.with(|ovr| {
2657 let mut cur = ovr.borrow_mut();
2658 assert!(cur.is_none(), "config override already present");
2659 *cur = Some(Box::new(override_fn));
2660 OverrideGuard
2661 })
2662 }
2663}
2664
2665impl ProtocolConfig {
2670 pub fn set_zklogin_auth_for_testing(&mut self, val: bool) {
2671 self.feature_flags.zklogin_auth = val
2672 }
2673 pub fn set_enable_jwk_consensus_updates_for_testing(&mut self, val: bool) {
2674 self.feature_flags.enable_jwk_consensus_updates = val
2675 }
2676
2677 pub fn set_accept_zklogin_in_multisig_for_testing(&mut self, val: bool) {
2678 self.feature_flags.accept_zklogin_in_multisig = val
2679 }
2680
2681 pub fn set_per_object_congestion_control_mode_for_testing(
2682 &mut self,
2683 val: PerObjectCongestionControlMode,
2684 ) {
2685 self.feature_flags.per_object_congestion_control_mode = val;
2686 }
2687
2688 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
2689 self.feature_flags.consensus_choice = val;
2690 }
2691
2692 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
2693 self.feature_flags.consensus_network = val;
2694 }
2695
2696 pub fn set_zklogin_max_epoch_upper_bound_delta_for_testing(&mut self, val: Option<u64>) {
2697 self.feature_flags.zklogin_max_epoch_upper_bound_delta = val
2698 }
2699
2700 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
2701 self.feature_flags.passkey_auth = val
2702 }
2703
2704 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
2705 self.feature_flags
2706 .disallow_new_modules_in_deps_only_packages = val;
2707 }
2708
2709 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
2710 self.feature_flags.consensus_round_prober = val;
2711 }
2712
2713 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
2714 self.feature_flags
2715 .consensus_distributed_vote_scoring_strategy = val;
2716 }
2717
2718 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
2719 self.consensus_gc_depth = Some(val);
2720 }
2721
2722 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
2723 self.feature_flags.consensus_linearize_subdag_v2 = val;
2724 }
2725
2726 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
2727 self.feature_flags
2728 .consensus_round_prober_probe_accepted_rounds = val;
2729 }
2730
2731 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
2732 self.feature_flags.accept_passkey_in_multisig = val;
2733 }
2734
2735 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
2736 self.feature_flags.consensus_smart_ancestor_selection = val;
2737 }
2738
2739 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
2740 self.feature_flags.consensus_batched_block_sync = val;
2741 }
2742
2743 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
2744 self.feature_flags
2745 .congestion_control_min_free_execution_slot = val;
2746 }
2747
2748 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
2749 self.feature_flags
2750 .congestion_control_gas_price_feedback_mechanism = val;
2751 }
2752
2753 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
2754 self.feature_flags.select_committee_from_eligible_validators = val;
2755 }
2756
2757 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
2758 self.feature_flags.track_non_committee_eligible_validators = val;
2759 }
2760
2761 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
2762 self.feature_flags
2763 .select_committee_supporting_next_epoch_version = val;
2764 }
2765
2766 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
2767 &mut self,
2768 val: bool,
2769 ) {
2770 self.feature_flags
2771 .consensus_median_timestamp_with_checkpoint_enforcement = val;
2772 }
2773
2774 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
2775 &mut self,
2776 val: bool,
2777 ) {
2778 self.feature_flags
2779 .consensus_commit_transactions_only_for_traversed_headers = val;
2780 }
2781
2782 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
2783 &mut self,
2784 val: bool,
2785 ) {
2786 self.feature_flags
2787 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
2788 }
2789
2790 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
2791 &mut self,
2792 val: bool,
2793 ) {
2794 self.feature_flags
2795 .separate_gas_price_feedback_mechanism_for_randomness = val;
2796 }
2797
2798 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
2799 self.feature_flags.metadata_in_module_bytes = val;
2800 }
2801
2802 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
2803 self.feature_flags.publish_package_metadata = val;
2804 }
2805
2806 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
2807 self.feature_flags.enable_move_authentication = val;
2808 }
2809 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
2810 self.feature_flags.consensus_fast_commit_sync = val;
2811 }
2812}
2813
2814type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
2815
2816thread_local! {
2817 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
2818}
2819
2820#[must_use]
2821pub struct OverrideGuard;
2822
2823impl Drop for OverrideGuard {
2824 fn drop(&mut self) {
2825 info!("restoring override fn");
2826 CONFIG_OVERRIDE.with(|ovr| {
2827 *ovr.borrow_mut() = None;
2828 });
2829 }
2830}
2831
2832#[derive(PartialEq, Eq)]
2836pub enum LimitThresholdCrossed {
2837 None,
2838 Soft(u128, u128),
2839 Hard(u128, u128),
2840}
2841
2842pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
2845 x: T,
2846 soft_limit: U,
2847 hard_limit: V,
2848) -> LimitThresholdCrossed {
2849 let x: V = x.into();
2850 let soft_limit: V = soft_limit.into();
2851
2852 debug_assert!(soft_limit <= hard_limit);
2853
2854 if x >= hard_limit {
2857 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
2858 } else if x < soft_limit {
2859 LimitThresholdCrossed::None
2860 } else {
2861 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
2862 }
2863}
2864
2865#[macro_export]
2866macro_rules! check_limit {
2867 ($x:expr, $hard:expr) => {
2868 check_limit!($x, $hard, $hard)
2869 };
2870 ($x:expr, $soft:expr, $hard:expr) => {
2871 check_limit_in_range($x as u64, $soft, $hard)
2872 };
2873}
2874
2875#[macro_export]
2879macro_rules! check_limit_by_meter {
2880 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
2881 let (h, metered_str) = if $is_metered {
2883 ($metered_limit, "metered")
2884 } else {
2885 ($unmetered_hard_limit, "unmetered")
2887 };
2888 use iota_protocol_config::check_limit_in_range;
2889 let result = check_limit_in_range($x as u64, $metered_limit, h);
2890 match result {
2891 LimitThresholdCrossed::None => {}
2892 LimitThresholdCrossed::Soft(_, _) => {
2893 $metric.with_label_values(&[metered_str, "soft"]).inc();
2894 }
2895 LimitThresholdCrossed::Hard(_, _) => {
2896 $metric.with_label_values(&[metered_str, "hard"]).inc();
2897 }
2898 };
2899 result
2900 }};
2901}
2902
2903#[cfg(all(test, not(msim)))]
2904mod test {
2905 use insta::assert_yaml_snapshot;
2906
2907 use super::*;
2908
2909 #[test]
2910 fn snapshot_tests() {
2911 println!("\n============================================================================");
2912 println!("! !");
2913 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
2914 println!("! !");
2915 println!("============================================================================\n");
2916 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
2917 let chain_str = match chain_id {
2922 Chain::Unknown => "".to_string(),
2923 _ => format!("{chain_id:?}_"),
2924 };
2925 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
2926 let cur = ProtocolVersion::new(i);
2927 assert_yaml_snapshot!(
2928 format!("{}version_{}", chain_str, cur.as_u64()),
2929 ProtocolConfig::get_for_version(cur, *chain_id)
2930 );
2931 }
2932 }
2933 }
2934
2935 #[test]
2936 fn test_getters() {
2937 let prot: ProtocolConfig =
2938 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2939 assert_eq!(
2940 prot.max_arguments(),
2941 prot.max_arguments_as_option().unwrap()
2942 );
2943 }
2944
2945 #[test]
2946 fn test_setters() {
2947 let mut prot: ProtocolConfig =
2948 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2949 prot.set_max_arguments_for_testing(123);
2950 assert_eq!(prot.max_arguments(), 123);
2951
2952 prot.set_max_arguments_from_str_for_testing("321".to_string());
2953 assert_eq!(prot.max_arguments(), 321);
2954
2955 prot.disable_max_arguments_for_testing();
2956 assert_eq!(prot.max_arguments_as_option(), None);
2957
2958 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
2959 assert_eq!(prot.max_arguments(), 456);
2960 }
2961
2962 #[test]
2963 #[should_panic(expected = "unsupported version")]
2964 fn max_version_test() {
2965 let _ = ProtocolConfig::get_for_version_impl(
2968 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
2969 Chain::Unknown,
2970 );
2971 }
2972
2973 #[test]
2974 fn lookup_by_string_test() {
2975 let prot: ProtocolConfig =
2976 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2977 assert!(prot.lookup_attr("some random string".to_string()).is_none());
2979
2980 assert!(
2981 prot.lookup_attr("max_arguments".to_string())
2982 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
2983 );
2984
2985 assert!(
2987 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2988 .is_none()
2989 );
2990 assert!(
2991 prot.attr_map()
2992 .get("poseidon_bn254_cost_base")
2993 .unwrap()
2994 .is_none()
2995 );
2996
2997 let prot: ProtocolConfig =
2999 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3000
3001 assert!(
3002 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3003 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3004 );
3005 assert!(
3006 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
3007 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3008 );
3009
3010 let prot: ProtocolConfig =
3012 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3013 assert!(
3015 prot.feature_flags
3016 .lookup_attr("some random string".to_owned())
3017 .is_none()
3018 );
3019 assert!(
3020 !prot
3021 .feature_flags
3022 .attr_map()
3023 .contains_key("some random string")
3024 );
3025
3026 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
3028 assert!(
3029 prot.feature_flags
3030 .attr_map()
3031 .get("enable_poseidon")
3032 .unwrap()
3033 == &false
3034 );
3035 let prot: ProtocolConfig =
3036 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3037 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
3039 assert!(
3040 prot.feature_flags
3041 .attr_map()
3042 .get("enable_poseidon")
3043 .unwrap()
3044 == &true
3045 );
3046 }
3047
3048 #[test]
3049 fn limit_range_fn_test() {
3050 let low = 100u32;
3051 let high = 10000u64;
3052
3053 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
3054 assert!(matches!(
3055 check_limit!(255u16, low, high),
3056 LimitThresholdCrossed::Soft(255u128, 100)
3057 ));
3058 assert!(matches!(
3065 check_limit!(2550000u64, low, high),
3066 LimitThresholdCrossed::Hard(2550000, 10000)
3067 ));
3068
3069 assert!(matches!(
3070 check_limit!(2550000u64, high, high),
3071 LimitThresholdCrossed::Hard(2550000, 10000)
3072 ));
3073
3074 assert!(matches!(
3075 check_limit!(1u8, high),
3076 LimitThresholdCrossed::None
3077 ));
3078
3079 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
3080
3081 assert!(matches!(
3082 check_limit!(2550000u64, high),
3083 LimitThresholdCrossed::Hard(2550000, 10000)
3084 ));
3085 }
3086}