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 = 26;
23
24pub const PROTOCOL_VERSION_IIP8: u64 = 20;
26#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
147pub struct ProtocolVersion(u64);
148
149impl ProtocolVersion {
150 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
156
157 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
158
159 #[cfg(not(msim))]
160 const MAX_ALLOWED: Self = Self::MAX;
161
162 #[cfg(msim)]
165 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
166
167 pub fn new(v: u64) -> Self {
168 Self(v)
169 }
170
171 pub const fn as_u64(&self) -> u64 {
172 self.0
173 }
174
175 pub fn max() -> Self {
178 Self::MAX
179 }
180}
181
182impl From<u64> for ProtocolVersion {
183 fn from(v: u64) -> Self {
184 Self::new(v)
185 }
186}
187
188impl std::ops::Sub<u64> for ProtocolVersion {
189 type Output = Self;
190 fn sub(self, rhs: u64) -> Self::Output {
191 Self::new(self.0 - rhs)
192 }
193}
194
195impl std::ops::Add<u64> for ProtocolVersion {
196 type Output = Self;
197 fn add(self, rhs: u64) -> Self::Output {
198 Self::new(self.0 + rhs)
199 }
200}
201
202#[derive(
203 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
204)]
205pub enum Chain {
206 Mainnet,
207 Testnet,
208 #[default]
209 Unknown,
210}
211
212impl Chain {
213 pub fn as_str(self) -> &'static str {
214 match self {
215 Chain::Mainnet => "mainnet",
216 Chain::Testnet => "testnet",
217 Chain::Unknown => "unknown",
218 }
219 }
220}
221
222pub struct Error(pub String);
223
224#[derive(Default, Clone, Serialize, Deserialize, Debug, ProtocolConfigFeatureFlagsGetters)]
228struct FeatureFlags {
229 #[serde(skip_serializing_if = "is_true")]
235 disable_invariant_violation_check_in_swap_loc: bool,
236
237 #[serde(skip_serializing_if = "is_true")]
240 no_extraneous_module_bytes: bool,
241
242 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
244 consensus_transaction_ordering: ConsensusTransactionOrdering,
245
246 #[serde(skip_serializing_if = "is_true")]
249 hardened_otw_check: bool,
250
251 #[serde(skip_serializing_if = "is_false")]
253 enable_poseidon: bool,
254
255 #[serde(skip_serializing_if = "is_false")]
257 enable_group_ops_native_function_msm: bool,
258
259 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
261 per_object_congestion_control_mode: PerObjectCongestionControlMode,
262
263 #[serde(
265 default = "ConsensusChoice::mysticeti_deprecated",
266 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
267 )]
268 consensus_choice: ConsensusChoice,
269
270 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
272 consensus_network: ConsensusNetwork,
273
274 #[deprecated]
276 #[serde(skip_serializing_if = "Option::is_none")]
277 zklogin_max_epoch_upper_bound_delta: Option<u64>,
278
279 #[serde(skip_serializing_if = "is_false")]
281 enable_vdf: bool,
282
283 #[serde(skip_serializing_if = "is_false")]
285 passkey_auth: bool,
286
287 #[serde(skip_serializing_if = "is_true")]
290 rethrow_serialization_type_layout_errors: bool,
291
292 #[serde(skip_serializing_if = "is_false")]
294 relocate_event_module: bool,
295
296 #[serde(skip_serializing_if = "is_false")]
298 protocol_defined_base_fee: bool,
299
300 #[serde(skip_serializing_if = "is_false")]
302 uncompressed_g1_group_elements: bool,
303
304 #[serde(skip_serializing_if = "is_false")]
306 disallow_new_modules_in_deps_only_packages: bool,
307
308 #[serde(skip_serializing_if = "is_false")]
310 native_charging_v2: bool,
311
312 #[serde(skip_serializing_if = "is_false")]
314 convert_type_argument_error: bool,
315
316 #[serde(skip_serializing_if = "is_false")]
318 consensus_round_prober: bool,
319
320 #[serde(skip_serializing_if = "is_false")]
322 consensus_distributed_vote_scoring_strategy: bool,
323
324 #[serde(skip_serializing_if = "is_false")]
328 consensus_linearize_subdag_v2: bool,
329
330 #[serde(skip_serializing_if = "is_false")]
332 variant_nodes: bool,
333
334 #[serde(skip_serializing_if = "is_false")]
336 consensus_smart_ancestor_selection: bool,
337
338 #[serde(skip_serializing_if = "is_false")]
340 consensus_round_prober_probe_accepted_rounds: bool,
341
342 #[serde(skip_serializing_if = "is_false")]
344 consensus_zstd_compression: bool,
345
346 #[serde(skip_serializing_if = "is_false")]
349 congestion_control_min_free_execution_slot: bool,
350
351 #[serde(skip_serializing_if = "is_false")]
353 accept_passkey_in_multisig: bool,
354
355 #[serde(skip_serializing_if = "is_false")]
357 consensus_batched_block_sync: bool,
358
359 #[serde(skip_serializing_if = "is_false")]
362 congestion_control_gas_price_feedback_mechanism: bool,
363
364 #[serde(skip_serializing_if = "is_false")]
366 validate_identifier_inputs: bool,
367
368 #[serde(skip_serializing_if = "is_false")]
371 minimize_child_object_mutations: bool,
372
373 #[serde(skip_serializing_if = "is_false")]
375 dependency_linkage_error: bool,
376
377 #[serde(skip_serializing_if = "is_false")]
379 additional_multisig_checks: bool,
380
381 #[serde(skip_serializing_if = "is_false")]
384 normalize_ptb_arguments: bool,
385
386 #[serde(skip_serializing_if = "is_false")]
390 select_committee_from_eligible_validators: bool,
391
392 #[serde(skip_serializing_if = "is_false")]
399 track_non_committee_eligible_validators: bool,
400
401 #[serde(skip_serializing_if = "is_false")]
407 select_committee_supporting_next_epoch_version: bool,
408
409 #[serde(skip_serializing_if = "is_false")]
413 consensus_median_timestamp_with_checkpoint_enforcement: bool,
414
415 #[serde(skip_serializing_if = "is_false")]
417 consensus_commit_transactions_only_for_traversed_headers: bool,
418
419 #[serde(skip_serializing_if = "is_false")]
421 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
422
423 #[serde(skip_serializing_if = "is_false")]
426 separate_gas_price_feedback_mechanism_for_randomness: bool,
427
428 #[serde(skip_serializing_if = "is_false")]
431 metadata_in_module_bytes: bool,
432
433 #[serde(skip_serializing_if = "is_false")]
435 publish_package_metadata: bool,
436
437 #[serde(skip_serializing_if = "is_false")]
439 enable_move_authentication: bool,
440
441 #[serde(skip_serializing_if = "is_false")]
443 enable_move_authentication_for_sponsor: bool,
444
445 #[serde(skip_serializing_if = "is_false")]
447 pass_validator_scores_to_advance_epoch: bool,
448
449 #[serde(skip_serializing_if = "is_false")]
451 calculate_validator_scores: bool,
452
453 #[serde(skip_serializing_if = "is_false")]
455 adjust_rewards_by_score: bool,
456
457 #[serde(skip_serializing_if = "is_false")]
460 pass_calculated_validator_scores_to_advance_epoch: bool,
461
462 #[serde(skip_serializing_if = "is_false")]
467 consensus_fast_commit_sync: bool,
468
469 #[serde(skip_serializing_if = "is_false")]
471 move_native_tx_context: bool,
472
473 #[serde(skip_serializing_if = "is_false")]
475 additional_borrow_checks: bool,
476}
477
478fn is_true(b: &bool) -> bool {
479 *b
480}
481
482fn is_false(b: &bool) -> bool {
483 !b
484}
485
486#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
488pub enum ConsensusTransactionOrdering {
489 #[default]
492 None,
493 ByGasPrice,
495}
496
497impl ConsensusTransactionOrdering {
498 pub fn is_none(&self) -> bool {
499 matches!(self, ConsensusTransactionOrdering::None)
500 }
501}
502
503#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
505pub enum PerObjectCongestionControlMode {
506 #[default]
507 None, TotalGasBudget, TotalTxCount, }
511
512impl PerObjectCongestionControlMode {
513 pub fn is_none(&self) -> bool {
514 matches!(self, PerObjectCongestionControlMode::None)
515 }
516}
517
518#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
520pub enum ConsensusChoice {
521 #[deprecated(note = "Mysticeti was replaced by Starfish")]
524 MysticetiDeprecated,
525 #[default]
526 Starfish,
527}
528
529#[expect(deprecated)]
530impl ConsensusChoice {
531 fn mysticeti_deprecated() -> Self {
538 ConsensusChoice::MysticetiDeprecated
539 }
540
541 pub fn is_mysticeti_deprecated(&self) -> bool {
542 matches!(self, ConsensusChoice::MysticetiDeprecated)
543 }
544 pub fn is_starfish(&self) -> bool {
545 matches!(self, ConsensusChoice::Starfish)
546 }
547}
548
549#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
551pub enum ConsensusNetwork {
552 #[default]
553 Tonic,
554}
555
556impl ConsensusNetwork {
557 pub fn is_tonic(&self) -> bool {
558 matches!(self, ConsensusNetwork::Tonic)
559 }
560}
561
562#[skip_serializing_none]
596#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
597pub struct ProtocolConfig {
598 pub version: ProtocolVersion,
599
600 feature_flags: FeatureFlags,
601
602 max_tx_size_bytes: Option<u64>,
607
608 max_input_objects: Option<u64>,
611
612 max_size_written_objects: Option<u64>,
617 max_size_written_objects_system_tx: Option<u64>,
621
622 max_serialized_tx_effects_size_bytes: Option<u64>,
624
625 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
627
628 max_gas_payment_objects: Option<u32>,
630
631 max_modules_in_publish: Option<u32>,
633
634 max_package_dependencies: Option<u32>,
636
637 max_arguments: Option<u32>,
640
641 max_type_arguments: Option<u32>,
643
644 max_type_argument_depth: Option<u32>,
646
647 max_pure_argument_size: Option<u32>,
649
650 max_programmable_tx_commands: Option<u32>,
652
653 move_binary_format_version: Option<u32>,
659 min_move_binary_format_version: Option<u32>,
660
661 binary_module_handles: Option<u16>,
663 binary_struct_handles: Option<u16>,
664 binary_function_handles: Option<u16>,
665 binary_function_instantiations: Option<u16>,
666 binary_signatures: Option<u16>,
667 binary_constant_pool: Option<u16>,
668 binary_identifiers: Option<u16>,
669 binary_address_identifiers: Option<u16>,
670 binary_struct_defs: Option<u16>,
671 binary_struct_def_instantiations: Option<u16>,
672 binary_function_defs: Option<u16>,
673 binary_field_handles: Option<u16>,
674 binary_field_instantiations: Option<u16>,
675 binary_friend_decls: Option<u16>,
676 binary_enum_defs: Option<u16>,
677 binary_enum_def_instantiations: Option<u16>,
678 binary_variant_handles: Option<u16>,
679 binary_variant_instantiation_handles: Option<u16>,
680
681 max_move_object_size: Option<u64>,
684
685 max_move_package_size: Option<u64>,
690
691 max_publish_or_upgrade_per_ptb: Option<u64>,
694
695 max_tx_gas: Option<u64>,
697
698 max_auth_gas: Option<u64>,
700
701 max_gas_price: Option<u64>,
704
705 max_gas_computation_bucket: Option<u64>,
708
709 gas_rounding_step: Option<u64>,
711
712 max_loop_depth: Option<u64>,
714
715 max_generic_instantiation_length: Option<u64>,
718
719 max_function_parameters: Option<u64>,
722
723 max_basic_blocks: Option<u64>,
726
727 max_value_stack_size: Option<u64>,
729
730 max_type_nodes: Option<u64>,
734
735 max_push_size: Option<u64>,
738
739 max_struct_definitions: Option<u64>,
742
743 max_function_definitions: Option<u64>,
746
747 max_fields_in_struct: Option<u64>,
750
751 max_dependency_depth: Option<u64>,
754
755 max_num_event_emit: Option<u64>,
758
759 max_num_new_move_object_ids: Option<u64>,
762
763 max_num_new_move_object_ids_system_tx: Option<u64>,
766
767 max_num_deleted_move_object_ids: Option<u64>,
770
771 max_num_deleted_move_object_ids_system_tx: Option<u64>,
774
775 max_num_transferred_move_object_ids: Option<u64>,
778
779 max_num_transferred_move_object_ids_system_tx: Option<u64>,
782
783 max_event_emit_size: Option<u64>,
785
786 max_event_emit_size_total: Option<u64>,
788
789 max_move_vector_len: Option<u64>,
792
793 max_move_identifier_len: Option<u64>,
796
797 max_move_value_depth: Option<u64>,
799
800 max_move_enum_variants: Option<u64>,
803
804 max_back_edges_per_function: Option<u64>,
807
808 max_back_edges_per_module: Option<u64>,
811
812 max_verifier_meter_ticks_per_function: Option<u64>,
815
816 max_meter_ticks_per_module: Option<u64>,
819
820 max_meter_ticks_per_package: Option<u64>,
823
824 object_runtime_max_num_cached_objects: Option<u64>,
831
832 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
835
836 object_runtime_max_num_store_entries: Option<u64>,
839
840 object_runtime_max_num_store_entries_system_tx: Option<u64>,
843
844 base_tx_cost_fixed: Option<u64>,
849
850 package_publish_cost_fixed: Option<u64>,
854
855 base_tx_cost_per_byte: Option<u64>,
859
860 package_publish_cost_per_byte: Option<u64>,
862
863 obj_access_cost_read_per_byte: Option<u64>,
865
866 obj_access_cost_mutate_per_byte: Option<u64>,
868
869 obj_access_cost_delete_per_byte: Option<u64>,
871
872 obj_access_cost_verify_per_byte: Option<u64>,
882
883 max_type_to_layout_nodes: Option<u64>,
885
886 max_ptb_value_size: Option<u64>,
888
889 gas_model_version: Option<u64>,
894
895 obj_data_cost_refundable: Option<u64>,
901
902 obj_metadata_cost_non_refundable: Option<u64>,
906
907 storage_rebate_rate: Option<u64>,
913
914 reward_slashing_rate: Option<u64>,
917
918 storage_gas_price: Option<u64>,
920
921 base_gas_price: Option<u64>,
923
924 validator_target_reward: Option<u64>,
926
927 max_transactions_per_checkpoint: Option<u64>,
934
935 max_checkpoint_size_bytes: Option<u64>,
939
940 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
946
947 address_from_bytes_cost_base: Option<u64>,
952 address_to_u256_cost_base: Option<u64>,
954 address_from_u256_cost_base: Option<u64>,
956
957 config_read_setting_impl_cost_base: Option<u64>,
962 config_read_setting_impl_cost_per_byte: Option<u64>,
963
964 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
968 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
969 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
970 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
971 dynamic_field_add_child_object_cost_base: Option<u64>,
974 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
975 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
976 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
977 dynamic_field_borrow_child_object_cost_base: Option<u64>,
980 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
981 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
982 dynamic_field_remove_child_object_cost_base: Option<u64>,
985 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
986 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
987 dynamic_field_has_child_object_cost_base: Option<u64>,
990 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
993 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
994 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
995
996 event_emit_cost_base: Option<u64>,
999 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1000 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1001 event_emit_output_cost_per_byte: Option<u64>,
1002
1003 object_borrow_uid_cost_base: Option<u64>,
1006 object_delete_impl_cost_base: Option<u64>,
1008 object_record_new_uid_cost_base: Option<u64>,
1010
1011 transfer_transfer_internal_cost_base: Option<u64>,
1014 transfer_freeze_object_cost_base: Option<u64>,
1016 transfer_share_object_cost_base: Option<u64>,
1018 transfer_receive_object_cost_base: Option<u64>,
1021
1022 tx_context_derive_id_cost_base: Option<u64>,
1025 tx_context_fresh_id_cost_base: Option<u64>,
1026 tx_context_sender_cost_base: Option<u64>,
1027 tx_context_digest_cost_base: Option<u64>,
1028 tx_context_epoch_cost_base: Option<u64>,
1029 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1030 tx_context_sponsor_cost_base: Option<u64>,
1031 tx_context_rgp_cost_base: Option<u64>,
1032 tx_context_gas_price_cost_base: Option<u64>,
1033 tx_context_gas_budget_cost_base: Option<u64>,
1034 tx_context_ids_created_cost_base: Option<u64>,
1035 tx_context_replace_cost_base: Option<u64>,
1036
1037 types_is_one_time_witness_cost_base: Option<u64>,
1040 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1041 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1042
1043 validator_validate_metadata_cost_base: Option<u64>,
1046 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1047
1048 crypto_invalid_arguments_cost: Option<u64>,
1050 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1052 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1053 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1054
1055 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1057 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1058 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1059
1060 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1062 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1063 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1064 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1065 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1066 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1067
1068 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1070
1071 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1073 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1074 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1075 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1076 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1077 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1078
1079 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1081 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1082 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1083 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1084 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1085 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1086
1087 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1089 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1090 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1091 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1092 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1093 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1094
1095 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1097 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1098 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1099
1100 ed25519_ed25519_verify_cost_base: Option<u64>,
1102 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1103 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1104
1105 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1107 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1108
1109 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1111 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1112 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1113 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1114 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1115
1116 hash_blake2b256_cost_base: Option<u64>,
1118 hash_blake2b256_data_cost_per_byte: Option<u64>,
1119 hash_blake2b256_data_cost_per_block: Option<u64>,
1120
1121 hash_keccak256_cost_base: Option<u64>,
1123 hash_keccak256_data_cost_per_byte: Option<u64>,
1124 hash_keccak256_data_cost_per_block: Option<u64>,
1125
1126 poseidon_bn254_cost_base: Option<u64>,
1128 poseidon_bn254_cost_per_block: Option<u64>,
1129
1130 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1132 group_ops_bls12381_decode_g1_cost: Option<u64>,
1133 group_ops_bls12381_decode_g2_cost: Option<u64>,
1134 group_ops_bls12381_decode_gt_cost: Option<u64>,
1135 group_ops_bls12381_scalar_add_cost: Option<u64>,
1136 group_ops_bls12381_g1_add_cost: Option<u64>,
1137 group_ops_bls12381_g2_add_cost: Option<u64>,
1138 group_ops_bls12381_gt_add_cost: Option<u64>,
1139 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1140 group_ops_bls12381_g1_sub_cost: Option<u64>,
1141 group_ops_bls12381_g2_sub_cost: Option<u64>,
1142 group_ops_bls12381_gt_sub_cost: Option<u64>,
1143 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1144 group_ops_bls12381_g1_mul_cost: Option<u64>,
1145 group_ops_bls12381_g2_mul_cost: Option<u64>,
1146 group_ops_bls12381_gt_mul_cost: Option<u64>,
1147 group_ops_bls12381_scalar_div_cost: Option<u64>,
1148 group_ops_bls12381_g1_div_cost: Option<u64>,
1149 group_ops_bls12381_g2_div_cost: Option<u64>,
1150 group_ops_bls12381_gt_div_cost: Option<u64>,
1151 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1152 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1153 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1154 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1155 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1156 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1157 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1158 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1159 group_ops_bls12381_msm_max_len: Option<u32>,
1160 group_ops_bls12381_pairing_cost: Option<u64>,
1161 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1162 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1163 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1164 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1165 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1166
1167 hmac_hmac_sha3_256_cost_base: Option<u64>,
1169 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1170 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1171
1172 #[deprecated]
1174 check_zklogin_id_cost_base: Option<u64>,
1175 #[deprecated]
1177 check_zklogin_issuer_cost_base: Option<u64>,
1178
1179 vdf_verify_vdf_cost: Option<u64>,
1180 vdf_hash_to_input_cost: Option<u64>,
1181
1182 bcs_per_byte_serialized_cost: Option<u64>,
1184 bcs_legacy_min_output_size_cost: Option<u64>,
1185 bcs_failure_cost: Option<u64>,
1186
1187 hash_sha2_256_base_cost: Option<u64>,
1188 hash_sha2_256_per_byte_cost: Option<u64>,
1189 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1190 hash_sha3_256_base_cost: Option<u64>,
1191 hash_sha3_256_per_byte_cost: Option<u64>,
1192 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1193 type_name_get_base_cost: Option<u64>,
1194 type_name_get_per_byte_cost: Option<u64>,
1195
1196 string_check_utf8_base_cost: Option<u64>,
1197 string_check_utf8_per_byte_cost: Option<u64>,
1198 string_is_char_boundary_base_cost: Option<u64>,
1199 string_sub_string_base_cost: Option<u64>,
1200 string_sub_string_per_byte_cost: Option<u64>,
1201 string_index_of_base_cost: Option<u64>,
1202 string_index_of_per_byte_pattern_cost: Option<u64>,
1203 string_index_of_per_byte_searched_cost: Option<u64>,
1204
1205 vector_empty_base_cost: Option<u64>,
1206 vector_length_base_cost: Option<u64>,
1207 vector_push_back_base_cost: Option<u64>,
1208 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1209 vector_borrow_base_cost: Option<u64>,
1210 vector_pop_back_base_cost: Option<u64>,
1211 vector_destroy_empty_base_cost: Option<u64>,
1212 vector_swap_base_cost: Option<u64>,
1213 debug_print_base_cost: Option<u64>,
1214 debug_print_stack_trace_base_cost: Option<u64>,
1215
1216 execution_version: Option<u64>,
1218
1219 consensus_bad_nodes_stake_threshold: Option<u64>,
1223
1224 #[deprecated]
1225 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1226 #[deprecated]
1230 max_age_of_jwk_in_epochs: Option<u64>,
1231
1232 random_beacon_reduction_allowed_delta: Option<u16>,
1236
1237 random_beacon_reduction_lower_bound: Option<u32>,
1240
1241 random_beacon_dkg_timeout_round: Option<u32>,
1244
1245 random_beacon_min_round_interval_ms: Option<u64>,
1247
1248 random_beacon_dkg_version: Option<u64>,
1252
1253 consensus_max_transaction_size_bytes: Option<u64>,
1258 consensus_max_transactions_in_block_bytes: Option<u64>,
1260 consensus_max_num_transactions_in_block: Option<u64>,
1262
1263 max_deferral_rounds_for_congestion_control: Option<u64>,
1267
1268 min_checkpoint_interval_ms: Option<u64>,
1270
1271 checkpoint_summary_version_specific_data: Option<u64>,
1273
1274 max_soft_bundle_size: Option<u64>,
1277
1278 bridge_should_try_to_finalize_committee: Option<bool>,
1283
1284 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1290
1291 max_committee_members_count: Option<u64>,
1295
1296 consensus_gc_depth: Option<u32>,
1299
1300 consensus_max_acknowledgments_per_block: Option<u32>,
1306
1307 max_congestion_limit_overshoot_per_commit: Option<u64>,
1312
1313 scorer_version: Option<u16>,
1322
1323 auth_context_digest_cost_base: Option<u64>,
1326 auth_context_tx_data_bytes_cost_base: Option<u64>,
1328 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1329 auth_context_tx_commands_cost_base: Option<u64>,
1331 auth_context_tx_commands_cost_per_byte: Option<u64>,
1332 auth_context_tx_inputs_cost_base: Option<u64>,
1334 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1335 auth_context_replace_cost_base: Option<u64>,
1338 auth_context_replace_cost_per_byte: Option<u64>,
1339}
1340
1341impl ProtocolConfig {
1343 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1356 self.feature_flags
1357 .disable_invariant_violation_check_in_swap_loc
1358 }
1359
1360 pub fn no_extraneous_module_bytes(&self) -> bool {
1361 self.feature_flags.no_extraneous_module_bytes
1362 }
1363
1364 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1365 self.feature_flags.consensus_transaction_ordering
1366 }
1367
1368 pub fn dkg_version(&self) -> u64 {
1369 self.random_beacon_dkg_version.unwrap_or(1)
1371 }
1372
1373 pub fn hardened_otw_check(&self) -> bool {
1374 self.feature_flags.hardened_otw_check
1375 }
1376
1377 pub fn enable_poseidon(&self) -> bool {
1378 self.feature_flags.enable_poseidon
1379 }
1380
1381 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1382 self.feature_flags.enable_group_ops_native_function_msm
1383 }
1384
1385 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1386 self.feature_flags.per_object_congestion_control_mode
1387 }
1388
1389 pub fn consensus_choice(&self) -> ConsensusChoice {
1390 self.feature_flags.consensus_choice
1391 }
1392
1393 pub fn consensus_network(&self) -> ConsensusNetwork {
1394 self.feature_flags.consensus_network
1395 }
1396
1397 pub fn enable_vdf(&self) -> bool {
1398 self.feature_flags.enable_vdf
1399 }
1400
1401 pub fn passkey_auth(&self) -> bool {
1402 self.feature_flags.passkey_auth
1403 }
1404
1405 pub fn max_transaction_size_bytes(&self) -> u64 {
1406 self.consensus_max_transaction_size_bytes
1408 .unwrap_or(256 * 1024)
1409 }
1410
1411 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1412 if cfg!(msim) {
1413 256 * 1024
1414 } else {
1415 self.consensus_max_transactions_in_block_bytes
1416 .unwrap_or(512 * 1024)
1417 }
1418 }
1419
1420 pub fn max_num_transactions_in_block(&self) -> u64 {
1421 if cfg!(msim) {
1422 8
1423 } else {
1424 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1425 }
1426 }
1427
1428 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1429 self.feature_flags.rethrow_serialization_type_layout_errors
1430 }
1431
1432 pub fn relocate_event_module(&self) -> bool {
1433 self.feature_flags.relocate_event_module
1434 }
1435
1436 pub fn protocol_defined_base_fee(&self) -> bool {
1437 self.feature_flags.protocol_defined_base_fee
1438 }
1439
1440 pub fn uncompressed_g1_group_elements(&self) -> bool {
1441 self.feature_flags.uncompressed_g1_group_elements
1442 }
1443
1444 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1445 self.feature_flags
1446 .disallow_new_modules_in_deps_only_packages
1447 }
1448
1449 pub fn native_charging_v2(&self) -> bool {
1450 self.feature_flags.native_charging_v2
1451 }
1452
1453 pub fn consensus_round_prober(&self) -> bool {
1454 self.feature_flags.consensus_round_prober
1455 }
1456
1457 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1458 self.feature_flags
1459 .consensus_distributed_vote_scoring_strategy
1460 }
1461
1462 pub fn gc_depth(&self) -> u32 {
1463 if cfg!(msim) {
1464 min(5, self.consensus_gc_depth.unwrap_or(0))
1466 } else {
1467 self.consensus_gc_depth.unwrap_or(0)
1468 }
1469 }
1470
1471 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1472 let res = self.feature_flags.consensus_linearize_subdag_v2;
1473 assert!(
1474 !res || self.gc_depth() > 0,
1475 "The consensus linearize sub dag V2 requires GC to be enabled"
1476 );
1477 res
1478 }
1479
1480 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1481 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1482 }
1483
1484 pub fn variant_nodes(&self) -> bool {
1485 self.feature_flags.variant_nodes
1486 }
1487
1488 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1489 self.feature_flags.consensus_smart_ancestor_selection
1490 }
1491
1492 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1493 self.feature_flags
1494 .consensus_round_prober_probe_accepted_rounds
1495 }
1496
1497 pub fn consensus_zstd_compression(&self) -> bool {
1498 self.feature_flags.consensus_zstd_compression
1499 }
1500
1501 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1502 self.feature_flags
1503 .congestion_control_min_free_execution_slot
1504 }
1505
1506 pub fn accept_passkey_in_multisig(&self) -> bool {
1507 self.feature_flags.accept_passkey_in_multisig
1508 }
1509
1510 pub fn consensus_batched_block_sync(&self) -> bool {
1511 self.feature_flags.consensus_batched_block_sync
1512 }
1513
1514 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1517 self.feature_flags
1518 .congestion_control_gas_price_feedback_mechanism
1519 }
1520
1521 pub fn validate_identifier_inputs(&self) -> bool {
1522 self.feature_flags.validate_identifier_inputs
1523 }
1524
1525 pub fn minimize_child_object_mutations(&self) -> bool {
1526 self.feature_flags.minimize_child_object_mutations
1527 }
1528
1529 pub fn dependency_linkage_error(&self) -> bool {
1530 self.feature_flags.dependency_linkage_error
1531 }
1532
1533 pub fn additional_multisig_checks(&self) -> bool {
1534 self.feature_flags.additional_multisig_checks
1535 }
1536
1537 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1538 0
1541 }
1542
1543 pub fn normalize_ptb_arguments(&self) -> bool {
1544 self.feature_flags.normalize_ptb_arguments
1545 }
1546
1547 pub fn select_committee_from_eligible_validators(&self) -> bool {
1548 let res = self.feature_flags.select_committee_from_eligible_validators;
1549 assert!(
1550 !res || (self.protocol_defined_base_fee()
1551 && self.max_committee_members_count_as_option().is_some()),
1552 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1553 );
1554 res
1555 }
1556
1557 pub fn track_non_committee_eligible_validators(&self) -> bool {
1558 self.feature_flags.track_non_committee_eligible_validators
1559 }
1560
1561 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1562 let res = self
1563 .feature_flags
1564 .select_committee_supporting_next_epoch_version;
1565 assert!(
1566 !res || (self.track_non_committee_eligible_validators()
1567 && self.select_committee_from_eligible_validators()),
1568 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1569 );
1570 res
1571 }
1572
1573 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1574 let res = self
1575 .feature_flags
1576 .consensus_median_timestamp_with_checkpoint_enforcement;
1577 assert!(
1578 !res || self.gc_depth() > 0,
1579 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1580 );
1581 res
1582 }
1583
1584 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1585 self.feature_flags
1586 .consensus_commit_transactions_only_for_traversed_headers
1587 }
1588
1589 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1592 self.feature_flags
1593 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1594 }
1595
1596 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1599 self.feature_flags
1600 .separate_gas_price_feedback_mechanism_for_randomness
1601 }
1602
1603 pub fn metadata_in_module_bytes(&self) -> bool {
1604 self.feature_flags.metadata_in_module_bytes
1605 }
1606
1607 pub fn publish_package_metadata(&self) -> bool {
1608 self.feature_flags.publish_package_metadata
1609 }
1610
1611 pub fn enable_move_authentication(&self) -> bool {
1612 self.feature_flags.enable_move_authentication
1613 }
1614
1615 pub fn additional_borrow_checks(&self) -> bool {
1616 self.feature_flags.additional_borrow_checks
1617 }
1618
1619 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1620 let enable_move_authentication_for_sponsor =
1621 self.feature_flags.enable_move_authentication_for_sponsor;
1622 assert!(
1623 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1624 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1625 );
1626 enable_move_authentication_for_sponsor
1627 }
1628
1629 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1630 self.feature_flags.pass_validator_scores_to_advance_epoch
1631 }
1632
1633 pub fn calculate_validator_scores(&self) -> bool {
1634 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1635 assert!(
1636 !calculate_validator_scores || self.scorer_version.is_some(),
1637 "calculate_validator_scores requires scorer_version to be set"
1638 );
1639 calculate_validator_scores
1640 }
1641
1642 pub fn adjust_rewards_by_score(&self) -> bool {
1643 let adjust = self.feature_flags.adjust_rewards_by_score;
1644 assert!(
1645 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1646 "adjust_rewards_by_score requires scorer_version to be set"
1647 );
1648 adjust
1649 }
1650
1651 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1652 let pass = self
1653 .feature_flags
1654 .pass_calculated_validator_scores_to_advance_epoch;
1655 assert!(
1656 !pass
1657 || (self.pass_validator_scores_to_advance_epoch()
1658 && self.calculate_validator_scores()),
1659 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
1660 );
1661 pass
1662 }
1663 pub fn consensus_fast_commit_sync(&self) -> bool {
1664 let res = self.feature_flags.consensus_fast_commit_sync;
1665 assert!(
1666 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
1667 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
1668 );
1669 res
1670 }
1671
1672 pub fn move_native_tx_context(&self) -> bool {
1673 self.feature_flags.move_native_tx_context
1674 }
1675}
1676
1677#[cfg(not(msim))]
1678static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1679
1680#[cfg(msim)]
1682thread_local! {
1683 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
1684}
1685
1686impl ProtocolConfig {
1688 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
1691 assert!(
1693 version >= ProtocolVersion::MIN,
1694 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
1695 version,
1696 ProtocolVersion::MIN.0,
1697 );
1698 assert!(
1699 version <= ProtocolVersion::MAX_ALLOWED,
1700 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
1701 version,
1702 ProtocolVersion::MAX_ALLOWED.0,
1703 );
1704
1705 let mut ret = Self::get_for_version_impl(version, chain);
1706 ret.version = version;
1707
1708 ret = CONFIG_OVERRIDE.with(|ovr| {
1709 if let Some(override_fn) = &*ovr.borrow() {
1710 warn!(
1711 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
1712 );
1713 override_fn(version, ret)
1714 } else {
1715 ret
1716 }
1717 });
1718
1719 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
1720 warn!(
1721 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
1722 );
1723 let overrides: ProtocolConfigOptional =
1724 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
1725 .expect("failed to parse ProtocolConfig override env variables");
1726 overrides.apply_to(&mut ret);
1727 }
1728
1729 ret
1730 }
1731
1732 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
1735 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
1736 let mut ret = Self::get_for_version_impl(version, chain);
1737 ret.version = version;
1738 Some(ret)
1739 } else {
1740 None
1741 }
1742 }
1743
1744 #[cfg(not(msim))]
1745 pub fn poison_get_for_min_version() {
1746 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
1747 }
1748
1749 #[cfg(not(msim))]
1750 fn load_poison_get_for_min_version() -> bool {
1751 POISON_VERSION_METHODS.load(Ordering::Relaxed)
1752 }
1753
1754 #[cfg(msim)]
1755 pub fn poison_get_for_min_version() {
1756 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
1757 }
1758
1759 #[cfg(msim)]
1760 fn load_poison_get_for_min_version() -> bool {
1761 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
1762 }
1763
1764 pub fn convert_type_argument_error(&self) -> bool {
1765 self.feature_flags.convert_type_argument_error
1766 }
1767
1768 pub fn get_for_min_version() -> Self {
1772 if Self::load_poison_get_for_min_version() {
1773 panic!("get_for_min_version called on validator");
1774 }
1775 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
1776 }
1777
1778 #[expect(non_snake_case)]
1789 pub fn get_for_max_version_UNSAFE() -> Self {
1790 if Self::load_poison_get_for_min_version() {
1791 panic!("get_for_max_version_UNSAFE called on validator");
1792 }
1793 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
1794 }
1795
1796 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
1797 #[cfg(msim)]
1798 {
1799 if version > ProtocolVersion::MAX {
1801 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
1802 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
1803 return config;
1804 }
1805 }
1806
1807 let mut cfg = Self {
1811 version,
1812
1813 feature_flags: Default::default(),
1814
1815 max_tx_size_bytes: Some(128 * 1024),
1816 max_input_objects: Some(2048),
1819 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
1820 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
1821 max_gas_payment_objects: Some(256),
1822 max_modules_in_publish: Some(64),
1823 max_package_dependencies: Some(32),
1824 max_arguments: Some(512),
1825 max_type_arguments: Some(16),
1826 max_type_argument_depth: Some(16),
1827 max_pure_argument_size: Some(16 * 1024),
1828 max_programmable_tx_commands: Some(1024),
1829 move_binary_format_version: Some(7),
1830 min_move_binary_format_version: Some(6),
1831 binary_module_handles: Some(100),
1832 binary_struct_handles: Some(300),
1833 binary_function_handles: Some(1500),
1834 binary_function_instantiations: Some(750),
1835 binary_signatures: Some(1000),
1836 binary_constant_pool: Some(4000),
1837 binary_identifiers: Some(10000),
1838 binary_address_identifiers: Some(100),
1839 binary_struct_defs: Some(200),
1840 binary_struct_def_instantiations: Some(100),
1841 binary_function_defs: Some(1000),
1842 binary_field_handles: Some(500),
1843 binary_field_instantiations: Some(250),
1844 binary_friend_decls: Some(100),
1845 binary_enum_defs: None,
1846 binary_enum_def_instantiations: None,
1847 binary_variant_handles: None,
1848 binary_variant_instantiation_handles: None,
1849 max_move_object_size: Some(250 * 1024),
1850 max_move_package_size: Some(100 * 1024),
1851 max_publish_or_upgrade_per_ptb: Some(5),
1852 max_auth_gas: None,
1854 max_tx_gas: Some(50_000_000_000),
1856 max_gas_price: Some(100_000),
1857 max_gas_computation_bucket: Some(5_000_000),
1858 max_loop_depth: Some(5),
1859 max_generic_instantiation_length: Some(32),
1860 max_function_parameters: Some(128),
1861 max_basic_blocks: Some(1024),
1862 max_value_stack_size: Some(1024),
1863 max_type_nodes: Some(256),
1864 max_push_size: Some(10000),
1865 max_struct_definitions: Some(200),
1866 max_function_definitions: Some(1000),
1867 max_fields_in_struct: Some(32),
1868 max_dependency_depth: Some(100),
1869 max_num_event_emit: Some(1024),
1870 max_num_new_move_object_ids: Some(2048),
1871 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
1872 max_num_deleted_move_object_ids: Some(2048),
1873 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
1874 max_num_transferred_move_object_ids: Some(2048),
1875 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
1876 max_event_emit_size: Some(250 * 1024),
1877 max_move_vector_len: Some(256 * 1024),
1878 max_type_to_layout_nodes: None,
1879 max_ptb_value_size: None,
1880
1881 max_back_edges_per_function: Some(10_000),
1882 max_back_edges_per_module: Some(10_000),
1883
1884 max_verifier_meter_ticks_per_function: Some(16_000_000),
1885
1886 max_meter_ticks_per_module: Some(16_000_000),
1887 max_meter_ticks_per_package: Some(16_000_000),
1888
1889 object_runtime_max_num_cached_objects: Some(1000),
1890 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
1891 object_runtime_max_num_store_entries: Some(1000),
1892 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
1893 base_tx_cost_fixed: Some(1_000),
1895 package_publish_cost_fixed: Some(1_000),
1896 base_tx_cost_per_byte: Some(0),
1897 package_publish_cost_per_byte: Some(80),
1898 obj_access_cost_read_per_byte: Some(15),
1899 obj_access_cost_mutate_per_byte: Some(40),
1900 obj_access_cost_delete_per_byte: Some(40),
1901 obj_access_cost_verify_per_byte: Some(200),
1902 obj_data_cost_refundable: Some(100),
1903 obj_metadata_cost_non_refundable: Some(50),
1904 gas_model_version: Some(1),
1905 storage_rebate_rate: Some(10000),
1906 reward_slashing_rate: Some(10000),
1908 storage_gas_price: Some(76),
1909 base_gas_price: None,
1910 validator_target_reward: Some(767_000 * 1_000_000_000),
1913 max_transactions_per_checkpoint: Some(10_000),
1914 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
1915
1916 buffer_stake_for_protocol_upgrade_bps: Some(5000),
1918
1919 address_from_bytes_cost_base: Some(52),
1923 address_to_u256_cost_base: Some(52),
1925 address_from_u256_cost_base: Some(52),
1927
1928 config_read_setting_impl_cost_base: Some(100),
1931 config_read_setting_impl_cost_per_byte: Some(40),
1932
1933 dynamic_field_hash_type_and_key_cost_base: Some(100),
1937 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
1938 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
1939 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
1940 dynamic_field_add_child_object_cost_base: Some(100),
1943 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
1944 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
1945 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
1946 dynamic_field_borrow_child_object_cost_base: Some(100),
1949 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
1950 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
1951 dynamic_field_remove_child_object_cost_base: Some(100),
1954 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
1955 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
1956 dynamic_field_has_child_object_cost_base: Some(100),
1959 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
1962 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
1963 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
1964
1965 event_emit_cost_base: Some(52),
1968 event_emit_value_size_derivation_cost_per_byte: Some(2),
1969 event_emit_tag_size_derivation_cost_per_byte: Some(5),
1970 event_emit_output_cost_per_byte: Some(10),
1971
1972 object_borrow_uid_cost_base: Some(52),
1975 object_delete_impl_cost_base: Some(52),
1977 object_record_new_uid_cost_base: Some(52),
1979
1980 transfer_transfer_internal_cost_base: Some(52),
1984 transfer_freeze_object_cost_base: Some(52),
1986 transfer_share_object_cost_base: Some(52),
1988 transfer_receive_object_cost_base: Some(52),
1989
1990 tx_context_derive_id_cost_base: Some(52),
1994 tx_context_fresh_id_cost_base: None,
1995 tx_context_sender_cost_base: None,
1996 tx_context_digest_cost_base: None,
1997 tx_context_epoch_cost_base: None,
1998 tx_context_epoch_timestamp_ms_cost_base: None,
1999 tx_context_sponsor_cost_base: None,
2000 tx_context_rgp_cost_base: None,
2001 tx_context_gas_price_cost_base: None,
2002 tx_context_gas_budget_cost_base: None,
2003 tx_context_ids_created_cost_base: None,
2004 tx_context_replace_cost_base: None,
2005
2006 types_is_one_time_witness_cost_base: Some(52),
2009 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2010 types_is_one_time_witness_type_cost_per_byte: Some(2),
2011
2012 validator_validate_metadata_cost_base: Some(52),
2016 validator_validate_metadata_data_cost_per_byte: Some(2),
2017
2018 crypto_invalid_arguments_cost: Some(100),
2020 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2022 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2023 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2024
2025 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2027 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2028 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2029
2030 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2032 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2033 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2034 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2035 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2036 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2037
2038 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2040
2041 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2043 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2044 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2045 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2046 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2047 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2048
2049 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2051 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2052 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2053 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2054 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2055 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2056
2057 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2059 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2060 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2061 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2062 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2063 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2064
2065 ecvrf_ecvrf_verify_cost_base: Some(52),
2067 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2068 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2069
2070 ed25519_ed25519_verify_cost_base: Some(52),
2072 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2073 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2074
2075 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2077 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2078
2079 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2081 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2082 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2083 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2084 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2085
2086 hash_blake2b256_cost_base: Some(52),
2088 hash_blake2b256_data_cost_per_byte: Some(2),
2089 hash_blake2b256_data_cost_per_block: Some(2),
2090 hash_keccak256_cost_base: Some(52),
2092 hash_keccak256_data_cost_per_byte: Some(2),
2093 hash_keccak256_data_cost_per_block: Some(2),
2094
2095 poseidon_bn254_cost_base: None,
2096 poseidon_bn254_cost_per_block: None,
2097
2098 hmac_hmac_sha3_256_cost_base: Some(52),
2100 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2101 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2102
2103 group_ops_bls12381_decode_scalar_cost: Some(52),
2105 group_ops_bls12381_decode_g1_cost: Some(52),
2106 group_ops_bls12381_decode_g2_cost: Some(52),
2107 group_ops_bls12381_decode_gt_cost: Some(52),
2108 group_ops_bls12381_scalar_add_cost: Some(52),
2109 group_ops_bls12381_g1_add_cost: Some(52),
2110 group_ops_bls12381_g2_add_cost: Some(52),
2111 group_ops_bls12381_gt_add_cost: Some(52),
2112 group_ops_bls12381_scalar_sub_cost: Some(52),
2113 group_ops_bls12381_g1_sub_cost: Some(52),
2114 group_ops_bls12381_g2_sub_cost: Some(52),
2115 group_ops_bls12381_gt_sub_cost: Some(52),
2116 group_ops_bls12381_scalar_mul_cost: Some(52),
2117 group_ops_bls12381_g1_mul_cost: Some(52),
2118 group_ops_bls12381_g2_mul_cost: Some(52),
2119 group_ops_bls12381_gt_mul_cost: Some(52),
2120 group_ops_bls12381_scalar_div_cost: Some(52),
2121 group_ops_bls12381_g1_div_cost: Some(52),
2122 group_ops_bls12381_g2_div_cost: Some(52),
2123 group_ops_bls12381_gt_div_cost: Some(52),
2124 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2125 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2126 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2127 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2128 group_ops_bls12381_g1_msm_base_cost: Some(52),
2129 group_ops_bls12381_g2_msm_base_cost: Some(52),
2130 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2131 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2132 group_ops_bls12381_msm_max_len: Some(32),
2133 group_ops_bls12381_pairing_cost: Some(52),
2134 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2135 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2136 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2137 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2138 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2139
2140 #[allow(deprecated)]
2142 check_zklogin_id_cost_base: Some(200),
2143 #[allow(deprecated)]
2144 check_zklogin_issuer_cost_base: Some(200),
2146
2147 vdf_verify_vdf_cost: None,
2148 vdf_hash_to_input_cost: None,
2149
2150 bcs_per_byte_serialized_cost: Some(2),
2151 bcs_legacy_min_output_size_cost: Some(1),
2152 bcs_failure_cost: Some(52),
2153 hash_sha2_256_base_cost: Some(52),
2154 hash_sha2_256_per_byte_cost: Some(2),
2155 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2156 hash_sha3_256_base_cost: Some(52),
2157 hash_sha3_256_per_byte_cost: Some(2),
2158 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2159 type_name_get_base_cost: Some(52),
2160 type_name_get_per_byte_cost: Some(2),
2161 string_check_utf8_base_cost: Some(52),
2162 string_check_utf8_per_byte_cost: Some(2),
2163 string_is_char_boundary_base_cost: Some(52),
2164 string_sub_string_base_cost: Some(52),
2165 string_sub_string_per_byte_cost: Some(2),
2166 string_index_of_base_cost: Some(52),
2167 string_index_of_per_byte_pattern_cost: Some(2),
2168 string_index_of_per_byte_searched_cost: Some(2),
2169 vector_empty_base_cost: Some(52),
2170 vector_length_base_cost: Some(52),
2171 vector_push_back_base_cost: Some(52),
2172 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2173 vector_borrow_base_cost: Some(52),
2174 vector_pop_back_base_cost: Some(52),
2175 vector_destroy_empty_base_cost: Some(52),
2176 vector_swap_base_cost: Some(52),
2177 debug_print_base_cost: Some(52),
2178 debug_print_stack_trace_base_cost: Some(52),
2179
2180 max_size_written_objects: Some(5 * 1000 * 1000),
2181 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2184
2185 max_move_identifier_len: Some(128),
2187 max_move_value_depth: Some(128),
2188 max_move_enum_variants: None,
2189
2190 gas_rounding_step: Some(1_000),
2191
2192 execution_version: Some(1),
2193
2194 max_event_emit_size_total: Some(
2197 256 * 250 * 1024, ),
2199
2200 consensus_bad_nodes_stake_threshold: Some(20),
2207
2208 #[allow(deprecated)]
2210 max_jwk_votes_per_validator_per_epoch: Some(240),
2211
2212 #[allow(deprecated)]
2213 max_age_of_jwk_in_epochs: Some(1),
2214
2215 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2219
2220 random_beacon_reduction_allowed_delta: Some(800),
2221
2222 random_beacon_reduction_lower_bound: Some(1000),
2223 random_beacon_dkg_timeout_round: Some(3000),
2224 random_beacon_min_round_interval_ms: Some(500),
2225
2226 random_beacon_dkg_version: Some(1),
2227
2228 consensus_max_num_transactions_in_block: Some(512),
2232
2233 max_deferral_rounds_for_congestion_control: Some(10),
2234
2235 min_checkpoint_interval_ms: Some(200),
2236
2237 checkpoint_summary_version_specific_data: Some(1),
2238
2239 max_soft_bundle_size: Some(5),
2240
2241 bridge_should_try_to_finalize_committee: None,
2242
2243 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2244
2245 max_committee_members_count: None,
2246
2247 consensus_gc_depth: None,
2248
2249 consensus_max_acknowledgments_per_block: None,
2250
2251 max_congestion_limit_overshoot_per_commit: None,
2252
2253 scorer_version: None,
2254
2255 auth_context_digest_cost_base: None,
2257 auth_context_tx_data_bytes_cost_base: None,
2258 auth_context_tx_data_bytes_cost_per_byte: None,
2259 auth_context_tx_commands_cost_base: None,
2260 auth_context_tx_commands_cost_per_byte: None,
2261 auth_context_tx_inputs_cost_base: None,
2262 auth_context_tx_inputs_cost_per_byte: None,
2263 auth_context_replace_cost_base: None,
2264 auth_context_replace_cost_per_byte: None,
2265 };
2268
2269 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2270
2271 {
2273 cfg.feature_flags
2274 .disable_invariant_violation_check_in_swap_loc = true;
2275 cfg.feature_flags.no_extraneous_module_bytes = true;
2276 cfg.feature_flags.hardened_otw_check = true;
2277 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2278 }
2279
2280 {
2282 #[allow(deprecated)]
2283 {
2284 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2285 }
2286 }
2287
2288 #[expect(deprecated)]
2292 {
2293 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2294 }
2295 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2297
2298 cfg.feature_flags.per_object_congestion_control_mode =
2299 PerObjectCongestionControlMode::TotalTxCount;
2300
2301 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2303
2304 if chain != Chain::Mainnet && chain != Chain::Testnet {
2306 cfg.feature_flags.enable_poseidon = true;
2307 cfg.poseidon_bn254_cost_base = Some(260);
2308 cfg.poseidon_bn254_cost_per_block = Some(10);
2309
2310 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2311
2312 cfg.feature_flags.enable_vdf = true;
2313 cfg.vdf_verify_vdf_cost = Some(1500);
2316 cfg.vdf_hash_to_input_cost = Some(100);
2317
2318 cfg.feature_flags.passkey_auth = true;
2319 }
2320
2321 for cur in 2..=version.0 {
2322 match cur {
2323 1 => unreachable!(),
2324 2 => {}
2326 3 => {
2327 cfg.feature_flags.relocate_event_module = true;
2328 }
2329 4 => {
2330 cfg.max_type_to_layout_nodes = Some(512);
2331 }
2332 5 => {
2333 cfg.feature_flags.protocol_defined_base_fee = true;
2334 cfg.base_gas_price = Some(1000);
2335
2336 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2337 cfg.feature_flags.convert_type_argument_error = true;
2338 cfg.feature_flags.native_charging_v2 = true;
2339
2340 if chain != Chain::Mainnet && chain != Chain::Testnet {
2341 cfg.feature_flags.uncompressed_g1_group_elements = true;
2342 }
2343
2344 cfg.gas_model_version = Some(2);
2345
2346 cfg.poseidon_bn254_cost_per_block = Some(388);
2347
2348 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2349 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2350 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2351 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2352 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2353 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2354 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2355 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2356
2357 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2359 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2360 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2361 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2362
2363 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2364 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2365 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2366 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2367 Some(8213);
2368 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2369 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2370 Some(9484);
2371
2372 cfg.hash_keccak256_cost_base = Some(10);
2373 cfg.hash_blake2b256_cost_base = Some(10);
2374
2375 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2377 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2378 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2379 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2380
2381 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2382 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2383 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2384 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2385
2386 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2387 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2388 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2389 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2390
2391 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2392 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2393 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2394 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2395
2396 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2397 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2398 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2399 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2400
2401 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2402 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2403
2404 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2405 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2406 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2407 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2408
2409 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2410 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2411 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2412 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2413 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2414
2415 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2416
2417 cfg.validator_validate_metadata_cost_base = Some(20000);
2418
2419 cfg.max_committee_members_count = Some(50);
2420 }
2421 6 => {
2422 cfg.max_ptb_value_size = Some(1024 * 1024);
2423 }
2424 7 => {
2425 }
2428 8 => {
2429 cfg.feature_flags.variant_nodes = true;
2430
2431 if chain != Chain::Mainnet {
2432 cfg.feature_flags.consensus_round_prober = true;
2434 cfg.feature_flags
2436 .consensus_distributed_vote_scoring_strategy = true;
2437 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2438 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2440 cfg.feature_flags
2442 .consensus_round_prober_probe_accepted_rounds = true;
2443 cfg.feature_flags.consensus_zstd_compression = true;
2445 cfg.consensus_gc_depth = Some(60);
2449 }
2450
2451 if chain != Chain::Testnet && chain != Chain::Mainnet {
2454 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2455 }
2456 }
2457 9 => {
2458 if chain != Chain::Mainnet {
2459 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2461 }
2462
2463 cfg.feature_flags.consensus_zstd_compression = true;
2465
2466 if chain != Chain::Testnet && chain != Chain::Mainnet {
2468 cfg.feature_flags.accept_passkey_in_multisig = true;
2469 }
2470
2471 cfg.bridge_should_try_to_finalize_committee = None;
2473 }
2474 10 => {
2475 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2478
2479 cfg.max_committee_members_count = Some(80);
2481
2482 cfg.feature_flags.consensus_round_prober = true;
2484 cfg.feature_flags
2486 .consensus_round_prober_probe_accepted_rounds = true;
2487 cfg.feature_flags
2489 .consensus_distributed_vote_scoring_strategy = true;
2490 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2492
2493 cfg.consensus_gc_depth = Some(60);
2498
2499 cfg.feature_flags.minimize_child_object_mutations = true;
2501
2502 if chain != Chain::Mainnet {
2503 cfg.feature_flags.consensus_batched_block_sync = true;
2505 }
2506
2507 if chain != Chain::Testnet && chain != Chain::Mainnet {
2508 cfg.feature_flags
2511 .congestion_control_gas_price_feedback_mechanism = true;
2512 }
2513
2514 cfg.feature_flags.validate_identifier_inputs = true;
2515 cfg.feature_flags.dependency_linkage_error = true;
2516 cfg.feature_flags.additional_multisig_checks = true;
2517 }
2518 11 => {
2519 }
2522 12 => {
2523 cfg.feature_flags
2526 .congestion_control_gas_price_feedback_mechanism = true;
2527
2528 cfg.feature_flags.normalize_ptb_arguments = true;
2530 }
2531 13 => {
2532 cfg.feature_flags.select_committee_from_eligible_validators = true;
2535 cfg.feature_flags.track_non_committee_eligible_validators = true;
2538
2539 if chain != Chain::Testnet && chain != Chain::Mainnet {
2540 cfg.feature_flags
2543 .select_committee_supporting_next_epoch_version = true;
2544 }
2545 }
2546 14 => {
2547 cfg.feature_flags.consensus_batched_block_sync = true;
2549
2550 if chain != Chain::Mainnet {
2551 cfg.feature_flags
2554 .consensus_median_timestamp_with_checkpoint_enforcement = true;
2555 cfg.feature_flags
2559 .select_committee_supporting_next_epoch_version = true;
2560 }
2561 if chain != Chain::Testnet && chain != Chain::Mainnet {
2562 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2564 }
2565 }
2566 15 => {
2567 if chain != Chain::Mainnet && chain != Chain::Testnet {
2568 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2572 }
2573 }
2574 16 => {
2575 cfg.feature_flags
2578 .select_committee_supporting_next_epoch_version = true;
2579 cfg.feature_flags
2581 .consensus_commit_transactions_only_for_traversed_headers = true;
2582 }
2583 17 => {
2584 cfg.max_committee_members_count = Some(100);
2586 }
2587 18 => {
2588 if chain != Chain::Mainnet {
2589 cfg.feature_flags.passkey_auth = true;
2591 }
2592 }
2593 19 => {
2594 if chain != Chain::Testnet && chain != Chain::Mainnet {
2595 cfg.feature_flags
2598 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2599 cfg.feature_flags
2602 .separate_gas_price_feedback_mechanism_for_randomness = true;
2603 cfg.feature_flags.metadata_in_module_bytes = true;
2606 cfg.feature_flags.publish_package_metadata = true;
2607 cfg.feature_flags.enable_move_authentication = true;
2609 cfg.max_auth_gas = Some(250_000_000);
2611 cfg.transfer_receive_object_cost_base = Some(100);
2614 cfg.feature_flags.adjust_rewards_by_score = true;
2616 }
2617
2618 if chain != Chain::Mainnet {
2619 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2621
2622 cfg.feature_flags.calculate_validator_scores = true;
2624 cfg.scorer_version = Some(1);
2625 }
2626
2627 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
2629
2630 cfg.feature_flags.passkey_auth = true;
2632 }
2633 20 => {
2634 if chain != Chain::Testnet && chain != Chain::Mainnet {
2635 cfg.feature_flags
2637 .pass_calculated_validator_scores_to_advance_epoch = true;
2638 }
2639 }
2640 21 => {
2641 if chain != Chain::Testnet && chain != Chain::Mainnet {
2642 cfg.feature_flags.consensus_fast_commit_sync = true;
2644 }
2645 if chain != Chain::Mainnet {
2646 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2651 cfg.feature_flags
2654 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2655 cfg.feature_flags
2658 .separate_gas_price_feedback_mechanism_for_randomness = true;
2659 }
2660
2661 cfg.auth_context_digest_cost_base = Some(30);
2662 cfg.auth_context_tx_commands_cost_base = Some(30);
2663 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
2664 cfg.auth_context_tx_inputs_cost_base = Some(30);
2665 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
2666 cfg.auth_context_replace_cost_base = Some(30);
2667 cfg.auth_context_replace_cost_per_byte = Some(2);
2668
2669 if chain != Chain::Testnet && chain != Chain::Mainnet {
2670 cfg.max_auth_gas = Some(250_000);
2672 }
2673 }
2674 22 => {
2675 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
2680 cfg.feature_flags
2683 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
2684 cfg.feature_flags
2687 .separate_gas_price_feedback_mechanism_for_randomness = true;
2688
2689 if chain != Chain::Mainnet {
2690 cfg.feature_flags.metadata_in_module_bytes = true;
2693 cfg.feature_flags.publish_package_metadata = true;
2694 cfg.feature_flags.enable_move_authentication = true;
2696 cfg.max_auth_gas = Some(250_000);
2698 cfg.transfer_receive_object_cost_base = Some(100);
2701 }
2702
2703 if chain != Chain::Mainnet {
2704 cfg.feature_flags.consensus_fast_commit_sync = true;
2706 }
2707 }
2708 23 => {
2709 cfg.feature_flags.move_native_tx_context = true;
2711 cfg.tx_context_fresh_id_cost_base = Some(52);
2712 cfg.tx_context_sender_cost_base = Some(30);
2713 cfg.tx_context_digest_cost_base = Some(30);
2714 cfg.tx_context_epoch_cost_base = Some(30);
2715 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
2716 cfg.tx_context_sponsor_cost_base = Some(30);
2717 cfg.tx_context_rgp_cost_base = Some(30);
2718 cfg.tx_context_gas_price_cost_base = Some(30);
2719 cfg.tx_context_gas_budget_cost_base = Some(30);
2720 cfg.tx_context_ids_created_cost_base = Some(30);
2721 cfg.tx_context_replace_cost_base = Some(30);
2722 }
2723 24 => {
2724 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
2726
2727 if chain != Chain::Testnet && chain != Chain::Mainnet {
2728 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
2730 }
2731
2732 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
2735 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
2736
2737 cfg.feature_flags.additional_borrow_checks = true;
2739 }
2740 #[allow(deprecated)]
2741 25 => {
2742 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
2745 cfg.check_zklogin_id_cost_base = None;
2746 cfg.check_zklogin_issuer_cost_base = None;
2747 cfg.max_jwk_votes_per_validator_per_epoch = None;
2748 cfg.max_age_of_jwk_in_epochs = None;
2749 }
2750 26 => {
2751 }
2754
2755 _ => panic!("unsupported version {version:?}"),
2766 }
2767 }
2768 cfg
2769 }
2770
2771 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
2777 let (
2778 max_back_edges_per_function,
2779 max_back_edges_per_module,
2780 sanity_check_with_regex_reference_safety,
2781 ) = if let Some((
2782 max_back_edges_per_function,
2783 max_back_edges_per_module,
2784 sanity_check_with_regex_reference_safety,
2785 )) = signing_limits
2786 {
2787 (
2788 Some(max_back_edges_per_function),
2789 Some(max_back_edges_per_module),
2790 Some(sanity_check_with_regex_reference_safety),
2791 )
2792 } else {
2793 (None, None, None)
2794 };
2795
2796 let additional_borrow_checks = if signing_limits.is_some() {
2797 true
2800 } else {
2801 self.additional_borrow_checks()
2802 };
2803
2804 VerifierConfig {
2805 max_loop_depth: Some(self.max_loop_depth() as usize),
2806 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
2807 max_function_parameters: Some(self.max_function_parameters() as usize),
2808 max_basic_blocks: Some(self.max_basic_blocks() as usize),
2809 max_value_stack_size: self.max_value_stack_size() as usize,
2810 max_type_nodes: Some(self.max_type_nodes() as usize),
2811 max_push_size: Some(self.max_push_size() as usize),
2812 max_dependency_depth: Some(self.max_dependency_depth() as usize),
2813 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
2814 max_function_definitions: Some(self.max_function_definitions() as usize),
2815 max_data_definitions: Some(self.max_struct_definitions() as usize),
2816 max_constant_vector_len: Some(self.max_move_vector_len()),
2817 max_back_edges_per_function,
2818 max_back_edges_per_module,
2819 max_basic_blocks_in_script: None,
2820 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
2824 max_variants_in_enum: self.max_move_enum_variants_as_option(),
2825 additional_borrow_checks,
2826 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
2827 .map(|limit| limit as u128),
2828 }
2829 }
2830
2831 pub fn apply_overrides_for_testing(
2836 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
2837 ) -> OverrideGuard {
2838 CONFIG_OVERRIDE.with(|ovr| {
2839 let mut cur = ovr.borrow_mut();
2840 assert!(cur.is_none(), "config override already present");
2841 *cur = Some(Box::new(override_fn));
2842 OverrideGuard
2843 })
2844 }
2845}
2846
2847impl ProtocolConfig {
2852 pub fn set_per_object_congestion_control_mode_for_testing(
2853 &mut self,
2854 val: PerObjectCongestionControlMode,
2855 ) {
2856 self.feature_flags.per_object_congestion_control_mode = val;
2857 }
2858
2859 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
2860 self.feature_flags.consensus_choice = val;
2861 }
2862
2863 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
2864 self.feature_flags.consensus_network = val;
2865 }
2866
2867 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
2868 self.feature_flags.passkey_auth = val
2869 }
2870
2871 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
2872 self.feature_flags
2873 .disallow_new_modules_in_deps_only_packages = val;
2874 }
2875
2876 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
2877 self.feature_flags.consensus_round_prober = val;
2878 }
2879
2880 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
2881 self.feature_flags
2882 .consensus_distributed_vote_scoring_strategy = val;
2883 }
2884
2885 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
2886 self.consensus_gc_depth = Some(val);
2887 }
2888
2889 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
2890 self.feature_flags.consensus_linearize_subdag_v2 = val;
2891 }
2892
2893 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
2894 self.feature_flags
2895 .consensus_round_prober_probe_accepted_rounds = val;
2896 }
2897
2898 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
2899 self.feature_flags.accept_passkey_in_multisig = val;
2900 }
2901
2902 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
2903 self.feature_flags.consensus_smart_ancestor_selection = val;
2904 }
2905
2906 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
2907 self.feature_flags.consensus_batched_block_sync = val;
2908 }
2909
2910 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
2911 self.feature_flags
2912 .congestion_control_min_free_execution_slot = val;
2913 }
2914
2915 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
2916 self.feature_flags
2917 .congestion_control_gas_price_feedback_mechanism = val;
2918 }
2919
2920 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
2921 self.feature_flags.select_committee_from_eligible_validators = val;
2922 }
2923
2924 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
2925 self.feature_flags.track_non_committee_eligible_validators = val;
2926 }
2927
2928 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
2929 self.feature_flags
2930 .select_committee_supporting_next_epoch_version = val;
2931 }
2932
2933 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
2934 &mut self,
2935 val: bool,
2936 ) {
2937 self.feature_flags
2938 .consensus_median_timestamp_with_checkpoint_enforcement = val;
2939 }
2940
2941 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
2942 &mut self,
2943 val: bool,
2944 ) {
2945 self.feature_flags
2946 .consensus_commit_transactions_only_for_traversed_headers = val;
2947 }
2948
2949 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
2950 &mut self,
2951 val: bool,
2952 ) {
2953 self.feature_flags
2954 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
2955 }
2956
2957 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
2958 &mut self,
2959 val: bool,
2960 ) {
2961 self.feature_flags
2962 .separate_gas_price_feedback_mechanism_for_randomness = val;
2963 }
2964
2965 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
2966 self.feature_flags.metadata_in_module_bytes = val;
2967 }
2968
2969 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
2970 self.feature_flags.publish_package_metadata = val;
2971 }
2972
2973 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
2974 self.feature_flags.enable_move_authentication = val;
2975 }
2976
2977 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
2978 self.feature_flags.enable_move_authentication_for_sponsor = val;
2979 }
2980
2981 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
2982 self.feature_flags.consensus_fast_commit_sync = val;
2983 }
2984}
2985
2986type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
2987
2988thread_local! {
2989 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
2990}
2991
2992#[must_use]
2993pub struct OverrideGuard;
2994
2995impl Drop for OverrideGuard {
2996 fn drop(&mut self) {
2997 info!("restoring override fn");
2998 CONFIG_OVERRIDE.with(|ovr| {
2999 *ovr.borrow_mut() = None;
3000 });
3001 }
3002}
3003
3004#[derive(PartialEq, Eq)]
3008pub enum LimitThresholdCrossed {
3009 None,
3010 Soft(u128, u128),
3011 Hard(u128, u128),
3012}
3013
3014pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
3017 x: T,
3018 soft_limit: U,
3019 hard_limit: V,
3020) -> LimitThresholdCrossed {
3021 let x: V = x.into();
3022 let soft_limit: V = soft_limit.into();
3023
3024 debug_assert!(soft_limit <= hard_limit);
3025
3026 if x >= hard_limit {
3029 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
3030 } else if x < soft_limit {
3031 LimitThresholdCrossed::None
3032 } else {
3033 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
3034 }
3035}
3036
3037#[macro_export]
3038macro_rules! check_limit {
3039 ($x:expr, $hard:expr) => {
3040 check_limit!($x, $hard, $hard)
3041 };
3042 ($x:expr, $soft:expr, $hard:expr) => {
3043 check_limit_in_range($x as u64, $soft, $hard)
3044 };
3045}
3046
3047#[macro_export]
3051macro_rules! check_limit_by_meter {
3052 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
3053 let (h, metered_str) = if $is_metered {
3055 ($metered_limit, "metered")
3056 } else {
3057 ($unmetered_hard_limit, "unmetered")
3059 };
3060 use iota_protocol_config::check_limit_in_range;
3061 let result = check_limit_in_range($x as u64, $metered_limit, h);
3062 match result {
3063 LimitThresholdCrossed::None => {}
3064 LimitThresholdCrossed::Soft(_, _) => {
3065 $metric.with_label_values(&[metered_str, "soft"]).inc();
3066 }
3067 LimitThresholdCrossed::Hard(_, _) => {
3068 $metric.with_label_values(&[metered_str, "hard"]).inc();
3069 }
3070 };
3071 result
3072 }};
3073}
3074
3075#[cfg(all(test, not(msim)))]
3076mod test {
3077 use insta::assert_yaml_snapshot;
3078
3079 use super::*;
3080
3081 #[test]
3082 fn snapshot_tests() {
3083 println!("\n============================================================================");
3084 println!("! !");
3085 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
3086 println!("! !");
3087 println!("============================================================================\n");
3088 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
3089 let chain_str = match chain_id {
3094 Chain::Unknown => "".to_string(),
3095 _ => format!("{chain_id:?}_"),
3096 };
3097 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
3098 let cur = ProtocolVersion::new(i);
3099 assert_yaml_snapshot!(
3100 format!("{}version_{}", chain_str, cur.as_u64()),
3101 ProtocolConfig::get_for_version(cur, *chain_id)
3102 );
3103 }
3104 }
3105 }
3106
3107 #[test]
3108 fn test_getters() {
3109 let prot: ProtocolConfig =
3110 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3111 assert_eq!(
3112 prot.max_arguments(),
3113 prot.max_arguments_as_option().unwrap()
3114 );
3115 }
3116
3117 #[test]
3118 fn test_setters() {
3119 let mut prot: ProtocolConfig =
3120 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3121 prot.set_max_arguments_for_testing(123);
3122 assert_eq!(prot.max_arguments(), 123);
3123
3124 prot.set_max_arguments_from_str_for_testing("321".to_string());
3125 assert_eq!(prot.max_arguments(), 321);
3126
3127 prot.disable_max_arguments_for_testing();
3128 assert_eq!(prot.max_arguments_as_option(), None);
3129
3130 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
3131 assert_eq!(prot.max_arguments(), 456);
3132 }
3133
3134 #[test]
3135 #[should_panic(expected = "unsupported version")]
3136 fn max_version_test() {
3137 let _ = ProtocolConfig::get_for_version_impl(
3140 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
3141 Chain::Unknown,
3142 );
3143 }
3144
3145 #[test]
3146 fn lookup_by_string_test() {
3147 let prot: ProtocolConfig =
3148 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3149 assert!(prot.lookup_attr("some random string".to_string()).is_none());
3151
3152 assert!(
3153 prot.lookup_attr("max_arguments".to_string())
3154 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
3155 );
3156
3157 assert!(
3159 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3160 .is_none()
3161 );
3162 assert!(
3163 prot.attr_map()
3164 .get("poseidon_bn254_cost_base")
3165 .unwrap()
3166 .is_none()
3167 );
3168
3169 let prot: ProtocolConfig =
3171 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3172
3173 assert!(
3174 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3175 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3176 );
3177 assert!(
3178 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
3179 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3180 );
3181
3182 let prot: ProtocolConfig =
3184 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3185 assert!(
3187 prot.feature_flags
3188 .lookup_attr("some random string".to_owned())
3189 .is_none()
3190 );
3191 assert!(
3192 !prot
3193 .feature_flags
3194 .attr_map()
3195 .contains_key("some random string")
3196 );
3197
3198 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
3200 assert!(
3201 prot.feature_flags
3202 .attr_map()
3203 .get("enable_poseidon")
3204 .unwrap()
3205 == &false
3206 );
3207 let prot: ProtocolConfig =
3208 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3209 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
3211 assert!(
3212 prot.feature_flags
3213 .attr_map()
3214 .get("enable_poseidon")
3215 .unwrap()
3216 == &true
3217 );
3218 }
3219
3220 #[test]
3221 fn limit_range_fn_test() {
3222 let low = 100u32;
3223 let high = 10000u64;
3224
3225 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
3226 assert!(matches!(
3227 check_limit!(255u16, low, high),
3228 LimitThresholdCrossed::Soft(255u128, 100)
3229 ));
3230 assert!(matches!(
3237 check_limit!(2550000u64, low, high),
3238 LimitThresholdCrossed::Hard(2550000, 10000)
3239 ));
3240
3241 assert!(matches!(
3242 check_limit!(2550000u64, high, high),
3243 LimitThresholdCrossed::Hard(2550000, 10000)
3244 ));
3245
3246 assert!(matches!(
3247 check_limit!(1u8, high),
3248 LimitThresholdCrossed::None
3249 ));
3250
3251 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
3252
3253 assert!(matches!(
3254 check_limit!(2550000u64, high),
3255 LimitThresholdCrossed::Hard(2550000, 10000)
3256 ));
3257 }
3258}