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 = 15;
23
24#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
90pub struct ProtocolVersion(u64);
91
92impl ProtocolVersion {
93 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
99
100 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
101
102 #[cfg(not(msim))]
103 const MAX_ALLOWED: Self = Self::MAX;
104
105 #[cfg(msim)]
108 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
109
110 pub fn new(v: u64) -> Self {
111 Self(v)
112 }
113
114 pub const fn as_u64(&self) -> u64 {
115 self.0
116 }
117
118 pub fn max() -> Self {
121 Self::MAX
122 }
123}
124
125impl From<u64> for ProtocolVersion {
126 fn from(v: u64) -> Self {
127 Self::new(v)
128 }
129}
130
131impl std::ops::Sub<u64> for ProtocolVersion {
132 type Output = Self;
133 fn sub(self, rhs: u64) -> Self::Output {
134 Self::new(self.0 - rhs)
135 }
136}
137
138impl std::ops::Add<u64> for ProtocolVersion {
139 type Output = Self;
140 fn add(self, rhs: u64) -> Self::Output {
141 Self::new(self.0 + rhs)
142 }
143}
144
145#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum)]
146pub enum Chain {
147 Mainnet,
148 Testnet,
149 Unknown,
150}
151
152impl Default for Chain {
153 fn default() -> Self {
154 Self::Unknown
155 }
156}
157
158impl Chain {
159 pub fn as_str(self) -> &'static str {
160 match self {
161 Chain::Mainnet => "mainnet",
162 Chain::Testnet => "testnet",
163 Chain::Unknown => "unknown",
164 }
165 }
166}
167
168pub struct Error(pub String);
169
170#[derive(Default, Clone, Serialize, Deserialize, Debug, ProtocolConfigFeatureFlagsGetters)]
174struct FeatureFlags {
175 #[serde(skip_serializing_if = "is_true")]
181 disable_invariant_violation_check_in_swap_loc: bool,
182
183 #[serde(skip_serializing_if = "is_true")]
186 no_extraneous_module_bytes: bool,
187
188 #[serde(skip_serializing_if = "is_false")]
190 zklogin_auth: bool,
191
192 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
194 consensus_transaction_ordering: ConsensusTransactionOrdering,
195
196 #[serde(skip_serializing_if = "is_false")]
197 enable_jwk_consensus_updates: bool,
198
199 #[serde(skip_serializing_if = "is_false")]
201 accept_zklogin_in_multisig: bool,
202
203 #[serde(skip_serializing_if = "is_true")]
206 hardened_otw_check: bool,
207
208 #[serde(skip_serializing_if = "is_false")]
210 enable_poseidon: bool,
211
212 #[serde(skip_serializing_if = "is_false")]
214 enable_group_ops_native_function_msm: bool,
215
216 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
218 per_object_congestion_control_mode: PerObjectCongestionControlMode,
219
220 #[serde(skip_serializing_if = "ConsensusChoice::is_mysticeti")]
222 consensus_choice: ConsensusChoice,
223
224 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
226 consensus_network: ConsensusNetwork,
227
228 #[serde(skip_serializing_if = "Option::is_none")]
230 zklogin_max_epoch_upper_bound_delta: Option<u64>,
231
232 #[serde(skip_serializing_if = "is_false")]
234 enable_vdf: bool,
235
236 #[serde(skip_serializing_if = "is_false")]
238 passkey_auth: bool,
239
240 #[serde(skip_serializing_if = "is_true")]
243 rethrow_serialization_type_layout_errors: bool,
244
245 #[serde(skip_serializing_if = "is_false")]
247 relocate_event_module: bool,
248
249 #[serde(skip_serializing_if = "is_false")]
251 protocol_defined_base_fee: bool,
252
253 #[serde(skip_serializing_if = "is_false")]
255 uncompressed_g1_group_elements: bool,
256
257 #[serde(skip_serializing_if = "is_false")]
259 disallow_new_modules_in_deps_only_packages: bool,
260
261 #[serde(skip_serializing_if = "is_false")]
263 native_charging_v2: bool,
264
265 #[serde(skip_serializing_if = "is_false")]
267 convert_type_argument_error: bool,
268
269 #[serde(skip_serializing_if = "is_false")]
271 consensus_round_prober: bool,
272
273 #[serde(skip_serializing_if = "is_false")]
275 consensus_distributed_vote_scoring_strategy: bool,
276
277 #[serde(skip_serializing_if = "is_false")]
281 consensus_linearize_subdag_v2: bool,
282
283 #[serde(skip_serializing_if = "is_false")]
285 variant_nodes: bool,
286
287 #[serde(skip_serializing_if = "is_false")]
289 consensus_smart_ancestor_selection: bool,
290
291 #[serde(skip_serializing_if = "is_false")]
293 consensus_round_prober_probe_accepted_rounds: bool,
294
295 #[serde(skip_serializing_if = "is_false")]
297 consensus_zstd_compression: bool,
298
299 #[serde(skip_serializing_if = "is_false")]
302 congestion_control_min_free_execution_slot: bool,
303
304 #[serde(skip_serializing_if = "is_false")]
306 accept_passkey_in_multisig: bool,
307
308 #[serde(skip_serializing_if = "is_false")]
310 consensus_batched_block_sync: bool,
311
312 #[serde(skip_serializing_if = "is_false")]
315 congestion_control_gas_price_feedback_mechanism: bool,
316
317 #[serde(skip_serializing_if = "is_false")]
319 validate_identifier_inputs: bool,
320
321 #[serde(skip_serializing_if = "is_false")]
324 minimize_child_object_mutations: bool,
325
326 #[serde(skip_serializing_if = "is_false")]
328 dependency_linkage_error: bool,
329
330 #[serde(skip_serializing_if = "is_false")]
332 additional_multisig_checks: bool,
333
334 #[serde(skip_serializing_if = "is_false")]
337 normalize_ptb_arguments: bool,
338
339 #[serde(skip_serializing_if = "is_false")]
343 select_committee_from_eligible_validators: bool,
344
345 #[serde(skip_serializing_if = "is_false")]
352 track_non_committee_eligible_validators: bool,
353
354 #[serde(skip_serializing_if = "is_false")]
360 select_committee_supporting_next_epoch_version: bool,
361
362 #[serde(skip_serializing_if = "is_false")]
366 consensus_median_timestamp_with_checkpoint_enforcement: bool,
367}
368
369fn is_true(b: &bool) -> bool {
370 *b
371}
372
373fn is_false(b: &bool) -> bool {
374 !b
375}
376
377#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
379pub enum ConsensusTransactionOrdering {
380 #[default]
383 None,
384 ByGasPrice,
386}
387
388impl ConsensusTransactionOrdering {
389 pub fn is_none(&self) -> bool {
390 matches!(self, ConsensusTransactionOrdering::None)
391 }
392}
393
394#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
396pub enum PerObjectCongestionControlMode {
397 #[default]
398 None, TotalGasBudget, TotalTxCount, }
402
403impl PerObjectCongestionControlMode {
404 pub fn is_none(&self) -> bool {
405 matches!(self, PerObjectCongestionControlMode::None)
406 }
407}
408
409#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
411pub enum ConsensusChoice {
412 #[default]
413 Mysticeti,
414 Starfish,
415}
416
417impl ConsensusChoice {
418 pub fn is_mysticeti(&self) -> bool {
419 matches!(self, ConsensusChoice::Mysticeti)
420 }
421 pub fn is_starfish(&self) -> bool {
422 matches!(self, ConsensusChoice::Starfish)
423 }
424}
425
426#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
428pub enum ConsensusNetwork {
429 #[default]
430 Tonic,
431}
432
433impl ConsensusNetwork {
434 pub fn is_tonic(&self) -> bool {
435 matches!(self, ConsensusNetwork::Tonic)
436 }
437}
438
439#[skip_serializing_none]
473#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
474pub struct ProtocolConfig {
475 pub version: ProtocolVersion,
476
477 feature_flags: FeatureFlags,
478
479 max_tx_size_bytes: Option<u64>,
484
485 max_input_objects: Option<u64>,
488
489 max_size_written_objects: Option<u64>,
494 max_size_written_objects_system_tx: Option<u64>,
498
499 max_serialized_tx_effects_size_bytes: Option<u64>,
501
502 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
504
505 max_gas_payment_objects: Option<u32>,
507
508 max_modules_in_publish: Option<u32>,
510
511 max_package_dependencies: Option<u32>,
513
514 max_arguments: Option<u32>,
517
518 max_type_arguments: Option<u32>,
520
521 max_type_argument_depth: Option<u32>,
523
524 max_pure_argument_size: Option<u32>,
526
527 max_programmable_tx_commands: Option<u32>,
529
530 move_binary_format_version: Option<u32>,
536 min_move_binary_format_version: Option<u32>,
537
538 binary_module_handles: Option<u16>,
540 binary_struct_handles: Option<u16>,
541 binary_function_handles: Option<u16>,
542 binary_function_instantiations: Option<u16>,
543 binary_signatures: Option<u16>,
544 binary_constant_pool: Option<u16>,
545 binary_identifiers: Option<u16>,
546 binary_address_identifiers: Option<u16>,
547 binary_struct_defs: Option<u16>,
548 binary_struct_def_instantiations: Option<u16>,
549 binary_function_defs: Option<u16>,
550 binary_field_handles: Option<u16>,
551 binary_field_instantiations: Option<u16>,
552 binary_friend_decls: Option<u16>,
553 binary_enum_defs: Option<u16>,
554 binary_enum_def_instantiations: Option<u16>,
555 binary_variant_handles: Option<u16>,
556 binary_variant_instantiation_handles: Option<u16>,
557
558 max_move_object_size: Option<u64>,
561
562 max_move_package_size: Option<u64>,
567
568 max_publish_or_upgrade_per_ptb: Option<u64>,
571
572 max_tx_gas: Option<u64>,
574
575 max_gas_price: Option<u64>,
578
579 max_gas_computation_bucket: Option<u64>,
582
583 gas_rounding_step: Option<u64>,
585
586 max_loop_depth: Option<u64>,
588
589 max_generic_instantiation_length: Option<u64>,
592
593 max_function_parameters: Option<u64>,
596
597 max_basic_blocks: Option<u64>,
600
601 max_value_stack_size: Option<u64>,
603
604 max_type_nodes: Option<u64>,
608
609 max_push_size: Option<u64>,
612
613 max_struct_definitions: Option<u64>,
616
617 max_function_definitions: Option<u64>,
620
621 max_fields_in_struct: Option<u64>,
624
625 max_dependency_depth: Option<u64>,
628
629 max_num_event_emit: Option<u64>,
632
633 max_num_new_move_object_ids: Option<u64>,
636
637 max_num_new_move_object_ids_system_tx: Option<u64>,
640
641 max_num_deleted_move_object_ids: Option<u64>,
644
645 max_num_deleted_move_object_ids_system_tx: Option<u64>,
648
649 max_num_transferred_move_object_ids: Option<u64>,
652
653 max_num_transferred_move_object_ids_system_tx: Option<u64>,
656
657 max_event_emit_size: Option<u64>,
659
660 max_event_emit_size_total: Option<u64>,
662
663 max_move_vector_len: Option<u64>,
666
667 max_move_identifier_len: Option<u64>,
670
671 max_move_value_depth: Option<u64>,
673
674 max_move_enum_variants: Option<u64>,
677
678 max_back_edges_per_function: Option<u64>,
681
682 max_back_edges_per_module: Option<u64>,
685
686 max_verifier_meter_ticks_per_function: Option<u64>,
689
690 max_meter_ticks_per_module: Option<u64>,
693
694 max_meter_ticks_per_package: Option<u64>,
697
698 object_runtime_max_num_cached_objects: Option<u64>,
705
706 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
709
710 object_runtime_max_num_store_entries: Option<u64>,
713
714 object_runtime_max_num_store_entries_system_tx: Option<u64>,
717
718 base_tx_cost_fixed: Option<u64>,
723
724 package_publish_cost_fixed: Option<u64>,
728
729 base_tx_cost_per_byte: Option<u64>,
733
734 package_publish_cost_per_byte: Option<u64>,
736
737 obj_access_cost_read_per_byte: Option<u64>,
739
740 obj_access_cost_mutate_per_byte: Option<u64>,
742
743 obj_access_cost_delete_per_byte: Option<u64>,
745
746 obj_access_cost_verify_per_byte: Option<u64>,
756
757 max_type_to_layout_nodes: Option<u64>,
759
760 max_ptb_value_size: Option<u64>,
762
763 gas_model_version: Option<u64>,
768
769 obj_data_cost_refundable: Option<u64>,
775
776 obj_metadata_cost_non_refundable: Option<u64>,
780
781 storage_rebate_rate: Option<u64>,
787
788 reward_slashing_rate: Option<u64>,
791
792 storage_gas_price: Option<u64>,
794
795 base_gas_price: Option<u64>,
797
798 validator_target_reward: Option<u64>,
800
801 max_transactions_per_checkpoint: Option<u64>,
808
809 max_checkpoint_size_bytes: Option<u64>,
813
814 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
820
821 address_from_bytes_cost_base: Option<u64>,
826 address_to_u256_cost_base: Option<u64>,
828 address_from_u256_cost_base: Option<u64>,
830
831 config_read_setting_impl_cost_base: Option<u64>,
836 config_read_setting_impl_cost_per_byte: Option<u64>,
837
838 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
842 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
843 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
844 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
845 dynamic_field_add_child_object_cost_base: Option<u64>,
848 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
849 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
850 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
851 dynamic_field_borrow_child_object_cost_base: Option<u64>,
854 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
855 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
856 dynamic_field_remove_child_object_cost_base: Option<u64>,
859 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
860 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
861 dynamic_field_has_child_object_cost_base: Option<u64>,
864 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
867 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
868 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
869
870 event_emit_cost_base: Option<u64>,
873 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
874 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
875 event_emit_output_cost_per_byte: Option<u64>,
876
877 object_borrow_uid_cost_base: Option<u64>,
880 object_delete_impl_cost_base: Option<u64>,
882 object_record_new_uid_cost_base: Option<u64>,
884
885 transfer_transfer_internal_cost_base: Option<u64>,
888 transfer_freeze_object_cost_base: Option<u64>,
890 transfer_share_object_cost_base: Option<u64>,
892 transfer_receive_object_cost_base: Option<u64>,
895
896 tx_context_derive_id_cost_base: Option<u64>,
899
900 types_is_one_time_witness_cost_base: Option<u64>,
903 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
904 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
905
906 validator_validate_metadata_cost_base: Option<u64>,
909 validator_validate_metadata_data_cost_per_byte: Option<u64>,
910
911 crypto_invalid_arguments_cost: Option<u64>,
913 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
915 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
916 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
917
918 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
920 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
921 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
922
923 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
925 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
926 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
927 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
928 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
929 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
930
931 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
933
934 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
936 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
937 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
938 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
939 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
940 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
941
942 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
944 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
945 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
946 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
947 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
948 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
949
950 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
952 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
953 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
954 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
955 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
956 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
957
958 ecvrf_ecvrf_verify_cost_base: Option<u64>,
960 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
961 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
962
963 ed25519_ed25519_verify_cost_base: Option<u64>,
965 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
966 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
967
968 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
970 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
971
972 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
974 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
975 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
976 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
977 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
978
979 hash_blake2b256_cost_base: Option<u64>,
981 hash_blake2b256_data_cost_per_byte: Option<u64>,
982 hash_blake2b256_data_cost_per_block: Option<u64>,
983
984 hash_keccak256_cost_base: Option<u64>,
986 hash_keccak256_data_cost_per_byte: Option<u64>,
987 hash_keccak256_data_cost_per_block: Option<u64>,
988
989 poseidon_bn254_cost_base: Option<u64>,
991 poseidon_bn254_cost_per_block: Option<u64>,
992
993 group_ops_bls12381_decode_scalar_cost: Option<u64>,
995 group_ops_bls12381_decode_g1_cost: Option<u64>,
996 group_ops_bls12381_decode_g2_cost: Option<u64>,
997 group_ops_bls12381_decode_gt_cost: Option<u64>,
998 group_ops_bls12381_scalar_add_cost: Option<u64>,
999 group_ops_bls12381_g1_add_cost: Option<u64>,
1000 group_ops_bls12381_g2_add_cost: Option<u64>,
1001 group_ops_bls12381_gt_add_cost: Option<u64>,
1002 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1003 group_ops_bls12381_g1_sub_cost: Option<u64>,
1004 group_ops_bls12381_g2_sub_cost: Option<u64>,
1005 group_ops_bls12381_gt_sub_cost: Option<u64>,
1006 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1007 group_ops_bls12381_g1_mul_cost: Option<u64>,
1008 group_ops_bls12381_g2_mul_cost: Option<u64>,
1009 group_ops_bls12381_gt_mul_cost: Option<u64>,
1010 group_ops_bls12381_scalar_div_cost: Option<u64>,
1011 group_ops_bls12381_g1_div_cost: Option<u64>,
1012 group_ops_bls12381_g2_div_cost: Option<u64>,
1013 group_ops_bls12381_gt_div_cost: Option<u64>,
1014 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1015 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1016 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1017 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1018 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1019 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1020 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1021 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1022 group_ops_bls12381_msm_max_len: Option<u32>,
1023 group_ops_bls12381_pairing_cost: Option<u64>,
1024 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1025 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1026 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1027 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1028 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1029
1030 hmac_hmac_sha3_256_cost_base: Option<u64>,
1032 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1033 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1034
1035 check_zklogin_id_cost_base: Option<u64>,
1037 check_zklogin_issuer_cost_base: Option<u64>,
1039
1040 vdf_verify_vdf_cost: Option<u64>,
1041 vdf_hash_to_input_cost: Option<u64>,
1042
1043 bcs_per_byte_serialized_cost: Option<u64>,
1045 bcs_legacy_min_output_size_cost: Option<u64>,
1046 bcs_failure_cost: Option<u64>,
1047
1048 hash_sha2_256_base_cost: Option<u64>,
1049 hash_sha2_256_per_byte_cost: Option<u64>,
1050 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1051 hash_sha3_256_base_cost: Option<u64>,
1052 hash_sha3_256_per_byte_cost: Option<u64>,
1053 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1054 type_name_get_base_cost: Option<u64>,
1055 type_name_get_per_byte_cost: Option<u64>,
1056
1057 string_check_utf8_base_cost: Option<u64>,
1058 string_check_utf8_per_byte_cost: Option<u64>,
1059 string_is_char_boundary_base_cost: Option<u64>,
1060 string_sub_string_base_cost: Option<u64>,
1061 string_sub_string_per_byte_cost: Option<u64>,
1062 string_index_of_base_cost: Option<u64>,
1063 string_index_of_per_byte_pattern_cost: Option<u64>,
1064 string_index_of_per_byte_searched_cost: Option<u64>,
1065
1066 vector_empty_base_cost: Option<u64>,
1067 vector_length_base_cost: Option<u64>,
1068 vector_push_back_base_cost: Option<u64>,
1069 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1070 vector_borrow_base_cost: Option<u64>,
1071 vector_pop_back_base_cost: Option<u64>,
1072 vector_destroy_empty_base_cost: Option<u64>,
1073 vector_swap_base_cost: Option<u64>,
1074 debug_print_base_cost: Option<u64>,
1075 debug_print_stack_trace_base_cost: Option<u64>,
1076
1077 execution_version: Option<u64>,
1079
1080 consensus_bad_nodes_stake_threshold: Option<u64>,
1084
1085 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1086 max_age_of_jwk_in_epochs: Option<u64>,
1090
1091 random_beacon_reduction_allowed_delta: Option<u16>,
1095
1096 random_beacon_reduction_lower_bound: Option<u32>,
1099
1100 random_beacon_dkg_timeout_round: Option<u32>,
1103
1104 random_beacon_min_round_interval_ms: Option<u64>,
1106
1107 random_beacon_dkg_version: Option<u64>,
1111
1112 consensus_max_transaction_size_bytes: Option<u64>,
1117 consensus_max_transactions_in_block_bytes: Option<u64>,
1119 consensus_max_num_transactions_in_block: Option<u64>,
1121
1122 max_deferral_rounds_for_congestion_control: Option<u64>,
1126
1127 min_checkpoint_interval_ms: Option<u64>,
1129
1130 checkpoint_summary_version_specific_data: Option<u64>,
1132
1133 max_soft_bundle_size: Option<u64>,
1136
1137 bridge_should_try_to_finalize_committee: Option<bool>,
1142
1143 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1149
1150 max_committee_members_count: Option<u64>,
1154
1155 consensus_gc_depth: Option<u32>,
1158
1159 consensus_max_acknowledgments_per_block: Option<u32>,
1165
1166 max_congestion_limit_overshoot_per_commit: Option<u64>,
1171}
1172
1173impl ProtocolConfig {
1175 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1188 self.feature_flags
1189 .disable_invariant_violation_check_in_swap_loc
1190 }
1191
1192 pub fn no_extraneous_module_bytes(&self) -> bool {
1193 self.feature_flags.no_extraneous_module_bytes
1194 }
1195
1196 pub fn zklogin_auth(&self) -> bool {
1197 self.feature_flags.zklogin_auth
1198 }
1199
1200 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1201 self.feature_flags.consensus_transaction_ordering
1202 }
1203
1204 pub fn enable_jwk_consensus_updates(&self) -> bool {
1205 self.feature_flags.enable_jwk_consensus_updates
1206 }
1207
1208 pub fn create_authenticator_state_in_genesis(&self) -> bool {
1210 self.enable_jwk_consensus_updates()
1211 }
1212
1213 pub fn dkg_version(&self) -> u64 {
1214 self.random_beacon_dkg_version.unwrap_or(1)
1216 }
1217
1218 pub fn accept_zklogin_in_multisig(&self) -> bool {
1219 self.feature_flags.accept_zklogin_in_multisig
1220 }
1221
1222 pub fn zklogin_max_epoch_upper_bound_delta(&self) -> Option<u64> {
1223 self.feature_flags.zklogin_max_epoch_upper_bound_delta
1224 }
1225
1226 pub fn hardened_otw_check(&self) -> bool {
1227 self.feature_flags.hardened_otw_check
1228 }
1229
1230 pub fn enable_poseidon(&self) -> bool {
1231 self.feature_flags.enable_poseidon
1232 }
1233
1234 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1235 self.feature_flags.enable_group_ops_native_function_msm
1236 }
1237
1238 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1239 self.feature_flags.per_object_congestion_control_mode
1240 }
1241
1242 pub fn consensus_choice(&self) -> ConsensusChoice {
1243 self.feature_flags.consensus_choice
1244 }
1245
1246 pub fn consensus_network(&self) -> ConsensusNetwork {
1247 self.feature_flags.consensus_network
1248 }
1249
1250 pub fn enable_vdf(&self) -> bool {
1251 self.feature_flags.enable_vdf
1252 }
1253
1254 pub fn passkey_auth(&self) -> bool {
1255 self.feature_flags.passkey_auth
1256 }
1257
1258 pub fn max_transaction_size_bytes(&self) -> u64 {
1259 self.consensus_max_transaction_size_bytes
1261 .unwrap_or(256 * 1024)
1262 }
1263
1264 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1265 if cfg!(msim) {
1266 256 * 1024
1267 } else {
1268 self.consensus_max_transactions_in_block_bytes
1269 .unwrap_or(512 * 1024)
1270 }
1271 }
1272
1273 pub fn max_num_transactions_in_block(&self) -> u64 {
1274 if cfg!(msim) {
1275 8
1276 } else {
1277 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1278 }
1279 }
1280
1281 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1282 self.feature_flags.rethrow_serialization_type_layout_errors
1283 }
1284
1285 pub fn relocate_event_module(&self) -> bool {
1286 self.feature_flags.relocate_event_module
1287 }
1288
1289 pub fn protocol_defined_base_fee(&self) -> bool {
1290 self.feature_flags.protocol_defined_base_fee
1291 }
1292
1293 pub fn uncompressed_g1_group_elements(&self) -> bool {
1294 self.feature_flags.uncompressed_g1_group_elements
1295 }
1296
1297 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1298 self.feature_flags
1299 .disallow_new_modules_in_deps_only_packages
1300 }
1301
1302 pub fn native_charging_v2(&self) -> bool {
1303 self.feature_flags.native_charging_v2
1304 }
1305
1306 pub fn consensus_round_prober(&self) -> bool {
1307 self.feature_flags.consensus_round_prober
1308 }
1309
1310 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1311 self.feature_flags
1312 .consensus_distributed_vote_scoring_strategy
1313 }
1314
1315 pub fn gc_depth(&self) -> u32 {
1316 if cfg!(msim) {
1317 min(5, self.consensus_gc_depth.unwrap_or(0))
1319 } else {
1320 self.consensus_gc_depth.unwrap_or(0)
1321 }
1322 }
1323
1324 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1325 let res = self.feature_flags.consensus_linearize_subdag_v2;
1326 assert!(
1327 !res || self.gc_depth() > 0,
1328 "The consensus linearize sub dag V2 requires GC to be enabled"
1329 );
1330 res
1331 }
1332
1333 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1334 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1335 }
1336
1337 pub fn variant_nodes(&self) -> bool {
1338 self.feature_flags.variant_nodes
1339 }
1340
1341 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1342 self.feature_flags.consensus_smart_ancestor_selection
1343 }
1344
1345 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1346 self.feature_flags
1347 .consensus_round_prober_probe_accepted_rounds
1348 }
1349
1350 pub fn consensus_zstd_compression(&self) -> bool {
1351 self.feature_flags.consensus_zstd_compression
1352 }
1353
1354 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1355 self.feature_flags
1356 .congestion_control_min_free_execution_slot
1357 }
1358
1359 pub fn accept_passkey_in_multisig(&self) -> bool {
1360 self.feature_flags.accept_passkey_in_multisig
1361 }
1362
1363 pub fn consensus_batched_block_sync(&self) -> bool {
1364 self.feature_flags.consensus_batched_block_sync
1365 }
1366
1367 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1370 self.feature_flags
1371 .congestion_control_gas_price_feedback_mechanism
1372 }
1373
1374 pub fn validate_identifier_inputs(&self) -> bool {
1375 self.feature_flags.validate_identifier_inputs
1376 }
1377
1378 pub fn minimize_child_object_mutations(&self) -> bool {
1379 self.feature_flags.minimize_child_object_mutations
1380 }
1381
1382 pub fn dependency_linkage_error(&self) -> bool {
1383 self.feature_flags.dependency_linkage_error
1384 }
1385
1386 pub fn additional_multisig_checks(&self) -> bool {
1387 self.feature_flags.additional_multisig_checks
1388 }
1389
1390 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1391 0
1394 }
1395
1396 pub fn normalize_ptb_arguments(&self) -> bool {
1397 self.feature_flags.normalize_ptb_arguments
1398 }
1399
1400 pub fn select_committee_from_eligible_validators(&self) -> bool {
1401 let res = self.feature_flags.select_committee_from_eligible_validators;
1402 assert!(
1403 !res || (self.protocol_defined_base_fee()
1404 && self.max_committee_members_count_as_option().is_some()),
1405 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1406 );
1407 res
1408 }
1409
1410 pub fn track_non_committee_eligible_validators(&self) -> bool {
1411 self.feature_flags.track_non_committee_eligible_validators
1412 }
1413
1414 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1415 let res = self
1416 .feature_flags
1417 .select_committee_supporting_next_epoch_version;
1418 assert!(
1419 !res || (self.track_non_committee_eligible_validators()
1420 && self.select_committee_from_eligible_validators()),
1421 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1422 );
1423 res
1424 }
1425
1426 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1427 let res = self
1428 .feature_flags
1429 .consensus_median_timestamp_with_checkpoint_enforcement;
1430 assert!(
1431 !res || self.gc_depth() > 0,
1432 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1433 );
1434 res
1435 }
1436}
1437
1438#[cfg(not(msim))]
1439static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1440
1441#[cfg(msim)]
1443thread_local! {
1444 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1445}
1446
1447impl ProtocolConfig {
1449 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1452 assert!(
1454 version >= ProtocolVersion::MIN,
1455 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1456 version,
1457 ProtocolVersion::MIN.0,
1458 );
1459 assert!(
1460 version <= ProtocolVersion::MAX_ALLOWED,
1461 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1462 version,
1463 ProtocolVersion::MAX_ALLOWED.0,
1464 );
1465
1466 let mut ret = Self::get_for_version_impl(version, chain);
1467 ret.version = version;
1468
1469 ret = CONFIG_OVERRIDE.with(|ovr| {
1470 if let Some(override_fn) = &*ovr.borrow() {
1471 warn!(
1472 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1473 );
1474 override_fn(version, ret)
1475 } else {
1476 ret
1477 }
1478 });
1479
1480 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1481 warn!(
1482 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1483 );
1484 let overrides: ProtocolConfigOptional =
1485 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1486 .expect("failed to parse ProtocolConfig override env variables");
1487 overrides.apply_to(&mut ret);
1488 }
1489
1490 ret
1491 }
1492
1493 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1496 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1497 let mut ret = Self::get_for_version_impl(version, chain);
1498 ret.version = version;
1499 Some(ret)
1500 } else {
1501 None
1502 }
1503 }
1504
1505 #[cfg(not(msim))]
1506 pub fn poison_get_for_min_version() {
1507 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1508 }
1509
1510 #[cfg(not(msim))]
1511 fn load_poison_get_for_min_version() -> bool {
1512 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1513 }
1514
1515 #[cfg(msim)]
1516 pub fn poison_get_for_min_version() {
1517 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1518 }
1519
1520 #[cfg(msim)]
1521 fn load_poison_get_for_min_version() -> bool {
1522 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1523 }
1524
1525 pub fn convert_type_argument_error(&self) -> bool {
1526 self.feature_flags.convert_type_argument_error
1527 }
1528
1529 pub fn get_for_min_version() -> Self {
1533 if Self::load_poison_get_for_min_version() {
1534 panic!("get_for_min_version called on validator");
1535 }
1536 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1537 }
1538
1539 #[expect(non_snake_case)]
1550 pub fn get_for_max_version_UNSAFE() -> Self {
1551 if Self::load_poison_get_for_min_version() {
1552 panic!("get_for_max_version_UNSAFE called on validator");
1553 }
1554 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1555 }
1556
1557 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1558 #[cfg(msim)]
1559 {
1560 if version > ProtocolVersion::MAX {
1562 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1563 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1564 return config;
1565 }
1566 }
1567
1568 let mut cfg = Self {
1572 version,
1573
1574 feature_flags: Default::default(),
1575
1576 max_tx_size_bytes: Some(128 * 1024),
1577 max_input_objects: Some(2048),
1580 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1581 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1582 max_gas_payment_objects: Some(256),
1583 max_modules_in_publish: Some(64),
1584 max_package_dependencies: Some(32),
1585 max_arguments: Some(512),
1586 max_type_arguments: Some(16),
1587 max_type_argument_depth: Some(16),
1588 max_pure_argument_size: Some(16 * 1024),
1589 max_programmable_tx_commands: Some(1024),
1590 move_binary_format_version: Some(7),
1591 min_move_binary_format_version: Some(6),
1592 binary_module_handles: Some(100),
1593 binary_struct_handles: Some(300),
1594 binary_function_handles: Some(1500),
1595 binary_function_instantiations: Some(750),
1596 binary_signatures: Some(1000),
1597 binary_constant_pool: Some(4000),
1598 binary_identifiers: Some(10000),
1599 binary_address_identifiers: Some(100),
1600 binary_struct_defs: Some(200),
1601 binary_struct_def_instantiations: Some(100),
1602 binary_function_defs: Some(1000),
1603 binary_field_handles: Some(500),
1604 binary_field_instantiations: Some(250),
1605 binary_friend_decls: Some(100),
1606 binary_enum_defs: None,
1607 binary_enum_def_instantiations: None,
1608 binary_variant_handles: None,
1609 binary_variant_instantiation_handles: None,
1610 max_move_object_size: Some(250 * 1024),
1611 max_move_package_size: Some(100 * 1024),
1612 max_publish_or_upgrade_per_ptb: Some(5),
1613 max_tx_gas: Some(50_000_000_000),
1615 max_gas_price: Some(100_000),
1616 max_gas_computation_bucket: Some(5_000_000),
1617 max_loop_depth: Some(5),
1618 max_generic_instantiation_length: Some(32),
1619 max_function_parameters: Some(128),
1620 max_basic_blocks: Some(1024),
1621 max_value_stack_size: Some(1024),
1622 max_type_nodes: Some(256),
1623 max_push_size: Some(10000),
1624 max_struct_definitions: Some(200),
1625 max_function_definitions: Some(1000),
1626 max_fields_in_struct: Some(32),
1627 max_dependency_depth: Some(100),
1628 max_num_event_emit: Some(1024),
1629 max_num_new_move_object_ids: Some(2048),
1630 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1631 max_num_deleted_move_object_ids: Some(2048),
1632 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1633 max_num_transferred_move_object_ids: Some(2048),
1634 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1635 max_event_emit_size: Some(250 * 1024),
1636 max_move_vector_len: Some(256 * 1024),
1637 max_type_to_layout_nodes: None,
1638 max_ptb_value_size: None,
1639
1640 max_back_edges_per_function: Some(10_000),
1641 max_back_edges_per_module: Some(10_000),
1642
1643 max_verifier_meter_ticks_per_function: Some(16_000_000),
1644
1645 max_meter_ticks_per_module: Some(16_000_000),
1646 max_meter_ticks_per_package: Some(16_000_000),
1647
1648 object_runtime_max_num_cached_objects: Some(1000),
1649 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
1650 object_runtime_max_num_store_entries: Some(1000),
1651 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
1652 base_tx_cost_fixed: Some(1_000),
1654 package_publish_cost_fixed: Some(1_000),
1655 base_tx_cost_per_byte: Some(0),
1656 package_publish_cost_per_byte: Some(80),
1657 obj_access_cost_read_per_byte: Some(15),
1658 obj_access_cost_mutate_per_byte: Some(40),
1659 obj_access_cost_delete_per_byte: Some(40),
1660 obj_access_cost_verify_per_byte: Some(200),
1661 obj_data_cost_refundable: Some(100),
1662 obj_metadata_cost_non_refundable: Some(50),
1663 gas_model_version: Some(1),
1664 storage_rebate_rate: Some(10000),
1665 reward_slashing_rate: Some(10000),
1667 storage_gas_price: Some(76),
1668 base_gas_price: None,
1669 validator_target_reward: Some(767_000 * 1_000_000_000),
1672 max_transactions_per_checkpoint: Some(10_000),
1673 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
1674
1675 buffer_stake_for_protocol_upgrade_bps: Some(5000),
1677
1678 address_from_bytes_cost_base: Some(52),
1682 address_to_u256_cost_base: Some(52),
1684 address_from_u256_cost_base: Some(52),
1686
1687 config_read_setting_impl_cost_base: Some(100),
1690 config_read_setting_impl_cost_per_byte: Some(40),
1691
1692 dynamic_field_hash_type_and_key_cost_base: Some(100),
1696 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
1697 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
1698 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
1699 dynamic_field_add_child_object_cost_base: Some(100),
1702 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
1703 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
1704 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
1705 dynamic_field_borrow_child_object_cost_base: Some(100),
1708 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
1709 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
1710 dynamic_field_remove_child_object_cost_base: Some(100),
1713 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
1714 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
1715 dynamic_field_has_child_object_cost_base: Some(100),
1718 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
1721 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
1722 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
1723
1724 event_emit_cost_base: Some(52),
1727 event_emit_value_size_derivation_cost_per_byte: Some(2),
1728 event_emit_tag_size_derivation_cost_per_byte: Some(5),
1729 event_emit_output_cost_per_byte: Some(10),
1730
1731 object_borrow_uid_cost_base: Some(52),
1734 object_delete_impl_cost_base: Some(52),
1736 object_record_new_uid_cost_base: Some(52),
1738
1739 transfer_transfer_internal_cost_base: Some(52),
1743 transfer_freeze_object_cost_base: Some(52),
1745 transfer_share_object_cost_base: Some(52),
1747 transfer_receive_object_cost_base: Some(52),
1748
1749 tx_context_derive_id_cost_base: Some(52),
1753
1754 types_is_one_time_witness_cost_base: Some(52),
1757 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
1758 types_is_one_time_witness_type_cost_per_byte: Some(2),
1759
1760 validator_validate_metadata_cost_base: Some(52),
1764 validator_validate_metadata_data_cost_per_byte: Some(2),
1765
1766 crypto_invalid_arguments_cost: Some(100),
1768 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
1770 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
1771 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
1772
1773 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
1775 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
1776 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
1777
1778 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
1780 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1781 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1782 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
1783 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1784 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
1785
1786 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
1788
1789 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
1791 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
1792 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
1793 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
1794 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
1795 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
1796
1797 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
1799 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
1800 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
1801 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
1802 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
1803 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
1804
1805 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
1807 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
1808 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
1809 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
1810 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
1811 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
1812
1813 ecvrf_ecvrf_verify_cost_base: Some(52),
1815 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
1816 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
1817
1818 ed25519_ed25519_verify_cost_base: Some(52),
1820 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
1821 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
1822
1823 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
1825 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
1826
1827 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
1829 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
1830 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
1831 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
1832 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
1833
1834 hash_blake2b256_cost_base: Some(52),
1836 hash_blake2b256_data_cost_per_byte: Some(2),
1837 hash_blake2b256_data_cost_per_block: Some(2),
1838 hash_keccak256_cost_base: Some(52),
1840 hash_keccak256_data_cost_per_byte: Some(2),
1841 hash_keccak256_data_cost_per_block: Some(2),
1842
1843 poseidon_bn254_cost_base: None,
1844 poseidon_bn254_cost_per_block: None,
1845
1846 hmac_hmac_sha3_256_cost_base: Some(52),
1848 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
1849 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
1850
1851 group_ops_bls12381_decode_scalar_cost: Some(52),
1853 group_ops_bls12381_decode_g1_cost: Some(52),
1854 group_ops_bls12381_decode_g2_cost: Some(52),
1855 group_ops_bls12381_decode_gt_cost: Some(52),
1856 group_ops_bls12381_scalar_add_cost: Some(52),
1857 group_ops_bls12381_g1_add_cost: Some(52),
1858 group_ops_bls12381_g2_add_cost: Some(52),
1859 group_ops_bls12381_gt_add_cost: Some(52),
1860 group_ops_bls12381_scalar_sub_cost: Some(52),
1861 group_ops_bls12381_g1_sub_cost: Some(52),
1862 group_ops_bls12381_g2_sub_cost: Some(52),
1863 group_ops_bls12381_gt_sub_cost: Some(52),
1864 group_ops_bls12381_scalar_mul_cost: Some(52),
1865 group_ops_bls12381_g1_mul_cost: Some(52),
1866 group_ops_bls12381_g2_mul_cost: Some(52),
1867 group_ops_bls12381_gt_mul_cost: Some(52),
1868 group_ops_bls12381_scalar_div_cost: Some(52),
1869 group_ops_bls12381_g1_div_cost: Some(52),
1870 group_ops_bls12381_g2_div_cost: Some(52),
1871 group_ops_bls12381_gt_div_cost: Some(52),
1872 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
1873 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
1874 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
1875 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
1876 group_ops_bls12381_g1_msm_base_cost: Some(52),
1877 group_ops_bls12381_g2_msm_base_cost: Some(52),
1878 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
1879 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
1880 group_ops_bls12381_msm_max_len: Some(32),
1881 group_ops_bls12381_pairing_cost: Some(52),
1882 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
1883 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
1884 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
1885 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
1886 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
1887
1888 check_zklogin_id_cost_base: Some(200),
1890 check_zklogin_issuer_cost_base: Some(200),
1892
1893 vdf_verify_vdf_cost: None,
1894 vdf_hash_to_input_cost: None,
1895
1896 bcs_per_byte_serialized_cost: Some(2),
1897 bcs_legacy_min_output_size_cost: Some(1),
1898 bcs_failure_cost: Some(52),
1899 hash_sha2_256_base_cost: Some(52),
1900 hash_sha2_256_per_byte_cost: Some(2),
1901 hash_sha2_256_legacy_min_input_len_cost: Some(1),
1902 hash_sha3_256_base_cost: Some(52),
1903 hash_sha3_256_per_byte_cost: Some(2),
1904 hash_sha3_256_legacy_min_input_len_cost: Some(1),
1905 type_name_get_base_cost: Some(52),
1906 type_name_get_per_byte_cost: Some(2),
1907 string_check_utf8_base_cost: Some(52),
1908 string_check_utf8_per_byte_cost: Some(2),
1909 string_is_char_boundary_base_cost: Some(52),
1910 string_sub_string_base_cost: Some(52),
1911 string_sub_string_per_byte_cost: Some(2),
1912 string_index_of_base_cost: Some(52),
1913 string_index_of_per_byte_pattern_cost: Some(2),
1914 string_index_of_per_byte_searched_cost: Some(2),
1915 vector_empty_base_cost: Some(52),
1916 vector_length_base_cost: Some(52),
1917 vector_push_back_base_cost: Some(52),
1918 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
1919 vector_borrow_base_cost: Some(52),
1920 vector_pop_back_base_cost: Some(52),
1921 vector_destroy_empty_base_cost: Some(52),
1922 vector_swap_base_cost: Some(52),
1923 debug_print_base_cost: Some(52),
1924 debug_print_stack_trace_base_cost: Some(52),
1925
1926 max_size_written_objects: Some(5 * 1000 * 1000),
1927 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
1930
1931 max_move_identifier_len: Some(128),
1933 max_move_value_depth: Some(128),
1934 max_move_enum_variants: None,
1935
1936 gas_rounding_step: Some(1_000),
1937
1938 execution_version: Some(1),
1939
1940 max_event_emit_size_total: Some(
1943 256 * 250 * 1024, ),
1945
1946 consensus_bad_nodes_stake_threshold: Some(20),
1953
1954 max_jwk_votes_per_validator_per_epoch: Some(240),
1956
1957 max_age_of_jwk_in_epochs: Some(1),
1958
1959 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
1963
1964 random_beacon_reduction_allowed_delta: Some(800),
1965
1966 random_beacon_reduction_lower_bound: Some(1000),
1967 random_beacon_dkg_timeout_round: Some(3000),
1968 random_beacon_min_round_interval_ms: Some(500),
1969
1970 random_beacon_dkg_version: Some(1),
1971
1972 consensus_max_num_transactions_in_block: Some(512),
1976
1977 max_deferral_rounds_for_congestion_control: Some(10),
1978
1979 min_checkpoint_interval_ms: Some(200),
1980
1981 checkpoint_summary_version_specific_data: Some(1),
1982
1983 max_soft_bundle_size: Some(5),
1984
1985 bridge_should_try_to_finalize_committee: None,
1986
1987 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
1988
1989 max_committee_members_count: None,
1990
1991 consensus_gc_depth: None,
1992
1993 consensus_max_acknowledgments_per_block: None,
1994
1995 max_congestion_limit_overshoot_per_commit: None,
1996 };
1999
2000 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2001
2002 {
2004 cfg.feature_flags
2005 .disable_invariant_violation_check_in_swap_loc = true;
2006 cfg.feature_flags.no_extraneous_module_bytes = true;
2007 cfg.feature_flags.hardened_otw_check = true;
2008 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2009 }
2010
2011 {
2013 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2014 }
2015
2016 cfg.feature_flags.consensus_choice = ConsensusChoice::Mysticeti;
2018 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2020
2021 cfg.feature_flags.per_object_congestion_control_mode =
2022 PerObjectCongestionControlMode::TotalTxCount;
2023
2024 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2026
2027 if chain != Chain::Mainnet && chain != Chain::Testnet {
2029 cfg.feature_flags.enable_poseidon = true;
2030 cfg.poseidon_bn254_cost_base = Some(260);
2031 cfg.poseidon_bn254_cost_per_block = Some(10);
2032
2033 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2034
2035 cfg.feature_flags.enable_vdf = true;
2036 cfg.vdf_verify_vdf_cost = Some(1500);
2039 cfg.vdf_hash_to_input_cost = Some(100);
2040
2041 cfg.feature_flags.passkey_auth = true;
2042 }
2043
2044 for cur in 2..=version.0 {
2045 match cur {
2046 1 => unreachable!(),
2047 2 => {}
2049 3 => {
2050 cfg.feature_flags.relocate_event_module = true;
2051 }
2052 4 => {
2053 cfg.max_type_to_layout_nodes = Some(512);
2054 }
2055 5 => {
2056 cfg.feature_flags.protocol_defined_base_fee = true;
2057 cfg.base_gas_price = Some(1000);
2058
2059 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2060 cfg.feature_flags.convert_type_argument_error = true;
2061 cfg.feature_flags.native_charging_v2 = true;
2062
2063 if chain != Chain::Mainnet && chain != Chain::Testnet {
2064 cfg.feature_flags.uncompressed_g1_group_elements = true;
2065 }
2066
2067 cfg.gas_model_version = Some(2);
2068
2069 cfg.poseidon_bn254_cost_per_block = Some(388);
2070
2071 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2072 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2073 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2074 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2075 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2076 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2077 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2078 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2079
2080 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2082 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2083 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2084 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2085
2086 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2087 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2088 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2089 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2090 Some(8213);
2091 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2092 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2093 Some(9484);
2094
2095 cfg.hash_keccak256_cost_base = Some(10);
2096 cfg.hash_blake2b256_cost_base = Some(10);
2097
2098 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2100 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2101 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2102 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2103
2104 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2105 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2106 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2107 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2108
2109 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2110 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2111 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2112 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2113
2114 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2115 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2116 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2117 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2118
2119 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2120 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2121 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2122 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2123
2124 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2125 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2126
2127 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2128 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2129 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2130 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2131
2132 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2133 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2134 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2135 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2136 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2137
2138 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2139
2140 cfg.validator_validate_metadata_cost_base = Some(20000);
2141
2142 cfg.max_committee_members_count = Some(50);
2143 }
2144 6 => {
2145 cfg.max_ptb_value_size = Some(1024 * 1024);
2146 }
2147 7 => {
2148 }
2151 8 => {
2152 cfg.feature_flags.variant_nodes = true;
2153
2154 if chain != Chain::Mainnet {
2155 cfg.feature_flags.consensus_round_prober = true;
2157 cfg.feature_flags
2159 .consensus_distributed_vote_scoring_strategy = true;
2160 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2161 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2163 cfg.feature_flags
2165 .consensus_round_prober_probe_accepted_rounds = true;
2166 cfg.feature_flags.consensus_zstd_compression = true;
2168 cfg.consensus_gc_depth = Some(60);
2172 }
2173
2174 if chain != Chain::Testnet && chain != Chain::Mainnet {
2177 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2178 }
2179 }
2180 9 => {
2181 if chain != Chain::Mainnet {
2182 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2184 }
2185
2186 cfg.feature_flags.consensus_zstd_compression = true;
2188
2189 if chain != Chain::Testnet && chain != Chain::Mainnet {
2191 cfg.feature_flags.accept_passkey_in_multisig = true;
2192 }
2193
2194 cfg.bridge_should_try_to_finalize_committee = None;
2196 }
2197 10 => {
2198 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2201
2202 cfg.max_committee_members_count = Some(80);
2204
2205 cfg.feature_flags.consensus_round_prober = true;
2207 cfg.feature_flags
2209 .consensus_round_prober_probe_accepted_rounds = true;
2210 cfg.feature_flags
2212 .consensus_distributed_vote_scoring_strategy = true;
2213 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2215
2216 cfg.consensus_gc_depth = Some(60);
2221
2222 cfg.feature_flags.minimize_child_object_mutations = true;
2224
2225 if chain != Chain::Mainnet {
2226 cfg.feature_flags.consensus_batched_block_sync = true;
2228 }
2229
2230 if chain != Chain::Testnet && chain != Chain::Mainnet {
2231 cfg.feature_flags
2234 .congestion_control_gas_price_feedback_mechanism = true;
2235 }
2236
2237 cfg.feature_flags.validate_identifier_inputs = true;
2238 cfg.feature_flags.dependency_linkage_error = true;
2239 cfg.feature_flags.additional_multisig_checks = true;
2240 }
2241 11 => {
2242 }
2245 12 => {
2246 cfg.feature_flags
2249 .congestion_control_gas_price_feedback_mechanism = true;
2250
2251 cfg.feature_flags.normalize_ptb_arguments = true;
2253 }
2254 13 => {
2255 cfg.feature_flags.select_committee_from_eligible_validators = true;
2258 cfg.feature_flags.track_non_committee_eligible_validators = true;
2261
2262 if chain != Chain::Testnet && chain != Chain::Mainnet {
2263 cfg.feature_flags
2266 .select_committee_supporting_next_epoch_version = true;
2267 }
2268 }
2269 14 => {
2270 cfg.feature_flags.consensus_batched_block_sync = true;
2272
2273 if chain != Chain::Mainnet {
2274 cfg.feature_flags
2277 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2278 cfg.feature_flags
2282 .select_committee_supporting_next_epoch_version = true;
2283 }
2284 if chain != Chain::Testnet && chain != Chain::Mainnet {
2285 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2287 }
2288 }
2289 15 => {
2290 if chain != Chain::Mainnet && chain != Chain::Testnet {
2291 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2295 }
2296 }
2297 _ => panic!("unsupported version {version:?}"),
2308 }
2309 }
2310 cfg
2311 }
2312
2313 pub fn verifier_config(&self, signing_limits: Option<(usize, usize)>) -> VerifierConfig {
2317 let (max_back_edges_per_function, max_back_edges_per_module) = if let Some((
2318 max_back_edges_per_function,
2319 max_back_edges_per_module,
2320 )) = signing_limits
2321 {
2322 (
2323 Some(max_back_edges_per_function),
2324 Some(max_back_edges_per_module),
2325 )
2326 } else {
2327 (None, None)
2328 };
2329
2330 VerifierConfig {
2331 max_loop_depth: Some(self.max_loop_depth() as usize),
2332 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2333 max_function_parameters: Some(self.max_function_parameters() as usize),
2334 max_basic_blocks: Some(self.max_basic_blocks() as usize),
2335 max_value_stack_size: self.max_value_stack_size() as usize,
2336 max_type_nodes: Some(self.max_type_nodes() as usize),
2337 max_push_size: Some(self.max_push_size() as usize),
2338 max_dependency_depth: Some(self.max_dependency_depth() as usize),
2339 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2340 max_function_definitions: Some(self.max_function_definitions() as usize),
2341 max_data_definitions: Some(self.max_struct_definitions() as usize),
2342 max_constant_vector_len: Some(self.max_move_vector_len()),
2343 max_back_edges_per_function,
2344 max_back_edges_per_module,
2345 max_basic_blocks_in_script: None,
2346 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
2350 max_variants_in_enum: self.max_move_enum_variants_as_option(),
2351 }
2352 }
2353
2354 pub fn apply_overrides_for_testing(
2359 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
2360 ) -> OverrideGuard {
2361 CONFIG_OVERRIDE.with(|ovr| {
2362 let mut cur = ovr.borrow_mut();
2363 assert!(cur.is_none(), "config override already present");
2364 *cur = Some(Box::new(override_fn));
2365 OverrideGuard
2366 })
2367 }
2368}
2369
2370impl ProtocolConfig {
2375 pub fn set_zklogin_auth_for_testing(&mut self, val: bool) {
2376 self.feature_flags.zklogin_auth = val
2377 }
2378 pub fn set_enable_jwk_consensus_updates_for_testing(&mut self, val: bool) {
2379 self.feature_flags.enable_jwk_consensus_updates = val
2380 }
2381
2382 pub fn set_accept_zklogin_in_multisig_for_testing(&mut self, val: bool) {
2383 self.feature_flags.accept_zklogin_in_multisig = val
2384 }
2385
2386 pub fn set_per_object_congestion_control_mode_for_testing(
2387 &mut self,
2388 val: PerObjectCongestionControlMode,
2389 ) {
2390 self.feature_flags.per_object_congestion_control_mode = val;
2391 }
2392
2393 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
2394 self.feature_flags.consensus_choice = val;
2395 }
2396
2397 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
2398 self.feature_flags.consensus_network = val;
2399 }
2400
2401 pub fn set_zklogin_max_epoch_upper_bound_delta_for_testing(&mut self, val: Option<u64>) {
2402 self.feature_flags.zklogin_max_epoch_upper_bound_delta = val
2403 }
2404
2405 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
2406 self.feature_flags.passkey_auth = val
2407 }
2408
2409 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
2410 self.feature_flags
2411 .disallow_new_modules_in_deps_only_packages = val;
2412 }
2413
2414 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
2415 self.feature_flags.consensus_round_prober = val;
2416 }
2417
2418 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
2419 self.feature_flags
2420 .consensus_distributed_vote_scoring_strategy = val;
2421 }
2422
2423 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
2424 self.consensus_gc_depth = Some(val);
2425 }
2426
2427 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
2428 self.feature_flags.consensus_linearize_subdag_v2 = val;
2429 }
2430
2431 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
2432 self.feature_flags
2433 .consensus_round_prober_probe_accepted_rounds = val;
2434 }
2435
2436 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
2437 self.feature_flags.accept_passkey_in_multisig = val;
2438 }
2439
2440 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
2441 self.feature_flags.consensus_smart_ancestor_selection = val;
2442 }
2443
2444 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
2445 self.feature_flags.consensus_batched_block_sync = val;
2446 }
2447
2448 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
2449 self.feature_flags
2450 .congestion_control_min_free_execution_slot = val;
2451 }
2452
2453 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
2454 self.feature_flags
2455 .congestion_control_gas_price_feedback_mechanism = val;
2456 }
2457 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
2458 self.feature_flags.select_committee_from_eligible_validators = val;
2459 }
2460
2461 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
2462 self.feature_flags.track_non_committee_eligible_validators = val;
2463 }
2464
2465 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
2466 self.feature_flags
2467 .select_committee_supporting_next_epoch_version = val;
2468 }
2469
2470 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
2471 &mut self,
2472 val: bool,
2473 ) {
2474 self.feature_flags
2475 .consensus_median_timestamp_with_checkpoint_enforcement = val;
2476 }
2477}
2478
2479type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
2480
2481thread_local! {
2482 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
2483}
2484
2485#[must_use]
2486pub struct OverrideGuard;
2487
2488impl Drop for OverrideGuard {
2489 fn drop(&mut self) {
2490 info!("restoring override fn");
2491 CONFIG_OVERRIDE.with(|ovr| {
2492 *ovr.borrow_mut() = None;
2493 });
2494 }
2495}
2496
2497#[derive(PartialEq, Eq)]
2501pub enum LimitThresholdCrossed {
2502 None,
2503 Soft(u128, u128),
2504 Hard(u128, u128),
2505}
2506
2507pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
2510 x: T,
2511 soft_limit: U,
2512 hard_limit: V,
2513) -> LimitThresholdCrossed {
2514 let x: V = x.into();
2515 let soft_limit: V = soft_limit.into();
2516
2517 debug_assert!(soft_limit <= hard_limit);
2518
2519 if x >= hard_limit {
2522 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
2523 } else if x < soft_limit {
2524 LimitThresholdCrossed::None
2525 } else {
2526 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
2527 }
2528}
2529
2530#[macro_export]
2531macro_rules! check_limit {
2532 ($x:expr, $hard:expr) => {
2533 check_limit!($x, $hard, $hard)
2534 };
2535 ($x:expr, $soft:expr, $hard:expr) => {
2536 check_limit_in_range($x as u64, $soft, $hard)
2537 };
2538}
2539
2540#[macro_export]
2544macro_rules! check_limit_by_meter {
2545 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
2546 let (h, metered_str) = if $is_metered {
2548 ($metered_limit, "metered")
2549 } else {
2550 ($unmetered_hard_limit, "unmetered")
2552 };
2553 use iota_protocol_config::check_limit_in_range;
2554 let result = check_limit_in_range($x as u64, $metered_limit, h);
2555 match result {
2556 LimitThresholdCrossed::None => {}
2557 LimitThresholdCrossed::Soft(_, _) => {
2558 $metric.with_label_values(&[metered_str, "soft"]).inc();
2559 }
2560 LimitThresholdCrossed::Hard(_, _) => {
2561 $metric.with_label_values(&[metered_str, "hard"]).inc();
2562 }
2563 };
2564 result
2565 }};
2566}
2567
2568#[cfg(all(test, not(msim)))]
2569mod test {
2570 use insta::assert_yaml_snapshot;
2571
2572 use super::*;
2573
2574 #[test]
2575 fn snapshot_tests() {
2576 println!("\n============================================================================");
2577 println!("! !");
2578 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
2579 println!("! !");
2580 println!("============================================================================\n");
2581 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
2582 let chain_str = match chain_id {
2587 Chain::Unknown => "".to_string(),
2588 _ => format!("{chain_id:?}_"),
2589 };
2590 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
2591 let cur = ProtocolVersion::new(i);
2592 assert_yaml_snapshot!(
2593 format!("{}version_{}", chain_str, cur.as_u64()),
2594 ProtocolConfig::get_for_version(cur, *chain_id)
2595 );
2596 }
2597 }
2598 }
2599
2600 #[test]
2601 fn test_getters() {
2602 let prot: ProtocolConfig =
2603 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2604 assert_eq!(
2605 prot.max_arguments(),
2606 prot.max_arguments_as_option().unwrap()
2607 );
2608 }
2609
2610 #[test]
2611 fn test_setters() {
2612 let mut prot: ProtocolConfig =
2613 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2614 prot.set_max_arguments_for_testing(123);
2615 assert_eq!(prot.max_arguments(), 123);
2616
2617 prot.set_max_arguments_from_str_for_testing("321".to_string());
2618 assert_eq!(prot.max_arguments(), 321);
2619
2620 prot.disable_max_arguments_for_testing();
2621 assert_eq!(prot.max_arguments_as_option(), None);
2622
2623 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
2624 assert_eq!(prot.max_arguments(), 456);
2625 }
2626
2627 #[test]
2628 #[should_panic(expected = "unsupported version")]
2629 fn max_version_test() {
2630 let _ = ProtocolConfig::get_for_version_impl(
2633 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
2634 Chain::Unknown,
2635 );
2636 }
2637
2638 #[test]
2639 fn lookup_by_string_test() {
2640 let prot: ProtocolConfig =
2641 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2642 assert!(prot.lookup_attr("some random string".to_string()).is_none());
2644
2645 assert!(
2646 prot.lookup_attr("max_arguments".to_string())
2647 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
2648 );
2649
2650 assert!(
2652 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2653 .is_none()
2654 );
2655 assert!(
2656 prot.attr_map()
2657 .get("poseidon_bn254_cost_base")
2658 .unwrap()
2659 .is_none()
2660 );
2661
2662 let prot: ProtocolConfig =
2664 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2665
2666 assert!(
2667 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
2668 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2669 );
2670 assert!(
2671 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
2672 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
2673 );
2674
2675 let prot: ProtocolConfig =
2677 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
2678 assert!(
2680 prot.feature_flags
2681 .lookup_attr("some random string".to_owned())
2682 .is_none()
2683 );
2684 assert!(
2685 !prot
2686 .feature_flags
2687 .attr_map()
2688 .contains_key("some random string")
2689 );
2690
2691 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
2693 assert!(
2694 prot.feature_flags
2695 .attr_map()
2696 .get("enable_poseidon")
2697 .unwrap()
2698 == &false
2699 );
2700 let prot: ProtocolConfig =
2701 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
2702 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
2704 assert!(
2705 prot.feature_flags
2706 .attr_map()
2707 .get("enable_poseidon")
2708 .unwrap()
2709 == &true
2710 );
2711 }
2712
2713 #[test]
2714 fn limit_range_fn_test() {
2715 let low = 100u32;
2716 let high = 10000u64;
2717
2718 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
2719 assert!(matches!(
2720 check_limit!(255u16, low, high),
2721 LimitThresholdCrossed::Soft(255u128, 100)
2722 ));
2723 assert!(matches!(
2730 check_limit!(2550000u64, low, high),
2731 LimitThresholdCrossed::Hard(2550000, 10000)
2732 ));
2733
2734 assert!(matches!(
2735 check_limit!(2550000u64, high, high),
2736 LimitThresholdCrossed::Hard(2550000, 10000)
2737 ));
2738
2739 assert!(matches!(
2740 check_limit!(1u8, high),
2741 LimitThresholdCrossed::None
2742 ));
2743
2744 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
2745
2746 assert!(matches!(
2747 check_limit!(2550000u64, high),
2748 LimitThresholdCrossed::Hard(2550000, 10000)
2749 ));
2750 }
2751}