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 = 34;
23
24pub const PROTOCOL_VERSION_IIP8: u64 = 20;
26#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
216pub struct ProtocolVersion(u64);
217
218impl ProtocolVersion {
219 pub const MIN: Self = Self(MIN_PROTOCOL_VERSION);
225
226 pub const MAX: Self = Self(MAX_PROTOCOL_VERSION);
227
228 #[cfg(not(msim))]
229 const MAX_ALLOWED: Self = Self::MAX;
230
231 #[cfg(msim)]
234 pub const MAX_ALLOWED: Self = Self(MAX_PROTOCOL_VERSION + 1);
235
236 pub fn new(v: u64) -> Self {
237 Self(v)
238 }
239
240 pub const fn as_u64(&self) -> u64 {
241 self.0
242 }
243
244 pub fn max() -> Self {
247 Self::MAX
248 }
249}
250
251impl From<u64> for ProtocolVersion {
252 fn from(v: u64) -> Self {
253 Self::new(v)
254 }
255}
256
257impl std::ops::Sub<u64> for ProtocolVersion {
258 type Output = Self;
259 fn sub(self, rhs: u64) -> Self::Output {
260 Self::new(self.0 - rhs)
261 }
262}
263
264impl std::ops::Add<u64> for ProtocolVersion {
265 type Output = Self;
266 fn add(self, rhs: u64) -> Self::Output {
267 Self::new(self.0 + rhs)
268 }
269}
270
271#[derive(
272 Clone, Serialize, Deserialize, Debug, PartialEq, Copy, PartialOrd, Ord, Eq, ValueEnum, Default,
273)]
274pub enum Chain {
275 Mainnet,
276 Testnet,
277 #[default]
278 Unknown,
279}
280
281impl Chain {
282 pub fn as_str(self) -> &'static str {
283 match self {
284 Chain::Mainnet => "mainnet",
285 Chain::Testnet => "testnet",
286 Chain::Unknown => "unknown",
287 }
288 }
289}
290
291pub struct Error(pub String);
292
293#[derive(
297 Default,
298 Clone,
299 Serialize,
300 Deserialize,
301 Debug,
302 ProtocolConfigFeatureFlagsGetters,
303 ProtocolConfigOverride,
304)]
305struct FeatureFlags {
306 #[serde(skip_serializing_if = "is_true")]
312 disable_invariant_violation_check_in_swap_loc: bool,
313
314 #[serde(skip_serializing_if = "is_true")]
317 no_extraneous_module_bytes: bool,
318
319 #[serde(skip_serializing_if = "ConsensusTransactionOrdering::is_none")]
321 consensus_transaction_ordering: ConsensusTransactionOrdering,
322
323 #[serde(skip_serializing_if = "is_true")]
326 hardened_otw_check: bool,
327
328 #[serde(skip_serializing_if = "is_false")]
330 enable_poseidon: bool,
331
332 #[serde(skip_serializing_if = "is_false")]
334 enable_group_ops_native_function_msm: bool,
335
336 #[serde(skip_serializing_if = "PerObjectCongestionControlMode::is_none")]
338 per_object_congestion_control_mode: PerObjectCongestionControlMode,
339
340 #[serde(
342 default = "ConsensusChoice::mysticeti_deprecated",
343 skip_serializing_if = "ConsensusChoice::is_mysticeti_deprecated"
344 )]
345 consensus_choice: ConsensusChoice,
346
347 #[serde(skip_serializing_if = "ConsensusNetwork::is_tonic")]
349 consensus_network: ConsensusNetwork,
350
351 #[deprecated]
353 #[serde(skip_serializing_if = "Option::is_none")]
354 zklogin_max_epoch_upper_bound_delta: Option<u64>,
355
356 #[serde(skip_serializing_if = "is_false")]
358 enable_vdf: bool,
359
360 #[serde(skip_serializing_if = "is_false")]
362 passkey_auth: bool,
363
364 #[serde(skip_serializing_if = "is_true")]
367 rethrow_serialization_type_layout_errors: bool,
368
369 #[serde(skip_serializing_if = "is_false")]
371 relocate_event_module: bool,
372
373 #[serde(skip_serializing_if = "is_false")]
375 protocol_defined_base_fee: bool,
376
377 #[serde(skip_serializing_if = "is_false")]
379 uncompressed_g1_group_elements: bool,
380
381 #[serde(skip_serializing_if = "is_false")]
383 disallow_new_modules_in_deps_only_packages: bool,
384
385 #[serde(skip_serializing_if = "is_false")]
387 native_charging_v2: bool,
388
389 #[serde(skip_serializing_if = "is_false")]
391 convert_type_argument_error: bool,
392
393 #[serde(skip_serializing_if = "is_false")]
395 consensus_round_prober: bool,
396
397 #[serde(skip_serializing_if = "is_false")]
399 consensus_distributed_vote_scoring_strategy: bool,
400
401 #[serde(skip_serializing_if = "is_false")]
405 consensus_linearize_subdag_v2: bool,
406
407 #[serde(skip_serializing_if = "is_false")]
409 variant_nodes: bool,
410
411 #[serde(skip_serializing_if = "is_false")]
413 consensus_smart_ancestor_selection: bool,
414
415 #[serde(skip_serializing_if = "is_false")]
417 consensus_round_prober_probe_accepted_rounds: bool,
418
419 #[serde(skip_serializing_if = "is_false")]
421 consensus_zstd_compression: bool,
422
423 #[serde(skip_serializing_if = "is_false")]
426 congestion_control_min_free_execution_slot: bool,
427
428 #[serde(skip_serializing_if = "is_false")]
430 accept_passkey_in_multisig: bool,
431
432 #[serde(skip_serializing_if = "is_false")]
434 consensus_batched_block_sync: bool,
435
436 #[serde(skip_serializing_if = "is_false")]
439 congestion_control_gas_price_feedback_mechanism: bool,
440
441 #[serde(skip_serializing_if = "is_false")]
443 validate_identifier_inputs: bool,
444
445 #[serde(skip_serializing_if = "is_false")]
448 minimize_child_object_mutations: bool,
449
450 #[serde(skip_serializing_if = "is_false")]
452 dependency_linkage_error: bool,
453
454 #[serde(skip_serializing_if = "is_false")]
456 additional_multisig_checks: bool,
457
458 #[serde(skip_serializing_if = "is_false")]
461 normalize_ptb_arguments: bool,
462
463 #[serde(skip_serializing_if = "is_false")]
467 select_committee_from_eligible_validators: bool,
468
469 #[serde(skip_serializing_if = "is_false")]
476 track_non_committee_eligible_validators: bool,
477
478 #[serde(skip_serializing_if = "is_false")]
484 select_committee_supporting_next_epoch_version: bool,
485
486 #[serde(skip_serializing_if = "is_false")]
490 consensus_median_timestamp_with_checkpoint_enforcement: bool,
491
492 #[serde(skip_serializing_if = "is_false")]
494 consensus_commit_transactions_only_for_traversed_headers: bool,
495
496 #[serde(skip_serializing_if = "is_false")]
498 congestion_limit_overshoot_in_gas_price_feedback_mechanism: bool,
499
500 #[serde(skip_serializing_if = "is_false")]
503 separate_gas_price_feedback_mechanism_for_randomness: bool,
504
505 #[serde(skip_serializing_if = "is_false")]
508 metadata_in_module_bytes: bool,
509
510 #[serde(skip_serializing_if = "is_false")]
512 publish_package_metadata: bool,
513
514 #[serde(skip_serializing_if = "is_false")]
516 enable_move_authentication: bool,
517
518 #[serde(skip_serializing_if = "is_false")]
520 enable_move_authentication_for_sponsor: bool,
521
522 #[serde(skip_serializing_if = "is_false")]
524 pass_validator_scores_to_advance_epoch: bool,
525
526 #[serde(skip_serializing_if = "is_false")]
528 calculate_validator_scores: bool,
529
530 #[serde(skip_serializing_if = "is_false")]
532 adjust_rewards_by_score: bool,
533
534 #[serde(skip_serializing_if = "is_false")]
537 pass_calculated_validator_scores_to_advance_epoch: bool,
538
539 #[serde(skip_serializing_if = "is_false")]
544 consensus_fast_commit_sync: bool,
545
546 #[serde(skip_serializing_if = "is_false")]
549 consensus_block_restrictions: bool,
550
551 #[serde(skip_serializing_if = "is_false")]
553 move_native_tx_context: bool,
554
555 #[serde(skip_serializing_if = "is_false")]
557 additional_borrow_checks: bool,
558
559 #[serde(skip_serializing_if = "is_false")]
561 pre_consensus_sponsor_only_move_authentication: bool,
562
563 #[serde(skip_serializing_if = "is_false")]
565 consensus_starfish_speed: bool,
566
567 #[serde(skip_serializing_if = "is_false")]
574 always_advance_dkg_to_resolution: bool,
575
576 #[serde(skip_serializing_if = "is_false")]
581 enable_pcool_flow: bool,
582
583 #[serde(skip_serializing_if = "is_false")]
588 pcool_skip_immutable_object_locks: bool,
589
590 #[serde(skip_serializing_if = "is_false")]
592 validator_metadata_verify_v2: bool,
593
594 #[serde(skip_serializing_if = "is_false")]
598 deny_rule_governance: bool,
599
600 #[serde(skip_serializing_if = "is_false")]
605 deny_rule_governance_on_chain: bool,
606
607 #[serde(skip_serializing_if = "is_false")]
610 package_metadata_with_dynamic_module_metadata: bool,
611
612 #[serde(skip_serializing_if = "is_false")]
615 report_move_authentication_error: bool,
616
617 #[serde(skip_serializing_if = "is_false")]
622 consensus_enable_sliding_window_leader_schedule: bool,
623
624 #[serde(skip_serializing_if = "is_false")]
629 consensus_enable_absolute_score_leader_schedule: bool,
630}
631
632fn is_true(b: &bool) -> bool {
633 *b
634}
635
636fn is_false(b: &bool) -> bool {
637 !b
638}
639
640#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
642pub enum ConsensusTransactionOrdering {
643 #[default]
646 None,
647 ByGasPrice,
649}
650
651impl ConsensusTransactionOrdering {
652 pub fn is_none(&self) -> bool {
653 matches!(self, ConsensusTransactionOrdering::None)
654 }
655}
656
657#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
659pub enum PerObjectCongestionControlMode {
660 #[default]
661 None, TotalGasBudget, TotalTxCount, }
665
666impl PerObjectCongestionControlMode {
667 pub fn is_none(&self) -> bool {
668 matches!(self, PerObjectCongestionControlMode::None)
669 }
670}
671
672#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
674pub enum ConsensusChoice {
675 #[deprecated(note = "Mysticeti was replaced by Starfish")]
678 MysticetiDeprecated,
679 #[default]
680 Starfish,
681}
682
683#[expect(deprecated)]
684impl ConsensusChoice {
685 fn mysticeti_deprecated() -> Self {
692 ConsensusChoice::MysticetiDeprecated
693 }
694
695 pub fn is_mysticeti_deprecated(&self) -> bool {
696 matches!(self, ConsensusChoice::MysticetiDeprecated)
697 }
698 pub fn is_starfish(&self) -> bool {
699 matches!(self, ConsensusChoice::Starfish)
700 }
701}
702
703#[derive(Default, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
705pub enum ConsensusNetwork {
706 #[default]
707 Tonic,
708}
709
710impl ConsensusNetwork {
711 pub fn is_tonic(&self) -> bool {
712 matches!(self, ConsensusNetwork::Tonic)
713 }
714}
715
716#[skip_serializing_none]
750#[derive(Clone, Serialize, Debug, ProtocolConfigAccessors, ProtocolConfigOverride)]
751pub struct ProtocolConfig {
752 pub version: ProtocolVersion,
753
754 feature_flags: FeatureFlags,
755
756 max_tx_size_bytes: Option<u64>,
761
762 max_input_objects: Option<u64>,
765
766 max_size_written_objects: Option<u64>,
771 max_size_written_objects_system_tx: Option<u64>,
775
776 max_serialized_tx_effects_size_bytes: Option<u64>,
778
779 max_serialized_tx_effects_size_bytes_system_tx: Option<u64>,
781
782 max_gas_payment_objects: Option<u32>,
784
785 max_modules_in_publish: Option<u32>,
787
788 max_package_dependencies: Option<u32>,
790
791 max_arguments: Option<u32>,
794
795 max_type_arguments: Option<u32>,
797
798 max_type_argument_depth: Option<u32>,
800
801 max_pure_argument_size: Option<u32>,
803
804 max_programmable_tx_commands: Option<u32>,
806
807 move_binary_format_version: Option<u32>,
813 min_move_binary_format_version: Option<u32>,
814
815 binary_module_handles: Option<u16>,
817 binary_struct_handles: Option<u16>,
818 binary_function_handles: Option<u16>,
819 binary_function_instantiations: Option<u16>,
820 binary_signatures: Option<u16>,
821 binary_constant_pool: Option<u16>,
822 binary_identifiers: Option<u16>,
823 binary_address_identifiers: Option<u16>,
824 binary_struct_defs: Option<u16>,
825 binary_struct_def_instantiations: Option<u16>,
826 binary_function_defs: Option<u16>,
827 binary_field_handles: Option<u16>,
828 binary_field_instantiations: Option<u16>,
829 binary_friend_decls: Option<u16>,
830 binary_enum_defs: Option<u16>,
831 binary_enum_def_instantiations: Option<u16>,
832 binary_variant_handles: Option<u16>,
833 binary_variant_instantiation_handles: Option<u16>,
834
835 max_move_object_size: Option<u64>,
838
839 max_move_package_size: Option<u64>,
844
845 max_publish_or_upgrade_per_ptb: Option<u64>,
848
849 max_tx_gas: Option<u64>,
851
852 max_auth_gas: Option<u64>,
854
855 max_gas_price: Option<u64>,
858
859 max_gas_computation_bucket: Option<u64>,
862
863 gas_rounding_step: Option<u64>,
865
866 max_loop_depth: Option<u64>,
868
869 max_generic_instantiation_length: Option<u64>,
872
873 max_function_parameters: Option<u64>,
876
877 max_basic_blocks: Option<u64>,
880
881 max_value_stack_size: Option<u64>,
883
884 max_type_nodes: Option<u64>,
888
889 max_push_size: Option<u64>,
892
893 max_struct_definitions: Option<u64>,
896
897 max_function_definitions: Option<u64>,
900
901 max_fields_in_struct: Option<u64>,
904
905 max_dependency_depth: Option<u64>,
908
909 max_num_event_emit: Option<u64>,
912
913 max_num_new_move_object_ids: Option<u64>,
916
917 max_num_new_move_object_ids_system_tx: Option<u64>,
920
921 max_num_deleted_move_object_ids: Option<u64>,
924
925 max_num_deleted_move_object_ids_system_tx: Option<u64>,
928
929 max_num_transferred_move_object_ids: Option<u64>,
932
933 max_num_transferred_move_object_ids_system_tx: Option<u64>,
936
937 max_event_emit_size: Option<u64>,
939
940 max_event_emit_size_total: Option<u64>,
942
943 max_move_vector_len: Option<u64>,
946
947 max_move_identifier_len: Option<u64>,
950
951 max_move_value_depth: Option<u64>,
953
954 max_move_enum_variants: Option<u64>,
957
958 max_back_edges_per_function: Option<u64>,
961
962 max_back_edges_per_module: Option<u64>,
965
966 max_verifier_meter_ticks_per_function: Option<u64>,
969
970 max_meter_ticks_per_module: Option<u64>,
973
974 max_meter_ticks_per_package: Option<u64>,
977
978 object_runtime_max_num_cached_objects: Option<u64>,
985
986 object_runtime_max_num_cached_objects_system_tx: Option<u64>,
989
990 object_runtime_max_num_store_entries: Option<u64>,
993
994 object_runtime_max_num_store_entries_system_tx: Option<u64>,
997
998 base_tx_cost_fixed: Option<u64>,
1003
1004 package_publish_cost_fixed: Option<u64>,
1008
1009 base_tx_cost_per_byte: Option<u64>,
1013
1014 package_publish_cost_per_byte: Option<u64>,
1016
1017 obj_access_cost_read_per_byte: Option<u64>,
1019
1020 obj_access_cost_mutate_per_byte: Option<u64>,
1022
1023 obj_access_cost_delete_per_byte: Option<u64>,
1025
1026 obj_access_cost_verify_per_byte: Option<u64>,
1036
1037 max_type_to_layout_nodes: Option<u64>,
1039
1040 max_ptb_value_size: Option<u64>,
1042
1043 gas_model_version: Option<u64>,
1048
1049 obj_data_cost_refundable: Option<u64>,
1055
1056 obj_metadata_cost_non_refundable: Option<u64>,
1060
1061 storage_rebate_rate: Option<u64>,
1067
1068 reward_slashing_rate: Option<u64>,
1071
1072 storage_gas_price: Option<u64>,
1074
1075 base_gas_price: Option<u64>,
1077
1078 validator_target_reward: Option<u64>,
1080
1081 max_transactions_per_checkpoint: Option<u64>,
1088
1089 max_checkpoint_size_bytes: Option<u64>,
1093
1094 buffer_stake_for_protocol_upgrade_bps: Option<u64>,
1100
1101 address_from_bytes_cost_base: Option<u64>,
1106 address_to_u256_cost_base: Option<u64>,
1108 address_from_u256_cost_base: Option<u64>,
1110
1111 config_read_setting_impl_cost_base: Option<u64>,
1116 config_read_setting_impl_cost_per_byte: Option<u64>,
1117
1118 dynamic_field_hash_type_and_key_cost_base: Option<u64>,
1122 dynamic_field_hash_type_and_key_type_cost_per_byte: Option<u64>,
1123 dynamic_field_hash_type_and_key_value_cost_per_byte: Option<u64>,
1124 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Option<u64>,
1125 dynamic_field_add_child_object_cost_base: Option<u64>,
1128 dynamic_field_add_child_object_type_cost_per_byte: Option<u64>,
1129 dynamic_field_add_child_object_value_cost_per_byte: Option<u64>,
1130 dynamic_field_add_child_object_struct_tag_cost_per_byte: Option<u64>,
1131 dynamic_field_borrow_child_object_cost_base: Option<u64>,
1134 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Option<u64>,
1135 dynamic_field_borrow_child_object_type_cost_per_byte: Option<u64>,
1136 dynamic_field_remove_child_object_cost_base: Option<u64>,
1139 dynamic_field_remove_child_object_child_cost_per_byte: Option<u64>,
1140 dynamic_field_remove_child_object_type_cost_per_byte: Option<u64>,
1141 dynamic_field_has_child_object_cost_base: Option<u64>,
1144 dynamic_field_has_child_object_with_ty_cost_base: Option<u64>,
1147 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Option<u64>,
1148 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Option<u64>,
1149
1150 event_emit_cost_base: Option<u64>,
1153 event_emit_value_size_derivation_cost_per_byte: Option<u64>,
1154 event_emit_tag_size_derivation_cost_per_byte: Option<u64>,
1155 event_emit_output_cost_per_byte: Option<u64>,
1156
1157 object_borrow_uid_cost_base: Option<u64>,
1160 object_delete_impl_cost_base: Option<u64>,
1162 object_record_new_uid_cost_base: Option<u64>,
1164
1165 transfer_transfer_internal_cost_base: Option<u64>,
1168 transfer_freeze_object_cost_base: Option<u64>,
1170 transfer_share_object_cost_base: Option<u64>,
1172 transfer_receive_object_cost_base: Option<u64>,
1175
1176 tx_context_derive_id_cost_base: Option<u64>,
1179 tx_context_fresh_id_cost_base: Option<u64>,
1180 tx_context_sender_cost_base: Option<u64>,
1181 tx_context_digest_cost_base: Option<u64>,
1182 tx_context_epoch_cost_base: Option<u64>,
1183 tx_context_epoch_timestamp_ms_cost_base: Option<u64>,
1184 tx_context_sponsor_cost_base: Option<u64>,
1185 tx_context_rgp_cost_base: Option<u64>,
1186 tx_context_gas_price_cost_base: Option<u64>,
1187 tx_context_gas_budget_cost_base: Option<u64>,
1188 tx_context_ids_created_cost_base: Option<u64>,
1189 tx_context_replace_cost_base: Option<u64>,
1190
1191 types_is_one_time_witness_cost_base: Option<u64>,
1194 types_is_one_time_witness_type_tag_cost_per_byte: Option<u64>,
1195 types_is_one_time_witness_type_cost_per_byte: Option<u64>,
1196
1197 validator_validate_metadata_cost_base: Option<u64>,
1200 validator_validate_metadata_data_cost_per_byte: Option<u64>,
1201
1202 crypto_invalid_arguments_cost: Option<u64>,
1204 bls12381_bls12381_min_sig_verify_cost_base: Option<u64>,
1206 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Option<u64>,
1207 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Option<u64>,
1208
1209 bls12381_bls12381_min_pk_verify_cost_base: Option<u64>,
1211 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Option<u64>,
1212 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Option<u64>,
1213
1214 ecdsa_k1_ecrecover_keccak256_cost_base: Option<u64>,
1216 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1217 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1218 ecdsa_k1_ecrecover_sha256_cost_base: Option<u64>,
1219 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1220 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1221
1222 ecdsa_k1_decompress_pubkey_cost_base: Option<u64>,
1224
1225 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Option<u64>,
1227 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1228 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Option<u64>,
1229 ecdsa_k1_secp256k1_verify_sha256_cost_base: Option<u64>,
1230 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Option<u64>,
1231 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Option<u64>,
1232
1233 ecdsa_r1_ecrecover_keccak256_cost_base: Option<u64>,
1235 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Option<u64>,
1236 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Option<u64>,
1237 ecdsa_r1_ecrecover_sha256_cost_base: Option<u64>,
1238 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Option<u64>,
1239 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Option<u64>,
1240
1241 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Option<u64>,
1243 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Option<u64>,
1244 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Option<u64>,
1245 ecdsa_r1_secp256r1_verify_sha256_cost_base: Option<u64>,
1246 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Option<u64>,
1247 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Option<u64>,
1248
1249 ecvrf_ecvrf_verify_cost_base: Option<u64>,
1251 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Option<u64>,
1252 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Option<u64>,
1253
1254 ed25519_ed25519_verify_cost_base: Option<u64>,
1256 ed25519_ed25519_verify_msg_cost_per_byte: Option<u64>,
1257 ed25519_ed25519_verify_msg_cost_per_block: Option<u64>,
1258
1259 groth16_prepare_verifying_key_bls12381_cost_base: Option<u64>,
1261 groth16_prepare_verifying_key_bn254_cost_base: Option<u64>,
1262
1263 groth16_verify_groth16_proof_internal_bls12381_cost_base: Option<u64>,
1265 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Option<u64>,
1266 groth16_verify_groth16_proof_internal_bn254_cost_base: Option<u64>,
1267 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Option<u64>,
1268 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Option<u64>,
1269
1270 hash_blake2b256_cost_base: Option<u64>,
1272 hash_blake2b256_data_cost_per_byte: Option<u64>,
1273 hash_blake2b256_data_cost_per_block: Option<u64>,
1274
1275 hash_keccak256_cost_base: Option<u64>,
1277 hash_keccak256_data_cost_per_byte: Option<u64>,
1278 hash_keccak256_data_cost_per_block: Option<u64>,
1279
1280 poseidon_bn254_cost_base: Option<u64>,
1282 poseidon_bn254_cost_per_block: Option<u64>,
1283
1284 group_ops_bls12381_decode_scalar_cost: Option<u64>,
1286 group_ops_bls12381_decode_g1_cost: Option<u64>,
1287 group_ops_bls12381_decode_g2_cost: Option<u64>,
1288 group_ops_bls12381_decode_gt_cost: Option<u64>,
1289 group_ops_bls12381_scalar_add_cost: Option<u64>,
1290 group_ops_bls12381_g1_add_cost: Option<u64>,
1291 group_ops_bls12381_g2_add_cost: Option<u64>,
1292 group_ops_bls12381_gt_add_cost: Option<u64>,
1293 group_ops_bls12381_scalar_sub_cost: Option<u64>,
1294 group_ops_bls12381_g1_sub_cost: Option<u64>,
1295 group_ops_bls12381_g2_sub_cost: Option<u64>,
1296 group_ops_bls12381_gt_sub_cost: Option<u64>,
1297 group_ops_bls12381_scalar_mul_cost: Option<u64>,
1298 group_ops_bls12381_g1_mul_cost: Option<u64>,
1299 group_ops_bls12381_g2_mul_cost: Option<u64>,
1300 group_ops_bls12381_gt_mul_cost: Option<u64>,
1301 group_ops_bls12381_scalar_div_cost: Option<u64>,
1302 group_ops_bls12381_g1_div_cost: Option<u64>,
1303 group_ops_bls12381_g2_div_cost: Option<u64>,
1304 group_ops_bls12381_gt_div_cost: Option<u64>,
1305 group_ops_bls12381_g1_hash_to_base_cost: Option<u64>,
1306 group_ops_bls12381_g2_hash_to_base_cost: Option<u64>,
1307 group_ops_bls12381_g1_hash_to_cost_per_byte: Option<u64>,
1308 group_ops_bls12381_g2_hash_to_cost_per_byte: Option<u64>,
1309 group_ops_bls12381_g1_msm_base_cost: Option<u64>,
1310 group_ops_bls12381_g2_msm_base_cost: Option<u64>,
1311 group_ops_bls12381_g1_msm_base_cost_per_input: Option<u64>,
1312 group_ops_bls12381_g2_msm_base_cost_per_input: Option<u64>,
1313 group_ops_bls12381_msm_max_len: Option<u32>,
1314 group_ops_bls12381_pairing_cost: Option<u64>,
1315 group_ops_bls12381_g1_to_uncompressed_g1_cost: Option<u64>,
1316 group_ops_bls12381_uncompressed_g1_to_g1_cost: Option<u64>,
1317 group_ops_bls12381_uncompressed_g1_sum_base_cost: Option<u64>,
1318 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: Option<u64>,
1319 group_ops_bls12381_uncompressed_g1_sum_max_terms: Option<u64>,
1320
1321 hmac_hmac_sha3_256_cost_base: Option<u64>,
1323 hmac_hmac_sha3_256_input_cost_per_byte: Option<u64>,
1324 hmac_hmac_sha3_256_input_cost_per_block: Option<u64>,
1325
1326 #[deprecated]
1328 check_zklogin_id_cost_base: Option<u64>,
1329 #[deprecated]
1331 check_zklogin_issuer_cost_base: Option<u64>,
1332
1333 vdf_verify_vdf_cost: Option<u64>,
1334 vdf_hash_to_input_cost: Option<u64>,
1335
1336 bcs_per_byte_serialized_cost: Option<u64>,
1338 bcs_legacy_min_output_size_cost: Option<u64>,
1339 bcs_failure_cost: Option<u64>,
1340
1341 hash_sha2_256_base_cost: Option<u64>,
1342 hash_sha2_256_per_byte_cost: Option<u64>,
1343 hash_sha2_256_legacy_min_input_len_cost: Option<u64>,
1344 hash_sha3_256_base_cost: Option<u64>,
1345 hash_sha3_256_per_byte_cost: Option<u64>,
1346 hash_sha3_256_legacy_min_input_len_cost: Option<u64>,
1347 type_name_get_base_cost: Option<u64>,
1348 type_name_get_per_byte_cost: Option<u64>,
1349
1350 string_check_utf8_base_cost: Option<u64>,
1351 string_check_utf8_per_byte_cost: Option<u64>,
1352 string_is_char_boundary_base_cost: Option<u64>,
1353 string_sub_string_base_cost: Option<u64>,
1354 string_sub_string_per_byte_cost: Option<u64>,
1355 string_index_of_base_cost: Option<u64>,
1356 string_index_of_per_byte_pattern_cost: Option<u64>,
1357 string_index_of_per_byte_searched_cost: Option<u64>,
1358
1359 vector_empty_base_cost: Option<u64>,
1360 vector_length_base_cost: Option<u64>,
1361 vector_push_back_base_cost: Option<u64>,
1362 vector_push_back_legacy_per_abstract_memory_unit_cost: Option<u64>,
1363 vector_borrow_base_cost: Option<u64>,
1364 vector_pop_back_base_cost: Option<u64>,
1365 vector_destroy_empty_base_cost: Option<u64>,
1366 vector_swap_base_cost: Option<u64>,
1367 debug_print_base_cost: Option<u64>,
1368 debug_print_stack_trace_base_cost: Option<u64>,
1369
1370 execution_version: Option<u64>,
1372
1373 consensus_bad_nodes_stake_threshold: Option<u64>,
1377
1378 #[deprecated]
1379 max_jwk_votes_per_validator_per_epoch: Option<u64>,
1380 #[deprecated]
1384 max_age_of_jwk_in_epochs: Option<u64>,
1385
1386 random_beacon_reduction_allowed_delta: Option<u16>,
1390
1391 random_beacon_reduction_lower_bound: Option<u32>,
1394
1395 random_beacon_dkg_timeout_round: Option<u32>,
1398
1399 random_beacon_min_round_interval_ms: Option<u64>,
1401
1402 random_beacon_dkg_version: Option<u64>,
1406
1407 consensus_max_transaction_size_bytes: Option<u64>,
1412 consensus_max_transactions_in_block_bytes: Option<u64>,
1414 consensus_max_num_transactions_in_block: Option<u64>,
1416
1417 max_deferral_rounds_for_congestion_control: Option<u64>,
1421
1422 min_checkpoint_interval_ms: Option<u64>,
1424
1425 checkpoint_rate_window_size: Option<u64>,
1435
1436 checkpoint_summary_version_specific_data: Option<u64>,
1438
1439 max_soft_bundle_size: Option<u64>,
1442
1443 bridge_should_try_to_finalize_committee: Option<bool>,
1448
1449 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Option<u64>,
1455
1456 max_committee_members_count: Option<u64>,
1460
1461 deny_rule_update_max_entries_per_tx: Option<u64>,
1466
1467 deny_rule_removal_grace_round_floor: Option<u64>,
1472
1473 consensus_gc_depth: Option<u32>,
1476
1477 consensus_max_acknowledgments_per_block: Option<u32>,
1483
1484 max_congestion_limit_overshoot_per_commit: Option<u64>,
1489
1490 max_concurrent_execution_workers: Option<u16>,
1497
1498 scorer_version: Option<u16>,
1507
1508 auth_context_digest_cost_base: Option<u64>,
1511 auth_context_tx_data_bytes_cost_base: Option<u64>,
1513 auth_context_tx_data_bytes_cost_per_byte: Option<u64>,
1514 auth_context_tx_commands_cost_base: Option<u64>,
1516 auth_context_tx_commands_cost_per_byte: Option<u64>,
1517 auth_context_tx_inputs_cost_base: Option<u64>,
1519 auth_context_tx_inputs_cost_per_byte: Option<u64>,
1520 auth_context_replace_cost_base: Option<u64>,
1523 auth_context_replace_cost_per_byte: Option<u64>,
1524 auth_context_authenticator_function_info_v1_cost_base: Option<u64>,
1528
1529 consensus_commits_per_schedule: Option<u32>,
1532
1533 min_validator_count: Option<u64>,
1536
1537 max_validator_count: Option<u64>,
1541
1542 min_validator_joining_stake: Option<u64>,
1546
1547 validator_low_stake_threshold: Option<u64>,
1552
1553 validator_very_low_stake_threshold: Option<u64>,
1557
1558 validator_low_stake_grace_period: Option<u64>,
1562
1563 consensus_leader_schedule_window_size: Option<u32>,
1567}
1568
1569impl ProtocolConfig {
1571 pub fn disable_invariant_violation_check_in_swap_loc(&self) -> bool {
1584 self.feature_flags
1585 .disable_invariant_violation_check_in_swap_loc
1586 }
1587
1588 pub fn no_extraneous_module_bytes(&self) -> bool {
1589 self.feature_flags.no_extraneous_module_bytes
1590 }
1591
1592 pub fn consensus_transaction_ordering(&self) -> ConsensusTransactionOrdering {
1593 self.feature_flags.consensus_transaction_ordering
1594 }
1595
1596 pub fn dkg_version(&self) -> u64 {
1597 self.random_beacon_dkg_version.unwrap_or(1)
1599 }
1600
1601 pub fn hardened_otw_check(&self) -> bool {
1602 self.feature_flags.hardened_otw_check
1603 }
1604
1605 pub fn enable_poseidon(&self) -> bool {
1606 self.feature_flags.enable_poseidon
1607 }
1608
1609 pub fn enable_group_ops_native_function_msm(&self) -> bool {
1610 self.feature_flags.enable_group_ops_native_function_msm
1611 }
1612
1613 pub fn per_object_congestion_control_mode(&self) -> PerObjectCongestionControlMode {
1614 self.feature_flags.per_object_congestion_control_mode
1615 }
1616
1617 pub fn consensus_choice(&self) -> ConsensusChoice {
1618 self.feature_flags.consensus_choice
1619 }
1620
1621 pub fn consensus_network(&self) -> ConsensusNetwork {
1622 self.feature_flags.consensus_network
1623 }
1624
1625 pub fn enable_vdf(&self) -> bool {
1626 self.feature_flags.enable_vdf
1627 }
1628
1629 pub fn passkey_auth(&self) -> bool {
1630 self.feature_flags.passkey_auth
1631 }
1632
1633 pub fn max_transaction_size_bytes(&self) -> u64 {
1634 self.consensus_max_transaction_size_bytes
1636 .unwrap_or(256 * 1024)
1637 }
1638
1639 pub fn max_transactions_in_block_bytes(&self) -> u64 {
1640 if cfg!(msim) {
1641 256 * 1024
1642 } else {
1643 self.consensus_max_transactions_in_block_bytes
1644 .unwrap_or(512 * 1024)
1645 }
1646 }
1647
1648 pub fn max_num_transactions_in_block(&self) -> u64 {
1649 if cfg!(msim) {
1650 8
1651 } else {
1652 self.consensus_max_num_transactions_in_block.unwrap_or(512)
1653 }
1654 }
1655
1656 pub fn rethrow_serialization_type_layout_errors(&self) -> bool {
1657 self.feature_flags.rethrow_serialization_type_layout_errors
1658 }
1659
1660 pub fn relocate_event_module(&self) -> bool {
1661 self.feature_flags.relocate_event_module
1662 }
1663
1664 pub fn protocol_defined_base_fee(&self) -> bool {
1665 self.feature_flags.protocol_defined_base_fee
1666 }
1667
1668 pub fn uncompressed_g1_group_elements(&self) -> bool {
1669 self.feature_flags.uncompressed_g1_group_elements
1670 }
1671
1672 pub fn disallow_new_modules_in_deps_only_packages(&self) -> bool {
1673 self.feature_flags
1674 .disallow_new_modules_in_deps_only_packages
1675 }
1676
1677 pub fn native_charging_v2(&self) -> bool {
1678 self.feature_flags.native_charging_v2
1679 }
1680
1681 pub fn consensus_round_prober(&self) -> bool {
1682 self.feature_flags.consensus_round_prober
1683 }
1684
1685 pub fn consensus_distributed_vote_scoring_strategy(&self) -> bool {
1686 self.feature_flags
1687 .consensus_distributed_vote_scoring_strategy
1688 }
1689
1690 pub fn gc_depth(&self) -> u32 {
1691 if cfg!(msim) {
1692 min(5, self.consensus_gc_depth.unwrap_or(0))
1694 } else {
1695 self.consensus_gc_depth.unwrap_or(0)
1696 }
1697 }
1698
1699 pub fn consensus_linearize_subdag_v2(&self) -> bool {
1700 let res = self.feature_flags.consensus_linearize_subdag_v2;
1701 assert!(
1702 !res || self.gc_depth() > 0,
1703 "The consensus linearize sub dag V2 requires GC to be enabled"
1704 );
1705 res
1706 }
1707
1708 pub fn consensus_max_acknowledgments_per_block_or_default(&self) -> u32 {
1709 self.consensus_max_acknowledgments_per_block.unwrap_or(400)
1710 }
1711
1712 pub fn max_acknowledgments_per_block(&self, committee_size: usize) -> usize {
1713 2 * committee_size
1714 }
1715
1716 pub fn max_commit_votes_per_block(&self, committee_size: usize) -> usize {
1717 committee_size
1718 }
1719
1720 pub fn variant_nodes(&self) -> bool {
1721 self.feature_flags.variant_nodes
1722 }
1723
1724 pub fn consensus_smart_ancestor_selection(&self) -> bool {
1725 self.feature_flags.consensus_smart_ancestor_selection
1726 }
1727
1728 pub fn consensus_round_prober_probe_accepted_rounds(&self) -> bool {
1729 self.feature_flags
1730 .consensus_round_prober_probe_accepted_rounds
1731 }
1732
1733 pub fn consensus_zstd_compression(&self) -> bool {
1734 self.feature_flags.consensus_zstd_compression
1735 }
1736
1737 pub fn congestion_control_min_free_execution_slot(&self) -> bool {
1738 self.feature_flags
1739 .congestion_control_min_free_execution_slot
1740 }
1741
1742 pub fn accept_passkey_in_multisig(&self) -> bool {
1743 self.feature_flags.accept_passkey_in_multisig
1744 }
1745
1746 pub fn consensus_batched_block_sync(&self) -> bool {
1747 self.feature_flags.consensus_batched_block_sync
1748 }
1749
1750 pub fn congestion_control_gas_price_feedback_mechanism(&self) -> bool {
1753 self.feature_flags
1754 .congestion_control_gas_price_feedback_mechanism
1755 }
1756
1757 pub fn validate_identifier_inputs(&self) -> bool {
1758 self.feature_flags.validate_identifier_inputs
1759 }
1760
1761 pub fn minimize_child_object_mutations(&self) -> bool {
1762 self.feature_flags.minimize_child_object_mutations
1763 }
1764
1765 pub fn dependency_linkage_error(&self) -> bool {
1766 self.feature_flags.dependency_linkage_error
1767 }
1768
1769 pub fn additional_multisig_checks(&self) -> bool {
1770 self.feature_flags.additional_multisig_checks
1771 }
1772
1773 pub fn consensus_num_requested_prior_commits_at_startup(&self) -> u32 {
1774 0
1777 }
1778
1779 pub fn normalize_ptb_arguments(&self) -> bool {
1780 self.feature_flags.normalize_ptb_arguments
1781 }
1782
1783 pub fn select_committee_from_eligible_validators(&self) -> bool {
1784 let res = self.feature_flags.select_committee_from_eligible_validators;
1785 assert!(
1786 !res || (self.protocol_defined_base_fee()
1787 && self.max_committee_members_count_as_option().is_some()),
1788 "select_committee_from_eligible_validators requires protocol_defined_base_fee and max_committee_members_count to be set"
1789 );
1790 res
1791 }
1792
1793 pub fn track_non_committee_eligible_validators(&self) -> bool {
1794 self.feature_flags.track_non_committee_eligible_validators
1795 }
1796
1797 pub fn select_committee_supporting_next_epoch_version(&self) -> bool {
1798 let res = self
1799 .feature_flags
1800 .select_committee_supporting_next_epoch_version;
1801 assert!(
1802 !res || (self.track_non_committee_eligible_validators()
1803 && self.select_committee_from_eligible_validators()),
1804 "select_committee_supporting_next_epoch_version requires select_committee_from_eligible_validators to be set"
1805 );
1806 res
1807 }
1808
1809 pub fn consensus_median_timestamp_with_checkpoint_enforcement(&self) -> bool {
1810 let res = self
1811 .feature_flags
1812 .consensus_median_timestamp_with_checkpoint_enforcement;
1813 assert!(
1814 !res || self.gc_depth() > 0,
1815 "The consensus median timestamp with checkpoint enforcement requires GC to be enabled"
1816 );
1817 res
1818 }
1819
1820 pub fn consensus_commit_transactions_only_for_traversed_headers(&self) -> bool {
1821 self.feature_flags
1822 .consensus_commit_transactions_only_for_traversed_headers
1823 }
1824
1825 pub fn congestion_limit_overshoot_in_gas_price_feedback_mechanism(&self) -> bool {
1828 self.feature_flags
1829 .congestion_limit_overshoot_in_gas_price_feedback_mechanism
1830 }
1831
1832 pub fn separate_gas_price_feedback_mechanism_for_randomness(&self) -> bool {
1835 self.feature_flags
1836 .separate_gas_price_feedback_mechanism_for_randomness
1837 }
1838
1839 pub fn metadata_in_module_bytes(&self) -> bool {
1840 self.feature_flags.metadata_in_module_bytes
1841 }
1842
1843 pub fn publish_package_metadata(&self) -> bool {
1844 self.feature_flags.publish_package_metadata
1845 }
1846
1847 pub fn enable_move_authentication(&self) -> bool {
1848 self.feature_flags.enable_move_authentication
1849 }
1850
1851 pub fn additional_borrow_checks(&self) -> bool {
1852 self.feature_flags.additional_borrow_checks
1853 }
1854
1855 pub fn enable_move_authentication_for_sponsor(&self) -> bool {
1856 let enable_move_authentication_for_sponsor =
1857 self.feature_flags.enable_move_authentication_for_sponsor;
1858 assert!(
1859 !enable_move_authentication_for_sponsor || self.enable_move_authentication(),
1860 "enable_move_authentication_for_sponsor requires enable_move_authentication to be set"
1861 );
1862 enable_move_authentication_for_sponsor
1863 }
1864
1865 pub fn pass_validator_scores_to_advance_epoch(&self) -> bool {
1866 self.feature_flags.pass_validator_scores_to_advance_epoch
1867 }
1868
1869 pub fn calculate_validator_scores(&self) -> bool {
1870 let calculate_validator_scores = self.feature_flags.calculate_validator_scores;
1871 assert!(
1872 !calculate_validator_scores || self.scorer_version.is_some(),
1873 "calculate_validator_scores requires scorer_version to be set"
1874 );
1875 calculate_validator_scores
1876 }
1877
1878 pub fn adjust_rewards_by_score(&self) -> bool {
1879 let adjust = self.feature_flags.adjust_rewards_by_score;
1880 assert!(
1881 !adjust || (self.scorer_version.is_some() && self.calculate_validator_scores()),
1882 "adjust_rewards_by_score requires scorer_version to be set"
1883 );
1884 adjust
1885 }
1886
1887 pub fn pass_calculated_validator_scores_to_advance_epoch(&self) -> bool {
1888 let pass = self
1889 .feature_flags
1890 .pass_calculated_validator_scores_to_advance_epoch;
1891 assert!(
1892 !pass
1893 || (self.pass_validator_scores_to_advance_epoch()
1894 && self.calculate_validator_scores()),
1895 "pass_calculated_validator_scores_to_advance_epoch requires pass_validator_scores_to_advance_epoch and calculate_validator_scores to be enabled"
1896 );
1897 pass
1898 }
1899 pub fn consensus_fast_commit_sync(&self) -> bool {
1900 let res = self.feature_flags.consensus_fast_commit_sync;
1901 assert!(
1902 !res || self.consensus_commit_transactions_only_for_traversed_headers(),
1903 "consensus_fast_commit_sync requires consensus_commit_transactions_only_for_traversed_headers to be enabled"
1904 );
1905 res
1906 }
1907
1908 pub fn consensus_block_restrictions(&self) -> bool {
1909 self.feature_flags.consensus_block_restrictions
1910 }
1911
1912 pub fn move_native_tx_context(&self) -> bool {
1913 self.feature_flags.move_native_tx_context
1914 }
1915
1916 pub fn pre_consensus_sponsor_only_move_authentication(&self) -> bool {
1917 let pre_consensus_sponsor_only_move_authentication = self
1918 .feature_flags
1919 .pre_consensus_sponsor_only_move_authentication;
1920 if pre_consensus_sponsor_only_move_authentication {
1921 assert!(
1922 self.enable_move_authentication(),
1923 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication to be set"
1924 );
1925 assert!(
1926 self.enable_move_authentication_for_sponsor(),
1927 "pre_consensus_sponsor_only_move_authentication requires enable_move_authentication_for_sponsor to be set"
1928 );
1929 }
1930 pre_consensus_sponsor_only_move_authentication
1931 }
1932
1933 pub fn consensus_starfish_speed(&self) -> bool {
1934 let res = self.feature_flags.consensus_starfish_speed;
1935 assert!(
1936 !res || self.consensus_fast_commit_sync(),
1937 "consensus_starfish_speed requires consensus_fast_commit_sync to be enabled"
1938 );
1939 res
1940 }
1941
1942 pub fn always_advance_dkg_to_resolution(&self) -> bool {
1943 self.feature_flags.always_advance_dkg_to_resolution
1944 }
1945
1946 pub fn enable_pcool_flow(&self) -> bool {
1947 self.feature_flags.enable_pcool_flow
1948 }
1949
1950 pub fn pcool_skip_immutable_object_locks(&self) -> bool {
1951 self.feature_flags.pcool_skip_immutable_object_locks
1952 }
1953
1954 pub fn validator_metadata_verify_v2(&self) -> bool {
1955 self.feature_flags.validator_metadata_verify_v2
1956 }
1957
1958 pub fn commits_per_schedule(&self) -> u32 {
1959 let commits_per_schedule = if cfg!(msim) {
1960 min(10, self.consensus_commits_per_schedule.unwrap_or(300))
1962 } else {
1963 self.consensus_commits_per_schedule.unwrap_or(300)
1964 };
1965 assert!(
1966 commits_per_schedule > 0,
1967 "consensus_commits_per_schedule must be greater than 0"
1968 );
1969 commits_per_schedule
1970 }
1971
1972 pub fn leader_schedule_window_size(&self) -> u32 {
1973 if cfg!(msim) {
1974 min(
1977 20,
1978 self.consensus_leader_schedule_window_size.unwrap_or(600),
1979 )
1980 } else {
1981 self.consensus_leader_schedule_window_size.unwrap_or(600)
1982 }
1983 }
1984
1985 pub fn consensus_enable_sliding_window_leader_schedule(&self) -> bool {
1986 let res = self
1987 .feature_flags
1988 .consensus_enable_sliding_window_leader_schedule;
1989 assert!(
1990 !res || self.leader_schedule_window_size() >= self.commits_per_schedule(),
1991 "consensus_enable_sliding_window_leader_schedule requires window_size >= commits_per_schedule"
1992 );
1993 res
1994 }
1995
1996 pub fn consensus_enable_absolute_score_leader_schedule(&self) -> bool {
1997 self.feature_flags
1998 .consensus_enable_absolute_score_leader_schedule
1999 }
2000
2001 pub fn deny_rule_governance(&self) -> bool {
2002 self.feature_flags.deny_rule_governance
2003 }
2004
2005 pub fn deny_rule_governance_on_chain(&self) -> bool {
2006 self.feature_flags.deny_rule_governance_on_chain
2007 }
2008
2009 pub fn package_metadata_with_dynamic_module_metadata(&self) -> bool {
2010 let res = self
2011 .feature_flags
2012 .package_metadata_with_dynamic_module_metadata;
2013 assert!(
2014 !res || self.publish_package_metadata(),
2015 "package_metadata_with_dynamic_module_metadata requires publish_package_metadata to be enabled"
2016 );
2017 res
2018 }
2019
2020 pub fn report_move_authentication_error(&self) -> bool {
2021 let report_move_authentication_error = self.feature_flags.report_move_authentication_error;
2022 assert!(
2023 !report_move_authentication_error || self.enable_move_authentication(),
2024 "report_move_authentication_error requires enable_move_authentication to be set"
2025 );
2026 report_move_authentication_error
2027 }
2028
2029 pub fn concurrent_execution_workers(&self) -> Option<u16> {
2033 let res = self.max_concurrent_execution_workers;
2034 assert!(
2035 res.is_none() || self.enable_pcool_flow(),
2036 "max_concurrent_execution_workers requires enable_pcool_flow to be enabled"
2037 );
2038 assert!(
2039 res.is_none()
2040 || self
2041 .max_accumulated_txn_cost_per_object_in_mysticeti_commit
2042 .is_some(),
2043 "max_concurrent_execution_workers requires per-object congestion control \
2044 (max_accumulated_txn_cost_per_object_in_mysticeti_commit) to be enabled"
2045 );
2046 assert!(
2047 res.is_none() || self.congestion_control_gas_price_feedback_mechanism(),
2048 "max_concurrent_execution_workers requires the gas price feedback mechanism \
2049 (congestion_control_gas_price_feedback_mechanism), which carries the suggested \
2050 gas price of an execution-worker congestion cancellation"
2051 );
2052 assert!(
2053 res.is_none() || !self.separate_gas_price_feedback_mechanism_for_randomness(),
2054 "max_concurrent_execution_workers implies a single congestion tracker and suggested \
2055 gas price calculator for all transactions, which is incompatible with \
2056 separate_gas_price_feedback_mechanism_for_randomness"
2057 );
2058 assert!(
2059 res != Some(0),
2060 "max_concurrent_execution_workers must be positive when set"
2061 );
2062 res
2063 }
2064}
2065
2066#[cfg(not(msim))]
2067static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2068
2069#[cfg(msim)]
2071thread_local! {
2072 static POISON_VERSION_METHODS: AtomicBool = const { AtomicBool::new(false) };
2073}
2074
2075impl ProtocolConfig {
2077 pub fn get_for_version(version: ProtocolVersion, chain: Chain) -> Self {
2080 assert!(
2082 version >= ProtocolVersion::MIN,
2083 "Network protocol version is {:?}, but the minimum supported version by the binary is {:?}. Please upgrade the binary.",
2084 version,
2085 ProtocolVersion::MIN.0,
2086 );
2087 assert!(
2088 version <= ProtocolVersion::MAX_ALLOWED,
2089 "Network protocol version is {:?}, but the maximum supported version by the binary is {:?}. Please upgrade the binary.",
2090 version,
2091 ProtocolVersion::MAX_ALLOWED.0,
2092 );
2093
2094 let mut ret = Self::get_for_version_impl(version, chain);
2095 ret.version = version;
2096
2097 ret = CONFIG_OVERRIDE.with(|ovr| {
2098 if let Some(override_fn) = &*ovr.borrow() {
2099 warn!(
2100 "overriding ProtocolConfig settings with custom settings (you should not see this log outside of tests)"
2101 );
2102 override_fn(version, ret)
2103 } else {
2104 ret
2105 }
2106 });
2107
2108 if std::env::var("IOTA_PROTOCOL_CONFIG_OVERRIDE_ENABLE").is_ok() {
2109 warn!(
2110 "overriding ProtocolConfig settings with custom settings; this may break non-local networks"
2111 );
2112
2113 let overrides: ProtocolConfigOptional =
2115 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_OVERRIDE")
2116 .expect("failed to parse ProtocolConfig override env variables");
2117 overrides.apply_to(&mut ret);
2118
2119 let feature_flag_overrides: FeatureFlagsOptional =
2121 serde_env::from_env_with_prefix("IOTA_PROTOCOL_CONFIG_FEATURE_FLAGS_OVERRIDE")
2122 .expect("failed to parse ProtocolConfig feature flags override env variables");
2123
2124 feature_flag_overrides.apply_to(&mut ret.feature_flags);
2125 }
2126
2127 assert!(
2129 !ret.feature_flags.deny_rule_governance_on_chain
2130 || ret.feature_flags.deny_rule_governance,
2131 "deny_rule_governance_on_chain requires deny_rule_governance"
2132 );
2133 assert!(
2136 !ret.feature_flags.deny_rule_governance_on_chain
2137 || (ret.deny_rule_update_max_entries_per_tx.is_some()
2138 && ret.deny_rule_removal_grace_round_floor.is_some()),
2139 "deny_rule_governance_on_chain requires deny_rule_update_max_entries_per_tx and deny_rule_removal_grace_round_floor"
2140 );
2141 const DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING: u64 = 2048;
2149 assert!(
2150 ret.deny_rule_update_max_entries_per_tx
2151 .is_none_or(|max_entries| {
2152 max_entries > 0
2153 && max_entries <= DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING
2154 && [
2155 ret.max_num_new_move_object_ids_system_tx,
2156 ret.max_num_deleted_move_object_ids_system_tx,
2157 ret.object_runtime_max_num_cached_objects_system_tx,
2158 ret.object_runtime_max_num_store_entries_system_tx,
2159 ]
2160 .iter()
2161 .all(|limit| limit.is_none_or(|limit| max_entries <= limit))
2162 }),
2163 "deny_rule_update_max_entries_per_tx must be positive, at most {DENY_RULE_UPDATE_MAX_ENTRIES_PER_TX_CEILING}, and within the system transaction object limits"
2164 );
2165
2166 ret
2167 }
2168
2169 pub fn get_for_version_if_supported(version: ProtocolVersion, chain: Chain) -> Option<Self> {
2172 if version.0 >= ProtocolVersion::MIN.0 && version.0 <= ProtocolVersion::MAX_ALLOWED.0 {
2173 let mut ret = Self::get_for_version_impl(version, chain);
2174 ret.version = version;
2175 Some(ret)
2176 } else {
2177 None
2178 }
2179 }
2180
2181 #[cfg(not(msim))]
2182 pub fn poison_get_for_min_version() {
2183 POISON_VERSION_METHODS.store(true, Ordering::Relaxed);
2184 }
2185
2186 #[cfg(not(msim))]
2187 fn load_poison_get_for_min_version() -> bool {
2188 POISON_VERSION_METHODS.load(Ordering::Relaxed)
2189 }
2190
2191 #[cfg(msim)]
2192 pub fn poison_get_for_min_version() {
2193 POISON_VERSION_METHODS.with(|p| p.store(true, Ordering::Relaxed));
2194 }
2195
2196 #[cfg(msim)]
2197 fn load_poison_get_for_min_version() -> bool {
2198 POISON_VERSION_METHODS.with(|p| p.load(Ordering::Relaxed))
2199 }
2200
2201 pub fn convert_type_argument_error(&self) -> bool {
2202 self.feature_flags.convert_type_argument_error
2203 }
2204
2205 pub fn get_for_min_version() -> Self {
2209 if Self::load_poison_get_for_min_version() {
2210 panic!("get_for_min_version called on validator");
2211 }
2212 ProtocolConfig::get_for_version(ProtocolVersion::MIN, Chain::Unknown)
2213 }
2214
2215 #[expect(non_snake_case)]
2226 pub fn get_for_max_version_UNSAFE() -> Self {
2227 if Self::load_poison_get_for_min_version() {
2228 panic!("get_for_max_version_UNSAFE called on validator");
2229 }
2230 ProtocolConfig::get_for_version(ProtocolVersion::MAX, Chain::Unknown)
2231 }
2232
2233 fn get_for_version_impl(version: ProtocolVersion, chain: Chain) -> Self {
2234 #[cfg(msim)]
2235 {
2236 if version > ProtocolVersion::MAX {
2238 let mut config = Self::get_for_version_impl(ProtocolVersion::MAX, Chain::Unknown);
2239 config.base_tx_cost_fixed = Some(config.base_tx_cost_fixed() + 1000);
2240 return config;
2241 }
2242 }
2243
2244 let mut cfg = Self {
2248 version,
2249
2250 feature_flags: Default::default(),
2251
2252 max_tx_size_bytes: Some(128 * 1024),
2253 max_input_objects: Some(2048),
2256 max_serialized_tx_effects_size_bytes: Some(512 * 1024),
2257 max_serialized_tx_effects_size_bytes_system_tx: Some(512 * 1024 * 16),
2258 max_gas_payment_objects: Some(256),
2259 max_modules_in_publish: Some(64),
2260 max_package_dependencies: Some(32),
2261 max_arguments: Some(512),
2262 max_type_arguments: Some(16),
2263 max_type_argument_depth: Some(16),
2264 max_pure_argument_size: Some(16 * 1024),
2265 max_programmable_tx_commands: Some(1024),
2266 move_binary_format_version: Some(7),
2267 min_move_binary_format_version: Some(6),
2268 binary_module_handles: Some(100),
2269 binary_struct_handles: Some(300),
2270 binary_function_handles: Some(1500),
2271 binary_function_instantiations: Some(750),
2272 binary_signatures: Some(1000),
2273 binary_constant_pool: Some(4000),
2274 binary_identifiers: Some(10000),
2275 binary_address_identifiers: Some(100),
2276 binary_struct_defs: Some(200),
2277 binary_struct_def_instantiations: Some(100),
2278 binary_function_defs: Some(1000),
2279 binary_field_handles: Some(500),
2280 binary_field_instantiations: Some(250),
2281 binary_friend_decls: Some(100),
2282 binary_enum_defs: None,
2283 binary_enum_def_instantiations: None,
2284 binary_variant_handles: None,
2285 binary_variant_instantiation_handles: None,
2286 max_move_object_size: Some(250 * 1024),
2287 max_move_package_size: Some(100 * 1024),
2288 max_publish_or_upgrade_per_ptb: Some(5),
2289 max_auth_gas: None,
2291 max_tx_gas: Some(50_000_000_000),
2293 max_gas_price: Some(100_000),
2294 max_gas_computation_bucket: Some(5_000_000),
2295 max_loop_depth: Some(5),
2296 max_generic_instantiation_length: Some(32),
2297 max_function_parameters: Some(128),
2298 max_basic_blocks: Some(1024),
2299 max_value_stack_size: Some(1024),
2300 max_type_nodes: Some(256),
2301 max_push_size: Some(10000),
2302 max_struct_definitions: Some(200),
2303 max_function_definitions: Some(1000),
2304 max_fields_in_struct: Some(32),
2305 max_dependency_depth: Some(100),
2306 max_num_event_emit: Some(1024),
2307 max_num_new_move_object_ids: Some(2048),
2308 max_num_new_move_object_ids_system_tx: Some(2048 * 16),
2309 max_num_deleted_move_object_ids: Some(2048),
2310 max_num_deleted_move_object_ids_system_tx: Some(2048 * 16),
2311 max_num_transferred_move_object_ids: Some(2048),
2312 max_num_transferred_move_object_ids_system_tx: Some(2048 * 16),
2313 max_event_emit_size: Some(250 * 1024),
2314 max_move_vector_len: Some(256 * 1024),
2315 max_type_to_layout_nodes: None,
2316 max_ptb_value_size: None,
2317
2318 max_back_edges_per_function: Some(10_000),
2319 max_back_edges_per_module: Some(10_000),
2320
2321 max_verifier_meter_ticks_per_function: Some(16_000_000),
2322
2323 max_meter_ticks_per_module: Some(16_000_000),
2324 max_meter_ticks_per_package: Some(16_000_000),
2325
2326 object_runtime_max_num_cached_objects: Some(1000),
2327 object_runtime_max_num_cached_objects_system_tx: Some(1000 * 16),
2328 object_runtime_max_num_store_entries: Some(1000),
2329 object_runtime_max_num_store_entries_system_tx: Some(1000 * 16),
2330 base_tx_cost_fixed: Some(1_000),
2332 package_publish_cost_fixed: Some(1_000),
2333 base_tx_cost_per_byte: Some(0),
2334 package_publish_cost_per_byte: Some(80),
2335 obj_access_cost_read_per_byte: Some(15),
2336 obj_access_cost_mutate_per_byte: Some(40),
2337 obj_access_cost_delete_per_byte: Some(40),
2338 obj_access_cost_verify_per_byte: Some(200),
2339 obj_data_cost_refundable: Some(100),
2340 obj_metadata_cost_non_refundable: Some(50),
2341 gas_model_version: Some(1),
2342 storage_rebate_rate: Some(10000),
2343 reward_slashing_rate: Some(10000),
2345 storage_gas_price: Some(76),
2346 base_gas_price: None,
2347 validator_target_reward: Some(767_000 * 1_000_000_000),
2350 max_transactions_per_checkpoint: Some(10_000),
2351 max_checkpoint_size_bytes: Some(30 * 1024 * 1024),
2352
2353 buffer_stake_for_protocol_upgrade_bps: Some(5000),
2355
2356 address_from_bytes_cost_base: Some(52),
2360 address_to_u256_cost_base: Some(52),
2362 address_from_u256_cost_base: Some(52),
2364
2365 config_read_setting_impl_cost_base: Some(100),
2368 config_read_setting_impl_cost_per_byte: Some(40),
2369
2370 dynamic_field_hash_type_and_key_cost_base: Some(100),
2374 dynamic_field_hash_type_and_key_type_cost_per_byte: Some(2),
2375 dynamic_field_hash_type_and_key_value_cost_per_byte: Some(2),
2376 dynamic_field_hash_type_and_key_type_tag_cost_per_byte: Some(2),
2377 dynamic_field_add_child_object_cost_base: Some(100),
2380 dynamic_field_add_child_object_type_cost_per_byte: Some(10),
2381 dynamic_field_add_child_object_value_cost_per_byte: Some(10),
2382 dynamic_field_add_child_object_struct_tag_cost_per_byte: Some(10),
2383 dynamic_field_borrow_child_object_cost_base: Some(100),
2386 dynamic_field_borrow_child_object_child_ref_cost_per_byte: Some(10),
2387 dynamic_field_borrow_child_object_type_cost_per_byte: Some(10),
2388 dynamic_field_remove_child_object_cost_base: Some(100),
2391 dynamic_field_remove_child_object_child_cost_per_byte: Some(2),
2392 dynamic_field_remove_child_object_type_cost_per_byte: Some(2),
2393 dynamic_field_has_child_object_cost_base: Some(100),
2396 dynamic_field_has_child_object_with_ty_cost_base: Some(100),
2399 dynamic_field_has_child_object_with_ty_type_cost_per_byte: Some(2),
2400 dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: Some(2),
2401
2402 event_emit_cost_base: Some(52),
2405 event_emit_value_size_derivation_cost_per_byte: Some(2),
2406 event_emit_tag_size_derivation_cost_per_byte: Some(5),
2407 event_emit_output_cost_per_byte: Some(10),
2408
2409 object_borrow_uid_cost_base: Some(52),
2412 object_delete_impl_cost_base: Some(52),
2414 object_record_new_uid_cost_base: Some(52),
2416
2417 transfer_transfer_internal_cost_base: Some(52),
2421 transfer_freeze_object_cost_base: Some(52),
2423 transfer_share_object_cost_base: Some(52),
2425 transfer_receive_object_cost_base: Some(52),
2426
2427 tx_context_derive_id_cost_base: Some(52),
2431 tx_context_fresh_id_cost_base: None,
2432 tx_context_sender_cost_base: None,
2433 tx_context_digest_cost_base: None,
2434 tx_context_epoch_cost_base: None,
2435 tx_context_epoch_timestamp_ms_cost_base: None,
2436 tx_context_sponsor_cost_base: None,
2437 tx_context_rgp_cost_base: None,
2438 tx_context_gas_price_cost_base: None,
2439 tx_context_gas_budget_cost_base: None,
2440 tx_context_ids_created_cost_base: None,
2441 tx_context_replace_cost_base: None,
2442
2443 types_is_one_time_witness_cost_base: Some(52),
2446 types_is_one_time_witness_type_tag_cost_per_byte: Some(2),
2447 types_is_one_time_witness_type_cost_per_byte: Some(2),
2448
2449 validator_validate_metadata_cost_base: Some(52),
2453 validator_validate_metadata_data_cost_per_byte: Some(2),
2454
2455 crypto_invalid_arguments_cost: Some(100),
2457 bls12381_bls12381_min_sig_verify_cost_base: Some(52),
2459 bls12381_bls12381_min_sig_verify_msg_cost_per_byte: Some(2),
2460 bls12381_bls12381_min_sig_verify_msg_cost_per_block: Some(2),
2461
2462 bls12381_bls12381_min_pk_verify_cost_base: Some(52),
2464 bls12381_bls12381_min_pk_verify_msg_cost_per_byte: Some(2),
2465 bls12381_bls12381_min_pk_verify_msg_cost_per_block: Some(2),
2466
2467 ecdsa_k1_ecrecover_keccak256_cost_base: Some(52),
2469 ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2470 ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2471 ecdsa_k1_ecrecover_sha256_cost_base: Some(52),
2472 ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2473 ecdsa_k1_ecrecover_sha256_msg_cost_per_block: Some(2),
2474
2475 ecdsa_k1_decompress_pubkey_cost_base: Some(52),
2477
2478 ecdsa_k1_secp256k1_verify_keccak256_cost_base: Some(52),
2480 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: Some(2),
2481 ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: Some(2),
2482 ecdsa_k1_secp256k1_verify_sha256_cost_base: Some(52),
2483 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: Some(2),
2484 ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: Some(2),
2485
2486 ecdsa_r1_ecrecover_keccak256_cost_base: Some(52),
2488 ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: Some(2),
2489 ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: Some(2),
2490 ecdsa_r1_ecrecover_sha256_cost_base: Some(52),
2491 ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: Some(2),
2492 ecdsa_r1_ecrecover_sha256_msg_cost_per_block: Some(2),
2493
2494 ecdsa_r1_secp256r1_verify_keccak256_cost_base: Some(52),
2496 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: Some(2),
2497 ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: Some(2),
2498 ecdsa_r1_secp256r1_verify_sha256_cost_base: Some(52),
2499 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: Some(2),
2500 ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: Some(2),
2501
2502 ecvrf_ecvrf_verify_cost_base: Some(52),
2504 ecvrf_ecvrf_verify_alpha_string_cost_per_byte: Some(2),
2505 ecvrf_ecvrf_verify_alpha_string_cost_per_block: Some(2),
2506
2507 ed25519_ed25519_verify_cost_base: Some(52),
2509 ed25519_ed25519_verify_msg_cost_per_byte: Some(2),
2510 ed25519_ed25519_verify_msg_cost_per_block: Some(2),
2511
2512 groth16_prepare_verifying_key_bls12381_cost_base: Some(52),
2514 groth16_prepare_verifying_key_bn254_cost_base: Some(52),
2515
2516 groth16_verify_groth16_proof_internal_bls12381_cost_base: Some(52),
2518 groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: Some(2),
2519 groth16_verify_groth16_proof_internal_bn254_cost_base: Some(52),
2520 groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: Some(2),
2521 groth16_verify_groth16_proof_internal_public_input_cost_per_byte: Some(2),
2522
2523 hash_blake2b256_cost_base: Some(52),
2525 hash_blake2b256_data_cost_per_byte: Some(2),
2526 hash_blake2b256_data_cost_per_block: Some(2),
2527 hash_keccak256_cost_base: Some(52),
2529 hash_keccak256_data_cost_per_byte: Some(2),
2530 hash_keccak256_data_cost_per_block: Some(2),
2531
2532 poseidon_bn254_cost_base: None,
2533 poseidon_bn254_cost_per_block: None,
2534
2535 hmac_hmac_sha3_256_cost_base: Some(52),
2537 hmac_hmac_sha3_256_input_cost_per_byte: Some(2),
2538 hmac_hmac_sha3_256_input_cost_per_block: Some(2),
2539
2540 group_ops_bls12381_decode_scalar_cost: Some(52),
2542 group_ops_bls12381_decode_g1_cost: Some(52),
2543 group_ops_bls12381_decode_g2_cost: Some(52),
2544 group_ops_bls12381_decode_gt_cost: Some(52),
2545 group_ops_bls12381_scalar_add_cost: Some(52),
2546 group_ops_bls12381_g1_add_cost: Some(52),
2547 group_ops_bls12381_g2_add_cost: Some(52),
2548 group_ops_bls12381_gt_add_cost: Some(52),
2549 group_ops_bls12381_scalar_sub_cost: Some(52),
2550 group_ops_bls12381_g1_sub_cost: Some(52),
2551 group_ops_bls12381_g2_sub_cost: Some(52),
2552 group_ops_bls12381_gt_sub_cost: Some(52),
2553 group_ops_bls12381_scalar_mul_cost: Some(52),
2554 group_ops_bls12381_g1_mul_cost: Some(52),
2555 group_ops_bls12381_g2_mul_cost: Some(52),
2556 group_ops_bls12381_gt_mul_cost: Some(52),
2557 group_ops_bls12381_scalar_div_cost: Some(52),
2558 group_ops_bls12381_g1_div_cost: Some(52),
2559 group_ops_bls12381_g2_div_cost: Some(52),
2560 group_ops_bls12381_gt_div_cost: Some(52),
2561 group_ops_bls12381_g1_hash_to_base_cost: Some(52),
2562 group_ops_bls12381_g2_hash_to_base_cost: Some(52),
2563 group_ops_bls12381_g1_hash_to_cost_per_byte: Some(2),
2564 group_ops_bls12381_g2_hash_to_cost_per_byte: Some(2),
2565 group_ops_bls12381_g1_msm_base_cost: Some(52),
2566 group_ops_bls12381_g2_msm_base_cost: Some(52),
2567 group_ops_bls12381_g1_msm_base_cost_per_input: Some(52),
2568 group_ops_bls12381_g2_msm_base_cost_per_input: Some(52),
2569 group_ops_bls12381_msm_max_len: Some(32),
2570 group_ops_bls12381_pairing_cost: Some(52),
2571 group_ops_bls12381_g1_to_uncompressed_g1_cost: None,
2572 group_ops_bls12381_uncompressed_g1_to_g1_cost: None,
2573 group_ops_bls12381_uncompressed_g1_sum_base_cost: None,
2574 group_ops_bls12381_uncompressed_g1_sum_cost_per_term: None,
2575 group_ops_bls12381_uncompressed_g1_sum_max_terms: None,
2576
2577 #[allow(deprecated)]
2579 check_zklogin_id_cost_base: Some(200),
2580 #[allow(deprecated)]
2581 check_zklogin_issuer_cost_base: Some(200),
2583
2584 vdf_verify_vdf_cost: None,
2585 vdf_hash_to_input_cost: None,
2586
2587 bcs_per_byte_serialized_cost: Some(2),
2588 bcs_legacy_min_output_size_cost: Some(1),
2589 bcs_failure_cost: Some(52),
2590 hash_sha2_256_base_cost: Some(52),
2591 hash_sha2_256_per_byte_cost: Some(2),
2592 hash_sha2_256_legacy_min_input_len_cost: Some(1),
2593 hash_sha3_256_base_cost: Some(52),
2594 hash_sha3_256_per_byte_cost: Some(2),
2595 hash_sha3_256_legacy_min_input_len_cost: Some(1),
2596 type_name_get_base_cost: Some(52),
2597 type_name_get_per_byte_cost: Some(2),
2598 string_check_utf8_base_cost: Some(52),
2599 string_check_utf8_per_byte_cost: Some(2),
2600 string_is_char_boundary_base_cost: Some(52),
2601 string_sub_string_base_cost: Some(52),
2602 string_sub_string_per_byte_cost: Some(2),
2603 string_index_of_base_cost: Some(52),
2604 string_index_of_per_byte_pattern_cost: Some(2),
2605 string_index_of_per_byte_searched_cost: Some(2),
2606 vector_empty_base_cost: Some(52),
2607 vector_length_base_cost: Some(52),
2608 vector_push_back_base_cost: Some(52),
2609 vector_push_back_legacy_per_abstract_memory_unit_cost: Some(2),
2610 vector_borrow_base_cost: Some(52),
2611 vector_pop_back_base_cost: Some(52),
2612 vector_destroy_empty_base_cost: Some(52),
2613 vector_swap_base_cost: Some(52),
2614 debug_print_base_cost: Some(52),
2615 debug_print_stack_trace_base_cost: Some(52),
2616
2617 max_size_written_objects: Some(5 * 1000 * 1000),
2618 max_size_written_objects_system_tx: Some(50 * 1000 * 1000),
2621
2622 max_move_identifier_len: Some(128),
2624 max_move_value_depth: Some(128),
2625 max_move_enum_variants: None,
2626
2627 gas_rounding_step: Some(1_000),
2628
2629 execution_version: Some(1),
2630
2631 max_event_emit_size_total: Some(
2634 256 * 250 * 1024, ),
2636
2637 consensus_bad_nodes_stake_threshold: Some(20),
2644
2645 #[allow(deprecated)]
2647 max_jwk_votes_per_validator_per_epoch: Some(240),
2648
2649 #[allow(deprecated)]
2650 max_age_of_jwk_in_epochs: Some(1),
2651
2652 consensus_max_transaction_size_bytes: Some(256 * 1024), consensus_max_transactions_in_block_bytes: Some(512 * 1024),
2656
2657 random_beacon_reduction_allowed_delta: Some(800),
2658
2659 random_beacon_reduction_lower_bound: Some(1000),
2660 random_beacon_dkg_timeout_round: Some(3000),
2661 random_beacon_min_round_interval_ms: Some(500),
2662
2663 random_beacon_dkg_version: Some(1),
2664
2665 consensus_max_num_transactions_in_block: Some(512),
2669
2670 max_deferral_rounds_for_congestion_control: Some(10),
2671
2672 min_checkpoint_interval_ms: Some(200),
2673
2674 checkpoint_rate_window_size: None,
2675
2676 checkpoint_summary_version_specific_data: Some(1),
2677
2678 max_soft_bundle_size: Some(5),
2679
2680 bridge_should_try_to_finalize_committee: None,
2681
2682 max_accumulated_txn_cost_per_object_in_mysticeti_commit: Some(10),
2683
2684 max_committee_members_count: None,
2685 deny_rule_update_max_entries_per_tx: None,
2686 deny_rule_removal_grace_round_floor: None,
2687
2688 consensus_gc_depth: None,
2689
2690 consensus_max_acknowledgments_per_block: None,
2691
2692 max_congestion_limit_overshoot_per_commit: None,
2693
2694 max_concurrent_execution_workers: None,
2695
2696 scorer_version: None,
2697
2698 auth_context_digest_cost_base: None,
2700 auth_context_tx_data_bytes_cost_base: None,
2701 auth_context_tx_data_bytes_cost_per_byte: None,
2702 auth_context_tx_commands_cost_base: None,
2703 auth_context_tx_commands_cost_per_byte: None,
2704 auth_context_tx_inputs_cost_base: None,
2705 auth_context_tx_inputs_cost_per_byte: None,
2706 auth_context_replace_cost_base: None,
2707 auth_context_replace_cost_per_byte: None,
2708 auth_context_authenticator_function_info_v1_cost_base: None,
2709 consensus_commits_per_schedule: None,
2710 min_validator_count: None,
2711 max_validator_count: None,
2712 min_validator_joining_stake: None,
2713 validator_low_stake_threshold: None,
2714 validator_very_low_stake_threshold: None,
2715 validator_low_stake_grace_period: None,
2716 consensus_leader_schedule_window_size: None,
2717 };
2720
2721 cfg.feature_flags.consensus_transaction_ordering = ConsensusTransactionOrdering::ByGasPrice;
2722
2723 {
2725 cfg.feature_flags
2726 .disable_invariant_violation_check_in_swap_loc = true;
2727 cfg.feature_flags.no_extraneous_module_bytes = true;
2728 cfg.feature_flags.hardened_otw_check = true;
2729 cfg.feature_flags.rethrow_serialization_type_layout_errors = true;
2730 }
2731
2732 {
2734 #[allow(deprecated)]
2735 {
2736 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = Some(30);
2737 }
2738 }
2739
2740 #[expect(deprecated)]
2744 {
2745 cfg.feature_flags.consensus_choice = ConsensusChoice::MysticetiDeprecated;
2746 }
2747 cfg.feature_flags.consensus_network = ConsensusNetwork::Tonic;
2749
2750 cfg.feature_flags.per_object_congestion_control_mode =
2751 PerObjectCongestionControlMode::TotalTxCount;
2752
2753 cfg.bridge_should_try_to_finalize_committee = Some(chain != Chain::Mainnet);
2755
2756 if chain != Chain::Mainnet && chain != Chain::Testnet {
2758 cfg.feature_flags.enable_poseidon = true;
2759 cfg.poseidon_bn254_cost_base = Some(260);
2760 cfg.poseidon_bn254_cost_per_block = Some(10);
2761
2762 cfg.feature_flags.enable_group_ops_native_function_msm = true;
2763
2764 cfg.feature_flags.enable_vdf = true;
2765 cfg.vdf_verify_vdf_cost = Some(1500);
2768 cfg.vdf_hash_to_input_cost = Some(100);
2769
2770 cfg.feature_flags.passkey_auth = true;
2771 }
2772
2773 for cur in 2..=version.0 {
2774 match cur {
2775 1 => unreachable!(),
2776 2 => {}
2778 3 => {
2779 cfg.feature_flags.relocate_event_module = true;
2780 }
2781 4 => {
2782 cfg.max_type_to_layout_nodes = Some(512);
2783 }
2784 5 => {
2785 cfg.feature_flags.protocol_defined_base_fee = true;
2786 cfg.base_gas_price = Some(1000);
2787
2788 cfg.feature_flags.disallow_new_modules_in_deps_only_packages = true;
2789 cfg.feature_flags.convert_type_argument_error = true;
2790 cfg.feature_flags.native_charging_v2 = true;
2791
2792 if chain != Chain::Mainnet && chain != Chain::Testnet {
2793 cfg.feature_flags.uncompressed_g1_group_elements = true;
2794 }
2795
2796 cfg.gas_model_version = Some(2);
2797
2798 cfg.poseidon_bn254_cost_per_block = Some(388);
2799
2800 cfg.bls12381_bls12381_min_sig_verify_cost_base = Some(44064);
2801 cfg.bls12381_bls12381_min_pk_verify_cost_base = Some(49282);
2802 cfg.ecdsa_k1_secp256k1_verify_keccak256_cost_base = Some(1470);
2803 cfg.ecdsa_k1_secp256k1_verify_sha256_cost_base = Some(1470);
2804 cfg.ecdsa_r1_secp256r1_verify_sha256_cost_base = Some(4225);
2805 cfg.ecdsa_r1_secp256r1_verify_keccak256_cost_base = Some(4225);
2806 cfg.ecvrf_ecvrf_verify_cost_base = Some(4848);
2807 cfg.ed25519_ed25519_verify_cost_base = Some(1802);
2808
2809 cfg.ecdsa_r1_ecrecover_keccak256_cost_base = Some(1173);
2811 cfg.ecdsa_r1_ecrecover_sha256_cost_base = Some(1173);
2812 cfg.ecdsa_k1_ecrecover_keccak256_cost_base = Some(500);
2813 cfg.ecdsa_k1_ecrecover_sha256_cost_base = Some(500);
2814
2815 cfg.groth16_prepare_verifying_key_bls12381_cost_base = Some(53838);
2816 cfg.groth16_prepare_verifying_key_bn254_cost_base = Some(82010);
2817 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_base = Some(72090);
2818 cfg.groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input =
2819 Some(8213);
2820 cfg.groth16_verify_groth16_proof_internal_bn254_cost_base = Some(115502);
2821 cfg.groth16_verify_groth16_proof_internal_bn254_cost_per_public_input =
2822 Some(9484);
2823
2824 cfg.hash_keccak256_cost_base = Some(10);
2825 cfg.hash_blake2b256_cost_base = Some(10);
2826
2827 cfg.group_ops_bls12381_decode_scalar_cost = Some(7);
2829 cfg.group_ops_bls12381_decode_g1_cost = Some(2848);
2830 cfg.group_ops_bls12381_decode_g2_cost = Some(3770);
2831 cfg.group_ops_bls12381_decode_gt_cost = Some(3068);
2832
2833 cfg.group_ops_bls12381_scalar_add_cost = Some(10);
2834 cfg.group_ops_bls12381_g1_add_cost = Some(1556);
2835 cfg.group_ops_bls12381_g2_add_cost = Some(3048);
2836 cfg.group_ops_bls12381_gt_add_cost = Some(188);
2837
2838 cfg.group_ops_bls12381_scalar_sub_cost = Some(10);
2839 cfg.group_ops_bls12381_g1_sub_cost = Some(1550);
2840 cfg.group_ops_bls12381_g2_sub_cost = Some(3019);
2841 cfg.group_ops_bls12381_gt_sub_cost = Some(497);
2842
2843 cfg.group_ops_bls12381_scalar_mul_cost = Some(11);
2844 cfg.group_ops_bls12381_g1_mul_cost = Some(4842);
2845 cfg.group_ops_bls12381_g2_mul_cost = Some(9108);
2846 cfg.group_ops_bls12381_gt_mul_cost = Some(27490);
2847
2848 cfg.group_ops_bls12381_scalar_div_cost = Some(91);
2849 cfg.group_ops_bls12381_g1_div_cost = Some(5091);
2850 cfg.group_ops_bls12381_g2_div_cost = Some(9206);
2851 cfg.group_ops_bls12381_gt_div_cost = Some(27804);
2852
2853 cfg.group_ops_bls12381_g1_hash_to_base_cost = Some(2962);
2854 cfg.group_ops_bls12381_g2_hash_to_base_cost = Some(8688);
2855
2856 cfg.group_ops_bls12381_g1_msm_base_cost = Some(62648);
2857 cfg.group_ops_bls12381_g2_msm_base_cost = Some(131192);
2858 cfg.group_ops_bls12381_g1_msm_base_cost_per_input = Some(1333);
2859 cfg.group_ops_bls12381_g2_msm_base_cost_per_input = Some(3216);
2860
2861 cfg.group_ops_bls12381_uncompressed_g1_to_g1_cost = Some(677);
2862 cfg.group_ops_bls12381_g1_to_uncompressed_g1_cost = Some(2099);
2863 cfg.group_ops_bls12381_uncompressed_g1_sum_base_cost = Some(77);
2864 cfg.group_ops_bls12381_uncompressed_g1_sum_cost_per_term = Some(26);
2865 cfg.group_ops_bls12381_uncompressed_g1_sum_max_terms = Some(1200);
2866
2867 cfg.group_ops_bls12381_pairing_cost = Some(26897);
2868
2869 cfg.validator_validate_metadata_cost_base = Some(20000);
2870
2871 cfg.max_committee_members_count = Some(50);
2872 }
2873 6 => {
2874 cfg.max_ptb_value_size = Some(1024 * 1024);
2875 }
2876 7 => {
2877 }
2880 8 => {
2881 cfg.feature_flags.variant_nodes = true;
2882
2883 if chain != Chain::Mainnet {
2884 cfg.feature_flags.consensus_round_prober = true;
2886 cfg.feature_flags
2888 .consensus_distributed_vote_scoring_strategy = true;
2889 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2890 cfg.feature_flags.consensus_smart_ancestor_selection = true;
2892 cfg.feature_flags
2894 .consensus_round_prober_probe_accepted_rounds = true;
2895 cfg.feature_flags.consensus_zstd_compression = true;
2897 cfg.consensus_gc_depth = Some(60);
2901 }
2902
2903 if chain != Chain::Testnet && chain != Chain::Mainnet {
2906 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2907 }
2908 }
2909 9 => {
2910 if chain != Chain::Mainnet {
2911 cfg.feature_flags.consensus_smart_ancestor_selection = false;
2913 }
2914
2915 cfg.feature_flags.consensus_zstd_compression = true;
2917
2918 if chain != Chain::Testnet && chain != Chain::Mainnet {
2920 cfg.feature_flags.accept_passkey_in_multisig = true;
2921 }
2922
2923 cfg.bridge_should_try_to_finalize_committee = None;
2925 }
2926 10 => {
2927 cfg.feature_flags.congestion_control_min_free_execution_slot = true;
2930
2931 cfg.max_committee_members_count = Some(80);
2933
2934 cfg.feature_flags.consensus_round_prober = true;
2936 cfg.feature_flags
2938 .consensus_round_prober_probe_accepted_rounds = true;
2939 cfg.feature_flags
2941 .consensus_distributed_vote_scoring_strategy = true;
2942 cfg.feature_flags.consensus_linearize_subdag_v2 = true;
2944
2945 cfg.consensus_gc_depth = Some(60);
2950
2951 cfg.feature_flags.minimize_child_object_mutations = true;
2953
2954 if chain != Chain::Mainnet {
2955 cfg.feature_flags.consensus_batched_block_sync = true;
2957 }
2958
2959 if chain != Chain::Testnet && chain != Chain::Mainnet {
2960 cfg.feature_flags
2963 .congestion_control_gas_price_feedback_mechanism = true;
2964 }
2965
2966 cfg.feature_flags.validate_identifier_inputs = true;
2967 cfg.feature_flags.dependency_linkage_error = true;
2968 cfg.feature_flags.additional_multisig_checks = true;
2969 }
2970 11 => {
2971 }
2974 12 => {
2975 cfg.feature_flags
2978 .congestion_control_gas_price_feedback_mechanism = true;
2979
2980 cfg.feature_flags.normalize_ptb_arguments = true;
2982 }
2983 13 => {
2984 cfg.feature_flags.select_committee_from_eligible_validators = true;
2987 cfg.feature_flags.track_non_committee_eligible_validators = true;
2990
2991 if chain != Chain::Testnet && chain != Chain::Mainnet {
2992 cfg.feature_flags
2995 .select_committee_supporting_next_epoch_version = true;
2996 }
2997 }
2998 14 => {
2999 cfg.feature_flags.consensus_batched_block_sync = true;
3001
3002 if chain != Chain::Mainnet {
3003 cfg.feature_flags
3006 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3007 cfg.feature_flags
3011 .select_committee_supporting_next_epoch_version = true;
3012 }
3013 if chain != Chain::Testnet && chain != Chain::Mainnet {
3014 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3016 }
3017 }
3018 15 => {
3019 if chain != Chain::Mainnet && chain != Chain::Testnet {
3020 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3024 }
3025 }
3026 16 => {
3027 cfg.feature_flags
3030 .select_committee_supporting_next_epoch_version = true;
3031 cfg.feature_flags
3033 .consensus_commit_transactions_only_for_traversed_headers = true;
3034 }
3035 17 => {
3036 cfg.max_committee_members_count = Some(100);
3038 }
3039 18 => {
3040 if chain != Chain::Mainnet {
3041 cfg.feature_flags.passkey_auth = true;
3043 }
3044 }
3045 19 => {
3046 if chain != Chain::Testnet && chain != Chain::Mainnet {
3047 cfg.feature_flags
3050 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3051 cfg.feature_flags
3054 .separate_gas_price_feedback_mechanism_for_randomness = true;
3055 cfg.feature_flags.metadata_in_module_bytes = true;
3058 cfg.feature_flags.publish_package_metadata = true;
3059 cfg.feature_flags.enable_move_authentication = true;
3061 cfg.max_auth_gas = Some(250_000_000);
3063 cfg.transfer_receive_object_cost_base = Some(100);
3066 cfg.feature_flags.adjust_rewards_by_score = true;
3068 }
3069
3070 if chain != Chain::Mainnet {
3071 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3073
3074 cfg.feature_flags.calculate_validator_scores = true;
3076 cfg.scorer_version = Some(1);
3077 }
3078
3079 cfg.feature_flags.pass_validator_scores_to_advance_epoch = true;
3081
3082 cfg.feature_flags.passkey_auth = true;
3084 }
3085 20 => {
3086 if chain != Chain::Testnet && chain != Chain::Mainnet {
3087 cfg.feature_flags
3089 .pass_calculated_validator_scores_to_advance_epoch = true;
3090 }
3091 }
3092 21 => {
3093 if chain != Chain::Testnet && chain != Chain::Mainnet {
3094 cfg.feature_flags.consensus_fast_commit_sync = true;
3096 }
3097 if chain != Chain::Mainnet {
3098 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3103 cfg.feature_flags
3106 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3107 cfg.feature_flags
3110 .separate_gas_price_feedback_mechanism_for_randomness = true;
3111 }
3112
3113 cfg.auth_context_digest_cost_base = Some(30);
3114 cfg.auth_context_tx_commands_cost_base = Some(30);
3115 cfg.auth_context_tx_commands_cost_per_byte = Some(2);
3116 cfg.auth_context_tx_inputs_cost_base = Some(30);
3117 cfg.auth_context_tx_inputs_cost_per_byte = Some(2);
3118 cfg.auth_context_replace_cost_base = Some(30);
3119 cfg.auth_context_replace_cost_per_byte = Some(2);
3120
3121 if chain != Chain::Testnet && chain != Chain::Mainnet {
3122 cfg.max_auth_gas = Some(250_000);
3124 }
3125 }
3126 22 => {
3127 cfg.max_congestion_limit_overshoot_per_commit = Some(100);
3132 cfg.feature_flags
3135 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = true;
3136 cfg.feature_flags
3139 .separate_gas_price_feedback_mechanism_for_randomness = true;
3140
3141 if chain != Chain::Mainnet {
3142 cfg.feature_flags.metadata_in_module_bytes = true;
3145 cfg.feature_flags.publish_package_metadata = true;
3146 cfg.feature_flags.enable_move_authentication = true;
3148 cfg.max_auth_gas = Some(250_000);
3150 cfg.transfer_receive_object_cost_base = Some(100);
3153 }
3154
3155 if chain != Chain::Mainnet {
3156 cfg.feature_flags.consensus_fast_commit_sync = true;
3158 }
3159 }
3160 23 => {
3161 cfg.feature_flags.move_native_tx_context = true;
3163 cfg.tx_context_fresh_id_cost_base = Some(52);
3164 cfg.tx_context_sender_cost_base = Some(30);
3165 cfg.tx_context_digest_cost_base = Some(30);
3166 cfg.tx_context_epoch_cost_base = Some(30);
3167 cfg.tx_context_epoch_timestamp_ms_cost_base = Some(30);
3168 cfg.tx_context_sponsor_cost_base = Some(30);
3169 cfg.tx_context_rgp_cost_base = Some(30);
3170 cfg.tx_context_gas_price_cost_base = Some(30);
3171 cfg.tx_context_gas_budget_cost_base = Some(30);
3172 cfg.tx_context_ids_created_cost_base = Some(30);
3173 cfg.tx_context_replace_cost_base = Some(30);
3174 }
3175 24 => {
3176 cfg.feature_flags.consensus_choice = ConsensusChoice::Starfish;
3178
3179 if chain != Chain::Testnet && chain != Chain::Mainnet {
3180 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3182 }
3183
3184 cfg.auth_context_tx_data_bytes_cost_base = Some(30);
3187 cfg.auth_context_tx_data_bytes_cost_per_byte = Some(2);
3188
3189 cfg.feature_flags.additional_borrow_checks = true;
3191 }
3192 #[allow(deprecated)]
3193 25 => {
3194 cfg.feature_flags.zklogin_max_epoch_upper_bound_delta = None;
3197 cfg.check_zklogin_id_cost_base = None;
3198 cfg.check_zklogin_issuer_cost_base = None;
3199 cfg.max_jwk_votes_per_validator_per_epoch = None;
3200 cfg.max_age_of_jwk_in_epochs = None;
3201 }
3202 26 => {
3203 }
3206 27 => {
3207 if chain != Chain::Mainnet {
3208 cfg.feature_flags.consensus_block_restrictions = true;
3211 }
3212
3213 if chain != Chain::Testnet && chain != Chain::Mainnet {
3214 cfg.feature_flags
3216 .pre_consensus_sponsor_only_move_authentication = true;
3217 }
3218 }
3219 28 => {
3220 cfg.auth_context_authenticator_function_info_v1_cost_base = Some(270);
3225
3226 cfg.feature_flags.metadata_in_module_bytes = true;
3229 cfg.feature_flags.publish_package_metadata = true;
3230 cfg.feature_flags.enable_move_authentication = true;
3232 cfg.transfer_receive_object_cost_base = Some(100);
3235
3236 if chain != Chain::Unknown {
3237 cfg.max_auth_gas = Some(20_000);
3239 }
3240
3241 if chain != Chain::Mainnet {
3242 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3244 cfg.feature_flags
3246 .pre_consensus_sponsor_only_move_authentication = true;
3247 }
3248 }
3249 29 => {
3250 cfg.feature_flags.always_advance_dkg_to_resolution = true;
3256
3257 cfg.feature_flags
3260 .consensus_median_timestamp_with_checkpoint_enforcement = true;
3261
3262 cfg.feature_flags.consensus_fast_commit_sync = true;
3264 cfg.feature_flags.consensus_block_restrictions = true;
3268 }
3269 30 => {
3270 }
3278 31 => {
3279 cfg.feature_flags.validator_metadata_verify_v2 = true;
3280
3281 if chain != Chain::Mainnet && chain != Chain::Testnet {
3282 cfg.checkpoint_rate_window_size = Some(20);
3285 cfg.feature_flags
3288 .package_metadata_with_dynamic_module_metadata = true;
3289 cfg.feature_flags.consensus_starfish_speed = true;
3292 }
3293
3294 cfg.feature_flags.report_move_authentication_error = true;
3295 }
3296 32 => {
3297 cfg.min_validator_count = Some(4);
3301 cfg.max_validator_count = Some(150);
3302 cfg.min_validator_joining_stake = Some(2_000_000_000_000_000);
3303 cfg.validator_low_stake_threshold = Some(1_500_000_000_000_000);
3304 cfg.validator_very_low_stake_threshold = Some(1_000_000_000_000_000);
3305 cfg.validator_low_stake_grace_period = Some(7);
3306
3307 cfg.feature_flags.enable_move_authentication_for_sponsor = true;
3309 cfg.feature_flags
3311 .pre_consensus_sponsor_only_move_authentication = true;
3312
3313 if chain != Chain::Mainnet {
3314 cfg.feature_flags.consensus_starfish_speed = true;
3317 cfg.checkpoint_rate_window_size = Some(20);
3320 cfg.feature_flags
3323 .package_metadata_with_dynamic_module_metadata = true;
3324 }
3325
3326 if chain != Chain::Mainnet && chain != Chain::Testnet {
3327 cfg.feature_flags
3331 .consensus_enable_sliding_window_leader_schedule = true;
3332 cfg.feature_flags
3333 .consensus_enable_absolute_score_leader_schedule = true;
3334 cfg.feature_flags.enable_pcool_flow = true;
3338 }
3339 }
3340 33 => {
3341 cfg.checkpoint_rate_window_size = Some(20);
3344 if chain != Chain::Mainnet {
3348 cfg.feature_flags
3349 .consensus_enable_sliding_window_leader_schedule = true;
3350 cfg.feature_flags
3351 .consensus_enable_absolute_score_leader_schedule = true;
3352 }
3353 }
3354 34 => {
3355 if chain != Chain::Testnet && chain != Chain::Mainnet {
3356 cfg.scorer_version = Some(2);
3360 }
3361 cfg.feature_flags.pcool_skip_immutable_object_locks = true;
3365 }
3366 _ => panic!("unsupported version {version:?}"),
3377 }
3378 }
3379 cfg
3380 }
3381
3382 pub fn verifier_config(&self, signing_limits: Option<(usize, usize, usize)>) -> VerifierConfig {
3388 let (
3389 max_back_edges_per_function,
3390 max_back_edges_per_module,
3391 sanity_check_with_regex_reference_safety,
3392 ) = if let Some((
3393 max_back_edges_per_function,
3394 max_back_edges_per_module,
3395 sanity_check_with_regex_reference_safety,
3396 )) = signing_limits
3397 {
3398 (
3399 Some(max_back_edges_per_function),
3400 Some(max_back_edges_per_module),
3401 Some(sanity_check_with_regex_reference_safety),
3402 )
3403 } else {
3404 (None, None, None)
3405 };
3406
3407 let additional_borrow_checks = if signing_limits.is_some() {
3408 true
3411 } else {
3412 self.additional_borrow_checks()
3413 };
3414
3415 VerifierConfig {
3416 max_loop_depth: Some(self.max_loop_depth() as usize),
3417 max_generic_instantiation_length: Some(self.max_generic_instantiation_length() as usize),
3418 max_function_parameters: Some(self.max_function_parameters() as usize),
3419 max_basic_blocks: Some(self.max_basic_blocks() as usize),
3420 max_value_stack_size: self.max_value_stack_size() as usize,
3421 max_type_nodes: Some(self.max_type_nodes() as usize),
3422 max_push_size: Some(self.max_push_size() as usize),
3423 max_dependency_depth: Some(self.max_dependency_depth() as usize),
3424 max_fields_in_struct: Some(self.max_fields_in_struct() as usize),
3425 max_function_definitions: Some(self.max_function_definitions() as usize),
3426 max_data_definitions: Some(self.max_struct_definitions() as usize),
3427 max_constant_vector_len: Some(self.max_move_vector_len()),
3428 max_back_edges_per_function,
3429 max_back_edges_per_module,
3430 max_basic_blocks_in_script: None,
3431 max_identifier_len: self.max_move_identifier_len_as_option(), bytecode_version: self.move_binary_format_version(),
3435 max_variants_in_enum: self.max_move_enum_variants_as_option(),
3436 additional_borrow_checks,
3437 sanity_check_with_regex_reference_safety: sanity_check_with_regex_reference_safety
3438 .map(|limit| limit as u128),
3439 }
3440 }
3441
3442 pub fn apply_overrides_for_testing(
3447 override_fn: impl Fn(ProtocolVersion, Self) -> Self + Send + Sync + 'static,
3448 ) -> OverrideGuard {
3449 CONFIG_OVERRIDE.with(|ovr| {
3450 let mut cur = ovr.borrow_mut();
3451 assert!(cur.is_none(), "config override already present");
3452 *cur = Some(Box::new(override_fn));
3453 OverrideGuard
3454 })
3455 }
3456}
3457
3458impl ProtocolConfig {
3463 pub fn set_per_object_congestion_control_mode_for_testing(
3464 &mut self,
3465 val: PerObjectCongestionControlMode,
3466 ) {
3467 self.feature_flags.per_object_congestion_control_mode = val;
3468 }
3469
3470 pub fn set_consensus_choice_for_testing(&mut self, val: ConsensusChoice) {
3471 self.feature_flags.consensus_choice = val;
3472 }
3473
3474 pub fn set_consensus_network_for_testing(&mut self, val: ConsensusNetwork) {
3475 self.feature_flags.consensus_network = val;
3476 }
3477
3478 pub fn set_passkey_auth_for_testing(&mut self, val: bool) {
3479 self.feature_flags.passkey_auth = val
3480 }
3481
3482 pub fn set_disallow_new_modules_in_deps_only_packages_for_testing(&mut self, val: bool) {
3483 self.feature_flags
3484 .disallow_new_modules_in_deps_only_packages = val;
3485 }
3486
3487 pub fn set_consensus_round_prober_for_testing(&mut self, val: bool) {
3488 self.feature_flags.consensus_round_prober = val;
3489 }
3490
3491 pub fn set_consensus_distributed_vote_scoring_strategy_for_testing(&mut self, val: bool) {
3492 self.feature_flags
3493 .consensus_distributed_vote_scoring_strategy = val;
3494 }
3495
3496 pub fn set_gc_depth_for_testing(&mut self, val: u32) {
3497 self.consensus_gc_depth = Some(val);
3498 }
3499
3500 pub fn set_consensus_linearize_subdag_v2_for_testing(&mut self, val: bool) {
3501 self.feature_flags.consensus_linearize_subdag_v2 = val;
3502 }
3503
3504 pub fn set_consensus_round_prober_probe_accepted_rounds(&mut self, val: bool) {
3505 self.feature_flags
3506 .consensus_round_prober_probe_accepted_rounds = val;
3507 }
3508
3509 pub fn set_accept_passkey_in_multisig_for_testing(&mut self, val: bool) {
3510 self.feature_flags.accept_passkey_in_multisig = val;
3511 }
3512
3513 pub fn set_consensus_smart_ancestor_selection_for_testing(&mut self, val: bool) {
3514 self.feature_flags.consensus_smart_ancestor_selection = val;
3515 }
3516
3517 pub fn set_consensus_batched_block_sync_for_testing(&mut self, val: bool) {
3518 self.feature_flags.consensus_batched_block_sync = val;
3519 }
3520
3521 pub fn set_congestion_control_min_free_execution_slot_for_testing(&mut self, val: bool) {
3522 self.feature_flags
3523 .congestion_control_min_free_execution_slot = val;
3524 }
3525
3526 pub fn set_congestion_control_gas_price_feedback_mechanism_for_testing(&mut self, val: bool) {
3527 self.feature_flags
3528 .congestion_control_gas_price_feedback_mechanism = val;
3529 }
3530
3531 pub fn set_select_committee_from_eligible_validators_for_testing(&mut self, val: bool) {
3532 self.feature_flags.select_committee_from_eligible_validators = val;
3533 }
3534
3535 pub fn set_track_non_committee_eligible_validators_for_testing(&mut self, val: bool) {
3536 self.feature_flags.track_non_committee_eligible_validators = val;
3537 }
3538
3539 pub fn set_select_committee_supporting_next_epoch_version(&mut self, val: bool) {
3540 self.feature_flags
3541 .select_committee_supporting_next_epoch_version = val;
3542 }
3543
3544 pub fn set_consensus_median_timestamp_with_checkpoint_enforcement_for_testing(
3545 &mut self,
3546 val: bool,
3547 ) {
3548 self.feature_flags
3549 .consensus_median_timestamp_with_checkpoint_enforcement = val;
3550 }
3551
3552 pub fn set_consensus_commit_transactions_only_for_traversed_headers_for_testing(
3553 &mut self,
3554 val: bool,
3555 ) {
3556 self.feature_flags
3557 .consensus_commit_transactions_only_for_traversed_headers = val;
3558 }
3559
3560 pub fn set_congestion_limit_overshoot_in_gas_price_feedback_mechanism_for_testing(
3561 &mut self,
3562 val: bool,
3563 ) {
3564 self.feature_flags
3565 .congestion_limit_overshoot_in_gas_price_feedback_mechanism = val;
3566 }
3567
3568 pub fn set_separate_gas_price_feedback_mechanism_for_randomness_for_testing(
3569 &mut self,
3570 val: bool,
3571 ) {
3572 self.feature_flags
3573 .separate_gas_price_feedback_mechanism_for_randomness = val;
3574 }
3575
3576 pub fn set_metadata_in_module_bytes_for_testing(&mut self, val: bool) {
3577 self.feature_flags.metadata_in_module_bytes = val;
3578 }
3579
3580 pub fn set_publish_package_metadata_for_testing(&mut self, val: bool) {
3581 self.feature_flags.publish_package_metadata = val;
3582 }
3583
3584 pub fn set_enable_move_authentication_for_testing(&mut self, val: bool) {
3585 self.feature_flags.enable_move_authentication = val;
3586 }
3587
3588 pub fn set_enable_move_authentication_for_sponsor_for_testing(&mut self, val: bool) {
3589 self.feature_flags.enable_move_authentication_for_sponsor = val;
3590 }
3591
3592 pub fn set_consensus_fast_commit_sync_for_testing(&mut self, val: bool) {
3593 self.feature_flags.consensus_fast_commit_sync = val;
3594 }
3595
3596 pub fn set_consensus_block_restrictions_for_testing(&mut self, val: bool) {
3597 self.feature_flags.consensus_block_restrictions = val;
3598 }
3599
3600 pub fn set_pre_consensus_sponsor_only_move_authentication_for_testing(&mut self, val: bool) {
3601 self.feature_flags
3602 .pre_consensus_sponsor_only_move_authentication = val;
3603 }
3604
3605 pub fn set_consensus_starfish_speed_for_testing(&mut self, val: bool) {
3606 self.feature_flags.consensus_starfish_speed = val;
3607 }
3608
3609 pub fn set_always_advance_dkg_to_resolution_for_testing(&mut self, val: bool) {
3610 self.feature_flags.always_advance_dkg_to_resolution = val;
3611 }
3612
3613 pub fn set_enable_pcool_flow_for_testing(&mut self, val: bool) {
3614 self.feature_flags.enable_pcool_flow = val;
3615 }
3616
3617 pub fn set_pcool_skip_immutable_object_locks_for_testing(&mut self, val: bool) {
3618 self.feature_flags.pcool_skip_immutable_object_locks = val;
3619 }
3620
3621 pub fn set_commits_per_schedule_for_testing(&mut self, val: u32) {
3622 self.consensus_commits_per_schedule = Some(val);
3623 }
3624
3625 pub fn set_deny_rule_governance_for_testing(&mut self, val: bool) {
3626 self.feature_flags.deny_rule_governance = val;
3627 }
3628
3629 pub fn set_deny_rule_governance_on_chain_for_testing(&mut self, val: bool) {
3630 self.feature_flags.deny_rule_governance_on_chain = val;
3631 }
3632
3633 pub fn set_package_metadata_with_dynamic_module_metadata_for_testing(&mut self, val: bool) {
3634 self.feature_flags
3635 .package_metadata_with_dynamic_module_metadata = val;
3636 }
3637
3638 pub fn set_report_move_authentication_error_for_testing(&mut self, val: bool) {
3639 self.feature_flags.report_move_authentication_error = val;
3640 }
3641
3642 pub fn set_leader_schedule_window_size_for_testing(&mut self, val: u32) {
3643 self.consensus_leader_schedule_window_size = Some(val);
3644 }
3645
3646 pub fn set_consensus_enable_sliding_window_leader_schedule_for_testing(&mut self, val: bool) {
3647 self.feature_flags
3648 .consensus_enable_sliding_window_leader_schedule = val;
3649 }
3650
3651 pub fn set_consensus_enable_absolute_score_leader_schedule_for_testing(&mut self, val: bool) {
3652 self.feature_flags
3653 .consensus_enable_absolute_score_leader_schedule = val;
3654 }
3655}
3656
3657type OverrideFn = dyn Fn(ProtocolVersion, ProtocolConfig) -> ProtocolConfig + Send + Sync;
3658
3659thread_local! {
3660 static CONFIG_OVERRIDE: RefCell<Option<Box<OverrideFn>>> = const { RefCell::new(None) };
3661}
3662
3663#[must_use]
3664pub struct OverrideGuard;
3665
3666impl Drop for OverrideGuard {
3667 fn drop(&mut self) {
3668 info!("restoring override fn");
3669 CONFIG_OVERRIDE.with(|ovr| {
3670 *ovr.borrow_mut() = None;
3671 });
3672 }
3673}
3674
3675#[derive(PartialEq, Eq)]
3679pub enum LimitThresholdCrossed {
3680 None,
3681 Soft(u128, u128),
3682 Hard(u128, u128),
3683}
3684
3685pub fn check_limit_in_range<T: Into<V>, U: Into<V>, V: PartialOrd + Into<u128>>(
3688 x: T,
3689 soft_limit: U,
3690 hard_limit: V,
3691) -> LimitThresholdCrossed {
3692 let x: V = x.into();
3693 let soft_limit: V = soft_limit.into();
3694
3695 debug_assert!(soft_limit <= hard_limit);
3696
3697 if x >= hard_limit {
3700 LimitThresholdCrossed::Hard(x.into(), hard_limit.into())
3701 } else if x < soft_limit {
3702 LimitThresholdCrossed::None
3703 } else {
3704 LimitThresholdCrossed::Soft(x.into(), soft_limit.into())
3705 }
3706}
3707
3708#[macro_export]
3709macro_rules! check_limit {
3710 ($x:expr, $hard:expr) => {
3711 check_limit!($x, $hard, $hard)
3712 };
3713 ($x:expr, $soft:expr, $hard:expr) => {
3714 check_limit_in_range($x as u64, $soft, $hard)
3715 };
3716}
3717
3718#[macro_export]
3722macro_rules! check_limit_by_meter {
3723 ($is_metered:expr, $x:expr, $metered_limit:expr, $unmetered_hard_limit:expr, $metric:expr) => {{
3724 let (h, metered_str) = if $is_metered {
3726 ($metered_limit, "metered")
3727 } else {
3728 ($unmetered_hard_limit, "unmetered")
3730 };
3731 use iota_protocol_config::check_limit_in_range;
3732 let result = check_limit_in_range($x as u64, $metered_limit, h);
3733 match result {
3734 LimitThresholdCrossed::None => {}
3735 LimitThresholdCrossed::Soft(_, _) => {
3736 $metric.with_label_values(&[metered_str, "soft"]).inc();
3737 }
3738 LimitThresholdCrossed::Hard(_, _) => {
3739 $metric.with_label_values(&[metered_str, "hard"]).inc();
3740 }
3741 };
3742 result
3743 }};
3744}
3745
3746#[cfg(all(test, not(msim)))]
3747mod test {
3748 use insta::assert_yaml_snapshot;
3749
3750 use super::*;
3751
3752 #[test]
3753 fn snapshot_tests() {
3754 println!("\n============================================================================");
3755 println!("! !");
3756 println!("! IMPORTANT: never update snapshots from this test. only add new versions! !");
3757 println!("! !");
3758 println!("============================================================================\n");
3759 for chain_id in &[Chain::Unknown, Chain::Mainnet, Chain::Testnet] {
3760 let chain_str = match chain_id {
3765 Chain::Unknown => "".to_string(),
3766 _ => format!("{chain_id:?}_"),
3767 };
3768 for i in MIN_PROTOCOL_VERSION..=MAX_PROTOCOL_VERSION {
3769 let cur = ProtocolVersion::new(i);
3770 assert_yaml_snapshot!(
3771 format!("{}version_{}", chain_str, cur.as_u64()),
3772 ProtocolConfig::get_for_version(cur, *chain_id)
3773 );
3774 }
3775 }
3776 }
3777
3778 #[test]
3779 fn test_getters() {
3780 let prot: ProtocolConfig =
3781 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3782 assert_eq!(
3783 prot.max_arguments(),
3784 prot.max_arguments_as_option().unwrap()
3785 );
3786 }
3787
3788 #[test]
3789 fn test_setters() {
3790 let mut prot: ProtocolConfig =
3791 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3792 prot.set_max_arguments_for_testing(123);
3793 assert_eq!(prot.max_arguments(), 123);
3794
3795 prot.set_max_arguments_from_str_for_testing("321".to_string());
3796 assert_eq!(prot.max_arguments(), 321);
3797
3798 prot.disable_max_arguments_for_testing();
3799 assert_eq!(prot.max_arguments_as_option(), None);
3800
3801 prot.set_attr_for_testing("max_arguments".to_string(), "456".to_string());
3802 assert_eq!(prot.max_arguments(), 456);
3803 }
3804
3805 #[test]
3806 #[should_panic(expected = "unsupported version")]
3807 fn max_version_test() {
3808 let _ = ProtocolConfig::get_for_version_impl(
3811 ProtocolVersion::new(MAX_PROTOCOL_VERSION + 1),
3812 Chain::Unknown,
3813 );
3814 }
3815
3816 #[test]
3817 fn lookup_by_string_test() {
3818 let prot: ProtocolConfig =
3819 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3820 assert!(prot.lookup_attr("some random string".to_string()).is_none());
3822
3823 assert!(
3824 prot.lookup_attr("max_arguments".to_string())
3825 == Some(ProtocolConfigValue::u32(prot.max_arguments())),
3826 );
3827
3828 assert!(
3830 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3831 .is_none()
3832 );
3833 assert!(
3834 prot.attr_map()
3835 .get("poseidon_bn254_cost_base")
3836 .unwrap()
3837 .is_none()
3838 );
3839
3840 let prot: ProtocolConfig =
3842 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3843
3844 assert!(
3845 prot.lookup_attr("poseidon_bn254_cost_base".to_string())
3846 == Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3847 );
3848 assert!(
3849 prot.attr_map().get("poseidon_bn254_cost_base").unwrap()
3850 == &Some(ProtocolConfigValue::u64(prot.poseidon_bn254_cost_base()))
3851 );
3852
3853 let prot: ProtocolConfig =
3855 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Mainnet);
3856 assert!(
3858 prot.feature_flags
3859 .lookup_attr("some random string".to_owned())
3860 .is_none()
3861 );
3862 assert!(
3863 !prot
3864 .feature_flags
3865 .attr_map()
3866 .contains_key("some random string")
3867 );
3868
3869 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(false));
3871 assert!(
3872 prot.feature_flags
3873 .attr_map()
3874 .get("enable_poseidon")
3875 .unwrap()
3876 == &false
3877 );
3878 let prot: ProtocolConfig =
3879 ProtocolConfig::get_for_version(ProtocolVersion::new(1), Chain::Unknown);
3880 assert!(prot.feature_flags.lookup_attr("enable_poseidon".to_owned()) == Some(true));
3882 assert!(
3883 prot.feature_flags
3884 .attr_map()
3885 .get("enable_poseidon")
3886 .unwrap()
3887 == &true
3888 );
3889 }
3890
3891 #[test]
3895 #[should_panic(expected = "deny_rule_update_max_entries_per_tx must be positive")]
3896 fn deny_rule_chunk_limit_above_the_ceiling_is_rejected() {
3897 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
3898 config.set_deny_rule_governance_for_testing(true);
3899 config.set_deny_rule_governance_on_chain_for_testing(true);
3900 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
3901 config.set_deny_rule_update_max_entries_per_tx_for_testing(2048 + 1);
3902 config
3903 });
3904 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
3905 }
3906
3907 #[test]
3910 #[should_panic(expected = "deny_rule_update_max_entries_per_tx must be positive")]
3911 fn deny_rule_chunk_limit_of_zero_is_rejected() {
3912 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
3913 config.set_deny_rule_governance_for_testing(true);
3914 config.set_deny_rule_governance_on_chain_for_testing(true);
3915 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
3916 config.set_deny_rule_update_max_entries_per_tx_for_testing(0);
3917 config
3918 });
3919 let _ = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
3920 }
3921
3922 #[test]
3924 fn deny_rule_chunk_limit_within_system_tx_object_id_limit_is_accepted() {
3925 let _guard = ProtocolConfig::apply_overrides_for_testing(|_, mut config| {
3926 config.set_deny_rule_governance_for_testing(true);
3927 config.set_deny_rule_governance_on_chain_for_testing(true);
3928 config.set_deny_rule_removal_grace_round_floor_for_testing(0);
3929 config.set_deny_rule_update_max_entries_per_tx_for_testing(1000);
3930 config
3931 });
3932 let config = ProtocolConfig::get_for_version(ProtocolVersion::max(), Chain::Unknown);
3933 assert_eq!(config.deny_rule_update_max_entries_per_tx(), 1000);
3934 }
3935
3936 #[test]
3937 fn limit_range_fn_test() {
3938 let low = 100u32;
3939 let high = 10000u64;
3940
3941 assert!(check_limit!(1u8, low, high) == LimitThresholdCrossed::None);
3942 assert!(matches!(
3943 check_limit!(255u16, low, high),
3944 LimitThresholdCrossed::Soft(255u128, 100)
3945 ));
3946 assert!(matches!(
3953 check_limit!(2550000u64, low, high),
3954 LimitThresholdCrossed::Hard(2550000, 10000)
3955 ));
3956
3957 assert!(matches!(
3958 check_limit!(2550000u64, high, high),
3959 LimitThresholdCrossed::Hard(2550000, 10000)
3960 ));
3961
3962 assert!(matches!(
3963 check_limit!(1u8, high),
3964 LimitThresholdCrossed::None
3965 ));
3966
3967 assert!(check_limit!(255u16, high) == LimitThresholdCrossed::None);
3968
3969 assert!(matches!(
3970 check_limit!(2550000u64, high),
3971 LimitThresholdCrossed::Hard(2550000, 10000)
3972 ));
3973 }
3974}