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 = 19;
23
24#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
101pub struct ProtocolVersion(u64);
102
103impl ProtocolVersion {
104 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
110
111 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
112
113 #[cfg(not(msim))]
114 const MAX_ALLOWED: Self = Self::MAX;
115
116 #[cfg(msim)]
119 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
120
121 pub fn new(v: u64) -> Self {
122 Self(v)
123 }
124
125 pub const fn as_u64(&self) -> u64 {
126 self.0
127 }
128
129 pub fn max() -> Self {
132 Self::MAX
133 }
134}
135
136impl From<u64> for ProtocolVersion {
137 fn from(v: u64) -> Self {
138 Self::new(v)
139 }
140}
141
142impl std::ops::Sub<u64> for ProtocolVersion {
143 type Output = Self;
144 fn sub(self, rhs: u64) -> Self::Output {
145 Self::new(self.0 - rhs)
146 }
147}
148
149impl std::ops::Add<u64> for ProtocolVersion {
150 type Output = Self;
151 fn add(self, rhs: u64) -> Self::Output {
152 Self::new(self.0 + rhs)
153 }
154}
155
156#[derive(
157 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
158)]
159pub enum Chain {
160 Mainnet,
161 Testnet,
162 #[default]
163 Unknown,
164}
165
166impl Chain {
167 pub fn as_str(self) -> &'static str {
168 match self {
169 Chain::Mainnet => "mainnet",
170 Chain::Testnet => "testnet",
171 Chain::Unknown => "unknown",
172 }
173 }
174}
175
176pub struct Error(pub String);
177
178#[derive(Default, Clone, Serialize, Deserialize, Debug, ProtocolConfigFeatureFlagsGetters)]
182struct FeatureFlags {
183 #[serde(skip_serializing_if = "is_true")]
189 disable_invariant_violation_check_in_swap_loc: bool,
190
191 #[serde(skip_serializing_if = "is_true")]
194 no_extraneous_module_bytes: bool,
195
196 #[serde(skip_serializing_if = "is_false")]
198 zklogin_auth: bool,
199
200 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
202 consensus_transaction_ordering: ConsensusTransactionOrdering,
203
204 #[serde(skip_serializing_if = "is_false")]
205 enable_jwk_consensus_updates: bool,
206
207 #[serde(skip_serializing_if = "is_false")]
209 accept_zklogin_in_multisig: bool,
210
211 #[serde(skip_serializing_if = "is_true")]
214 hardened_otw_check: bool,
215
216 #[serde(skip_serializing_if = "is_false")]
218 enable_poseidon: bool,
219
220 #[serde(skip_serializing_if = "is_false")]
222 enable_group_ops_native_function_msm: bool,
223
224 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
226 per_object_congestion_control_mode: PerObjectCongestionControlMode,
227
228 #[serde(skip_serializing_if = "ConsensusChoice::is_mysticeti")]
230 consensus_choice: ConsensusChoice,
231
232 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
234 consensus_network: ConsensusNetwork,
235
236 #[serde(skip_serializing_if = "Option::is_none")]
238 zklogin_max_epoch_upper_bound_delta: Option<u64>,
239
240 #[serde(skip_serializing_if = "is_false")]
242 enable_vdf: bool,
243
244 #[serde(skip_serializing_if = "is_false")]
246 passkey_auth: bool,
247
248 #[serde(skip_serializing_if = "is_true")]
251 rethrow_serialization_type_layout_errors: bool,
252
253 #[serde(skip_serializing_if = "is_false")]
255 relocate_event_module: bool,
256
257 #[serde(skip_serializing_if = "is_false")]
259 protocol_defined_base_fee: bool,
260
261 #[serde(skip_serializing_if = "is_false")]
263 uncompressed_g1_group_elements: bool,
264
265 #[serde(skip_serializing_if = "is_false")]
267 disallow_new_modules_in_deps_only_packages: bool,
268
269 #[serde(skip_serializing_if = "is_false")]
271 native_charging_v2: bool,
272
273 #[serde(skip_serializing_if = "is_false")]
275 convert_type_argument_error: bool,
276
277 #[serde(skip_serializing_if = "is_false")]
279 consensus_round_prober: bool,
280
281 #[serde(skip_serializing_if = "is_false")]
283 consensus_distributed_vote_scoring_strategy: bool,
284
285 #[serde(skip_serializing_if = "is_false")]
289 consensus_linearize_subdag_v2: bool,
290
291 #[serde(skip_serializing_if = "is_false")]
293 variant_nodes: bool,
294
295 #[serde(skip_serializing_if = "is_false")]
297 consensus_smart_ancestor_selection: bool,
298
299 #[serde(skip_serializing_if = "is_false")]
301 consensus_round_prober_probe_accepted_rounds: bool,
302
303 #[serde(skip_serializing_if = "is_false")]
305 consensus_zstd_compression: bool,
306
307 #[serde(skip_serializing_if = "is_false")]
310 congestion_control_min_free_execution_slot: bool,
311
312 #[serde(skip_serializing_if = "is_false")]
314 accept_passkey_in_multisig: bool,
315
316 #[serde(skip_serializing_if = "is_false")]
318 consensus_batched_block_sync: bool,
319
320 #[serde(skip_serializing_if = "is_false")]
323 congestion_control_gas_price_feedback_mechanism: bool,
324
325 #[serde(skip_serializing_if = "is_false")]
327 validate_identifier_inputs: bool,
328
329 #[serde(skip_serializing_if = "is_false")]
332 minimize_child_object_mutations: bool,
333
334 #[serde(skip_serializing_if = "is_false")]
336 dependency_linkage_error: bool,
337
338 #[serde(skip_serializing_if = "is_false")]
340 additional_multisig_checks: bool,
341
342 #[serde(skip_serializing_if = "is_false")]
345 normalize_ptb_arguments: bool,
346
347 #[serde(skip_serializing_if = "is_false")]
351 select_committee_from_eligible_validators: bool,
352
353 #[serde(skip_serializing_if = "is_false")]
360 track_non_committee_eligible_validators: bool,
361
362 #[serde(skip_serializing_if = "is_false")]
368 select_committee_supporting_next_epoch_version: bool,
369
370 #[serde(skip_serializing_if = "is_false")]
374 consensus_median_timestamp_with_checkpoint_enforcement: bool,
375
376 #[serde(skip_serializing_if = "is_false")]
378 consensus_commit_transactions_only_for_traversed_headers: bool,
379
380 #[serde(skip_serializing_if = "is_false")]
382 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
383
384 #[serde(skip_serializing_if = "is_false")]
387 separate_gas_price_feedback_mechanism_for_randomness: bool,
388}
389
390fn is_true(b: &bool) -> bool {
391 *b
392}
393
394fn is_false(b: &bool) -> bool {
395 !b
396}
397
398#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
400pub enum ConsensusTransactionOrdering {
401 #[default]
404 None,
405 ByGasPrice,
407}
408
409impl ConsensusTransactionOrdering {
410 pub fn is_none(&self) -> bool {
411 matches!(self, ConsensusTransactionOrdering::None)
412 }
413}
414
415#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
417pub enum PerObjectCongestionControlMode {
418 #[default]
419 None, TotalGasBudget, TotalTxCount, }
423
424impl PerObjectCongestionControlMode {
425 pub fn is_none(&self) -> bool {
426 matches!(self, PerObjectCongestionControlMode::None)
427 }
428}
429
430#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
432pub enum ConsensusChoice {
433 #[default]
434 Mysticeti,
435 Starfish,
436}
437
438impl ConsensusChoice {
439 pub fn is_mysticeti(&self) -> bool {
440 matches!(self, ConsensusChoice::Mysticeti)
441 }
442 pub fn is_starfish(&self) -> bool {
443 matches!(self, ConsensusChoice::Starfish)
444 }
445}
446
447#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
449pub enum ConsensusNetwork {
450 #[default]
451 Tonic,
452}
453
454impl ConsensusNetwork {
455 pub fn is_tonic(&self) -> bool {
456 matches!(self, ConsensusNetwork::Tonic)
457 }
458}
459
460#[skip_serializing_none]
494#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
495pub struct ProtocolConfig {
496 pub version: ProtocolVersion,
497
498 feature_flags: FeatureFlags,
499
500 max_tx_size_bytes: Option<u64>,
505
506 max_input_objects: Option<u64>,
509
510 max_size_written_objects: Option<u64>,
515 max_size_written_objects_system_tx: Option<u64>,
519
520 max_serialized_tx_effects_size_bytes: Option<u64>,
522
523 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
525
526 max_gas_payment_objects: Option<u32>,
528
529 max_modules_in_publish: Option<u32>,
531
532 max_package_dependencies: Option<u32>,
534
535 max_arguments: Option<u32>,
538
539 max_type_arguments: Option<u32>,
541
542 max_type_argument_depth: Option<u32>,
544
545 max_pure_argument_size: Option<u32>,
547
548 max_programmable_tx_commands: Option<u32>,
550
551 move_binary_format_version: Option<u32>,
557 min_move_binary_format_version: Option<u32>,
558
559 binary_module_handles: Option<u16>,
561 binary_struct_handles: Option<u16>,
562 binary_function_handles: Option<u16>,
563 binary_function_instantiations: Option<u16>,
564 binary_signatures: Option<u16>,
565 binary_constant_pool: Option<u16>,
566 binary_identifiers: Option<u16>,
567 binary_address_identifiers: Option<u16>,
568 binary_struct_defs: Option<u16>,
569 binary_struct_def_instantiations: Option<u16>,
570 binary_function_defs: Option<u16>,
571 binary_field_handles: Option<u16>,
572 binary_field_instantiations: Option<u16>,
573 binary_friend_decls: Option<u16>,
574 binary_enum_defs: Option<u16>,
575 binary_enum_def_instantiations: Option<u16>,
576 binary_variant_handles: Option<u16>,
577 binary_variant_instantiation_handles: Option<u16>,
578
579 max_move_object_size: Option<u64>,
582
583 max_move_package_size: Option<u64>,
588
589 max_publish_or_upgrade_per_ptb: Option<u64>,
592
593 max_tx_gas: Option<u64>,
595
596 max_gas_price: Option<u64>,
599
600 max_gas_computation_bucket: Option<u64>,
603
604 gas_rounding_step: Option<u64>,
606
607 max_loop_depth: Option<u64>,
609
610 max_generic_instantiation_length: Option<u64>,
613
614 max_function_parameters: Option<u64>,
617
618 max_basic_blocks: Option<u64>,
621
622 max_value_stack_size: Option<u64>,
624
625 max_type_nodes: Option<u64>,
629
630 max_push_size: Option<u64>,
633
634 max_struct_definitions: Option<u64>,
637
638 max_function_definitions: Option<u64>,
641
642 max_fields_in_struct: Option<u64>,
645
646 max_dependency_depth: Option<u64>,
649
650 max_num_event_emit: Option<u64>,
653
654 max_num_new_move_object_ids: Option<u64>,
657
658 max_num_new_move_object_ids_system_tx: Option<u64>,
661
662 max_num_deleted_move_object_ids: Option<u64>,
665
666 max_num_deleted_move_object_ids_system_tx: Option<u64>,
669
670 max_num_transferred_move_object_ids: Option<u64>,
673
674 max_num_transferred_move_object_ids_system_tx: Option<u64>,
677
678 max_event_emit_size: Option<u64>,
680
681 max_event_emit_size_total: Option<u64>,
683
684 max_move_vector_len: Option<u64>,
687
688 max_move_identifier_len: Option<u64>,
691
692 max_move_value_depth: Option<u64>,
694
695 max_move_enum_variants: Option<u64>,
698
699 max_back_edges_per_function: Option<u64>,
702
703 max_back_edges_per_module: Option<u64>,
706
707 max_verifier_meter_ticks_per_function: Option<u64>,
710
711 max_meter_ticks_per_module: Option<u64>,
714
715 max_meter_ticks_per_package: Option<u64>,
718
719 object_runtime_max_num_cached_objects: Option<u64>,
726
727 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
730
731 object_runtime_max_num_store_entries: Option<u64>,
734
735 object_runtime_max_num_store_entries_system_tx: Option<u64>,
738
739 base_tx_cost_fixed: Option<u64>,
744
745 package_publish_cost_fixed: Option<u64>,
749
750 base_tx_cost_per_byte: Option<u64>,
754
755 package_publish_cost_per_byte: Option<u64>,
757
758 obj_access_cost_read_per_byte: Option<u64>,
760
761 obj_access_cost_mutate_per_byte: Option<u64>,
763
764 obj_access_cost_delete_per_byte: Option<u64>,
766
767 obj_access_cost_verify_per_byte: Option<u64>,
777
778 max_type_to_layout_nodes: Option<u64>,
780
781 max_ptb_value_size: Option<u64>,
783
784 gas_model_version: Option<u64>,
789
790 obj_data_cost_refundable: Option<u64>,
796
797 obj_metadata_cost_non_refundable: Option<u64>,
801
802 storage_rebate_rate: Option<u64>,
808
809 reward_slashing_rate: Option<u64>,
812
813 storage_gas_price: Option<u64>,
815
816 base_gas_price: Option<u64>,
818
819 validator_target_reward: Option<u64>,
821
822 max_transactions_per_checkpoint: Option<u64>,
829
830 max_checkpoint_size_bytes: Option<u64>,
834
835 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
841
842 address_from_bytes_cost_base: Option<u64>,
847 address_to_u256_cost_base: Option<u64>,
849 address_from_u256_cost_base: Option<u64>,
851
852 config_read_setting_impl_cost_base: Option<u64>,
857 config_read_setting_impl_cost_per_byte: Option<u64>,
858
859 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
863 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
864 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
865 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
866 dynamic_field_add_child_object_cost_base: Option<u64>,
869 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
870 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
871 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
872 dynamic_field_borrow_child_object_cost_base: Option<u64>,
875 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
876 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
877 dynamic_field_remove_child_object_cost_base: Option<u64>,
880 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
881 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
882 dynamic_field_has_child_object_cost_base: Option<u64>,
885 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
888 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
889 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
890
891 event_emit_cost_base: Option<u64>,
894 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
895 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
896 event_emit_output_cost_per_byte: Option<u64>,
897
898 object_borrow_uid_cost_base: Option<u64>,
901 object_delete_impl_cost_base: Option<u64>,
903 object_record_new_uid_cost_base: Option<u64>,
905
906 transfer_transfer_internal_cost_base: Option<u64>,
909 transfer_freeze_object_cost_base: Option<u64>,
911 transfer_share_object_cost_base: Option<u64>,
913 transfer_receive_object_cost_base: Option<u64>,
916
917 tx_context_derive_id_cost_base: Option<u64>,
920
921 types_is_one_time_witness_cost_base: Option<u64>,
924 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
925 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
926
927 validator_validate_metadata_cost_base: Option<u64>,
930 validator_validate_metadata_data_cost_per_byte: Option<u64>,
931
932 crypto_invalid_arguments_cost: Option<u64>,
934 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
936 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
937 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
938
939 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
941 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
942 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
943
944 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
946 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
947 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
948 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
949 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
950 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
951
952 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
954
955 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
957 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
958 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
959 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
960 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
961 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
962
963 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
965 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
966 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
967 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
968 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
969 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
970
971 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
973 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
974 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
975 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
976 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
977 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
978
979 ecvrf_ecvrf_verify_cost_base: Option<u64>,
981 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
982 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
983
984 ed25519_ed25519_verify_cost_base: Option<u64>,
986 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
987 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
988
989 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
991 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
992
993 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
995 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
996 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
997 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
998 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
999
1000 hash_blake2b256_cost_base: Option<u64>,
1002 hash_blake2b256_data_cost_per_byte: Option<u64>,
1003 hash_blake2b256_data_cost_per_block: Option<u64>,
1004
1005 hash_keccak256_cost_base: Option<u64>,
1007 hash_keccak256_data_cost_per_byte: Option<u64>,
1008 hash_keccak256_data_cost_per_block: Option<u64>,
1009
1010 poseidon_bn254_cost_base: Option<u64>,
1012 poseidon_bn254_cost_per_block: Option<u64>,
1013
1014 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1016 group_ops_bls12381_decode_g1_cost: Option<u64>,
1017 group_ops_bls12381_decode_g2_cost: Option<u64>,
1018 group_ops_bls12381_decode_gt_cost: Option<u64>,
1019 group_ops_bls12381_scalar_add_cost: Option<u64>,
1020 group_ops_bls12381_g1_add_cost: Option<u64>,
1021 group_ops_bls12381_g2_add_cost: Option<u64>,
1022 group_ops_bls12381_gt_add_cost: Option<u64>,
1023 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1024 group_ops_bls12381_g1_sub_cost: Option<u64>,
1025 group_ops_bls12381_g2_sub_cost: Option<u64>,
1026 group_ops_bls12381_gt_sub_cost: Option<u64>,
1027 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1028 group_ops_bls12381_g1_mul_cost: Option<u64>,
1029 group_ops_bls12381_g2_mul_cost: Option<u64>,
1030 group_ops_bls12381_gt_mul_cost: Option<u64>,
1031 group_ops_bls12381_scalar_div_cost: Option<u64>,
1032 group_ops_bls12381_g1_div_cost: Option<u64>,
1033 group_ops_bls12381_g2_div_cost: Option<u64>,
1034 group_ops_bls12381_gt_div_cost: Option<u64>,
1035 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1036 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1037 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1038 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1039 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1040 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1041 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1042 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1043 group_ops_bls12381_msm_max_len: Option<u32>,
1044 group_ops_bls12381_pairing_cost: Option<u64>,
1045 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1046 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1047 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1048 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1049 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1050
1051 hmac_hmac_sha3_256_cost_base: Option<u64>,
1053 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1054 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1055
1056 check_zklogin_id_cost_base: Option<u64>,
1058 check_zklogin_issuer_cost_base: Option<u64>,
1060
1061 vdf_verify_vdf_cost: Option<u64>,
1062 vdf_hash_to_input_cost: Option<u64>,
1063
1064 bcs_per_byte_serialized_cost: Option<u64>,
1066 bcs_legacy_min_output_size_cost: Option<u64>,
1067 bcs_failure_cost: Option<u64>,
1068
1069 hash_sha2_256_base_cost: Option<u64>,
1070 hash_sha2_256_per_byte_cost: Option<u64>,
1071 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1072 hash_sha3_256_base_cost: Option<u64>,
1073 hash_sha3_256_per_byte_cost: Option<u64>,
1074 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1075 type_name_get_base_cost: Option<u64>,
1076 type_name_get_per_byte_cost: Option<u64>,
1077
1078 string_check_utf8_base_cost: Option<u64>,
1079 string_check_utf8_per_byte_cost: Option<u64>,
1080 string_is_char_boundary_base_cost: Option<u64>,
1081 string_sub_string_base_cost: Option<u64>,
1082 string_sub_string_per_byte_cost: Option<u64>,
1083 string_index_of_base_cost: Option<u64>,
1084 string_index_of_per_byte_pattern_cost: Option<u64>,
1085 string_index_of_per_byte_searched_cost: Option<u64>,
1086
1087 vector_empty_base_cost: Option<u64>,
1088 vector_length_base_cost: Option<u64>,
1089 vector_push_back_base_cost: Option<u64>,
1090 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1091 vector_borrow_base_cost: Option<u64>,
1092 vector_pop_back_base_cost: Option<u64>,
1093 vector_destroy_empty_base_cost: Option<u64>,
1094 vector_swap_base_cost: Option<u64>,
1095 debug_print_base_cost: Option<u64>,
1096 debug_print_stack_trace_base_cost: Option<u64>,
1097
1098 execution_version: Option<u64>,
1100
1101 consensus_bad_nodes_stake_threshold: Option<u64>,
1105
1106 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1107 max_age_of_jwk_in_epochs: Option<u64>,
1111
1112 random_beacon_reduction_allowed_delta: Option<u16>,
1116
1117 random_beacon_reduction_lower_bound: Option<u32>,
1120
1121 random_beacon_dkg_timeout_round: Option<u32>,
1124
1125 random_beacon_min_round_interval_ms: Option<u64>,
1127
1128 random_beacon_dkg_version: Option<u64>,
1132
1133 consensus_max_transaction_size_bytes: Option<u64>,
1138 consensus_max_transactions_in_block_bytes: Option<u64>,
1140 consensus_max_num_transactions_in_block: Option<u64>,
1142
1143 max_deferral_rounds_for_congestion_control: Option<u64>,
1147
1148 min_checkpoint_interval_ms: Option<u64>,
1150
1151 checkpoint_summary_version_specific_data: Option<u64>,
1153
1154 max_soft_bundle_size: Option<u64>,
1157
1158 bridge_should_try_to_finalize_committee: Option<bool>,
1163
1164 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1170
1171 max_committee_members_count: Option<u64>,
1175
1176 consensus_gc_depth: Option<u32>,
1179
1180 consensus_max_acknowledgments_per_block: Option<u32>,
1186
1187 max_congestion_limit_overshoot_per_commit: Option<u64>,
1192}
1193
1194impl ProtocolConfig {
1196 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1209 self.feature_flags
1210 .disable_invariant_violation_check_in_swap_loc
1211 }
1212
1213 pub fn no_extraneous_module_bytes(&self) -> bool {
1214 self.feature_flags.no_extraneous_module_bytes
1215 }
1216
1217 pub fn zklogin_auth(&self) -> bool {
1218 self.feature_flags.zklogin_auth
1219 }
1220
1221 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1222 self.feature_flags.consensus_transaction_ordering
1223 }
1224
1225 pub fn enable_jwk_consensus_updates(&self) -> bool {
1226 self.feature_flags.enable_jwk_consensus_updates
1227 }
1228
1229 pub fn create_authenticator_state_in_genesis(&self) -> bool {
1231 self.enable_jwk_consensus_updates()
1232 }
1233
1234 pub fn dkg_version(&self) -> u64 {
1235 self.random_beacon_dkg_version.unwrap_or(1)
1237 }
1238
1239 pub fn accept_zklogin_in_multisig(&self) -> bool {
1240 self.feature_flags.accept_zklogin_in_multisig
1241 }
1242
1243 pub fn zklogin_max_epoch_upper_bound_delta(&self) -> Option<u64> {
1244 self.feature_flags.zklogin_max_epoch_upper_bound_delta
1245 }
1246
1247 pub fn hardened_otw_check(&self) -> bool {
1248 self.feature_flags.hardened_otw_check
1249 }
1250
1251 pub fn enable_poseidon(&self) -> bool {
1252 self.feature_flags.enable_poseidon
1253 }
1254
1255 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1256 self.feature_flags.enable_group_ops_native_function_msm
1257 }
1258
1259 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1260 self.feature_flags.per_object_congestion_control_mode
1261 }
1262
1263 pub fn consensus_choice(&self) -> ConsensusChoice {
1264 self.feature_flags.consensus_choice
1265 }
1266
1267 pub fn consensus_network(&self) -> ConsensusNetwork {
1268 self.feature_flags.consensus_network
1269 }
1270
1271 pub fn enable_vdf(&self) -> bool {
1272 self.feature_flags.enable_vdf
1273 }
1274
1275 pub fn passkey_auth(&self) -> bool {
1276 self.feature_flags.passkey_auth
1277 }
1278
1279 pub fn max_transaction_size_bytes(&self) -> u64 {
1280 self.consensus_max_transaction_size_bytes
1282 .unwrap_or(256 * 1024)
1283 }
1284
1285 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1286 if cfg!(msim) {
1287 256 * 1024
1288 } else {
1289 self.consensus_max_transactions_in_block_bytes
1290 .unwrap_or(512 * 1024)
1291 }
1292 }
1293
1294 pub fn max_num_transactions_in_block(&self) -> u64 {
1295 if cfg!(msim) {
1296 8
1297 } else {
1298 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1299 }
1300 }
1301
1302 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1303 self.feature_flags.rethrow_serialization_type_layout_errors
1304 }
1305
1306 pub fn relocate_event_module(&self) -> bool {
1307 self.feature_flags.relocate_event_module
1308 }
1309
1310 pub fn protocol_defined_base_fee(&self) -> bool {
1311 self.feature_flags.protocol_defined_base_fee
1312 }
1313
1314 pub fn uncompressed_g1_group_elements(&self) -> bool {
1315 self.feature_flags.uncompressed_g1_group_elements
1316 }
1317
1318 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1319 self.feature_flags
1320 .disallow_new_modules_in_deps_only_packages
1321 }
1322
1323 pub fn native_charging_v2(&self) -> bool {
1324 self.feature_flags.native_charging_v2
1325 }
1326
1327 pub fn consensus_round_prober(&self) -> bool {
1328 self.feature_flags.consensus_round_prober
1329 }
1330
1331 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1332 self.feature_flags
1333 .consensus_distributed_vote_scoring_strategy
1334 }
1335
1336 pub fn gc_depth(&self) -> u32 {
1337 if cfg!(msim) {
1338 min(5, self.consensus_gc_depth.unwrap_or(0))
1340 } else {
1341 self.consensus_gc_depth.unwrap_or(0)
1342 }
1343 }
1344
1345 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1346 let res = self.feature_flags.consensus_linearize_subdag_v2;
1347 assert!(
1348 !res || self.gc_depth() > 0,
1349 "The consensus linearize sub dag V2 requires GC to be enabled"
1350 );
1351 res
1352 }
1353
1354 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1355 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1356 }
1357
1358 pub fn variant_nodes(&self) -> bool {
1359 self.feature_flags.variant_nodes
1360 }
1361
1362 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1363 self.feature_flags.consensus_smart_ancestor_selection
1364 }
1365
1366 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1367 self.feature_flags
1368 .consensus_round_prober_probe_accepted_rounds
1369 }
1370
1371 pub fn consensus_zstd_compression(&self) -> bool {
1372 self.feature_flags.consensus_zstd_compression
1373 }
1374
1375 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1376 self.feature_flags
1377 .congestion_control_min_free_execution_slot
1378 }
1379
1380 pub fn accept_passkey_in_multisig(&self) -> bool {
1381 self.feature_flags.accept_passkey_in_multisig
1382 }
1383
1384 pub fn consensus_batched_block_sync(&self) -> bool {
1385 self.feature_flags.consensus_batched_block_sync
1386 }
1387
1388 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1391 self.feature_flags
1392 .congestion_control_gas_price_feedback_mechanism
1393 }
1394
1395 pub fn validate_identifier_inputs(&self) -> bool {
1396 self.feature_flags.validate_identifier_inputs
1397 }
1398
1399 pub fn minimize_child_object_mutations(&self) -> bool {
1400 self.feature_flags.minimize_child_object_mutations
1401 }
1402
1403 pub fn dependency_linkage_error(&self) -> bool {
1404 self.feature_flags.dependency_linkage_error
1405 }
1406
1407 pub fn additional_multisig_checks(&self) -> bool {
1408 self.feature_flags.additional_multisig_checks
1409 }
1410
1411 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1412 0
1415 }
1416
1417 pub fn normalize_ptb_arguments(&self) -> bool {
1418 self.feature_flags.normalize_ptb_arguments
1419 }
1420
1421 pub fn select_committee_from_eligible_validators(&self) -> bool {
1422 let res = self.feature_flags.select_committee_from_eligible_validators;
1423 assert!(
1424 !res || (self.protocol_defined_base_fee()
1425 && self.max_committee_members_count_as_option().is_some()),
1426 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1427 );
1428 res
1429 }
1430
1431 pub fn track_non_committee_eligible_validators(&self) -> bool {
1432 self.feature_flags.track_non_committee_eligible_validators
1433 }
1434
1435 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1436 let res = self
1437 .feature_flags
1438 .select_committee_supporting_next_epoch_version;
1439 assert!(
1440 !res || (self.track_non_committee_eligible_validators()
1441 && self.select_committee_from_eligible_validators()),
1442 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1443 );
1444 res
1445 }
1446
1447 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1448 let res = self
1449 .feature_flags
1450 .consensus_median_timestamp_with_checkpoint_enforcement;
1451 assert!(
1452 !res || self.gc_depth() > 0,
1453 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1454 );
1455 res
1456 }
1457
1458 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1459 self.feature_flags
1460 .consensus_commit_transactions_only_for_traversed_headers
1461 }
1462
1463 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1466 self.feature_flags
1467 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1468 }
1469
1470 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1473 self.feature_flags
1474 .separate_gas_price_feedback_mechanism_for_randomness
1475 }
1476}
1477
1478#[cfg(not(msim))]
1479static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1480
1481#[cfg(msim)]
1483thread_local! {
1484 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1485}
1486
1487impl ProtocolConfig {
1489 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1492 assert!(
1494 version >= ProtocolVersion::MIN,
1495 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1496 version,
1497 ProtocolVersion::MIN.0,
1498 );
1499 assert!(
1500 version <= ProtocolVersion::MAX_ALLOWED,
1501 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1502 version,
1503 ProtocolVersion::MAX_ALLOWED.0,
1504 );
1505
1506 let mut ret = Self::get_for_version_impl(version, chain);
1507 ret.version = version;
1508
1509 ret = CONFIG_OVERRIDE.with(|ovr| {
1510 if let Some(override_fn) = &*ovr.borrow() {
1511 warn!(
1512 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1513 );
1514 override_fn(version, ret)
1515 } else {
1516 ret
1517 }
1518 });
1519
1520 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1521 warn!(
1522 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1523 );
1524 let overrides: ProtocolConfigOptional =
1525 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1526 .expect("failed to parse ProtocolConfig override env variables");
1527 overrides.apply_to(&mut ret);
1528 }
1529
1530 ret
1531 }
1532
1533 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1536 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1537 let mut ret = Self::get_for_version_impl(version, chain);
1538 ret.version = version;
1539 Some(ret)
1540 } else {
1541 None
1542 }
1543 }
1544
1545 #[cfg(not(msim))]
1546 pub fn poison_get_for_min_version() {
1547 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1548 }
1549
1550 #[cfg(not(msim))]
1551 fn load_poison_get_for_min_version() -> bool {
1552 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1553 }
1554
1555 #[cfg(msim)]
1556 pub fn poison_get_for_min_version() {
1557 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1558 }
1559
1560 #[cfg(msim)]
1561 fn load_poison_get_for_min_version() -> bool {
1562 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1563 }
1564
1565 pub fn convert_type_argument_error(&self) -> bool {
1566 self.feature_flags.convert_type_argument_error
1567 }
1568
1569 pub fn get_for_min_version() -> Self {
1573 if Self::load_poison_get_for_min_version() {
1574 panic!("get_for_min_version called on validator");
1575 }
1576 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1577 }
1578
1579 #[expect(non_snake_case)]
1590 pub fn get_for_max_version_UNSAFE() -> Self {
1591 if Self::load_poison_get_for_min_version() {
1592 panic!("get_for_max_version_UNSAFE called on validator");
1593 }
1594 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1595 }
1596
1597 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1598 #[cfg(msim)]
1599 {
1600 if version > ProtocolVersion::MAX {
1602 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1603 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1604 return config;
1605 }
1606 }
1607
1608 let mut cfg = Self {
1612 version,
1613
1614 feature_flags: Default::default(),
1615
1616 max_tx_size_bytes: Some(128 * 1024),
1617 max_input_objects: Some(2048),
1620 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1621 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1622 max_gas_payment_objects: Some(256),
1623 max_modules_in_publish: Some(64),
1624 max_package_dependencies: Some(32),
1625 max_arguments: Some(512),
1626 max_type_arguments: Some(16),
1627 max_type_argument_depth: Some(16),
1628 max_pure_argument_size: Some(16 * 1024),
1629 max_programmable_tx_commands: Some(1024),
1630 move_binary_format_version: Some(7),
1631 min_move_binary_format_version: Some(6),
1632 binary_module_handles: Some(100),
1633 binary_struct_handles: Some(300),
1634 binary_function_handles: Some(1500),
1635 binary_function_instantiations: Some(750),
1636 binary_signatures: Some(1000),
1637 binary_constant_pool: Some(4000),
1638 binary_identifiers: Some(10000),
1639 binary_address_identifiers: Some(100),
1640 binary_struct_defs: Some(200),
1641 binary_struct_def_instantiations: Some(100),
1642 binary_function_defs: Some(1000),
1643 binary_field_handles: Some(500),
1644 binary_field_instantiations: Some(250),
1645 binary_friend_decls: Some(100),
1646 binary_enum_defs: None,
1647 binary_enum_def_instantiations: None,
1648 binary_variant_handles: None,
1649 binary_variant_instantiation_handles: None,
1650 max_move_object_size: Some(250 * 1024),
1651 max_move_package_size: Some(100 * 1024),
1652 max_publish_or_upgrade_per_ptb: Some(5),
1653 max_tx_gas: Some(50_000_000_000),
1655 max_gas_price: Some(100_000),
1656 max_gas_computation_bucket: Some(5_000_000),
1657 max_loop_depth: Some(5),
1658 max_generic_instantiation_length: Some(32),
1659 max_function_parameters: Some(128),
1660 max_basic_blocks: Some(1024),
1661 max_value_stack_size: Some(1024),
1662 max_type_nodes: Some(256),
1663 max_push_size: Some(10000),
1664 max_struct_definitions: Some(200),
1665 max_function_definitions: Some(1000),
1666 max_fields_in_struct: Some(32),
1667 max_dependency_depth: Some(100),
1668 max_num_event_emit: Some(1024),
1669 max_num_new_move_object_ids: Some(2048),
1670 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1671 max_num_deleted_move_object_ids: Some(2048),
1672 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1673 max_num_transferred_move_object_ids: Some(2048),
1674 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1675 max_event_emit_size: Some(250 * 1024),
1676 max_move_vector_len: Some(256 * 1024),
1677 max_type_to_layout_nodes: None,
1678 max_ptb_value_size: None,
1679
1680 max_back_edges_per_function: Some(10_000),
1681 max_back_edges_per_module: Some(10_000),
1682
1683 max_verifier_meter_ticks_per_function: Some(16_000_000),
1684
1685 max_meter_ticks_per_module: Some(16_000_000),
1686 max_meter_ticks_per_package: Some(16_000_000),
1687
1688 object_runtime_max_num_cached_objects: Some(1000),
1689 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
1690 object_runtime_max_num_store_entries: Some(1000),
1691 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
1692 base_tx_cost_fixed: Some(1_000),
1694 package_publish_cost_fixed: Some(1_000),
1695 base_tx_cost_per_byte: Some(0),
1696 package_publish_cost_per_byte: Some(80),
1697 obj_access_cost_read_per_byte: Some(15),
1698 obj_access_cost_mutate_per_byte: Some(40),
1699 obj_access_cost_delete_per_byte: Some(40),
1700 obj_access_cost_verify_per_byte: Some(200),
1701 obj_data_cost_refundable: Some(100),
1702 obj_metadata_cost_non_refundable: Some(50),
1703 gas_model_version: Some(1),
1704 storage_rebate_rate: Some(10000),
1705 reward_slashing_rate: Some(10000),
1707 storage_gas_price: Some(76),
1708 base_gas_price: None,
1709 validator_target_reward: Some(767_000 * 1_000_000_000),
1712 max_transactions_per_checkpoint: Some(10_000),
1713 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
1714
1715 buffer_stake_for_protocol_upgrade_bps: Some(5000),
1717
1718 address_from_bytes_cost_base: Some(52),
1722 address_to_u256_cost_base: Some(52),
1724 address_from_u256_cost_base: Some(52),
1726
1727 config_read_setting_impl_cost_base: Some(100),
1730 config_read_setting_impl_cost_per_byte: Some(40),
1731
1732 dynamic_field_hash_type_and_key_cost_base: Some(100),
1736 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
1737 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
1738 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
1739 dynamic_field_add_child_object_cost_base: Some(100),
1742 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
1743 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
1744 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
1745 dynamic_field_borrow_child_object_cost_base: Some(100),
1748 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
1749 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
1750 dynamic_field_remove_child_object_cost_base: Some(100),
1753 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
1754 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
1755 dynamic_field_has_child_object_cost_base: Some(100),
1758 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
1761 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
1762 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
1763
1764 event_emit_cost_base: Some(52),
1767 event_emit_value_size_derivation_cost_per_byte: Some(2),
1768 event_emit_tag_size_derivation_cost_per_byte: Some(5),
1769 event_emit_output_cost_per_byte: Some(10),
1770
1771 object_borrow_uid_cost_base: Some(52),
1774 object_delete_impl_cost_base: Some(52),
1776 object_record_new_uid_cost_base: Some(52),
1778
1779 transfer_transfer_internal_cost_base: Some(52),
1783 transfer_freeze_object_cost_base: Some(52),
1785 transfer_share_object_cost_base: Some(52),
1787 transfer_receive_object_cost_base: Some(52),
1788
1789 tx_context_derive_id_cost_base: Some(52),
1793
1794 types_is_one_time_witness_cost_base: Some(52),
1797 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
1798 types_is_one_time_witness_type_cost_per_byte: Some(2),
1799
1800 validator_validate_metadata_cost_base: Some(52),
1804 validator_validate_metadata_data_cost_per_byte: Some(2),
1805
1806 crypto_invalid_arguments_cost: Some(100),
1808 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
1810 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
1811 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
1812
1813 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
1815 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
1816 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
1817
1818 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
1820 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1821 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1822 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
1823 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1824 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
1825
1826 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
1828
1829 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
1831 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
1832 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
1833 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
1834 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
1835 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
1836
1837 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
1839 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1840 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1841 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
1842 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1843 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
1844
1845 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
1847 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
1848 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
1849 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
1850 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
1851 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
1852
1853 ecvrf_ecvrf_verify_cost_base: Some(52),
1855 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
1856 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
1857
1858 ed25519_ed25519_verify_cost_base: Some(52),
1860 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
1861 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
1862
1863 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
1865 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
1866
1867 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
1869 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
1870 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
1871 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
1872 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
1873
1874 hash_blake2b256_cost_base: Some(52),
1876 hash_blake2b256_data_cost_per_byte: Some(2),
1877 hash_blake2b256_data_cost_per_block: Some(2),
1878 hash_keccak256_cost_base: Some(52),
1880 hash_keccak256_data_cost_per_byte: Some(2),
1881 hash_keccak256_data_cost_per_block: Some(2),
1882
1883 poseidon_bn254_cost_base: None,
1884 poseidon_bn254_cost_per_block: None,
1885
1886 hmac_hmac_sha3_256_cost_base: Some(52),
1888 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
1889 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
1890
1891 group_ops_bls12381_decode_scalar_cost: Some(52),
1893 group_ops_bls12381_decode_g1_cost: Some(52),
1894 group_ops_bls12381_decode_g2_cost: Some(52),
1895 group_ops_bls12381_decode_gt_cost: Some(52),
1896 group_ops_bls12381_scalar_add_cost: Some(52),
1897 group_ops_bls12381_g1_add_cost: Some(52),
1898 group_ops_bls12381_g2_add_cost: Some(52),
1899 group_ops_bls12381_gt_add_cost: Some(52),
1900 group_ops_bls12381_scalar_sub_cost: Some(52),
1901 group_ops_bls12381_g1_sub_cost: Some(52),
1902 group_ops_bls12381_g2_sub_cost: Some(52),
1903 group_ops_bls12381_gt_sub_cost: Some(52),
1904 group_ops_bls12381_scalar_mul_cost: Some(52),
1905 group_ops_bls12381_g1_mul_cost: Some(52),
1906 group_ops_bls12381_g2_mul_cost: Some(52),
1907 group_ops_bls12381_gt_mul_cost: Some(52),
1908 group_ops_bls12381_scalar_div_cost: Some(52),
1909 group_ops_bls12381_g1_div_cost: Some(52),
1910 group_ops_bls12381_g2_div_cost: Some(52),
1911 group_ops_bls12381_gt_div_cost: Some(52),
1912 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
1913 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
1914 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
1915 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
1916 group_ops_bls12381_g1_msm_base_cost: Some(52),
1917 group_ops_bls12381_g2_msm_base_cost: Some(52),
1918 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
1919 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
1920 group_ops_bls12381_msm_max_len: Some(32),
1921 group_ops_bls12381_pairing_cost: Some(52),
1922 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
1923 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
1924 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
1925 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
1926 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
1927
1928 check_zklogin_id_cost_base: Some(200),
1930 check_zklogin_issuer_cost_base: Some(200),
1932
1933 vdf_verify_vdf_cost: None,
1934 vdf_hash_to_input_cost: None,
1935
1936 bcs_per_byte_serialized_cost: Some(2),
1937 bcs_legacy_min_output_size_cost: Some(1),
1938 bcs_failure_cost: Some(52),
1939 hash_sha2_256_base_cost: Some(52),
1940 hash_sha2_256_per_byte_cost: Some(2),
1941 hash_sha2_256_legacy_min_input_len_cost: Some(1),
1942 hash_sha3_256_base_cost: Some(52),
1943 hash_sha3_256_per_byte_cost: Some(2),
1944 hash_sha3_256_legacy_min_input_len_cost: Some(1),
1945 type_name_get_base_cost: Some(52),
1946 type_name_get_per_byte_cost: Some(2),
1947 string_check_utf8_base_cost: Some(52),
1948 string_check_utf8_per_byte_cost: Some(2),
1949 string_is_char_boundary_base_cost: Some(52),
1950 string_sub_string_base_cost: Some(52),
1951 string_sub_string_per_byte_cost: Some(2),
1952 string_index_of_base_cost: Some(52),
1953 string_index_of_per_byte_pattern_cost: Some(2),
1954 string_index_of_per_byte_searched_cost: Some(2),
1955 vector_empty_base_cost: Some(52),
1956 vector_length_base_cost: Some(52),
1957 vector_push_back_base_cost: Some(52),
1958 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
1959 vector_borrow_base_cost: Some(52),
1960 vector_pop_back_base_cost: Some(52),
1961 vector_destroy_empty_base_cost: Some(52),
1962 vector_swap_base_cost: Some(52),
1963 debug_print_base_cost: Some(52),
1964 debug_print_stack_trace_base_cost: Some(52),
1965
1966 max_size_written_objects: Some(5 * 1000 * 1000),
1967 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
1970
1971 max_move_identifier_len: Some(128),
1973 max_move_value_depth: Some(128),
1974 max_move_enum_variants: None,
1975
1976 gas_rounding_step: Some(1_000),
1977
1978 execution_version: Some(1),
1979
1980 max_event_emit_size_total: Some(
1983 256 * 250 * 1024, ),
1985
1986 consensus_bad_nodes_stake_threshold: Some(20),
1993
1994 max_jwk_votes_per_validator_per_epoch: Some(240),
1996
1997 max_age_of_jwk_in_epochs: Some(1),
1998
1999 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2003
2004 random_beacon_reduction_allowed_delta: Some(800),
2005
2006 random_beacon_reduction_lower_bound: Some(1000),
2007 random_beacon_dkg_timeout_round: Some(3000),
2008 random_beacon_min_round_interval_ms: Some(500),
2009
2010 random_beacon_dkg_version: Some(1),
2011
2012 consensus_max_num_transactions_in_block: Some(512),
2016
2017 max_deferral_rounds_for_congestion_control: Some(10),
2018
2019 min_checkpoint_interval_ms: Some(200),
2020
2021 checkpoint_summary_version_specific_data: Some(1),
2022
2023 max_soft_bundle_size: Some(5),
2024
2025 bridge_should_try_to_finalize_committee: None,
2026
2027 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2028
2029 max_committee_members_count: None,
2030
2031 consensus_gc_depth: None,
2032
2033 consensus_max_acknowledgments_per_block: None,
2034
2035 max_congestion_limit_overshoot_per_commit: None,
2036 };
2039
2040 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2041
2042 {
2044 cfg.feature_flags
2045 .disable_invariant_violation_check_in_swap_loc = true;
2046 cfg.feature_flags.no_extraneous_module_bytes = true;
2047 cfg.feature_flags.hardened_otw_check = true;
2048 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2049 }
2050
2051 {
2053 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2054 }
2055
2056 cfg.feature_flags.consensus_choice = ConsensusChoice::Mysticeti;
2058 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2060
2061 cfg.feature_flags.per_object_congestion_control_mode =
2062 PerObjectCongestionControlMode::TotalTxCount;
2063
2064 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2066
2067 if chain != Chain::Mainnet && chain != Chain::Testnet {
2069 cfg.feature_flags.enable_poseidon = true;
2070 cfg.poseidon_bn254_cost_base = Some(260);
2071 cfg.poseidon_bn254_cost_per_block = Some(10);
2072
2073 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2074
2075 cfg.feature_flags.enable_vdf = true;
2076 cfg.vdf_verify_vdf_cost = Some(1500);
2079 cfg.vdf_hash_to_input_cost = Some(100);
2080
2081 cfg.feature_flags.passkey_auth = true;
2082 }
2083
2084 for cur in 2..=version.0 {
2085 match cur {
2086 1 => unreachable!(),
2087 2 => {}
2089 3 => {
2090 cfg.feature_flags.relocate_event_module = true;
2091 }
2092 4 => {
2093 cfg.max_type_to_layout_nodes = Some(512);
2094 }
2095 5 => {
2096 cfg.feature_flags.protocol_defined_base_fee = true;
2097 cfg.base_gas_price = Some(1000);
2098
2099 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2100 cfg.feature_flags.convert_type_argument_error = true;
2101 cfg.feature_flags.native_charging_v2 = true;
2102
2103 if chain != Chain::Mainnet && chain != Chain::Testnet {
2104 cfg.feature_flags.uncompressed_g1_group_elements = true;
2105 }
2106
2107 cfg.gas_model_version = Some(2);
2108
2109 cfg.poseidon_bn254_cost_per_block = Some(388);
2110
2111 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2112 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2113 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2114 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2115 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2116 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2117 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2118 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2119
2120 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2122 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2123 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2124 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2125
2126 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2127 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2128 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2129 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2130 Some(8213);
2131 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2132 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2133 Some(9484);
2134
2135 cfg.hash_keccak256_cost_base = Some(10);
2136 cfg.hash_blake2b256_cost_base = Some(10);
2137
2138 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2140 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2141 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2142 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2143
2144 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2145 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2146 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2147 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2148
2149 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2150 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2151 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2152 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2153
2154 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2155 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2156 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2157 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2158
2159 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2160 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2161 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2162 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2163
2164 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2165 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2166
2167 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2168 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2169 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2170 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2171
2172 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2173 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2174 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2175 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2176 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2177
2178 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2179
2180 cfg.validator_validate_metadata_cost_base = Some(20000);
2181
2182 cfg.max_committee_members_count = Some(50);
2183 }
2184 6 => {
2185 cfg.max_ptb_value_size = Some(1024 * 1024);
2186 }
2187 7 => {
2188 }
2191 8 => {
2192 cfg.feature_flags.variant_nodes = true;
2193
2194 if chain != Chain::Mainnet {
2195 cfg.feature_flags.consensus_round_prober = true;
2197 cfg.feature_flags
2199 .consensus_distributed_vote_scoring_strategy = true;
2200 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2201 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2203 cfg.feature_flags
2205 .consensus_round_prober_probe_accepted_rounds = true;
2206 cfg.feature_flags.consensus_zstd_compression = true;
2208 cfg.consensus_gc_depth = Some(60);
2212 }
2213
2214 if chain != Chain::Testnet && chain != Chain::Mainnet {
2217 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2218 }
2219 }
2220 9 => {
2221 if chain != Chain::Mainnet {
2222 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2224 }
2225
2226 cfg.feature_flags.consensus_zstd_compression = true;
2228
2229 if chain != Chain::Testnet && chain != Chain::Mainnet {
2231 cfg.feature_flags.accept_passkey_in_multisig = true;
2232 }
2233
2234 cfg.bridge_should_try_to_finalize_committee = None;
2236 }
2237 10 => {
2238 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2241
2242 cfg.max_committee_members_count = Some(80);
2244
2245 cfg.feature_flags.consensus_round_prober = true;
2247 cfg.feature_flags
2249 .consensus_round_prober_probe_accepted_rounds = true;
2250 cfg.feature_flags
2252 .consensus_distributed_vote_scoring_strategy = true;
2253 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2255
2256 cfg.consensus_gc_depth = Some(60);
2261
2262 cfg.feature_flags.minimize_child_object_mutations = true;
2264
2265 if chain != Chain::Mainnet {
2266 cfg.feature_flags.consensus_batched_block_sync = true;
2268 }
2269
2270 if chain != Chain::Testnet && chain != Chain::Mainnet {
2271 cfg.feature_flags
2274 .congestion_control_gas_price_feedback_mechanism = true;
2275 }
2276
2277 cfg.feature_flags.validate_identifier_inputs = true;
2278 cfg.feature_flags.dependency_linkage_error = true;
2279 cfg.feature_flags.additional_multisig_checks = true;
2280 }
2281 11 => {
2282 }
2285 12 => {
2286 cfg.feature_flags
2289 .congestion_control_gas_price_feedback_mechanism = true;
2290
2291 cfg.feature_flags.normalize_ptb_arguments = true;
2293 }
2294 13 => {
2295 cfg.feature_flags.select_committee_from_eligible_validators = true;
2298 cfg.feature_flags.track_non_committee_eligible_validators = true;
2301
2302 if chain != Chain::Testnet && chain != Chain::Mainnet {
2303 cfg.feature_flags
2306 .select_committee_supporting_next_epoch_version = true;
2307 }
2308 }
2309 14 => {
2310 cfg.feature_flags.consensus_batched_block_sync = true;
2312
2313 if chain != Chain::Mainnet {
2314 cfg.feature_flags
2317 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2318 cfg.feature_flags
2322 .select_committee_supporting_next_epoch_version = true;
2323 }
2324 if chain != Chain::Testnet && chain != Chain::Mainnet {
2325 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2327 }
2328 }
2329 15 => {
2330 if chain != Chain::Mainnet && chain != Chain::Testnet {
2331 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2335 }
2336 }
2337 16 => {
2338 cfg.feature_flags
2341 .select_committee_supporting_next_epoch_version = true;
2342 cfg.feature_flags
2344 .consensus_commit_transactions_only_for_traversed_headers = true;
2345 }
2346 17 => {
2347 cfg.max_committee_members_count = Some(100);
2349 }
2350 18 => {
2351 if chain != Chain::Mainnet {
2352 cfg.feature_flags.passkey_auth = true;
2354 }
2355 }
2356 19 => {
2357 if chain != Chain::Testnet && chain != Chain::Mainnet {
2358 cfg.feature_flags
2361 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2362 cfg.feature_flags
2365 .separate_gas_price_feedback_mechanism_for_randomness = true;
2366 }
2367 }
2368 _ => panic!("unsupported version {version:?}"),
2379 }
2380 }
2381 cfg
2382 }
2383
2384 pub fn verifier_config(&self, signing_limits: Option<(usize, usize)>) -> VerifierConfig {
2388 let (max_back_edges_per_function, max_back_edges_per_module) = if let Some((
2389 max_back_edges_per_function,
2390 max_back_edges_per_module,
2391 )) = signing_limits
2392 {
2393 (
2394 Some(max_back_edges_per_function),
2395 Some(max_back_edges_per_module),
2396 )
2397 } else {
2398 (None, None)
2399 };
2400
2401 VerifierConfig {
2402 max_loop_depth: Some(self.max_loop_depth() as usize),
2403 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2404 max_function_parameters: Some(self.max_function_parameters() as usize),
2405 max_basic_blocks: Some(self.max_basic_blocks() as usize),
2406 max_value_stack_size: self.max_value_stack_size() as usize,
2407 max_type_nodes: Some(self.max_type_nodes() as usize),
2408 max_push_size: Some(self.max_push_size() as usize),
2409 max_dependency_depth: Some(self.max_dependency_depth() as usize),
2410 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2411 max_function_definitions: Some(self.max_function_definitions() as usize),
2412 max_data_definitions: Some(self.max_struct_definitions() as usize),
2413 max_constant_vector_len: Some(self.max_move_vector_len()),
2414 max_back_edges_per_function,
2415 max_back_edges_per_module,
2416 max_basic_blocks_in_script: None,
2417 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
2421 max_variants_in_enum: self.max_move_enum_variants_as_option(),
2422 }
2423 }
2424
2425 pub fn apply_overrides_for_testing(
2430 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
2431 ) -> OverrideGuard {
2432 CONFIG_OVERRIDE.with(|ovr| {
2433 let mut cur = ovr.borrow_mut();
2434 assert!(cur.is_none(), "config override already present");
2435 *cur = Some(Box::new(override_fn));
2436 OverrideGuard
2437 })
2438 }
2439}
2440
2441impl ProtocolConfig {
2446 pub fn set_zklogin_auth_for_testing(&mut self, val: bool) {
2447 self.feature_flags.zklogin_auth = val
2448 }
2449 pub fn set_enable_jwk_consensus_updates_for_testing(&mut self, val: bool) {
2450 self.feature_flags.enable_jwk_consensus_updates = val
2451 }
2452
2453 pub fn set_accept_zklogin_in_multisig_for_testing(&mut self, val: bool) {
2454 self.feature_flags.accept_zklogin_in_multisig = val
2455 }
2456
2457 pub fn set_per_object_congestion_control_mode_for_testing(
2458 &mut self,
2459 val: PerObjectCongestionControlMode,
2460 ) {
2461 self.feature_flags.per_object_congestion_control_mode = val;
2462 }
2463
2464 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
2465 self.feature_flags.consensus_choice = val;
2466 }
2467
2468 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
2469 self.feature_flags.consensus_network = val;
2470 }
2471
2472 pub fn set_zklogin_max_epoch_upper_bound_delta_for_testing(&mut self, val: Option<u64>) {
2473 self.feature_flags.zklogin_max_epoch_upper_bound_delta = val
2474 }
2475
2476 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
2477 self.feature_flags.passkey_auth = val
2478 }
2479
2480 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
2481 self.feature_flags
2482 .disallow_new_modules_in_deps_only_packages = val;
2483 }
2484
2485 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
2486 self.feature_flags.consensus_round_prober = val;
2487 }
2488
2489 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
2490 self.feature_flags
2491 .consensus_distributed_vote_scoring_strategy = val;
2492 }
2493
2494 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
2495 self.consensus_gc_depth = Some(val);
2496 }
2497
2498 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
2499 self.feature_flags.consensus_linearize_subdag_v2 = val;
2500 }
2501
2502 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
2503 self.feature_flags
2504 .consensus_round_prober_probe_accepted_rounds = val;
2505 }
2506
2507 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
2508 self.feature_flags.accept_passkey_in_multisig = val;
2509 }
2510
2511 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
2512 self.feature_flags.consensus_smart_ancestor_selection = val;
2513 }
2514
2515 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
2516 self.feature_flags.consensus_batched_block_sync = val;
2517 }
2518
2519 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
2520 self.feature_flags
2521 .congestion_control_min_free_execution_slot = val;
2522 }
2523
2524 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
2525 self.feature_flags
2526 .congestion_control_gas_price_feedback_mechanism = val;
2527 }
2528
2529 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
2530 self.feature_flags.select_committee_from_eligible_validators = val;
2531 }
2532
2533 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
2534 self.feature_flags.track_non_committee_eligible_validators = val;
2535 }
2536
2537 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
2538 self.feature_flags
2539 .select_committee_supporting_next_epoch_version = val;
2540 }
2541
2542 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
2543 &mut self,
2544 val: bool,
2545 ) {
2546 self.feature_flags
2547 .consensus_median_timestamp_with_checkpoint_enforcement = val;
2548 }
2549
2550 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
2551 &mut self,
2552 val: bool,
2553 ) {
2554 self.feature_flags
2555 .consensus_commit_transactions_only_for_traversed_headers = val;
2556 }
2557
2558 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
2559 &mut self,
2560 val: bool,
2561 ) {
2562 self.feature_flags
2563 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
2564 }
2565
2566 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
2567 &mut self,
2568 val: bool,
2569 ) {
2570 self.feature_flags
2571 .separate_gas_price_feedback_mechanism_for_randomness = val;
2572 }
2573}
2574
2575type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
2576
2577thread_local! {
2578 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
2579}
2580
2581#[must_use]
2582pub struct OverrideGuard;
2583
2584impl Drop for OverrideGuard {
2585 fn drop(&mut self) {
2586 info!("restoring override fn");
2587 CONFIG_OVERRIDE.with(|ovr| {
2588 *ovr.borrow_mut() = None;
2589 });
2590 }
2591}
2592
2593#[derive(PartialEq, Eq)]
2597pub enum LimitThresholdCrossed {
2598 None,
2599 Soft(u128, u128),
2600 Hard(u128, u128),
2601}
2602
2603pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
2606 x: T,
2607 soft_limit: U,
2608 hard_limit: V,
2609) -> LimitThresholdCrossed {
2610 let x: V = x.into();
2611 let soft_limit: V = soft_limit.into();
2612
2613 debug_assert!(soft_limit <= hard_limit);
2614
2615 if x >= hard_limit {
2618 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
2619 } else if x < soft_limit {
2620 LimitThresholdCrossed::None
2621 } else {
2622 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
2623 }
2624}
2625
2626#[macro_export]
2627macro_rules! check_limit {
2628 ($x:expr, $hard:expr) => {
2629 check_limit!($x, $hard, $hard)
2630 };
2631 ($x:expr, $soft:expr, $hard:expr) => {
2632 check_limit_in_range($x as u64, $soft, $hard)
2633 };
2634}
2635
2636#[macro_export]
2640macro_rules! check_limit_by_meter {
2641 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
2642 let (h, metered_str) = if $is_metered {
2644 ($metered_limit, "metered")
2645 } else {
2646 ($unmetered_hard_limit, "unmetered")
2648 };
2649 use iota_protocol_config::check_limit_in_range;
2650 let result = check_limit_in_range($x as u64, $metered_limit, h);
2651 match result {
2652 LimitThresholdCrossed::None => {}
2653 LimitThresholdCrossed::Soft(_, _) => {
2654 $metric.with_label_values(&[metered_str, "soft"]).inc();
2655 }
2656 LimitThresholdCrossed::Hard(_, _) => {
2657 $metric.with_label_values(&[metered_str, "hard"]).inc();
2658 }
2659 };
2660 result
2661 }};
2662}
2663
2664#[cfg(all(test, not(msim)))]
2665mod test {
2666 use insta::assert_yaml_snapshot;
2667
2668 use super::*;
2669
2670 #[test]
2671 fn snapshot_tests() {
2672 println!("\n============================================================================");
2673 println!("! !");
2674 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
2675 println!("! !");
2676 println!("============================================================================\n");
2677 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
2678 let chain_str = match chain_id {
2683 Chain::Unknown => "".to_string(),
2684 _ => format!("{chain_id:?}_"),
2685 };
2686 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
2687 let cur = ProtocolVersion::new(i);
2688 assert_yaml_snapshot!(
2689 format!("{}version_{}", chain_str, cur.as_u64()),
2690 ProtocolConfig::get_for_version(cur, *chain_id)
2691 );
2692 }
2693 }
2694 }
2695
2696 #[test]
2697 fn test_getters() {
2698 let prot: ProtocolConfig =
2699 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2700 assert_eq!(
2701 prot.max_arguments(),
2702 prot.max_arguments_as_option().unwrap()
2703 );
2704 }
2705
2706 #[test]
2707 fn test_setters() {
2708 let mut prot: ProtocolConfig =
2709 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2710 prot.set_max_arguments_for_testing(123);
2711 assert_eq!(prot.max_arguments(), 123);
2712
2713 prot.set_max_arguments_from_str_for_testing("321".to_string());
2714 assert_eq!(prot.max_arguments(), 321);
2715
2716 prot.disable_max_arguments_for_testing();
2717 assert_eq!(prot.max_arguments_as_option(), None);
2718
2719 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
2720 assert_eq!(prot.max_arguments(), 456);
2721 }
2722
2723 #[test]
2724 #[should_panic(expected = "unsupported version")]
2725 fn max_version_test() {
2726 let _ = ProtocolConfig::get_for_version_impl(
2729 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
2730 Chain::Unknown,
2731 );
2732 }
2733
2734 #[test]
2735 fn lookup_by_string_test() {
2736 let prot: ProtocolConfig =
2737 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2738 assert!(prot.lookup_attr("some random string".to_string()).is_none());
2740
2741 assert!(
2742 prot.lookup_attr("max_arguments".to_string())
2743 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
2744 );
2745
2746 assert!(
2748 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2749 .is_none()
2750 );
2751 assert!(
2752 prot.attr_map()
2753 .get("poseidon_bn254_cost_base")
2754 .unwrap()
2755 .is_none()
2756 );
2757
2758 let prot: ProtocolConfig =
2760 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2761
2762 assert!(
2763 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2764 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2765 );
2766 assert!(
2767 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
2768 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2769 );
2770
2771 let prot: ProtocolConfig =
2773 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2774 assert!(
2776 prot.feature_flags
2777 .lookup_attr("some random string".to_owned())
2778 .is_none()
2779 );
2780 assert!(
2781 !prot
2782 .feature_flags
2783 .attr_map()
2784 .contains_key("some random string")
2785 );
2786
2787 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
2789 assert!(
2790 prot.feature_flags
2791 .attr_map()
2792 .get("enable_poseidon")
2793 .unwrap()
2794 == &false
2795 );
2796 let prot: ProtocolConfig =
2797 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2798 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
2800 assert!(
2801 prot.feature_flags
2802 .attr_map()
2803 .get("enable_poseidon")
2804 .unwrap()
2805 == &true
2806 );
2807 }
2808
2809 #[test]
2810 fn limit_range_fn_test() {
2811 let low = 100u32;
2812 let high = 10000u64;
2813
2814 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
2815 assert!(matches!(
2816 check_limit!(255u16, low, high),
2817 LimitThresholdCrossed::Soft(255u128, 100)
2818 ));
2819 assert!(matches!(
2826 check_limit!(2550000u64, low, high),
2827 LimitThresholdCrossed::Hard(2550000, 10000)
2828 ));
2829
2830 assert!(matches!(
2831 check_limit!(2550000u64, high, high),
2832 LimitThresholdCrossed::Hard(2550000, 10000)
2833 ));
2834
2835 assert!(matches!(
2836 check_limit!(1u8, high),
2837 LimitThresholdCrossed::None
2838 ));
2839
2840 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
2841
2842 assert!(matches!(
2843 check_limit!(2550000u64, high),
2844 LimitThresholdCrossed::Hard(2550000, 10000)
2845 ));
2846 }
2847}