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 = 20;
23
24#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
117pub struct ProtocolVersion(u64);
118
119impl ProtocolVersion {
120 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
126
127 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
128
129 #[cfg(not(msim))]
130 const MAX_ALLOWED: Self = Self::MAX;
131
132 #[cfg(msim)]
135 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
136
137 pub fn new(v: u64) -> Self {
138 Self(v)
139 }
140
141 pub const fn as_u64(&self) -> u64 {
142 self.0
143 }
144
145 pub fn max() -> Self {
148 Self::MAX
149 }
150}
151
152impl From<u64> for ProtocolVersion {
153 fn from(v: u64) -> Self {
154 Self::new(v)
155 }
156}
157
158impl std::ops::Sub<u64> for ProtocolVersion {
159 type Output = Self;
160 fn sub(self, rhs: u64) -> Self::Output {
161 Self::new(self.0 - rhs)
162 }
163}
164
165impl std::ops::Add<u64> for ProtocolVersion {
166 type Output = Self;
167 fn add(self, rhs: u64) -> Self::Output {
168 Self::new(self.0 + rhs)
169 }
170}
171
172#[derive(
173 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
174)]
175pub enum Chain {
176 Mainnet,
177 Testnet,
178 #[default]
179 Unknown,
180}
181
182impl Chain {
183 pub fn as_str(self) -> &'static str {
184 match self {
185 Chain::Mainnet => "mainnet",
186 Chain::Testnet => "testnet",
187 Chain::Unknown => "unknown",
188 }
189 }
190}
191
192pub struct Error(pub String);
193
194#[derive(Default, Clone, Serialize, Deserialize, Debug, ProtocolConfigFeatureFlagsGetters)]
198struct FeatureFlags {
199 #[serde(skip_serializing_if = "is_true")]
205 disable_invariant_violation_check_in_swap_loc: bool,
206
207 #[serde(skip_serializing_if = "is_true")]
210 no_extraneous_module_bytes: bool,
211
212 #[serde(skip_serializing_if = "is_false")]
214 zklogin_auth: bool,
215
216 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
218 consensus_transaction_ordering: ConsensusTransactionOrdering,
219
220 #[serde(skip_serializing_if = "is_false")]
221 enable_jwk_consensus_updates: bool,
222
223 #[serde(skip_serializing_if = "is_false")]
225 accept_zklogin_in_multisig: bool,
226
227 #[serde(skip_serializing_if = "is_true")]
230 hardened_otw_check: bool,
231
232 #[serde(skip_serializing_if = "is_false")]
234 enable_poseidon: bool,
235
236 #[serde(skip_serializing_if = "is_false")]
238 enable_group_ops_native_function_msm: bool,
239
240 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
242 per_object_congestion_control_mode: PerObjectCongestionControlMode,
243
244 #[serde(skip_serializing_if = "ConsensusChoice::is_mysticeti")]
246 consensus_choice: ConsensusChoice,
247
248 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
250 consensus_network: ConsensusNetwork,
251
252 #[serde(skip_serializing_if = "Option::is_none")]
254 zklogin_max_epoch_upper_bound_delta: Option<u64>,
255
256 #[serde(skip_serializing_if = "is_false")]
258 enable_vdf: bool,
259
260 #[serde(skip_serializing_if = "is_false")]
262 passkey_auth: bool,
263
264 #[serde(skip_serializing_if = "is_true")]
267 rethrow_serialization_type_layout_errors: bool,
268
269 #[serde(skip_serializing_if = "is_false")]
271 relocate_event_module: bool,
272
273 #[serde(skip_serializing_if = "is_false")]
275 protocol_defined_base_fee: bool,
276
277 #[serde(skip_serializing_if = "is_false")]
279 uncompressed_g1_group_elements: bool,
280
281 #[serde(skip_serializing_if = "is_false")]
283 disallow_new_modules_in_deps_only_packages: bool,
284
285 #[serde(skip_serializing_if = "is_false")]
287 native_charging_v2: bool,
288
289 #[serde(skip_serializing_if = "is_false")]
291 convert_type_argument_error: bool,
292
293 #[serde(skip_serializing_if = "is_false")]
295 consensus_round_prober: bool,
296
297 #[serde(skip_serializing_if = "is_false")]
299 consensus_distributed_vote_scoring_strategy: bool,
300
301 #[serde(skip_serializing_if = "is_false")]
305 consensus_linearize_subdag_v2: bool,
306
307 #[serde(skip_serializing_if = "is_false")]
309 variant_nodes: bool,
310
311 #[serde(skip_serializing_if = "is_false")]
313 consensus_smart_ancestor_selection: bool,
314
315 #[serde(skip_serializing_if = "is_false")]
317 consensus_round_prober_probe_accepted_rounds: bool,
318
319 #[serde(skip_serializing_if = "is_false")]
321 consensus_zstd_compression: bool,
322
323 #[serde(skip_serializing_if = "is_false")]
326 congestion_control_min_free_execution_slot: bool,
327
328 #[serde(skip_serializing_if = "is_false")]
330 accept_passkey_in_multisig: bool,
331
332 #[serde(skip_serializing_if = "is_false")]
334 consensus_batched_block_sync: bool,
335
336 #[serde(skip_serializing_if = "is_false")]
339 congestion_control_gas_price_feedback_mechanism: bool,
340
341 #[serde(skip_serializing_if = "is_false")]
343 validate_identifier_inputs: bool,
344
345 #[serde(skip_serializing_if = "is_false")]
348 minimize_child_object_mutations: bool,
349
350 #[serde(skip_serializing_if = "is_false")]
352 dependency_linkage_error: bool,
353
354 #[serde(skip_serializing_if = "is_false")]
356 additional_multisig_checks: bool,
357
358 #[serde(skip_serializing_if = "is_false")]
361 normalize_ptb_arguments: bool,
362
363 #[serde(skip_serializing_if = "is_false")]
367 select_committee_from_eligible_validators: bool,
368
369 #[serde(skip_serializing_if = "is_false")]
376 track_non_committee_eligible_validators: bool,
377
378 #[serde(skip_serializing_if = "is_false")]
384 select_committee_supporting_next_epoch_version: bool,
385
386 #[serde(skip_serializing_if = "is_false")]
390 consensus_median_timestamp_with_checkpoint_enforcement: bool,
391
392 #[serde(skip_serializing_if = "is_false")]
394 consensus_commit_transactions_only_for_traversed_headers: bool,
395
396 #[serde(skip_serializing_if = "is_false")]
398 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
399
400 #[serde(skip_serializing_if = "is_false")]
403 separate_gas_price_feedback_mechanism_for_randomness: bool,
404
405 #[serde(skip_serializing_if = "is_false")]
408 metadata_in_module_bytes: bool,
409
410 #[serde(skip_serializing_if = "is_false")]
412 publish_package_metadata: bool,
413
414 #[serde(skip_serializing_if = "is_false")]
416 enable_move_authentication: bool,
417
418 #[serde(skip_serializing_if = "is_false")]
420 pass_validator_scores_to_advance_epoch: bool,
421
422 #[serde(skip_serializing_if = "is_false")]
424 calculate_validator_scores: bool,
425
426 #[serde(skip_serializing_if = "is_false")]
428 adjust_rewards_by_score: bool,
429
430 #[serde(skip_serializing_if = "is_false")]
433 pass_calculated_validator_scores_to_advance_epoch: bool,
434}
435
436fn is_true(b: &bool) -> bool {
437 *b
438}
439
440fn is_false(b: &bool) -> bool {
441 !b
442}
443
444#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
446pub enum ConsensusTransactionOrdering {
447 #[default]
450 None,
451 ByGasPrice,
453}
454
455impl ConsensusTransactionOrdering {
456 pub fn is_none(&self) -> bool {
457 matches!(self, ConsensusTransactionOrdering::None)
458 }
459}
460
461#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
463pub enum PerObjectCongestionControlMode {
464 #[default]
465 None, TotalGasBudget, TotalTxCount, }
469
470impl PerObjectCongestionControlMode {
471 pub fn is_none(&self) -> bool {
472 matches!(self, PerObjectCongestionControlMode::None)
473 }
474}
475
476#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
478pub enum ConsensusChoice {
479 #[default]
480 Mysticeti,
481 Starfish,
482}
483
484impl ConsensusChoice {
485 pub fn is_mysticeti(&self) -> bool {
486 matches!(self, ConsensusChoice::Mysticeti)
487 }
488 pub fn is_starfish(&self) -> bool {
489 matches!(self, ConsensusChoice::Starfish)
490 }
491}
492
493#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
495pub enum ConsensusNetwork {
496 #[default]
497 Tonic,
498}
499
500impl ConsensusNetwork {
501 pub fn is_tonic(&self) -> bool {
502 matches!(self, ConsensusNetwork::Tonic)
503 }
504}
505
506#[skip_serializing_none]
540#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
541pub struct ProtocolConfig {
542 pub version: ProtocolVersion,
543
544 feature_flags: FeatureFlags,
545
546 max_tx_size_bytes: Option<u64>,
551
552 max_input_objects: Option<u64>,
555
556 max_size_written_objects: Option<u64>,
561 max_size_written_objects_system_tx: Option<u64>,
565
566 max_serialized_tx_effects_size_bytes: Option<u64>,
568
569 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
571
572 max_gas_payment_objects: Option<u32>,
574
575 max_modules_in_publish: Option<u32>,
577
578 max_package_dependencies: Option<u32>,
580
581 max_arguments: Option<u32>,
584
585 max_type_arguments: Option<u32>,
587
588 max_type_argument_depth: Option<u32>,
590
591 max_pure_argument_size: Option<u32>,
593
594 max_programmable_tx_commands: Option<u32>,
596
597 move_binary_format_version: Option<u32>,
603 min_move_binary_format_version: Option<u32>,
604
605 binary_module_handles: Option<u16>,
607 binary_struct_handles: Option<u16>,
608 binary_function_handles: Option<u16>,
609 binary_function_instantiations: Option<u16>,
610 binary_signatures: Option<u16>,
611 binary_constant_pool: Option<u16>,
612 binary_identifiers: Option<u16>,
613 binary_address_identifiers: Option<u16>,
614 binary_struct_defs: Option<u16>,
615 binary_struct_def_instantiations: Option<u16>,
616 binary_function_defs: Option<u16>,
617 binary_field_handles: Option<u16>,
618 binary_field_instantiations: Option<u16>,
619 binary_friend_decls: Option<u16>,
620 binary_enum_defs: Option<u16>,
621 binary_enum_def_instantiations: Option<u16>,
622 binary_variant_handles: Option<u16>,
623 binary_variant_instantiation_handles: Option<u16>,
624
625 max_move_object_size: Option<u64>,
628
629 max_move_package_size: Option<u64>,
634
635 max_publish_or_upgrade_per_ptb: Option<u64>,
638
639 max_tx_gas: Option<u64>,
641
642 max_auth_gas: Option<u64>,
644
645 max_gas_price: Option<u64>,
648
649 max_gas_computation_bucket: Option<u64>,
652
653 gas_rounding_step: Option<u64>,
655
656 max_loop_depth: Option<u64>,
658
659 max_generic_instantiation_length: Option<u64>,
662
663 max_function_parameters: Option<u64>,
666
667 max_basic_blocks: Option<u64>,
670
671 max_value_stack_size: Option<u64>,
673
674 max_type_nodes: Option<u64>,
678
679 max_push_size: Option<u64>,
682
683 max_struct_definitions: Option<u64>,
686
687 max_function_definitions: Option<u64>,
690
691 max_fields_in_struct: Option<u64>,
694
695 max_dependency_depth: Option<u64>,
698
699 max_num_event_emit: Option<u64>,
702
703 max_num_new_move_object_ids: Option<u64>,
706
707 max_num_new_move_object_ids_system_tx: Option<u64>,
710
711 max_num_deleted_move_object_ids: Option<u64>,
714
715 max_num_deleted_move_object_ids_system_tx: Option<u64>,
718
719 max_num_transferred_move_object_ids: Option<u64>,
722
723 max_num_transferred_move_object_ids_system_tx: Option<u64>,
726
727 max_event_emit_size: Option<u64>,
729
730 max_event_emit_size_total: Option<u64>,
732
733 max_move_vector_len: Option<u64>,
736
737 max_move_identifier_len: Option<u64>,
740
741 max_move_value_depth: Option<u64>,
743
744 max_move_enum_variants: Option<u64>,
747
748 max_back_edges_per_function: Option<u64>,
751
752 max_back_edges_per_module: Option<u64>,
755
756 max_verifier_meter_ticks_per_function: Option<u64>,
759
760 max_meter_ticks_per_module: Option<u64>,
763
764 max_meter_ticks_per_package: Option<u64>,
767
768 object_runtime_max_num_cached_objects: Option<u64>,
775
776 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
779
780 object_runtime_max_num_store_entries: Option<u64>,
783
784 object_runtime_max_num_store_entries_system_tx: Option<u64>,
787
788 base_tx_cost_fixed: Option<u64>,
793
794 package_publish_cost_fixed: Option<u64>,
798
799 base_tx_cost_per_byte: Option<u64>,
803
804 package_publish_cost_per_byte: Option<u64>,
806
807 obj_access_cost_read_per_byte: Option<u64>,
809
810 obj_access_cost_mutate_per_byte: Option<u64>,
812
813 obj_access_cost_delete_per_byte: Option<u64>,
815
816 obj_access_cost_verify_per_byte: Option<u64>,
826
827 max_type_to_layout_nodes: Option<u64>,
829
830 max_ptb_value_size: Option<u64>,
832
833 gas_model_version: Option<u64>,
838
839 obj_data_cost_refundable: Option<u64>,
845
846 obj_metadata_cost_non_refundable: Option<u64>,
850
851 storage_rebate_rate: Option<u64>,
857
858 reward_slashing_rate: Option<u64>,
861
862 storage_gas_price: Option<u64>,
864
865 base_gas_price: Option<u64>,
867
868 validator_target_reward: Option<u64>,
870
871 max_transactions_per_checkpoint: Option<u64>,
878
879 max_checkpoint_size_bytes: Option<u64>,
883
884 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
890
891 address_from_bytes_cost_base: Option<u64>,
896 address_to_u256_cost_base: Option<u64>,
898 address_from_u256_cost_base: Option<u64>,
900
901 config_read_setting_impl_cost_base: Option<u64>,
906 config_read_setting_impl_cost_per_byte: Option<u64>,
907
908 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
912 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
913 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
914 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
915 dynamic_field_add_child_object_cost_base: Option<u64>,
918 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
919 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
920 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
921 dynamic_field_borrow_child_object_cost_base: Option<u64>,
924 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
925 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
926 dynamic_field_remove_child_object_cost_base: Option<u64>,
929 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
930 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
931 dynamic_field_has_child_object_cost_base: Option<u64>,
934 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
937 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
938 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
939
940 event_emit_cost_base: Option<u64>,
943 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
944 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
945 event_emit_output_cost_per_byte: Option<u64>,
946
947 object_borrow_uid_cost_base: Option<u64>,
950 object_delete_impl_cost_base: Option<u64>,
952 object_record_new_uid_cost_base: Option<u64>,
954
955 transfer_transfer_internal_cost_base: Option<u64>,
958 transfer_freeze_object_cost_base: Option<u64>,
960 transfer_share_object_cost_base: Option<u64>,
962 transfer_receive_object_cost_base: Option<u64>,
965
966 tx_context_derive_id_cost_base: Option<u64>,
969
970 types_is_one_time_witness_cost_base: Option<u64>,
973 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
974 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
975
976 validator_validate_metadata_cost_base: Option<u64>,
979 validator_validate_metadata_data_cost_per_byte: Option<u64>,
980
981 crypto_invalid_arguments_cost: Option<u64>,
983 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
985 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
986 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
987
988 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
990 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
991 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
992
993 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
995 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
996 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
997 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
998 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
999 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1000
1001 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1003
1004 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1006 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1007 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1008 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1009 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1010 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1011
1012 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1014 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1015 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1016 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1017 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1018 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1019
1020 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1022 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1023 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1024 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1025 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1026 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1027
1028 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1030 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1031 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1032
1033 ed25519_ed25519_verify_cost_base: Option<u64>,
1035 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1036 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1037
1038 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1040 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1041
1042 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1044 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1045 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1046 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1047 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1048
1049 hash_blake2b256_cost_base: Option<u64>,
1051 hash_blake2b256_data_cost_per_byte: Option<u64>,
1052 hash_blake2b256_data_cost_per_block: Option<u64>,
1053
1054 hash_keccak256_cost_base: Option<u64>,
1056 hash_keccak256_data_cost_per_byte: Option<u64>,
1057 hash_keccak256_data_cost_per_block: Option<u64>,
1058
1059 poseidon_bn254_cost_base: Option<u64>,
1061 poseidon_bn254_cost_per_block: Option<u64>,
1062
1063 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1065 group_ops_bls12381_decode_g1_cost: Option<u64>,
1066 group_ops_bls12381_decode_g2_cost: Option<u64>,
1067 group_ops_bls12381_decode_gt_cost: Option<u64>,
1068 group_ops_bls12381_scalar_add_cost: Option<u64>,
1069 group_ops_bls12381_g1_add_cost: Option<u64>,
1070 group_ops_bls12381_g2_add_cost: Option<u64>,
1071 group_ops_bls12381_gt_add_cost: Option<u64>,
1072 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1073 group_ops_bls12381_g1_sub_cost: Option<u64>,
1074 group_ops_bls12381_g2_sub_cost: Option<u64>,
1075 group_ops_bls12381_gt_sub_cost: Option<u64>,
1076 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1077 group_ops_bls12381_g1_mul_cost: Option<u64>,
1078 group_ops_bls12381_g2_mul_cost: Option<u64>,
1079 group_ops_bls12381_gt_mul_cost: Option<u64>,
1080 group_ops_bls12381_scalar_div_cost: Option<u64>,
1081 group_ops_bls12381_g1_div_cost: Option<u64>,
1082 group_ops_bls12381_g2_div_cost: Option<u64>,
1083 group_ops_bls12381_gt_div_cost: Option<u64>,
1084 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1085 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1086 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1087 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1088 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1089 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1090 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1091 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1092 group_ops_bls12381_msm_max_len: Option<u32>,
1093 group_ops_bls12381_pairing_cost: Option<u64>,
1094 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1095 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1096 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1097 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1098 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1099
1100 hmac_hmac_sha3_256_cost_base: Option<u64>,
1102 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1103 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1104
1105 check_zklogin_id_cost_base: Option<u64>,
1107 check_zklogin_issuer_cost_base: Option<u64>,
1109
1110 vdf_verify_vdf_cost: Option<u64>,
1111 vdf_hash_to_input_cost: Option<u64>,
1112
1113 bcs_per_byte_serialized_cost: Option<u64>,
1115 bcs_legacy_min_output_size_cost: Option<u64>,
1116 bcs_failure_cost: Option<u64>,
1117
1118 hash_sha2_256_base_cost: Option<u64>,
1119 hash_sha2_256_per_byte_cost: Option<u64>,
1120 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1121 hash_sha3_256_base_cost: Option<u64>,
1122 hash_sha3_256_per_byte_cost: Option<u64>,
1123 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1124 type_name_get_base_cost: Option<u64>,
1125 type_name_get_per_byte_cost: Option<u64>,
1126
1127 string_check_utf8_base_cost: Option<u64>,
1128 string_check_utf8_per_byte_cost: Option<u64>,
1129 string_is_char_boundary_base_cost: Option<u64>,
1130 string_sub_string_base_cost: Option<u64>,
1131 string_sub_string_per_byte_cost: Option<u64>,
1132 string_index_of_base_cost: Option<u64>,
1133 string_index_of_per_byte_pattern_cost: Option<u64>,
1134 string_index_of_per_byte_searched_cost: Option<u64>,
1135
1136 vector_empty_base_cost: Option<u64>,
1137 vector_length_base_cost: Option<u64>,
1138 vector_push_back_base_cost: Option<u64>,
1139 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1140 vector_borrow_base_cost: Option<u64>,
1141 vector_pop_back_base_cost: Option<u64>,
1142 vector_destroy_empty_base_cost: Option<u64>,
1143 vector_swap_base_cost: Option<u64>,
1144 debug_print_base_cost: Option<u64>,
1145 debug_print_stack_trace_base_cost: Option<u64>,
1146
1147 execution_version: Option<u64>,
1149
1150 consensus_bad_nodes_stake_threshold: Option<u64>,
1154
1155 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1156 max_age_of_jwk_in_epochs: Option<u64>,
1160
1161 random_beacon_reduction_allowed_delta: Option<u16>,
1165
1166 random_beacon_reduction_lower_bound: Option<u32>,
1169
1170 random_beacon_dkg_timeout_round: Option<u32>,
1173
1174 random_beacon_min_round_interval_ms: Option<u64>,
1176
1177 random_beacon_dkg_version: Option<u64>,
1181
1182 consensus_max_transaction_size_bytes: Option<u64>,
1187 consensus_max_transactions_in_block_bytes: Option<u64>,
1189 consensus_max_num_transactions_in_block: Option<u64>,
1191
1192 max_deferral_rounds_for_congestion_control: Option<u64>,
1196
1197 min_checkpoint_interval_ms: Option<u64>,
1199
1200 checkpoint_summary_version_specific_data: Option<u64>,
1202
1203 max_soft_bundle_size: Option<u64>,
1206
1207 bridge_should_try_to_finalize_committee: Option<bool>,
1212
1213 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1219
1220 max_committee_members_count: Option<u64>,
1224
1225 consensus_gc_depth: Option<u32>,
1228
1229 consensus_max_acknowledgments_per_block: Option<u32>,
1235
1236 max_congestion_limit_overshoot_per_commit: Option<u64>,
1241
1242 scorer_version: Option<u16>,
1249}
1250
1251impl ProtocolConfig {
1253 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1266 self.feature_flags
1267 .disable_invariant_violation_check_in_swap_loc
1268 }
1269
1270 pub fn no_extraneous_module_bytes(&self) -> bool {
1271 self.feature_flags.no_extraneous_module_bytes
1272 }
1273
1274 pub fn zklogin_auth(&self) -> bool {
1275 self.feature_flags.zklogin_auth
1276 }
1277
1278 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1279 self.feature_flags.consensus_transaction_ordering
1280 }
1281
1282 pub fn enable_jwk_consensus_updates(&self) -> bool {
1283 self.feature_flags.enable_jwk_consensus_updates
1284 }
1285
1286 pub fn create_authenticator_state_in_genesis(&self) -> bool {
1288 self.enable_jwk_consensus_updates()
1289 }
1290
1291 pub fn dkg_version(&self) -> u64 {
1292 self.random_beacon_dkg_version.unwrap_or(1)
1294 }
1295
1296 pub fn accept_zklogin_in_multisig(&self) -> bool {
1297 self.feature_flags.accept_zklogin_in_multisig
1298 }
1299
1300 pub fn zklogin_max_epoch_upper_bound_delta(&self) -> Option<u64> {
1301 self.feature_flags.zklogin_max_epoch_upper_bound_delta
1302 }
1303
1304 pub fn hardened_otw_check(&self) -> bool {
1305 self.feature_flags.hardened_otw_check
1306 }
1307
1308 pub fn enable_poseidon(&self) -> bool {
1309 self.feature_flags.enable_poseidon
1310 }
1311
1312 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1313 self.feature_flags.enable_group_ops_native_function_msm
1314 }
1315
1316 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1317 self.feature_flags.per_object_congestion_control_mode
1318 }
1319
1320 pub fn consensus_choice(&self) -> ConsensusChoice {
1321 self.feature_flags.consensus_choice
1322 }
1323
1324 pub fn consensus_network(&self) -> ConsensusNetwork {
1325 self.feature_flags.consensus_network
1326 }
1327
1328 pub fn enable_vdf(&self) -> bool {
1329 self.feature_flags.enable_vdf
1330 }
1331
1332 pub fn passkey_auth(&self) -> bool {
1333 self.feature_flags.passkey_auth
1334 }
1335
1336 pub fn max_transaction_size_bytes(&self) -> u64 {
1337 self.consensus_max_transaction_size_bytes
1339 .unwrap_or(256 * 1024)
1340 }
1341
1342 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1343 if cfg!(msim) {
1344 256 * 1024
1345 } else {
1346 self.consensus_max_transactions_in_block_bytes
1347 .unwrap_or(512 * 1024)
1348 }
1349 }
1350
1351 pub fn max_num_transactions_in_block(&self) -> u64 {
1352 if cfg!(msim) {
1353 8
1354 } else {
1355 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1356 }
1357 }
1358
1359 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1360 self.feature_flags.rethrow_serialization_type_layout_errors
1361 }
1362
1363 pub fn relocate_event_module(&self) -> bool {
1364 self.feature_flags.relocate_event_module
1365 }
1366
1367 pub fn protocol_defined_base_fee(&self) -> bool {
1368 self.feature_flags.protocol_defined_base_fee
1369 }
1370
1371 pub fn uncompressed_g1_group_elements(&self) -> bool {
1372 self.feature_flags.uncompressed_g1_group_elements
1373 }
1374
1375 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1376 self.feature_flags
1377 .disallow_new_modules_in_deps_only_packages
1378 }
1379
1380 pub fn native_charging_v2(&self) -> bool {
1381 self.feature_flags.native_charging_v2
1382 }
1383
1384 pub fn consensus_round_prober(&self) -> bool {
1385 self.feature_flags.consensus_round_prober
1386 }
1387
1388 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1389 self.feature_flags
1390 .consensus_distributed_vote_scoring_strategy
1391 }
1392
1393 pub fn gc_depth(&self) -> u32 {
1394 if cfg!(msim) {
1395 min(5, self.consensus_gc_depth.unwrap_or(0))
1397 } else {
1398 self.consensus_gc_depth.unwrap_or(0)
1399 }
1400 }
1401
1402 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1403 let res = self.feature_flags.consensus_linearize_subdag_v2;
1404 assert!(
1405 !res || self.gc_depth() > 0,
1406 "The consensus linearize sub dag V2 requires GC to be enabled"
1407 );
1408 res
1409 }
1410
1411 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1412 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1413 }
1414
1415 pub fn variant_nodes(&self) -> bool {
1416 self.feature_flags.variant_nodes
1417 }
1418
1419 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1420 self.feature_flags.consensus_smart_ancestor_selection
1421 }
1422
1423 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1424 self.feature_flags
1425 .consensus_round_prober_probe_accepted_rounds
1426 }
1427
1428 pub fn consensus_zstd_compression(&self) -> bool {
1429 self.feature_flags.consensus_zstd_compression
1430 }
1431
1432 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1433 self.feature_flags
1434 .congestion_control_min_free_execution_slot
1435 }
1436
1437 pub fn accept_passkey_in_multisig(&self) -> bool {
1438 self.feature_flags.accept_passkey_in_multisig
1439 }
1440
1441 pub fn consensus_batched_block_sync(&self) -> bool {
1442 self.feature_flags.consensus_batched_block_sync
1443 }
1444
1445 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1448 self.feature_flags
1449 .congestion_control_gas_price_feedback_mechanism
1450 }
1451
1452 pub fn validate_identifier_inputs(&self) -> bool {
1453 self.feature_flags.validate_identifier_inputs
1454 }
1455
1456 pub fn minimize_child_object_mutations(&self) -> bool {
1457 self.feature_flags.minimize_child_object_mutations
1458 }
1459
1460 pub fn dependency_linkage_error(&self) -> bool {
1461 self.feature_flags.dependency_linkage_error
1462 }
1463
1464 pub fn additional_multisig_checks(&self) -> bool {
1465 self.feature_flags.additional_multisig_checks
1466 }
1467
1468 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1469 0
1472 }
1473
1474 pub fn normalize_ptb_arguments(&self) -> bool {
1475 self.feature_flags.normalize_ptb_arguments
1476 }
1477
1478 pub fn select_committee_from_eligible_validators(&self) -> bool {
1479 let res = self.feature_flags.select_committee_from_eligible_validators;
1480 assert!(
1481 !res || (self.protocol_defined_base_fee()
1482 && self.max_committee_members_count_as_option().is_some()),
1483 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1484 );
1485 res
1486 }
1487
1488 pub fn track_non_committee_eligible_validators(&self) -> bool {
1489 self.feature_flags.track_non_committee_eligible_validators
1490 }
1491
1492 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1493 let res = self
1494 .feature_flags
1495 .select_committee_supporting_next_epoch_version;
1496 assert!(
1497 !res || (self.track_non_committee_eligible_validators()
1498 && self.select_committee_from_eligible_validators()),
1499 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1500 );
1501 res
1502 }
1503
1504 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1505 let res = self
1506 .feature_flags
1507 .consensus_median_timestamp_with_checkpoint_enforcement;
1508 assert!(
1509 !res || self.gc_depth() > 0,
1510 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1511 );
1512 res
1513 }
1514
1515 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1516 self.feature_flags
1517 .consensus_commit_transactions_only_for_traversed_headers
1518 }
1519
1520 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1523 self.feature_flags
1524 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1525 }
1526
1527 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1530 self.feature_flags
1531 .separate_gas_price_feedback_mechanism_for_randomness
1532 }
1533
1534 pub fn metadata_in_module_bytes(&self) -> bool {
1535 self.feature_flags.metadata_in_module_bytes
1536 }
1537
1538 pub fn publish_package_metadata(&self) -> bool {
1539 self.feature_flags.publish_package_metadata
1540 }
1541
1542 pub fn enable_move_authentication(&self) -> bool {
1543 self.feature_flags.enable_move_authentication
1544 }
1545
1546 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1547 self.feature_flags.pass_validator_scores_to_advance_epoch
1548 }
1549
1550 pub fn calculate_validator_scores(&self) -> bool {
1551 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1552 assert!(
1553 !calculate_validator_scores || self.scorer_version.is_some(),
1554 "calculate_validator_scores requires scorer_version to be set"
1555 );
1556 calculate_validator_scores
1557 }
1558
1559 pub fn adjust_rewards_by_score(&self) -> bool {
1560 let adjust = self.feature_flags.adjust_rewards_by_score;
1561 assert!(
1562 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1563 "adjust_rewards_by_score requires scorer_version to be set"
1564 );
1565 adjust
1566 }
1567
1568 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1569 let pass = self
1570 .feature_flags
1571 .pass_calculated_validator_scores_to_advance_epoch;
1572 assert!(
1573 !pass
1574 || (self.pass_validator_scores_to_advance_epoch()
1575 && self.calculate_validator_scores()),
1576 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
1577 );
1578 pass
1579 }
1580}
1581
1582#[cfg(not(msim))]
1583static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1584
1585#[cfg(msim)]
1587thread_local! {
1588 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1589}
1590
1591impl ProtocolConfig {
1593 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1596 assert!(
1598 version >= ProtocolVersion::MIN,
1599 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1600 version,
1601 ProtocolVersion::MIN.0,
1602 );
1603 assert!(
1604 version <= ProtocolVersion::MAX_ALLOWED,
1605 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1606 version,
1607 ProtocolVersion::MAX_ALLOWED.0,
1608 );
1609
1610 let mut ret = Self::get_for_version_impl(version, chain);
1611 ret.version = version;
1612
1613 ret = CONFIG_OVERRIDE.with(|ovr| {
1614 if let Some(override_fn) = &*ovr.borrow() {
1615 warn!(
1616 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1617 );
1618 override_fn(version, ret)
1619 } else {
1620 ret
1621 }
1622 });
1623
1624 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1625 warn!(
1626 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1627 );
1628 let overrides: ProtocolConfigOptional =
1629 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1630 .expect("failed to parse ProtocolConfig override env variables");
1631 overrides.apply_to(&mut ret);
1632 }
1633
1634 ret
1635 }
1636
1637 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1640 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1641 let mut ret = Self::get_for_version_impl(version, chain);
1642 ret.version = version;
1643 Some(ret)
1644 } else {
1645 None
1646 }
1647 }
1648
1649 #[cfg(not(msim))]
1650 pub fn poison_get_for_min_version() {
1651 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1652 }
1653
1654 #[cfg(not(msim))]
1655 fn load_poison_get_for_min_version() -> bool {
1656 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1657 }
1658
1659 #[cfg(msim)]
1660 pub fn poison_get_for_min_version() {
1661 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1662 }
1663
1664 #[cfg(msim)]
1665 fn load_poison_get_for_min_version() -> bool {
1666 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1667 }
1668
1669 pub fn convert_type_argument_error(&self) -> bool {
1670 self.feature_flags.convert_type_argument_error
1671 }
1672
1673 pub fn get_for_min_version() -> Self {
1677 if Self::load_poison_get_for_min_version() {
1678 panic!("get_for_min_version called on validator");
1679 }
1680 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1681 }
1682
1683 #[expect(non_snake_case)]
1694 pub fn get_for_max_version_UNSAFE() -> Self {
1695 if Self::load_poison_get_for_min_version() {
1696 panic!("get_for_max_version_UNSAFE called on validator");
1697 }
1698 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1699 }
1700
1701 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1702 #[cfg(msim)]
1703 {
1704 if version > ProtocolVersion::MAX {
1706 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1707 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1708 return config;
1709 }
1710 }
1711
1712 let mut cfg = Self {
1716 version,
1717
1718 feature_flags: Default::default(),
1719
1720 max_tx_size_bytes: Some(128 * 1024),
1721 max_input_objects: Some(2048),
1724 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1725 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1726 max_gas_payment_objects: Some(256),
1727 max_modules_in_publish: Some(64),
1728 max_package_dependencies: Some(32),
1729 max_arguments: Some(512),
1730 max_type_arguments: Some(16),
1731 max_type_argument_depth: Some(16),
1732 max_pure_argument_size: Some(16 * 1024),
1733 max_programmable_tx_commands: Some(1024),
1734 move_binary_format_version: Some(7),
1735 min_move_binary_format_version: Some(6),
1736 binary_module_handles: Some(100),
1737 binary_struct_handles: Some(300),
1738 binary_function_handles: Some(1500),
1739 binary_function_instantiations: Some(750),
1740 binary_signatures: Some(1000),
1741 binary_constant_pool: Some(4000),
1742 binary_identifiers: Some(10000),
1743 binary_address_identifiers: Some(100),
1744 binary_struct_defs: Some(200),
1745 binary_struct_def_instantiations: Some(100),
1746 binary_function_defs: Some(1000),
1747 binary_field_handles: Some(500),
1748 binary_field_instantiations: Some(250),
1749 binary_friend_decls: Some(100),
1750 binary_enum_defs: None,
1751 binary_enum_def_instantiations: None,
1752 binary_variant_handles: None,
1753 binary_variant_instantiation_handles: None,
1754 max_move_object_size: Some(250 * 1024),
1755 max_move_package_size: Some(100 * 1024),
1756 max_publish_or_upgrade_per_ptb: Some(5),
1757 max_auth_gas: None,
1759 max_tx_gas: Some(50_000_000_000),
1761 max_gas_price: Some(100_000),
1762 max_gas_computation_bucket: Some(5_000_000),
1763 max_loop_depth: Some(5),
1764 max_generic_instantiation_length: Some(32),
1765 max_function_parameters: Some(128),
1766 max_basic_blocks: Some(1024),
1767 max_value_stack_size: Some(1024),
1768 max_type_nodes: Some(256),
1769 max_push_size: Some(10000),
1770 max_struct_definitions: Some(200),
1771 max_function_definitions: Some(1000),
1772 max_fields_in_struct: Some(32),
1773 max_dependency_depth: Some(100),
1774 max_num_event_emit: Some(1024),
1775 max_num_new_move_object_ids: Some(2048),
1776 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1777 max_num_deleted_move_object_ids: Some(2048),
1778 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1779 max_num_transferred_move_object_ids: Some(2048),
1780 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1781 max_event_emit_size: Some(250 * 1024),
1782 max_move_vector_len: Some(256 * 1024),
1783 max_type_to_layout_nodes: None,
1784 max_ptb_value_size: None,
1785
1786 max_back_edges_per_function: Some(10_000),
1787 max_back_edges_per_module: Some(10_000),
1788
1789 max_verifier_meter_ticks_per_function: Some(16_000_000),
1790
1791 max_meter_ticks_per_module: Some(16_000_000),
1792 max_meter_ticks_per_package: Some(16_000_000),
1793
1794 object_runtime_max_num_cached_objects: Some(1000),
1795 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
1796 object_runtime_max_num_store_entries: Some(1000),
1797 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
1798 base_tx_cost_fixed: Some(1_000),
1800 package_publish_cost_fixed: Some(1_000),
1801 base_tx_cost_per_byte: Some(0),
1802 package_publish_cost_per_byte: Some(80),
1803 obj_access_cost_read_per_byte: Some(15),
1804 obj_access_cost_mutate_per_byte: Some(40),
1805 obj_access_cost_delete_per_byte: Some(40),
1806 obj_access_cost_verify_per_byte: Some(200),
1807 obj_data_cost_refundable: Some(100),
1808 obj_metadata_cost_non_refundable: Some(50),
1809 gas_model_version: Some(1),
1810 storage_rebate_rate: Some(10000),
1811 reward_slashing_rate: Some(10000),
1813 storage_gas_price: Some(76),
1814 base_gas_price: None,
1815 validator_target_reward: Some(767_000 * 1_000_000_000),
1818 max_transactions_per_checkpoint: Some(10_000),
1819 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
1820
1821 buffer_stake_for_protocol_upgrade_bps: Some(5000),
1823
1824 address_from_bytes_cost_base: Some(52),
1828 address_to_u256_cost_base: Some(52),
1830 address_from_u256_cost_base: Some(52),
1832
1833 config_read_setting_impl_cost_base: Some(100),
1836 config_read_setting_impl_cost_per_byte: Some(40),
1837
1838 dynamic_field_hash_type_and_key_cost_base: Some(100),
1842 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
1843 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
1844 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
1845 dynamic_field_add_child_object_cost_base: Some(100),
1848 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
1849 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
1850 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
1851 dynamic_field_borrow_child_object_cost_base: Some(100),
1854 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
1855 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
1856 dynamic_field_remove_child_object_cost_base: Some(100),
1859 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
1860 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
1861 dynamic_field_has_child_object_cost_base: Some(100),
1864 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
1867 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
1868 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
1869
1870 event_emit_cost_base: Some(52),
1873 event_emit_value_size_derivation_cost_per_byte: Some(2),
1874 event_emit_tag_size_derivation_cost_per_byte: Some(5),
1875 event_emit_output_cost_per_byte: Some(10),
1876
1877 object_borrow_uid_cost_base: Some(52),
1880 object_delete_impl_cost_base: Some(52),
1882 object_record_new_uid_cost_base: Some(52),
1884
1885 transfer_transfer_internal_cost_base: Some(52),
1889 transfer_freeze_object_cost_base: Some(52),
1891 transfer_share_object_cost_base: Some(52),
1893 transfer_receive_object_cost_base: Some(52),
1894
1895 tx_context_derive_id_cost_base: Some(52),
1899
1900 types_is_one_time_witness_cost_base: Some(52),
1903 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
1904 types_is_one_time_witness_type_cost_per_byte: Some(2),
1905
1906 validator_validate_metadata_cost_base: Some(52),
1910 validator_validate_metadata_data_cost_per_byte: Some(2),
1911
1912 crypto_invalid_arguments_cost: Some(100),
1914 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
1916 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
1917 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
1918
1919 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
1921 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
1922 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
1923
1924 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
1926 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1927 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1928 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
1929 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1930 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
1931
1932 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
1934
1935 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
1937 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
1938 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
1939 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
1940 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
1941 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
1942
1943 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
1945 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1946 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1947 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
1948 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1949 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
1950
1951 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
1953 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
1954 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
1955 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
1956 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
1957 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
1958
1959 ecvrf_ecvrf_verify_cost_base: Some(52),
1961 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
1962 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
1963
1964 ed25519_ed25519_verify_cost_base: Some(52),
1966 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
1967 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
1968
1969 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
1971 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
1972
1973 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
1975 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
1976 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
1977 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
1978 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
1979
1980 hash_blake2b256_cost_base: Some(52),
1982 hash_blake2b256_data_cost_per_byte: Some(2),
1983 hash_blake2b256_data_cost_per_block: Some(2),
1984 hash_keccak256_cost_base: Some(52),
1986 hash_keccak256_data_cost_per_byte: Some(2),
1987 hash_keccak256_data_cost_per_block: Some(2),
1988
1989 poseidon_bn254_cost_base: None,
1990 poseidon_bn254_cost_per_block: None,
1991
1992 hmac_hmac_sha3_256_cost_base: Some(52),
1994 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
1995 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
1996
1997 group_ops_bls12381_decode_scalar_cost: Some(52),
1999 group_ops_bls12381_decode_g1_cost: Some(52),
2000 group_ops_bls12381_decode_g2_cost: Some(52),
2001 group_ops_bls12381_decode_gt_cost: Some(52),
2002 group_ops_bls12381_scalar_add_cost: Some(52),
2003 group_ops_bls12381_g1_add_cost: Some(52),
2004 group_ops_bls12381_g2_add_cost: Some(52),
2005 group_ops_bls12381_gt_add_cost: Some(52),
2006 group_ops_bls12381_scalar_sub_cost: Some(52),
2007 group_ops_bls12381_g1_sub_cost: Some(52),
2008 group_ops_bls12381_g2_sub_cost: Some(52),
2009 group_ops_bls12381_gt_sub_cost: Some(52),
2010 group_ops_bls12381_scalar_mul_cost: Some(52),
2011 group_ops_bls12381_g1_mul_cost: Some(52),
2012 group_ops_bls12381_g2_mul_cost: Some(52),
2013 group_ops_bls12381_gt_mul_cost: Some(52),
2014 group_ops_bls12381_scalar_div_cost: Some(52),
2015 group_ops_bls12381_g1_div_cost: Some(52),
2016 group_ops_bls12381_g2_div_cost: Some(52),
2017 group_ops_bls12381_gt_div_cost: Some(52),
2018 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2019 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2020 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2021 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2022 group_ops_bls12381_g1_msm_base_cost: Some(52),
2023 group_ops_bls12381_g2_msm_base_cost: Some(52),
2024 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2025 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2026 group_ops_bls12381_msm_max_len: Some(32),
2027 group_ops_bls12381_pairing_cost: Some(52),
2028 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2029 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2030 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2031 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2032 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2033
2034 check_zklogin_id_cost_base: Some(200),
2036 check_zklogin_issuer_cost_base: Some(200),
2038
2039 vdf_verify_vdf_cost: None,
2040 vdf_hash_to_input_cost: None,
2041
2042 bcs_per_byte_serialized_cost: Some(2),
2043 bcs_legacy_min_output_size_cost: Some(1),
2044 bcs_failure_cost: Some(52),
2045 hash_sha2_256_base_cost: Some(52),
2046 hash_sha2_256_per_byte_cost: Some(2),
2047 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2048 hash_sha3_256_base_cost: Some(52),
2049 hash_sha3_256_per_byte_cost: Some(2),
2050 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2051 type_name_get_base_cost: Some(52),
2052 type_name_get_per_byte_cost: Some(2),
2053 string_check_utf8_base_cost: Some(52),
2054 string_check_utf8_per_byte_cost: Some(2),
2055 string_is_char_boundary_base_cost: Some(52),
2056 string_sub_string_base_cost: Some(52),
2057 string_sub_string_per_byte_cost: Some(2),
2058 string_index_of_base_cost: Some(52),
2059 string_index_of_per_byte_pattern_cost: Some(2),
2060 string_index_of_per_byte_searched_cost: Some(2),
2061 vector_empty_base_cost: Some(52),
2062 vector_length_base_cost: Some(52),
2063 vector_push_back_base_cost: Some(52),
2064 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2065 vector_borrow_base_cost: Some(52),
2066 vector_pop_back_base_cost: Some(52),
2067 vector_destroy_empty_base_cost: Some(52),
2068 vector_swap_base_cost: Some(52),
2069 debug_print_base_cost: Some(52),
2070 debug_print_stack_trace_base_cost: Some(52),
2071
2072 max_size_written_objects: Some(5 * 1000 * 1000),
2073 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2076
2077 max_move_identifier_len: Some(128),
2079 max_move_value_depth: Some(128),
2080 max_move_enum_variants: None,
2081
2082 gas_rounding_step: Some(1_000),
2083
2084 execution_version: Some(1),
2085
2086 max_event_emit_size_total: Some(
2089 256 * 250 * 1024, ),
2091
2092 consensus_bad_nodes_stake_threshold: Some(20),
2099
2100 max_jwk_votes_per_validator_per_epoch: Some(240),
2102
2103 max_age_of_jwk_in_epochs: Some(1),
2104
2105 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2109
2110 random_beacon_reduction_allowed_delta: Some(800),
2111
2112 random_beacon_reduction_lower_bound: Some(1000),
2113 random_beacon_dkg_timeout_round: Some(3000),
2114 random_beacon_min_round_interval_ms: Some(500),
2115
2116 random_beacon_dkg_version: Some(1),
2117
2118 consensus_max_num_transactions_in_block: Some(512),
2122
2123 max_deferral_rounds_for_congestion_control: Some(10),
2124
2125 min_checkpoint_interval_ms: Some(200),
2126
2127 checkpoint_summary_version_specific_data: Some(1),
2128
2129 max_soft_bundle_size: Some(5),
2130
2131 bridge_should_try_to_finalize_committee: None,
2132
2133 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2134
2135 max_committee_members_count: None,
2136
2137 consensus_gc_depth: None,
2138
2139 consensus_max_acknowledgments_per_block: None,
2140
2141 max_congestion_limit_overshoot_per_commit: None,
2142
2143 scorer_version: None,
2144 };
2147
2148 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2149
2150 {
2152 cfg.feature_flags
2153 .disable_invariant_violation_check_in_swap_loc = true;
2154 cfg.feature_flags.no_extraneous_module_bytes = true;
2155 cfg.feature_flags.hardened_otw_check = true;
2156 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2157 }
2158
2159 {
2161 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2162 }
2163
2164 cfg.feature_flags.consensus_choice = ConsensusChoice::Mysticeti;
2166 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2168
2169 cfg.feature_flags.per_object_congestion_control_mode =
2170 PerObjectCongestionControlMode::TotalTxCount;
2171
2172 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2174
2175 if chain != Chain::Mainnet && chain != Chain::Testnet {
2177 cfg.feature_flags.enable_poseidon = true;
2178 cfg.poseidon_bn254_cost_base = Some(260);
2179 cfg.poseidon_bn254_cost_per_block = Some(10);
2180
2181 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2182
2183 cfg.feature_flags.enable_vdf = true;
2184 cfg.vdf_verify_vdf_cost = Some(1500);
2187 cfg.vdf_hash_to_input_cost = Some(100);
2188
2189 cfg.feature_flags.passkey_auth = true;
2190 }
2191
2192 for cur in 2..=version.0 {
2193 match cur {
2194 1 => unreachable!(),
2195 2 => {}
2197 3 => {
2198 cfg.feature_flags.relocate_event_module = true;
2199 }
2200 4 => {
2201 cfg.max_type_to_layout_nodes = Some(512);
2202 }
2203 5 => {
2204 cfg.feature_flags.protocol_defined_base_fee = true;
2205 cfg.base_gas_price = Some(1000);
2206
2207 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2208 cfg.feature_flags.convert_type_argument_error = true;
2209 cfg.feature_flags.native_charging_v2 = true;
2210
2211 if chain != Chain::Mainnet && chain != Chain::Testnet {
2212 cfg.feature_flags.uncompressed_g1_group_elements = true;
2213 }
2214
2215 cfg.gas_model_version = Some(2);
2216
2217 cfg.poseidon_bn254_cost_per_block = Some(388);
2218
2219 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2220 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2221 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2222 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2223 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2224 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2225 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2226 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2227
2228 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2230 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2231 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2232 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2233
2234 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2235 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2236 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2237 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2238 Some(8213);
2239 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2240 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2241 Some(9484);
2242
2243 cfg.hash_keccak256_cost_base = Some(10);
2244 cfg.hash_blake2b256_cost_base = Some(10);
2245
2246 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2248 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2249 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2250 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2251
2252 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2253 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2254 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2255 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2256
2257 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2258 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2259 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2260 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2261
2262 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2263 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2264 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2265 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2266
2267 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2268 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2269 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2270 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2271
2272 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2273 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2274
2275 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2276 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2277 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2278 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2279
2280 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2281 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2282 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2283 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2284 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2285
2286 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2287
2288 cfg.validator_validate_metadata_cost_base = Some(20000);
2289
2290 cfg.max_committee_members_count = Some(50);
2291 }
2292 6 => {
2293 cfg.max_ptb_value_size = Some(1024 * 1024);
2294 }
2295 7 => {
2296 }
2299 8 => {
2300 cfg.feature_flags.variant_nodes = true;
2301
2302 if chain != Chain::Mainnet {
2303 cfg.feature_flags.consensus_round_prober = true;
2305 cfg.feature_flags
2307 .consensus_distributed_vote_scoring_strategy = true;
2308 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2309 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2311 cfg.feature_flags
2313 .consensus_round_prober_probe_accepted_rounds = true;
2314 cfg.feature_flags.consensus_zstd_compression = true;
2316 cfg.consensus_gc_depth = Some(60);
2320 }
2321
2322 if chain != Chain::Testnet && chain != Chain::Mainnet {
2325 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2326 }
2327 }
2328 9 => {
2329 if chain != Chain::Mainnet {
2330 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2332 }
2333
2334 cfg.feature_flags.consensus_zstd_compression = true;
2336
2337 if chain != Chain::Testnet && chain != Chain::Mainnet {
2339 cfg.feature_flags.accept_passkey_in_multisig = true;
2340 }
2341
2342 cfg.bridge_should_try_to_finalize_committee = None;
2344 }
2345 10 => {
2346 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2349
2350 cfg.max_committee_members_count = Some(80);
2352
2353 cfg.feature_flags.consensus_round_prober = true;
2355 cfg.feature_flags
2357 .consensus_round_prober_probe_accepted_rounds = true;
2358 cfg.feature_flags
2360 .consensus_distributed_vote_scoring_strategy = true;
2361 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2363
2364 cfg.consensus_gc_depth = Some(60);
2369
2370 cfg.feature_flags.minimize_child_object_mutations = true;
2372
2373 if chain != Chain::Mainnet {
2374 cfg.feature_flags.consensus_batched_block_sync = true;
2376 }
2377
2378 if chain != Chain::Testnet && chain != Chain::Mainnet {
2379 cfg.feature_flags
2382 .congestion_control_gas_price_feedback_mechanism = true;
2383 }
2384
2385 cfg.feature_flags.validate_identifier_inputs = true;
2386 cfg.feature_flags.dependency_linkage_error = true;
2387 cfg.feature_flags.additional_multisig_checks = true;
2388 }
2389 11 => {
2390 }
2393 12 => {
2394 cfg.feature_flags
2397 .congestion_control_gas_price_feedback_mechanism = true;
2398
2399 cfg.feature_flags.normalize_ptb_arguments = true;
2401 }
2402 13 => {
2403 cfg.feature_flags.select_committee_from_eligible_validators = true;
2406 cfg.feature_flags.track_non_committee_eligible_validators = true;
2409
2410 if chain != Chain::Testnet && chain != Chain::Mainnet {
2411 cfg.feature_flags
2414 .select_committee_supporting_next_epoch_version = true;
2415 }
2416 }
2417 14 => {
2418 cfg.feature_flags.consensus_batched_block_sync = true;
2420
2421 if chain != Chain::Mainnet {
2422 cfg.feature_flags
2425 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2426 cfg.feature_flags
2430 .select_committee_supporting_next_epoch_version = true;
2431 }
2432 if chain != Chain::Testnet && chain != Chain::Mainnet {
2433 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2435 }
2436 }
2437 15 => {
2438 if chain != Chain::Mainnet && chain != Chain::Testnet {
2439 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2443 }
2444 }
2445 16 => {
2446 cfg.feature_flags
2449 .select_committee_supporting_next_epoch_version = true;
2450 cfg.feature_flags
2452 .consensus_commit_transactions_only_for_traversed_headers = true;
2453 }
2454 17 => {
2455 cfg.max_committee_members_count = Some(100);
2457 }
2458 18 => {
2459 if chain != Chain::Mainnet {
2460 cfg.feature_flags.passkey_auth = true;
2462 }
2463 }
2464 19 => {
2465 if chain != Chain::Testnet && chain != Chain::Mainnet {
2466 cfg.feature_flags
2469 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2470 cfg.feature_flags
2473 .separate_gas_price_feedback_mechanism_for_randomness = true;
2474 cfg.feature_flags.metadata_in_module_bytes = true;
2477 cfg.feature_flags.publish_package_metadata = true;
2478 cfg.feature_flags.enable_move_authentication = true;
2480 cfg.max_auth_gas = Some(250_000_000);
2482 cfg.transfer_receive_object_cost_base = Some(100);
2485 cfg.feature_flags.adjust_rewards_by_score = true;
2487 }
2488
2489 if chain != Chain::Mainnet {
2490 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2492
2493 cfg.feature_flags.calculate_validator_scores = true;
2495 cfg.scorer_version = Some(1);
2496 }
2497
2498 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
2500
2501 cfg.feature_flags.passkey_auth = true;
2503 }
2504 20 => {
2505 if chain != Chain::Testnet && chain != Chain::Mainnet {
2506 cfg.feature_flags
2508 .pass_calculated_validator_scores_to_advance_epoch = true;
2509 }
2510 }
2511
2512 _ => panic!("unsupported version {version:?}"),
2523 }
2524 }
2525 cfg
2526 }
2527
2528 pub fn verifier_config(&self, signing_limits: Option<(usize, usize)>) -> VerifierConfig {
2532 let (max_back_edges_per_function, max_back_edges_per_module) = if let Some((
2533 max_back_edges_per_function,
2534 max_back_edges_per_module,
2535 )) = signing_limits
2536 {
2537 (
2538 Some(max_back_edges_per_function),
2539 Some(max_back_edges_per_module),
2540 )
2541 } else {
2542 (None, None)
2543 };
2544
2545 VerifierConfig {
2546 max_loop_depth: Some(self.max_loop_depth() as usize),
2547 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2548 max_function_parameters: Some(self.max_function_parameters() as usize),
2549 max_basic_blocks: Some(self.max_basic_blocks() as usize),
2550 max_value_stack_size: self.max_value_stack_size() as usize,
2551 max_type_nodes: Some(self.max_type_nodes() as usize),
2552 max_push_size: Some(self.max_push_size() as usize),
2553 max_dependency_depth: Some(self.max_dependency_depth() as usize),
2554 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2555 max_function_definitions: Some(self.max_function_definitions() as usize),
2556 max_data_definitions: Some(self.max_struct_definitions() as usize),
2557 max_constant_vector_len: Some(self.max_move_vector_len()),
2558 max_back_edges_per_function,
2559 max_back_edges_per_module,
2560 max_basic_blocks_in_script: None,
2561 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
2565 max_variants_in_enum: self.max_move_enum_variants_as_option(),
2566 }
2567 }
2568
2569 pub fn apply_overrides_for_testing(
2574 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
2575 ) -> OverrideGuard {
2576 CONFIG_OVERRIDE.with(|ovr| {
2577 let mut cur = ovr.borrow_mut();
2578 assert!(cur.is_none(), "config override already present");
2579 *cur = Some(Box::new(override_fn));
2580 OverrideGuard
2581 })
2582 }
2583}
2584
2585impl ProtocolConfig {
2590 pub fn set_zklogin_auth_for_testing(&mut self, val: bool) {
2591 self.feature_flags.zklogin_auth = val
2592 }
2593 pub fn set_enable_jwk_consensus_updates_for_testing(&mut self, val: bool) {
2594 self.feature_flags.enable_jwk_consensus_updates = val
2595 }
2596
2597 pub fn set_accept_zklogin_in_multisig_for_testing(&mut self, val: bool) {
2598 self.feature_flags.accept_zklogin_in_multisig = val
2599 }
2600
2601 pub fn set_per_object_congestion_control_mode_for_testing(
2602 &mut self,
2603 val: PerObjectCongestionControlMode,
2604 ) {
2605 self.feature_flags.per_object_congestion_control_mode = val;
2606 }
2607
2608 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
2609 self.feature_flags.consensus_choice = val;
2610 }
2611
2612 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
2613 self.feature_flags.consensus_network = val;
2614 }
2615
2616 pub fn set_zklogin_max_epoch_upper_bound_delta_for_testing(&mut self, val: Option<u64>) {
2617 self.feature_flags.zklogin_max_epoch_upper_bound_delta = val
2618 }
2619
2620 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
2621 self.feature_flags.passkey_auth = val
2622 }
2623
2624 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
2625 self.feature_flags
2626 .disallow_new_modules_in_deps_only_packages = val;
2627 }
2628
2629 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
2630 self.feature_flags.consensus_round_prober = val;
2631 }
2632
2633 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
2634 self.feature_flags
2635 .consensus_distributed_vote_scoring_strategy = val;
2636 }
2637
2638 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
2639 self.consensus_gc_depth = Some(val);
2640 }
2641
2642 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
2643 self.feature_flags.consensus_linearize_subdag_v2 = val;
2644 }
2645
2646 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
2647 self.feature_flags
2648 .consensus_round_prober_probe_accepted_rounds = val;
2649 }
2650
2651 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
2652 self.feature_flags.accept_passkey_in_multisig = val;
2653 }
2654
2655 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
2656 self.feature_flags.consensus_smart_ancestor_selection = val;
2657 }
2658
2659 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
2660 self.feature_flags.consensus_batched_block_sync = val;
2661 }
2662
2663 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
2664 self.feature_flags
2665 .congestion_control_min_free_execution_slot = val;
2666 }
2667
2668 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
2669 self.feature_flags
2670 .congestion_control_gas_price_feedback_mechanism = val;
2671 }
2672
2673 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
2674 self.feature_flags.select_committee_from_eligible_validators = val;
2675 }
2676
2677 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
2678 self.feature_flags.track_non_committee_eligible_validators = val;
2679 }
2680
2681 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
2682 self.feature_flags
2683 .select_committee_supporting_next_epoch_version = val;
2684 }
2685
2686 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
2687 &mut self,
2688 val: bool,
2689 ) {
2690 self.feature_flags
2691 .consensus_median_timestamp_with_checkpoint_enforcement = val;
2692 }
2693
2694 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
2695 &mut self,
2696 val: bool,
2697 ) {
2698 self.feature_flags
2699 .consensus_commit_transactions_only_for_traversed_headers = val;
2700 }
2701
2702 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
2703 &mut self,
2704 val: bool,
2705 ) {
2706 self.feature_flags
2707 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
2708 }
2709
2710 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
2711 &mut self,
2712 val: bool,
2713 ) {
2714 self.feature_flags
2715 .separate_gas_price_feedback_mechanism_for_randomness = val;
2716 }
2717
2718 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
2719 self.feature_flags.metadata_in_module_bytes = val;
2720 }
2721
2722 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
2723 self.feature_flags.publish_package_metadata = val;
2724 }
2725
2726 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
2727 self.feature_flags.enable_move_authentication = val;
2728 }
2729}
2730
2731type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
2732
2733thread_local! {
2734 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
2735}
2736
2737#[must_use]
2738pub struct OverrideGuard;
2739
2740impl Drop for OverrideGuard {
2741 fn drop(&mut self) {
2742 info!("restoring override fn");
2743 CONFIG_OVERRIDE.with(|ovr| {
2744 *ovr.borrow_mut() = None;
2745 });
2746 }
2747}
2748
2749#[derive(PartialEq, Eq)]
2753pub enum LimitThresholdCrossed {
2754 None,
2755 Soft(u128, u128),
2756 Hard(u128, u128),
2757}
2758
2759pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
2762 x: T,
2763 soft_limit: U,
2764 hard_limit: V,
2765) -> LimitThresholdCrossed {
2766 let x: V = x.into();
2767 let soft_limit: V = soft_limit.into();
2768
2769 debug_assert!(soft_limit <= hard_limit);
2770
2771 if x >= hard_limit {
2774 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
2775 } else if x < soft_limit {
2776 LimitThresholdCrossed::None
2777 } else {
2778 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
2779 }
2780}
2781
2782#[macro_export]
2783macro_rules! check_limit {
2784 ($x:expr, $hard:expr) => {
2785 check_limit!($x, $hard, $hard)
2786 };
2787 ($x:expr, $soft:expr, $hard:expr) => {
2788 check_limit_in_range($x as u64, $soft, $hard)
2789 };
2790}
2791
2792#[macro_export]
2796macro_rules! check_limit_by_meter {
2797 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
2798 let (h, metered_str) = if $is_metered {
2800 ($metered_limit, "metered")
2801 } else {
2802 ($unmetered_hard_limit, "unmetered")
2804 };
2805 use iota_protocol_config::check_limit_in_range;
2806 let result = check_limit_in_range($x as u64, $metered_limit, h);
2807 match result {
2808 LimitThresholdCrossed::None => {}
2809 LimitThresholdCrossed::Soft(_, _) => {
2810 $metric.with_label_values(&[metered_str, "soft"]).inc();
2811 }
2812 LimitThresholdCrossed::Hard(_, _) => {
2813 $metric.with_label_values(&[metered_str, "hard"]).inc();
2814 }
2815 };
2816 result
2817 }};
2818}
2819
2820#[cfg(all(test, not(msim)))]
2821mod test {
2822 use insta::assert_yaml_snapshot;
2823
2824 use super::*;
2825
2826 #[test]
2827 fn snapshot_tests() {
2828 println!("\n============================================================================");
2829 println!("! !");
2830 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
2831 println!("! !");
2832 println!("============================================================================\n");
2833 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
2834 let chain_str = match chain_id {
2839 Chain::Unknown => "".to_string(),
2840 _ => format!("{chain_id:?}_"),
2841 };
2842 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
2843 let cur = ProtocolVersion::new(i);
2844 assert_yaml_snapshot!(
2845 format!("{}version_{}", chain_str, cur.as_u64()),
2846 ProtocolConfig::get_for_version(cur, *chain_id)
2847 );
2848 }
2849 }
2850 }
2851
2852 #[test]
2853 fn test_getters() {
2854 let prot: ProtocolConfig =
2855 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2856 assert_eq!(
2857 prot.max_arguments(),
2858 prot.max_arguments_as_option().unwrap()
2859 );
2860 }
2861
2862 #[test]
2863 fn test_setters() {
2864 let mut prot: ProtocolConfig =
2865 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2866 prot.set_max_arguments_for_testing(123);
2867 assert_eq!(prot.max_arguments(), 123);
2868
2869 prot.set_max_arguments_from_str_for_testing("321".to_string());
2870 assert_eq!(prot.max_arguments(), 321);
2871
2872 prot.disable_max_arguments_for_testing();
2873 assert_eq!(prot.max_arguments_as_option(), None);
2874
2875 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
2876 assert_eq!(prot.max_arguments(), 456);
2877 }
2878
2879 #[test]
2880 #[should_panic(expected = "unsupported version")]
2881 fn max_version_test() {
2882 let _ = ProtocolConfig::get_for_version_impl(
2885 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
2886 Chain::Unknown,
2887 );
2888 }
2889
2890 #[test]
2891 fn lookup_by_string_test() {
2892 let prot: ProtocolConfig =
2893 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2894 assert!(prot.lookup_attr("some random string".to_string()).is_none());
2896
2897 assert!(
2898 prot.lookup_attr("max_arguments".to_string())
2899 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
2900 );
2901
2902 assert!(
2904 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2905 .is_none()
2906 );
2907 assert!(
2908 prot.attr_map()
2909 .get("poseidon_bn254_cost_base")
2910 .unwrap()
2911 .is_none()
2912 );
2913
2914 let prot: ProtocolConfig =
2916 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2917
2918 assert!(
2919 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2920 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2921 );
2922 assert!(
2923 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
2924 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2925 );
2926
2927 let prot: ProtocolConfig =
2929 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2930 assert!(
2932 prot.feature_flags
2933 .lookup_attr("some random string".to_owned())
2934 .is_none()
2935 );
2936 assert!(
2937 !prot
2938 .feature_flags
2939 .attr_map()
2940 .contains_key("some random string")
2941 );
2942
2943 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
2945 assert!(
2946 prot.feature_flags
2947 .attr_map()
2948 .get("enable_poseidon")
2949 .unwrap()
2950 == &false
2951 );
2952 let prot: ProtocolConfig =
2953 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2954 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
2956 assert!(
2957 prot.feature_flags
2958 .attr_map()
2959 .get("enable_poseidon")
2960 .unwrap()
2961 == &true
2962 );
2963 }
2964
2965 #[test]
2966 fn limit_range_fn_test() {
2967 let low = 100u32;
2968 let high = 10000u64;
2969
2970 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
2971 assert!(matches!(
2972 check_limit!(255u16, low, high),
2973 LimitThresholdCrossed::Soft(255u128, 100)
2974 ));
2975 assert!(matches!(
2982 check_limit!(2550000u64, low, high),
2983 LimitThresholdCrossed::Hard(2550000, 10000)
2984 ));
2985
2986 assert!(matches!(
2987 check_limit!(2550000u64, high, high),
2988 LimitThresholdCrossed::Hard(2550000, 10000)
2989 ));
2990
2991 assert!(matches!(
2992 check_limit!(1u8, high),
2993 LimitThresholdCrossed::None
2994 ));
2995
2996 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
2997
2998 assert!(matches!(
2999 check_limit!(2550000u64, high),
3000 LimitThresholdCrossed::Hard(2550000, 10000)
3001 ));
3002 }
3003}